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

mercurial at gmplib.org mercurial at gmplib.org
Sun Nov 15 14:05:18 UTC 2020


details:   /var/hg/gmp/rev/4a0df7eccfb1
changeset: 18138:4a0df7eccfb1
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Nov 15 07:06:57 2020 +0100
description:
mini-gmp/mini-gmp.c (mpz_gcd): Support limbs larger than ui.

details:   /var/hg/gmp/rev/819eeb41d888
changeset: 18139:819eeb41d888
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Nov 15 07:07:40 2020 +0100
description:
mini-gmp/tests/t-invert.c: Support limbs larger than ui.

details:   /var/hg/gmp/rev/90c5eed1f4d6
changeset: 18140:90c5eed1f4d6
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Nov 15 14:48:37 2020 +0100
description:
primesieve.c: Differentiate n_to_bit into floor and ceil.

details:   /var/hg/gmp/rev/b7953a3b7b82
changeset: 18141:b7953a3b7b82
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Nov 15 14:50:38 2020 +0100
description:
tests/devel/primes.c: Correctly use n_cto_bit or n_fto_bit.

details:   /var/hg/gmp/rev/d738b0c2722a
changeset: 18142:d738b0c2722a
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Nov 15 14:51:16 2020 +0100
description:
Whitespace cleanup.

details:   /var/hg/gmp/rev/dcb8f96adfff
changeset: 18143:dcb8f96adfff
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Nov 15 14:52:21 2020 +0100
description:
scanf/doscan.c: Mask ASSERT_CODE.

details:   /var/hg/gmp/rev/067b915bf513
changeset: 18144:067b915bf513
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Nov 15 14:53:38 2020 +0100
description:
rand/randlc2x.c: Replace __GMPN_ADD with mpn_add.

details:   /var/hg/gmp/rev/bb84d0458504
changeset: 18145:bb84d0458504
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Nov 15 14:55:24 2020 +0100
description:
mpn/generic/mod_1_3.c: Use default in a switch (reduce warnings).

details:   /var/hg/gmp/rev/ab9628ad89ff
changeset: 18146:ab9628ad89ff
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Nov 15 14:58:56 2020 +0100
description:
mpn/generic/mu_divappr_q.c: Transform while {} into do {} while (reduce warnings)

details:   /var/hg/gmp/rev/9ae375700274
changeset: 18147:9ae375700274
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Nov 15 15:05:06 2020 +0100
description:
ChangeLog

diffstat:

 ChangeLog                  |  10 ++++++++++
 mini-gmp/ChangeLog         |   5 +++++
 mini-gmp/mini-gmp.c        |  10 +++++++---
 mini-gmp/tests/t-invert.c  |  18 ++++++++++--------
 mpn/generic/mod_1_3.c      |   5 ++---
 mpn/generic/mu_divappr_q.c |   3 ++-
 mpn/generic/rootrem.c      |  16 ++++++++--------
 primesieve.c               |  40 ++++++++++++++++++++++------------------
 rand/randlc2x.c            |   3 +--
 scanf/doscan.c             |   2 +-
 tests/devel/primes.c       |  16 ++++++++--------
 11 files changed, 76 insertions(+), 52 deletions(-)

diffs (truncated from 385 to 300 lines):

diff -r 36c93153e71c -r 9ae375700274 ChangeLog
--- a/ChangeLog	Tue Nov 10 18:51:19 2020 +0100
+++ b/ChangeLog	Sun Nov 15 15:05:06 2020 +0100
@@ -1,3 +1,13 @@
+2020-11-15 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpn/generic/mu_divappr_q.c: Transform while {} into do {} while;
+	* mpn/generic/mod_1_3.c: Use default in a switch;
+	* rand/randlc2x.c: Replace __GMPN_ADD with mpn_add;
+	* scanf/doscan.c: Mask ASSERT_CODE, to reduce warnings.
+
+	* tests/devel/primes.c: Correctly use n_cto_bit or n_fto_bit.
+	* primesieve.c: Differentiate n_to_bit into floor and ceil.
+
 2020-11-10 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
 	* configure.ac (fat_path): Add bd1, goldmont,silvermont for CPUVEC.
