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

mercurial at gmplib.org mercurial at gmplib.org
Mon Nov 16 07:04:54 UTC 2015


details:   /var/hg/gmp/rev/fb549f8e5248
changeset: 16964:fb549f8e5248
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Nov 13 07:23:32 2015 +0100
description:
mpq/init.c: Remove conditional code for __CHECKER__.

details:   /var/hg/gmp/rev/4f4275ff8c85
changeset: 16965:4f4275ff8c85
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Nov 16 08:01:47 2015 +0100
description:
mpq/set*.c: Shorten scope of local variables.

details:   /var/hg/gmp/rev/348606a49402
changeset: 16966:348606a49402
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Nov 16 08:02:22 2015 +0100
description:
mini-gmp/mini-gmp.c (mpz_rootrem): Exploit lazy allocation to avoid init2.

details:   /var/hg/gmp/rev/69e6a14022e8
changeset: 16967:69e6a14022e8
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Nov 16 08:02:43 2015 +0100
description:
primesieve.c: Fill (initial) sieve with a presieved 70bits pattern.

details:   /var/hg/gmp/rev/731d0cdf4bb7
changeset: 16968:731d0cdf4bb7
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Nov 16 08:04:31 2015 +0100
description:
ChangeLog

diffstat:

 ChangeLog           |   9 +++++++
 mini-gmp/mini-gmp.c |   8 +----
 mpq/init.c          |   7 +----
 mpq/set.c           |   7 +++--
 mpq/set_den.c       |   5 ++-
 mpq/set_num.c       |   5 ++-
 mpq/set_z.c         |   4 +-
 primesieve.c        |  64 ++++++++++++++++++++++++++++++++++++++++++++++------
 8 files changed, 80 insertions(+), 29 deletions(-)

diffs (274 lines):

diff -r c1ae4ee719a1 -r 731d0cdf4bb7 ChangeLog
--- a/ChangeLog	Fri Nov 13 07:13:46 2015 +0100
+++ b/ChangeLog	Mon Nov 16 08:04:31 2015 +0100
@@ -1,8 +1,17 @@
 2015-11-13 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
 	* mini-gmp/mini-gmp.c: Lazy allocation for mpz_t.
+	(mpz_rootrem): Exploit lazy allocation to avoid init2.
 	* mpz/set.c: Use MPZ_NEWALLOC.
 
+	* mpq/init.c: Remove conditional code for __CHECKER__.
+	* mpq/set.c: Shorten scope of local variables.
+	* mpq/set_den.c: Likewise.
+	* mpq/set_num.c: Likewise.
+	* mpq/set_z.c: Likewise.
+
+	* primesieve.c: Fill (initial) sieve with a presieved 70bits pattern.
+
 2015-11-12  Marc Glisse  <marc.glisse at inria.fr>
 
 	* gmpxx.h (__gmp_fibonacci_function): New class.
diff -r c1ae4ee719a1 -r 731d0cdf4bb7 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Fri Nov 13 07:13:46 2015 +0100
+++ b/mini-gmp/mini-gmp.c	Mon Nov 16 08:04:31 2015 +0100
@@ -3214,12 +3214,8 @@
   }
 
   mpz_init (u);
-  {
-    mp_bitcnt_t tb;
-    tb = mpz_sizeinbase (y, 2) / z + 1;
-    mpz_init2 (t, tb + 1);
-    mpz_setbit (t, tb);
-  }
+  mpz_init (t);
+  mpz_setbit (t, mpz_sizeinbase (y, 2) / z + 1);
 
   if (z == 2) /* simplify sqrt loop: z-1 == 1 */
     do {
diff -r c1ae4ee719a1 -r 731d0cdf4bb7 mpq/init.c
--- a/mpq/init.c	Fri Nov 13 07:13:46 2015 +0100
+++ b/mpq/init.c	Mon Nov 16 08:04:31 2015 +0100
@@ -1,6 +1,6 @@
 /* mpq_init -- Make a new rational number with value 0/1.
 
-Copyright 1991, 1994, 1995, 2000-2002 Free Software Foundation, Inc.
+Copyright 1991, 1994, 1995, 2000-2002, 2015 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -41,9 +41,4 @@
   PTR(DEN(x)) = __GMP_ALLOCATE_FUNC_LIMBS (1);
   PTR(DEN(x))[0] = 1;
   SIZ(DEN(x)) = 1;
-
-#ifdef __CHECKER__
-  /* let the low limb look initialized, for the benefit of mpz_get_ui etc */
-  PTR(NUM(x))[0] = 0;
-#endif
 }
