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

mercurial at gmplib.org mercurial at gmplib.org
Tue Aug 16 22:04:00 CEST 2022


details:   /var/hg/gmp/rev/60815c1e8252
changeset: 18365:60815c1e8252
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Aug 16 22:01:09 2022 +0200
description:
mpz/primorial_ui.c: Rename some variables and add comments

details:   /var/hg/gmp/rev/e3123b88d012
changeset: 18366:e3123b88d012
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Aug 16 22:02:45 2022 +0200
description:
ChangeLog

diffstat:

 ChangeLog          |  18 ++++++++++++++++++
 mini-gmp/ChangeLog |   3 +++
 mpz/primorial_ui.c |  27 ++++++++++++++++-----------
 3 files changed, 37 insertions(+), 11 deletions(-)

diffs (110 lines):

diff -r d337756619a0 -r e3123b88d012 ChangeLog
--- a/ChangeLog	Thu Aug 11 22:58:46 2022 +0200
+++ b/ChangeLog	Tue Aug 16 22:02:45 2022 +0200
@@ -1,3 +1,21 @@
+2022-08-11 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpz/primorial_ui.c: Rename some variables and add comments.
+
+2022-06-19 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpz/millerrabin.c: Use mp_bitcnt_t.
+	* mpz/stronglucas.c: Skip some impossible values searching for D.
+
+2022-05-14 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpz/nextprime.c: Smaller operand for mpz_sqrt.
+	* tests/mpz/t-nextprime.c: Exit on error.
+	* tests/mpz/t-pprime_p.c: More cases to trigger unlikely branches.
+
+	* tests/mpz/t-aorsmul.c: Test the (r,x,x) case.
+	* mpz/aorsmul.c: Speed-up the (r,x,x) case (tx:Fredrik Johansson).
+
 2022-04-18  Marc Glisse  <marc.glisse at inria.fr>
 
 	* gmpxx.h (mpz_class): Do not use mp directly.
diff -r d337756619a0 -r e3123b88d012 mini-gmp/ChangeLog
--- a/mini-gmp/ChangeLog	Thu Aug 11 22:58:46 2022 +0200
+++ b/mini-gmp/ChangeLog	Tue Aug 16 22:02:45 2022 +0200
@@ -1,3 +1,6 @@
+2022-05-29 Marco Bodrato <bodrato at mail.dm.unipi.it>
+	* mini-mpq.c (mpq_helper_2exp): New helper (internal) function.
+
 2022-04-18  Niels Möller  <nisse at lysator.liu.se>
 
 	* mini-gmp.c (gmp_assert_nocarry): Avoid warning about unused
diff -r d337756619a0 -r e3123b88d012 mpz/primorial_ui.c
--- a/mpz/primorial_ui.c	Thu Aug 11 22:58:46 2022 +0200
+++ b/mpz/primorial_ui.c	Tue Aug 16 22:02:45 2022 +0200
@@ -1,4 +1,4 @@
-/* mpz_primorial_ui(RESULT, N) -- Set RESULT to N# the product of primes <= N.
+/* mpz_primorial_ui(RES, N) -- Set RES to N# the product of primes <= N.
 
 Contributed to the GNU project by Marco Bodrato.
 
@@ -66,14 +66,16 @@
 /*********************************************************/
 
 void
-mpz_primorial_ui (mpz_ptr x, unsigned long n)
+mpz_primorial_ui (mpz_ptr res, unsigned long n)
 {
   ASSERT (n <= GMP_NUMB_MAX);
 
   if (n < 5)
     {
-      MPZ_NEWALLOC (x, 1)[0] = (066211 >> (n*3)) & 7;
-      SIZ (x) = 1;
+      /* The smallest 5 results for primorial are stored */
+      /* in a 15-bits constant (five octal digits)	 */
+      MPZ_NEWALLOC (res, 1)[0] = (066211 >> (n * 3)) & 7;
+      SIZ (res) = 1;
     }
   else
     {
@@ -82,10 +84,12 @@
       mp_limb_t prod;
       TMP_DECL;
 
+      /* Try to estimate the result size, to avoid	*/
+      /* resizing, and to initially store the sieve.	*/
       size = n / GMP_NUMB_BITS;
       size = size + (size >> 1) + 1;
       ASSERT (size >= primesieve_size (n));
-      sieve = MPZ_NEWALLOC (x, size);
+      sieve = MPZ_NEWALLOC (res, size);
       size = (gmp_primesieve (sieve, n) + 1) / log_n_max (n) + 1;
 
       TMP_MARK;
@@ -101,24 +105,25 @@
 
 	max_prod = GMP_NUMB_MAX / n;
 
+	/* Loop on sieved primes. */
 	for (mp_limb_t i = 4, *sp = sieve; i < n; i += GMP_LIMB_BITS * 3)
-	  for (mp_limb_t b = i, k = ~ *(sp++); k != 0; b += 3, k >>= 1)
-	    if (k & 1)
+	  for (mp_limb_t b = i, x = ~ *(sp++); x != 0; b += 3, x >>= 1)
+	    if (x & 1)
 	      {
 		mp_limb_t prime = b | 1;
-	FACTOR_LIST_STORE (prime, prod, max_prod, factors, j);
+		FACTOR_LIST_STORE (prime, prod, max_prod, factors, j);
 	      }
       }
 
       if (j != 0)
 	{
 	  factors[j++] = prod;
-	  mpz_prodlimbs (x, factors, j);
+	  mpz_prodlimbs (res, factors, j);
 	}
       else
 	{
-	  PTR (x)[0] = prod;
-	  SIZ (x) = 1;
+	  PTR (res)[0] = prod;
+	  SIZ (res) = 1;
 	}
 
       TMP_FREE;


More information about the gmp-commit mailing list