diff -r 36c93153e71c -r 9ae375700274 mini-gmp/ChangeLog
--- a/mini-gmp/ChangeLog	Tue Nov 10 18:51:19 2020 +0100
+++ b/mini-gmp/ChangeLog	Sun Nov 15 15:05:06 2020 +0100
@@ -1,3 +1,8 @@
+2020-11-15 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mini-gmp.c (mpz_gcd): Support limbs larger than unsigned long.
+	* tests/t-invert.c: Likewise.
+
 2020-11-10 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
 	* tests/run-tests: Update WINEPATH, instead of overwriting it.
diff -r 36c93153e71c -r 9ae375700274 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Tue Nov 10 18:51:19 2020 +0100
+++ b/mini-gmp/mini-gmp.c	Sun Nov 15 15:05:06 2020 +0100
@@ -2777,9 +2777,13 @@
 
 	if (tv->_mp_size == 1)
 	  {
-	    mp_limb_t vl = tv->_mp_d[0];
-	    mp_limb_t ul = mpz_tdiv_ui (tu, vl);
-	    mpz_set_ui (g, mpn_gcd_11 (ul, vl));
+	    mp_limb_t gl;
+	    mpz_t tg;
+
+	    mpz_tdiv_r (tu, tu, tv);
+	    gl = mpn_gcd_11 (tu->_mp_d[0], tv->_mp_d[0]);
+
+	    mpz_set (g, mpz_roinit_n (tg, &gl, 1));
 	    break;
 	  }
 	mpz_sub (tu, tu, tv);