diff -r c1ae4ee719a1 -r 731d0cdf4bb7 mpq/set.c
--- a/mpq/set.c	Fri Nov 13 07:13:46 2015 +0100
+++ b/mpq/set.c	Mon Nov 16 08:04:31 2015 +0100
@@ -1,6 +1,7 @@
 /* mpq_set(dest,src) -- Set DEST to SRC.
 
-Copyright 1991, 1994, 1995, 2001, 2012 Free Software Foundation, Inc.
+Copyright 1991, 1994, 1995, 2001, 2012, 2015 Free Software Foundation,
+Inc.
 
 This file is part of the GNU MP Library.
 
@@ -39,13 +40,13 @@
   mp_ptr dp;
 
   num_size = SIZ(NUM(src));
+  SIZ(NUM(dest)) = num_size;
   abs_num_size = ABS (num_size);
   dp = MPZ_NEWALLOC (NUM(dest), abs_num_size);
-  SIZ(NUM(dest)) = num_size;
   MPN_COPY (dp, PTR(NUM(src)), abs_num_size);
 
   den_size = SIZ(DEN(src));
+  SIZ(DEN(dest)) = den_size;
   dp = MPZ_NEWALLOC (DEN(dest), den_size);
-  SIZ(DEN(dest)) = den_size;
   MPN_COPY (dp, PTR(DEN(src)), den_size);
 }
diff -r c1ae4ee719a1 -r 731d0cdf4bb7 mpq/set_den.c
--- a/mpq/set_den.c	Fri Nov 13 07:13:46 2015 +0100
+++ b/mpq/set_den.c	Mon Nov 16 08:04:31 2015 +0100
@@ -1,6 +1,7 @@
 /* mpq_set_den(dest,den) -- Set the denominator of DEST from DEN.
 
-Copyright 1991, 1994-1996, 2000, 2001, 2012 Free Software Foundation, Inc.
+Copyright 1991, 1994-1996, 2000, 2001, 2012, 2015 Free Software
+Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -38,8 +39,8 @@
   mp_size_t abs_size = ABS (size);
   mp_ptr dp;
 
+  SIZ(DEN(dest)) = size;
   dp = MPZ_NEWALLOC (DEN(dest), abs_size);
 
-  SIZ(DEN(dest)) = size;
   MPN_COPY (dp, PTR(den), abs_size);
 }
diff -r c1ae4ee719a1 -r 731d0cdf4bb7 mpq/set_num.c
--- a/mpq/set_num.c	Fri Nov 13 07:13:46 2015 +0100
+++ b/mpq/set_num.c	Mon Nov 16 08:04:31 2015 +0100
@@ -1,6 +1,7 @@
 /* mpq_set_num(dest,num) -- Set the numerator of DEST from NUM.
 
-Copyright 1991, 1994, 1995, 2001, 2012 Free Software Foundation, Inc.
+Copyright 1991, 1994, 1995, 2001, 2012, 2015 Free Software Foundation,
+Inc.
 
 This file is part of the GNU MP Library.
 
@@ -38,8 +39,8 @@
   mp_size_t abs_size = ABS (size);
   mp_ptr dp;
 
+  SIZ(NUM(dest)) = size;
   dp = MPZ_NEWALLOC (NUM(dest), abs_size);
 
-  SIZ(NUM(dest)) = size;
   MPN_COPY (dp, PTR(num), abs_size);
 }
diff -r c1ae4ee719a1 -r 731d0cdf4bb7 mpq/set_z.c
--- a/mpq/set_z.c	Fri Nov 13 07:13:46 2015 +0100
+++ b/mpq/set_z.c	Mon Nov 16 08:04:31 2015 +0100
@@ -1,6 +1,6 @@
 /* mpq_set_z (dest,src) -- Set DEST to SRC.
 
-Copyright 1996, 2001, 2012 Free Software Foundation, Inc.
+Copyright 1996, 2001, 2012, 2015 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -39,9 +39,9 @@
   mp_ptr dp;
 
   num_size = SIZ (src);
+  SIZ(NUM(dest)) = num_size;
   abs_num_size = ABS (num_size);
   dp = MPZ_NEWALLOC (NUM(dest), abs_num_size);
-  SIZ(NUM(dest)) = num_size;
   MPN_COPY (dp, PTR(src), abs_num_size);
 
   PTR(DEN(dest))[0] = 1;
diff -r c1ae4ee719a1 -r 731d0cdf4bb7 primesieve.c
--- a/primesieve.c	Fri Nov 13 07:13:46 2015 +0100
+++ b/primesieve.c	Mon Nov 16 08:04:31 2015 +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 Free Software Foundation, Inc.
+Copyright 2010-2012, 2015 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -96,11 +96,24 @@
 
 #if GMP_LIMB_BITS > 61
 #define SIEVE_SEED CNST_LIMB(0x3294C9E069128480)
+#if GMP_LIMB_BITS < 67
+#define SIEVE_MASK1 CNST_LIMB(0x1214896069128483)
+#define SIEVE_MASKT (CNST_LIMB(0x3) << (66 - GMP_LIMB_BITS))
+#define SEED_LIMIT 208
+#else
 #define SEED_LIMIT 202
+#endif
 #else
 #if GMP_LIMB_BITS > 30
 #define SIEVE_SEED CNST_LIMB(0x69128480)
+#if GMP_LIMB_BITS < 35
+#define SIEVE_MASK1 CNST_LIMB(0x69128483)
+#define SIEVE_MASK2 (CNST_LIMB(0x1214896) << (36 - GMP_LIMB_BITS))
+#define SIEVE_MASKT (CNST_LIMB(0x3) << (34 - GMP_LIMB_BITS))
+#define SEED_LIMIT 120
+#else
 #define SEED_LIMIT 114
+#endif
 #else
 #if GMP_LIMB_BITS > 15
 #define SIEVE_SEED CNST_LIMB(0x8480)
@@ -117,31 +130,66 @@
 #endif /* 30 */
 #endif /* 61 */
 
