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

mercurial at gmplib.org mercurial at gmplib.org
Thu Jun 11 14:01:50 UTC 2015


details:   /var/hg/gmp/rev/52b40f84e16f
changeset: 16699:52b40f84e16f
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Jun 11 14:09:40 2015 +0200
description:
mpn/generic/rootrem.c: Fix a miscomputation.

details:   /var/hg/gmp/rev/e0f9abb34d6e
changeset: 16700:e0f9abb34d6e
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Jun 11 15:47:06 2015 +0200
description:
mpn/generic/rootrem.c: Use NORMALIZE_NOT_ZERO.

details:   /var/hg/gmp/rev/a9aebe3c9bfb
changeset: 16701:a9aebe3c9bfb
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Jun 11 16:01:42 2015 +0200
description:
ChangeLog

diffstat:

 ChangeLog             |   9 +++++++++
 mpn/generic/rootrem.c |  25 +++++++++++++------------
 2 files changed, 22 insertions(+), 12 deletions(-)

diffs (117 lines):

diff -r 6fc5b81e601d -r a9aebe3c9bfb ChangeLog
--- a/ChangeLog	Wed Jun 10 23:42:36 2015 +0200
+++ b/ChangeLog	Thu Jun 11 16:01:42 2015 +0200
@@ -1,3 +1,12 @@
+2015-06-10 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* tests/mpz/t-root.c: Check also mpz_root retunr value.
+	* mpn/generic/rootrem.c: Shorten first and last loop.
+
+	* mpn/generic/toom2_sqr.c: Add some ASSERTs.
+	* mpn/generic/toom22_mul.c: Likewise.
+	* tests/mpn/t-toom22.c: stop testing some unsafe (unused) corner cases.
+
 2015-06-08  Torbjörn Granlund  <torbjorng at google.com>
 
 	* mpn/x86/p6/gcd_1.asm: Align stack for calls.
diff -r 6fc5b81e601d -r a9aebe3c9bfb mpn/generic/rootrem.c
--- a/mpn/generic/rootrem.c	Wed Jun 10 23:42:36 2015 +0200
+++ b/mpn/generic/rootrem.c	Thu Jun 11 16:01:42 2015 +0200
@@ -8,7 +8,7 @@
    ONLY SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES.  IN FACT, IT'S ALMOST
    GUARANTEED THAT THEY'LL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
 
-Copyright 2002, 2005, 2009-2012 Free Software Foundation, Inc.
+Copyright 2002, 2005, 2009-2012, 2015 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -168,8 +168,8 @@
      know the root has exactly xnb bits, we write r0 = 2^(xnb-1), so that
      r0^k = 2^(k*(xnb-1)), that we subtract to the input. */
   kk = k * (xnb - 1);		/* number of truncated bits in the input */
+  --kk;
   rn = un - kk / GMP_NUMB_BITS; /* number of limbs of the non-truncated part */
-  --kk;
 
   for (logk = 1; ((k - 1) >> logk) != 0; logk++)
     ;
@@ -222,13 +222,14 @@
   sp = rootp;
 
   MPN_RSHIFT (cy, rp, up + kk / GMP_NUMB_BITS, rn, kk % GMP_NUMB_BITS);
-  mpn_sub_1 (rp, rp, rn, 2);	/* subtract the initial approximation: since
+  MPN_DECR_U (rp, rn, 2);	/* subtract the initial approximation: since
 				   the non-truncated part is less than 2^k, it
 				   is <= k bits: rn <= ceil(k/GMP_NUMB_BITS) */
+  rn -= rp [rn - 1] == 0;
   sp[0] = save = 2;		/* initial approximation */
   sn = 1;			/* it has one limb */
 
-  wp[0] = k; /* k * {sp,sn}^(k-1) = 1 */
+  wp[0] = k; /* k * {sp,sn}^(k-1) */
   wn = 1;
   i = ni;
   b = bn = 1;
@@ -325,7 +326,7 @@
       if (perf_pow != 0)
 	{
 	  mpn_sub (rp, rp, rn, qp, qn);
-	  MPN_NORMALIZE (rp, rn);
+	  MPN_NORMALIZE_NOT_ZERO (rp, rn);
 	}
       else
 	{
@@ -333,15 +334,15 @@
 	  rp[0] = 0;
 	}
       /* 11: current buffers: {sp,sn}, {rp,rn}, {wp,wn} */
-      /* Reinsert a low zero limb if we normalized away the entire remainder */
-      rn += (rn == 0);
 
       b = sizes[i - 1] - sizes[i]; /* number of bits to compute in the
 				      next iteration */
 
       /* first multiply the remainder by 2^b */
-      MPN_LSHIFT (cy, rp + b / GMP_NUMB_BITS, rp, rn, b % GMP_NUMB_BITS);
-      rn = rn + b / GMP_NUMB_BITS;
+      bn = b / GMP_NUMB_BITS; /* lowest limb from high part of rp[] */
+      /* FIXME: next shift can be moved in the only branch above where it makes sense. */
+      MPN_LSHIFT (cy, rp + bn, rp, rn, b % GMP_NUMB_BITS);
+      rn = rn + bn;
       if (cy != 0)
 	{
 	  rp[rn] = cy;
@@ -353,7 +354,6 @@
       /* 2: current buffers: {sp,sn}, {rp,rn}, {wp,wn} */
 
       /* Now insert bits [kk,kk+b-1] from the input U */
-      bn = b / GMP_NUMB_BITS; /* lowest limb from high part of rp[] */
       save = rp[bn];
       /* nl is the number of limbs in U which contain bits [kk,kk+b-1] */
       nl = 1 + (kk + b - 1) / GMP_NUMB_BITS - (kk / GMP_NUMB_BITS);
@@ -369,13 +369,14 @@
 	save2 = rp[bn + 1];
       MPN_RSHIFT (cy, rp, up + kk / GMP_NUMB_BITS, nl, kk % GMP_NUMB_BITS);
       /* set to zero high bits of rp[bn] */
-      rp[bn] &= ((mp_limb_t) 1 << (b % GMP_NUMB_BITS)) - 1;
+      rp[bn] &= (CNST_LIMB (1) << (b % GMP_NUMB_BITS)) - 1;
       /* restore corresponding bits */
       rp[bn] |= save;
       if (nl - 1 > bn)
 	rp[bn + 1] = save2; /* the low b bits go in rp[0..bn] only, since
 			       they start by bit 0 in rp[0], so they use
 			       at most ceil(b/GMP_NUMB_BITS) limbs */
+      /* FIXME: Should we normalise {rp,rn} here ?*/
 
       /* 3: current buffers: {sp,sn}, {rp,rn}, {wp,wn} */
 
@@ -426,7 +427,7 @@
 	{
 	  mpn_sub (remp, up, un, qp, qn);
 	  rn = un;
-	  MPN_NORMALIZE (remp, rn);
+	  MPN_NORMALIZE_NOT_ZERO (remp, rn);
 	}
     }
 


More information about the gmp-commit mailing list