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

mercurial at gmplib.org mercurial at gmplib.org
Sat Dec 8 11:03:46 UTC 2018


details:   /var/hg/gmp/rev/0c2e952fe1a7
changeset: 17721:0c2e952fe1a7
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Dec 08 11:49:07 2018 +0100
description:
tests/mpz/: Use TESTS_REPS.

details:   /var/hg/gmp/rev/13cf603961d2
changeset: 17722:13cf603961d2
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Dec 08 11:59:31 2018 +0100
description:
mini-gmp/tests/t-div.c: use unsigned long for mpz_*_ui return value (tx Paul)

details:   /var/hg/gmp/rev/94da90db24e2
changeset: 17723:94da90db24e2
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Dec 08 12:00:47 2018 +0100
description:
mini-gmp/mini-mpq.c: Don't use _roinit if types has different sizes.

details:   /var/hg/gmp/rev/230246fe9acd
changeset: 17724:230246fe9acd
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Dec 08 12:02:53 2018 +0100
description:
mini-gmp/mini-gmp.c: Do not mix GMP_LIMB_HIGHBIT and ULONG_M{IN,AX}

details:   /var/hg/gmp/rev/ad2fba4b602d
changeset: 17725:ad2fba4b602d
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Dec 08 12:03:14 2018 +0100
description:
Copyright years

diffstat:

 mini-gmp/mini-gmp.c          |  56 ++++++++++++++++++++++++++-----------------
 mini-gmp/mini-mpq.c          |  20 ++++++++++++++-
 mini-gmp/tests/hex-random.c  |   2 +-
 mini-gmp/tests/hex-random.h  |   2 +-
 mini-gmp/tests/mini-random.c |   2 +-
 mini-gmp/tests/mini-random.h |   2 +-
 mini-gmp/tests/t-div.c       |   2 +-
 tests/mpz/bit.c              |   3 +-
 tests/mpz/dive_ui.c          |   3 +-
 tests/mpz/io.c               |   3 +-
 tests/mpz/logic.c            |   3 +-
 tests/mpz/t-addsub.c         |   3 +-
 tests/mpz/t-aorsmul.c        |   3 +-
 tests/mpz/t-cdiv_ui.c        |   3 +-
 tests/mpz/t-cong.c           |   3 +-
 tests/mpz/t-div_2exp.c       |   3 +-
 tests/mpz/t-fdiv.c           |   3 +-
 tests/mpz/t-fdiv_ui.c        |   3 +-
 tests/mpz/t-nextprime.c      |   3 +-
 tests/mpz/t-perfpow.c        |   4 +-
 tests/mpz/t-perfsqr.c        |   3 +-
 tests/mpz/t-pow.c            |   3 +-
 tests/mpz/t-remove.c         |   3 +-
 tests/mpz/t-tdiv_ui.c        |   3 +-
 24 files changed, 91 insertions(+), 47 deletions(-)

diffs (truncated from 467 to 300 lines):

diff -r ba8b7b6c9b1a -r ad2fba4b602d mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Fri Nov 30 17:35:17 2018 +0100
+++ b/mini-gmp/mini-gmp.c	Sat Dec 08 12:03:14 2018 +0100
@@ -58,7 +58,7 @@
 /* Macros */
 #define GMP_LIMB_BITS (sizeof(mp_limb_t) * CHAR_BIT)
 
-#define GMP_LIMB_MAX (~ (mp_limb_t) 0)
+#define GMP_LIMB_MAX ((mp_limb_t) ~ (mp_limb_t) 0)
 #define GMP_LIMB_HIGHBIT ((mp_limb_t) 1 << (GMP_LIMB_BITS - 1))
 
 #define GMP_HLIMB_BIT ((mp_limb_t) 1 << (GMP_LIMB_BITS / 2))
@@ -1029,7 +1029,7 @@
 
   if (shift > 0)
     {
-      assert ((r0 << (GMP_LIMB_BITS - shift)) == 0);
+      assert ((r0 & GMP_LIMB_MAX >> GMP_LIMB_BITS - shift) == 0);
       r0 = (r0 >> shift) | (r1 << (GMP_LIMB_BITS - shift));
       r1 >>= shift;
     }
