[BACK]Return to init.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / engine

Annotation of OpenXM_contrib2/asir2000/engine/init.c, Revision 1.12

1.2       noro        1: /*
                      2:  * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
                      3:  * All rights reserved.
                      4:  *
                      5:  * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
                      6:  * non-exclusive and royalty-free license to use, copy, modify and
                      7:  * redistribute, solely for non-commercial and non-profit purposes, the
                      8:  * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
                      9:  * conditions of this Agreement. For the avoidance of doubt, you acquire
                     10:  * only a limited right to use the SOFTWARE hereunder, and FLL or any
                     11:  * third party developer retains all rights, including but not limited to
                     12:  * copyrights, in and to the SOFTWARE.
                     13:  *
                     14:  * (1) FLL does not grant you a license in any way for commercial
                     15:  * purposes. You may use the SOFTWARE only for non-commercial and
                     16:  * non-profit purposes only, such as academic, research and internal
                     17:  * business use.
                     18:  * (2) The SOFTWARE is protected by the Copyright Law of Japan and
                     19:  * international copyright treaties. If you make copies of the SOFTWARE,
                     20:  * with or without modification, as permitted hereunder, you shall affix
                     21:  * to all such copies of the SOFTWARE the above copyright notice.
                     22:  * (3) An explicit reference to this SOFTWARE and its copyright owner
                     23:  * shall be made on your publication or presentation in any form of the
                     24:  * results obtained by use of the SOFTWARE.
                     25:  * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.3       noro       26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.2       noro       27:  * for such modification or the source code of the modified part of the
                     28:  * SOFTWARE.
                     29:  *
                     30:  * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
                     31:  * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
                     32:  * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
                     33:  * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
                     34:  * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
                     35:  * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
                     36:  * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
                     37:  * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
                     38:  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
                     39:  * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
                     40:  * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
                     41:  * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
                     42:  * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
                     43:  * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
                     44:  * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
                     45:  * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
                     46:  * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
                     47:  *
1.12    ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/engine/init.c,v 1.11 2001/06/07 04:54:40 noro Exp $
1.2       noro       49: */
1.1       noro       50: #include "ca.h"
                     51: #include "version.h"
1.11      noro       52: #include "prime.h"
1.1       noro       53:
                     54: struct oN oUNIN,oTWON,oTHREEN,oFOURN,oFIVEN,oSIXN,oSEVENN,oEIGHTN;
                     55: struct oQ oUNIQ,oTWOQ,oTHREEQ,oFOURQ,oFIVEQ,oSIXQ,oSEVENQ,oEIGHTQ;
                     56:
                     57: struct oUP2 oONEUP2;
                     58:
                     59: N ONEN = &oUNIN;
                     60: Q ONE = &oUNIQ;
                     61: Q TWO = &oTWOQ;
                     62: Q THREE = &oTHREEQ;
                     63: Q FOUR = &oFOURQ;
                     64: Q FIVE = &oFIVEQ;
                     65: Q SIX = &oSIXQ;
                     66: Q SEVEN = &oSEVENQ;
                     67: Q EIGHT = &oEIGHTQ;
                     68:
                     69: LM THREE_LM,FOUR_LM,EIGHT_LM;
                     70:
                     71: struct oR oUNIR;
                     72: struct oMQ oUNIMQ;
                     73: struct oLM oUNILM;
                     74: struct oC oIU;
                     75: struct oUSINT oVOID;
                     76:
                     77: MQ ONEM = &oUNIMQ;
                     78: LM ONELM = &oUNILM;
                     79: UP2 ONEUP2 = &oONEUP2;
                     80: C IU = &oIU;
                     81: USINT VOIDobj = &oVOID;
                     82:
                     83: int bigfloat;
                     84: int nez = 1;
                     85: int current_mod = 0;
                     86:
1.11      noro       87: static int *lprime;
                     88: int lprime_size;
                     89:
1.1       noro       90: #if PARI
                     91: int paristack = 1<<16;
1.10      noro       92: #define ADDBF addbf
                     93: #define SUBBF subbf
                     94: #define MULBF mulbf
                     95: #define DIVBF divbf
                     96: #define PWRBF pwrbf
                     97: #define CHSGNBF chsgnbf
                     98: #define CMPBF cmpbf
                     99: # else
                    100: #define ADDBF 0
                    101: #define SUBBF 0
                    102: #define MULBF 0
                    103: #define DIVBF 0
                    104: #define PWRBF 0
                    105: #define CHSGNBF 0
                    106: #define CMPBF 0
                    107: #endif
