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

Annotation of OpenXM_contrib2/asir2018/engine/init.c, Revision 1.4

1.1       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
                     26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
                     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.4     ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2018/engine/init.c,v 1.3 2018/09/28 08:20:28 noro Exp $
1.1       noro       49: */
                     50: #include "ca.h"
                     51: #include "parse.h"
                     52: #include "version.h"
                     53: #include "prime.h"
                     54:
                     55: struct oZ oUNIQ,oTWOQ,oTHREEQ,oFOURQ,oFIVEQ,oSIXQ,oSEVENQ,oEIGHTQ;
                     56: struct oLM oUNILM,oTHREELM,oFOURLM,oEIGHTLM;
                     57:
                     58: struct oUP2 oONEUP2;
                     59:
                     60: Z ONE = &oUNIQ;
                     61: Z TWO = &oTWOQ;
                     62: Z THREE = &oTHREEQ;
                     63: Z FOUR = &oFOURQ;
                     64: Z FIVE = &oFIVEQ;
                     65: Z SIX = &oSIXQ;
                     66: Z SEVEN = &oSEVENQ;
                     67: Z EIGHT = &oEIGHTQ;
                     68:
                     69: LM ONELM = &oUNILM;
                     70: LM THREE_LM = &oTHREELM;
                     71: LM FOUR_LM = &oFOURLM;
                     72: LM EIGHT_LM = &oEIGHTLM;
                     73:
                     74: struct oR oUNIR;
                     75: struct oMQ oUNIMQ;
                     76: struct oC oIU;
                     77: struct oUSINT oVOID;
                     78:
                     79: MQ ONEM = &oUNIMQ;
                     80:
                     81: UP2 ONEUP2 = &oONEUP2;
                     82: C IU = &oIU;
                     83: USINT VOIDobj = &oVOID;
                     84:
                     85: int bigfloat;
                     86: int evalef = 0;
                     87: int nez = 1;
                     88: int current_mod = 0;
                     89: int StrassenSize = 0;
                     90: int outputstyle = 0;
                     91: int Itvplot = 33;
                     92:
                     93: static int *lprime;
                     94: static int lprime_size;
                     95:
                     96: #define ADDBF addbf
                     97: #define SUBBF subbf
                     98: #define MULBF mulbf
                     99: #define DIVBF divbf
                    100: #define PWRBF pwrbf
                    101: #define CHSGNBF chsgnbf
                    102: #define CMPBF cmpbf
                    103:
                    104: #if defined(INTERVAL)
                    105: int zerorewrite = 0;
                    106: void (*addnumt[])() = { addq, addreal, addalg, ADDBF, 0, additvp, additvd, 0, additvf, addcplx, addmi, addlm, addgf2n, addgfpn, addgfs, addgfsn, adddalg };
                    107: void (*subnumt[])() = { subq, subreal, subalg, SUBBF, 0, subitvp, subitvd, 0, subitvf, subcplx, submi, sublm, subgf2n, subgfpn, subgfs, subgfsn, subdalg };
                    108: void (*mulnumt[])() = { mulq, mulreal, mulalg, MULBF, 0, mulitvp, mulitvd, 0, mulitvf, mulcplx, mulmi, mullm, mulgf2n, mulgfpn, mulgfs, mulgfsn, muldalg };
                    109: void (*divnumt[])() = { divq, divreal, divalg, DIVBF, 0, divitvp, divitvd, 0, divitvf, divcplx, divmi, divlm, divgf2n, divgfpn, divgfs, divgfsn, divdalg };
                    110: void (*pwrnumt[])() = { pwrq, pwrreal, pwralg, PWRBF, 0, pwritvp, pwritvd, 0, pwritvf, pwrcplx, pwrmi, pwrlm, pwrgf2n, pwrgfpn, pwrgfs, pwrgfsn, pwrdalg };
                    111: void (*chsgnnumt[])() = { chsgnq, chsgnreal, chsgnalg, CHSGNBF, 0, chsgnitvp, chsgnitvd, 0, chsgnitvf, chsgncplx, chsgnmi, chsgnlm, chsgngf2n, chsgngfpn, chsgngfs , chsgngfsn, chsgndalg};
                    112: int (*cmpnumt[])() = { cmpq, cmpreal, cmpalg, CMPBF, 0, cmpitvp, cmpitvd, 0, cmpitvf, cmpcplx, cmpmi, cmplm, cmpgf2n, cmpgfpn, cmpgfs, cmpgfsn, cmpdalg };
                    113: #else
                    114: void (*addnumt[])() = { addq, addreal, addalg, ADDBF, addcplx, addmi, addlm, addgf2n, addgfpn, addgfs, addgfsn, adddalg };
                    115: void (*subnumt[])() = { subq, subreal, subalg, SUBBF, subcplx, submi, sublm, subgf2n, subgfpn, subgfs, subgfsn, subdalg };
                    116: void (*mulnumt[])() = { mulq, mulreal, mulalg, MULBF, mulcplx, mulmi, mullm, mulgf2n, mulgfpn, mulgfs, mulgfsn, muldalg };
                    117: void (*divnumt[])() = { divq, divreal, divalg, DIVBF, divcplx, divmi, divlm, divgf2n, divgfpn, divgfs, divgfsn, divdalg };
                    118: void (*pwrnumt[])() = { pwrq, pwrreal, pwralg, PWRBF, pwrcplx, pwrmi, pwrlm, pwrgf2n, pwrgfpn, pwrgfs, pwrgfsn, pwrdalg };
                    119: void (*chsgnnumt[])() = { chsgnq, chsgnreal, chsgnalg, CHSGNBF, chsgncplx, chsgnmi, chsgnlm, chsgngf2n, chsgngfpn, chsgngfs, chsgngfsn, chsgndalg };
                    120: int (*cmpnumt[])() = { cmpq, cmpreal, cmpalg, CMPBF, cmpcplx, cmpmi, cmplm, cmpgf2n, cmpgfpn, cmpgfs, cmpgfsn, cmpdalg };
                    121: #endif
                    122:
                    123: double get_current_time();
                    124: void init_lprime();
                    125:
                    126: void nglob_init() {
                    127:   oONEUP2.w = 1; oONEUP2.b[0] = 1;
                    128:
1.3       noro      129:   STOZ0(1,&oUNIQ);
                    130:   STOZ0(2,&oTWOQ);
                    131:   STOZ0(3,&oTHREEQ);
                    132:   STOZ0(4,&oFOURQ);
                    133:   STOZ0(5,&oFIVEQ);
                    134:   STOZ0(6,&oSIXQ);
                    135:   STOZ0(7,&oSEVENQ);
                    136:   STOZ0(8,&oEIGHTQ);
1.1       noro      137:
                    138:   STOLM0(1,&oUNILM);
                    139:   STOLM0(3,&oTHREELM);
                    140:   STOLM0(4,&oFOURLM);
                    141:   STOLM0(8,&oEIGHTLM);
                    142:
                    143:   OID(&oUNIR) = O_R; NM(&oUNIR) = (P)&oUNIQ; DN(&oUNIR) = (P)&oUNIQ; oUNIR.reduced = 1;
                    144:   OID(&oUNIMQ) = O_N; NID(&oUNIMQ) = N_M; CONT(&oUNIMQ) = 1;
                    145:   OID(&oIU) = O_N; NID(&oIU) = N_C; oIU.r = 0; oIU.i = (Num)ONE;
                    146:
                    147:   OID(&oVOID) = O_VOID;
                    148:
                    149: /* moved to parse/main.c */
                    150: #if 0
                    151: #if defined(PARI)
                    152:   risa_pari_init();
                    153: #endif
                    154:   srandom((int)get_current_time());
                    155: #endif
                    156:   init_up2_tab();
                    157:
                    158:   init_lprime();
                    159:   init_gmpq();
                    160: }
                    161:
                    162: double suspend_start;
                    163: double suspended_time=0;
                    164:
                    165: void get_eg(struct oEGT *p)
                    166: {
1.2       noro      167:   p->exectime = get_clock()-suspended_time; p->gctime = 0;
1.1       noro      168: }
                    169:
                    170: void init_eg(struct oEGT *eg)
                    171: {
                    172:   bzero((char *)eg,sizeof(struct oEGT));
                    173: }
                    174:
                    175: void add_eg(struct oEGT *base,struct oEGT *start,struct oEGT *end)
                    176: {
                    177:   base->exectime += end->exectime - start->exectime;
                    178: }
                    179:
                    180: void print_eg(char *item,struct oEGT *eg)
                    181: {
1.2       noro      182:   printf("%s=(%.4g)",item,eg->exectime);
1.1       noro      183: }
                    184:
                    185: void print_split_eg(struct oEGT *start,struct oEGT *end)
                    186: {
                    187:   struct oEGT base;
                    188:
                    189:   init_eg(&base); add_eg(&base,start,end);
1.2       noro      190:   printf("(%.4g)",base.exectime);
1.1       noro      191: }
                    192:
                    193: void print_split_e(struct oEGT *start,struct oEGT *end)
                    194: {
                    195:   struct oEGT base;
                    196:
                    197:   init_eg(&base); add_eg(&base,start,end);
                    198:   printf("(%.4g)",base.exectime);
                    199: }
                    200:
                    201: void suspend_timer() {
                    202:   suspend_start = get_clock();
                    203: }
                    204:
                    205: void resume_timer() {
                    206:   suspended_time += get_clock()-suspend_start;
                    207: }
                    208:
                    209: extern int lm_lazy, up_lazy;
                    210: extern int GC_dont_gc;
                    211: extern int do_weyl;
                    212: extern int dp_fcoeffs;
                    213:
                    214: void reset_engine() {
                    215:   lm_lazy = 0;
                    216:   up_lazy = 0;
                    217:   do_weyl = 0;
                    218:   dp_fcoeffs = 0;
                    219:   GC_dont_gc = 0;
                    220: }
                    221:
                    222: unsigned int get_asir_version() {
                    223:   return ASIR_VERSION;
                    224: }
                    225:
                    226: char *get_asir_distribution() {
                    227:   return ASIR_DISTRIBUTION;
                    228: }
                    229:
                    230:
                    231: void create_error(ERR *err,unsigned int serial,char *msg,LIST trace)
                    232: {
                    233:   int len;
                    234:   USINT ui,notsupp;
                    235:   NODE n,n1;
                    236:   LIST list;
                    237:   char *msg1;
                    238:   STRING errmsg;
                    239:
                    240:   MKUSINT(ui,serial);
                    241:   MKUSINT(notsupp,-1);
                    242:   len = strlen(msg);
                    243:   msg1 = (char *)MALLOC(len+1);
                    244:   strcpy(msg1,msg);
                    245:   MKSTR(errmsg,msg1);
                    246:   if ( !trace )
                    247:     MKLIST(trace,0);
                    248:   n = mknode(4,ui,notsupp,errmsg,trace); MKLIST(list,n);
                    249:   MKERR(*err,list);
                    250: }
                    251:
