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

mercurial at gmplib.org mercurial at gmplib.org
Tue Feb 12 15:42:17 CET 2013


details:   /var/hg/gmp/rev/14281e212de1
changeset: 15395:14281e212de1
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 12 15:36:29 2013 +0100
description:
mpn/generic/mulmod_bnm1.c: Reorganise branches.

details:   /var/hg/gmp/rev/e005c2b2ac72
changeset: 15396:e005c2b2ac72
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 12 15:36:49 2013 +0100
description:
mini-gmp/mini-gmp.c: Reduce branches.

details:   /var/hg/gmp/rev/5cc37326fe3f
changeset: 15397:5cc37326fe3f
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 12 15:37:42 2013 +0100
description:
ChangeLog

details:   /var/hg/gmp/rev/22060487a3c1
changeset: 15398:22060487a3c1
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 12 15:38:14 2013 +0100
description:
mpz/bin_ui.c: Avoid a copy when n < 0.

details:   /var/hg/gmp/rev/f5cbbf231a70
changeset: 15399:f5cbbf231a70
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 12 15:38:40 2013 +0100
description:
mpz/mfac_uiui.c: Reduce memory usage.

details:   /var/hg/gmp/rev/0604f910900d
changeset: 15400:0604f910900d
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 12 15:38:57 2013 +0100
description:
mpz/primorial_ui.c: Use MPZ_NEWALLOC.

details:   /var/hg/gmp/rev/52c4ebb808a2
changeset: 15401:52c4ebb808a2
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 12 15:39:23 2013 +0100
description:
ChangeLog

details:   /var/hg/gmp/rev/549209f2261d
changeset: 15402:549209f2261d
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 12 15:40:31 2013 +0100
description:
mpz/import.c, mpz/inp_raw.c: Use BITS_TO_LIMBS and MPZ_NEWALLOC.

details:   /var/hg/gmp/rev/1ebe25840b85
changeset: 15403:1ebe25840b85
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 12 15:41:57 2013 +0100
description:
Use BITS_TO_LIMBS and MPZ_NEWALLOC in random functions.

details:   /var/hg/gmp/rev/c09b54202499
changeset: 15404:c09b54202499
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 12 15:42:11 2013 +0100
description:
ChangeLog

diffstat:

 ChangeLog                 |   13 +++++
 mini-gmp/mini-gmp.c       |  104 +++++++++++++--------------------------------
 mpn/generic/mulmod_bnm1.c |   43 +++++++-----------
 mpn/generic/random2.c     |    2 +-
 mpz/bin_ui.c              |    7 +-
 mpz/import.c              |    4 +-
 mpz/inp_raw.c             |    4 +-
 mpz/mfac_uiui.c           |   25 ++++++----
 mpz/primorial_ui.c        |    4 +-
 mpz/rrandomb.c            |    6 +-
 mpz/urandomb.c            |    2 +-
 11 files changed, 91 insertions(+), 123 deletions(-)

diffs (truncated from 568 to 300 lines):

diff -r 8ff47fa25e7e -r c09b54202499 ChangeLog
--- a/ChangeLog	Tue Feb 12 09:17:51 2013 +0100
+++ b/ChangeLog	Tue Feb 12 15:42:11 2013 +0100
@@ -4,6 +4,19 @@
 	* 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.
 
+	* mpn/generic/mulmod_bnm1.c: Reorganise branches.
+	* mini-gmp/mini-gmp.c: Reduce branches.
+
+	* mpz/bin_ui.c: Avoid a copy when n < 0.
+	* mpz/mfac_uiui.c: Reduce memory usage.
+	* mpz/primorial_ui.c: Use MPZ_NEWALLOC.
+
+	* mpz/import.c: Use BITS_TO_LIMBS and MPZ_NEWALLOC.
+	* mpz/inp_raw.c: Likewise.
+	* mpz/rrandomb.c: Likewise.
+	* mpz/urandomb.c: Likewise.
+	* mpn/generic/random2.c: Likewise.
+
 2013-02-10  Torbjorn Granlund  <tege at gmplib.org>
 
 	* Version 5.1.1 released.
