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

mercurial at gmplib.org mercurial at gmplib.org
Tue Mar 17 16:05:47 UTC 2020


details:   /var/hg/gmp/rev/b37a55da909b
changeset: 18054:b37a55da909b
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Mar 15 18:24:40 2020 +0100
description:
primesieve.c (SEED_LIMIT): Use the best value for ABI=64

details:   /var/hg/gmp/rev/3e8598b3d039
changeset: 18055:3e8598b3d039
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Mar 15 18:26:21 2020 +0100
description:
: Use one less variable to loop on primes.

details:   /var/hg/gmp/rev/f1511ce1412c
changeset: 18056:f1511ce1412c
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Mar 15 19:44:09 2020 +0100
description:
mpz/root.c: Move a branch out of the likely path.

diffstat:

 mpz/bin_uiui.c       |  14 +++++++-------
 mpz/oddfac_1.c       |  14 +++++++-------
 mpz/primorial_ui.c   |  12 ++++++------
 mpz/root.c           |  28 +++++++++++++---------------
 primesieve.c         |   9 ++++-----
 tests/devel/primes.c |  14 +++++++-------
 6 files changed, 44 insertions(+), 47 deletions(-)

diffs (277 lines):

diff -r 766a0d7bd89e -r f1511ce1412c mpz/bin_uiui.c
--- a/mpz/bin_uiui.c	Wed Mar 11 21:20:57 2020 +0100
+++ b/mpz/bin_uiui.c	Sun Mar 15 19:44:09 2020 +0100
@@ -491,31 +491,31 @@
       (PR) *= (P);						\
   } while (0)
 
-#define LOOP_ON_SIEVE_CONTINUE(prime,end,sieve)			\
+#define LOOP_ON_SIEVE_CONTINUE(prime,end)			\
     __max_i = (end);						\
 								\
     do {							\
       ++__i;							\
-      if (((sieve)[__index] & __mask) == 0)			\
+      if ((*__sieve & __mask) == 0)				\
 	{							\
 	  mp_limb_t prime;					\
 	  prime = id_to_n(__i)
 
 #define LOOP_ON_SIEVE_BEGIN(prime,start,end,off,sieve)		\
   do {								\
-    mp_limb_t __mask, __index, __max_i, __i;			\
+    mp_limb_t __mask, *__sieve, __max_i, __i;			\
 								\
     __i = (start)-(off);					\
-    __index = __i / GMP_LIMB_BITS;				\
+    __sieve = (sieve) + __i / GMP_LIMB_BITS;			\
     __mask = CNST_LIMB(1) << (__i % GMP_LIMB_BITS);		\
     __i += (off);						\
 								\
-    LOOP_ON_SIEVE_CONTINUE(prime,end,sieve)
+    LOOP_ON_SIEVE_CONTINUE(prime,end)
 
 #define LOOP_ON_SIEVE_STOP					\
 	}							\
       __mask = __mask << 1 | __mask >> (GMP_LIMB_BITS-1);	\
-      __index += __mask & 1;					\
+      __sieve += __mask & 1;					\
     }  while (__i <= __max_i)
 
 #define LOOP_ON_SIEVE_END					\
@@ -632,7 +632,7 @@
       ASSERT (max_prod <= GMP_NUMB_MAX / 2);
       max_prod <<= 1;
 
-      LOOP_ON_SIEVE_CONTINUE (prime, n_to_bit (n >> 1),sieve);
+      LOOP_ON_SIEVE_CONTINUE (prime, n_to_bit (n >> 1));
       SH_COUNT_A_PRIME (prime, n, k, prod, max_prod, factors, j);
       LOOP_ON_SIEVE_END;
 
diff -r 766a0d7bd89e -r f1511ce1412c mpz/oddfac_1.c
--- a/mpz/oddfac_1.c	Wed Mar 11 21:20:57 2020 +0100
+++ b/mpz/oddfac_1.c	Sun Mar 15 19:44:09 2020 +0100
@@ -61,31 +61,31 @@
       (PR) *= (P);						\
   } while (0)
 
