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

mercurial at gmplib.org mercurial at gmplib.org
Thu Feb 14 13:04:41 CET 2013


details:   /var/hg/gmp/rev/defbd04bc727
changeset: 15420:defbd04bc727
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Feb 14 12:12:32 2013 +0100
description:
tests/mpq/t-cmp_ui.c: Test special comparisons: 0/1, 1/1.

details:   /var/hg/gmp/rev/95284249a2f2
changeset: 15421:95284249a2f2
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Feb 14 12:14:04 2013 +0100
description:
ChangeLog

details:   /var/hg/gmp/rev/0671ccbc9ef6
changeset: 15422:0671ccbc9ef6
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Feb 14 12:16:44 2013 +0100
description:
mpz/setbit.c, mpz/clrbit.c: Reorganise branches.

details:   /var/hg/gmp/rev/04b477a74597
changeset: 15423:04b477a74597
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Feb 14 12:16:51 2013 +0100
description:
ChangeLog

details:   /var/hg/gmp/rev/eb8d0536bb7b
changeset: 15424:eb8d0536bb7b
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Feb 14 12:19:22 2013 +0100
description:
mpz/combit.c: Same micro-optimisations as in set/clr.

details:   /var/hg/gmp/rev/f0486d56b5a4
changeset: 15425:f0486d56b5a4
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Feb 14 12:19:28 2013 +0100
description:
ChangeLog

details:   /var/hg/gmp/rev/2f58b7d01105
changeset: 15426:2f58b7d01105
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Feb 14 12:32:56 2013 +0100
description:
mpz/aors_ui.h: No realloc if size was	zero.

details:   /var/hg/gmp/rev/1bb38d4b72d9
changeset: 15427:1bb38d4b72d9
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Feb 14 12:34:45 2013 +0100
description:
mpz/ior.c: Use macros: MPZ_REALLOC and MPN_INCR_U.

details:   /var/hg/gmp/rev/24dcd94bb286
changeset: 15428:24dcd94bb286
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Feb 14 12:34:52 2013 +0100
description:
ChangeLog

details:   /var/hg/gmp/rev/9a1e2c08517d
changeset: 15429:9a1e2c08517d
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Feb 14 12:37:53 2013 +0100
description:
gmp-impl.h (NEG_CAST): New macro, used by ABS_CAST.

details:   /var/hg/gmp/rev/bc02b22069fa
changeset: 15430:bc02b22069fa
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Feb 14 12:43:55 2013 +0100
description:
ChangeLog

details:   /var/hg/gmp/rev/73c0ec76a662
changeset: 15431:73c0ec76a662
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Feb 14 13:03:57 2013 +0100
description:
mpz/cmp_si.c: Reorganise branches.

details:   /var/hg/gmp/rev/5ee0a73b049c
changeset: 15432:5ee0a73b049c
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Feb 14 13:04:36 2013 +0100
description:
ChangeLog

diffstat:

 ChangeLog            |  12 +++++++
 gmp-impl.h           |   3 +-
 mpq/cmp_si.c         |   8 ++--
 mpz/aors_ui.h        |  21 ++++++-------
 mpz/clrbit.c         |  80 +++++++++++++++++++++++++++------------------------
 mpz/cmp_si.c         |  53 ++++++++++++++-------------------
 mpz/com.c            |   2 +-
 mpz/combit.c         |  21 +++++++-----
 mpz/ior.c            |  17 +++-------
 mpz/setbit.c         |  49 ++++++++++++++----------------
 tests/mpq/t-cmp_ui.c |  12 +++++++
 11 files changed, 147 insertions(+), 131 deletions(-)

diffs (truncated from 490 to 300 lines):

diff -r 665b15ea3738 -r 5ee0a73b049c ChangeLog
--- a/ChangeLog	Thu Feb 14 08:46:30 2013 +0100
+++ b/ChangeLog	Thu Feb 14 13:04:36 2013 +0100
@@ -6,6 +6,18 @@
 	* mpz/set_str.c: Likewise.
 
 	* gmp-h.in (mpq_cmp_ui): Optimize comparison with 1/1.
