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

mercurial at gmplib.org mercurial at gmplib.org
Sun Jan 29 22:37:12 UTC 2017


details:   /var/hg/gmp/rev/d5fec182f35a
changeset: 17218:d5fec182f35a
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Jan 29 21:04:33 2017 +0100
description:
gen-bases.c: In generate file, include just gmp-impl.h, it includes gmp.h

details:   /var/hg/gmp/rev/69c5066b74ae
changeset: 17219:69c5066b74ae
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Jan 29 23:33:04 2017 +0100
description:
mpz/{and,ior,xor}.c: Simplify branches.

details:   /var/hg/gmp/rev/c23ab247bc13
changeset: 17220:c23ab247bc13
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Jan 29 23:36:58 2017 +0100
description:
ChangeLog

diffstat:

 ChangeLog   |   8 ++++
 gen-bases.c |   5 +-
 mpz/and.c   |  99 ++++++++++++++++++++++++++----------------------------------
 mpz/ior.c   |  85 +++++++++++++++------------------------------------
 mpz/xor.c   |  85 ++++++++++++++-------------------------------------
 5 files changed, 102 insertions(+), 180 deletions(-)

diffs (truncated from 499 to 300 lines):

diff -r 9d4b73b05564 -r c23ab247bc13 ChangeLog
--- a/ChangeLog	Sun Jan 29 20:23:41 2017 +0100
+++ b/ChangeLog	Sun Jan 29 23:36:58 2017 +0100
@@ -1,3 +1,11 @@
+2017-01-29 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpz/and.c: Simplify branches.
+	* mpz/ior.c: Likewise.
+	* mpz/xor.c: Likewise.
+
+	* gen-bases.c: In generated file, include just gmp-impl.h, not gmp.h
+
 2017-01-24  Torbjörn Granlund  <tg at gmplib.org>
 
 	* mpn/generic/compute_powtab.c: New file, providing mpn_compute_powtab
diff -r 9d4b73b05564 -r c23ab247bc13 gen-bases.c
--- a/gen-bases.c	Sun Jan 29 20:23:41 2017 +0100
+++ b/gen-bases.c	Sun Jan 29 23:36:58 2017 +0100
@@ -1,7 +1,7 @@
 /* Generate mp_bases data.
 
-Copyright 1991, 1993, 1994, 1996, 2000, 2002, 2004, 2011, 2012, 2015
-Free Software Foundation, Inc.
+Copyright 1991, 1993, 1994, 1996, 2000, 2002, 2004, 2011, 2012,
+2015-2017 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -157,7 +157,6 @@
 
   printf ("/* This file generated by gen-bases.c - DO NOT EDIT. */\n");
   printf ("\n");
-  printf ("#include \"gmp.h\"\n");
   printf ("#include \"gmp-impl.h\"\n");
   printf ("\n");
   printf ("#if GMP_NUMB_BITS != %d\n", numb_bits);