-#define LOOP_ON_SIEVE_CONTINUE(prime,end,sieve)			\
+#define LOOP_ON_SIEVE_CONTINUE(prime,end)			\
     __max_i = (end);						\
 								\
     do {							\
       ++__i;							\
-      if (((sieve)[__index] & __mask) == 0)			\
+      if ((*__sieve & __mask) == 0)				\
 	{							\
 	  mp_limb_t prime;					\
 	  prime = id_to_n(__i)
 
 #define LOOP_ON_SIEVE_BEGIN(prime,start,end,off,sieve)		\
   do {								\
-    mp_limb_t __mask, __index, __max_i, __i;			\
+    mp_limb_t __mask, *__sieve, __max_i, __i;			\
 								\
     __i = (start)-(off);					\
-    __index = __i / GMP_LIMB_BITS;				\
+    __sieve = (sieve) + __i / GMP_LIMB_BITS;			\
     __mask = CNST_LIMB(1) << (__i % GMP_LIMB_BITS);		\
     __i += (off);						\
 								\
-    LOOP_ON_SIEVE_CONTINUE(prime,end,sieve)
+    LOOP_ON_SIEVE_CONTINUE(prime,end)
 
 #define LOOP_ON_SIEVE_STOP					\
 	}							\
       __mask = __mask << 1 | __mask >> (GMP_LIMB_BITS-1);	\
-      __index += __mask & 1;					\
+      __sieve += __mask & 1;					\
     }  while (__i <= __max_i)
 
 #define LOOP_ON_SIEVE_END					\
@@ -222,7 +222,7 @@
 
     l_max_prod = max_prod * 3;
 
-    LOOP_ON_SIEVE_CONTINUE (prime, n_to_bit (n/3), sieve);
+    LOOP_ON_SIEVE_CONTINUE (prime, n_to_bit (n/3));
     SH_SWING_A_PRIME (prime, n, prod, l_max_prod, factors, j);
     LOOP_ON_SIEVE_END;
   }
diff -r 766a0d7bd89e -r f1511ce1412c mpz/primorial_ui.c
--- a/mpz/primorial_ui.c	Wed Mar 11 21:20:57 2020 +0100
+++ b/mpz/primorial_ui.c	Sun Mar 15 19:44:09 2020 +0100
@@ -48,31 +48,31 @@
       (PR) *= (P);						\
   } while (0)
 
