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

mercurial at gmplib.org mercurial at gmplib.org
Tue Feb 12 08:15:54 CET 2013


details:   /var/hg/gmp/rev/0297705cc8bf
changeset: 15388:0297705cc8bf
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 12 07:54:20 2013 +0100
description:
gen-fac.c (gen_consts): Remove obsolete code.

details:   /var/hg/gmp/rev/c4c73d28ae01
changeset: 15389:c4c73d28ae01
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 12 08:02:01 2013 +0100
description:
gmp-impl.h (MPZ_PROVOKE_REALLOC): Remove unused macro.

details:   /var/hg/gmp/rev/66d75ab54e08
changeset: 15390:66d75ab54e08
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 12 08:10:46 2013 +0100
description:
gen-fac.c (gen_consts): use swap instead of set.

details:   /var/hg/gmp/rev/23a97d1c5843
changeset: 15391:23a97d1c5843
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 12 08:11:38 2013 +0100
description:
mini-gmp/mini-gmp.c (fac_ui, bin_uiui): Use shorter and faster code.

details:   /var/hg/gmp/rev/09468c1f549b
changeset: 15392:09468c1f549b
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 12 08:12:23 2013 +0100
description:
Copyright year.

details:   /var/hg/gmp/rev/972cf6c9c78e
changeset: 15393:972cf6c9c78e
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 12 08:12:35 2013 +0100
description:
ChangeLog

diffstat:

 ChangeLog           |   6 ++++
 gen-fac.c           |  72 +++++-----------------------------------------------
 gmp-impl.h          |   4 --
 mini-gmp/mini-gmp.c |  26 ++++++++----------
 4 files changed, 26 insertions(+), 82 deletions(-)

diffs (188 lines):

diff -r 44cab8046433 -r 972cf6c9c78e ChangeLog
--- a/ChangeLog	Mon Feb 11 22:22:14 2013 +0100
+++ b/ChangeLog	Tue Feb 12 08:12:35 2013 +0100
@@ -1,3 +1,9 @@
+2013-02-12 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* gmp-impl.h (MPZ_PROVOKE_REALLOC): Remove unused macro.
+	* gen-fac.c (gen_consts): Remove obsolete code, use swap instead of set.
+	* mini-gmp/mini-gmp.c (fac_ui, bin_uiui): Use shorter and faster code.
+
 2013-02-10  Torbjorn Granlund  <tege at gmplib.org>
 
 	* Version 5.1.1 released.