diff -r 36c93153e71c -r 9ae375700274 mini-gmp/tests/t-invert.c
--- a/mini-gmp/tests/t-invert.c	Tue Nov 10 18:51:19 2020 +0100
+++ b/mini-gmp/tests/t-invert.c	Sun Nov 15 15:05:06 2020 +0100
@@ -32,19 +32,20 @@
 test_2by1(const mpz_t u)
 {
   mpz_t m, p, t;
+  mp_limb_t tl;
 
-  mpz_init (m);
   mpz_init (p);
-  mpz_init (t);
 
   assert (mpz_size (u) == 1);
 
-  mpz_set_ui (m, mpn_invert_limb (u->_mp_d[0]));
+  tl = mpn_invert_limb (u->_mp_d[0]);
+  mpz_roinit_n (t, &tl, 1);
+  mpz_init_set (m, t);
   mpz_setbit (m, GMP_LIMB_BITS);
 
   mpz_mul (p, m, u);
 
-  mpz_set_ui (t, 0);
+  mpz_init (t);
   mpz_setbit (t, 2* GMP_LIMB_BITS);
   mpz_sub (t, t, p);
 
@@ -67,20 +68,21 @@
 test_3by2(const mpz_t u)
 {
   mpz_t m, p, t;
+  mp_limb_t tl;
 
-  mpz_init (m);
   mpz_init (p);
-  mpz_init (t);
 
   assert (mpz_size (u) == 2);
 
-  mpz_set_ui (m, mpn_invert_3by2 (u->_mp_d[1], u[0]._mp_d[0]));
+  tl = mpn_invert_3by2 (u->_mp_d[1], u->_mp_d[0]);
+  mpz_roinit_n (t, &tl, 1);
+  mpz_init_set (m, t);
 
   mpz_setbit (m, GMP_LIMB_BITS);
 
   mpz_mul (p, m, u);
 
-  mpz_set_ui (t, 0);
+  mpz_init (t);
   mpz_setbit (t, 3 * GMP_LIMB_BITS);
   mpz_sub (t, t, p);
 
diff -r 36c93153e71c -r 9ae375700274 mpn/generic/mod_1_3.c
--- a/mpn/generic/mod_1_3.c	Tue Nov 10 18:51:19 2020 +0100
+++ b/mpn/generic/mod_1_3.c	Sun Nov 15 15:05:06 2020 +0100
@@ -110,10 +110,9 @@
       add_ssaaaa (rh, rl, rh, rl, ph, pl);
       n -= 3;
       break;
-    case 2:	/* n mod 3 = 1 */
+    default:	/* n mod 3 = 1; (case 2)*/
       rh = 0;
-      rl = ap[n - 1];
-      n -= 1;
+      rl = ap[--n];
       break;
     case 1:	/* n mod 3 = 2 */
       rh = ap[n - 1];
diff -r 36c93153e71c -r 9ae375700274 mpn/generic/mu_divappr_q.c
--- a/mpn/generic/mu_divappr_q.c	Tue Nov 10 18:51:19 2020 +0100
+++ b/mpn/generic/mu_divappr_q.c	Sun Nov 15 15:05:06 2020 +0100
@@ -191,7 +191,7 @@
   if (qn == 0)
     return qh;			/* Degenerate use.  Should we allow this? */
 
-  while (qn > 0)
+  do
     {
       if (qn < in)
 	{
@@ -283,6 +283,7 @@
 	      }
 	    );
     }
+  while (qn > 0);
 
   /* FIXME: We should perhaps be somewhat more elegant in our rounding of the
      quotient.  For now, just make sure the returned quotient is >= the real
diff -r 36c93153e71c -r 9ae375700274 mpn/generic/rootrem.c
--- a/mpn/generic/rootrem.c	Tue Nov 10 18:51:19 2020 +0100
+++ b/mpn/generic/rootrem.c	Sun Nov 15 15:05:06 2020 +0100
@@ -451,13 +451,13 @@
 	    qn += qp[qn] != 0;
 	  }
 
-      /* 5: current buffers: {sp,sn}, {qp,qn}.
-	 Note: {rp,rn} is not needed any more since we'll compute it from
-	 scratch at the end of the loop.
-       */
+	  /* 5: current buffers: {sp,sn}, {qp,qn}.
+	     Note: {rp,rn} is not needed any more since we'll compute it from
+	     scratch at the end of the loop.
+	  */
 
-      /* the quotient should be smaller than 2^b, since the previous
-	 approximation was correctly rounded toward zero */
+	  /* the quotient should be smaller than 2^b, since the previous
+	     approximation was correctly rounded toward zero */
 	  if (qn > bn || (qn == bn && (b % GMP_NUMB_BITS != 0) &&
 			  qp[qn - 1] >= (CNST_LIMB (1) << (b % GMP_NUMB_BITS))))
 	    {
@@ -467,9 +467,9 @@
 	    }
 	  else
 	    {
-      /* 7: current buffers: {sp,sn}, {qp,qn} */
+	      /* 7: current buffers: {sp,sn}, {qp,qn} */
 
-      /* Combine sB and q to form sB + q.  */
+	      /* Combine sB and q to form sB + q.  */
 	      MPN_COPY (sp, qp, qn);
 	      MPN_ZERO (sp + qn, bn - qn);
 	    }
diff -r 36c93153e71c -r 9ae375700274 primesieve.c
--- a/primesieve.c	Tue Nov 10 18:51:19 2020 +0100
+++ b/primesieve.c	Sun Nov 15 15:05:06 2020 +0100
@@ -46,13 +46,17 @@
 static mp_limb_t
 id_to_n  (mp_limb_t id)  { return id*3+1+(id&1); }
 
-/* n_to_bit (n) = ((n-1)&(-CNST_LIMB(2)))/3U-1 */
+/* n_fto_bit (n) = ((n-1)&(-CNST_LIMB(2)))/3U-1 */
 static mp_limb_t
-n_to_bit (mp_limb_t n) { return ((n-5)|1)/3U; }
+n_fto_bit (mp_limb_t n) { return ((n-5)|1)/3U; }
+
+/* n_cto_bit (n) = ((n-2)&(-CNST_LIMB(2)))/3U */
+static mp_limb_t
+n_cto_bit (mp_limb_t n) { return (n|1)/3U-1; }
 
 #if 0
 static mp_size_t
-primesieve_size (mp_limb_t n) { return n_to_bit(n) / GMP_LIMB_BITS + 1; }
+primesieve_size (mp_limb_t n) { return n_fto_bit(n) / GMP_LIMB_BITS + 1; }
 #endif
 
 #if GMP_LIMB_BITS > 61
@@ -65,7 +69,7 @@
 #define SIEVE_2MSK1 CNST_LIMB(0x9402180c40230184)
 #define SIEVE_2MSK2 CNST_LIMB(0x0285021088402120)
 #define SIEVE_2MSKT CNST_LIMB(0xa41210084421)
-#define SEED_LIMIT 288
+#define SEED_LIMIT (17*17-1)
 #else
 #define SEED_LIMIT 202
 #endif
@@ -77,7 +81,7 @@
 #define SIEVE_MASK1 CNST_LIMB(0x12148960)
 #define SIEVE_MASK2 CNST_LIMB(0x44a120cc)
 #define SIEVE_MASKT CNST_LIMB(0x1a)
-#define SEED_LIMIT 120
+#define SEED_LIMIT (11*11-1)
 #else
 #define SEED_LIMIT 114
 #endif
@@ -91,7 +95,7 @@
 #define SEED_LIMIT 34
 #else
 #define SIEVE_SEED CNST_LIMB(0x0)
-#define SEED_LIMIT 24
+#define SEED_LIMIT (5*5-1)
 #endif /* 7 */
 #endif /* 15 */
 #endif /* 30 */
@@ -193,10 +197,10 @@
     m22 = SIEVE_2MSK2;
     m23 = SIEVE_2MSKT;
   } else { /* correctly handle offset == 0... */
-    m21 = offset % 110;
-    SET_OFF1 (m11, m12, SIEVE_MASK1, SIEVE_MASKT, m21, 110);
-    offset %= 182;
-    SET_OFF2 (m21, m22, m23, SIEVE_2MSK1, SIEVE_2MSK2, SIEVE_2MSKT, offset, 182);
+    m21 = offset % (11 * 5 * 2);
+    SET_OFF1 (m11, m12, SIEVE_MASK1, SIEVE_MASKT, m21, 11 * 5 * 2);
+    offset %= 13 * 7 * 2;
+    SET_OFF2 (m21, m22, m23, SIEVE_2MSK1, SIEVE_2MSK2, SIEVE_2MSKT, offset, 13 * 7 * 2);
   }
   /* THINK: Consider handling odd values of 'limbs' outside the loop,
      to have a single exit condition. */
