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

mercurial at gmplib.org mercurial at gmplib.org
Fri Apr 20 11:01:53 CEST 2012


details:   /var/hg/gmp/rev/e0ddedf3706f
changeset: 14865:e0ddedf3706f
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Apr 20 08:39:55 2012 +0200
description:
mpz/setbit.c: Simplify.

details:   /var/hg/gmp/rev/6dcfa8799a86
changeset: 14866:6dcfa8799a86
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Apr 20 09:32:28 2012 +0200
description:
Move LOG2C to gmp-impl.h

details:   /var/hg/gmp/rev/26a932524290
changeset: 14867:26a932524290
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Apr 20 10:59:07 2012 +0200
description:
mpz/bin_uiui.c (mpz_goetgheluck_bin_uiui): Move declarations.

details:   /var/hg/gmp/rev/2b95dd17ac2d
changeset: 14868:2b95dd17ac2d
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Apr 20 11:01:42 2012 +0200
description:
mpz/bin_uiui.c (mpz_goetgheluck_bin_uiui): assume that n and k are not small.

diffstat:

 ChangeLog                |  14 ++++++++++++++
 gmp-impl.h               |   7 +++++++
 mpn/generic/binvert.c    |  11 ++---------
 mpn/generic/invertappr.c |  10 +---------
 mpz/2fac_ui.c            |   8 --------
 mpz/bin_uiui.c           |  17 ++++++++---------
 mpz/fac_ui.c             |   8 --------
 mpz/oddfac_1.c           |   8 --------
 mpz/setbit.c             |  26 ++++++++++++--------------
 9 files changed, 44 insertions(+), 65 deletions(-)

diffs (287 lines):

diff -r 518022aa78cf -r 2b95dd17ac2d ChangeLog
--- a/ChangeLog	Thu Apr 19 23:30:58 2012 +0200
+++ b/ChangeLog	Fri Apr 20 11:01:42 2012 +0200
@@ -1,3 +1,17 @@
+2012-04-20 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpz/setbit.c: Simplify.
+
+	* gmp-impl.h (LOG2C): Define.
+	* mpz/fac_ui.c (LOG2C): Remove.
+	* mpz/2fac_ui.c (LOG2C): Remove.
+	* mpz/oddfac_1.c (LOG2C): Remove.
+	* mpn/generic/binvert.c (LOG2C): Remove.
+	* mpn/generic/invertappr.c (LOG2C): Remove.
+
+	* mpz/bin_uiui.c (mpz_goetgheluck_bin_uiui): Move declarations,
+	and assume that n and k are not small.
+
 2012-04-19  Torbjorn Granlund  <tege at gmplib.org>
 
 	* tests/mpz/Makefile.am (check_PROGRAMS): Add t-remove.
diff -r 518022aa78cf -r 2b95dd17ac2d gmp-impl.h
--- a/gmp-impl.h	Thu Apr 19 23:30:58 2012 +0200
+++ b/gmp-impl.h	Fri Apr 20 11:01:42 2012 +0200
@@ -528,6 +528,13 @@
    return true though, so avoid that.  */
 #define POW2_P(n)  (((n) & ((n) - 1)) == 0)
 
+/* This is intended for constant THRESHOLDs only, where the compiler
+   can completely fold the result.  */
+#define LOG2C(n) \
+ (((n) >=    0x1) + ((n) >=    0x2) + ((n) >=    0x4) + ((n) >=    0x8) + \
+  ((n) >=   0x10) + ((n) >=   0x20) + ((n) >=   0x40) + ((n) >=   0x80) + \
+  ((n) >=  0x100) + ((n) >=  0x200) + ((n) >=  0x400) + ((n) >=  0x800) + \
+  ((n) >= 0x1000) + ((n) >= 0x2000) + ((n) >= 0x4000) + ((n) >= 0x8000))
 
 /* The "short" defines are a bit different because shorts are promoted to
    ints by ~ or >> etc.
diff -r 518022aa78cf -r 2b95dd17ac2d mpn/generic/binvert.c
--- a/mpn/generic/binvert.c	Thu Apr 19 23:30:58 2012 +0200
+++ b/mpn/generic/binvert.c	Fri Apr 20 11:01:42 2012 +0200
@@ -6,7 +6,8 @@
    SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES.  IN FACT, IT IS ALMOST
    GUARANTEED THAT THEY WILL CHANGE OR DISAPPEAR IN A FUTURE GMP RELEASE.
 
-Copyright (C) 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
+Copyright (C) 2004, 2005, 2006, 2007, 2009, 2012 Free Software
+Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -32,14 +33,6 @@
   r[k+1] = r[k] + r[k] - r[k]*(u*r[k])
 */
 