diff -r 9d4b73b05564 -r c23ab247bc13 mpz/and.c
--- a/mpz/and.c	Sun Jan 29 20:23:41 2017 +0100
+++ b/mpz/and.c	Sun Jan 29 23:36:58 2017 +0100
@@ -1,7 +1,7 @@
 /* mpz_and -- Logical and.
 
 Copyright 1991, 1993, 1994, 1996, 1997, 2000, 2001, 2003, 2005, 2012,
-2015, 2016 Free Software Foundation, Inc.
+2015-2017 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -45,39 +45,39 @@
   op1_size = SIZ(op1);
   op2_size = SIZ(op2);
 
+  if (op1_size < op2_size)
+    {
+      MPZ_SRCPTR_SWAP (op1, op2);
+      MP_SIZE_T_SWAP (op1_size, op2_size);
+    }
+
   op1_ptr = PTR(op1);
   op2_ptr = PTR(op2);
 
-  if (op1_size >= 0)
+  if (op2_size >= 0)
     {
-      if (op2_size >= 0)
-	{
-	  res_size = MIN (op1_size, op2_size);
-	  /* First loop finds the size of the result.  */
-	  for (i = res_size - 1; i >= 0; i--)
-	    if ((op1_ptr[i] & op2_ptr[i]) != 0)
-	      break;
-	  res_size = i + 1;
+      res_size = op2_size;
+      /* First loop finds the size of the result.  */
+      for (i = res_size; --i >= 0;)
+	if ((op1_ptr[i] & op2_ptr[i]) != 0)
+	  {
+	    res_size = i + 1;
+	    /* Handle allocation, now then we know exactly how much space is
+	       needed for the result.  */
+	    /* 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;
+	    mpn_and_n (MPZ_NEWALLOC (res, res_size), op1_ptr, op2_ptr, res_size);
+	    return;
+	  }
 
-	  /* Handle allocation, now then we know exactly how much space is
-	     needed for the result.  */
-	  /* 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))
-	    mpn_and_n (MPZ_NEWALLOC (res, res_size), op1_ptr, op2_ptr, res_size);
-	  return;
-	}
-      else /* op2_size < 0 */
-	{
-	  /* Fall through to the code at the end of the function.  */
-	}
+      SIZ (res) = 0;
+      return;
     }
   else
     {
-      if (op2_size < 0)
+      if (op1_size < 0)
 	{
 	  mp_ptr opx, opy;
 	  mp_limb_t cy;
@@ -95,9 +95,6 @@
 	  op1_size = -op1_size;
 	  op2_size = -op2_size;
 
-	  if (op1_size > op2_size)
-	    MPN_SRCPTR_SWAP (op1_ptr, op1_size, op2_ptr, op2_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;
@@ -117,19 +114,12 @@
 
 	  cy = mpn_add_1 (res_ptr, res_ptr, res_size, (mp_limb_t) 1);
 	  res_ptr[res_size] = cy;
-	  res_size += (cy != 0);
+	  res_size += cy;
 
 	  SIZ(res) = -res_size;
 	  TMP_FREE;
 	  return;
 	}
-      else
-	{
-	  /* We should compute -OP1 & OP2.  Swap OP1 and OP2 and fall
-	     through to the code that handles OP1 & -OP2.  */
-	  MPN_SRCPTR_SWAP (op1_ptr, op1_size, op2_ptr, op2_size);
-	}
-
     }
 
   {
@@ -180,8 +170,6 @@
 	  res_ptr[i] = op1_ptr[i] & ~op2_ptr[i];
 	res_ptr[op2_lim] = op1_ptr[op2_lim] & -op2_ptr[op2_lim];
       }
-
-    SIZ(res) = res_size;
 #else
 
     /* OP1 is positive and zero-extended,
@@ -209,33 +197,32 @@
 	   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);
 	mpn_andn_n (res_ptr, op1_ptr, op2_ptr, op2_size);
-
-	SIZ(res) = res_size;
+	MPN_COPY (res_ptr + op2_size, op1_ptr + op2_size, res_size - op2_size);
       }
     else
       {
 	/* Find out the exact result size.  Ignore the high limbs of OP2,
 	   OP1 is zero-extended and would make the result zero.  */
-	for (i = op1_size - 1; i >= 0; i--)
+	res_size = 0;
+	for (i = op1_size; --i >= 0;)
 	  if ((op1_ptr[i] & ~op2_ptr[i]) != 0)
-	    break;
-	res_size = i + 1;
+	    {
+	      res_size = i + 1;
+	      /* Handle allocation, now then we know exactly how much
+		 space is needed for the result.  */
+	      /* 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.  */
+	      mpn_andn_n (MPZ_NEWALLOC (res, res_size), op1_ptr, op2_ptr, res_size);
 
-	/* Handle allocation, now then we know exactly how much space is
-	   needed for the result.  */
-	/* 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.  */
-
-	if (LIKELY (res_size != 0))
-	  mpn_andn_n (MPZ_NEWALLOC (res, res_size), op1_ptr, op2_ptr, res_size);
-
-	SIZ(res) = res_size;
+	      break;
+	    }
       }
 #endif