+	* tests/mpq/t-cmp_ui.c: Test special comparisons: 0/1, 1/1.
+
+	* mpz/clrbit.c: Reorganise branches.
+	* mpz/setbit.c: Likewise.
+	* mpz/combit.c: Same micro-optimisations as in set/clr.
+
+	* mpz/aors_ui.h: No realloc if size was zero.
+	* mpz/ior.c: Use macros: MPZ_REALLOC and MPN_INCR_U.
+
+	* gmp-impl.h (NEG_CAST): New macro, used by ABS_CAST.
+	* mpq/cmp_si.c: Use NEG_CAST.
+	* mpz/cmp_si.c: Reorganise branches.
 
 2013-02-13  Torbjorn Granlund  <tege at gmplib.org>
 
diff -r 665b15ea3738 -r 5ee0a73b049c gmp-impl.h
--- a/gmp-impl.h	Thu Feb 14 08:46:30 2013 +0100
+++ b/gmp-impl.h	Thu Feb 14 13:04:36 2013 +0100
@@ -506,7 +506,8 @@
 #define UNLIKELY(cond)                 __GMP_UNLIKELY(cond)
 
 #define ABS(x) ((x) >= 0 ? (x) : -(x))
-#define ABS_CAST(T,x) ((x) >= 0 ? (T)(x) : -((T)((x) + 1) - 1))
+#define NEG_CAST(T,x) (-((T)((x) + 1) - 1))
+#define ABS_CAST(T,x) ((x) >= 0 ? (T)(x) : NEG_CAST(T,x))
 #undef MIN
 #define MIN(l,o) ((l) < (o) ? (l) : (o))
 #undef MAX
diff -r 665b15ea3738 -r 5ee0a73b049c mpq/cmp_si.c
--- a/mpq/cmp_si.c	Thu Feb 14 08:46:30 2013 +0100
+++ b/mpq/cmp_si.c	Thu Feb 14 13:04:36 2013 +0100
@@ -1,6 +1,6 @@
 /* _mpq_cmp_si -- compare mpq and long/ulong fraction.
 
-Copyright 2001 Free Software Foundation, Inc.
+Copyright 2001, 2013 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -46,11 +46,11 @@
         {
           mpq_t  qabs;
           SIZ(NUM(qabs)) = ABSIZ(NUM(q));
-          PTR(NUM(qabs))    = PTR(NUM(q));
+          PTR(NUM(qabs)) = PTR(NUM(q));
           SIZ(DEN(qabs)) = SIZ(DEN(q));
-          PTR(DEN(qabs))    = PTR(DEN(q));
+          PTR(DEN(qabs)) = PTR(DEN(q));
 
-          return - _mpq_cmp_ui (qabs, -n, d);    /* <0 cmp <0 */
+          return - _mpq_cmp_ui (qabs, NEG_CAST (unsigned long, n), d);    /* <0 cmp <0 */
         }
     }
 }
diff -r 665b15ea3738 -r 5ee0a73b049c mpz/aors_ui.h
--- a/mpz/aors_ui.h	Thu Feb 14 08:46:30 2013 +0100
+++ b/mpz/aors_ui.h	Thu Feb 14 13:04:36 2013 +0100
@@ -1,8 +1,8 @@
 /* mpz_add_ui, mpz_sub_ui -- Add or subtract an mpz_t and an unsigned
    one-word integer.
 
-Copyright 1991, 1993, 1994, 1996, 1999, 2000, 2001, 2002, 2004, 2012 Free
-Software Foundation, Inc.
+Copyright 1991, 1993, 1994, 1996, 1999, 2000, 2001, 2002, 2004, 2012,
+2013 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -67,22 +67,21 @@
 #endif
 
   usize = SIZ (u);
+  if (usize == 0)
+    {
+      PTR (w)[0] = vval;
+      SIZ (w) = VARIATION_NEG (vval != 0);
+      return;
+    }
+
   abs_usize = ABS (usize);
 
   /* If not space for W (and possible carry), increase space.  */
