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

mercurial at gmplib.org mercurial at gmplib.org
Mon Feb 20 20:19:59 CET 2012


details:   /var/hg/gmp/rev/b1cd4bd8a3fb
changeset: 14646:b1cd4bd8a3fb
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Feb 20 19:23:43 2012 +0100
description:
toom_interpolate_8pts: compute carry only when non-trivial.

details:   /var/hg/gmp/rev/6181b30078cf
changeset: 14647:6181b30078cf
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Feb 20 19:39:57 2012 +0100
description:
mpz_gcdext: don't swap operands if it's not needed.

details:   /var/hg/gmp/rev/7b274b5885a7
changeset: 14648:7b274b5885a7
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Feb 20 19:48:36 2012 +0100
description:
mpz_gcdext: move computations to branches where they are needed.

details:   /var/hg/gmp/rev/441d6a0f7c98
changeset: 14649:441d6a0f7c98
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Feb 20 19:58:00 2012 +0100
description:
mpz/and.c: Use mpn_ logic everywhere.

details:   /var/hg/gmp/rev/32085248bf0f
changeset: 14650:32085248bf0f
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Feb 20 20:01:30 2012 +0100
description:
mpz/and.c: use MPZ_REALLOC

details:   /var/hg/gmp/rev/d7539f094914
changeset: 14651:d7539f094914
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Feb 20 20:05:59 2012 +0100
description:
mpz/and.c: Reduce branches.

details:   /var/hg/gmp/rev/af1daa06ffed
changeset: 14652:af1daa06ffed
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Feb 20 20:19:49 2012 +0100
description:
mpz/and.c: Use TMP_ALLOC_LIMBS_2.

diffstat:

 ChangeLog                           |    9 +++
 mpn/generic/toom_interpolate_8pts.c |    8 +-
 mpz/and.c                           |  105 ++++++++++++------------------------
 mpz/gcdext.c                        |   56 +++++++++---------
 4 files changed, 76 insertions(+), 102 deletions(-)

diffs (truncated from 336 to 300 lines):

diff -r cfc4a1f99a29 -r af1daa06ffed ChangeLog
--- a/ChangeLog	Mon Feb 20 19:03:33 2012 +0100
+++ b/ChangeLog	Mon Feb 20 20:19:49 2012 +0100
@@ -1,3 +1,11 @@
+2012-02-20 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpn/generic/toom_interpolate_8pts.c: Compute carry iif non-trivial.
+
+	* mpz/gcdext.c: Adapt to relaxed mpn_gcdext's input requirements.
+
+	* mpz/and.c: Use mpn_ logic everywhere. Reduce branches.
+
 2012-02-20  Torbjorn Granlund  <tege at gmplib.org>
 
 	* mpn/x86_64/coreisbr/aorsmul_1.asm: New file.
@@ -21,6 +29,7 @@
 	* mpn/generic/powm_sec.c (MPN_REDC_1_SEC): Likewise.
 	* mpn/generic/powm.c (MPN_REDC_2): New macro, use for mpn_redc_2.
 
+>>>>>>> other
 2012-02-18  Marc Glisse  <marc.glisse at inria.fr>
 
 	* gmpxx.h (std::common_type): New partial specialization in C++11.
diff -r cfc4a1f99a29 -r af1daa06ffed mpn/generic/toom_interpolate_8pts.c
--- a/mpn/generic/toom_interpolate_8pts.c	Mon Feb 20 19:03:33 2012 +0100
+++ b/mpn/generic/toom_interpolate_8pts.c	Mon Feb 20 20:19:49 2012 +0100
@@ -6,7 +6,7 @@
    SAFE TO REACH IT THROUGH DOCUMENTED INTERFACES.  IN FACT, IT IS ALMOST
    GUARANTEED THAT IT WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
 
-Copyright 2009, 2011 Free Software Foundation, Inc.
+Copyright 2009, 2011, 2012 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -193,9 +193,9 @@
 
   cy = mpn_add_1 (pp + 6*n, r3 + n, n, pp[6*n]);
   MPN_INCR_U (r3 + 2*n, n + 1, cy);
