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

mercurial at gmplib.org mercurial at gmplib.org
Thu Nov 5 11:18:53 UTC 2015


details:   /var/hg/gmp/rev/c1446dce3dab
changeset: 16938:c1446dce3dab
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Nov 05 12:14:40 2015 +0100
description:
mini-gmp: New functions mpn_com, mpn_neg.

details:   /var/hg/gmp/rev/ff5a9af2d807
changeset: 16939:ff5a9af2d807
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Nov 05 12:16:47 2015 +0100
description:
mpz/xor.c: Use NEWALLOC, and NORMALIZE_NOT_ZERO.

details:   /var/hg/gmp/rev/c0ed3ac5ce4b
changeset: 16940:c0ed3ac5ce4b
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Nov 05 12:17:05 2015 +0100
description:
mpz/and.c: Use MPZ_NEWALLOC.

details:   /var/hg/gmp/rev/ef7f8ee4ab39
changeset: 16941:ef7f8ee4ab39
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Nov 05 12:18:16 2015 +0100
description:
mpz/init*.c: Remove conditional code for __CHECKER__

diffstat:

 mini-gmp/mini-gmp.c |  61 ++++++++++++++++++++++++++++------------------------
 mini-gmp/mini-gmp.h |   3 ++
 mpz/and.c           |  12 +++++-----
 mpz/init.c          |   5 ----
 mpz/init2.c         |   5 ----
 mpz/inits.c         |   5 ----
 mpz/iset.c          |   6 -----
 mpz/iset_str.c      |   5 ----
 mpz/xor.c           |   7 ++++-
 9 files changed, 47 insertions(+), 62 deletions(-)

diffs (247 lines):

diff -r 5586e38395fc -r ef7f8ee4ab39 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Wed Nov 04 19:24:35 2015 +0100
+++ b/mini-gmp/mini-gmp.c	Thu Nov 05 12:18:16 2015 +0100
@@ -70,7 +70,7 @@
 #define GMP_MAX(a, b) ((a) > (b) ? (a) : (b))
 
 #define gmp_assert_nocarry(x) do { \
-    mp_limb_t __cy = x;		   \
+    mp_limb_t __cy = (x);	   \
     assert (__cy == 0);		   \
   } while (0)
 
@@ -701,6 +701,28 @@
 			  i, ptr, i, GMP_LIMB_MAX);
 }
 
+void
+mpn_com (mp_ptr rp, mp_srcptr up, mp_size_t n)
+{
+  while (--n >= 0)
+    *rp++ = ~ *up++;
+}
+
+mp_limb_t
+mpn_neg (mp_ptr rp, mp_srcptr up, mp_size_t n)
+{
+  while (*up == 0)
+    {
+      *rp = 0;
+      if (!--n)
+	return 0;
+      ++up; ++rp;
+    }
+  *rp = - *up;
+  mpn_com (++rp, ++up, --n);
+  return 1;
+}
+
 
 /* MPN division interface. */
 mp_limb_t
@@ -2377,16 +2399,9 @@
 	{
 	  /* Have to negate and sign extend. */
 	  mp_size_t i;
-	  mp_limb_t cy;
-
-	  for (cy = 1, i = 0; i < un; i++)
-	    {
-	      mp_limb_t s = ~u->_mp_d[i] + cy;
-	      cy = s < cy;
-	      rp[i] = s;
-	    }
-	  assert (cy == 0);
-	  for (; i < rn - 1; i++)
+
+	  gmp_assert_nocarry (! mpn_neg (rp, u->_mp_d, un));
+	  for (i = un; i < rn - 1; i++)
 	    rp[i] = GMP_LIMB_MAX;
 
 	  rp[rn-1] = mask;
@@ -2411,23 +2426,13 @@
       if (mode == ((us > 0) ? GMP_DIV_CEIL : GMP_DIV_FLOOR)) /* us != 0 here. */
 	{
 	  /* If r != 0, compute 2^{bit_count} - r. */
-	  mp_size_t i;
-
-	  for (i = 0; i < rn && rp[i] == 0; i++)
-	    ;
-	  if (i < rn)
-	    {
-	      /* r > 0, need to flip sign. */
-	      rp[i] = ~rp[i] + 1;
-	      while (++i < rn)
-		rp[i] = ~rp[i];
-
-	      rp[rn-1] &= mask;
-
-	      /* us is not used for anything else, so we can modify it
-		 here to indicate flipped sign. */
-	      us = -us;
-	    }
+	  mpn_neg (rp, rp, rn);
+
+	  rp[rn-1] &= mask;
+	      
+	  /* us is not used for anything else, so we can modify it
+	     here to indicate flipped sign. */
+	  us = -us;
 	}
     }
   rn = mpn_normalized_size (rp, rn);