1.1       noro      108:
1.7       saito     109: #if defined(INTERVAL)
                    110: int zerorewrite = 0;
1.12    ! noro      111: void (*addnumt[])() = { addq, addreal, addalg, ADDBF, additvp, additvd, 0, additvf, addcplx, addmi, addlm, addgf2n, addgfpn, addgfs, addgfsn };
        !           112: void (*subnumt[])() = { subq, subreal, subalg, SUBBF, subitvp, subitvd, 0, subitvf, subcplx, submi, sublm, subgf2n, subgfpn, subgfs, subfspn };
        !           113: void (*mulnumt[])() = { mulq, mulreal, mulalg, MULBF, mulitvp, mulitvd, 0, mulitvf, mulcplx, mulmi, mullm, mulgf2n, mulgfpn, mulgfs, mulgfsn };
        !           114: void (*divnumt[])() = { divq, divreal, divalg, DIVBF, divitvp, divitvd, 0, divitvf, divcplx, divmi, divlm, divgf2n, divgfpn, divgfs, divgfsn };
        !           115: void (*pwrnumt[])() = { pwrq, pwrreal, pwralg, PWRBF, pwritvp, pwritvd, 0, pwritvf, pwrcplx, pwrmi, pwrlm, pwrgf2n, pwrgfpn, pwrgfs, pwrgfsn };
        !           116: void (*chsgnnumt[])() = { chsgnq, chsgnreal, chsgnalg, CHSGNBF, chsgnitvp, chsgnitvd, 0, chsgnitvf, chsgncplx, chsgnmi, chsgnlm, chsgngf2n, chsgngfpn, chsgngfs , chsgngfsn};
        !           117: int (*cmpnumt[])() = { cmpq, cmpreal, cmpalg, CMPBF, cmpitvp, cmpitvd, 0, cmpitvf, cmpcplx, cmpmi, cmplm, cmpgf2n, cmpgfpn, cmpgfs, cmpgfsn };
1.7       saito     118: #else
1.12    ! noro      119: void (*addnumt[])() = { addq, addreal, addalg, ADDBF, addcplx, addmi, addlm, addgf2n, addgfpn, addgfs, addgfsn };
        !           120: void (*subnumt[])() = { subq, subreal, subalg, SUBBF, subcplx, submi, sublm, subgf2n, subgfpn, subgfs, subgfsn };
        !           121: void (*mulnumt[])() = { mulq, mulreal, mulalg, MULBF, mulcplx, mulmi, mullm, mulgf2n, mulgfpn, mulgfs, mulgfsn };
        !           122: void (*divnumt[])() = { divq, divreal, divalg, DIVBF, divcplx, divmi, divlm, divgf2n, divgfpn, divgfs, divgfsn };
        !           123: void (*pwrnumt[])() = { pwrq, pwrreal, pwralg, PWRBF, pwrcplx, pwrmi, pwrlm, pwrgf2n, pwrgfpn, pwrgfs, pwrgfsn };
        !           124: void (*chsgnnumt[])() = { chsgnq, chsgnreal, chsgnalg, CHSGNBF, chsgncplx, chsgnmi, chsgnlm, chsgngf2n, chsgngfpn, chsgngfs, chsgngfsn };
        !           125: int (*cmpnumt[])() = { cmpq, cmpreal, cmpalg, CMPBF, cmpcplx, cmpmi, cmplm, cmpgf2n, cmpgfpn, cmpgfs, cmpgfsn };
1.1       noro      126: #endif
                    127:
                    128: double get_current_time();
