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

mercurial at gmplib.org mercurial at gmplib.org
Tue Feb 21 15:37:04 CET 2012


details:   /var/hg/gmp/rev/3ad6d110afe6
changeset: 14657:3ad6d110afe6
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 21 08:19:22 2012 +0100
description:
Copyright year, Changelog, and whitespace cleanup.

details:   /var/hg/gmp/rev/a27b8754d95d
changeset: 14658:a27b8754d95d
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 21 14:33:39 2012 +0100
description:
mpz/?or.c: Use mpn_ logic everywhere.

details:   /var/hg/gmp/rev/5fb1134ce9c8
changeset: 14659:5fb1134ce9c8
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 21 14:42:52 2012 +0100
description:
mpz/xor.c: Reduce branches.

details:   /var/hg/gmp/rev/00f6bd44d2aa
changeset: 14660:00f6bd44d2aa
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 21 15:12:43 2012 +0100
description:
mpz/?or.c: Use TMP_ALLOC_LIMBS_2.

details:   /var/hg/gmp/rev/8962b1b5c96b
changeset: 14661:8962b1b5c96b
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 21 15:31:10 2012 +0100
description:
mpz/?or.c: use MPZ_REALLOC.

details:   /var/hg/gmp/rev/872770d4ed80
changeset: 14662:872770d4ed80
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 21 15:35:32 2012 +0100
description:
mpz/xor.c: Reduce branches.

diffstat:

 ChangeLog |  28 +++++++++++++-------------
 gmp-h.in  |   7 +++--
 mpz/ior.c |  37 ++++++++++++++--------------------
 mpz/xor.c |  67 ++++++++++++++++++++++----------------------------------------
 4 files changed, 57 insertions(+), 82 deletions(-)

diffs (280 lines):

diff -r 257d67ba6351 -r 872770d4ed80 ChangeLog
--- a/ChangeLog	Mon Feb 20 21:48:54 2012 +0100
+++ b/ChangeLog	Tue Feb 21 15:35:32 2012 +0100
@@ -1,22 +1,22 @@
+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.
+	* mpz/ior.c: Likewise.
+	* mpz/xor.c: Likewise.
+
 2012-02-20  Torbjorn Granlund  <tege at gmplib.org>
 
+	* mpn/x86_64/coreisbr/mul_1.asm: New file.
+
+	* mpn/x86_64/coreisbr/aorsmul_1.asm: New file.
+
 	* mpn/x86_64/mod_34lsub1.asm: Avoid ",pt" branch hint since many
 	assemblers don't support it.
 
-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/mul_1.asm: New file.
-
-	* mpn/x86_64/coreisbr/aorsmul_1.asm: New file.
-
 2012-02-19  Torbjorn Granlund  <tege at gmplib.org>
 
 	* mpn/generic/redc_1.c: Put back mpn_add_n call, return its carry.
diff -r 257d67ba6351 -r 872770d4ed80 gmp-h.in
--- a/gmp-h.in	Mon Feb 20 21:48:54 2012 +0100
+++ b/gmp-h.in	Tue Feb 21 15:35:32 2012 +0100
@@ -1,7 +1,8 @@
 /* Definitions for GNU multiple precision functions.   -*- mode: c -*-
 
-Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002, 2003,
-2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002,
+2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free
+Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -1496,7 +1497,7 @@
 
 #define mpn_add __MPN(add)
 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_add)
-__GMP_DECLSPEC mp_limb_t mpn_add __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t));
+__GMP_DECLSPEC mp_limb_t mpn_add __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t));
 #endif
 
 #define mpn_add_1 __MPN(add_1)
diff -r 257d67ba6351 -r 872770d4ed80 mpz/ior.c
--- a/mpz/ior.c	Mon Feb 20 21:48:54 2012 +0100
+++ b/mpz/ior.c	Tue Feb 21 15:35:32 2012 +0100
@@ -1,7 +1,7 @@
 /* mpz_ior -- Logical inclusive or.
 
-Copyright 1991, 1993, 1994, 1996, 1997, 2000, 2001, 2005 Free Software
-Foundation, Inc.
+Copyright 1991, 1993, 1994, 1996, 1997, 2000, 2001, 2005, 2012 Free
+Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -56,8 +56,8 @@
 	      if (res_ptr != op1_ptr)
 		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];
+	      if (LIKELY (op2_size != 0))
+		mpn_ior_n (res_ptr, op1_ptr, op2_ptr, op2_size);
 	      res_size = op1_size;
 	    }
 	  else
@@ -73,8 +73,8 @@
 	      if (res_ptr != op2_ptr)
 		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];
+	      if (LIKELY (op1_size != 0))
+		mpn_ior_n (res_ptr, op1_ptr, op2_ptr, op1_size);
 	      res_size = op2_size;
 	    }
 
@@ -90,7 +90,7 @@
     {
       if (op2_size < 0)
 	{
-	  mp_ptr opx;
+	  mp_ptr opx, opy;
 	  mp_limb_t cy;
 
 	  /* Both operands are negative, so will be the result.
@@ -105,20 +105,12 @@
 
 	  /* Possible optimization: Decrease mpn_sub precision,
 	     as we won't use the entire res of both.  */
