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

mercurial at gmplib.org mercurial at gmplib.org
Fri Jun 8 21:59:09 CEST 2012


details:   /var/hg/gmp/rev/b2a6b6b58028
changeset: 15049:b2a6b6b58028
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Jun 08 16:00:20 2012 +0200
description:
gmp-impl.h (__GMP_WITHIN_CONFIGURE): Use the same #if as in gmp-h.in.

details:   /var/hg/gmp/rev/46472b4e72bc
changeset: 15050:46472b4e72bc
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Jun 08 16:01:59 2012 +0200
description:
gmp-impl.h (MPN_NORMALIZE_NOT_ZERO): Tighter ASSERT.

details:   /var/hg/gmp/rev/bae4cf9a8b76
changeset: 15051:bae4cf9a8b76
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Jun 08 21:54:49 2012 +0200
description:
(MPZ_NEWALLOC): New macro. Use it in mpq and some mpz.

details:   /var/hg/gmp/rev/5047615e937b
changeset: 15052:5047615e937b
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Jun 08 21:59:03 2012 +0200
description:
mini-gmp/mini-gmp.c (mpz_realloc): remove a branch.

diffstat:

 ChangeLog           |  12 ++++++++++++
 gmp-impl.h          |  19 +++++++++++++++++--
 mini-gmp/mini-gmp.c |   3 +--
 mpq/abs.c           |   4 ++--
 mpq/get_den.c       |   2 +-
 mpq/get_num.c       |   2 +-
 mpq/inv.c           |   4 ++--
 mpq/neg.c           |   4 ++--
 mpq/set.c           |   4 ++--
 mpq/set_d.c         |   6 +++---
 mpq/set_den.c       |   2 +-
 mpq/set_f.c         |   6 +++---
 mpq/set_num.c       |   2 +-
 mpq/set_z.c         |   2 +-
 mpz/bin_uiui.c      |  10 +++++-----
 mpz/oddfac_1.c      |  12 +++++++-----
 mpz/prodlimbs.c     |   4 ++--
 17 files changed, 63 insertions(+), 35 deletions(-)

diffs (truncated from 354 to 300 lines):

diff -r 296c16554698 -r 5047615e937b ChangeLog
--- a/ChangeLog	Wed Jun 06 14:21:56 2012 +0200
+++ b/ChangeLog	Fri Jun 08 21:59:03 2012 +0200
@@ -1,3 +1,15 @@
+2012-06-08 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* gmp-impl.h (__GMP_WITHIN_CONFIGURE): Use the same #if as in gmp-h.in.
+	(MPN_NORMALIZE_NOT_ZERO): Tighter ASSERT.
+	(MPZ_NEWALLOC): New macro.
+	* mpq: Use the new macro when possible.
+	* mpz/bin_uiui.c: Likewise.
+	* mpz/oddfac_1.c: Likewise.
+	* mpz/prodlimbs.c: Likewise.
+
+	* mini-gmp/mini-gmp.c (mpz_realloc): remove a branch.
+
 2012-06-04  Torbjorn Granlund  <tege at gmplib.org>
 
 	* mpn/powerpc64/aix.m4 (ASM_START): Claim machine type "any".
diff -r 296c16554698 -r 5047615e937b gmp-impl.h
--- a/gmp-impl.h	Wed Jun 06 14:21:56 2012 +0200
+++ b/gmp-impl.h	Fri Jun 08 21:59:03 2012 +0200
@@ -129,7 +129,7 @@
 #define DECL_submul_1(name) \
   DECL_addmul_1 (name)
 
-#if ! __GMP_WITHIN_CONFIGURE
+#if ! defined (__GMP_WITHIN_CONFIGURE)
 #include "config.h"
 #include "gmp-mparam.h"
 #include "fib_table.h"