diff -r 5586e38395fc -r ef7f8ee4ab39 mini-gmp/mini-gmp.h
--- a/mini-gmp/mini-gmp.h	Wed Nov 04 19:24:35 2015 +0100
+++ b/mini-gmp/mini-gmp.h	Thu Nov 05 12:18:16 2015 +0100
@@ -108,6 +108,9 @@
 mp_bitcnt_t mpn_scan0 (mp_srcptr, mp_bitcnt_t);
 mp_bitcnt_t mpn_scan1 (mp_srcptr, mp_bitcnt_t);
 
+void mpn_com (mp_ptr, mp_srcptr, mp_size_t);
+mp_limb_t mpn_neg (mp_ptr, mp_srcptr, mp_size_t);
+
 mp_bitcnt_t mpn_popcount (mp_srcptr, mp_size_t);
 
 mp_limb_t mpn_invert_3by2 (mp_limb_t, mp_limb_t);
diff -r 5586e38395fc -r ef7f8ee4ab39 mpz/and.c
--- a/mpz/and.c	Wed Nov 04 19:24:35 2015 +0100
+++ b/mpz/and.c	Thu Nov 05 12:18:16 2015 +0100
@@ -1,7 +1,7 @@
 /* mpz_and -- Logical and.
 
-Copyright 1991, 1993, 1994, 1996, 1997, 2000, 2001, 2003, 2005, 2012 Free
-Software Foundation, Inc.
+Copyright 1991, 1993, 1994, 1996, 1997, 2000, 2001, 2003, 2005, 2012,
+2015 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -62,7 +62,7 @@
 
 	  /* Handle allocation, now then we know exactly how much space is
 	     needed for the result.  */
-	  res_ptr = MPZ_REALLOC (res, res_size);
+	  res_ptr = MPZ_NEWALLOC (res, res_size);
 	  /* Don't re-read op1_ptr and op2_ptr.  Since res_size <=
 	     MIN(op1_size, op2_size), res is not changed when op1
 	     is identical to res or op2 is identical to res.  */
@@ -107,7 +107,7 @@
 	  mpn_sub_1 (opy, op2_ptr, op2_size, (mp_limb_t) 1);
 	  op2_ptr = opy;
 
-	  res_ptr = MPZ_REALLOC (res, 1 + op2_size);
+	  res_ptr = MPZ_NEWALLOC (res, 1 + op2_size);
 	  /* Don't re-read OP1_PTR and OP2_PTR.  They point to temporary
 	     space--never to the space PTR(res) used to point to before
 	     reallocation.  */
@@ -206,7 +206,7 @@
 
 	/* Handle allocation, now then we know exactly how much space is
 	   needed for the result.  */
-	res_ptr = MPZ_REALLOC (res, res_size);
+	res_ptr = MPZ_NEWALLOC (res, res_size);
 	/* Don't re-read OP1_PTR or OP2_PTR.  Since res_size = op1_size,
 	   op1 is not changed if it is identical to res.
 	   OP2_PTR points to temporary space.  */
@@ -227,7 +227,7 @@
 
 	/* Handle allocation, now then we know exactly how much space is
 	   needed for the result.  */
-	res_ptr = MPZ_REALLOC (res, res_size);
+	res_ptr = MPZ_NEWALLOC (res, res_size);
 	/* Don't re-read OP1_PTR.  Since res_size <= op1_size,
 	   op1 is not changed if it is identical to res.
 	   Don't re-read OP2_PTR.  It points to temporary space--never
diff -r 5586e38395fc -r ef7f8ee4ab39 mpz/init.c
--- a/mpz/init.c	Wed Nov 04 19:24:35 2015 +0100
+++ b/mpz/init.c	Thu Nov 05 12:18:16 2015 +0100
@@ -37,9 +37,4 @@
   ALLOC (x) = 1;
   PTR (x) = __GMP_ALLOCATE_FUNC_LIMBS (1);
   SIZ (x) = 0;
-
-#ifdef __CHECKER__
-  /* let the low limb look initialized, for the benefit of mpz_get_ui etc */
-  PTR (x)[0] = 0;
-#endif
 }
