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

mercurial at gmplib.org mercurial at gmplib.org
Mon Jul 28 20:06:59 UTC 2014


details:   /var/hg/gmp/rev/413112d567a8
changeset: 16458:413112d567a8
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Jul 28 22:05:44 2014 +0200
description:
mpn/generic/fib2_ui.c: remove #if HAVE_NATIVE_mpn_rsblsh_n.

details:   /var/hg/gmp/rev/2464e9e60eab
changeset: 16459:2464e9e60eab
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Jul 28 22:06:07 2014 +0200
description:
mpz/fib2_ui.c: Use tabulated values, when available.

details:   /var/hg/gmp/rev/12832292fae4
changeset: 16460:12832292fae4
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Jul 28 22:06:30 2014 +0200
description:
mpz/fib_ui.c: #if HAVE_NATIVE_mpn_addlsh1_n, use it.

details:   /var/hg/gmp/rev/bfc155c8a85f
changeset: 16461:bfc155c8a85f
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Jul 28 22:06:42 2014 +0200
description:
ChangeLog

diffstat:

 ChangeLog             |   6 ++++++
 mpn/generic/fib2_ui.c |   4 ----
 mpz/fib2_ui.c         |  17 +++++++++++++----
 mpz/fib_ui.c          |  15 +++++++++++----
 4 files changed, 30 insertions(+), 12 deletions(-)

diffs (120 lines):

diff -r ee3927e6fc88 -r bfc155c8a85f ChangeLog
--- a/ChangeLog	Sun Jul 27 16:44:48 2014 +0200
+++ b/ChangeLog	Mon Jul 28 22:06:42 2014 +0200
@@ -1,3 +1,9 @@
+2014-07-28 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpn/generic/fib2_ui.c: remove #if HAVE_NATIVE_mpn_rsblsh_n.
+	* mpz/fib2_ui.c: Use tabulated values, when available.
+	* mpz/fib_ui.c: #if HAVE_NATIVE_mpn_addlsh1_n, use it.
+
 2014-07-27  Torbjörn Granlund  <tege at gmplib.org>
 
 	* mpn/x86/k7/gcd_1.asm: Use LEAL.
diff -r ee3927e6fc88 -r bfc155c8a85f mpn/generic/fib2_ui.c
--- a/mpn/generic/fib2_ui.c	Sun Jul 27 16:44:48 2014 +0200
+++ b/mpn/generic/fib2_ui.c	Mon Jul 28 22:06:42 2014 +0200
@@ -132,12 +132,8 @@
 
 	  /* Calculate F[2k+1] = 4*F[k]^2 - F[k-1]^2 + 2*(-1)^k.
 	     n&mask is the low bit of our implied k.  */
-#if HAVE_NATIVE_mpn_rsblsh2_n || HAVE_NATIVE_mpn_rsblsh_n
 #if HAVE_NATIVE_mpn_rsblsh2_n
 	  fp[size] = mpn_rsblsh2_n (fp, fp, xp, size);
-#else /* HAVE_NATIVE_mpn_rsblsh_n */
-	  fp[size] = mpn_rsblsh_n (fp, fp, xp, size, 2);
-#endif
 	  if ((n & mask) == 0)
 	    MPN_INCR_U(fp, size + 1, 2);	/* possible +2 */
 	  else
diff -r ee3927e6fc88 -r bfc155c8a85f mpz/fib2_ui.c
--- a/mpz/fib2_ui.c	Sun Jul 27 16:44:48 2014 +0200
+++ b/mpz/fib2_ui.c	Mon Jul 28 22:06:42 2014 +0200
@@ -1,6 +1,6 @@
 /* mpz_fib2_ui -- calculate Fibonacci numbers.
 
-Copyright 2001, 2012 Free Software Foundation, Inc.
+Copyright 2001, 2012, 2014 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -39,12 +39,21 @@
   mp_ptr     fp, f1p;
   mp_size_t  size;
 
+  if (n <= FIB_TABLE_LIMIT)
+    {
+      PTR(fn)[0] = FIB_TABLE (n);
+      SIZ(fn) = (n != 0);      /* F[0]==0, others are !=0 */
+      PTR(fnsub1)[0] = FIB_TABLE ((int) n - 1);
+      SIZ(fnsub1) = (n != 1);  /* F[1-1]==0, others are !=0 */
+      return;
+    }
+
   size = MPN_FIB2_SIZE (n);
-  fp =  MPZ_REALLOC (fn,     size);
-  f1p = MPZ_REALLOC (fnsub1, size);
+  fp =  MPZ_NEWALLOC (fn,     size);
+  f1p = MPZ_NEWALLOC (fnsub1, size);
 
   size = mpn_fib2_ui (fp, f1p, n);
 
-  SIZ(fn)     = size - (n == 0);
+  SIZ(fn)     = size;
   SIZ(fnsub1) = size - (f1p[size-1] == 0);
 }
diff -r ee3927e6fc88 -r bfc155c8a85f mpz/fib_ui.c
--- a/mpz/fib_ui.c	Sun Jul 27 16:44:48 2014 +0200
+++ b/mpz/fib_ui.c	Mon Jul 28 22:06:42 2014 +0200
@@ -1,6 +1,6 @@
 /* mpz_fib_ui -- calculate Fibonacci numbers.
 
-Copyright 2000-2002, 2005, 2012 Free Software Foundation, Inc.
+Copyright 2000-2002, 2005, 2012, 2014 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -60,7 +60,7 @@
   mp_ptr         fp, xp, yp;
   mp_size_t      size, xalloc;
   unsigned long  n2;
-  mp_limb_t      c, c2;
+  mp_limb_t      c;
   TMP_DECL;
 
   if (n <= FIB_TABLE_LIMIT)
@@ -72,7 +72,7 @@
 
   n2 = n/2;
   xalloc = MPN_FIB2_SIZE (n2) + 1;
-  fp = MPZ_REALLOC (fn, 2*xalloc+1);
+  fp = MPZ_NEWALLOC (fn, 2 * xalloc);
 
   TMP_MARK;
   TMP_ALLOC_LIMBS_2 (xp,xalloc, yp,xalloc);
@@ -93,8 +93,11 @@
       yp[size] = 0;
       ASSERT_NOCARRY (mpn_add_n_sub_n (xp, yp, xp, yp, size+1));
       xsize = size + (xp[size] != 0);
-      ysize = size + (yp[size] != 0);
+      ASSERT (yp[size] <= 1);
+      ysize = size + yp[size];
 #else
+      mp_limb_t  c2;
+
       c2 = mpn_lshift (fp, xp, size, 1);
       c = c2 + mpn_add_n (xp, fp, yp, size);
       xp[size] = c;
@@ -131,8 +134,12 @@
       /* F[2k] = F[k]*(F[k]+2F[k-1]) */
 
       mp_size_t  xsize, ysize;
+#if HAVE_NATIVE_mpn_addlsh1_n
+      c = mpn_addlsh1_n (yp, xp, yp, size);
+#else
       c = mpn_lshift (yp, yp, size, 1);
       c += mpn_add_n (yp, yp, xp, size);
+#endif
       yp[size] = c;
       xsize = size;
       ysize = size + (c != 0);


More information about the gmp-commit mailing list