[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.5

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.5     ! kondoh     48:  * $OpenXM: OpenXM_contrib2/asir2018/engine/init.c,v 1.4 2018/10/01 05:49:06 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;
1.5     ! kondoh    106: int zerorewriteCount = 0;
        !           107: //                     N_Q,  N_R,      N_A,    N_B, N4, N_IP,  N_IDouble,N_IQ, N_IBF, N_C,     N_M    N_LM, N_GF2N,   N_GFPN, N_GFS,  N_GFSN,  N_DA,   N_GZ, N_GQ, N_PARIB
1.1       noro      108: void (*addnumt[])() = { addq, addreal, addalg, ADDBF, 0, additvp, additvd, 0, additvf, addcplx, addmi, addlm, addgf2n, addgfpn, addgfs, addgfsn, adddalg };
                    109: void (*subnumt[])() = { subq, subreal, subalg, SUBBF, 0, subitvp, subitvd, 0, subitvf, subcplx, submi, sublm, subgf2n, subgfpn, subgfs, subgfsn, subdalg };
                    110: void (*mulnumt[])() = { mulq, mulreal, mulalg, MULBF, 0, mulitvp, mulitvd, 0, mulitvf, mulcplx, mulmi, mullm, mulgf2n, mulgfpn, mulgfs, mulgfsn, muldalg };
                    111: void (*divnumt[])() = { divq, divreal, divalg, DIVBF, 0, divitvp, divitvd, 0, divitvf, divcplx, divmi, divlm, divgf2n, divgfpn, divgfs, divgfsn, divdalg };
                    112: void (*pwrnumt[])() = { pwrq, pwrreal, pwralg, PWRBF, 0, pwritvp, pwritvd, 0, pwritvf, pwrcplx, pwrmi, pwrlm, pwrgf2n, pwrgfpn, pwrgfs, pwrgfsn, pwrdalg };
                    113: void (*chsgnnumt[])() = { chsgnq, chsgnreal, chsgnalg, CHSGNBF, 0, chsgnitvp, chsgnitvd, 0, chsgnitvf, chsgncplx, chsgnmi, chsgnlm, chsgngf2n, chsgngfpn, chsgngfs , chsgngfsn, chsgndalg};
                    114: int (*cmpnumt[])() = { cmpq, cmpreal, cmpalg, CMPBF, 0, cmpitvp, cmpitvd, 0, cmpitvf, cmpcplx, cmpmi, cmplm, cmpgf2n, cmpgfpn, cmpgfs, cmpgfsn, cmpdalg };
                    115: #else
1.5     ! kondoh    116: //                     N_Q,  N_R,      N_A,    N_B,   N_C,     N_M,   N_LM, N_GF2N,   N_GFPN, N_GFS,  N_GFSN,  N_DA,   N_GZ, N_GQ, N_PARIB
1.1       noro      117: void (*addnumt[])() = { addq, addreal, addalg, ADDBF, addcplx, addmi, addlm, addgf2n, addgfpn, addgfs, addgfsn, adddalg };
                    118: void (*subnumt[])() = { subq, subreal, subalg, SUBBF, subcplx, submi, sublm, subgf2n, subgfpn, subgfs, subgfsn, subdalg };
                    119: void (*mulnumt[])() = { mulq, mulreal, mulalg, MULBF, mulcplx, mulmi, mullm, mulgf2n, mulgfpn, mulgfs, mulgfsn, muldalg };
                    120: void (*divnumt[])() = { divq, divreal, divalg, DIVBF, divcplx, divmi, divlm, divgf2n, divgfpn, divgfs, divgfsn, divdalg };
                    121: void (*pwrnumt[])() = { pwrq, pwrreal, pwralg, PWRBF, pwrcplx, pwrmi, pwrlm, pwrgf2n, pwrgfpn, pwrgfs, pwrgfsn, pwrdalg };
                    122: void (*chsgnnumt[])() = { chsgnq, chsgnreal, chsgnalg, CHSGNBF, chsgncplx, chsgnmi, chsgnlm, chsgngf2n, chsgngfpn, chsgngfs, chsgngfsn, chsgndalg };
                    123: int (*cmpnumt[])() = { cmpq, cmpreal, cmpalg, CMPBF, cmpcplx, cmpmi, cmplm, cmpgf2n, cmpgfpn, cmpgfs, cmpgfsn, cmpdalg };
                    124: #endif
                    125:
                    126: double get_current_time();
                    127: void init_lprime();
                    128:
                    129: void nglob_init() {
                    130:   oONEUP2.w = 1; oONEUP2.b[0] = 1;
                    131:
1.3       noro      132:   STOZ0(1,&oUNIQ);
                    133:   STOZ0(2,&oTWOQ);
                    134:   STOZ0(3,&oTHREEQ);
                    135:   STOZ0(4,&oFOURQ);
                    136:   STOZ0(5,&oFIVEQ);
                    137:   STOZ0(6,&oSIXQ);
                    138:   STOZ0(7,&oSEVENQ);
                    139:   STOZ0(8,&oEIGHTQ);
1.1       noro      140:
                    141:   STOLM0(1,&oUNILM);
                    142:   STOLM0(3,&oTHREELM);
                    143:   STOLM0(4,&oFOURLM);
                    144:   STOLM0(8,&oEIGHTLM);
                    145:
                    146:   OID(&oUNIR) = O_R; NM(&oUNIR) = (P)&oUNIQ; DN(&oUNIR) = (P)&oUNIQ; oUNIR.reduced = 1;
                    147:   OID(&oUNIMQ) = O_N; NID(&oUNIMQ) = N_M; CONT(&oUNIMQ) = 1;
                    148:   OID(&oIU) = O_N; NID(&oIU) = N_C; oIU.r = 0; oIU.i = (Num)ONE;
                    149:
                    150:   OID(&oVOID) = O_VOID;
                    151:
                    152: /* moved to parse/main.c */
                    153: #if 0
                    154: #if defined(PARI)
                    155:   risa_pari_init();
                    156: #endif
                    157:   srandom((int)get_current_time());
                    158: #endif
                    159:   init_up2_tab();
                    160:
                    161:   init_lprime();
                    162:   init_gmpq();
                    163: }
                    164:
                    165: double suspend_start;
                    166: double suspended_time=0;
                    167:
                    168: void get_eg(struct oEGT *p)
                    169: {
1.2       noro      170:   p->exectime = get_clock()-suspended_time; p->gctime = 0;
1.1       noro      171: }
                    172:
                    173: void init_eg(struct oEGT *eg)
                    174: {
                    175:   bzero((char *)eg,sizeof(struct oEGT));
                    176: }
                    177:
                    178: void add_eg(struct oEGT *base,struct oEGT *start,struct oEGT *end)
                    179: {
                    180:   base->exectime += end->exectime - start->exectime;
                    181: }
                    182:
                    183: void print_eg(char *item,struct oEGT *eg)
                    184: {
1.2       noro      185:   printf("%s=(%.4g)",item,eg->exectime);
1.1       noro      186: }
                    187:
                    188: void print_split_eg(struct oEGT *start,struct oEGT *end)
                    189: {
                    190:   struct oEGT base;
                    191:
                    192:   init_eg(&base); add_eg(&base,start,end);
1.2       noro      193:   printf("(%.4g)",base.exectime);
1.1       noro      194: }
                    195:
                    196: void print_split_e(struct oEGT *start,struct oEGT *end)
                    197: {
                    198:   struct oEGT base;
                    199:
                    200:   init_eg(&base); add_eg(&base,start,end);
                    201:   printf("(%.4g)",base.exectime);
                    202: }
                    203:
                    204: void suspend_timer() {
                    205:   suspend_start = get_clock();
                    206: }
                    207:
                    208: void resume_timer() {
                    209:   suspended_time += get_clock()-suspend_start;
                    210: }
                    211:
                    212: extern int lm_lazy, up_lazy;
                    213: extern int GC_dont_gc;
                    214: extern int do_weyl;
                    215: extern int dp_fcoeffs;
                    216:
                    217: void reset_engine() {
                    218:   lm_lazy = 0;
                    219:   up_lazy = 0;
                    220:   do_weyl = 0;
                    221:   dp_fcoeffs = 0;
                    222:   GC_dont_gc = 0;
                    223: }
                    224:
                    225: unsigned int get_asir_version() {
                    226:   return ASIR_VERSION;
                    227: }
                    228:
                    229: char *get_asir_distribution() {
                    230:   return ASIR_DISTRIBUTION;
                    231: }
                    232:
                    233:
                    234: void create_error(ERR *err,unsigned int serial,char *msg,LIST trace)
                    235: {
                    236:   int len;
                    237:   USINT ui,notsupp;
                    238:   NODE n,n1;
                    239:   LIST list;
                    240:   char *msg1;
                    241:   STRING errmsg;
                    242:
                    243:   MKUSINT(ui,serial);
                    244:   MKUSINT(notsupp,-1);
                    245:   len = strlen(msg);
                    246:   msg1 = (char *)MALLOC(len+1);
                    247:   strcpy(msg1,msg);
                    248:   MKSTR(errmsg,msg1);
                    249:   if ( !trace )
                    250:     MKLIST(trace,0);
                    251:   n = mknode(4,ui,notsupp,errmsg,trace); MKLIST(list,n);
                    252:   MKERR(*err,list);
                    253: }
                    254:
1.4       noro      255: static mp_limb_t *lprime64;
                    256: static int lprime64_size;
                    257:
1.1       noro      258: void init_lprime()
                    259: {
                    260:   int s,i;
                    261:
                    262:   s = sizeof(lprime_init);
                    263:   lprime = (int *)MALLOC_ATOMIC(s);
                    264:   lprime_size = s/sizeof(int);
                    265:   for ( i = 0; i < lprime_size; i++ )
                    266:     lprime[i] = lprime_init[lprime_size-i-1];
1.4       noro      267:
                    268: #if SIZEOF_LONG == 8
                    269:   s = sizeof(lprime64_init);
                    270:   lprime64 = (mp_limb_t *)MALLOC_ATOMIC(s);
                    271:   lprime64_size = s/sizeof(mp_limb_t);
                    272:   for ( i = 0; i < lprime64_size; i++ )
                    273:     lprime64[i] = lprime64_init[lprime64_size-i-1];
                    274: #endif
1.1       noro      275: }
                    276:
                    277: void create_new_lprimes(int);
1.4       noro      278: void create_new_lprimes64(int);
1.1       noro      279:
                    280: int get_lprime(int index)
                    281: {
                    282:   if ( index >= lprime_size )
                    283:     create_new_lprimes(index);
                    284:   return lprime[index];
                    285: }
                    286:
1.4       noro      287: #if SIZEOF_LONG == 8
                    288: mp_limb_t get_lprime64(int index)
                    289: {
                    290:   if ( index >= lprime64_size )
                    291:     create_new_lprimes64(index);
                    292:   return lprime64[index];
                    293: }
                    294: #endif
                    295:
1.1       noro      296: void create_new_lprimes(int index)
                    297: {
                    298:   int count,p,i,j,d;
                    299:
                    300:   if ( index < lprime_size )
                    301:     return;
                    302:   count = index-lprime_size+1;
                    303:   if ( count < 256 )
                    304:     count = 256;
                    305:   lprime = (int *)GC_realloc(lprime,(lprime_size+count)*sizeof(int));
                    306:   p = lprime[lprime_size-1]+2;
                    307:   for ( i = 0; i < count; p += 2 ) {
                    308:     for ( j = 0; (d = sprime[j]) != 0; j++ ) {
                    309:       if ( d*d > p ) {
                    310:         lprime[i+lprime_size] = p;
                    311:         i++;
                    312:         break;
                    313:       }
                    314:       if ( !(p%d) )
                    315:         break;
                    316:     }
                    317:   }
                    318:   lprime_size += count;
                    319: }
1.4       noro      320:
                    321: mp_limb_t nextprime(mp_limb_t a)
                    322: {
                    323:   static FUNC f=0;
                    324:   Z z,r;
                    325:
                    326:   if ( f == 0 ) mkparif("nextprime",&f);
                    327:   STOZ(a,z);
                    328:   r = (Z)evalparif(f,mknode(1,z));
                    329:   return ZTOS(r);
                    330: }
                    331:
                    332: void create_new_lprimes64(int index)
                    333: {
                    334:   int count,j;
                    335:   mp_limb_t p;
                    336:
                    337:   if ( index < lprime64_size )
                    338:     return;
                    339:   count = index-lprime64_size+1;
                    340:   if ( count < 256 )
                    341:     count = 256;
                    342:   lprime64 = (mp_limb_t *)GC_realloc(lprime64,(lprime64_size+count)*sizeof(mp_limb_t));
                    343:   for ( p = lprime64[lprime64_size-1], j = 0; j < count; j++ ) {
                    344:     p = nextprime(p+1);
                    345:     lprime64[lprime64_size+j] = p;
                    346:   }
                    347:   lprime64_size += count;
                    348: }

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