diff -r 5586e38395fc -r ef7f8ee4ab39 mpz/init2.c
--- a/mpz/init2.c	Wed Nov 04 19:24:35 2015 +0100
+++ b/mpz/init2.c	Thu Nov 05 12:18:16 2015 +0100
@@ -53,9 +53,4 @@
   PTR(x) = __GMP_ALLOCATE_FUNC_LIMBS (new_alloc);
   ALLOC(x) = new_alloc;
   SIZ(x) = 0;
-
-#ifdef __CHECKER__
-  /* let the low limb look initialized, for the benefit of mpz_get_ui etc */
-  PTR(x)[0] = 0;
-#endif
 }
diff -r 5586e38395fc -r ef7f8ee4ab39 mpz/inits.c
--- a/mpz/inits.c	Wed Nov 04 19:24:35 2015 +0100
+++ b/mpz/inits.c	Thu Nov 05 12:18:16 2015 +0100
@@ -45,11 +45,6 @@
       PTR (x) = __GMP_ALLOCATE_FUNC_LIMBS (1);
       SIZ (x) = 0;
 
-#ifdef __CHECKER__
-      /* let the low limb look initialized, for the benefit of mpz_get_ui etc */
-      PTR (x)[0] = 0;
-#endif
-
       x = va_arg (ap, mpz_ptr);
     }
 
diff -r 5586e38395fc -r ef7f8ee4ab39 mpz/iset.c
--- a/mpz/iset.c	Wed Nov 04 19:24:35 2015 +0100
+++ b/mpz/iset.c	Thu Nov 05 12:18:16 2015 +0100
@@ -50,10 +50,4 @@
 
   MPN_COPY (wp, up, size);
   SIZ (w) = usize;
-
-#ifdef __CHECKER__
-  /* let the low limb look initialized, for the benefit of mpz_get_ui etc */
-  if (size == 0)
-    wp[0] = 0;
-#endif
 }
diff -r 5586e38395fc -r ef7f8ee4ab39 mpz/iset_str.c
--- a/mpz/iset_str.c	Wed Nov 04 19:24:35 2015 +0100
+++ b/mpz/iset_str.c	Thu Nov 05 12:18:16 2015 +0100
@@ -43,10 +43,5 @@
   /* if str has no digits mpz_set_str leaves x->_mp_size unset */
   SIZ (x) = 0;
 
-#ifdef __CHECKER__
-  /* let the low limb look initialized, for the benefit of mpz_get_ui etc */
-  PTR (x)[0] = 0;
-#endif
-
   return mpz_set_str (x, str, base);
 }
diff -r 5586e38395fc -r ef7f8ee4ab39 mpz/xor.c
--- a/mpz/xor.c	Wed Nov 04 19:24:35 2015 +0100
+++ b/mpz/xor.c	Thu Nov 05 12:18:16 2015 +0100
@@ -122,7 +122,10 @@
 	    MPN_SRCPTR_SWAP (op1_ptr,op1_size, op2_ptr,op2_size);
 
 	  res_alloc = op2_size;
-	  res_ptr = MPZ_REALLOC (res, res_alloc);
+	  res_ptr = MPZ_NEWALLOC (res, res_alloc);
+	  /* Don't re-read OP1_PTR and OP2_PTR.  They point to temporary
+	     space--never to the space PTR(res) used to point to before
+	     reallocation.  */
 
 	  MPN_COPY (res_ptr + op1_size, op2_ptr + op1_size,
 		    op2_size - op1_size);
@@ -184,7 +187,7 @@
     res_ptr[res_size] = cy;
     res_size += (cy != 0);
 
-    MPN_NORMALIZE (res_ptr, res_size);
+    MPN_NORMALIZE_NOT_ZERO (res_ptr, res_size);
     SIZ(res) = -res_size;
     TMP_FREE;
   }


More information about the gmp-commit mailing list