-  cy = r3[3*n] + mpn_add_n (pp + 7*n, pp + 7*n, r3 + 2*n, n);
+  cy = mpn_add_n (pp + 7*n, pp + 7*n, r3 + 2*n, n);
   if (LIKELY(spt != n))
-    MPN_INCR_U (pp + 8*n, spt - n, cy);
+    MPN_INCR_U (pp + 8*n, spt - n, cy + r3[3*n]);
   else
-    ASSERT (cy == 0);
+    ASSERT (r3[3*n] | cy == 0);
 }
diff -r cfc4a1f99a29 -r af1daa06ffed mpz/and.c
--- a/mpz/and.c	Mon Feb 20 19:03:33 2012 +0100
+++ b/mpz/and.c	Mon Feb 20 20:19:49 2012 +0100
@@ -1,7 +1,7 @@
 /* mpz_and -- Logical and.
 
-Copyright 1991, 1993, 1994, 1996, 1997, 2000, 2001, 2003, 2005 Free Software
-Foundation, Inc.
+Copyright 1991, 1993, 1994, 1996, 1997, 2000, 2001, 2003, 2005, 2012
+Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -37,7 +37,6 @@
 
   op1_ptr = PTR(op1);
   op2_ptr = PTR(op2);
-  res_ptr = PTR(res);
 
   if (op1_size >= 0)
     {
@@ -52,14 +51,10 @@
 
 	  /* Handle allocation, now then we know exactly how much space is
 	     needed for the result.  */
-	  if (UNLIKELY (ALLOC(res) < res_size))
-	    {
-	      _mpz_realloc (res, res_size);
-	      res_ptr = PTR(res);
-	      /* Don't re-read op1_ptr and op2_ptr.  Since res_size <=
-		 MIN(op1_size, op2_size), we will not reach this code when op1
-		 is identical to res or op2 is identical to res.  */
-	    }
+	  res_ptr = MPZ_REALLOC (res, res_size);
+	  /* Don't re-read op1_ptr and op2_ptr.  Since res_size <=
+	     MIN(op1_size, op2_size), res is not changed when op1
+	     is identical to res or op2 is identical to res.  */
 
 	  SIZ(res) = res_size;
 	  if (LIKELY (res_size != 0))