1.4     ! noro      252: static mp_limb_t *lprime64;
        !           253: static int lprime64_size;
        !           254:
1.1       noro      255: void init_lprime()
                    256: {
                    257:   int s,i;
                    258:
                    259:   s = sizeof(lprime_init);
                    260:   lprime = (int *)MALLOC_ATOMIC(s);
                    261:   lprime_size = s/sizeof(int);
                    262:   for ( i = 0; i < lprime_size; i++ )
                    263:     lprime[i] = lprime_init[lprime_size-i-1];
1.4     ! noro      264:
        !           265: #if SIZEOF_LONG == 8
        !           266:   s = sizeof(lprime64_init);
        !           267:   lprime64 = (mp_limb_t *)MALLOC_ATOMIC(s);
        !           268:   lprime64_size = s/sizeof(mp_limb_t);
        !           269:   for ( i = 0; i < lprime64_size; i++ )
        !           270:     lprime64[i] = lprime64_init[lprime64_size-i-1];
        !           271: #endif
1.1       noro      272: }
                    273:
                    274: void create_new_lprimes(int);
1.4     ! noro      275: void create_new_lprimes64(int);
1.1       noro      276:
                    277: int get_lprime(int index)
                    278: {
                    279:   if ( index >= lprime_size )
                    280:     create_new_lprimes(index);
                    281:   return lprime[index];
                    282: }
                    283:
1.4     ! noro      284: #if SIZEOF_LONG == 8
        !           285: mp_limb_t get_lprime64(int index)
        !           286: {
        !           287:   if ( index >= lprime64_size )
        !           288:     create_new_lprimes64(index);
        !           289:   return lprime64[index];
        !           290: }
        !           291: #endif
        !           292:
1.1       noro      293: void create_new_lprimes(int index)
                    294: {
                    295:   int count,p,i,j,d;
                    296:
                    297:   if ( index < lprime_size )
                    298:     return;
                    299:   count = index-lprime_size+1;
                    300:   if ( count < 256 )
                    301:     count = 256;
                    302:   lprime = (int *)GC_realloc(lprime,(lprime_size+count)*sizeof(int));
                    303:   p = lprime[lprime_size-1]+2;
                    304:   for ( i = 0; i < count; p += 2 ) {
                    305:     for ( j = 0; (d = sprime[j]) != 0; j++ ) {
                    306:       if ( d*d > p ) {
                    307:         lprime[i+lprime_size] = p;
                    308:         i++;
                    309:         break;
                    310:       }
                    311:       if ( !(p%d) )
                    312:         break;
                    313:     }
                    314:   }
                    315:   lprime_size += count;
                    316: }
1.4     ! noro      317:
        !           318: mp_limb_t nextprime(mp_limb_t a)
        !           319: {
        !           320:   static FUNC f=0;
        !           321:   Z z,r;
        !           322:
        !           323:   if ( f == 0 ) mkparif("nextprime",&f);
        !           324:   STOZ(a,z);
        !           325:   r = (Z)evalparif(f,mknode(1,z));
        !           326:   return ZTOS(r);
        !           327: }
        !           328:
        !           329: void create_new_lprimes64(int index)
        !           330: {
        !           331:   int count,j;
        !           332:   mp_limb_t p;
        !           333:
        !           334:   if ( index < lprime64_size )
        !           335:     return;
        !           336:   count = index-lprime64_size+1;
        !           337:   if ( count < 256 )
        !           338:     count = 256;
        !           339:   lprime64 = (mp_limb_t *)GC_realloc(lprime64,(lprime64_size+count)*sizeof(mp_limb_t));
        !           340:   for ( p = lprime64[lprime64_size-1], j = 0; j < count; j++ ) {
        !           341:     p = nextprime(p+1);
        !           342:     lprime64[lprime64_size+j] = p;
        !           343:   }
        !           344:   lprime64_size += count;
        !           345: }

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