-/* This is intended for constant THRESHOLDs only, where the compiler can
-   completely fold the result.  */
-#define LOG2C(n) \
- (((n) >=    0x1) + ((n) >=    0x2) + ((n) >=    0x4) + ((n) >=    0x8) + \
-  ((n) >=   0x10) + ((n) >=   0x20) + ((n) >=   0x40) + ((n) >=   0x80) + \
-  ((n) >=  0x100) + ((n) >=  0x200) + ((n) >=  0x400) + ((n) >=  0x800) + \
-  ((n) >= 0x1000) + ((n) >= 0x2000) + ((n) >= 0x4000) + ((n) >= 0x8000))
-
 #if TUNE_PROGRAM_BUILD
 #define NPOWS \
  ((sizeof(mp_size_t) > 6 ? 48 : 8*sizeof(mp_size_t)))
diff -r 518022aa78cf -r 2b95dd17ac2d mpn/generic/invertappr.c
--- a/mpn/generic/invertappr.c	Thu Apr 19 23:30:58 2012 +0200
+++ b/mpn/generic/invertappr.c	Fri Apr 20 11:01:42 2012 +0200
@@ -12,7 +12,7 @@
    SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES.  IN FACT, IT IS ALMOST
    GUARANTEED THAT THEY WILL CHANGE OR DISAPPEAR IN A FUTURE GMP RELEASE.
 
-Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
+Copyright (C) 2007, 2009, 2010, 2012 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -41,14 +41,6 @@
    parts, the use of log_2 (or counting the bits) underestimate the maximum
    number of iterations.  */
 
-/* This is intended for constant THRESHOLDs only, where the compiler
-   can completely fold the result.  */
-#define LOG2C(n) \
- (((n) >=    0x1) + ((n) >=    0x2) + ((n) >=    0x4) + ((n) >=    0x8) + \
-  ((n) >=   0x10) + ((n) >=   0x20) + ((n) >=   0x40) + ((n) >=   0x80) + \
-  ((n) >=  0x100) + ((n) >=  0x200) + ((n) >=  0x400) + ((n) >=  0x800) + \
-  ((n) >= 0x1000) + ((n) >= 0x2000) + ((n) >= 0x4000) + ((n) >= 0x8000))
-
 #if TUNE_PROGRAM_BUILD
 #define NPOWS \
  ((sizeof(mp_size_t) > 6 ? 48 : 8*sizeof(mp_size_t)))
diff -r 518022aa78cf -r 2b95dd17ac2d mpz/2fac_ui.c
--- a/mpz/2fac_ui.c	Thu Apr 19 23:30:58 2012 +0200
+++ b/mpz/2fac_ui.c	Fri Apr 20 11:01:42 2012 +0200
@@ -24,14 +24,6 @@
 
 #include "fac_ui.h"
 
