shithub: drawterm

Download patch

ref: 88f161d1786b19af9c1a79275ed57de0333918bd
parent: 17da0b9dd1e7dc8f6b43eaa55c291a6ecbb00d69
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Aug 28 14:02:13 EDT 2016

libmp: sync with 9front

--- a/include/mp.h
+++ b/include/mp.h
@@ -81,6 +81,7 @@
 void	mpxor(mpint *b1, mpint *b2, mpint *res);
 void	mptrunc(mpint *b, int n, mpint *res);
 void	mpxtend(mpint *b, int n, mpint *res);
+void	mpasr(mpint *b, int shift, mpint *res);
 
 /* modular arithmetic, time invariant when 0≤b1≤m-1 and 0≤b2≤m-1 */
 void	mpmodadd(mpint *b1, mpint *b2, mpint *m, mpint *sum);	/* sum = b1+b2 % m */
--- a/libmp/mpdiv.c
+++ b/libmp/mpdiv.c
@@ -24,9 +24,12 @@
 	if(divisor->top == 1 && (divisor->p[0] & divisor->p[0]-1) == 0){
 		vlong r = (vlong)dividend->sign * (dividend->p[0] & divisor->p[0]-1);
 		if(quotient != nil){
+			sign = divisor->sign;
 			for(s = 0; ((divisor->p[0] >> s) & 1) == 0; s++)
 				;
 			mpright(dividend, s, quotient);
+			if(sign < 0)
+				quotient->sign ^= (-mpmagcmp(quotient, mpzero) >> 31) << 1;
 		}
 		if(remainder != nil){
 			remainder->flags |= dividend->flags & MPtimesafe;
--- a/libmp/mplogic.c
+++ b/libmp/mplogic.c
@@ -85,7 +85,8 @@
 mpnot(mpint *b, mpint *r)
 {
 	mpadd(b, mpone, r);
-	r->sign ^= -2;
+	if(r->top != 0)
+		r->sign ^= -2;
 }
 
 void
@@ -192,4 +193,16 @@
 			c = 0;
 	}
 	mpnorm(r);
+}
+
+void
+mpasr(mpint *b, int n, mpint *r)
+{
+	if(b->sign > 0 || n <= 0){
+		mpright(b, n, r);
+		return;
+	}
+	mpadd(b, mpone, r);
+	mpright(r, n, r);
+	mpsub(r, mpone, r);
 }
--- a/libmp/mptov.c
+++ b/libmp/mptov.c
@@ -15,10 +15,10 @@
 	uvlong uv;
 
 	if(b == nil){
-		b = mpnew(VLDIGITS*sizeof(mpdigit));
+		b = mpnew(VLDIGITS*Dbits);
 		setmalloctag(b, getcallerpc(&v));
 	}else
-		mpbits(b, VLDIGITS*sizeof(mpdigit));
+		mpbits(b, VLDIGITS*Dbits);
 	b->sign = (v >> (sizeof(v)*8 - 1)) | 1;
 	uv = v * b->sign;
 	for(s = 0; s < VLDIGITS; s++){