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