diff -r 8ff47fa25e7e -r c09b54202499 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Tue Feb 12 09:17:51 2013 +0100
+++ b/mini-gmp/mini-gmp.c	Tue Feb 12 15:42:11 2013 +0100
@@ -222,7 +222,7 @@
   } while (0)
 #define MPZ_SRCPTR_SWAP(x, y)						\
   do {									\
-    mpz_srcptr __mpz_srcptr_swap__tmp = (x);			\
+    mpz_srcptr __mpz_srcptr_swap__tmp = (x);				\
     (x) = (y);								\
     (y) = __mpz_srcptr_swap__tmp;					\
   } while (0)
@@ -344,10 +344,8 @@
 {
   for (; n > 0; n--)
     {
-      if (ap[n-1] < bp[n-1])
-	return -1;
-      else if (ap[n-1] > bp[n-1])
-	return 1;
+      if (ap[n-1] != bp[n-1])
+	return ap[n-1] > bp[n-1] ? 1 : -1;
     }
   return 0;
 }
@@ -355,10 +353,8 @@
 static int
 mpn_cmp4 (mp_srcptr ap, mp_size_t an, mp_srcptr bp, mp_size_t bn)
 {
-  if (an > bn)
-    return 1;
-  else if (an < bn)
-    return -1;
+  if (an != bn)
+    return an < bn ? -1 : 1;
   else
     return mpn_cmp (ap, bp, an);
 }
@@ -715,8 +711,7 @@
       if (r < th)
 	{
 	  m--;
-	  if (r > u1 || (r == u1 && tl > u0))
-	    m--;
+	  m -= ((r > u1) | ((r == u1) & (tl > u0)));
 	}
     }
 
@@ -1422,7 +1417,7 @@
 {
   mp_size_t us = u->_mp_size;
 
-  return us == 0 || us == 1;
+  return (us == (us > 0));
 }
 
 long int
@@ -1473,19 +1468,15 @@
 
   /* x != x is true when x is a NaN, and x == x * 0.5 is true when x is
      zero or infinity. */
-  if (x == 0.0 || x != x || x == x * 0.5)
+  if (x != x || x == x * 0.5)
     {
       r->_mp_size = 0;
       return;
     }
 
-  if (x < 0.0)
-    {
-      x = - x;
-      sign = 1;
-    }
-  else
-    sign = 0;
+  sign = x < 0.0 ;
+  if (sign)
+    x = - x;
 
   if (x < 1.0)
     {
@@ -1611,12 +1602,7 @@
 {
   mp_size_t usize = u->_mp_size;
 
-  if (usize > 0)
-    return 1;
-  else if (usize < 0)
-    return -1;
-  else
-    return 0;
+  return (usize > 0) - (usize < 0);
 }
 
 int
@@ -1635,10 +1621,9 @@
       mp_limb_t ul = u->_mp_d[0];
       if ((mp_limb_t)GMP_NEG_CAST (unsigned long int, v) < ul)
 	return -1;
-      else if ( (mp_limb_t)GMP_NEG_CAST (unsigned long int, v) > ul)
-	return 1;
+      else 
+	return (mp_limb_t)GMP_NEG_CAST (unsigned long int, v) > ul;
     }
-  return 0;
 }
 
 int
@@ -1653,12 +1638,8 @@
   else
     {
       mp_limb_t ul = (usize > 0) ? u->_mp_d[0] : 0;
-      if (ul > v)
-	return 1;
-      else if (ul < v)
-	return -1;
+      return (ul > v) - (ul < v);
     }
-  return 0;
 }
 
 int
@@ -1667,16 +1648,12 @@
   mp_size_t asize = a->_mp_size;
   mp_size_t bsize = b->_mp_size;
 
-  if (asize > bsize)
-    return 1;
-  else if (asize < bsize)
-    return -1;
-  else if (asize > 0)
+  if (asize != bsize)
+    return (asize < bsize) ? -1 : 1;
+  else if (asize >= 0)
     return mpn_cmp (a->_mp_d, b->_mp_d, asize);
-  else if (asize < 0)
-    return -mpn_cmp (a->_mp_d, b->_mp_d, -asize);
   else
-    return 0;
+    return mpn_cmp (b->_mp_d, a->_mp_d, -asize);
 }
 
 int