@@ -75,9 +70,8 @@
     {
       if (op2_size < 0)
 	{
-	  mp_ptr opx;
+	  mp_ptr opx, opy;
 	  mp_limb_t cy;
-	  mp_size_t res_alloc;
 
 	  /* Both operands are negative, so will be the result.
 	     -((-OP1) & (-OP2)) = -(~(OP1 - 1) & ~(OP2 - 1)) =
@@ -92,48 +86,29 @@
 	  op1_size = -op1_size;
 	  op2_size = -op2_size;
 
-	  res_alloc = 1 + MAX (op1_size, op2_size);
+	  if (op1_size > op2_size)
+	    MPN_SRCPTR_SWAP (op1_ptr, op1_size, op2_ptr, op2_size);
 
-	  opx = TMP_ALLOC_LIMBS (op1_size);
+	  TMP_ALLOC_LIMBS_2 (opx, op1_size, opy, op2_size);
 	  mpn_sub_1 (opx, op1_ptr, op1_size, (mp_limb_t) 1);
 	  op1_ptr = opx;
 
-	  opx = TMP_ALLOC_LIMBS (op2_size);
-	  mpn_sub_1 (opx, op2_ptr, op2_size, (mp_limb_t) 1);
-	  op2_ptr = opx;
+	  mpn_sub_1 (opy, op2_ptr, op2_size, (mp_limb_t) 1);
+	  op2_ptr = opy;
 
-	  if (ALLOC(res) < res_alloc)
-	    {
-	      _mpz_realloc (res, res_alloc);
-	      res_ptr = PTR(res);
-	      /* Don't re-read OP1_PTR and OP2_PTR.  They point to temporary
-		 space--never to the space PTR(res) used to point to before
-		 reallocation.  */
-	    }
+	  res_ptr = MPZ_REALLOC (res, 1 + op2_size);
+	  /* Don't re-read OP1_PTR and OP2_PTR.  They point to temporary
+	     space--never to the space PTR(res) used to point to before
+	     reallocation.  */
 
-	  if (op1_size >= op2_size)
-	    {
-	      MPN_COPY (res_ptr + op2_size, op1_ptr + op2_size,
-			op1_size - op2_size);
-	      for (i = op2_size - 1; i >= 0; i--)
-		res_ptr[i] = op1_ptr[i] | op2_ptr[i];
-	      res_size = op1_size;
-	    }
-	  else
-	    {
-	      MPN_COPY (res_ptr + op1_size, op2_ptr + op1_size,
-			op2_size - op1_size);
-	      for (i = op1_size - 1; i >= 0; i--)
-		res_ptr[i] = op1_ptr[i] | op2_ptr[i];
-	      res_size = op2_size;
-	    }
+	  MPN_COPY (res_ptr + op1_size, op2_ptr + op1_size,
+		    op2_size - op1_size);
+	  mpn_ior_n (res_ptr, op1_ptr, op2_ptr, op1_size);
+	  res_size = op2_size;
 
 	  cy = mpn_add_1 (res_ptr, res_ptr, res_size, (mp_limb_t) 1);
-	  if (cy)
-	    {
-	      res_ptr[res_size] = cy;
-	      res_size++;
-	    }
+	  res_ptr[res_size] = cy;
+	  res_size += (cy != 0);
 
 	  SIZ(res) = -res_size;
 	  TMP_FREE;
@@ -143,8 +118,7 @@
 	{
 	  /* We should compute -OP1 & OP2.  Swap OP1 and OP2 and fall
 	     through to the code that handles OP1 & -OP2.  */
-	  MPZ_SRCPTR_SWAP (op1, op2);
-	  MPN_SRCPTR_SWAP (op1_ptr,op1_size, op2_ptr,op2_size);
+	  MPN_SRCPTR_SWAP (op1_ptr, op1_size, op2_ptr, op2_size);
 	}
 
     }
@@ -221,18 +195,13 @@
 
 	/* Handle allocation, now then we know exactly how much space is
 	   needed for the result.  */
-	if (ALLOC(res) < res_size)
-	  {
-	    _mpz_realloc (res, res_size);
-	    res_ptr = PTR(res);
-	    /* Don't re-read OP1_PTR or OP2_PTR.  Since res_size = op1_size,
-	       we will not reach this code when op1 is identical to res.
-	       OP2_PTR points to temporary space.  */
-	  }
+	res_ptr = MPZ_REALLOC (res, res_size);
+	/* Don't re-read OP1_PTR or OP2_PTR.  Since res_size = op1_size,
+	   op1 is not changed if it is identical to res.
+	   OP2_PTR points to temporary space.  */
 
 	MPN_COPY (res_ptr + op2_size, op1_ptr + op2_size, res_size - op2_size);
-	for (i = op2_size - 1; i >= 0; i--)
-	  res_ptr[i] = op1_ptr[i] & ~op2_ptr[i];
+	mpn_andn_n (res_ptr, op1_ptr, op2_ptr, op2_size);
 
 	SIZ(res) = res_size;
       }
@@ -247,18 +216,14 @@
 
 	/* Handle allocation, now then we know exactly how much space is
 	   needed for the result.  */
-	if (ALLOC(res) < res_size)
-	  {
-	    _mpz_realloc (res, res_size);
-	    res_ptr = PTR(res);
-	    /* Don't re-read OP1_PTR.  Since res_size <= op1_size, we will
-	       not reach this code when op1 is identical to res.  */
-	    /* Don't re-read OP2_PTR.  It points to temporary space--never
-	       to the space PTR(res) used to point to before reallocation.  */
-	  }
+	res_ptr = MPZ_REALLOC (res, res_size);
+	/* Don't re-read OP1_PTR.  Since res_size <= op1_size,
+	   op1 is not changed if it is identical to res.
+	   Don't re-read OP2_PTR.  It points to temporary space--never
+	   to the space PTR(res) used to point to before reallocation.  */
 