+static mp_limb_t
+fill_bitpattern (mp_ptr bit_array, mp_size_t limbs)
+{
+#ifdef SIEVE_MASK1
+  mp_limb_t mask = SIEVE_MASK1;
+  mp_limb_t tail = SIEVE_MASKT;
+  mp_limb_t tmp;
+#ifdef SIEVE_MASK2
+  mp_limb_t mask2= SIEVE_MASK2;
+
+  do {
+    *bit_array = mask;
+    if (--limbs == 0)
+      break;
+    *++bit_array = mask2;
+    tmp = mask2 >> (GMP_LIMB_BITS - (70 - GMP_LIMB_BITS * 2));
+    mask2 = mask2 << (70 - GMP_LIMB_BITS * 2) | mask >> (GMP_LIMB_BITS - (70 - GMP_LIMB_BITS * 2));
+    mask = mask << (70 - GMP_LIMB_BITS * 2) | tail;
+#else
+  do {
+    *bit_array = mask;
+    tmp = mask >> (GMP_LIMB_BITS - (70 - GMP_LIMB_BITS));
+    mask <<= 70 - GMP_LIMB_BITS;
+#endif
+    mask |= tail;
+    tail = tmp;
+    bit_array++;
+  } while (--limbs != 0);
+  return 2;
+#else
+  MPN_ZERO (bit_array, limbs);
+  return 0;
+#endif
+}
+
 static void
 first_block_primesieve (mp_ptr bit_array, mp_limb_t n)
 {
   mp_size_t bits, limbs;
+  mp_limb_t i;
 
   ASSERT (n > 4);
 
   bits  = n_to_bit(n);
   limbs = bits / GMP_LIMB_BITS + 1;
 
-  /* FIXME: We can skip 5 too, filling with a 5-part pattern. */
-  MPN_ZERO (bit_array, limbs);
+  i = fill_bitpattern (bit_array, limbs);
   bit_array[0] = SIEVE_SEED;
 
   if ((bits + 1) % GMP_LIMB_BITS != 0)
     bit_array[limbs-1] |= MP_LIMB_T_MAX << ((bits + 1) % GMP_LIMB_BITS);
 
   if (n > SEED_LIMIT) {
-    mp_limb_t mask, index, i;
+    mp_limb_t mask, index;
 
     ASSERT (n > 49);
 
-    mask = 1;
+    mask = CNST_LIMB(1) << i;
     index = 0;
-    i = 1;
+    ++i;
     do {
       if ((bit_array[index] & mask) == 0)
 	{
@@ -192,8 +240,8 @@
 
   bits = limbs * GMP_LIMB_BITS - 1;
 
-  /* FIXME: We can skip 5 too, filling with a 5-part pattern. */
-  MPN_ZERO (bit_array, limbs);
+  /* FIXME: We can skip 5 and 7 too, filling with a 70-bits pattern. */
+  MPN_FILL (bit_array, limbs, 0);
 
   LOOP_ON_SIEVE_BEGIN(step,0,sieve_bits,0,sieve);
   {


More information about the gmp-commit mailing list