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);
367 x->c.bgnm.size=
makeint(vlen+1);
374 register int size, i;
381 for (i=0; i<size; i++) yv[i]=xv[i];
397 bv=bigvec(b); nbv=bigvec(nb); bsize=bigsize(b);
398 for (i=0; i<bsize; i++) nbv[i]=bv[i];
400 for (i=bsize; i<newsize; i++) nbv[i]= MASK;
401 nbv[newsize-1] = -1;}
411 register int i, size;
412 xv=bigvec(x); size=bigsize(x);
413 for (i=0; i<size; i++)
if (xv[i] != 0)
return(0);
427 return(y->
c.
ivec.
iv[vecsize(y)-1]);
440 register int xsize,ysize,i,j=0;
442 xv=bigvec(x); yv=bigvec(y);
443 xsize=bigsize(x); ysize=bigsize(y);
445 xsign=xv[xsize-1]; ysign=yv[ysize-1];
446 if (xsign<0 && ysign>=0)
return(-1);
447 else if (xsign>=0 && ysign<0)
return(1);
450 if (xsize>ysize)
return(-1);
451 else if (xsize<ysize)
return(1);
453 if (xv[xsize-1] < yv[xsize-1])
return(-1);
454 else if (xv[xsize-1]>yv[xsize-1])
return(1);
455 for (i=xsize-2; i>=0; i--) {
456 if (xv[i] < yv[i])
return(1);
457 else if (xv[i] > yv[i])
return(-1); }
460 if (xsize>ysize)
return(1);
461 else if (xsize<ysize)
return(-1);
463 for (i=xsize-1; i>=0; i--) {
464 if (xv[i] > yv[i])
return(1);
465 else if (xv[i] < yv[i])
return(-1); }
480 size=bigsize(x); xv=bigvec(x);
482 while (i != size-1) {
484 xv[i] = (-xv[i]) & MASK;
487 if (xv[i] == ~MASK) {
491 else xv[i] = -(xv[i]);
497 if (i==size-1)
break;
498 xv[i] = (~xv[i]) & MASK;}
513 size=bigsize(x); xv=bigvec(x);
519 yv[i]= (-xv[i]) & MASK;
goto ONE;}
521 if ((
unsigned long)xv[i] == MSB) {
526 else yv[i] = -(xv[i]);
535 if (i==size-1)
break;
536 yv[i] = (~xv[i]) & MASK;
555 {
register int size, i=0;
558 size=bigsize(x); xv=bigvec(x);
585 {
register int size, i=0;
587 size=bigsize(x); xv=bigvec(x);
591 c = 1; xv[i] &= MASK; i++;}
613 size=bigsize(x); xv=bigvec(x);
634 size=bigsize(x); xv=bigvec(x);
654 xsize=bigsize(x); ysize=bigsize(y);
657 i=xsize; xsize=ysize; ysize=i;}
661 xv=bigvec(x); yv=bigvec(y);
664 for (i=0; i<ysize; i++) {
665 zv[i]=zlast=zv[i]+yv[i]+c;
666 if (zlast<0) { c=1; zv[i] &= MASK;}
670 if (xv[i]>=0 && yv[i]>=0 && zlast<0)
stretch_big(z, 1);
671 else if (xv[i]<0 && yv[i]<0 && zlast>=0) {
673 else if (zlast<0) zv[i] |= MSB;
676 if (yv[ysize-1]>=0) c=1;
else c= -1;
678 if (zlast<0) zv[i] &= MASK;
683 if (c>=0 && xv[i]>=0 && zv[i]<0) {
685 else if (c<0 && xv[i]<0 && zv[i]>=0) {
697 {
int xsize, ysize, zsize;
703 xsize=bigsize(x); ysize=bigsize(y);
706 xv=bigvec(x); yv=bigvec(y); zv=bigvec(z);
710 for (i=0; i<xsize; i++) {
713 for (j=0; j<ysize; j++) {
717 if (zv[k] & MSB) { zv[k] &= MASK; hi++; }
723 if (zv[k] & MSB) { zv[k] &= MASK; hi=1; }
749 xsize=bigsize(x); ysize=bigsize(y);
750 xv=bigvec(x); yv=bigvec(y);
753 for (i=0;i<xsize;i++) {
785 {
int size,
s, newsize;
788 size=bigsize(x); xv=bigvec(x);
791 while (xv[newsize-1]==0 && newsize>=0) newsize--;
792 x->c.bgnm.bv->c.ivec.length=
makeint(newsize);
793 if (newsize==0)
return(-1);
794 for (j = 1, i = xv[newsize-1]; (i <<= 1) >= 0; j <<= 1) ;
811 {
int xsize, ysize, zsize;
816 xsize=bigsize(x); ysize=bigsize(y);
817 xv=bigvec(x); yv=bigvec(y);
819 if (xsize != ysize) {
820 if (yv[xsize] >= xv[xsize-1])
826 extended_div(xv[xsize-1], yv[xsize], yv[xsize-1], &q, &r);
833 q = yv[xsize-1] / xv[xsize-1] - 2;
848 xsize=bigsize(x); ysize=bigsize(y);
850 if (i < 0)
return(
NULL);
853 if (i == 0)
return(
NULL);
921 {
int size, i, newsize, positive;
924 size=bigsize(x); xv=bigvec(x);
926 positive = gez(xv[size-1]);
927 for (i=size-1; i>=0; i--) {
928 if (positive && xv[i]==0) newsize--;
929 else if (!positive && xv[i]==-1 && size!=1) newsize--;
931 if (newsize != size) {
934 if (!positive) xv[newsize-1] |= MSB;}
943 if (!isbignum(x))
return(x);
949 y=x->c.bgnm.bv->c.ivec.iv[0];
950 msb3= (y >> (WORD_SIZE-3)) & 0x7;
951 if (msb3==0 || msb3==7)
return(
makeint(y));}
958 size=bigsize(x); xv=bigvec(x);
960 for (i=0, d = 0.0, e = 1.0; i<size-1; i++) {
961 d += e * (double)(xv[i]);
962 e *= (double)((
unsigned long)1 << (WORD_SIZE-1));
964 d += e * (double)(xv[size-1]);
969 {
int i, j, exp, bsize, iz;
973 extern double frexp(
double,
int *);
974 extern double ldexp(
double,
int);
978 if (f<=MAXPOSFIXNUM+1) {
982 else if (f<=MAXPOSFIXNUM) {
991 bsize=(exp + WORD_SIZE - 2)/(WORD_SIZE - 1);
996 i=exp / (WORD_SIZE -1);
997 j=exp % (WORD_SIZE -1);
998 bv[i]= (iz << j) & MASK;
999 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)