@@ -1252,7 +1252,7 @@
       l = w << binv->shift;
 
       gmp_udiv_qrnnd_preinv (w, r, h, l, binv->d1, binv->di);
-      assert ( (r << (GMP_LIMB_BITS - binv->shift)) == 0);
+      assert ((r & GMP_LIMB_MAX >> GMP_LIMB_BITS - binv->shift) == 0);
       r >>= binv->shift;
 
       sp[i] = r;
@@ -1420,7 +1420,7 @@
 void
 mpz_init (mpz_t r)
 {
-  static const mp_limb_t dummy_limb = 0xc1a0;
+  static const mp_limb_t dummy_limb = GMP_LIMB_MAX & 0xc1a0;
 
   r->_mp_alloc = 0;
   r->_mp_size = 0;
@@ -1540,9 +1540,9 @@
   mp_size_t us = u->_mp_size;
 
   if (us == 1)
-    return u->_mp_d[0] < GMP_LIMB_HIGHBIT;
+    return u->_mp_d[0] <= LONG_MAX;
   else if (us == -1)
-    return u->_mp_d[0] <= GMP_LIMB_HIGHBIT;
+    return u->_mp_d[0] <= GMP_NEG_CAST (mp_limb_t, LONG_MIN);
   else
     return (us == 0);
 }
@@ -1558,11 +1558,13 @@
 long int
 mpz_get_si (const mpz_t u)
 {
+  unsigned long r = mpz_get_ui (u);
+
   if (u->_mp_size < 0)
-    /* This expression is necessary to properly handle 0x80000000 */
-    return -1 - (long) ((u->_mp_d[0] - 1) & ~GMP_LIMB_HIGHBIT);
+    /* This expression is necessary to properly handle -LONG_MIN */
+    return -(long) 1 - (long) ((r - 1) & LONG_MAX);
   else
-    return (long) (mpz_get_ui (u) & ~GMP_LIMB_HIGHBIT);
+    return (long) (r & LONG_MAX);
 }
 
 unsigned long int
@@ -1807,14 +1809,18 @@
 {
   mp_size_t usize = u->_mp_size;
 
-  if (usize < -1)
-    return -1;
-  else if (v >= 0)
+  if (v >= 0)
     return mpz_cmp_ui (u, v);
   else if (usize >= 0)
     return 1;
+  else if (usize < -1)
+    return -1;
   else /* usize == -1 */
-    return GMP_CMP (GMP_NEG_CAST (mp_limb_t, v), u->_mp_d[0]);
+    {
+      unsigned long uu = mpz_get_ui (u);
+      unsigned long vv = GMP_NEG_CAST (mp_limb_t, v);
+      return GMP_CMP(vv, uu);
+    }
 }
 
 int
@@ -1822,12 +1828,15 @@
 {
   mp_size_t usize = u->_mp_size;
 
-  if (usize > 1)
+  if (usize < 0)
+    return -1;
+  else if (usize > 1)
     return 1;
-  else if (usize < 0)
-    return -1;
   else
-    return GMP_CMP (mpz_get_ui (u), v);
+    {
+      unsigned long uu = mpz_get_ui (u);
+      return GMP_CMP(uu, v);
+    }
 }
 
 int
@@ -1850,7 +1859,10 @@
   if (GMP_ABS (u->_mp_size) > 1)
     return 1;
   else
-    return GMP_CMP (mpz_get_ui (u), v);
+    {
+      unsigned long uu = mpz_get_ui (u);
+      return GMP_CMP(uu, v);
+    }
 }
 
 int
@@ -2046,7 +2058,7 @@
       mpz_neg (r, r);
     }
   else
-    mpz_mul_ui (r, u, (unsigned long int) v);
+    mpz_mul_ui (r, u, v);
 }
 
 void