-  wsize = abs_usize + 1;
-  wp = MPZ_REALLOC (w, wsize);
+  wp = MPZ_REALLOC (w, abs_usize + 1);
 
   /* These must be after realloc (U may be the same as W).  */
   up = PTR (u);
 
-  if (abs_usize == 0)
-    {
-      wp[0] = vval;
-      SIZ (w) = VARIATION_NEG (vval != 0);
-      return;
-    }
-
   if (usize VARIATION_CMP 0)
     {
       mp_limb_t cy;
diff -r 665b15ea3738 -r 5ee0a73b049c mpz/clrbit.c
--- a/mpz/clrbit.c	Thu Feb 14 08:46:30 2013 +0100
+++ b/mpz/clrbit.c	Thu Feb 14 13:04:36 2013 +0100
@@ -36,11 +36,10 @@
       if (limb_idx < dsize)
 	{
 	  mp_limb_t  dlimb;
-	  dlimb = dp[limb_idx];
-	  dlimb &= ~mask;
+	  dlimb = dp[limb_idx] & ~mask;
 	  dp[limb_idx] = dlimb;
 
-	  if (UNLIKELY (dlimb == 0 && limb_idx == dsize-1))
+	  if (UNLIKELY ((dlimb == 0) + limb_idx == dsize)) /* dsize == limb_idx + 1 */
 	    {
 	      /* high limb became zero, must normalize */
 	      MPN_NORMALIZE (dp, limb_idx);
@@ -52,8 +51,6 @@
     }
   else
     {
-      mp_size_t zero_bound;
-
       /* Simulate two's complement arithmetic, i.e. simulate
 	 1. Set OP = ~(OP - 1) [with infinitely many leading ones].
 	 2. clear the bit.
@@ -61,42 +58,49 @@
 
       dsize = -dsize;
 
-      /* No index upper bound on this loop, we're sure there's a non-zero limb
-	 sooner or later.  */
-      zero_bound = 0;
-      while (dp[zero_bound] == 0)
-	zero_bound++;
+      if (limb_idx < dsize)
+	{
+	  mp_size_t zero_bound;
 
-      if (limb_idx > zero_bound)
-	{
-	  if (limb_idx < dsize)
-	    dp[limb_idx] |= mask;
+	  /* No index upper bound on this loop, we're sure there's a non-zero limb
+	     sooner or later.  */
+	  zero_bound = 0;
+	  while (dp[zero_bound] == 0)
+	    zero_bound++;
+
+	  if (limb_idx > zero_bound)
+	    {
+	      dp[limb_idx] |= mask;
+	    }
+	  else if (limb_idx == zero_bound)
+	    {
+	      mp_limb_t  dlimb;
+	      dlimb = (((dp[limb_idx] - 1) | mask) + 1) & GMP_NUMB_MASK;
+	      dp[limb_idx] = dlimb;
+
+	      if (dlimb == 0)
+		{
+		  /* Increment at limb_idx + 1.  Extend the number with a zero limb
+		     for simplicity.  */
+		  dp = MPZ_REALLOC (d, dsize + 1);
+		  dp[dsize] = 0;
+		  MPN_INCR_U (dp + limb_idx + 1, dsize - limb_idx, 1);
+		  dsize += dp[dsize];
+
+		  SIZ (d) = -dsize;
+		}
+	    }
 	  else
-	    {
-	      /* Ugh.  The bit should be cleared outside of the end of the
-		 number.  We have to increase the size of the number.  */
-	      dp = MPZ_REALLOC (d, limb_idx + 1);
-	      SIZ (d) = -(limb_idx + 1);
-	      MPN_ZERO (dp + dsize, limb_idx - dsize);
-	      dp[limb_idx] = mask;
-	    }
-	}
-      else if (limb_idx == zero_bound)
-	{
-	  dp[limb_idx] = ((((dp[limb_idx] - 1) | mask) + 1) & GMP_NUMB_MASK);
-	  if (dp[limb_idx] == 0)
-	    {
-	      /* Increment at limb_idx + 1.  Extend the number with a zero limb
-		 for simplicity.  */
-	      dp = MPZ_REALLOC (d, dsize + 1);
-	      dp[dsize] = 0;
-	      MPN_INCR_U (dp + limb_idx + 1, dsize - limb_idx, 1);
-	      dsize += dp[dsize];
-
-	      SIZ (d) = -dsize;
-	    }
+	    ;
 	}
       else
-	;
+	{
+	  /* Ugh.  The bit should be cleared outside of the end of the
+	     number.  We have to increase the size of the number.  */
+	  dp = MPZ_REALLOC (d, limb_idx + 1);
+	  SIZ (d) = -(limb_idx + 1);
+	  MPN_ZERO (dp + dsize, limb_idx - dsize);
+	  dp[limb_idx] = mask;
+	}
     }
 }
diff -r 665b15ea3738 -r 5ee0a73b049c mpz/cmp_si.c
--- a/mpz/cmp_si.c	Thu Feb 14 08:46:30 2013 +0100
+++ b/mpz/cmp_si.c	Thu Feb 14 13:04:36 2013 +0100
@@ -25,11 +25,6 @@
 int
 _mpz_cmp_si (mpz_srcptr u, signed long int v_digit) __GMP_NOTHROW
 {
-  mp_size_t usize = SIZ (u);
-  mp_size_t vsize;
-  mp_limb_t u_digit;
-  unsigned long int absv_digit;
-
 #if GMP_NAIL_BITS != 0
   /* FIXME.  This isn't very pretty.  */
   mpz_t tmp;
@@ -38,30 +33,28 @@
   ALLOC(tmp) = 2;
   mpz_set_si (tmp, v_digit);
   return mpz_cmp (u, tmp);
+#else
+
+  mp_size_t vsize, usize;
+
+  usize = SIZ (u);
+  vsize = (v_digit > 0) - (v_digit < 0);
+
+  if ((usize == 0) | (usize != vsize))
+    return usize - vsize;
+  else {
+    mp_limb_t u_digit, absv_digit;
+
+    u_digit = PTR (u)[0];
+    absv_digit = ABS_CAST (unsigned long, v_digit);
+
+    if (u_digit == absv_digit)
+      return 0;
+
+    if (u_digit > absv_digit)
+      return usize;
+    else
+      return -usize;
+  }
 #endif
-
-  vsize = 0;
-  if (v_digit > 0)
-    vsize = 1;
-  else if (v_digit < 0)
-    {
-      vsize = -1;
-    }
-  absv_digit = ABS_CAST (unsigned long int, v_digit);
-
-  if (usize != vsize)
-    return usize - vsize;
-
-  if (usize == 0)
-    return 0;
-
-  u_digit = PTR (u)[0];
-
-  if (u_digit == (mp_limb_t) absv_digit)
-    return 0;
-
-  if (u_digit > (mp_limb_t) absv_digit)
-    return usize;
-  else
-    return -usize;
 }
diff -r 665b15ea3738 -r 5ee0a73b049c mpz/com.c
--- a/mpz/com.c	Thu Feb 14 08:46:30 2013 +0100
+++ b/mpz/com.c	Thu Feb 14 13:04:36 2013 +0100
@@ -51,7 +51,7 @@
 
 	  cy = mpn_add_1 (dst_ptr, src_ptr, size, (mp_limb_t) 1);
 	  dst_ptr[size] = cy;
-	  size += (cy != 0);
+	  size += cy;
 
 	  /* Store a negative size, to indicate ones-extension.  */
 	  SIZ (dst) = -size;
diff -r 665b15ea3738 -r 5ee0a73b049c mpz/combit.c
--- a/mpz/combit.c	Thu Feb 14 08:46:30 2013 +0100
+++ b/mpz/combit.c	Thu Feb 14 13:04:36 2013 +0100
@@ -50,15 +50,16 @@


More information about the gmp-commit mailing list