@@ -1840,9 +1840,9 @@
 #ifndef MPN_NORMALIZE_NOT_ZERO
 #define MPN_NORMALIZE_NOT_ZERO(DST, NLIMBS)				\
   do {									\
-    ASSERT ((NLIMBS) >= 1);						\
     while (1)								\
       {									\
+	ASSERT ((NLIMBS) >= 1);						\
 	if ((DST)[(NLIMBS) - 1] != 0)					\
 	  break;							\
 	(NLIMBS)--;							\
@@ -1880,10 +1880,25 @@
     __x->_mp_d = TMP_ALLOC_LIMBS (NLIMBS);				\
   } while (0)
 
+#if WANT_ASSERT
+static void *
+_mpz_newalloc (mpz_ptr z, mp_size_t n)
+{
+  void * res = _mpz_realloc(z,n);
+  /* If we are checking the code, force a random change to limbs. */
+  ((mp_ptr) res)[0] = ~ ((mp_ptr) res)[ALLOC (z) - 1];
+  return res;
+}
+#else
+#define _mpz_newalloc _mpz_realloc
+#endif
 /* Realloc for an mpz_t WHAT if it has less than NEEDED limbs.  */
 #define MPZ_REALLOC(z,n) (UNLIKELY ((n) > ALLOC(z))			\
 			  ? (mp_ptr) _mpz_realloc(z,n)			\
 			  : PTR(z))
+#define MPZ_NEWALLOC(z,n) (UNLIKELY ((n) > ALLOC(z))			\
+			   ? (mp_ptr) _mpz_newalloc(z,n)		\
+			   : PTR(z))
 
 #define MPZ_EQUAL_1_P(z)  (SIZ(z)==1 && PTR(z)[0] == 1)
 
diff -r 296c16554698 -r 5047615e937b mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Wed Jun 06 14:21:56 2012 +0200
+++ b/mini-gmp/mini-gmp.c	Fri Jun 08 21:59:03 2012 +0200
@@ -1322,8 +1322,7 @@
 static void *
 mpz_realloc (mpz_t r, mp_size_t size)
 {
-  if (size < 1)
-    size = 1;
+  size = GMP_MAX (size, 1);
 
   r->_mp_d = gmp_xrealloc_limbs (r->_mp_d, size);
   r->_mp_alloc = size;
diff -r 296c16554698 -r 5047615e937b mpq/abs.c
--- a/mpq/abs.c	Wed Jun 06 14:21:56 2012 +0200
+++ b/mpq/abs.c	Fri Jun 08 21:59:03 2012 +0200
@@ -33,10 +33,10 @@
       mp_size_t  den_size = SIZ(DEN(src));
       mp_ptr dp;
 
-      dp = MPZ_REALLOC (NUM(dst), num_abs_size);
+      dp = MPZ_NEWALLOC (NUM(dst), num_abs_size);
       MPN_COPY (dp, PTR(NUM(src)), num_abs_size);
 
-      dp = MPZ_REALLOC (DEN(dst), den_size);
+      dp = MPZ_NEWALLOC (DEN(dst), den_size);
       SIZ(DEN(dst)) = den_size;
       MPN_COPY (dp, PTR(DEN(src)), den_size);
     }
diff -r 296c16554698 -r 5047615e937b mpq/get_den.c
--- a/mpq/get_den.c	Wed Jun 06 14:21:56 2012 +0200
+++ b/mpq/get_den.c	Fri Jun 08 21:59:03 2012 +0200
@@ -26,7 +26,7 @@
   mp_size_t size = SIZ(DEN(src));
   mp_ptr dp;
 
-  dp = MPZ_REALLOC (den, size);
+  dp = MPZ_NEWALLOC (den, size);
   SIZ(den) = size;
   MPN_COPY (dp, PTR(DEN(src)), size);
 }
diff -r 296c16554698 -r 5047615e937b mpq/get_num.c
--- a/mpq/get_num.c	Wed Jun 06 14:21:56 2012 +0200
+++ b/mpq/get_num.c	Fri Jun 08 21:59:03 2012 +0200
@@ -27,7 +27,7 @@
   mp_size_t abs_size = ABS (size);
   mp_ptr dp;
 
-  dp = MPZ_REALLOC (num, abs_size);
+  dp = MPZ_NEWALLOC (num, abs_size);
   SIZ(num) = size;
 
   MPN_COPY (dp, PTR(NUM(src)), abs_size);
diff -r 296c16554698 -r 5047615e937b mpq/inv.c
--- a/mpq/inv.c	Wed Jun 06 14:21:56 2012 +0200
+++ b/mpq/inv.c	Fri Jun 08 21:59:03 2012 +0200
@@ -51,10 +51,10 @@
       mp_ptr dp;
 
       den_size = ABS (den_size);
-      dp = MPZ_REALLOC (NUM(dest), den_size);
+      dp = MPZ_NEWALLOC (NUM(dest), den_size);
       MPN_COPY (dp, PTR(DEN(src)), den_size);
 
