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

mercurial at gmplib.org mercurial at gmplib.org
Sun Jan 3 10:39:10 UTC 2016


details:   /var/hg/gmp/rev/b9c86d4235db
changeset: 17022:b9c86d4235db
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Jan 03 11:31:32 2016 +0100
description:
Use STOP/CONT for loops on primesieve.

details:   /var/hg/gmp/rev/66131f626774
changeset: 17023:66131f626774
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Jan 03 11:39:01 2016 +0100
description:
ChangeLog

diffstat:

 ChangeLog          |   3 +++
 mpz/bin_uiui.c     |  41 +++++++++++++++++------------------------
 mpz/oddfac_1.c     |  51 +++++++++++++++++++++------------------------------
 mpz/primorial_ui.c |  17 +++++++++--------
 4 files changed, 50 insertions(+), 62 deletions(-)

diffs (234 lines):

diff -r ee31937aac1e -r 66131f626774 ChangeLog
--- a/ChangeLog	Sun Jan 03 10:25:43 2016 +0100
+++ b/ChangeLog	Sun Jan 03 11:39:01 2016 +0100
@@ -5,6 +5,9 @@
 
 	* primesieve.c: Heal a speed regression on small values.
 	* mpz/bin_uiui.c (mpz_bdiv_bin_uiui): 2 factors all at once.
+	  (mpz_goetgheluck_bin_uiui): Use STOP/CONT for loops on primesieve.
+	* mpz/oddfac_1.c: Likewise.
+	* mpz/primorial_ui.c (LOOP_ON_SIEVE_CONTINUE): Define prime locally.
 
 	* gen-fac.c: Use unsigned types for sizes.
 	* mini-gmp/mini-gmp.c: Silence wanrings due to (un)signed types.