1.11      noro      129: void init_lprime();
1.1       noro      130:
                    131: void nglob_init() {
                    132:        PL(&oUNIN) = 1; BD(&oUNIN)[0] = 1;
                    133:        PL(&oTWON) = 1; BD(&oTWON)[0] = 2;
                    134:        PL(&oTHREEN) = 1; BD(&oTHREEN)[0] = 3;
                    135:        PL(&oFOURN) = 1; BD(&oFOURN)[0] = 4;
                    136:        PL(&oFIVEN) = 1; BD(&oFIVEN)[0] = 5;
                    137:        PL(&oSIXN) = 1; BD(&oSIXN)[0] = 6;
                    138:        PL(&oSEVENN) = 1; BD(&oSEVENN)[0] = 7;
                    139:        PL(&oEIGHTN) = 1; BD(&oEIGHTN)[0] = 8;
                    140:
                    141:        oONEUP2.w = 1; oONEUP2.b[0] = 1;
                    142:
                    143:        OID(&oUNIQ) = O_N; NID(&oUNIQ) = N_Q;
                    144:        SGN(&oUNIQ) = 1; NM(&oUNIQ) = &oUNIN; DN(&oUNIQ) = 0;
                    145:
                    146:        OID(&oTWOQ) = O_N; NID(&oTWOQ) = N_Q;
                    147:        SGN(&oTWOQ) = 1; NM(&oTWOQ) = &oTWON; DN(&oTWOQ) = 0;
                    148:
                    149:        OID(&oTHREEQ) = O_N; NID(&oTHREEQ) = N_Q;
                    150:        SGN(&oTHREEQ) = 1; NM(&oTHREEQ) = &oTHREEN; DN(&oTHREEQ) = 0;
                    151:
                    152:        OID(&oFOURQ) = O_N; NID(&oFOURQ) = N_Q;
                    153:        SGN(&oFOURQ) = 1; NM(&oFOURQ) = &oFOURN; DN(&oFOURQ) = 0;
                    154:
                    155:        OID(&oFIVEQ) = O_N; NID(&oFIVEQ) = N_Q;
                    156:        SGN(&oFIVEQ) = 1; NM(&oFIVEQ) = &oFIVEN; DN(&oFIVEQ) = 0;
                    157:
                    158:        OID(&oSIXQ) = O_N; NID(&oSIXQ) = N_Q;
                    159:        SGN(&oSIXQ) = 1; NM(&oSIXQ) = &oSIXN; DN(&oSIXQ) = 0;
                    160:
                    161:        OID(&oSEVENQ) = O_N; NID(&oSEVENQ) = N_Q;
                    162:        SGN(&oSEVENQ) = 1; NM(&oSEVENQ) = &oSEVENN; DN(&oSEVENQ) = 0;
                    163:
                    164:        OID(&oEIGHTQ) = O_N; NID(&oEIGHTQ) = N_Q;
                    165:        SGN(&oEIGHTQ) = 1; NM(&oEIGHTQ) = &oEIGHTN; DN(&oEIGHTQ) = 0;
                    166:
                    167:        OID(&oUNIR) = O_R; NM(&oUNIR) = (P)&oUNIQ; DN(&oUNIR) = (P)&oUNIQ; oUNIR.reduced = 1;
                    168:        OID(&oUNIMQ) = O_N; NID(&oUNIMQ) = N_M; CONT(&oUNIMQ) = 1;
                    169:        OID(&oUNILM) = O_N; NID(&oUNILM) = N_LM; BDY(&oUNILM) = ONEN;
                    170:        OID(&oIU) = O_N; NID(&oIU) = N_C; oIU.r = 0; oIU.i = (Num)ONE;
                    171:
                    172:        MKLM(&oTHREEN,THREE_LM);
                    173:        MKLM(&oFOURN,FOUR_LM);
                    174:        MKLM(&oEIGHTN,EIGHT_LM);
                    175:
                    176:        OID(&oVOID) = O_VOID;
                    177:
                    178: /* moved to parse/main.c */
                    179: #if 0
                    180: #if PARI
                    181:        risa_pari_init();
                    182: #endif
                    183:        srandom((int)get_current_time());
                    184: #endif
                    185:        init_up2_tab();
1.11      noro      186:
                    187:        init_lprime();
1.1       noro      188: }
                    189:
                    190: extern double gctime;
                    191: double suspend_start;
                    192: double suspended_time=0;
                    193:
                    194: void get_eg(p)
                    195: struct oEGT *p;
                    196: {
                    197:        p->exectime = get_clock() - gctime - suspended_time; p->gctime = gctime;
                    198: }
                    199:
                    200: void init_eg(eg)
                    201: struct oEGT *eg;
                    202: {
                    203:        bzero((char *)eg,sizeof(struct oEGT));
                    204: }
                    205:
                    206: void add_eg(base,start,end)
                    207: struct oEGT *base,*start,*end;
                    208: {
                    209:        base->exectime += end->exectime - start->exectime;
                    210:        base->gctime += end->gctime - start->gctime;
                    211: }
                    212:
                    213: void print_eg(item,eg)
                    214: char *item;
                    215: struct oEGT *eg;
                    216: {
                    217:        printf("%s=(%.4g,%.4g)",item,eg->exectime,eg->gctime);
                    218: }
                    219:
                    220: void print_split_eg(start,end)
                    221: struct oEGT *start,*end;
                    222: {
                    223:        struct oEGT base;
                    224:
                    225:        init_eg(&base); add_eg(&base,start,end);
                    226:        printf("(%.4g,%.4g)",base.exectime,base.gctime);
                    227: }
                    228:
                    229: void print_split_e(start,end)
                    230: struct oEGT *start,*end;
                    231: {
                    232:        struct oEGT base;
                    233:
                    234:        init_eg(&base); add_eg(&base,start,end);
                    235:        printf("(%.4g)",base.exectime);
                    236: }
                    237:
                    238: void suspend_timer() {
                    239:        suspend_start = get_clock();
                    240: }
                    241:
                    242: void resume_timer() {
                    243:        suspended_time += get_clock()-suspend_start;
                    244: }
                    245:
                    246: extern int lm_lazy, up_lazy;