-	for (i = res_size - 1; i >= 0; i--)
-	  res_ptr[i] = op1_ptr[i] & ~op2_ptr[i];
+	if (LIKELY (res_size != 0))
+	  mpn_andn_n (res_ptr, op1_ptr, op2_ptr, res_size);
 
 	SIZ(res) = res_size;
       }
diff -r cfc4a1f99a29 -r af1daa06ffed mpz/gcdext.c
--- a/mpz/gcdext.c	Mon Feb 20 19:03:33 2012 +0100
+++ b/mpz/gcdext.c	Mon Feb 20 20:19:49 2012 +0100
@@ -1,8 +1,8 @@
 /* mpz_gcdext(g, s, t, a, b) -- Set G to gcd(a, b), and S and T such that
    g = as + bt.
 
-Copyright 1991, 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2005, 2011 Free Software
-Foundation, Inc.
+Copyright 1991, 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2005, 2011,
+2012 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -27,26 +27,23 @@
 mpz_gcdext (mpz_ptr g, mpz_ptr s, mpz_ptr t, mpz_srcptr a, mpz_srcptr b)
 {
   mp_size_t asize, bsize;
-  mp_srcptr ap, bp;
   mp_ptr tmp_ap, tmp_bp;
   mp_size_t gsize, ssize, tmp_ssize;
-  mp_ptr gp, sp, tmp_gp, tmp_sp;
-  __mpz_struct stmp, gtmp;
+  mp_ptr gp, tmp_gp, tmp_sp;
   TMP_DECL;
 
-  /* mpn_gcdext requires that U >= V.  Therefore, we often have to swap U and
-     V.  This in turn leads to a lot of complications.  The computed cofactor
-     will be the wrong one, so we have to fix that up at the end.  */
+  /* mpn_gcdext requires that Usize >= Vsize.  Therefore, we often
+     have to swap U and V.  The computed cofactor will be the
+     "smallest" one, which is faster to produce.  The wanted one will
+     be computed here; this is needed anyway when both are requested.  */
 
-  asize = ABS (SIZ (a));
-  bsize = ABS (SIZ (b));
-  ap = PTR (a);
-  bp = PTR (b);
+  asize = ABSIZ (a);
+  bsize = ABSIZ (b);
 
-  if (asize < bsize || (asize == bsize && mpn_cmp (ap, bp, asize) < 0))
+  if (asize < bsize)
     {
       MPZ_SRCPTR_SWAP (a, b);
-      MPN_SRCPTR_SWAP (ap, asize, bp, bsize);
+      MP_SIZE_T_SWAP (asize, bsize);
       MPZ_PTR_SWAP (s, t);
     }
 
@@ -56,7 +53,7 @@
       ssize = SIZ (a) >= 0 ? (asize != 0) : -1;
 
       gp = MPZ_REALLOC (g, asize);
-      MPN_COPY (gp, ap, asize);
+      MPN_COPY (gp, PTR (a), asize);
       SIZ (g) = asize;
 
       if (t != NULL)
@@ -71,27 +68,28 @@
 
   TMP_MARK;
 
-  tmp_ap = TMP_ALLOC_LIMBS (asize);
-  tmp_bp = TMP_ALLOC_LIMBS (bsize);
-  MPN_COPY (tmp_ap, ap, asize);
-  MPN_COPY (tmp_bp, bp, bsize);
+  TMP_ALLOC_LIMBS_2 (tmp_ap, asize, tmp_bp, bsize);
+  MPN_COPY (tmp_ap, PTR (a), asize);
+  MPN_COPY (tmp_bp, PTR (b), bsize);
 
-  tmp_gp = TMP_ALLOC_LIMBS (bsize);
-  tmp_sp = TMP_ALLOC_LIMBS (bsize + 1);
+  TMP_ALLOC_LIMBS_2 (tmp_gp, bsize, tmp_sp, bsize + 1);
 
   gsize = mpn_gcdext (tmp_gp, tmp_sp, &tmp_ssize, tmp_ap, asize, tmp_bp, bsize);
 


More information about the gmp-commit mailing list