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

mercurial at gmplib.org mercurial at gmplib.org
Sat Nov 28 22:38:42 UTC 2020


details:   /var/hg/gmp/rev/8a5f92f14e2b
changeset: 18158:8a5f92f14e2b
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Nov 28 23:36:06 2020 +0100
description:
tests/mpz/t-pprime_p.c (check_fermat_mersenne): Changes similar to Troisi's

details:   /var/hg/gmp/rev/090afdeba1f2
changeset: 18159:090afdeba1f2
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Nov 28 23:36:54 2020 +0100
description:
primesieve.c: Differentiate n_to_bit into floor and ceil.

details:   /var/hg/gmp/rev/50ffdedceb4a
changeset: 18160:50ffdedceb4a
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Nov 28 23:37:18 2020 +0100
description:
tests/devel/primes.c: Correctly use n_cto_bit or n_fto_bit

details:   /var/hg/gmp/rev/94986a5355b2
changeset: 18161:94986a5355b2
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Nov 28 23:37:57 2020 +0100
description:
mini-gmp/tests/t-invert.c: Support limbs larger than ui

details:   /var/hg/gmp/rev/1219d4682312
changeset: 18162:1219d4682312
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Nov 28 23:38:20 2020 +0100
description:
mini-gmp/mini-gmp.c (mpz_gcd): Support limbs larger than ui

details:   /var/hg/gmp/rev/94c84d919f83
changeset: 18163:94c84d919f83
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Nov 28 23:38:32 2020 +0100
description:
ChangeLog

diffstat:

 ChangeLog                 |   8 ++++++++
 mini-gmp/ChangeLog        |   5 +++++
 mini-gmp/mini-gmp.c       |  10 +++++++---
 mini-gmp/tests/t-invert.c |  18 ++++++++++--------
 primesieve.c              |  46 +++++++++++++++++++++++++---------------------
 tests/devel/primes.c      |  16 ++++++++--------
 tests/mpz/t-pprime_p.c    |   5 +++--
 7 files changed, 66 insertions(+), 42 deletions(-)

diffs (truncated from 311 to 300 lines):

diff -r a2b3babbcc8e -r 94c84d919f83 ChangeLog
--- a/ChangeLog	Mon Nov 23 19:30:19 2020 +0100
+++ b/ChangeLog	Sat Nov 28 23:38:32 2020 +0100
@@ -1,3 +1,11 @@
+2020-11-28 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* tests/mpz/t-pprime_p.c (check_fermat_mersenne): Check return
+	value.
+
+	* 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-23 Seth Troisi <sethtroisi at google.com>
 
 	* mpz/nextprime.c (mpz_prevprime): New function.
diff -r a2b3babbcc8e -r 94c84d919f83 mini-gmp/ChangeLog
--- a/mini-gmp/ChangeLog	Mon Nov 23 19:30:19 2020 +0100
+++ b/mini-gmp/ChangeLog	Sat Nov 28 23:38:32 2020 +0100
@@ -1,3 +1,8 @@
+2020-11-28 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-05-21  Torbjörn Granlund  <tg at gmplib.org>
 
 	* tests/t-double.c: Provide default M_PI definition.
diff -r a2b3babbcc8e -r 94c84d919f83 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Mon Nov 23 19:30:19 2020 +0100
+++ b/mini-gmp/mini-gmp.c	Sat Nov 28 23:38:32 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 *gp;
+
+	    mpz_tdiv_r (tu, tu, tv);
+	    gp = MPZ_REALLOC (g, 1); /* gp = mpz_limbs_modify (g, 1); */
+	    *gp = mpn_gcd_11 (tu->_mp_d[0], tv->_mp_d[0]);
+
+	    g->_mp_size = *gp != 0; /* mpz_limbs_finish (g, 1); */
 	    break;
 	  }
 	mpz_sub (tu, tu, tv);