-	  opx = TMP_ALLOC_LIMBS (res_size);
+	  TMP_ALLOC_LIMBS_2 (opx, res_size, opy, res_size);
 	  mpn_sub_1 (opx, op1_ptr, res_size, (mp_limb_t) 1);
 	  op1_ptr = opx;
 
-	  opx = TMP_ALLOC_LIMBS (res_size);
-	  mpn_sub_1 (opx, op2_ptr, res_size, (mp_limb_t) 1);
-	  op2_ptr = opx;
-
-	  if (ALLOC(res) < res_size)
-	    {
-	      _mpz_realloc (res, res_size);
-	      /* op1_ptr and op2_ptr point to temporary space.  */
-	      res_ptr = PTR(res);
-	    }
+	  mpn_sub_1 (opy, op2_ptr, res_size, (mp_limb_t) 1);
+	  op2_ptr = opy;
 
 	  /* First loop finds the size of the result.  */
 	  for (i = res_size - 1; i >= 0; i--)
@@ -128,9 +120,10 @@
 
 	  if (res_size != 0)
 	    {
+	      res_ptr = MPZ_REALLOC (res, res_size);
+
 	      /* Second loop computes the real result.  */
-	      for (i = res_size - 1; i >= 0; i--)
-		res_ptr[i] = op1_ptr[i] & op2_ptr[i];
+	      mpn_and_n (res_ptr, op1_ptr, op2_ptr, res_size);
 
 	      cy = mpn_add_1 (res_ptr, res_ptr, res_size, (mp_limb_t) 1);
 	      if (cy)
@@ -210,8 +203,8 @@
     if (res_size != 0)
       {
 	/* Second loop computes the real result.  */
-	for (i = count - 1; i >= 0; i--)
-	  res_ptr[i] = ~op1_ptr[i] & op2_ptr[i];
+	if (LIKELY (count != 0))
+	  mpn_andn_n (res_ptr, op2_ptr, op1_ptr, count);
 
 	cy = mpn_add_1 (res_ptr, res_ptr, res_size, (mp_limb_t) 1);
 	if (cy)
diff -r 257d67ba6351 -r 872770d4ed80 mpz/xor.c
--- a/mpz/xor.c	Mon Feb 20 21:48:54 2012 +0100
+++ b/mpz/xor.c	Tue Feb 21 15:35:32 2012 +0100
@@ -1,7 +1,7 @@
 /* mpz_xor -- Logical xor.
 
-Copyright 1991, 1993, 1994, 1996, 1997, 2000, 2001, 2005 Free Software
-Foundation, Inc.
+Copyright 1991, 1993, 1994, 1996, 1997, 2000, 2001, 2005, 2012 Free
+Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -56,8 +56,8 @@
 	      if (res_ptr != op1_ptr)
 		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];
+	      if (LIKELY (op2_size != 0))
+		mpn_xor_n (res_ptr, op1_ptr, op2_ptr, op2_size);
 	      res_size = op1_size;
 	    }
 	  else
@@ -73,8 +73,8 @@
 	      if (res_ptr != op2_ptr)
 		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];
+	      if (LIKELY (op1_size != 0))
+		mpn_xor_n (res_ptr, op1_ptr, op2_ptr, op1_size);
 	      res_size = op2_size;
 	    }
 
@@ -91,7 +91,7 @@
     {
       if (op2_size < 0)
 	{
-	  mp_ptr opx;
+	  mp_ptr opx, opy;
 
 	  /* Both operands are negative, the result will be positive.
 	      (-OP1) ^ (-OP2) =
@@ -103,38 +103,23 @@
 
 	  /* Possible optimization: Decrease mpn_sub precision,
 	     as we won't use the entire res of both.  */
-	  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;
-
-	  res_alloc = MAX (op1_size, op2_size);
-	  if (ALLOC(res) < res_alloc)
-	    {
-	      _mpz_realloc (res, res_alloc);
-	      res_ptr = PTR(res);
-	      /* op1_ptr and op2_ptr point to temporary space.  */
-	    }
+	  mpn_sub_1 (opy, op2_ptr, op2_size, (mp_limb_t) 1);
+	  op2_ptr = opy;
 
 	  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_SRCPTR_SWAP (op1_ptr,op1_size, op2_ptr,op2_size);
+
+	  res_alloc = op2_size;
+	  res_ptr = MPZ_REALLOC (res, res_alloc);
+
+	  MPN_COPY (res_ptr + op1_size, op2_ptr + op1_size,
+		    op2_size - op1_size);
+	  mpn_xor_n (res_ptr, op1_ptr, op2_ptr, op1_size);
+	  res_size = op2_size;
 
 	  MPN_NORMALIZE (res_ptr, res_size);
 	  SIZ(res) = res_size;
@@ -177,24 +162,20 @@
     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];
+	mpn_xor_n (res_ptr, op1_ptr, op2_ptr, op2_size);
 	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];
+	if (LIKELY (op1_size != 0))
+	  mpn_xor_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);
 
     MPN_NORMALIZE (res_ptr, res_size);
     SIZ(res) = -res_size;


More information about the gmp-commit mailing list