21 #define ltz(x) ((x)<0) 22 #define gez(x) ((x)>=0) 36 ld = (d & 0x00000000ffffffff);
38 hd = (hd & 0x000000007fffffff);
39 lq = (q & 0x00000000ffffffff);
41 hq = (hq & 0x000000007fffffff);
45 hm = (m & 0x8000000000000000);
47 hm = (hm & 0x0000000080000000);
48 m = (m & 0x7fffffffffffffff);
52 lz = (m & 0x00000000ffffffff);
55 m = (m & 0x00000000ffffffff);
58 hm = (m & 0x8000000000000000);
60 hm = (hm & 0x00000001ffffffff);
61 m = (m & 0x7fffffffffffffff);
65 lm = (m & 0x000000007fffffff);
70 m = (m & 0x00000001ffffffff);
73 hz = m + (hq * hd * 2);
104 lh = (0x7fffffffffffffff - ld) +
105 (lh & 0x7fffffffffffffff) + 1;
116 #if (!Solaris2 || !sun4) 122 long int ld, hd, lq, hq, m, lm, hm, lr;
126 ld = (
d & 0x0000ffff);
128 hd = (hd & 0x00007fff);
129 lq = (q & 0x0000ffff);
131 hq = (hq & 0x00007fff);
135 hm = (m & 0x80000000);
137 hm = (hm & 0x00008000);
138 m = (m & 0x7fffffff);
142 lz = (m & 0x0000ffff);
145 m = (m & 0x0000ffff);
148 hm = (m & 0x80000000);
150 hm = (hm & 0x0001ffff);
151 m = (m & 0x7fffffff);
155 lm = (m & 0x00007fff);
157 lz = lz + (lm << 16);
160 m = (m & 0x0001ffff);
163 hz = m + (hq * hd * 2);
194 lh = (0x7fffffff - ld) + (lh & 0x7fffffff) + 1;
207 #define u_int unsigned int 215 printf(
"ext.mul (%x %x %x)",d,q,r);fflush(stdout);
217 printf(
" =%x:%08x\n",*hp,*lp);fflush(stdout);
223 register u_int
d, q, r;
224 register u_int *hp, *lp;
226 asm(
" save %sp, -0x60, %sp");
228 asm(
" call .umul,2");
230 asm(
" addcc %o0,%i2,%o0");
231 asm(
" addx %o1, 0,%o1");
233 asm(
" sll %o1, 2,%o1");
234 asm(
" srl %o1, 1,%o1");
235 asm(
" srl %o0, 31,%i2");
236 asm(
" or %o1,%i2,%o1");
238 asm(
" sll %o0, 1,%o0");
239 asm(
" srl %o0, 1,%o0");
241 asm(
" st %o0,[%i4]");
242 asm(
" st %o1,[%i3]");
248 register u_int d, h,
l;
251 register u_int q,one;
253 printf(
"ext.div (%x %x:%x)",d,h,l);fflush(stdout);
255 l=l<<1; one=1<<31; q=0;
256 if (h>=d) { q+= one;h-=d; }
257 h<<=1; h|=l>>31; l<<=1; one>>=1;
258 if (h>=d) { q+= one;h-=d; }
259 h<<=1; h|=l>>31; l<<=1; one>>=1;
260 if (h>=d) { q+= one;h-=d; }
261 h<<=1; h|=l>>31; l<<=1; one>>=1;
262 if (h>=d) { q+= one;h-=d; }
263 h<<=1; h|=l>>31; l<<=1; one>>=1;
264 if (h>=d) { q+= one;h-=d; }
265 h<<=1; h|=l>>31; l<<=1; one>>=1;
266 if (h>=d) { q+= one;h-=d; }
267 h<<=1; h|=l>>31; l<<=1; one>>=1;
268 if (h>=d) { q+= one;h-=d; }
269 h<<=1; h|=l>>31; l<<=1; one>>=1;
270 if (h>=d) { q+= one;h-=d; }
271 h<<=1; h|=l>>31; l<<=1; one>>=1;
273 if (h>=d) { q+= one;h-=d; }
274 h<<=1; h|=l>>31; l<<=1; one>>=1;
275 if (h>=d) { q+= one;h-=d; }
276 h<<=1; h|=l>>31; l<<=1; one>>=1;
277 if (h>=d) { q+= one;h-=d; }
278 h<<=1; h|=l>>31; l<<=1; one>>=1;
279 if (h>=d) { q+= one;h-=d; }
280 h<<=1; h|=l>>31; l<<=1; one>>=1;
281 if (h>=d) { q+= one;h-=d; }
282 h<<=1; h|=l>>31; l<<=1; one>>=1;
283 if (h>=d) { q+= one;h-=d; }
284 h<<=1; h|=l>>31; l<<=1; one>>=1;
285 if (h>=d) { q+= one;h-=d; }
286 h<<=1; h|=l>>31; l<<=1; one>>=1;
287 if (h>=d) { q+= one;h-=d; }
288 h<<=1; h|=l>>31; l<<=1; one>>=1;
290 if (h>=d) { q+= one;h-=d; }
291 h<<=1; h|=l>>31; l<<=1; one>>=1;
292 if (h>=d) { q+= one;h-=d; }
293 h<<=1; h|=l>>31; l<<=1; one>>=1;
294 if (h>=d) { q+= one;h-=d; }
295 h<<=1; h|=l>>31; l<<=1; one>>=1;
296 if (h>=d) { q+= one;h-=d; }
297 h<<=1; h|=l>>31; l<<=1; one>>=1;
298 if (h>=d) { q+= one;h-=d; }
299 h<<=1; h|=l>>31; l<<=1; one>>=1;
300 if (h>=d) { q+= one;h-=d; }
301 h<<=1; h|=l>>31; l<<=1; one>>=1;
302 if (h>=d) { q+= one;h-=d; }
303 h<<=1; h|=l>>31; l<<=1; one>>=1;
304 if (h>=d) { q+= one;h-=d; }
305 h<<=1; h|=l>>31; l<<=1; one>>=1;
307 if (h>=d) { q+= one;h-=d; }
308 h<<=1; h|=l>>31; l<<=1; one>>=1;
309 if (h>=d) { q+= one;h-=d; }
310 h<<=1; h|=l>>31; l<<=1; one>>=1;
311 if (h>=d) { q+= one;h-=d; }
312 h<<=1; h|=l>>31; l<<=1; one>>=1;
313 if (h>=d) { q+= one;h-=d; }
314 h<<=1; h|=l>>31; l<<=1; one>>=1;
315 if (h>=d) { q+= one;h-=d; }
316 h<<=1; h|=l>>31; l<<=1; one>>=1;
317 if (h>=d) { q+= one;h-=d; }
318 h<<=1; h|=l>>31; l<<=1; one>>=1;
319 if (h>=d) { q+= one;h-=d; }
320 h<<=1; h|=l>>31; l<<=1; one>>=1;
321 if (h>=d) { q+= one;h-=d; }
322 h<<=1; h|=l>>31; l<<=1; one>>=1;
339 printf(
" =%x:%x\n",*qp,*rp);fflush(stdout);
359 int vlen=vecsize(bn);
366 pointer_update(x->c.bgnm.bv, newv);
373 register int size, i;
380 for (i=0; i<size; i++) yv[i]=xv[i];
396 bv=bigvec(b); nbv=bigvec(nb); bsize=bigsize(b);
397 for (i=0; i<bsize; i++) nbv[i]=bv[i];
399 for (i=bsize; i<newsize; i++) nbv[i]= MASK;
400 nbv[newsize-1] = -1;}
410 register int i, size;
411 xv=bigvec(x); size=bigsize(x);
412 for (i=0; i<size; i++)
if (xv[i] != 0)
return(0);
426 return(y->
c.
ivec.
iv[vecsize(y)-1]);
439 register int xsize,ysize,i,j=0;
441 xv=bigvec(x); yv=bigvec(y);
442 xsize=bigsize(x); ysize=bigsize(y);
444 xsign=xv[xsize-1]; ysign=yv[ysize-1];
445 if (xsign<0 && ysign>=0)
return(-1);
446 else if (xsign>=0 && ysign<0)
return(1);
449 if (xsize>ysize)
return(-1);
450 else if (xsize<ysize)
return(1);
452 if (xv[xsize-1] < yv[xsize-1])
return(-1);
453 else if (xv[xsize-1]>yv[xsize-1])
return(1);
454 for (i=xsize-2; i>=0; i--) {
455 if (xv[i] < yv[i])
return(1);
456 else if (xv[i] > yv[i])
return(-1); }
459 if (xsize>ysize)
return(1);
460 else if (xsize<ysize)
return(-1);
462 for (i=xsize-1; i>=0; i--) {
463 if (xv[i] > yv[i])
return(1);
464 else if (xv[i] < yv[i])
return(-1); }
479 size=bigsize(x); xv=bigvec(x);
481 while (i != size-1) {
483 xv[i] = (-xv[i]) & MASK;
486 if (xv[i] == ~MASK) {
490 else xv[i] = -(xv[i]);
496 if (i==size-1)
break;
497 xv[i] = (~xv[i]) & MASK;}
512 size=bigsize(x); xv=bigvec(x);
518 yv[i]= (-xv[i]) & MASK;
goto ONE;}
525 else yv[i] = -(xv[i]);
534 if (i==size-1)
break;
535 yv[i] = (~xv[i]) & MASK;
554 {
register int size, i=0;
557 size=bigsize(x); xv=bigvec(x);
584 {
register int size, i=0;
586 size=bigsize(x); xv=bigvec(x);
590 c = 1; xv[i] &= MASK; i++;}
612 size=bigsize(x); xv=bigvec(x);
633 size=bigsize(x); xv=bigvec(x);
653 xsize=bigsize(x); ysize=bigsize(y);
656 i=xsize; xsize=ysize; ysize=i;}
660 xv=bigvec(x); yv=bigvec(y);
663 for (i=0; i<ysize; i++) {
664 zv[i]=zlast=zv[i]+yv[i]+c;
665 if (zlast<0) { c=1; zv[i] &= MASK;}
669 if (xv[i]>=0 && yv[i]>=0 && zlast<0)
stretch_big(z, 1);
670 else if (xv[i]<0 && yv[i]<0 && zlast>=0) {
672 else if (zlast<0) zv[i] |= MSB;
675 if (yv[ysize-1]>=0) c=1;
else c= -1;
677 if (zlast<0) zv[i] &= MASK;
682 if (c>=0 && xv[i]>=0 && zv[i]<0) {
684 else if (c<0 && xv[i]<0 && zv[i]>=0) {
696 {
int xsize, ysize, zsize;
702 xsize=bigsize(x); ysize=bigsize(y);
705 xv=bigvec(x); yv=bigvec(y); zv=bigvec(z);
709 for (i=0; i<xsize; i++) {
712 for (j=0; j<ysize; j++) {
716 if (zv[k] & MSB) { zv[k] &= MASK; hi++; }
722 if (zv[k] & MSB) { zv[k] &= MASK; hi=1; }
748 xsize=bigsize(x); ysize=bigsize(y);
749 xv=bigvec(x); yv=bigvec(y);
752 for (i=0;i<xsize;i++) {
784 {
int size,
s, newsize;
787 size=bigsize(x); xv=bigvec(x);
790 while (xv[newsize-1]==0 && newsize>=0) newsize--;
791 x->c.bgnm.bv->c.ivec.length=
makeint(newsize);
792 if (newsize==0)
return(-1);
793 for (j = 1, i = xv[newsize-1]; (i <<= 1) >= 0; j <<= 1) ;
810 {
int xsize, ysize, zsize;
815 xsize=bigsize(x); ysize=bigsize(y);
816 xv=bigvec(x); yv=bigvec(y);
818 if (xsize != ysize) {
819 if (yv[xsize] >= xv[xsize-1])
825 extended_div(xv[xsize-1], yv[xsize], yv[xsize-1], &q, &r);
832 q = yv[xsize-1] / xv[xsize-1] - 2;
847 xsize=bigsize(x); ysize=bigsize(y);
849 if (i < 0)
return(
NULL);
852 if (i == 0)
return(
NULL);
920 {
int size, i, newsize, positive;
923 size=bigsize(x); xv=bigvec(x);
925 positive = gez(xv[size-1]);
926 for (i=size-1; i>=0; i--) {
927 if (positive && xv[i]==0) newsize--;
928 else if (!positive && xv[i]==-1 && size!=1) newsize--;
930 if (newsize != size) {
933 if (!positive) xv[newsize-1] |= MSB;}
942 if (!isbignum(x))
return(x);
948 y=x->c.bgnm.bv->c.ivec.iv[0];
949 msb3= (y >> (WORD_SIZE-3)) & 0x7;
950 if (msb3==0 || msb3==7)
return(
makeint(y));}
957 size=bigsize(x); xv=bigvec(x);
959 for (i=0, d = 0.0, e = 1.0; i<size-1; i++) {
960 d += e * (double)(xv[i]);
961 e *= (double)((
unsigned long)1 << (WORD_SIZE-1));
963 d += e * (double)(xv[size-1]);
968 {
int i, j, exp, bsize, iz;
972 extern double frexp(
double,
int *);
973 extern double ldexp(
double,
int);
977 if (f<=MAXPOSFIXNUM+1) {
981 else if (f<=MAXPOSFIXNUM) {
990 bsize=(exp + WORD_SIZE - 2)/(WORD_SIZE - 1);
995 i=exp / (WORD_SIZE -1);
996 j=exp % (WORD_SIZE -1);
997 bv[i]= (iz << j) & MASK;
998 if (j+24 > 31) bv[i+1]= (iz >> (WORD_SIZE -1 - j)) & MASK;
context * euscontexts[MAXTHREAD]
eusinteger_t div_int_big(eusinteger_t c, pointer x)
eusinteger_t get_standardizing_factor_and_normalize(pointer x)
pointer normalize_big(pointer x)
pointer big_minus(pointer x)
pointer makevector(pointer, int)
pointer copy_big(pointer x)
void mul_int_big(eusinteger_t c, pointer x)
pointer extend_big(pointer b, int newsize)
eusinteger_t div_big_big(pointer x, pointer y)
eusinteger_t big_zerop(pointer x)
void extended_mul(eusinteger_t d, eusinteger_t q, eusinteger_t r, eusinteger_t *hp, eusinteger_t *lp)
pointer stretch_big(pointer x, eusinteger_t i)
void sub_int_big_big(eusinteger_t c, pointer x, pointer y)
static low_extended_mul(extended_mul(d, extended_mul(q, extended_mul(r, extended_mul(hp, u_int *lp)
void add_int_big(eusinteger_t c, pointer x)
pointer error(enum errorcode ec,...) pointer error(va_alist) va_dcl
void extended_div(eusinteger_t d, eusinteger_t h, eusinteger_t l, eusinteger_t *qp, eusinteger_t *rp)
pointer big_plus(pointer x, pointer y)
pointer big_quotient_remainder_auxiliary(pointer x, pointer y, int i)
int big_compare(pointer x, pointer y)
pointer normalize_bignum(pointer x)
void sub_int_big(eusinteger_t c, pointer x)
void complement_big(pointer x)
eusinteger_t big_sign(pointer x)
pointer big_times(pointer x, pointer y)
int big_length(pointer x)
void big_quotient_remainder(pointer x0, pointer y0, pointer *qp, pointer *rp)
eusfloat_t big_to_float(pointer x)
pointer eusfloat_to_big(float f)