-#define LOOP_ON_SIEVE_CONTINUE(prime,end,sieve)			\
+#define LOOP_ON_SIEVE_CONTINUE(prime,end)			\
     __max_i = (end);						\
 								\
     do {							\
       ++__i;							\
-      if (((sieve)[__index] & __mask) == 0)			\
+      if ((*__sieve & __mask) == 0)				\
 	{							\
 	  mp_limb_t prime;					\
 	  prime = id_to_n(__i)
 
 #define LOOP_ON_SIEVE_BEGIN(prime,start,end,off,sieve)		\
   do {								\
-    mp_limb_t __mask, __index, __max_i, __i;			\
+    mp_limb_t __mask, *__sieve, __max_i, __i;			\
 								\
     __i = (start)-(off);					\
-    __index = __i / GMP_LIMB_BITS;				\
+    __sieve = (sieve) + __i / GMP_LIMB_BITS;			\
     __mask = CNST_LIMB(1) << (__i % GMP_LIMB_BITS);		\
     __i += (off);						\
 								\
-    LOOP_ON_SIEVE_CONTINUE(prime,end,sieve)
+    LOOP_ON_SIEVE_CONTINUE(prime,end)
 
 #define LOOP_ON_SIEVE_STOP					\
 	}							\
       __mask = __mask << 1 | __mask >> (GMP_LIMB_BITS-1);	\
-      __index += __mask & 1;					\
+      __sieve += __mask & 1;					\
     }  while (__i <= __max_i)
 
 #define LOOP_ON_SIEVE_END					\
diff -r 766a0d7bd89e -r f1511ce1412c mpz/root.c
--- a/mpz/root.c	Wed Mar 11 21:20:57 2020 +0100
+++ b/mpz/root.c	Sun Mar 15 19:44:09 2020 +0100
@@ -1,7 +1,7 @@
 /* mpz_root(root, u, nth) --  Set ROOT to floor(U^(1/nth)).
    Return an indication if the result is exact.
 
-Copyright 1999-2003, 2005, 2012 Free Software Foundation, Inc.
+Copyright 1999-2003, 2005, 2012, 2020 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -45,10 +45,17 @@
   if (UNLIKELY (us < 0 && (nth & 1) == 0))
     SQRT_OF_NEGATIVE;
 
-  /* root extraction interpreted as c^(1/nth) means a zeroth root should
-     provoke a divide by zero, do this even if c==0 */
-  if (UNLIKELY (nth == 0))
-    DIVIDE_BY_ZERO;
+  if (UNLIKELY (nth <= 1))
+    {
+      /* root extraction interpreted as c^(1/nth) means a zeroth root should
+	 provoke a divide by zero, do this even if c==0 */
+      if (UNLIKELY (nth == 0))
+	DIVIDE_BY_ZERO;
+      /* nth == 1 */
+      if (root != NULL && u != root)
+	mpz_set (root, u);
+      return 1;			/* exact result */
+    }
 
   if (us == 0)
     {
@@ -69,16 +76,7 @@
     rootp = TMP_ALLOC_LIMBS (rootn);
 
   up = PTR(u);
-
-  if (nth == 1)
-    {
-      MPN_COPY (rootp, up, un);
-      remn = 0;
-    }
-  else
-    {
-      remn = mpn_rootrem (rootp, NULL, up, un, (mp_limb_t) nth);
-    }
+  remn = mpn_rootrem (rootp, NULL, up, un, (mp_limb_t) nth);
 
   if (root != NULL)
     {
diff -r 766a0d7bd89e -r f1511ce1412c primesieve.c
--- a/primesieve.c	Wed Mar 11 21:20:57 2020 +0100
+++ b/primesieve.c	Sun Mar 15 19:44:09 2020 +0100
@@ -65,7 +65,7 @@
 #define SIEVE_2MSK1 CNST_LIMB(0x9402180c40230184)
 #define SIEVE_2MSK2 CNST_LIMB(0x0285021088402120)
 #define SIEVE_2MSKT CNST_LIMB(0xa41210084421)
-#define SEED_LIMIT 210
+#define SEED_LIMIT 288
 #else
 #define SEED_LIMIT 202
 #endif
@@ -313,7 +313,7 @@
 	       mp_srcptr sieve)
 {
   mp_size_t bits, off = offset;
-  mp_limb_t mask, index, i;
+  mp_limb_t mask, i;
 
   ASSERT (limbs > 0);
   ASSERT (offset >= GMP_LIMB_BITS);
@@ -325,10 +325,9 @@
   ASSERT (i < GMP_LIMB_BITS);
 
   mask = CNST_LIMB(1) << i;
-  index = 0;
   do {
     ++i;
-    if ((sieve[index] & mask) == 0)
+    if ((*sieve & mask) == 0)
       {
 	mp_size_t step, lindex;
 	mp_limb_t lmask;
@@ -371,7 +370,7 @@
 	};
       }
       mask = mask << 1 | mask >> (GMP_LIMB_BITS-1);
-      index += mask & 1;
+      sieve += mask & 1;
   } while (1);
 }
 
diff -r 766a0d7bd89e -r f1511ce1412c tests/devel/primes.c
--- a/tests/devel/primes.c	Wed Mar 11 21:20:57 2020 +0100
+++ b/tests/devel/primes.c	Sun Mar 15 19:44:09 2020 +0100
@@ -68,31 +68,31 @@
 /* Section macros: common macros, for swing/fac/bin (&sieve) */
 /*************************************************************/
 
-#define LOOP_ON_SIEVE_CONTINUE(prime,end,sieve)			\
+#define LOOP_ON_SIEVE_CONTINUE(prime,end)			\
     __max_i = (end);						\
 								\
     do {							\
       ++__i;							\
-      if (((sieve)[__index] & __mask) == 0)			\
+      if ((*__sieve & __mask) == 0)				\
 	{							\
-          mp_limb_t prime;					\
+	  mp_limb_t prime;					\
 	  prime = id_to_n(__i)
 
 #define LOOP_ON_SIEVE_BEGIN(prime,start,end,off,sieve)		\
   do {								\
-    mp_limb_t __mask, __index, __max_i, __i;			\
+    mp_limb_t __mask, *__sieve, __max_i, __i;			\
 								\
     __i = (start)-(off);					\
-    __index = __i / GMP_LIMB_BITS;				\
+    __sieve = (sieve) + __i / GMP_LIMB_BITS;			\
     __mask = CNST_LIMB(1) << (__i % GMP_LIMB_BITS);		\
     __i += (off);						\
 								\
-    LOOP_ON_SIEVE_CONTINUE(prime,end,sieve)
+    LOOP_ON_SIEVE_CONTINUE(prime,end)
 
 #define LOOP_ON_SIEVE_STOP					\
 	}							\
       __mask = __mask << 1 | __mask >> (GMP_LIMB_BITS-1);	\
-      __index += __mask & 1;					\
+      __sieve += __mask & 1;					\
     }  while (__i <= __max_i)
 
 #define LOOP_ON_SIEVE_END					\


More information about the gmp-commit mailing list