@@ -210,7 +214,7 @@
     ROTATE1 (m11, m12, 110);
     ROTATE2 (m21, m22, m23, 182);
   } while (--limbs != 0);
-  return 4;
+  return n_cto_bit (13 + 1);
 #else
 #ifdef SIEVE_MASK2
   mp_limb_t mask, mask2, tail;
@@ -220,8 +224,8 @@
     mask2 = SIEVE_MASK2;
     tail = SIEVE_MASKT;
   } else { /* correctly handle offset == 0... */
-    offset %= 70;
-    SET_OFF2 (mask, mask2, tail, SIEVE_MASK1, SIEVE_MASK2, SIEVE_MASKT, offset, 70);
+    offset %= 7 * 5 * 2;
+    SET_OFF2 (mask, mask2, tail, SIEVE_MASK1, SIEVE_MASK2, SIEVE_MASKT, offset, 7 * 5 * 2);
   }
   /* THINK: Consider handling odd values of 'limbs' outside the loop,
      to have a single exit condition. */
@@ -231,9 +235,9 @@
       break;
     bit_array[1] = mask2;
     bit_array += 2;
-    ROTATE2 (mask, mask2, tail, 70);
+    ROTATE2 (mask, mask2, tail, 7 * 5 * 2);
   } while (--limbs != 0);
-  return 2;
+  return n_cto_bit (7 + 1);
 #else
   MPN_FILL (bit_array, limbs, CNST_LIMB(0));
   return 0;
@@ -249,7 +253,7 @@
 
   ASSERT (n > 4);
 
-  bits  = n_to_bit(n);
+  bits  = n_fto_bit(n);
   limbs = bits / GMP_LIMB_BITS;
 
   if (limbs != 0)
@@ -264,7 +268,7 @@
 
     ASSERT (i < GMP_LIMB_BITS);
 
-    if (n_to_bit (SEED_LIMIT + 1) < GMP_LIMB_BITS)
+    if (n_cto_bit (SEED_LIMIT) < GMP_LIMB_BITS)
       i = 0;
     mask = CNST_LIMB(1) << i;
     index = 0;
@@ -400,7 +404,7 @@
 
   ASSERT (n > 4);
 
-  bits = n_to_bit(n);
+  bits = n_fto_bit(n);
   size = bits / GMP_LIMB_BITS + 1;
 
   if (size > BLOCK_SIZE * 2) {
diff -r 36c93153e71c -r 9ae375700274 rand/randlc2x.c



More information about the gmp-commit mailing list