diff -r 44cab8046433 -r 972cf6c9c78e gen-fac.c
--- a/gen-fac.c	Mon Feb 11 22:22:14 2013 +0100
+++ b/gen-fac.c	Tue Feb 12 08:12:35 2013 +0100
@@ -1,6 +1,6 @@
 /* Generate data for combinatorics: fac_ui, bin_uiui, ...
 
-Copyright 2002, 2011, 2012 Free Software Foundation, Inc.
+Copyright 2002, 2011, 2012, 2013 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -25,9 +25,8 @@
 int
 mpz_remove_twos (mpz_t x)
 {
-  int r = 0;
-  for (;mpz_even_p (x);r++)
-    mpz_tdiv_q_2exp (x, x, 1);
+  mp_bitcnt_t r = mpz_scan1(x, 0);
+  mpz_tdiv_q_2exp (x, x, r);
   return r;
 }
 
@@ -75,8 +74,8 @@
   for (b = 3;; b++)
     {
       for (a = b; (a & 1) == 0; a >>= 1);
-      mpz_set (last, x);
-      mpz_mul_ui (x, x, a);
+      mpz_swap (last, x);
+      mpz_mul_ui (x, last, a);
       if (mpz_sizeinbase (x, 2) > numb)
 	break;
       printf ("),CNST_LIMB(0x");
@@ -91,7 +90,7 @@
   ofl = b - 1;
   printf
     ("#define ODD_FACTORIAL_TABLE_LIMIT (%lu)\n", ofl);
-  mpz_init (mask);
+  mpz_init2 (mask, numb);
   mpz_setbit (mask, numb);
   mpz_sub_ui (mask, mask, 1);
   printf
@@ -130,8 +129,8 @@
   mpz_set_ui (x, 1);
   for (b = 3;; b+=2)
     {
-      mpz_set (last, x);
-      mpz_mul_ui (x, x, b);
+      mpz_swap (last, x);
+      mpz_mul_ui (x, last, b);
       if (mpz_sizeinbase (x, 2) > numb)
 	break;
       printf ("),CNST_LIMB(0x");
@@ -248,61 +247,6 @@
     }
   printf ("\n");
 
-#if 0
-  mpz_set_ui (x, 1);
-  mpz_mul_2exp (x, x, limb + 1);	/* x=2^(limb+1)        */
-  mpz_init (y);
-  mpz_set_ui (y, 10000);
-  mpz_mul (x, x, y);		/* x=2^(limb+1)*10^4     */
-  mpz_set_ui (y, 27182);	/* exp(1)*10^4      */
-  mpz_tdiv_q (x, x, y);		/* x=2^(limb+1)/exp(1)        */
-  printf ("\n/* is 2^(GMP_LIMB_BITS+1)/exp(1) */\n");
-  printf ("#define FAC2OVERE CNST_LIMB(0x");
-  mpz_out_str (stdout, 16, x);
-  printf (")\n");
-
-
-  printf
-    ("\n/* FACMULn is largest odd x such that x*(x+2)*...*(x+2(n-1))<=2^GMP_NUMB_BITS-1 */\n\n");
-  mpz_init (z);
-  mpz_init (t);
-  for (a = 2; a <= 4; a++)
-    {
-      mpz_set_ui (x, 1);
-      mpz_mul_2exp (x, x, numb);
-      mpz_root (x, x, a);
-      /* so x is approx sol       */
-      if (mpz_even_p (x))
-	mpz_sub_ui (x, x, 1);
-      mpz_set_ui (y, 1);
-      mpz_mul_2exp (y, y, numb);
-      mpz_sub_ui (y, y, 1);
-      /* decrement x until we are <= real sol     */
-      do
-	{
-	  mpz_sub_ui (x, x, 2);
-	  odd_products (t, x, a);
-	  if (mpz_cmp (t, y) <= 0)
-	    break;
-	}
-      while (1);
-      /* increment x until > real sol     */
-      do
-	{
-	  mpz_add_ui (x, x, 2);
-	  odd_products (t, x, a);
-	  if (mpz_cmp (t, y) > 0)
-	    break;
-	}
-      while (1);
-      /* dec once to get real sol */
-      mpz_sub_ui (x, x, 2);
-      printf ("#define FACMUL%lu CNST_LIMB(0x", a);
-      mpz_out_str (stdout, 16, x);
-      printf (")\n");
-    }
-#endif
-
   return 0;
 }
 
diff -r 44cab8046433 -r 972cf6c9c78e gmp-impl.h
--- a/gmp-impl.h	Mon Feb 11 22:22:14 2013 +0100
+++ b/gmp-impl.h	Tue Feb 12 08:12:35 2013 +0100
@@ -4536,10 +4536,6 @@
   } while (0)
 
 
-#define MPZ_PROVOKE_REALLOC(z)						\
-  do { ALLOC(z) = ABSIZ(z); } while (0)
-
-
 /* Enhancement: The "mod" and "gcd_1" functions below could have
    __GMP_ATTRIBUTE_PURE, but currently (gcc 3.3) that's not supported on
    function pointers, only actual functions.  It probably doesn't make much
diff -r 44cab8046433 -r 972cf6c9c78e mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Mon Feb 11 22:22:14 2013 +0100
+++ b/mini-gmp/mini-gmp.c	Tue Feb 12 08:12:35 2013 +0100
@@ -3148,13 +3148,9 @@
 void
 mpz_fac_ui (mpz_t x, unsigned long n)
 {
-  if (n < 2) {
-    mpz_set_ui (x, 1);
-    return;
-  }
-  mpz_set_ui (x, n);
-  for (;--n > 1;)
-    mpz_mul_ui (x, x, n);
+  mpz_set_ui (x, n + (n == 0));
+  for (;n > 2;)
+    mpz_mul_ui (x, x, --n);
 }
 
 void
@@ -3162,15 +3158,17 @@
 {
   mpz_t t;
 
-  if (k > n) {
-    r->_mp_size = 0;
-    return;
-  }
-  mpz_fac_ui (r, n);
+  mpz_set_ui (r, k <= n);
+
+  if (k > (n >> 1))
+    k = (k <= n) ? n - k : 0;
+
   mpz_init (t);
   mpz_fac_ui (t, k);
-  mpz_divexact (r, r, t);
-  mpz_fac_ui (t, n - k);
+
+  for (; k > 0; k--)
+      mpz_mul_ui (r, r, n--);
+
   mpz_divexact (r, r, t);
   mpz_clear (t);
 }


More information about the gmp-commit mailing list