=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/engine/Mgfs.c,v retrieving revision 1.12 retrieving revision 1.16 diff -u -p -r1.12 -r1.16 --- OpenXM_contrib2/asir2000/engine/Mgfs.c 2002/01/13 07:11:46 1.12 +++ OpenXM_contrib2/asir2000/engine/Mgfs.c 2004/07/30 07:34:40 1.16 @@ -1,7 +1,9 @@ -/* $OpenXM: OpenXM_contrib2/asir2000/engine/Mgfs.c,v 1.11 2001/10/09 01:36:10 noro Exp $ */ +/* $OpenXM: OpenXM_contrib2/asir2000/engine/Mgfs.c,v 1.15 2002/12/18 06:15:40 noro Exp $ */ #include "ca.h" +#include "inline.h" +extern int current_gfs_p; extern int up_kara_mag, current_gfs_q1; extern int *current_gfs_plus1; @@ -21,6 +23,18 @@ INLINE int _ADDSF(int a,int b) return a; a = IFTOF(a); b = IFTOF(b); + + if ( !current_gfs_ntoi ) { + a = a+b-current_gfs_q; + if ( a == 0 ) + return 0; + else { + if ( a < 0 ) + a += current_gfs_q; + return FTOIF(a); + } + } + if ( a > b ) { /* tab[a]+tab[b] = tab[b](tab[a-b]+1) */ a = current_gfs_plus1[a-b]; @@ -48,9 +62,15 @@ INLINE int _ADDSF(int a,int b) INLINE int _MULSF(int a,int b) { + int c; + if ( !a || !b ) return 0; - else { + else if ( !current_gfs_ntoi ) { + a = IFTOF(a); b = IFTOF(b); + DMAR(a,b,0,current_gfs_q,c); + return FTOIF(c); + } else { a = IFTOF(a) + IFTOF(b); if ( a >= current_gfs_q1 ) a -= current_gfs_q1; @@ -200,8 +220,8 @@ void kmulsfum(UM n1,UM n2,UM nr) len = (d+1)*d2; r0 = (unsigned int *)ALLOCA(len*sizeof(int)); bzero((char *)r0,len*sizeof(int)); - m = W_UMALLOC(d2+1); - carry = W_UMALLOC(d2+1); + m = W_UMALLOC(d1+d2+1); + carry = W_UMALLOC(d1+d2+1); t = W_UMALLOC(d1+d2+1); s = W_UMALLOC(d1+d2+1); for ( DEG(carry) = -1, i = 0, r = r0; i < d; i++, r += d2 ) { @@ -225,16 +245,17 @@ void kmulsfum(UM n1,UM n2,UM nr) void kmulsfummain(UM n1,UM n2,UM nr) { - int d1,d2,h,len; + int d1,d2,h,len,d; UM n1lo,n1hi,n2lo,n2hi,hi,lo,mid1,mid2,mid,s1,s2,t1,t2; d1 = DEG(n1)+1; d2 = DEG(n2)+1; h = (d1+1)/2; - n1lo = W_UMALLOC(d1+1); n1hi = W_UMALLOC(d1+1); - n2lo = W_UMALLOC(d2+1); n2hi = W_UMALLOC(d2+1); - lo = W_UMALLOC(d1+d2+1); hi = W_UMALLOC(d1+d2+1); - mid1 = W_UMALLOC(d1+d2+1); mid2 = W_UMALLOC(d1+d2+1); - mid = W_UMALLOC(d1+d2+1); - s1 = W_UMALLOC(d1+d2+1); s2 = W_UMALLOC(d1+d2+1); + d = d1+d2+1; + n1lo = W_UMALLOC(d); n1hi = W_UMALLOC(d); + n2lo = W_UMALLOC(d); n2hi = W_UMALLOC(d); + lo = W_UMALLOC(d); hi = W_UMALLOC(d); + mid1 = W_UMALLOC(d); mid2 = W_UMALLOC(d); + mid = W_UMALLOC(d); + s1 = W_UMALLOC(d); s2 = W_UMALLOC(d); extractum(n1,0,h,n1lo); extractum(n1,h,d1-h,n1hi); extractum(n2,0,h,n2lo); extractum(n2,h,d2-h,n2hi); kmulsfum(n1hi,n2hi,hi); kmulsfum(n1lo,n2lo,lo); @@ -300,7 +321,7 @@ void diffsfum(UM f,UM fd) for ( i = DEG(f), dp = COEF(fd)+i-1, sp = COEF(f)+i; i >= 1; i--, dp--, sp-- ) { - *dp = _MULSF(*sp,_itosf(i)); + *dp = _MULSF(*sp,_itosf(i%current_gfs_p)); } degum(fd,DEG(f) - 1); } @@ -671,11 +692,7 @@ void sfmintdeg(VL vl,P fx,int dy,int c,P *fr) /* create the head coeff */ for ( l = 0, k = dxdy-dy; l < dy; l++, k++ ) { - if ( prev[k] ) { - u = IFTOF(prev[k]); - MKGFS(u,s); - } else - s = 0; + iftogfs(prev[k],&s); COEF(h)[l] = (Num)s; } for ( l = dy-1; l >= 0 && !COEF(h)[l]; l--); @@ -711,8 +728,7 @@ void sfmintdeg(VL vl,P fx,int dy,int c,P *fr) for ( k = j = 0; k <= d; k++ ) for ( i = 0; i <= k; i++, j++ ) if ( hist[j] ) { - u = IFTOF(hist[j]); - MKGFS(u,s); + iftogfs(hist[j],&s); /* mono = s*x^(k-i)*y^i */ create_bmono((P)s,x,k-i,y,i,&mono); addp(vl,f,mono,&f1);