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

mercurial at gmplib.org mercurial at gmplib.org
Wed Aug 10 22:03:49 CEST 2011


details:   /var/hg/gmp/rev/d29e5e9fc55e
changeset: 14228:d29e5e9fc55e
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Wed Aug 10 21:19:35 2011 +0200
description:
(check_bigc): Call abort after reporting error.

details:   /var/hg/gmp/rev/ddec7ec349fd
changeset: 14229:ddec7ec349fd
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Wed Aug 10 22:03:19 2011 +0200
description:
(DIGITS_IN_BASEGT2_FROM_BITS): New.
(DIGITS_IN_BASE_FROM_BITS): Compute more accurate result.
(MPN_SIZEINBASE): Use DIGITS_IN_BASEGT2_FROM_BITS.

details:   /var/hg/gmp/rev/95fe5c7e63f1
changeset: 14230:95fe5c7e63f1
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Wed Aug 10 22:03:31 2011 +0200
description:
*** empty log message ***

diffstat:

 ChangeLog             |   8 ++++++++
 gmp-impl.h            |  32 +++++++++++++++++++++-----------
 tests/rand/t-lc2exp.c |   1 +
 3 files changed, 30 insertions(+), 11 deletions(-)

diffs (90 lines):

diff -r 82e5aca212f2 -r 95fe5c7e63f1 ChangeLog
--- a/ChangeLog	Tue Aug 09 21:54:42 2011 +0200
+++ b/ChangeLog	Wed Aug 10 22:03:31 2011 +0200
@@ -1,3 +1,11 @@
+2011-08-10  Torbjorn Granlund  <tege at gmplib.org>
+
+	* gmp-impl.h (DIGITS_IN_BASEGT2_FROM_BITS): New.
+	(DIGITS_IN_BASE_FROM_BITS): Compute more accurate result.
+	(MPN_SIZEINBASE): Use DIGITS_IN_BASEGT2_FROM_BITS.
+
+	* tests/rand/t-lc2exp.c (check_bigc): Call abort after reporting error.
+
 2011-08-09  Torbjorn Granlund  <tege at gmplib.org>
 
 	* mpz/out_str.c (mpz_out_str): Reinsert accidentally deleted str_size
diff -r 82e5aca212f2 -r 95fe5c7e63f1 gmp-impl.h
--- a/gmp-impl.h	Tue Aug 09 21:54:42 2011 +0200
+++ b/gmp-impl.h	Wed Aug 10 22:03:31 2011 +0200
@@ -2615,12 +2615,22 @@
 
 
 /* Compute the number of digits in base for nbits bits, making sure the result
-   is never too small.  */
+   is never too small.  The two variants of the macro implement the same
+   function; the GT2 variant below works just for bases > 2.  */
 #define DIGITS_IN_BASE_FROM_BITS(res, nbits, b)				\
   do {									\
-    mp_limb_t ph, dummy;						\
-    umul_ppmm (ph, dummy, mp_bases[b].logb2, nbits);			\
-    res = ph + 1;							\
+    mp_limb_t _ph, _dummy;						\
+    size_t _nbits = (nbits);						\
+    umul_ppmm (_ph, _dummy, mp_bases[b].logb2, _nbits);			\
+    _ph += (_dummy + _nbits < _dummy);					\
+    res = _ph + 1;							\
+  } while (0)
+#define DIGITS_IN_BASEGT2_FROM_BITS(res, nbits, b)			\
+  do {									\
+    mp_limb_t _ph, _dummy;						\
+    size_t _nbits = (nbits);						\
+    umul_ppmm (_ph, _dummy, mp_bases[b].logb2 + 1, _nbits);		\
+    res = _ph + 1;							\
   } while (0)
 
 /* For power of 2 bases this is exact.  For other bases the result is either
@@ -2657,7 +2667,7 @@
           }                                                             \
         else                                                            \
 	  {								\
-	    DIGITS_IN_BASE_FROM_BITS (result, __totbits, base);		\
+	    DIGITS_IN_BASEGT2_FROM_BITS (result, __totbits, base);	\
 	  }								\
       }                                                                 \
   } while (0)
@@ -4048,18 +4058,18 @@
    down.  */
 #define DIGITS_IN_BASE_PER_LIMB(res, nlimbs, b)				\
   do {									\
-    mp_limb_t ph, dummy;						\
-    umul_ppmm (ph, dummy, mp_bases[b].logb2, GMP_NUMB_BITS * (nlimbs));	\
-    res = ph;								\
+    mp_limb_t _ph, _dummy;						\
+    umul_ppmm (_ph, _dummy, mp_bases[b].logb2, GMP_NUMB_BITS * (nlimbs));	\
+    res = _ph;								\
   } while (0)
 
 /* Compute the number of limbs corresponding to ndigits base-b digits, rounding
    up.  */
 #define LIMBS_PER_DIGIT_IN_BASE(res, ndigits, b)			\
   do {									\
-    mp_limb_t ph, dummy;						\
-    umul_ppmm (ph, dummy, mp_bases[base].log2b, ndigits);		\
-    res = 8 * ph / GMP_NUMB_BITS + 2;					\
+    mp_limb_t _ph, _dummy;						\
+    umul_ppmm (_ph, _dummy, mp_bases[base].log2b, (ndigits));		\
+    res = 8 * _ph / GMP_NUMB_BITS + 2;					\
   } while (0)
 
 
diff -r 82e5aca212f2 -r 95fe5c7e63f1 tests/rand/t-lc2exp.c
--- a/tests/rand/t-lc2exp.c	Tue Aug 09 21:54:42 2011 +0200
+++ b/tests/rand/t-lc2exp.c	Wed Aug 10 22:03:31 2011 +0200
@@ -108,6 +108,7 @@
           printf     ("   m2exp=%lu\n", m2exp);
           gmp_printf ("   rand=%#ZX\n", a);
           gmp_printf ("   sizeinbase2=%u\n", mpz_sizeinbase (a, 2));
+	  abort ();
         }
     }
 


More information about the gmp-commit mailing list