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

mercurial at gmplib.org mercurial at gmplib.org
Wed May 9 16:20:14 CEST 2012


details:   /var/hg/gmp/rev/310c4134f592
changeset: 14958:310c4134f592
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed May 09 15:44:05 2012 +0200
description:
Whitespace cleanup.

details:   /var/hg/gmp/rev/0a2a35bcc665
changeset: 14959:0a2a35bcc665
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed May 09 16:18:18 2012 +0200
description:
mpz/bin_uiui.c: reinserted one of the shifts.

diffstat:

 ChangeLog           |  2 +-
 mini-gmp/mini-gmp.c |  6 +++---
 mpz/bin_uiui.c      |  8 +++-----
 3 files changed, 7 insertions(+), 9 deletions(-)

diffs (66 lines):

diff -r 8d68a25e59bc -r 0a2a35bcc665 ChangeLog
--- a/ChangeLog	Wed May 09 08:31:40 2012 +0200
+++ b/ChangeLog	Wed May 09 16:18:18 2012 +0200
@@ -4,7 +4,7 @@
 
 	* mpn/generic/sqrtrem.c (invsqrttab): Reduce size removing common byte.
 
-	* mpz/bin_uiui.c (mul2, mul3, mul4, mul8): Remove unneeded shifts.
+	* mpz/bin_uiui.c (mul3, mul4, mul8): Remove unneeded shifts.
 	(MAXFACS): Redefine, using the shared (safer) log_n_max.
 
 2012-05-08  Torbjorn Granlund  <tege at gmplib.org>
diff -r 8d68a25e59bc -r 0a2a35bcc665 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Wed May 09 08:31:40 2012 +0200
+++ b/mini-gmp/mini-gmp.c	Wed May 09 16:18:18 2012 +0200
@@ -3108,14 +3108,14 @@
       mpz_swap (u, t);			/* u = x */
       mpz_tdiv_q (t, y, u);		/* t = y/x */
       mpz_add (t, t, u);		/* t = y/x + x */
-      mpz_tdiv_q_2exp (t, t, 1);	/* x' = (y/x + x)/2 */
+      mpz_tdiv_q_2exp (t, t, 1);	/* x'= (y/x + x)/2 */
     } while (mpz_cmpabs (t, u) < 0);	/* |x'| < |x| */
   else /* z != 2 */ {
     mpz_t v;
 
     mpz_init (v);
     if (sgn)
-      mpz_neg (t,t);
+      mpz_neg (t, t);
 
     do {
       mpz_swap (u, t);			/* u = x */
@@ -3123,7 +3123,7 @@
       mpz_tdiv_q (t, y, t);		/* t = y/x^(z-1) */
       mpz_mul_ui (v, u, z - 1);		/* v = x*(z-1) */
       mpz_add (t, t, v);		/* t = y/x^(z-1) + x*(z-1) */
-      mpz_tdiv_q_ui (t, t, z);		/* x' = (y/x^(z-1) + x*(z-1))/z */
+      mpz_tdiv_q_ui (t, t, z);		/* x'=(y/x^(z-1) + x*(z-1))/z */
     } while (mpz_cmpabs (t, u) < 0);	/* |x'| < |x| */
 
     mpz_clear (v);
diff -r 8d68a25e59bc -r 0a2a35bcc665 mpz/bin_uiui.c
--- a/mpz/bin_uiui.c	Wed May 09 08:31:40 2012 +0200
+++ b/mpz/bin_uiui.c	Wed May 09 16:18:18 2012 +0200
@@ -83,10 +83,8 @@
 static mp_limb_t
 mul2 (mp_limb_t m)
 {
-  /* THINK: (m + 0) * (m + 1) >> 1 does overflow if (m + 0) * (m + 1)
-     does.  The shift does not give any advantage. We should shift
-     _before_ multiplying: (m | 1) * ((m + 1) >> 1) ... */
-  mp_limb_t m01 = (m + 0) * (m + 1);
+  /* We need to shift before multiplying, to avoid an overflow. */
+  mp_limb_t m01 = (m | 1) * ((m + 1) >> 1);
   return m01;
 }
 
@@ -152,7 +150,7 @@
 #define M (numberof(mulfunc)-1)
 
 /* Number of factors-of-2 removed by the corresponding mulN functon.  */
-static const unsigned char tcnttab[] = {0,0,0,1,2,2,4,4,6};
+static const unsigned char tcnttab[] = {0,0,1,1,2,2,4,4,6};
 
 #if 1
 /* This variant is inaccurate but share the code with other functions.  */


More information about the gmp-commit mailing list