Annotation of OpenXM_contrib2/asir2018/engine/init.c, Revision 1.3
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.3 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2018/engine/init.c,v 1.2 2018/09/27 02:39:37 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:
252: void init_lprime()
253: {
254: int s,i;
255:
256: s = sizeof(lprime_init);
257: lprime = (int *)MALLOC_ATOMIC(s);
258: lprime_size = s/sizeof(int);
259: for ( i = 0; i < lprime_size; i++ )
260: lprime[i] = lprime_init[lprime_size-i-1];
261: }
262:
263: void create_new_lprimes(int);
264:
265: int get_lprime(int index)
266: {
267: if ( index >= lprime_size )
268: create_new_lprimes(index);
269: return lprime[index];
270: }
271:
272: void create_new_lprimes(int index)
273: {
274: int count,p,i,j,d;
275:
276: if ( index < lprime_size )
277: return;
278: count = index-lprime_size+1;
279: if ( count < 256 )
280: count = 256;
281: lprime = (int *)GC_realloc(lprime,(lprime_size+count)*sizeof(int));
282: p = lprime[lprime_size-1]+2;
283: for ( i = 0; i < count; p += 2 ) {
284: for ( j = 0; (d = sprime[j]) != 0; j++ ) {
285: if ( d*d > p ) {
286: lprime[i+lprime_size] = p;
287: i++;
288: break;
289: }
290: if ( !(p%d) )
291: break;
292: }
293: }
294: lprime_size += count;
295: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>