-      dp = MPZ_REALLOC (DEN(dest), num_size);
+      dp = MPZ_NEWALLOC (DEN(dest), num_size);
       MPN_COPY (dp, PTR(NUM(src)), num_size);
     }
 }
diff -r 296c16554698 -r 5047615e937b mpq/neg.c
--- a/mpq/neg.c	Wed Jun 06 14:21:56 2012 +0200
+++ b/mpq/neg.c	Fri Jun 08 21:59:03 2012 +0200
@@ -34,11 +34,11 @@
       mp_ptr dp;
 
       size = ABS(num_size);
-      dp = MPZ_REALLOC (NUM(dst), size);
+      dp = MPZ_NEWALLOC (NUM(dst), size);
       MPN_COPY (dp, PTR(NUM(src)), size);
 
       size = SIZ(DEN(src));
-      dp = MPZ_REALLOC (DEN(dst), size);
+      dp = MPZ_NEWALLOC (DEN(dst), size);
       SIZ(DEN(dst)) = size;
       MPN_COPY (dp, PTR(DEN(src)), size);
     }
diff -r 296c16554698 -r 5047615e937b mpq/set.c
--- a/mpq/set.c	Wed Jun 06 14:21:56 2012 +0200
+++ b/mpq/set.c	Fri Jun 08 21:59:03 2012 +0200
@@ -29,12 +29,12 @@
 
   num_size = SIZ(NUM(src));
   abs_num_size = ABS (num_size);
-  dp = MPZ_REALLOC (NUM(dest), abs_num_size);
+  dp = MPZ_NEWALLOC (NUM(dest), abs_num_size);
   SIZ(NUM(dest)) = num_size;
   MPN_COPY (dp, PTR(NUM(src)), abs_num_size);
 
   den_size = SIZ(DEN(src));
-  dp = MPZ_REALLOC (DEN(dest), den_size);
+  dp = MPZ_NEWALLOC (DEN(dest), den_size);
   SIZ(DEN(dest)) = den_size;
   MPN_COPY (dp, PTR(DEN(src)), den_size);
 }
diff -r 296c16554698 -r 5047615e937b mpq/set_d.c
--- a/mpq/set_d.c	Wed Jun 06 14:21:56 2012 +0200
+++ b/mpq/set_d.c	Fri Jun 08 21:59:03 2012 +0200
@@ -71,7 +71,7 @@
 	}
 
       dn = -exp;
-      np = MPZ_REALLOC (NUM(dest), 3);
+      np = MPZ_NEWALLOC (NUM(dest), 3);
 #if LIMBS_PER_DOUBLE == 4
       if ((tp[0] | tp[1] | tp[2]) == 0)
 	np[0] = tp[3], nn = 1;
@@ -98,7 +98,7 @@
 #endif
       dn += nn + 1;
       ASSERT_ALWAYS (dn > 0);
-      dp = MPZ_REALLOC (DEN(dest), dn);
+      dp = MPZ_NEWALLOC (DEN(dest), dn);
       MPN_ZERO (dp, dn - 1);
       dp[dn - 1] = 1;
       count_trailing_zeros (c, np[0] | dp[0]);
