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

mercurial at gmplib.org mercurial at gmplib.org
Sat Feb 21 17:43:40 CET 2026


details:   /var/hg/gmp/rev/716f696550ef
changeset: 18490:716f696550ef
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Feb 21 17:10:01 2026 +0100
description:
mpz/millerrabin.c (millerrabin): Use mpz_srcptr for unchanged vars.

details:   /var/hg/gmp/rev/f0a841f38aa5
changeset: 18491:f0a841f38aa5
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Feb 21 17:12:24 2026 +0100
description:
mpz/millerrabin.c: Update comment

details:   /var/hg/gmp/rev/d4ead1a6ebd7
changeset: 18492:d4ead1a6ebd7
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Feb 21 17:17:58 2026 +0100
description:
ChangeLog

details:   /var/hg/gmp/rev/53bef16390f7
changeset: 18493:53bef16390f7
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Feb 21 17:36:40 2026 +0100
description:
tune/speed.h (SPEED_ROUTINE_MPN_MULMOD_BNP1_CALL): Use k=11 only when available.

details:   /var/hg/gmp/rev/7ff7050d24ea
changeset: 18494:7ff7050d24ea
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Feb 21 17:43:34 2026 +0100
description:
ChangeLog

diffstat:

 ChangeLog         |   8 ++++++++
 mpz/millerrabin.c |  21 ++++++++++++++-------
 tune/speed.h      |   3 ++-
 3 files changed, 24 insertions(+), 8 deletions(-)

diffs (74 lines):

diff -r b54d1f94b4ee -r 7ff7050d24ea ChangeLog
--- a/ChangeLog	Wed Sep 24 15:34:54 2025 +0200
+++ b/ChangeLog	Sat Feb 21 17:43:34 2026 +0100
@@ -1,3 +1,11 @@
+2026-02-21  Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpz/millerrabin.c: Improve description of the code with comments,
+	change a parameter to mpz_srcptr. Update also tested values.
+
+	* tune/speed.h (SPEED_ROUTINE_MPN_MULMOD_BNP1_CALL):
+	Use k=11 only when available.
+
 2025-09-24  Niels Möller  <nisse at lysator.liu.se>
 
 	* bootstrap.c (MINI_GMP_ENABLE_FLOAT): Define to 0. Replaces...
diff -r b54d1f94b4ee -r 7ff7050d24ea mpz/millerrabin.c
--- a/mpz/millerrabin.c	Wed Sep 24 15:34:54 2025 +0200
+++ b/mpz/millerrabin.c	Sat Feb 21 17:43:34 2026 +0100
@@ -8,7 +8,7 @@
    With the current implementation, the first 24 MR-tests are substituted by a
    Baillie-PSW probable prime test.
 
-   This implementation of the Baillie-PSW test was checked up to 2640*10^12,
+   This implementation of the Baillie-PSW test was checked up to 2860*10^12,
    for smaller values no MR-test is performed, regardless of reps, and
    2 ("surely prime") is returned if the number was not proved composite.
 
@@ -88,8 +88,15 @@
     }
 }
 
+/* Performs a Miller-Rabin test, on the number n, with base x.
+ * The value q is the odd number such that (q<<k) + 1 = n.
+ *
+ * The variable y is overwritten, it's only role is to reuse the same
+ * temp variable.
+ */
+
 static int
-millerrabin (mpz_srcptr n, mpz_ptr x, mpz_ptr y,
+millerrabin (mpz_srcptr n, mpz_srcptr x, mpz_ptr y,
 	     mpz_srcptr q, mp_bitcnt_t k)
 {
   mpz_powm (y, x, q, n);
@@ -146,11 +153,11 @@
 	  || SIZ (n) - 64 / GMP_NUMB_BITS == (PTR (n) [64 / GMP_NUMB_BITS] < CNST_LIMB(1) << 64 % GMP_NUMB_BITS)
 #endif
 #else
-	  /* Consider numbers up to 75*2^45 that pass the BPSW test as primes.
-	     This implementation was tested up to 264*10^13 > 2^51+2^48+2^46+2^45 */
-	  /* 2^6 < 75 = 0b1001011 < 2^7 */
-#define GMP_BPSW_LIMB_CONST CNST_LIMB(75)
-#define GMP_BPSW_BITS_CONST (LOG2C(75) - 1)
+	  /* Consider numbers up to 81*2^45 that pass the BPSW test as primes.
+	     This implementation was tested up to 286*10^13 > 2^51+2^49+2^45 */
+	  /* 2^6 < 81 = 0b1010001 < 2^7 */
+#define GMP_BPSW_LIMB_CONST CNST_LIMB(81)
+#define GMP_BPSW_BITS_CONST (LOG2C(81) - 1)
 #define GMP_BPSW_BITS_LIMIT (45 + GMP_BPSW_BITS_CONST)
 
 #define GMP_BPSW_LIMBS_LIMIT (GMP_BPSW_BITS_LIMIT / GMP_NUMB_BITS)
diff -r b54d1f94b4ee -r 7ff7050d24ea tune/speed.h
--- a/tune/speed.h	Wed Sep 24 15:34:54 2025 +0200
+++ b/tune/speed.h	Sat Feb 21 17:43:34 2026 +0100
@@ -1430,7 +1430,8 @@
 	if (s->size % 3 == 0) {nk = s->size / (k = 3);}			\
 	else if (s->size % 5 == 0) {nk = s->size / (k = 5);}		\
 	else if (s->size % 7 == 0) {nk = s->size / (k = 7);}		\
-	else if (s->size % 11 == 0) {nk = s->size / (k = 11);}		\
+	else if ((MOD_BKNP1_USE11) && (s->size % 11 == 0))		\
+	  {nk = s->size / (k = 11);}					\
 	else if (s->size % 13 == 0) {nk = s->size / (k = 13);}		\
 	else if (s->size % 17 == 0) {nk = s->size / (k = 17);}		\
 	else nk = s->size / (k = 1);					\


More information about the gmp-commit mailing list