-/* This is intended for constant THRESHOLDs only, where the compiler
-   can completely fold the result.  */
-#define LOG2C(n) \
- (((n) >=    0x1) + ((n) >=    0x2) + ((n) >=    0x4) + ((n) >=    0x8) + \
-  ((n) >=   0x10) + ((n) >=   0x20) + ((n) >=   0x40) + ((n) >=   0x80) + \
-  ((n) >=  0x100) + ((n) >=  0x200) + ((n) >=  0x400) + ((n) >=  0x800) + \
-  ((n) >= 0x1000) + ((n) >= 0x2000) + ((n) >= 0x4000) + ((n) >= 0x8000))
-
 #define FACTOR_LIST_STORE(P, PR, MAX_PR, VEC, I)		\
   do {								\
     if ((PR) > (MAX_PR)) {					\
diff -r 518022aa78cf -r 2b95dd17ac2d mpz/bin_uiui.c
--- a/mpz/bin_uiui.c	Thu Apr 19 23:30:58 2012 +0200
+++ b/mpz/bin_uiui.c	Fri Apr 20 11:01:42 2012 +0200
@@ -580,10 +580,11 @@
 mpz_goetgheluck_bin_uiui (mpz_ptr r, unsigned long int n, unsigned long int k)
 {
   mp_limb_t *sieve, *factors, count;
+  mp_limb_t prod, max_prod, j;
   TMP_DECL;
 
-  ASSERT (k >= 4);
-  ASSERT (n >= 8);
+  ASSERT (BIN_GOETGHELUCK_THRESHOLD >= 13);
+  ASSERT (n >= 25);
 
   TMP_MARK;
   sieve = TMP_ALLOC_LIMBS (primesieve_size (n));
@@ -591,7 +592,6 @@
   count = gmp_primesieve (sieve, n) + 1;
   factors = TMP_ALLOC_LIMBS (count / log_n_max (n) + 1);
 
-  mp_limb_t prod, max_prod, j;
   j = 0;
 
   prod = 1;
@@ -601,11 +601,11 @@
   COUNT_A_PRIME (2, n, k, prod, max_prod, factors, j);
   COUNT_A_PRIME (3, n, k, prod, max_prod, factors, j);
 
-  if (n >= 10) /* Accumulate prime factors from 5 to n/2 */
+  /* Accumulate prime factors from 5 to n/2 */
     {
       mp_limb_t s;
 
-      if (n > 24) {
+      {
 	mp_limb_t prime;
 	s = limb_apprsqrt(n);
 	s = n_to_bit (s);
@@ -613,8 +613,7 @@
 	COUNT_A_PRIME (prime, n, k, prod, max_prod, factors, j);
 	LOOP_ON_SIEVE_END;
 	s++;
-      } else
-	s = 0;
+      }
 
       ASSERT (max_prod <= GMP_NUMB_MAX / 2);
       max_prod <<= 1;
@@ -631,7 +630,7 @@
     }
 
   /* Store primes from (n-k)+1 to n */
-  if (n_to_bit (n - k) < n_to_bit (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);
@@ -639,7 +638,7 @@
       LOOP_ON_SIEVE_END;
     }
 
-  if (j != 0)
+  if (LIKELY (j != 0))
     {
       factors[j++] = prod;
       mpz_prodlimbs (r, factors, j);
diff -r 518022aa78cf -r 2b95dd17ac2d mpz/fac_ui.c
--- a/mpz/fac_ui.c	Thu Apr 19 23:30:58 2012 +0200
+++ b/mpz/fac_ui.c	Fri Apr 20 11:01:42 2012 +0200
@@ -25,14 +25,6 @@
 
 #include "fac_ui.h"
 
-/* This is intended for constant THRESHOLDs only, where the compiler
-   can completely fold the result.  */
-#define LOG2C(n) \
- (((n) >=    0x1) + ((n) >=    0x2) + ((n) >=    0x4) + ((n) >=    0x8) + \
-  ((n) >=   0x10) + ((n) >=   0x20) + ((n) >=   0x40) + ((n) >=   0x80) + \
-  ((n) >=  0x100) + ((n) >=  0x200) + ((n) >=  0x400) + ((n) >=  0x800) + \
-  ((n) >= 0x1000) + ((n) >= 0x2000) + ((n) >= 0x4000) + ((n) >= 0x8000))
-
 #define FACTOR_LIST_STORE(P, PR, MAX_PR, VEC, I)		\
   do {								\
     if ((PR) > (MAX_PR)) {					\
diff -r 518022aa78cf -r 2b95dd17ac2d mpz/oddfac_1.c
--- a/mpz/oddfac_1.c	Thu Apr 19 23:30:58 2012 +0200
+++ b/mpz/oddfac_1.c	Fri Apr 20 11:01:42 2012 +0200
@@ -251,14 +251,6 @@
 /* Section oddfac: odd factorial, needed also by binomial*/
 /*********************************************************/
 
-/* This is intended for constant THRESHOLDs only, where the compiler
-   can completely fold the result.  */
-#define LOG2C(n) \
- (((n) >=    0x1) + ((n) >=    0x2) + ((n) >=    0x4) + ((n) >=    0x8) + \
-  ((n) >=   0x10) + ((n) >=   0x20) + ((n) >=   0x40) + ((n) >=   0x80) + \
-  ((n) >=  0x100) + ((n) >=  0x200) + ((n) >=  0x400) + ((n) >=  0x800) + \
-  ((n) >= 0x1000) + ((n) >= 0x2000) + ((n) >= 0x4000) + ((n) >= 0x8000))
-
 #if TUNE_PROGRAM_BUILD
 #define FACTORS_PER_LIMB (GMP_NUMB_BITS / (LOG2C(FAC_DSC_THRESHOLD_LIMIT-1)+1))
 #else
diff -r 518022aa78cf -r 2b95dd17ac2d mpz/setbit.c
--- a/mpz/setbit.c	Thu Apr 19 23:30:58 2012 +0200
+++ b/mpz/setbit.c	Fri Apr 20 11:01:42 2012 +0200
@@ -27,23 +27,24 @@
   mp_size_t dsize = SIZ (d);
   mp_ptr dp = PTR (d);
   mp_size_t limb_index;
+  mp_limb_t mask;
 
   limb_index = bit_index / GMP_NUMB_BITS;
+  mask = CNST_LIMB(1) << (bit_index % GMP_NUMB_BITS);
   if (dsize >= 0)
     {
       if (limb_index < dsize)
 	{
-	  dp[limb_index] |= CNST_LIMB(1) << (bit_index % GMP_NUMB_BITS);
-	  SIZ (d) = dsize;
+	  dp[limb_index] |= mask;
 	}
       else
 	{
 	  /* Ugh.  The bit should be set outside of the end of the
 	     number.  We have to increase the size of the number.  */
 	  dp = MPZ_REALLOC (d, limb_index + 1);
+	  SIZ (d) = limb_index + 1;
 	  MPN_ZERO (dp + dsize, limb_index - dsize);
-	  dp[limb_index] = CNST_LIMB(1) << (bit_index % GMP_NUMB_BITS);
-	  SIZ (d) = limb_index + 1;
+	  dp[limb_index] = mask;
 	}
     }
   else
@@ -58,18 +59,17 @@
       dsize = -dsize;
 
       /* No upper bound on this loop, we're sure there's a non-zero limb
-	 sooner ot later.  */
-      for (zero_bound = 0; ; zero_bound++)
-	if (dp[zero_bound] != 0)
-	  break;
+	 sooner or later.  */
+      zero_bound = 0;
+      while (dp[zero_bound] == 0)
+	zero_bound++;
 
       if (limb_index > zero_bound)
 	{
 	  if (limb_index < dsize)
 	    {
 	      mp_limb_t	 dlimb;
-	      dlimb = dp[limb_index];
-	      dlimb &= ~(CNST_LIMB(1) << (bit_index % GMP_NUMB_BITS));
+	      dlimb = dp[limb_index] & ~mask;
 	      dp[limb_index] = dlimb;
 
 	      if (UNLIKELY (dlimb == 0 && limb_index == dsize-1))
@@ -84,14 +84,12 @@
 	}
       else if (limb_index == zero_bound)
 	{
-	  dp[limb_index] = ((dp[limb_index] - 1)
-			    & ~(CNST_LIMB(1) << (bit_index % GMP_NUMB_BITS))) + 1;
+	  dp[limb_index] = ((dp[limb_index] - 1) & ~mask) + 1;
 	  ASSERT (dp[limb_index] != 0);
 	}
       else
 	{
-	  mpn_decr_u (dp + limb_index,
-		     CNST_LIMB(1) << (bit_index % GMP_NUMB_BITS));
+	  MPN_DECR_U (dp + limb_index, dsize - limb_index, mask);
 	  dsize -= dp[dsize - 1] == 0;
 	  SIZ (d) = -dsize;
 	}


More information about the gmp-commit mailing list