@@ -1690,12 +1667,7 @@
 
   ul = (un == 1) ? u->_mp_d[0] : 0;
 
-  if (ul > v)
-    return 1;
-  else if (ul < v)
-    return -1;
-  else
-    return 0;
+  return (ul > v) - (ul < v);
 }
 
 int
@@ -1753,7 +1725,7 @@
 
   cy = mpn_add_1 (rp, a->_mp_d, an, b);
   rp[an] = cy;
-  an += (cy > 0);
+  an += cy;
 
   return an;
 }
@@ -1828,7 +1800,7 @@
 
   rp[rn] = cy;
 
-  return rn + (cy > 0);
+  return rn + cy;
 }
 
 static mp_size_t
@@ -2171,10 +2143,7 @@
 void
 mpz_mod (mpz_t r, const mpz_t n, const mpz_t d)
 {
-  if (d->_mp_size >= 0)
-    mpz_div_qr (NULL, r, n, d, GMP_DIV_FLOOR);
-  else
-    mpz_div_qr (NULL, r, n, d, GMP_DIV_CEIL);
+  mpz_div_qr (NULL, r, n, d, d->_mp_size >= 0 ? GMP_DIV_FLOOR : GMP_DIV_CEIL);
 }
 
 static void
@@ -3064,7 +3033,7 @@
   mpz_t t, u;
 
   sgn = y->_mp_size < 0;
-  if (sgn && (z & 1) == 0)
+  if ((~z & sgn) != 0)
     gmp_die ("mpz_rootrem: Negative argument, with even root.");
   if (z == 0)
     gmp_die ("mpz_rootrem: Zeroth root.");
@@ -3589,16 +3558,13 @@
   if ( (un ^ vn) < 0)
     return ~(mp_bitcnt_t) 0;
 
-  if (un < 0)
+  comp = - (uc = vc = (un < 0));
+  if (uc)
     {
       assert (vn < 0);
       un = -un;
       vn = -vn;
-      uc = vc = 1;
-      comp = - (mp_limb_t) 1;
     }
-  else
-    uc = vc = comp = 0;
 
   up = u->_mp_d;
   vp = v->_mp_d;
@@ -3859,13 +3825,8 @@
   while (isspace( (unsigned char) *sp))
     sp++;
 
-  if (*sp == '-')
-    {
-      sign = 1;
-      sp++;
-    }
-  else
-    sign = 0;
+  sign = (*sp == '-');
+  sp += sign;
 
   if (base == 0)
     {
@@ -3965,14 +3926,9 @@
 static int
 gmp_detect_endian (void)
 {
-  static const int i = 1;
+  static const int i = 2;
   const unsigned char *p = (const unsigned char *) &i;
-  if (*p == 1)
-    /* Little endian */
-    return -1;
-  else
-    /* Big endian */
-    return 1;
+  return 1 - *p;
 }
 
 /* Import and export. Does not support nails. */
diff -r 8ff47fa25e7e -r c09b54202499 mpn/generic/mulmod_bnm1.c
--- a/mpn/generic/mulmod_bnm1.c	Tue Feb 12 09:17:51 2013 +0100
+++ b/mpn/generic/mulmod_bnm1.c	Tue Feb 12 15:42:11 2013 +0100
@@ -7,7 +7,7 @@
    SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES.  IN FACT, IT IS ALMOST
    GUARANTEED THAT THEY WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
 
-Copyright 2009, 2010, 2012 Free Software Foundation, Inc.
+Copyright 2009, 2010, 2012, 2013 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -151,25 +151,22 @@
 	mp_size_t anm, bnm;
 	mp_ptr so;
 
+	bm1 = b0;
+	bnm = bn;
 	if (LIKELY (an > n))
 	  {
 	    am1 = xp;
 	    cy = mpn_add (xp, a0, n, a1, an - n);
 	    MPN_INCR_U (xp, n, cy);
 	    anm = n;
+	    so = xp + n;
 	    if (LIKELY (bn > n))
 	      {
-		bm1 = xp + n;
-		cy = mpn_add (xp + n, b0, n, b1, bn - n);


More information about the gmp-commit mailing list