diff -r ee31937aac1e -r 66131f626774 mpz/bin_uiui.c
--- a/mpz/bin_uiui.c	Sun Jan 03 10:25:43 2016 +0100
+++ b/mpz/bin_uiui.c	Sun Jan 03 11:39:01 2016 +0100
@@ -482,7 +482,8 @@
       ++__i;							\
       if (((sieve)[__index] & __mask) == 0)			\
 	{							\
-	  (prime) = id_to_n(__i)
+	  mp_limb_t prime;					\
+	  prime = id_to_n(__i)
 
 #define LOOP_ON_SIEVE_BEGIN(prime,start,end,off,sieve)		\
   do {								\
@@ -599,38 +600,30 @@
     {
       mp_limb_t s;
 
-      {
-	mp_limb_t prime;
-	s = limb_apprsqrt(n);
-	s = n_to_bit (s);
-	LOOP_ON_SIEVE_BEGIN (prime, n_to_bit (5), s, 0,sieve);
-	COUNT_A_PRIME (prime, n, k, prod, max_prod, factors, j);
-	LOOP_ON_SIEVE_END;
-	s++;
-      }
+      s = limb_apprsqrt(n);
+      s = n_to_bit (s);
+      ASSERT (bit_to_n (s) * bit_to_n (s) > n);
+      ASSERT (s <= n_to_bit (n >> 1));
+      LOOP_ON_SIEVE_BEGIN (prime, n_to_bit (5), s, 0,sieve);
+      COUNT_A_PRIME (prime, n, k, prod, max_prod, factors, j);
+      LOOP_ON_SIEVE_STOP;
 
       ASSERT (max_prod <= GMP_NUMB_MAX / 2);
       max_prod <<= 1;
-      ASSERT (bit_to_n (s) * bit_to_n (s) > n);
-      ASSERT (s <= n_to_bit (n >> 1));
-      {
-	mp_limb_t prime;
 
-	LOOP_ON_SIEVE_BEGIN (prime, s, n_to_bit (n >> 1), 0,sieve);
-	SH_COUNT_A_PRIME (prime, n, k, prod, max_prod, factors, j);
-	LOOP_ON_SIEVE_END;
-      }
+      LOOP_ON_SIEVE_CONTINUE (prime, n_to_bit (n >> 1),sieve);
+      SH_COUNT_A_PRIME (prime, n, k, prod, max_prod, factors, j);
+      LOOP_ON_SIEVE_END;
+
       max_prod >>= 1;
     }
 
   /* Store primes from (n-k)+1 to n */
   ASSERT (n_to_bit (n - k) < n_to_bit (n));
-    {
-      mp_limb_t prime;
-      LOOP_ON_SIEVE_BEGIN (prime, n_to_bit (n - k) + 1, n_to_bit (n), 0,sieve);
-      FACTOR_LIST_STORE (prime, prod, max_prod, factors, j);
-      LOOP_ON_SIEVE_END;
-    }
+
+  LOOP_ON_SIEVE_BEGIN (prime, n_to_bit (n - k) + 1, n_to_bit (n), 0,sieve);
+  FACTOR_LIST_STORE (prime, prod, max_prod, factors, j);
+  LOOP_ON_SIEVE_END;
 
   if (LIKELY (j != 0))
     {
diff -r ee31937aac1e -r 66131f626774 mpz/oddfac_1.c
--- a/mpz/oddfac_1.c	Sun Jan 03 10:25:43 2016 +0100
+++ b/mpz/oddfac_1.c	Sun Jan 03 11:39:01 2016 +0100
@@ -7,7 +7,7 @@
 IN FACT, IT IS ALMOST GUARANTEED THAT IT WILL CHANGE OR
 DISAPPEAR IN A FUTURE GNU MP RELEASE.
 
-Copyright 2010-2012, 2015 Free Software Foundation, Inc.
+Copyright 2010-2012, 2015, 2016 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -69,7 +69,8 @@
       ++__i;							\
       if (((sieve)[__index] & __mask) == 0)			\
 	{							\
-	  (prime) = id_to_n(__i)
+	  mp_limb_t prime;					\
+	  prime = id_to_n(__i)
 
 #define LOOP_ON_SIEVE_BEGIN(prime,start,end,off,sieve)		\
   do {								\
@@ -203,40 +204,30 @@
 
   /* Swing primes from 5 to n/3 */
   {
-    mp_limb_t s;
+    mp_limb_t s, l_max_prod;
 
-    {
-      mp_limb_t prime;
-
-      s = limb_apprsqrt(n);
-      ASSERT (s >= 5);
-      s = n_to_bit (s);
-      LOOP_ON_SIEVE_BEGIN (prime, n_to_bit (5), s, 0,sieve);
-      SWING_A_PRIME (prime, n, prod, max_prod, factors, j);
-      LOOP_ON_SIEVE_END;
-      s++;
-    }
+    s = limb_apprsqrt(n);
+    ASSERT (s >= 5);
+    s = n_to_bit (s);
+    ASSERT (bit_to_n (s) * bit_to_n (s) > n);
+    ASSERT (s <= n_to_bit (n / 3));
+    LOOP_ON_SIEVE_BEGIN (prime, n_to_bit (5), s, 0,sieve);
+    SWING_A_PRIME (prime, n, prod, max_prod, factors, j);
+    LOOP_ON_SIEVE_STOP;
 
     ASSERT (max_prod <= GMP_NUMB_MAX / 3);
-    ASSERT (bit_to_n (s) * bit_to_n (s) > n);
-    ASSERT (s <= n_to_bit (n / 3));
-    {
-      mp_limb_t prime;
-      mp_limb_t l_max_prod = max_prod * 3;
 
-      LOOP_ON_SIEVE_BEGIN (prime, s, n_to_bit (n/3), 0, sieve);
-      SH_SWING_A_PRIME (prime, n, prod, l_max_prod, factors, j);
-      LOOP_ON_SIEVE_END;
-    }
+    l_max_prod = max_prod * 3;
+
+    LOOP_ON_SIEVE_CONTINUE (prime, n_to_bit (n/3), sieve);
+    SH_SWING_A_PRIME (prime, n, prod, l_max_prod, factors, j);
+    LOOP_ON_SIEVE_END;
   }
 
   /* Store primes from (n+1)/2 to n */
-  {
-    mp_limb_t prime;
-    LOOP_ON_SIEVE_BEGIN (prime, n_to_bit (n >> 1) + 1, n_to_bit (n), 0,sieve);
-    FACTOR_LIST_STORE (prime, prod, max_prod, factors, j);
-    LOOP_ON_SIEVE_END;
-  }
+  LOOP_ON_SIEVE_BEGIN (prime, n_to_bit (n >> 1) + 1, n_to_bit (n), 0,sieve);
+  FACTOR_LIST_STORE (prime, prod, max_prod, factors, j);
+  LOOP_ON_SIEVE_END;
 
   if (LIKELY (j != 0))
     {
@@ -416,8 +407,8 @@
 	    ASSERT (ns <= size);
 	    cy = mpn_mul (px, square, size, PTR(mswing), ns); /* n!= n$ * floor(n/2)!^2 */
 
+	    SIZ(x) = nx - (cy == 0);
 	    TMP_FREE;
-	    SIZ(x) = nx - (cy == 0);
 	  } while (s != 0);
 	  TMP_FREE;
 	}
diff -r ee31937aac1e -r 66131f626774 mpz/primorial_ui.c
--- a/mpz/primorial_ui.c	Sun Jan 03 10:25:43 2016 +0100
+++ b/mpz/primorial_ui.c	Sun Jan 03 11:39:01 2016 +0100
@@ -2,7 +2,7 @@
 
 Contributed to the GNU project by Marco Bodrato.
 
-Copyright 2012, 2015 Free Software Foundation, Inc.
+Copyright 2012, 2015, 2016 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -56,7 +56,8 @@
       ++__i;							\
       if (((sieve)[__index] & __mask) == 0)			\
 	{							\
-	  (prime) = id_to_n(__i)
+	  mp_limb_t prime;					\
+	  prime = id_to_n(__i)
 
 #define LOOP_ON_SIEVE_BEGIN(prime,start,end,off,sieve)		\
   do {								\
@@ -120,12 +121,12 @@
   else
     {
       mp_limb_t *sieve, *factors;
-      mp_size_t size;
+      mp_size_t size, j;
       mp_limb_t prod;
-      mp_limb_t j;
       TMP_DECL;
 
-      size = 1 + n / GMP_NUMB_BITS + n / (2*GMP_NUMB_BITS);
+      size = n / GMP_NUMB_BITS;
+      size = size + (size >> 1) + 1;
       ASSERT (size >= primesieve_size (n));
       sieve = MPZ_NEWALLOC (x, size);
       size = (gmp_primesieve (sieve, n) + 1) / log_n_max (n) + 1;
@@ -139,7 +140,7 @@
 
       /* Store primes from 5 to n */
       {
-	mp_limb_t prime, max_prod;
+	mp_limb_t max_prod;
 
 	max_prod = GMP_NUMB_MAX / n;
 
@@ -148,14 +149,14 @@
 	LOOP_ON_SIEVE_END;
       }
 
-      if (LIKELY (j != 0))
+      if (j != 0)
 	{
 	  factors[j++] = prod;
 	  mpz_prodlimbs (x, factors, j);
 	}
       else
 	{
-	  MPZ_NEWALLOC (x, 1)[0] = prod;
+	  PTR (x)[0] = prod;
 	  SIZ (x) = 1;
 	}
 


More information about the gmp-commit mailing list