@@ -3478,8 +3490,8 @@
   int res;
 
   assert (b0 > 0);
-  assert (Q <= (long) (GMP_LIMB_HIGHBIT >> 1));
-  assert (Q > -(long) (GMP_LIMB_HIGHBIT >> 1));
+  assert (Q <= - (LONG_MIN / 2));
+  assert (Q >= - (LONG_MAX / 2));
   assert (mpz_cmp_ui (n, 4) > 0);
   assert (mpz_odd_p (n));
 
@@ -3728,7 +3740,7 @@
     {
       /* d < 0. Check if any of the bits below is set: If so, our bit
 	 must be complemented. */
-      if (shift > 0 && (w << (GMP_LIMB_BITS - shift)) > 0)
+      if (shift > 0 && (mp_limb_t) (w << (GMP_LIMB_BITS - shift)) > 0)
 	return bit ^ 1;
       while (--limb_index >= 0)
 	if (d->_mp_d[limb_index] > 0)
diff -r ba8b7b6c9b1a -r ad2fba4b602d mini-gmp/mini-mpq.c
--- a/mini-gmp/mini-mpq.c	Fri Nov 30 17:35:17 2018 +0100
+++ b/mini-gmp/mini-mpq.c	Sat Dec 08 12:03:14 2018 +0100
@@ -252,7 +252,18 @@
 {
   mpq_t t;
   assert (d != 0);
-  return mpq_cmp (q, mpq_roinit_normal_n (t, &n, n != 0, &d, 1));
+  if (sizeof (unsigned long) == sizeof (mp_limb_t))
+    return mpq_cmp (q, mpq_roinit_normal_n (t, (mp_srcptr) &n, n != 0, (mp_srcptr) &d, 1));
+  else {
+    int ret;
+
+    mpq_init (t);
+    mpq_set_ui (t, n, d);
+    ret = mpq_cmp (q, t);
+    mpq_clear (t);
+
+    return ret;
+  }
 }
 
 int
@@ -267,7 +278,12 @@
       mpq_t t;
       unsigned long l_n = GMP_NEG_CAST (unsigned long, n);
 
-      return mpq_cmp (q, mpq_roinit_normal_n (t, &l_n, -1, &d, 1));
+      if (sizeof (unsigned long) == sizeof (mp_limb_t))
+	return mpq_cmp (q, mpq_roinit_normal_n (t, (mp_srcptr) &l_n, -1, (mp_srcptr) &d, 1));
+
+      mpq_roinit_normal_n (t, mpq_numref (q)->_mp_d, - mpq_numref (q)->_mp_size,
+		       mpq_denref (q)->_mp_d, mpq_denref (q)->_mp_size);
+      return - mpq_cmp_ui (t, l_n, d);
     }
 }
 