+    SIZ(res) = res_size;
   }
   TMP_FREE;
 }
diff -r 9d4b73b05564 -r c23ab247bc13 mpz/ior.c
--- a/mpz/ior.c	Sun Jan 29 20:23:41 2017 +0100
+++ b/mpz/ior.c	Sun Jan 29 23:36:58 2017 +0100
@@ -1,7 +1,7 @@
 /* mpz_ior -- Logical inclusive or.
 
 Copyright 1991, 1993, 1994, 1996, 1997, 2000, 2001, 2005, 2012, 2013,
-2015 Free Software Foundation, Inc.
+2015-2017 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -45,58 +45,33 @@
   op1_size = SIZ(op1);
   op2_size = SIZ(op2);
 
+  if (op1_size < op2_size)
+    {
+      MPZ_SRCPTR_SWAP (op1, op2);
+      MP_SIZE_T_SWAP (op1_size, op2_size);
+    }
+
   op1_ptr = PTR(op1);
-  op2_ptr = PTR(op2);
   res_ptr = PTR(res);
 
-  if (op1_size >= 0)
+  if (op2_size >= 0)
     {
-      if (op2_size >= 0)
+      if (res_ptr != op1_ptr)
 	{
-	  if (op1_size >= op2_size)
-	    {
-	      if (UNLIKELY (ALLOC(res) < op1_size))
-		{
-		  res_ptr = (mp_ptr) _mpz_realloc (res, op1_size);
-		  /* No overlapping possible: op1_ptr = PTR(op1); */
-		  op2_ptr = PTR(op2);
-		}
+	  res_ptr = MPZ_REALLOC (res, op1_size);
+	  /* No overlapping possible: op1_ptr = PTR(op1); */
+	  MPN_COPY (res_ptr + op2_size, op1_ptr + op2_size,
+		    op1_size - op2_size);
+	}
+      if (LIKELY (op2_size != 0))
+	mpn_ior_n (res_ptr, op1_ptr, PTR(op2), op2_size);
 
-	      if (res_ptr != op1_ptr)
-		MPN_COPY (res_ptr + op2_size, op1_ptr + op2_size,
-			  op1_size - op2_size);
-	      if (LIKELY (op2_size != 0))
-		mpn_ior_n (res_ptr, op1_ptr, op2_ptr, op2_size);
-	      res_size = op1_size;
-	    }
-	  else
-	    {
-	      if (UNLIKELY (ALLOC(res) < op2_size))
-		{
-		  res_ptr = (mp_ptr) _mpz_realloc (res, op2_size);
-		  op1_ptr = PTR(op1);
-		  /* No overlapping possible: op2_ptr = PTR(op2); */
-		}
-
-	      if (res_ptr != op2_ptr)
-		MPN_COPY (res_ptr + op1_size, op2_ptr + op1_size,
-			  op2_size - op1_size);
-	      if (LIKELY (op1_size != 0))
-		mpn_ior_n (res_ptr, op1_ptr, op2_ptr, op1_size);
-	      res_size = op2_size;
-	    }
-
-	  SIZ(res) = res_size;
-	  return;
-	}
-      else /* op2_size < 0 */
-	{
-	  /* Fall through to the code at the end of the function.  */
-	}
+      SIZ(res) = op1_size;
+      return;
     }
   else
     {
-      if (op2_size < 0)
+      if (op1_size < 0)
 	{
 	  mp_ptr opx, opy;
 
@@ -105,10 +80,7 @@
 	     = ~(~(OP1 - 1) | ~(OP2 - 1)) + 1 =
 	     = ((OP1 - 1) & (OP2 - 1)) + 1      */
 
-	  op1_size = -op1_size;
-	  op2_size = -op2_size;
-
-	  res_size = MIN (op1_size, op2_size);


More information about the gmp-commit mailing list