[Gmp-commit] /var/hg/gmp: 2 new changesets

mercurial at gmplib.org mercurial at gmplib.org
Tue Jun 23 18:50:45 UTC 2015


details:   /var/hg/gmp/rev/246c63b34270
changeset: 16720:246c63b34270
user:      Torbjorn Granlund <torbjorng at google.com>
date:      Sat Jun 20 20:22:36 2015 +0200
description:
Whitespace cleanup.

details:   /var/hg/gmp/rev/ad29a3fa44e7
changeset: 16721:ad29a3fa44e7
user:      Torbjorn Granlund <torbjorng at google.com>
date:      Tue Jun 23 20:49:50 2015 +0200
description:
Trivial merge.

diffstat:

 mpn/generic/sqrtrem.c |  46 +++++++++++++++++-----------------------------
 mpq/div.c             |   2 +-
 2 files changed, 18 insertions(+), 30 deletions(-)

diffs (89 lines):

diff -r ac54869212ab -r ad29a3fa44e7 mpn/generic/sqrtrem.c
--- a/mpn/generic/sqrtrem.c	Mon Jun 15 22:56:58 2015 +0200
+++ b/mpn/generic/sqrtrem.c	Tue Jun 23 20:49:50 2015 +0200
@@ -171,45 +171,33 @@
 static mp_limb_t
 mpn_sqrtrem2 (mp_ptr sp, mp_ptr rp, mp_srcptr np)
 {
-  mp_limb_t qhl, q, u, np0, sp0, rp0, q2;
+  mp_limb_t q, u, np0, sp0, rp0, q2;
   int cc;
 
   ASSERT (np[1] >= GMP_NUMB_HIGHBIT / 2);
 
   np0 = np[0];
   sp0 = mpn_sqrtrem1 (rp, np[1]);
-  qhl = 0;
   rp0 = rp[0];
-  while (rp0 >= sp0)
-    {
-      qhl++;
-      rp0 -= sp0;
-    }
-  /* now rp0 < sp0 < 2^Prec */
-  rp0 = (rp0 << Prec) + (np0 >> Prec);
-  u = 2 * sp0;
-  q = rp0 / u;
-  u = rp0 - q * u;
-  q += (qhl & 1) << (Prec - 1);
-  qhl >>= 1; /* if qhl=1, necessary q=0 as qhl*2^Prec + q <= 2^Prec */
-  /* now we have (initial rp0)<<Prec + np0>>Prec = (qhl<<Prec + q) * (2sp0) + u */
-  sp0 = ((sp0 + qhl) << Prec) + q;
-  cc = u >> Prec;
-  rp0 = ((u << Prec) & GMP_NUMB_MASK) + (np0 & ((CNST_LIMB (1) << Prec) - 1));
-  /* subtract q * q or qhl*2^(2*Prec) from rp */
+  /* rp0 <= 2*sp0 < 2^(Prec + 1) */
+  rp0 = (rp0 << (Prec - 1)) + (np0 >> (Prec + 1));
+  q = rp0 / sp0;
+  /* q <= 2^Prec, if q = 2^Prec, reduce the overestimate. */
+  q -= q >> Prec;
+  /* now we have q < 2^Prec */
+  u = rp0 - q * sp0;
+  /* now we have (rp[0]<<Prec + np0>>Prec)/2 = q * sp0 + u */
+  sp0 = (sp0 << Prec) | q;
+  cc = u >> (Prec - 1);
+  rp0 = ((u << (Prec + 1)) & GMP_NUMB_MASK) + (np0 & ((CNST_LIMB (1) << (Prec + 1)) - 1));
+  /* subtract q * q from rp */
   q2 = q * q;
-  cc -= (rp0 < q2) + qhl;
+  cc -= rp0 < q2;
   rp0 -= q2;
-  /* now subtract 2*q*2^Prec + 2^(2*Prec) if qhl is set */
   if (cc < 0)
     {
-      if (sp0 != 0)
-	{
-	  rp0 += sp0;
-	  cc += rp0 < sp0;
-	}
-      else
-	cc++;
+      rp0 += sp0;
+      cc += rp0 < sp0;
       --sp0;
       rp0 += sp0;
       cc += rp0 < sp0;
@@ -253,10 +241,10 @@
       mpn_sqr (np + n, sp, l);
       b = q + mpn_sub_n (np, np, np + n, 2 * l);
       c -= (l == h) ? b : mpn_sub_1 (np + 2 * l, np + 2 * l, 1, (mp_limb_t) b);
-      q = mpn_add_1 (sp + l, sp + l, h, q);
 
       if (c < 0)
 	{
+	  q = mpn_add_1 (sp + l, sp + l, h, q);
 #if HAVE_NATIVE_mpn_addlsh1_n
 	  c += mpn_addlsh1_n (np, np, sp, n) + 2 * q;
 #else
diff -r ac54869212ab -r ad29a3fa44e7 mpq/div.c
--- a/mpq/div.c	Mon Jun 15 22:56:58 2015 +0200
+++ b/mpq/div.c	Tue Jun 23 20:49:50 2015 +0200
@@ -53,7 +53,7 @@
       SIZ(NUM(quot)) = 1;
       PTR(DEN(quot))[0] = 1;
       SIZ(DEN(quot)) = 1;
-      return;      
+      return;
     }
 
   if (quot == op2)


More information about the gmp-commit mailing list