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

mercurial at gmplib.org mercurial at gmplib.org
Sat May 14 09:13:53 CEST 2022


details:   /var/hg/gmp/rev/9e5f90c45fdc
changeset: 18350:9e5f90c45fdc
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat May 14 09:12:33 2022 +0200
description:
AUTHORS

details:   /var/hg/gmp/rev/0c1e6dd025d3
changeset: 18351:0c1e6dd025d3
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat May 14 09:13:07 2022 +0200
description:
mpz/nextprime.c: Prepare for nth_nextprime

details:   /var/hg/gmp/rev/e593a00163f3
changeset: 18352:e593a00163f3
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat May 14 09:13:49 2022 +0200
description:
tests/mpz/t-pprime_p.c (isprime): Simplify.

diffstat:

 AUTHORS                |   4 +++-
 mpz/nextprime.c        |  10 +++++-----
 tests/mpz/t-pprime_p.c |  25 ++++++++-----------------
 3 files changed, 16 insertions(+), 23 deletions(-)

diffs (122 lines):

diff -r f43365857aba -r e593a00163f3 AUTHORS
--- a/AUTHORS	Fri May 13 20:49:04 2022 +0200
+++ b/AUTHORS	Sat May 14 09:13:49 2022 +0200
@@ -62,7 +62,7 @@
 			toom8h_mul.c, toom8_sqr.c, toom_interpolate_16pts.c,
 			mulmod_bnm1.c, sqrmod_bnm1.c, nussbaumer_mul.c,
 			toom_eval_pm2.c, toom_eval_pm2rexp.c,
-			fib2m.c, strongfibo.c,
+			fib2m.c, strongfibo.c, mulmod_bknp1.c,
 			mullo_n.c, sqrlo.c, invert.c, invertappr.c;
 			mpn/x86/atom/aors_n.asm, aorslshC_n.asm,
 			aorrlsh{1,2,C}_n.asm, aorsmul_1.asm, logops_n.asm,
@@ -104,3 +104,5 @@
 			mpn/powerpc64/mode64/p7/gcd_1.asm,
 			mpn/powerpc64/p6/{lshift,lshiftc,rshift}.asm,
 			mpn/powerpc64/vmx/popcount.asm.
+
+Seth Troisi		mpz/nextprime.c general speed-up and prevprime.
diff -r f43365857aba -r e593a00163f3 mpz/nextprime.c
--- a/mpz/nextprime.c	Fri May 13 20:49:04 2022 +0200
+++ b/mpz/nextprime.c	Sat May 14 09:13:49 2022 +0200
@@ -1,6 +1,6 @@
 /* mpz_nextprime(p,t) - compute the next prime > t and store that in p.
 
-Copyright 1999-2001, 2008, 2009, 2012, 2020, 2021 Free Software
+Copyright 1999-2001, 2008, 2009, 2012, 2020-2022 Free Software
 Foundation, Inc.
 
 Contributed to the GNU project by Niels Möller and Torbjorn Granlund.
@@ -129,7 +129,7 @@
 static int
 findnext (mpz_ptr p,
           unsigned long(*negative_mod_ui)(const mpz_t, unsigned long),
-          void(*increment_ui)(mpz_t, const mpz_t, unsigned long))
+          void(*increment_ui)(mpz_t, const mpz_t, unsigned long), unsigned long nth)
 {
   char *composite;
   const unsigned char *primegap;
@@ -239,7 +239,7 @@
 
           /* Miller-Rabin test */
           primetest = mpz_millerrabin (p, 25);
-          if (primetest)
+          if (primetest && (--nth == 0))
 	    {
 	      TMP_FREE;
 	      return primetest;
@@ -265,7 +265,7 @@
   /* First odd greater than n */
   mpz_add_ui (p, n, 1);
 
-  findnext(p, mpz_cdiv_ui, mpz_add_ui);
+  findnext(p, mpz_cdiv_ui, mpz_add_ui, 1);
 }
 
 int
@@ -285,6 +285,6 @@
   /* First odd less than n */
   mpz_sub_ui (p, n, 2);
 
-  return findnext(p, mpz_tdiv_ui, mpz_sub_ui);
+  return findnext(p, mpz_tdiv_ui, mpz_sub_ui, 1);
 }
 
diff -r f43365857aba -r e593a00163f3 tests/mpz/t-pprime_p.c
--- a/tests/mpz/t-pprime_p.c	Fri May 13 20:49:04 2022 +0200
+++ b/tests/mpz/t-pprime_p.c	Sat May 14 09:13:49 2022 +0200
@@ -31,26 +31,20 @@
      composite.  */
 
 
-/* return 1 if prime, 0 if composite */
+/* return 2 if prime, 0 if composite */
 int
-isprime (long n)
+isprime (unsigned long n)
 {
-  long  i;
-
-  n = ABS(n);
-
-  if (n < 2)
-    return 0;
   if (n < 4)
-    return 1;
+    return (n & 2);
   if ((n & 1) == 0)
     return 0;
 
-  for (i = 3; i*i <= n; i+=2)
+  for (unsigned long i = 3; i*i <= n; i+=2)
     if ((n % i) == 0)
       return 0;
 
-  return 1;
+  return 2;
 }
 
 void
@@ -60,11 +54,8 @@
 
   got = mpz_probab_prime_p (n, 25);
 
-  /* "definitely prime" is fine if we only wanted "probably prime" */
-  if (got == 2 && want == 1)
-    want = 2;
-
-  if (got != want)
+  /* "definitely prime" (2) is fine if we only wanted "probably prime" (1) */
+  if ((got != want) && (got != want * 2))
     {
       printf ("mpz_probab_prime_p\n");
       mpz_trace ("  n    ", n);
@@ -94,7 +85,7 @@
   for (i = 0; i < 300; i++)
     {
       mpz_set_si (n, i);
-      check_pn (n, 2 * isprime (i));
+      check_pn (n, isprime (i));
     }
 
   mpz_clear (n);


More information about the gmp-commit mailing list