Annotation of OpenXM_contrib2/asir2018/engine/init.c, Revision 1.1
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: *
! 48: * $OpenXM$
! 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:
! 129: STOQ0(1,&oUNIQ);
! 130: STOQ0(2,&oTWOQ);
! 131: STOQ0(3,&oTHREEQ);
! 132: STOQ0(4,&oFOURQ);
! 133: STOQ0(5,&oFIVEQ);
! 134: STOQ0(6,&oSIXQ);
! 135: STOQ0(7,&oSEVENQ);
! 136: STOQ0(8,&oEIGHTQ);
! 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: extern double GC_get_gctime();
! 163: double suspend_start;
! 164: double suspended_time=0;
! 165:
! 166: void get_eg(struct oEGT *p)
! 167: {
! 168: double gctime = GC_get_gctime();
! 169: p->exectime = get_clock() - gctime - suspended_time; p->gctime = gctime;
! 170: }
! 171:
! 172: void init_eg(struct oEGT *eg)
! 173: {
! 174: bzero((char *)eg,sizeof(struct oEGT));
! 175: }
! 176:
! 177: void add_eg(struct oEGT *base,struct oEGT *start,struct oEGT *end)
! 178: {
! 179: base->exectime += end->exectime - start->exectime;
! 180: base->gctime += end->gctime - start->gctime;
! 181: }
! 182:
! 183: void print_eg(char *item,struct oEGT *eg)
! 184: {
! 185: printf("%s=(%.4g,%.4g)",item,eg->exectime,eg->gctime);
! 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);
! 193: printf("(%.4g,%.4g)",base.exectime,base.gctime);
! 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:
! 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];
! 264: }
! 265:
! 266: void create_new_lprimes(int);
! 267:
! 268: int get_lprime(int index)
! 269: {
! 270: if ( index >= lprime_size )
! 271: create_new_lprimes(index);
! 272: return lprime[index];
! 273: }
! 274:
! 275: void create_new_lprimes(int index)
! 276: {
! 277: int count,p,i,j,d;
! 278:
! 279: if ( index < lprime_size )
! 280: return;
! 281: count = index-lprime_size+1;
! 282: if ( count < 256 )
! 283: count = 256;
! 284: lprime = (int *)GC_realloc(lprime,(lprime_size+count)*sizeof(int));
! 285: p = lprime[lprime_size-1]+2;
! 286: for ( i = 0; i < count; p += 2 ) {
! 287: for ( j = 0; (d = sprime[j]) != 0; j++ ) {
! 288: if ( d*d > p ) {
! 289: lprime[i+lprime_size] = p;
! 290: i++;
! 291: break;
! 292: }
! 293: if ( !(p%d) )
! 294: break;
! 295: }
! 296: }
! 297: lprime_size += count;
! 298: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>