1.6       noro      247: extern int GC_dont_gc;
                    248: extern int do_weyl;
1.8       noro      249: extern int dp_fcoeffs;
1.1       noro      250:
                    251: void reset_engine() {
1.8       noro      252:        lm_lazy = 0;
                    253:        up_lazy = 0;
1.6       noro      254:        do_weyl = 0;
1.8       noro      255:        dp_fcoeffs = 0;
1.1       noro      256:        GC_dont_gc = 0;
                    257: }
                    258:
                    259: unsigned int get_asir_version() {
                    260:        return ASIR_VERSION;
1.4       noro      261: }
1.9       noro      262:
                    263: char *get_asir_distribution() {
                    264:        return ASIR_DISTRIBUTION;
                    265: }
                    266:
1.4       noro      267:
                    268: void create_error(ERR *err,unsigned int serial,char *msg)
                    269: {
                    270:        int len;
                    271:        USINT ui;
                    272:        NODE n,n1;
                    273:        LIST list;
                    274:        char *msg1;
                    275:        STRING errmsg;
                    276:
                    277:        MKUSINT(ui,serial);
                    278:        len = strlen(msg);
                    279:        msg1 = (char *)MALLOC(len+1);
                    280:        strcpy(msg1,msg);
                    281:        MKSTR(errmsg,msg1);
                    282:        MKNODE(n1,errmsg,0); MKNODE(n,ui,n1); MKLIST(list,n);
                    283:        MKERR(*err,list);
1.11      noro      284: }
                    285:
                    286: void init_lprime()
                    287: {
                    288:        int s,i;
                    289:
                    290:        s = sizeof(lprime_init);
                    291:        lprime = (int *)GC_malloc_atomic(s);
                    292:        lprime_size = s/sizeof(int);
                    293:        for ( i = 0; i < lprime_size; i++ )
                    294:                lprime[i] = lprime_init[lprime_size-i-1];
                    295: }
                    296:
                    297: void create_new_lprimes(int);
                    298:
                    299: int get_lprime(index)
                    300: {
                    301:        if ( index >= lprime_size )
                    302:                create_new_lprimes(index);
                    303:        return lprime[index];
                    304: }
                    305:
                    306: void create_new_lprimes(index)
                    307: int index;
                    308: {
                    309:        int count,p,i,j,d;
                    310:
                    311:        if ( index < lprime_size )
                    312:                return;
                    313:        count = index-lprime_size+1;
                    314:        if ( count < 256 )
                    315:                count = 256;
                    316:        lprime = (int *)GC_realloc(lprime,(lprime_size+count)*sizeof(int));
                    317:        p = lprime[lprime_size-1]+2;
                    318:        for ( i = 0; i < count; p += 2 ) {
                    319:                for ( j = 0; d = sprime[j]; j++ ) {
                    320:                        if ( d*d > p ) {
                    321:                                lprime[i+lprime_size] = p;
                    322:                                i++;
                    323:                                break;
                    324:                        }
                    325:                        if ( !(p%d) )
                    326:                                break;
                    327:                }
                    328:        }
                    329:        lprime_size += count;
1.1       noro      330: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>