version 1.7, 2005/02/13 16:01:02 |
version 1.16, 2018/03/29 01:32:51 |
|
|
#include "inline.h" |
#include "inline.h" |
|
|
#if defined(__GNUC__) |
#if defined(__GNUC__) |
#define INLINE inline |
#define INLINE static inline |
#elif defined(VISUAL) |
#elif defined(VISUAL) |
#define INLINE __inline |
#define INLINE __inline |
#else |
#else |
|
|
INLINE void _addz(Z n1,Z n2,Z nr); |
INLINE void _addz(Z n1,Z n2,Z nr); |
INLINE void _subz(Z n1,Z n2,Z nr); |
INLINE void _subz(Z n1,Z n2,Z nr); |
INLINE void _mulz(Z n1,Z n2,Z nr); |
INLINE void _mulz(Z n1,Z n2,Z nr); |
INLINE int _addz_main(unsigned int *m1,int d1,unsigned int *m2,int d2,unsigned int *mr); |
int _addz_main(unsigned int *m1,int d1,unsigned int *m2,int d2,unsigned int *mr); |
INLINE int _subz_main(unsigned int *m1,int d1,unsigned int *m2,int d2,unsigned int *mr); |
int _subz_main(unsigned int *m1,int d1,unsigned int *m2,int d2,unsigned int *mr); |
|
|
/* immediate int -> Z */ |
/* immediate int -> Z */ |
#define UTOZ(c,n) (n)=(!((unsigned int)(c))?0:(((unsigned int)(c))<=IMM_MAX?((Z)((((unsigned int)(c))<<1)|1)):utoz((unsigned int)(c)))) |
#define UTOZ(c,n) (n)=(!((unsigned int)(c))?0:(((unsigned int)(c))<=IMM_MAX?((Z)((((unsigned int)(c))<<1)|1)):utoz((unsigned int)(c)))) |
Line 30 INLINE int _subz_main(unsigned int *m1,int d1,unsigned |
|
Line 30 INLINE int _subz_main(unsigned int *m1,int d1,unsigned |
|
|
|
int uniz(Z a) |
int uniz(Z a) |
{ |
{ |
if ( IS_IMM(a) && ZTOS(a) == 1 ) return 1; |
if ( IS_IMM(a) && ZTOS(a) == 1 ) return 1; |
else return 0; |
else return 0; |
} |
} |
|
|
int cmpz(Z a,Z b) |
int cmpz(Z a,Z b) |
{ |
{ |
int *ma,*mb; |
int *ma,*mb; |
int sa,sb,da,db,ca,cb,i; |
int sa,sb,da,db,ca,cb,i; |
|
|
if ( !a ) |
if ( !a ) |
return -sgnz(b); |
return -sgnz(b); |
else if ( !b ) |
else if ( !b ) |
return sgnz(a); |
return sgnz(a); |
else { |
else { |
sa = sgnz(a); sb = sgnz(b); |
sa = sgnz(a); sb = sgnz(b); |
if ( sa > sb ) return 1; |
if ( sa > sb ) return 1; |
else if ( sa < sb ) return -1; |
else if ( sa < sb ) return -1; |
else if ( IS_IMM(a) ) |
else if ( IS_IMM(a) ) |
if ( IS_IMM(b) ) { |
if ( IS_IMM(b) ) { |
ca = ZTOS(a); cb = ZTOS(b); |
ca = ZTOS(a); cb = ZTOS(b); |
if ( ca > cb ) return sa; |
if ( ca > cb ) return sa; |
else if ( ca < cb ) return -sa; |
else if ( ca < cb ) return -sa; |
else return 0; |
else return 0; |
} else |
} else |
return -sa; |
return -sa; |
else if ( IS_IMM(b) ) |
else if ( IS_IMM(b) ) |
return sa; |
return sa; |
else { |
else { |
da = SL(a)*sa; db = SL(b)*sa; |
da = SL(a)*sa; db = SL(b)*sa; |
if ( da > db ) return sa; |
if ( da > db ) return sa; |
else if ( da < db ) return -sa; |
else if ( da < db ) return -sa; |
else { |
else { |
for ( i = da-1, ma = BD(a)+i, mb = BD(b)+i; i >= 0; i-- ) |
for ( i = da-1, ma = BD(a)+i, mb = BD(b)+i; i >= 0; i-- ) |
if ( *ma > *mb ) return sa; |
if ( *ma > *mb ) return sa; |
else if ( *ma < *mb ) return -sa; |
else if ( *ma < *mb ) return -sa; |
return 0; |
return 0; |
} |
} |
} |
} |
} |
} |
} |
} |
|
|
Z stoz(int c) |
Z stoz(int c) |
{ |
{ |
Z z; |
Z z; |
|
|
z = ZALLOC(1); |
z = ZALLOC(1); |
if ( c < 0 ) { |
if ( c < 0 ) { |
SL(z) = -1; BD(z)[0] = -c; |
SL(z) = -1; BD(z)[0] = -c; |
} else { |
} else { |
SL(z) = 1; BD(z)[0] = c; |
SL(z) = 1; BD(z)[0] = c; |
} |
} |
return z; |
return z; |
} |
} |
|
|
Z utoz(unsigned int c) |
Z utoz(unsigned int c) |
{ |
{ |
Z z; |
Z z; |
|
|
z = ZALLOC(1); |
z = ZALLOC(1); |
SL(z) = 1; BD(z)[0] = c; |
SL(z) = 1; BD(z)[0] = c; |
return z; |
return z; |
} |
} |
|
|
Z simpz(Z n) |
Z simpz(Z n) |
{ |
{ |
Z n1; |
Z n1; |
|
|
if ( !n ) return 0; |
if ( !n ) return 0; |
else if ( IS_IMM(n) ) return n; |
else if ( IS_IMM(n) ) return n; |
else if ( IS_SZ(n) ) { |
else if ( IS_SZ(n) ) { |
SZTOZ(n,n1); return n1; |
SZTOZ(n,n1); return n1; |
} else |
} else |
return n; |
return n; |
} |
} |
|
|
int sgnz(Z n) |
int sgnz(Z n) |
{ |
{ |
if ( !n ) return 0; |
if ( !n ) return 0; |
else if ( IS_IMM(n) ) return ZTOS(n)>0?1:-1; |
else if ( IS_IMM(n) ) return ZTOS(n)>0?1:-1; |
else if ( SL(n) < 0 ) return -1; |
else if ( SL(n) < 0 ) return -1; |
else return 1; |
else return 1; |
} |
} |
|
|
z_mag(Z n) |
z_mag(Z n) |
{ |
{ |
int c,i; |
int c,i; |
|
|
if ( !n ) return 0; |
if ( !n ) return 0; |
else if ( IS_IMM(n) ) { |
else if ( IS_IMM(n) ) { |
c = ZTOS(n); |
c = ZTOS(n); |
if ( c < 0 ) c = -c; |
if ( c < 0 ) c = -c; |
for ( i = 0; c; c >>= 1, i++ ); |
for ( i = 0; c; c >>= 1, i++ ); |
return i; |
return i; |
} |
} |
else return n_bits((N)n); |
else return n_bits((N)n); |
} |
} |
|
|
Z qtoz(Q n) |
Z qtoz(Q n) |
{ |
{ |
Z r,t; |
Z r,t; |
int c; |
int c; |
|
|
if ( !n ) return 0; |
if ( !n ) return 0; |
else if ( !INT(n) ) |
else if ( !INT(n) ) |
error("qtoz : invalid input"); |
error("qtoz : invalid input"); |
else { |
else { |
t = (Z)NM(n); |
t = (Z)NM(n); |
if ( IS_SZ(t) ) { |
if ( IS_SZ(t) ) { |
c = SGN(n) < 0 ? -BD(t)[0] : BD(t)[0]; |
c = SGN(n) < 0 ? -BD(t)[0] : BD(t)[0]; |
STOZ(c,r); |
STOZ(c,r); |
} else { |
} else { |
r = dupz((Z)t); |
r = dupz((Z)t); |
if ( SGN(n) < 0 ) SL(r) = -SL(r); |
if ( SGN(n) < 0 ) SL(r) = -SL(r); |
} |
} |
return r; |
return r; |
} |
} |
} |
} |
|
|
Q ztoq(Z n) |
Q ztoq(Z n) |
{ |
{ |
Q r; |
Q r; |
Z nm; |
Z nm; |
int sgn,c; |
int sgn,c; |
|
|
if ( !n ) return 0; |
if ( !n ) return 0; |
else if ( IS_IMM(n) ) { |
else if ( IS_IMM(n) ) { |
c = ZTOS(n); |
c = ZTOS(n); |
STOQ(c,r); |
STOQ(c,r); |
return r; |
return r; |
} else { |
} else { |
nm = dupz(n); |
nm = dupz(n); |
if ( SL(nm) < 0 ) { |
if ( SL(nm) < 0 ) { |
sgn = -1; |
sgn = -1; |
SL(nm) = -SL(nm); |
SL(nm) = -SL(nm); |
} else |
} else |
sgn = 1; |
sgn = 1; |
NTOQ((N)nm,sgn,r); |
NTOQ((N)nm,sgn,r); |
return r; |
return r; |
} |
} |
} |
} |
|
|
Z dupz(Z n) |
Z dupz(Z n) |
{ |
{ |
Z r; |
Z r; |
int sd,i; |
int sd,i; |
|
|
if ( !n ) return 0; |
if ( !n ) return 0; |
else if ( IS_IMM(n) ) return n; |
else if ( IS_IMM(n) ) return n; |
else { |
else { |
if ( (sd = SL(n)) < 0 ) sd = -sd; |
if ( (sd = SL(n)) < 0 ) sd = -sd; |
r = ZALLOC(sd); |
r = ZALLOC(sd); |
SL(r) = SL(n); |
SL(r) = SL(n); |
for ( i = 0; i < sd; i++ ) BD(r)[i] = BD(n)[i]; |
for ( i = 0; i < sd; i++ ) BD(r)[i] = BD(n)[i]; |
return r; |
return r; |
} |
} |
} |
} |
|
|
Z chsgnz(Z n) |
Z chsgnz(Z n) |
{ |
{ |
Z r; |
Z r; |
int c; |
int c; |
|
|
if ( !n ) return 0; |
if ( !n ) return 0; |
else if ( IS_IMM(n) ) { |
else if ( IS_IMM(n) ) { |
c = -ZTOS(n); |
c = -ZTOS(n); |
STOZ(c,r); |
STOZ(c,r); |
return r; |
return r; |
} else { |
} else { |
r = dupz(n); |
r = dupz(n); |
SL(r) = -SL(r); |
SL(r) = -SL(r); |
return r; |
return r; |
} |
} |
} |
} |
|
|
Z absz(Z n) |
Z absz(Z n) |
{ |
{ |
Z r; |
Z r; |
int c; |
int c; |
|
|
if ( !n ) return 0; |
if ( !n ) return 0; |
else if ( sgnz(n) > 0 ) |
else if ( sgnz(n) > 0 ) |
return n; |
return n; |
else |
else |
return chsgnz(n); |
return chsgnz(n); |
} |
} |
|
|
Z addz(Z n1,Z n2) |
Z addz(Z n1,Z n2) |
{ |
{ |
int d1,d2,d,c; |
int d1,d2,d,c; |
Z r,r1; |
Z r,r1; |
struct oZ t; |
struct oZ t; |
|
|
if ( !n1 ) return dupz(n2); |
if ( !n1 ) return dupz(n2); |
else if ( !n2 ) return dupz(n1); |
else if ( !n2 ) return dupz(n1); |
else if ( IS_IMM(n1) ) { |
else if ( IS_IMM(n1) ) { |
if ( IS_IMM(n2) ) { |
if ( IS_IMM(n2) ) { |
c = ZTOS(n1)+ZTOS(n2); |
c = ZTOS(n1)+ZTOS(n2); |
STOZ(c,r); |
STOZ(c,r); |
} else { |
} else { |
c = ZTOS(n1); |
c = ZTOS(n1); |
if ( c < 0 ) { |
if ( c < 0 ) { |
t.p = -1; t.b[0] = -c; |
t.p = -1; t.b[0] = -c; |
} else { |
} else { |
t.p = 1; t.b[0] = c; |
t.p = 1; t.b[0] = c; |
} |
} |
if ( (d2 = SL(n2)) < 0 ) d2 = -d2; |
if ( (d2 = SL(n2)) < 0 ) d2 = -d2; |
r = ZALLOC(d2+1); |
r = ZALLOC(d2+1); |
_addz(&t,n2,r); |
_addz(&t,n2,r); |
if ( !SL(r) ) r = 0; |
if ( !SL(r) ) r = 0; |
} |
} |
} else if ( IS_IMM(n2) ) { |
} else if ( IS_IMM(n2) ) { |
c = ZTOS(n2); |
c = ZTOS(n2); |
if ( c < 0 ) { |
if ( c < 0 ) { |
t.p = -1; t.b[0] = -c; |
t.p = -1; t.b[0] = -c; |
} else { |
} else { |
t.p = 1; t.b[0] = c; |
t.p = 1; t.b[0] = c; |
} |
} |
if ( (d1 = SL(n1)) < 0 ) d1 = -d1; |
if ( (d1 = SL(n1)) < 0 ) d1 = -d1; |
r = ZALLOC(d1+1); |
r = ZALLOC(d1+1); |
_addz(n1,&t,r); |
_addz(n1,&t,r); |
if ( !SL(r) ) r = 0; |
if ( !SL(r) ) r = 0; |
} else { |
} else { |
if ( (d1 = SL(n1)) < 0 ) d1 = -d1; |
if ( (d1 = SL(n1)) < 0 ) d1 = -d1; |
if ( (d2 = SL(n2)) < 0 ) d2 = -d2; |
if ( (d2 = SL(n2)) < 0 ) d2 = -d2; |
d = MAX(d1,d2)+1; |
d = MAX(d1,d2)+1; |
r = ZALLOC(d); |
r = ZALLOC(d); |
_addz(n1,n2,r); |
_addz(n1,n2,r); |
if ( !SL(r) ) r = 0; |
if ( !SL(r) ) r = 0; |
} |
} |
if ( r && !((int)r&1) && IS_SZ(r) ) { |
if ( r && !((int)r&1) && IS_SZ(r) ) { |
SZTOZ(r,r1); r = r1; |
SZTOZ(r,r1); r = r1; |
} |
} |
return r; |
return r; |
} |
} |
|
|
Z subz(Z n1,Z n2) |
Z subz(Z n1,Z n2) |
{ |
{ |
int d1,d2,d,c; |
int d1,d2,d,c; |
Z r,r1; |
Z r,r1; |
struct oZ t; |
struct oZ t; |
|
|
if ( !n1 ) |
if ( !n1 ) |
return chsgnz(n2); |
return chsgnz(n2); |
else if ( !n2 ) return n1; |
else if ( !n2 ) return n1; |
else if ( IS_IMM(n1) ) { |
else if ( IS_IMM(n1) ) { |
if ( IS_IMM(n2) ) { |
if ( IS_IMM(n2) ) { |
c = ZTOS(n1)-ZTOS(n2); |
c = ZTOS(n1)-ZTOS(n2); |
STOZ(c,r); |
STOZ(c,r); |
} else { |
} else { |
c = ZTOS(n1); |
c = ZTOS(n1); |
if ( c < 0 ) { |
if ( c < 0 ) { |
t.p = -1; t.b[0] = -c; |
t.p = -1; t.b[0] = -c; |
} else { |
} else { |
t.p = 1; t.b[0] = c; |
t.p = 1; t.b[0] = c; |
} |
} |
if ( (d2 = SL(n2)) < 0 ) d2 = -d2; |
if ( (d2 = SL(n2)) < 0 ) d2 = -d2; |
r = ZALLOC(d2+1); |
r = ZALLOC(d2+1); |
_subz(&t,n2,r); |
_subz(&t,n2,r); |
if ( !SL(r) ) r = 0; |
if ( !SL(r) ) r = 0; |
} |
} |
} else if ( IS_IMM(n2) ) { |
} else if ( IS_IMM(n2) ) { |
c = ZTOS(n2); |
c = ZTOS(n2); |
if ( c < 0 ) { |
if ( c < 0 ) { |
t.p = -1; t.b[0] = -c; |
t.p = -1; t.b[0] = -c; |
} else { |
} else { |
t.p = 1; t.b[0] = c; |
t.p = 1; t.b[0] = c; |
} |
} |
if ( (d1 = SL(n1)) < 0 ) d1 = -d1; |
if ( (d1 = SL(n1)) < 0 ) d1 = -d1; |
r = ZALLOC(d1+1); |
r = ZALLOC(d1+1); |
_subz(n1,&t,r); |
_subz(n1,&t,r); |
if ( !SL(r) ) r = 0; |
if ( !SL(r) ) r = 0; |
} else { |
} else { |
if ( (d1 = SL(n1)) < 0 ) d1 = -d1; |
if ( (d1 = SL(n1)) < 0 ) d1 = -d1; |
if ( (d2 = SL(n2)) < 0 ) d2 = -d2; |
if ( (d2 = SL(n2)) < 0 ) d2 = -d2; |
d = MAX(d1,d2)+1; |
d = MAX(d1,d2)+1; |
r = ZALLOC(d); |
r = ZALLOC(d); |
_subz(n1,n2,r); |
_subz(n1,n2,r); |
if ( !SL(r) ) r = 0; |
if ( !SL(r) ) r = 0; |
} |
} |
if ( r && !((int)r&1) && IS_SZ(r) ) { |
if ( r && !((int)r&1) && IS_SZ(r) ) { |
SZTOZ(r,r1); r = r1; |
SZTOZ(r,r1); r = r1; |
} |
} |
return r; |
return r; |
} |
} |
|
|
Z mulz(Z n1,Z n2) |
Z mulz(Z n1,Z n2) |
{ |
{ |
int d1,d2,sgn,i; |
int d1,d2,sgn,i; |
int c1,c2; |
int c1,c2; |
unsigned int u1,u2,u,l; |
unsigned int u1,u2,u,l; |
Z r; |
Z r; |
|
|
if ( !n1 || !n2 ) return 0; |
if ( !n1 || !n2 ) return 0; |
|
|
if ( IS_IMM(n1) ) { |
if ( IS_IMM(n1) ) { |
c1 = ZTOS(n1); |
c1 = ZTOS(n1); |
if ( IS_IMM(n2) ) { |
if ( IS_IMM(n2) ) { |
c2 = ZTOS(n2); |
c2 = ZTOS(n2); |
if ( c1 == 1 ) |
if ( c1 == 1 ) |
return n2; |
return n2; |
else if ( c1 == -1 ) |
else if ( c1 == -1 ) |
return chsgnz(n2); |
return chsgnz(n2); |
else if ( c2 == 1 ) |
else if ( c2 == 1 ) |
return n1; |
return n1; |
else if ( c2 == -1 ) |
else if ( c2 == -1 ) |
return chsgnz(n1); |
return chsgnz(n1); |
else { |
else { |
sgn = 1; |
sgn = 1; |
if ( c1 < 0 ) { c1 = -c1; sgn = -sgn; } |
if ( c1 < 0 ) { c1 = -c1; sgn = -sgn; } |
if ( c2 < 0 ) { c2 = -c2; sgn = -sgn; } |
if ( c2 < 0 ) { c2 = -c2; sgn = -sgn; } |
u1 = (unsigned int)c1; u2 = (unsigned int)c2; |
u1 = (unsigned int)c1; u2 = (unsigned int)c2; |
DM(u1,u2,u,l); |
DM(u1,u2,u,l); |
if ( !u ) { |
if ( !u ) { |
UTOZ(l,r); |
UTOZ(l,r); |
} else { |
} else { |
r = ZALLOC(2); SL(r) = 2; BD(r)[1] = u; BD(r)[0] = l; |
r = ZALLOC(2); SL(r) = 2; BD(r)[1] = u; BD(r)[0] = l; |
} |
} |
} |
} |
} else { |
} else { |
sgn = 1; |
sgn = 1; |
if ( c1 < 0 ) { c1 = -c1; sgn = -sgn; } |
if ( c1 < 0 ) { c1 = -c1; sgn = -sgn; } |
u1 = (unsigned int)c1; |
u1 = (unsigned int)c1; |
if ( (d2 = SL(n2)) < 0 ) { sgn = -sgn; d2 = -d2; } |
if ( (d2 = SL(n2)) < 0 ) { sgn = -sgn; d2 = -d2; } |
r = ZALLOC(d2+1); |
r = ZALLOC(d2+1); |
for ( i = d2; i >= 0; i-- ) BD(r)[i] = 0; |
for ( i = d2; i >= 0; i-- ) BD(r)[i] = 0; |
muln_1(BD(n2),d2,u1,BD(r)); |
muln_1(BD(n2),d2,u1,BD(r)); |
SL(r) = BD(r)[d2]?d2+1:d2; |
SL(r) = BD(r)[d2]?d2+1:d2; |
} |
} |
} else if ( IS_IMM(n2) ) { |
} else if ( IS_IMM(n2) ) { |
c2 = ZTOS(n2); |
c2 = ZTOS(n2); |
if ( c2 == 1 ) |
if ( c2 == 1 ) |
return n1; |
return n1; |
else if ( c2 == -1 ) |
else if ( c2 == -1 ) |
return chsgnz(n1); |
return chsgnz(n1); |
|
|
sgn = 1; |
sgn = 1; |
if ( c2 < 0 ) { sgn = -sgn; c2 = -c2; } |
if ( c2 < 0 ) { sgn = -sgn; c2 = -c2; } |
u2 = (unsigned int)c2; |
u2 = (unsigned int)c2; |
if ( (d1 = SL(n1)) < 0 ) { sgn = -sgn; d1 = -d1; } |
if ( (d1 = SL(n1)) < 0 ) { sgn = -sgn; d1 = -d1; } |
r = ZALLOC(d1+1); |
r = ZALLOC(d1+1); |
for ( i = d1; i >= 0; i-- ) BD(r)[i] = 0; |
for ( i = d1; i >= 0; i-- ) BD(r)[i] = 0; |
muln_1(BD(n1),d1,u2,BD(r)); |
muln_1(BD(n1),d1,u2,BD(r)); |
SL(r) = BD(r)[d1]?d1+1:d1; |
SL(r) = BD(r)[d1]?d1+1:d1; |
} else { |
} else { |
sgn = 1; |
sgn = 1; |
if ( (d1 = SL(n1)) < 0 ) d1 = -d1; |
if ( (d1 = SL(n1)) < 0 ) d1 = -d1; |
if ( (d2 = SL(n2)) < 0 ) d2 = -d2; |
if ( (d2 = SL(n2)) < 0 ) d2 = -d2; |
r = ZALLOC(d1+d2); |
r = ZALLOC(d1+d2); |
_mulz(n1,n2,r); |
_mulz(n1,n2,r); |
} |
} |
if ( sgn < 0 ) r = chsgnz(r); |
if ( sgn < 0 ) r = chsgnz(r); |
return r; |
return r; |
} |
} |
|
|
/* kokokara */ |
/* kokokara */ |
#if 0 |
#if 0 |
Z divsz(Z n1,Z n2) |
Z divsz(Z n1,Z n2) |
{ |
{ |
int sgn,d1,d2; |
int sgn,d1,d2; |
Z q; |
Z q; |
|
|
if ( !n2 ) error("divsz : division by 0"); |
if ( !n2 ) error("divsz : division by 0"); |
if ( !n1 ) return 0; |
if ( !n1 ) return 0; |
|
|
if ( IS_IMM(n1) ) { |
if ( IS_IMM(n1) ) { |
if ( !IS_IMM(n2) ) |
if ( !IS_IMM(n2) ) |
error("divsz : cannot happen"); |
error("divsz : cannot happen"); |
c = ZTOS(n1)/ZTOS(n2); |
c = ZTOS(n1)/ZTOS(n2); |
STOZ(c,q); |
STOZ(c,q); |
return q; |
return q; |
} |
} |
if ( IS_IMM(n2) ) { |
if ( IS_IMM(n2) ) { |
sgn = 1; |
sgn = 1; |
u2 = ZTOS(n2); if ( u2 < 0 ) { sgn = -sgn; u2 = -u2; } |
u2 = ZTOS(n2); if ( u2 < 0 ) { sgn = -sgn; u2 = -u2; } |
diviz(n1,u2,&q); |
diviz(n1,u2,&q); |
if ( sgn < 0 ) SL(q) = -SL(q); |
if ( sgn < 0 ) SL(q) = -SL(q); |
return q; |
return q; |
} |
} |
|
|
sgn = 1; |
sgn = 1; |
if ( (d2 = SL(n2)) < 0 ) { sgn = -sgn; d2 = -d2; } |
if ( (d2 = SL(n2)) < 0 ) { sgn = -sgn; d2 = -d2; } |
if ( d2 == 1 ) { |
if ( d2 == 1 ) { |
diviz(n1,BD(u2)[0],&q); |
diviz(n1,BD(u2)[0],&q); |
if ( sgn < 0 ) SL(q) = -SL(q); |
if ( sgn < 0 ) SL(q) = -SL(q); |
return q; |
return q; |
} |
} |
if ( (d1 = SL(n1)) < 0 ) { sgn = -sgn; d1 = -d1; } |
if ( (d1 = SL(n1)) < 0 ) { sgn = -sgn; d1 = -d1; } |
if ( d1 < d2 ) error("divsz : cannot happen"); |
if ( d1 < d2 ) error("divsz : cannot happen"); |
return q; |
return q; |
} |
} |
#endif |
#endif |
|
|
/* XXX */ |
/* XXX */ |
Z divz(Z n1,Z n2,Z *r) |
Z divz(Z n1,Z n2,Z *r) |
{ |
{ |
int s1,s2; |
int s1,s2; |
Q t1,t2,qq,rq; |
Q t1,t2,qq,rq; |
N qn,rn; |
N qn,rn; |
|
|
if ( !n1 ) { |
if ( !n1 ) { |
*r = 0; return 0; |
*r = 0; return 0; |
} |
} |
if ( !n2 ) |
if ( !n2 ) |
error("divz : division by 0"); |
error("divz : division by 0"); |
t1 = ztoq(n1); t2 = ztoq(n2); |
t1 = ztoq(n1); t2 = ztoq(n2); |
s1 = sgnz(n1); s2 = sgnz(n2); |
s1 = sgnz(n1); s2 = sgnz(n2); |
/* n1 = qn*SGN(n1)*SGN(n2)*n2+SGN(n1)*rn */ |
/* n1 = qn*SGN(n1)*SGN(n2)*n2+SGN(n1)*rn */ |
divn(NM(t1),NM(t2),&qn,&rn); |
divn(NM(t1),NM(t2),&qn,&rn); |
NTOQ(qn,s1*s2,qq); |
NTOQ(qn,s1*s2,qq); |
NTOQ(rn,s1,rq); |
NTOQ(rn,s1,rq); |
*r = qtoz(rq); |
*r = qtoz(rq); |
return qtoz(qq); |
return qtoz(qq); |
} |
} |
|
|
Z divsz(Z n1,Z n2) |
Z divsz(Z n1,Z n2) |
{ |
{ |
int s1,s2; |
int s1,s2; |
Q t1,t2,qq; |
Q t1,t2,qq; |
N qn; |
N qn; |
|
|
if ( !n1 ) |
if ( !n1 ) |
return 0; |
return 0; |
if ( !n2 ) |
if ( !n2 ) |
error("divsz : division by 0"); |
error("divsz : division by 0"); |
t1 = ztoq(n1); t2 = ztoq(n2); |
t1 = ztoq(n1); t2 = ztoq(n2); |
s1 = sgnz(n1); s2 = sgnz(n2); |
s1 = sgnz(n1); s2 = sgnz(n2); |
/* n1 = qn*SGN(n1)*SGN(n2)*n2 */ |
/* n1 = qn*SGN(n1)*SGN(n2)*n2 */ |
divsn(NM(t1),NM(t2),&qn); |
divsn(NM(t1),NM(t2),&qn); |
NTOQ(qn,s1*s2,qq); |
NTOQ(qn,s1*s2,qq); |
return qtoz(qq); |
return qtoz(qq); |
} |
} |
|
|
int gcdimm(int c1,int c2) |
int gcdimm(int c1,int c2) |
{ |
{ |
int r; |
int r; |
|
|
if ( !c1 ) return c2; |
if ( !c1 ) return c2; |
else if ( !c2 ) return c1; |
else if ( !c2 ) return c1; |
while ( 1 ) { |
while ( 1 ) { |
r = c1%c2; |
r = c1%c2; |
if ( !r ) return c2; |
if ( !r ) return c2; |
c1 = c2; c2 = r; |
c1 = c2; c2 = r; |
} |
} |
} |
} |
|
|
Z gcdz(Z n1,Z n2) |
Z gcdz(Z n1,Z n2) |
{ |
{ |
int c1,c2,g; |
int c1,c2,g; |
Z gcd,r; |
Z gcd,r; |
N gn; |
N gn; |
|
|
if ( !n1 ) return n2; |
if ( !n1 ) return n2; |
else if ( !n2 ) return n1; |
else if ( !n2 ) return n1; |
|
|
if ( IS_IMM(n1) ) { |
if ( IS_IMM(n1) ) { |
c1 = ZTOS(n1); |
c1 = ZTOS(n1); |
if ( c1 < 0 ) c1 = -c1; |
if ( c1 < 0 ) c1 = -c1; |
if ( IS_IMM(n2) ) |
if ( IS_IMM(n2) ) |
c2 = ZTOS(n2); |
c2 = ZTOS(n2); |
else |
else |
c2 = remzi(n2,c1>0?c1:-c1); |
c2 = remzi(n2,c1>0?c1:-c1); |
if ( c2 < 0 ) c2 = -c2; |
if ( c2 < 0 ) c2 = -c2; |
g = gcdimm(c1,c2); |
g = gcdimm(c1,c2); |
STOZ(g,gcd); |
STOZ(g,gcd); |
return gcd; |
return gcd; |
} else if ( IS_IMM(n2) ) { |
} else if ( IS_IMM(n2) ) { |
c2 = ZTOS(n2); |
c2 = ZTOS(n2); |
if ( c2 < 0 ) c2 = -c2; |
if ( c2 < 0 ) c2 = -c2; |
c1 = remzi(n1,c2>0?c2:-c2); |
c1 = remzi(n1,c2>0?c2:-c2); |
if ( c1 < 0 ) c1 = -c1; |
if ( c1 < 0 ) c1 = -c1; |
g = gcdimm(c1,c2); |
g = gcdimm(c1,c2); |
STOZ(g,gcd); |
STOZ(g,gcd); |
return gcd; |
return gcd; |
} else { |
} else { |
n1 = dupz(n1); |
n1 = dupz(n1); |
if ( SL(n1) < 0 ) SL(n1) = -SL(n1); |
if ( SL(n1) < 0 ) SL(n1) = -SL(n1); |
n2 = dupz(n2); |
n2 = dupz(n2); |
if ( SL(n2) < 0 ) SL(n2) = -SL(n2); |
if ( SL(n2) < 0 ) SL(n2) = -SL(n2); |
gcdn((N)n1,(N)n2,&gn); |
gcdn((N)n1,(N)n2,&gn); |
gcd = (Z)gn; |
gcd = (Z)gn; |
if ( IS_SZ(gcd) ) { |
if ( IS_SZ(gcd) ) { |
SZTOZ(gcd,r); gcd = r; |
SZTOZ(gcd,r); gcd = r; |
} |
} |
return gcd; |
return gcd; |
} |
} |
} |
} |
|
|
int remzi(Z n,int m) |
int remzi(Z n,int m) |
{ |
{ |
unsigned int *x; |
unsigned int *x; |
unsigned int t,r; |
unsigned int t,r; |
int i,c; |
int i,c; |
|
|
if ( !n ) return 0; |
if ( !n ) return 0; |
if ( IS_IMM(n) ) { |
if ( IS_IMM(n) ) { |
c = ZTOS(n)%m; |
c = ZTOS(n)%m; |
if ( c < 0 ) c += m; |
if ( c < 0 ) c += m; |
return c; |
return c; |
} |
} |
|
|
i = SL(n); |
i = SL(n); |
if ( i < 0 ) i = -i; |
if ( i < 0 ) i = -i; |
for ( i--, x = BD(n)+i, r = 0; i >= 0; i--, x-- ) { |
for ( i--, x = BD(n)+i, r = 0; i >= 0; i--, x-- ) { |
#if defined(sparc) |
#if defined(sparc) |
r = dsa(m,r,*x); |
r = dsa(m,r,*x); |
#else |
#else |
DSAB(m,r,*x,t,r); |
DSAB(m,r,*x,t,r); |
#endif |
#endif |
} |
} |
if ( r && SL(n) < 0 ) |
if ( r && SL(n) < 0 ) |
r = m-r; |
r = m-r; |
return r; |
return r; |
} |
} |
|
|
Z gcdz_cofactor(Z n1,Z n2,Z *c1,Z *c2) |
Z gcdz_cofactor(Z n1,Z n2,Z *c1,Z *c2) |
{ |
{ |
Z gcd; |
Z gcd; |
|
|
gcd = gcdz(n1,n2); |
gcd = gcdz(n1,n2); |
*c1 = divsz(n1,gcd); |
*c1 = divsz(n1,gcd); |
*c2 = divsz(n2,gcd); |
*c2 = divsz(n2,gcd); |
return gcd; |
return gcd; |
} |
} |
|
|
#if 0 |
#if 0 |
Z estimate_array_gcdz(Z *b,int n) |
Z estimate_array_gcdz(Z *b,int n) |
{ |
{ |
int m,i,j,sd; |
int m,i,j,sd; |
Z *a; |
Z *a; |
Z s,t; |
Z s,t; |
|
|
a = (Z *)ALLOCA(n*sizeof(Z)); |
a = (Z *)ALLOCA(n*sizeof(Z)); |
for ( i = j = 0; i < n; i++ ) if ( b[i] ) a[j++] = b[i]; |
for ( i = j = 0; i < n; i++ ) if ( b[i] ) a[j++] = b[i]; |
n = j; |
n = j; |
if ( !n ) return 0; |
if ( !n ) return 0; |
if ( n == 1 ) return a[0]; |
if ( n == 1 ) return a[0]; |
|
|
m = n/2; |
m = n/2; |
for ( i = 0, s = 0; i < m; i++ ) { |
for ( i = 0, s = 0; i < m; i++ ) { |
if ( !a[i] ) continue; |
if ( !a[i] ) continue; |
else s = (SL(a[i])<0)?subz(s,a[i]):addz(s,a[i]); |
else s = (SL(a[i])<0)?subz(s,a[i]):addz(s,a[i]); |
} |
} |
for ( t = 0; i < n; i++ ) { |
for ( t = 0; i < n; i++ ) { |
if ( !a[i] ) continue; |
if ( !a[i] ) continue; |
else t = (SL(a[i])<0)?subz(t,a[i]):addz(t,a[i]); |
else t = (SL(a[i])<0)?subz(t,a[i]):addz(t,a[i]); |
} |
} |
return gcdz(s,t); |
return gcdz(s,t); |
} |
} |
|
|
Z array_gcdz(Z *b,int n) |
Z array_gcdz(Z *b,int n) |
{ |
{ |
int m,i,j,sd; |
int m,i,j,sd; |
Z *a; |
Z *a; |
Z gcd; |
Z gcd; |
|
|
a = (Z *)ALLOCA(n*sizeof(Z)); |
a = (Z *)ALLOCA(n*sizeof(Z)); |
for ( i = j = 0; i < n; i++ ) if ( b[i] ) a[j++] = b[i]; |
for ( i = j = 0; i < n; i++ ) if ( b[i] ) a[j++] = b[i]; |
n = j; |
n = j; |
if ( !n ) return 0; |
if ( !n ) return 0; |
if ( n == 1 ) return a[0]; |
if ( n == 1 ) return a[0]; |
gcd = a[0]; |
gcd = a[0]; |
for ( i = 1; i < n; i++ ) |
for ( i = 1; i < n; i++ ) |
gcd = gcdz(gcd,a[i]); |
gcd = gcdz(gcd,a[i]); |
return gcd; |
return gcd; |
} |
} |
#endif |
#endif |
|
|
void _copyz(Z n1,Z n2) |
void _copyz(Z n1,Z n2) |
{ |
{ |
int n,i; |
int n,i; |
|
|
if ( !n1 || !SL(n1) ) SL(n2) = 0; |
if ( !n1 || !SL(n1) ) SL(n2) = 0; |
else { |
else { |
n = SL(n2) = SL(n1); |
n = SL(n2) = SL(n1); |
if ( n < 0 ) n = -n; |
if ( n < 0 ) n = -n; |
for ( i = 0; i < n; i++ ) BD(n2)[i] = BD(n1)[i]; |
for ( i = 0; i < n; i++ ) BD(n2)[i] = BD(n1)[i]; |
} |
} |
} |
} |
|
|
void _addz(Z n1,Z n2,Z nr) |
void _addz(Z n1,Z n2,Z nr) |
{ |
{ |
int d1,d2; |
int d1,d2; |
|
|
if ( !n1 || !SL(n1) ) _copyz(n2,nr); |
if ( !n1 || !SL(n1) ) _copyz(n2,nr); |
else if ( !n2 || !SL(n2) ) _copyz(n1,nr); |
else if ( !n2 || !SL(n2) ) _copyz(n1,nr); |
else if ( (d1=SL(n1)) > 0 ) |
else if ( (d1=SL(n1)) > 0 ) |
if ( (d2=SL(n2)) > 0 ) |
if ( (d2=SL(n2)) > 0 ) |
SL(nr) = _addz_main(BD(n1),d1,BD(n2),d2,BD(nr)); |
SL(nr) = _addz_main(BD(n1),d1,BD(n2),d2,BD(nr)); |
else |
else |
SL(nr) = _subz_main(BD(n1),d1,BD(n2),-d2,BD(nr)); |
SL(nr) = _subz_main(BD(n1),d1,BD(n2),-d2,BD(nr)); |
else if ( (d2=SL(n2)) > 0 ) |
else if ( (d2=SL(n2)) > 0 ) |
SL(nr) = _subz_main(BD(n2),d2,BD(n1),-d1,BD(nr)); |
SL(nr) = _subz_main(BD(n2),d2,BD(n1),-d1,BD(nr)); |
else |
else |
SL(nr) = -_addz_main(BD(n1),-d1,BD(n2),-d2,BD(nr)); |
SL(nr) = -_addz_main(BD(n1),-d1,BD(n2),-d2,BD(nr)); |
} |
} |
|
|
void _subz(Z n1,Z n2,Z nr) |
void _subz(Z n1,Z n2,Z nr) |
{ |
{ |
int d1,d2; |
int d1,d2; |
|
|
if ( !n1 || !SL(n1) ) _copyz(n2,nr); |
if ( !n1 || !SL(n1) ) _copyz(n2,nr); |
else if ( !n2 || !SL(n2) ) { |
else if ( !n2 || !SL(n2) ) { |
_copyz(n1,nr); |
_copyz(n1,nr); |
SL(nr) = -SL(nr); |
SL(nr) = -SL(nr); |
} else if ( (d1=SL(n1)) > 0 ) |
} else if ( (d1=SL(n1)) > 0 ) |
if ( (d2=SL(n2)) > 0 ) |
if ( (d2=SL(n2)) > 0 ) |
SL(nr) = _subz_main(BD(n1),d1,BD(n2),d2,BD(nr)); |
SL(nr) = _subz_main(BD(n1),d1,BD(n2),d2,BD(nr)); |
else |
else |
SL(nr) = _addz_main(BD(n1),d1,BD(n2),-d2,BD(nr)); |
SL(nr) = _addz_main(BD(n1),d1,BD(n2),-d2,BD(nr)); |
else if ( (d2=SL(n2)) > 0 ) |
else if ( (d2=SL(n2)) > 0 ) |
SL(nr) = -_addz_main(BD(n1),-d1,BD(n2),d2,BD(nr)); |
SL(nr) = -_addz_main(BD(n1),-d1,BD(n2),d2,BD(nr)); |
else |
else |
SL(nr) = -_subz_main(BD(n1),-d1,BD(n2),-d2,BD(nr)); |
SL(nr) = -_subz_main(BD(n1),-d1,BD(n2),-d2,BD(nr)); |
} |
} |
|
|
void _mulz(Z n1,Z n2,Z nr) |
void _mulz(Z n1,Z n2,Z nr) |
{ |
{ |
int d1,d2; |
int d1,d2; |
int i,d,sgn; |
int i,d,sgn; |
unsigned int mul; |
unsigned int mul; |
unsigned int *m1,*m2; |
unsigned int *m1,*m2; |
|
|
if ( !n1 || !SL(n1) || !n2 || !SL(n2) ) |
if ( !n1 || !SL(n1) || !n2 || !SL(n2) ) |
SL(nr) = 0; |
SL(nr) = 0; |
else { |
else { |
d1 = SL(n1); d2 = SL(n2); |
d1 = SL(n1); d2 = SL(n2); |
sgn = 1; |
sgn = 1; |
if ( d1 < 0 ) { sgn = -sgn; d1 = -d1; } |
if ( d1 < 0 ) { sgn = -sgn; d1 = -d1; } |
if ( d2 < 0 ) { sgn = -sgn; d2 = -d2; } |
if ( d2 < 0 ) { sgn = -sgn; d2 = -d2; } |
d = d1+d2; |
d = d1+d2; |
for ( i = d-1, m1 = BD(nr); i >= 0; i-- ) *m1++ = 0; |
for ( i = d-1, m1 = BD(nr); i >= 0; i-- ) *m1++ = 0; |
for ( i = 0, m1 = BD(n1), m2 = BD(n2); i < d2; i++, m2++ ) |
for ( i = 0, m1 = BD(n1), m2 = BD(n2); i < d2; i++, m2++ ) |
if ( mul = *m2 ) muln_1(m1,d1,mul,BD(nr)+i); |
if ( mul = *m2 ) muln_1(m1,d1,mul,BD(nr)+i); |
SL(nr) = sgn*(BD(nr)[d-1]?d:d-1); |
SL(nr) = sgn*(BD(nr)[d-1]?d:d-1); |
} |
} |
} |
} |
|
|
int _addz_main(unsigned int *m1,int d1,unsigned int *m2,int d2,unsigned int *mr) |
int _addz_main(unsigned int *m1,int d1,unsigned int *m2,int d2,unsigned int *mr) |
{ |
{ |
int d,i; |
int d,i; |
unsigned int tmp,c; |
unsigned int tmp,c; |
unsigned int *t; |
unsigned int *t; |
|
|
if ( d2 > d1 ) { |
if ( d2 > d1 ) { |
t = m1; m1 = m2; m2 = t; |
t = m1; m1 = m2; m2 = t; |
d = d1; d1 = d2; d2 = d; |
d = d1; d1 = d2; d2 = d; |
} |
} |
#if defined(VISUAL) |
#if defined(_M_IX86) && !defined(__MINGW32__) |
__asm { |
__asm { |
push esi |
push esi |
push edi |
push edi |
mov esi,m1 |
mov esi,m1 |
mov edi,m2 |
mov edi,m2 |
mov ebx,mr |
mov ebx,mr |
mov ecx,d2 |
mov ecx,d2 |
xor eax,eax |
xor eax,eax |
Lstart__addz: |
Lstart__addz: |
mov eax,DWORD PTR [esi] |
mov eax,DWORD PTR [esi] |
mov edx,DWORD PTR [edi] |
mov edx,DWORD PTR [edi] |
adc eax,edx |
adc eax,edx |
mov DWORD PTR [ebx],eax |
mov DWORD PTR [ebx],eax |
lea esi,DWORD PTR [esi+4] |
lea esi,DWORD PTR [esi+4] |
lea edi,DWORD PTR [edi+4] |
lea edi,DWORD PTR [edi+4] |
lea ebx,DWORD PTR [ebx+4] |
lea ebx,DWORD PTR [ebx+4] |
dec ecx |
dec ecx |
jnz Lstart__addz |
jnz Lstart__addz |
pop edi |
pop edi |
pop esi |
pop esi |
mov eax,0 |
mov eax,0 |
adc eax,eax |
adc eax,eax |
mov c,eax |
mov c,eax |
} |
} |
#elif defined(i386) |
#elif defined(i386) && !defined(__MINGW32__) |
asm volatile("\ |
asm volatile("\ |
movl %1,%%esi;\ |
pushl %%ebx;\ |
movl %2,%%edi;\ |
movl %1,%%esi;\ |
movl %3,%%ebx;\ |
movl %2,%%edi;\ |
movl %4,%%ecx;\ |
movl %3,%%ebx;\ |
testl %%eax,%%eax;\ |
movl %4,%%ecx;\ |
Lstart__addz:;\ |
testl %%eax,%%eax;\ |
movl (%%esi),%%eax;\ |
Lstart__addz:;\ |
movl (%%edi),%%edx;\ |
movl (%%esi),%%eax;\ |
adcl %%edx,%%eax;\ |
movl (%%edi),%%edx;\ |
movl %%eax,(%%ebx);\ |
adcl %%edx,%%eax;\ |
leal 4(%%esi),%%esi;\ |
movl %%eax,(%%ebx);\ |
leal 4(%%edi),%%edi;\ |
leal 4(%%esi),%%esi;\ |
leal 4(%%ebx),%%ebx;\ |
leal 4(%%edi),%%edi;\ |
decl %%ecx;\ |
leal 4(%%ebx),%%ebx;\ |
jnz Lstart__addz;\ |
decl %%ecx;\ |
movl $0,%%eax;\ |
jnz Lstart__addz;\ |
adcl %%eax,%%eax;\ |
movl $0,%%eax;\ |
movl %%eax,%0"\ |
adcl %%eax,%%eax;\ |
:"=m"(c)\ |
movl %%eax,%0;\ |
:"m"(m1),"m"(m2),"m"(mr),"m"(d2)\ |
popl %%ebx"\ |
:"eax","ebx","ecx","edx","esi","edi"); |
:"=m"(c)\ |
|
:"m"(m1),"m"(m2),"m"(mr),"m"(d2)\ |
|
:"eax","ecx","edx","esi","edi"); |
#else |
#else |
for ( i = 0, c = 0; i < d2; i++, m1++, m2++, mr++ ) { |
for ( i = 0, c = 0; i < d2; i++, m1++, m2++, mr++ ) { |
tmp = *m1 + *m2; |
tmp = *m1 + *m2; |
if ( tmp < *m1 ) { |
if ( tmp < *m1 ) { |
tmp += c; |
tmp += c; |
c = 1; |
c = 1; |
} else { |
} else { |
tmp += c; |
tmp += c; |
c = tmp < c ? 1 : 0; |
c = tmp < c ? 1 : 0; |
} |
} |
*mr = tmp; |
*mr = tmp; |
} |
} |
#endif |
#endif |
for ( i = d2, m1 += d2, mr += d2; (i < d1) && c ; i++ ) { |
for ( i = d2, m1 += d2, mr += d2; (i < d1) && c ; i++ ) { |
tmp = *m1++ + c; |
tmp = *m1++ + c; |
c = tmp < c ? 1 : 0; |
c = tmp < c ? 1 : 0; |
*mr++ = tmp; |
*mr++ = tmp; |
} |
} |
for ( ; i < d1; i++ ) |
for ( ; i < d1; i++ ) |
*mr++ = *m1++; |
*mr++ = *m1++; |
*mr = c; |
*mr = c; |
return (c?d1+1:d1); |
return (c?d1+1:d1); |
} |
} |
|
|
int _subz_main(unsigned int *m1,int d1,unsigned int *m2,int d2,unsigned int *mr) |
int _subz_main(unsigned int *m1,int d1,unsigned int *m2,int d2,unsigned int *mr) |
{ |
{ |
int d,i,sgn; |
int d,i,sgn; |
unsigned int t,tmp,br; |
unsigned int t,tmp,br; |
unsigned int *m; |
unsigned int *m; |
|
|
if ( d1 > d2 ) sgn = 1; |
if ( d1 > d2 ) sgn = 1; |
else if ( d1 < d2 ) sgn = -1; |
else if ( d1 < d2 ) sgn = -1; |
else { |
else { |
for ( i = d1-1; i >= 0 && m1[i] == m2[i]; i-- ); |
for ( i = d1-1; i >= 0 && m1[i] == m2[i]; i-- ); |
if ( i < 0 ) return 0; |
if ( i < 0 ) return 0; |
if ( m1[i] > m2[i] ) sgn = 1; |
if ( m1[i] > m2[i] ) sgn = 1; |
else if ( m1[i] < m2[i] ) sgn = -1; |
else if ( m1[i] < m2[i] ) sgn = -1; |
} |
} |
if ( sgn < 0 ) { |
if ( sgn < 0 ) { |
m = m1; m1 = m2; m2 = m; |
m = m1; m1 = m2; m2 = m; |
d = d1; d1 = d2; d2 = d; |
d = d1; d1 = d2; d2 = d; |
} |
} |
#if defined(VISUAL) |
#if defined(_M_IX86) && !defined(__MINGW32__) |
__asm { |
__asm { |
push esi |
push esi |
push edi |
push edi |
mov esi,m1 |
mov esi,m1 |
mov edi,m2 |
mov edi,m2 |
mov ebx,mr |
mov ebx,mr |
mov ecx,d2 |
mov ecx,d2 |
xor eax,eax |
xor eax,eax |
Lstart__subz: |
Lstart__subz: |
mov eax,DWORD PTR [esi] |
mov eax,DWORD PTR [esi] |
mov edx,DWORD PTR [edi] |
mov edx,DWORD PTR [edi] |
sbb eax,edx |
sbb eax,edx |
mov DWORD PTR [ebx],eax |
mov DWORD PTR [ebx],eax |
lea esi,DWORD PTR [esi+4] |
lea esi,DWORD PTR [esi+4] |
lea edi,DWORD PTR [edi+4] |
lea edi,DWORD PTR [edi+4] |
lea ebx,DWORD PTR [ebx+4] |
lea ebx,DWORD PTR [ebx+4] |
dec ecx |
dec ecx |
jnz Lstart__subz |
jnz Lstart__subz |
pop edi |
pop edi |
pop esi |
pop esi |
mov eax,0 |
mov eax,0 |
adc eax,eax |
adc eax,eax |
mov br,eax |
mov br,eax |
} |
} |
#elif defined(i386) |
#elif defined(i386) && !defined(__MINGW32__) |
asm volatile("\ |
asm volatile("\ |
movl %1,%%esi;\ |
pushl %%ebx;\ |
movl %2,%%edi;\ |
movl %1,%%esi;\ |
movl %3,%%ebx;\ |
movl %2,%%edi;\ |
movl %4,%%ecx;\ |
movl %3,%%ebx;\ |
testl %%eax,%%eax;\ |
movl %4,%%ecx;\ |
Lstart__subz:;\ |
testl %%eax,%%eax;\ |
movl (%%esi),%%eax;\ |
Lstart__subz:;\ |
movl (%%edi),%%edx;\ |
movl (%%esi),%%eax;\ |
sbbl %%edx,%%eax;\ |
movl (%%edi),%%edx;\ |
movl %%eax,(%%ebx);\ |
sbbl %%edx,%%eax;\ |
leal 4(%%esi),%%esi;\ |
movl %%eax,(%%ebx);\ |
leal 4(%%edi),%%edi;\ |
leal 4(%%esi),%%esi;\ |
leal 4(%%ebx),%%ebx;\ |
leal 4(%%edi),%%edi;\ |
decl %%ecx;\ |
leal 4(%%ebx),%%ebx;\ |
jnz Lstart__subz;\ |
decl %%ecx;\ |
movl $0,%%eax;\ |
jnz Lstart__subz;\ |
adcl %%eax,%%eax;\ |
movl $0,%%eax;\ |
movl %%eax,%0"\ |
adcl %%eax,%%eax;\ |
:"=m"(br)\ |
movl %%eax,%0;\ |
:"m"(m1),"m"(m2),"m"(mr),"m"(d2)\ |
popl %%ebx"\ |
:"eax","ebx","ecx","edx","esi","edi"); |
:"=m"(br)\ |
|
:"m"(m1),"m"(m2),"m"(mr),"m"(d2)\ |
|
:"eax","ecx","edx","esi","edi"); |
#else |
#else |
for ( i = 0, br = 0; i < d2; i++, mr++ ) { |
for ( i = 0, br = 0; i < d2; i++, mr++ ) { |
t = *m1++; |
t = *m1++; |
tmp = *m2++ + br; |
tmp = *m2++ + br; |
if ( br > 0 && !tmp ) { |
if ( br > 0 && !tmp ) { |
/* tmp = 2^32 => br = 1 */ |
/* tmp = 2^32 => br = 1 */ |
}else { |
}else { |
tmp = t-tmp; |
tmp = t-tmp; |
br = tmp > t ? 1 : 0; |
br = tmp > t ? 1 : 0; |
*mr = tmp; |
*mr = tmp; |
} |
} |
} |
} |
#endif |
#endif |
for ( i = d2, m1 += d2, mr += d2; (i < d1) && br; i++ ) { |
for ( i = d2, m1 += d2, mr += d2; (i < d1) && br; i++ ) { |
t = *m1++; |
t = *m1++; |
tmp = t - br; |
tmp = t - br; |
br = tmp > t ? 1 : 0; |
br = tmp > t ? 1 : 0; |
*mr++ = tmp; |
*mr++ = tmp; |
} |
} |
for ( ; i < d1; i++ ) |
for ( ; i < d1; i++ ) |
*mr++ = *m1++; |
*mr++ = *m1++; |
for ( i = d1-1, mr--; i >= 0 && !*mr--; i-- ); |
for ( i = d1-1, mr--; i >= 0 && !*mr--; i-- ); |
return sgn*(i+1); |
return sgn*(i+1); |
} |
} |
|
|
/* XXX */ |
/* XXX */ |
|
|
void printz(Z n) |
void printz(Z n) |
{ |
{ |
int sd,u; |
int sd,u; |
|
|
if ( !n ) |
if ( !n ) |
fprintf(asir_out,"0"); |
fprintf(asir_out,"0"); |
else if ( IS_IMM(n) ) { |
else if ( IS_IMM(n) ) { |
u = ZTOS(n); |
u = ZTOS(n); |
fprintf(asir_out,"%d",u); |
fprintf(asir_out,"%d",u); |
} else { |
} else { |
if ( (sd = SL(n)) < 0 ) { SL(n) = -SL(n); fprintf(asir_out,"-"); } |
if ( (sd = SL(n)) < 0 ) { SL(n) = -SL(n); fprintf(asir_out,"-"); } |
printn((N)n); |
printn((N)n); |
if ( sd < 0 ) SL(n) = -SL(n); |
if ( sd < 0 ) SL(n) = -SL(n); |
} |
} |
} |
} |
|
|
/* |
/* |
Line 867 void printz(Z n) |
|
Line 871 void printz(Z n) |
|
|
|
void mkwcz(int k,int l,Z *t) |
void mkwcz(int k,int l,Z *t) |
{ |
{ |
int i,n,up,low; |
int i,n,up,low; |
N nm,d,c; |
N nm,d,c; |
|
|
n = MIN(k,l); |
n = MIN(k,l); |
for ( t[0] = (Z)ONEN, i = 1; i <= n; i++ ) { |
for ( t[0] = (Z)ONEN, i = 1; i <= n; i++ ) { |
DM(k-i+1,l-i+1,up,low); |
DM(k-i+1,l-i+1,up,low); |
if ( up ) { |
if ( up ) { |
nm = NALLOC(2); PL(nm) = 2; BD(nm)[0] = low; BD(nm)[1] = up; |
nm = NALLOC(2); PL(nm) = 2; BD(nm)[0] = low; BD(nm)[1] = up; |
} else { |
} else { |
nm = NALLOC(1); PL(nm) = 1; BD(nm)[0] = low; |
nm = NALLOC(1); PL(nm) = 1; BD(nm)[0] = low; |
} |
} |
kmuln((N)t[i-1],nm,&d); divin(d,i,&c); t[i] = (Z)c; |
kmuln((N)t[i-1],nm,&d); divin(d,i,&c); t[i] = (Z)c; |
} |
} |
} |
} |