diff -r ba8b7b6c9b1a -r ad2fba4b602d mini-gmp/tests/hex-random.c
--- a/mini-gmp/tests/hex-random.c	Fri Nov 30 17:35:17 2018 +0100
+++ b/mini-gmp/tests/hex-random.c	Sat Dec 08 12:03:14 2018 +0100
@@ -1,6 +1,6 @@
 /*
 
-Copyright 2011, 2016 Free Software Foundation, Inc.
+Copyright 2011, 2016, 2018 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library test suite.
 
diff -r ba8b7b6c9b1a -r ad2fba4b602d mini-gmp/tests/hex-random.h
--- a/mini-gmp/tests/hex-random.h	Fri Nov 30 17:35:17 2018 +0100
+++ b/mini-gmp/tests/hex-random.h	Sat Dec 08 12:03:14 2018 +0100
@@ -1,6 +1,6 @@
 /*
 
-Copyright 2011, Free Software Foundation, Inc.
+Copyright 2011, 2018 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library test suite.
 
diff -r ba8b7b6c9b1a -r ad2fba4b602d mini-gmp/tests/mini-random.c
--- a/mini-gmp/tests/mini-random.c	Fri Nov 30 17:35:17 2018 +0100
+++ b/mini-gmp/tests/mini-random.c	Sat Dec 08 12:03:14 2018 +0100
@@ -1,6 +1,6 @@
 /*
 
-Copyright 2011, 2013, Free Software Foundation, Inc.
+Copyright 2011, 2013, 2018 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library test suite.
 
diff -r ba8b7b6c9b1a -r ad2fba4b602d mini-gmp/tests/mini-random.h
--- a/mini-gmp/tests/mini-random.h	Fri Nov 30 17:35:17 2018 +0100
+++ b/mini-gmp/tests/mini-random.h	Sat Dec 08 12:03:14 2018 +0100
@@ -1,6 +1,6 @@
 /*
 
-Copyright 2011, Free Software Foundation, Inc.
+Copyright 2011, 2018 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library test suite.
 
diff -r ba8b7b6c9b1a -r ad2fba4b602d mini-gmp/tests/t-div.c
--- a/mini-gmp/tests/t-div.c	Fri Nov 30 17:35:17 2018 +0100
+++ b/mini-gmp/tests/t-div.c	Sat Dec 08 12:03:14 2018 +0100
@@ -162,7 +162,7 @@
 
 	  if (mpz_fits_ulong_p (b))
 	    {
-	      mp_limb_t rl;
+	      unsigned long rl;
 
 	      mpz_set_si (r, -7);
 	      mpz_set_ui (q, ~7);
diff -r ba8b7b6c9b1a -r ad2fba4b602d tests/mpz/bit.c
--- a/tests/mpz/bit.c	Fri Nov 30 17:35:17 2018 +0100
+++ b/tests/mpz/bit.c	Sat Dec 08 12:03:14 2018 +0100
@@ -289,7 +289,8 @@
   unsigned long int bitindex;
   const char  *s = "";
 
-  TESTS_REPS (reps, argv, argc);
+  if (argc == 2)
+    reps = atoi (argv[1]);
 
   mpz_init (x);
   mpz_init (s0);
diff -r ba8b7b6c9b1a -r ad2fba4b602d tests/mpz/dive_ui.c
--- a/tests/mpz/dive_ui.c	Fri Nov 30 17:35:17 2018 +0100
+++ b/tests/mpz/dive_ui.c	Sat Dec 08 12:03:14 2018 +0100
@@ -33,7 +33,8 @@
   int    i, qneg;
   unsigned long  d;
 
-  TESTS_REPS (reps, argv, argc);
+  if (argc == 2)
+    reps = atoi (argv[1]);
 
   mpz_init (a);
   mpz_init (q);
diff -r ba8b7b6c9b1a -r ad2fba4b602d tests/mpz/io.c
--- a/tests/mpz/io.c	Fri Nov 30 17:35:17 2018 +0100
+++ b/tests/mpz/io.c	Sat Dec 08 12:03:14 2018 +0100
@@ -55,7 +55,8 @@
 
   mpz_init (bs);
 
-  TESTS_REPS (reps, argv, argc);
+  if (argc == 2)
+    reps = atoi (argv[1]);
 
   mpz_init (op1);
   mpz_init (op2);
diff -r ba8b7b6c9b1a -r ad2fba4b602d tests/mpz/logic.c
--- a/tests/mpz/logic.c	Fri Nov 30 17:35:17 2018 +0100
+++ b/tests/mpz/logic.c	Sat Dec 08 12:03:14 2018 +0100
@@ -43,7 +43,8 @@
 
   mpz_init (bs);
 
-  TESTS_REPS (reps, argv, argc);
+  if (argc == 2)
+     reps = atoi (argv[1]);
 
   mpz_init (x);
   mpz_init (y);
diff -r ba8b7b6c9b1a -r ad2fba4b602d tests/mpz/t-addsub.c
--- a/tests/mpz/t-addsub.c	Fri Nov 30 17:35:17 2018 +0100
+++ b/tests/mpz/t-addsub.c	Sat Dec 08 12:03:14 2018 +0100


More information about the gmp-commit mailing list