diff -r a2b3babbcc8e -r 94c84d919f83 mini-gmp/tests/t-invert.c
--- a/mini-gmp/tests/t-invert.c	Mon Nov 23 19:30:19 2020 +0100
+++ b/mini-gmp/tests/t-invert.c	Sat Nov 28 23:38:32 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 a2b3babbcc8e -r 94c84d919f83 primesieve.c
--- a/primesieve.c	Mon Nov 23 19:30:19 2020 +0100
+++ b/primesieve.c	Sat Nov 28 23:38:32 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. */
@@ -204,13 +208,13 @@
     bit_array[0] = m11 | m21;
     if (--limbs == 0)
       break;
-    ROTATE1 (m11, m12, 110);
+    ROTATE1 (m11, m12, 11 * 5 * 2);
     bit_array[1] = m11 | m22;
     bit_array += 2;
-    ROTATE1 (m11, m12, 110);
-    ROTATE2 (m21, m22, m23, 182);
+    ROTATE1 (m11, m12, 11 * 5 * 2);
+    ROTATE2 (m21, m22, m23, 13 * 7 * 2);
   } 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 a2b3babbcc8e -r 94c84d919f83 tests/devel/primes.c
--- a/tests/devel/primes.c	Mon Nov 23 19:30:19 2020 +0100
+++ b/tests/devel/primes.c	Sat Nov 28 23:38:32 2020 +0100
@@ -63,7 +63,7 @@
 /*********************************************************/
 
 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; }
 
 /*************************************************************/
 /* Section macros: common macros, for swing/fac/bin (&sieve) */
@@ -143,7 +143,7 @@
 
 	size_s = BLOCK_SIZE * 2;
 	sieve = __GMP_ALLOCATE_FUNC_LIMBS (size_s);
-	off = n_to_bit(begin) + (begin % 3 == 0);
+	off = n_cto_bit(begin);
 
 	do {
 	  TRACE (printf ("off =%li\n", off),3);
@@ -189,8 +189,8 @@
 	sieve = __GMP_ALLOCATE_FUNC_LIMBS (size);
 	gmp_primesieve (sieve, end);
 	start = MAX (begin, 5) | 1;
-	LOOP_ON_SIEVE_BEGIN (prime, n_to_bit(start) + (start % 3 == 0),
-			     n_to_bit (end), 0, sieve);
+	LOOP_ON_SIEVE_BEGIN (prime, n_cto_bit(start),
+			     n_fto_bit (end), 0, sieve);
 
 	do {
 	  *(g->_mp_d) = begin;
@@ -263,8 +263,8 @@
 	gmp_primesieve (sieve, end);
 	start = MAX (begin, 5) | 1;
 	*(g->_mp_d) = begin;
-	LOOP_ON_SIEVE_BEGIN (prime, n_to_bit(start) + (start % 3 == 0),
-			     n_to_bit (end), 0, sieve);
+	LOOP_ON_SIEVE_BEGIN (prime, n_cto_bit(start),
+			     n_fto_bit (end), 0, sieve);
 
 	mpz_nextprime (g, g);
 	if (mpz_cmp_ui (g, prime) != 0)
@@ -334,8 +334,8 @@
 	gmp_primesieve (sieve, end);
 	start = MAX (begin, 5) | 1;
 	opl = begin;
-	LOOP_ON_SIEVE_BEGIN (prime, n_to_bit(start) + (start % 3 == 0),
-			     n_to_bit (end), 0, sieve);
+	LOOP_ON_SIEVE_BEGIN (prime, n_cto_bit(start),
+			     n_fto_bit (end), 0, sieve);
 
 	do {
 	  *(op->_mp_d) = opl;
diff -r a2b3babbcc8e -r 94c84d919f83 tests/mpz/t-pprime_p.c
--- a/tests/mpz/t-pprime_p.c	Mon Nov 23 19:30:19 2020 +0100
+++ b/tests/mpz/t-pprime_p.c	Sat Nov 28 23:38:32 2020 +0100
@@ -194,7 +194,8 @@
       for (j = 0; j < numberof (fermat_exponents); j++)
 	if (fermat_exponents[j] == i)
 	  {
-	    want = 1;
+	    /* Fermat's primes are small enough for a definite answer. */
+	    want = 2;
 	    break;



More information about the gmp-commit mailing list