@@ -115,7 +115,7 @@
   else
     {
       nn = exp;
-      np = MPZ_REALLOC (NUM(dest), nn);
+      np = MPZ_NEWALLOC (NUM(dest), nn);
       switch (nn)
         {
 	default:
diff -r 296c16554698 -r 5047615e937b mpq/set_den.c
--- a/mpq/set_den.c	Wed Jun 06 14:21:56 2012 +0200
+++ b/mpq/set_den.c	Fri Jun 08 21:59:03 2012 +0200
@@ -28,7 +28,7 @@
   mp_size_t abs_size = ABS (size);
   mp_ptr dp;
 
-  dp = MPZ_REALLOC (DEN(dest), abs_size);
+  dp = MPZ_NEWALLOC (DEN(dest), abs_size);
 
   SIZ(DEN(dest)) = size;
   MPN_COPY (dp, PTR(den), abs_size);
diff -r 296c16554698 -r 5047615e937b mpq/set_f.c
--- a/mpq/set_f.c	Wed Jun 06 14:21:56 2012 +0200
+++ b/mpq/set_f.c	Fri Jun 08 21:59:03 2012 +0200
@@ -49,7 +49,7 @@
       /* radix point is to the right of the limbs, no denominator */
       mp_ptr  num_ptr;
 
-      num_ptr = MPZ_REALLOC (mpq_numref (q), fexp);
+      num_ptr = MPZ_NEWALLOC (mpq_numref (q), fexp);
       MPN_ZERO (num_ptr, fexp - abs_fsize);
       MPN_COPY (num_ptr + fexp - abs_fsize, fptr, abs_fsize);
 
@@ -64,8 +64,8 @@
       mp_size_t  den_size;
 
       den_size = abs_fsize - fexp;
-      num_ptr = MPZ_REALLOC (mpq_numref (q), abs_fsize);
-      den_ptr = MPZ_REALLOC (mpq_denref (q), den_size+1);
+      num_ptr = MPZ_NEWALLOC (mpq_numref (q), abs_fsize);
+      den_ptr = MPZ_NEWALLOC (mpq_denref (q), den_size+1);
 
       if (flow & 1)
         {
diff -r 296c16554698 -r 5047615e937b mpq/set_num.c
--- a/mpq/set_num.c	Wed Jun 06 14:21:56 2012 +0200
+++ b/mpq/set_num.c	Fri Jun 08 21:59:03 2012 +0200
@@ -27,7 +27,7 @@
   mp_size_t abs_size = ABS (size);
   mp_ptr dp;
 
-  dp = MPZ_REALLOC (NUM(dest), abs_size);
+  dp = MPZ_NEWALLOC (NUM(dest), abs_size);
 
   SIZ(NUM(dest)) = size;
   MPN_COPY (dp, PTR(num), abs_size);
diff -r 296c16554698 -r 5047615e937b mpq/set_z.c
--- a/mpq/set_z.c	Wed Jun 06 14:21:56 2012 +0200
+++ b/mpq/set_z.c	Fri Jun 08 21:59:03 2012 +0200
@@ -29,7 +29,7 @@
 
   num_size = SIZ (src);
   abs_num_size = ABS (num_size);
-  dp = MPZ_REALLOC (NUM(dest), abs_num_size);
+  dp = MPZ_NEWALLOC (NUM(dest), abs_num_size);
   SIZ(NUM(dest)) = num_size;
   MPN_COPY (dp, PTR(src), abs_num_size);
 
diff -r 296c16554698 -r 5047615e937b mpz/bin_uiui.c
--- a/mpz/bin_uiui.c	Wed Jun 06 14:21:56 2012 +0200
+++ b/mpz/bin_uiui.c	Fri Jun 08 21:59:03 2012 +0200
@@ -294,9 +294,9 @@
 
   nn -= np[nn - 1] == 0;	/* normalisation */
 
-  MPZ_REALLOC (r, nn);
+  kp = MPZ_NEWALLOC (r, nn);
   SIZ(r) = nn;
-  MPN_COPY (PTR(r), np, nn);
+  MPN_COPY (kp, np, nn);
   TMP_FREE;
 }
 
@@ -312,7 +312,7 @@
   count_leading_zeros (cnt, (mp_limb_t) n);
   cnt = GMP_LIMB_BITS - cnt;
   alloc = cnt * k / GMP_NUMB_BITS + 3;	/* FIXME: ensure rounding is enough. */
-  rp = MPZ_REALLOC (r, alloc);
+  rp = MPZ_NEWALLOC (r, alloc);
 
   MAXFACS (nmax, n);
   nmax = MIN (nmax, M);
@@ -411,8 +411,8 @@
     mp_limb_t buffer[ODD_CENTRAL_BINOMIAL_TABLE_LIMIT + 3];
     mpz_t t;
 
-    t->_mp_alloc = ODD_CENTRAL_BINOMIAL_TABLE_LIMIT + 3;
-    t->_mp_d = buffer;
+    ALLOC (t) = ODD_CENTRAL_BINOMIAL_TABLE_LIMIT + 3;
+    PTR (t) = buffer;
     if ((! BIN_UIUI_RECURSIVE_SMALLDC) || k <= ODD_FACTORIAL_TABLE_LIMIT)
       mpz_smallk_bin_uiui (t, n, k);
     else
diff -r 296c16554698 -r 5047615e937b mpz/oddfac_1.c
--- a/mpz/oddfac_1.c	Wed Jun 06 14:21:56 2012 +0200
+++ b/mpz/oddfac_1.c	Fri Jun 08 21:59:03 2012 +0200
@@ -284,8 +284,10 @@


More information about the gmp-commit mailing list