[Gmp-commit] /var/hg/gmp: Simpify some mpz functions.

mercurial at gmplib.org mercurial at gmplib.org
Tue May 22 20:32:39 CEST 2012


details:   /var/hg/gmp/rev/95565da39490
changeset: 14996:95565da39490
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Tue May 22 20:32:36 2012 +0200
description:
Simpify some mpz functions.

diffstat:

 ChangeLog     |   5 +++++
 mpz/sqrt.c    |  22 +++++++---------------
 mpz/sqrtrem.c |  21 ++++++---------------
 3 files changed, 18 insertions(+), 30 deletions(-)

diffs (121 lines):

diff -r 8b7baba38e9b -r 95565da39490 ChangeLog
--- a/ChangeLog	Tue May 22 07:51:15 2012 +0200
+++ b/ChangeLog	Tue May 22 20:32:36 2012 +0200
@@ -1,3 +1,8 @@
+2012-05-22  Torbjorn Granlund  <tege at gmplib.org>
+
+	* mpz/sqrt.c: Simplify.
+	* mpz/sqrtrem.c: Likewise.
+
 2012-05-21 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
 	* mpn/generic/toom8_sqr.c: Reduce branches for recursion.
diff -r 8b7baba38e9b -r 95565da39490 mpz/sqrt.c
--- a/mpz/sqrt.c	Tue May 22 07:51:15 2012 +0200
+++ b/mpz/sqrt.c	Tue May 22 20:32:36 2012 +0200
@@ -1,7 +1,7 @@
 /* mpz_sqrt(root, u) --  Set ROOT to floor(sqrt(U)).
 
-Copyright 1991, 1993, 1994, 1996, 2000, 2001, 2005 Free Software Foundation,
-Inc.
+Copyright 1991, 1993, 1994, 1996, 2000, 2001, 2005, 2012 Free Software
+Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -27,8 +27,6 @@
 {
   mp_size_t op_size, root_size;
   mp_ptr root_ptr, op_ptr;
-  mp_ptr free_me = NULL;
-  mp_size_t free_me_size;
   TMP_DECL;
 
   TMP_MARK;
@@ -49,16 +47,13 @@
 
   if (ALLOC (root) < root_size)
     {
-      if (root_ptr == op_ptr)
-	{
-	  free_me = root_ptr;
-	  free_me_size = ALLOC (root);
-	}
-      else
-	(*__gmp_free_func) (root_ptr, ALLOC (root) * BYTES_PER_MP_LIMB);
+      /* From size relations, we can tell ROOT != OP.  */
+      ASSERT (root_ptr != op_ptr);
+
+      __GMP_FREE_FUNC_LIMBS (root_ptr, ALLOC (root));
 
       ALLOC (root) = root_size;
-      root_ptr = (mp_ptr) (*__gmp_allocate_func) (root_size * BYTES_PER_MP_LIMB);
+      root_ptr = __GMP_ALLOCATE_FUNC_LIMBS (root_size);
       PTR (root) = root_ptr;
     }
   else
@@ -77,8 +72,5 @@
   mpn_sqrtrem (root_ptr, NULL, op_ptr, op_size);
 
   SIZ (root) = root_size;
-
-  if (free_me != NULL)
-    (*__gmp_free_func) (free_me, free_me_size * BYTES_PER_MP_LIMB);
   TMP_FREE;
 }
diff -r 8b7baba38e9b -r 95565da39490 mpz/sqrtrem.c
--- a/mpz/sqrtrem.c	Tue May 22 07:51:15 2012 +0200
+++ b/mpz/sqrtrem.c	Tue May 22 20:32:36 2012 +0200
@@ -1,7 +1,7 @@
 /* mpz_sqrtrem(root,rem,x) -- Set ROOT to floor(sqrt(X)) and REM
    to the remainder, i.e. X - ROOT**2.
 
-Copyright 1991, 1993, 1994, 1996, 2000, 2001, 2005, 2011 Free Software
+Copyright 1991, 1993, 1994, 1996, 2000, 2001, 2005, 2011, 2012 Free Software
 Foundation, Inc.
 
 This file is part of the GNU MP Library.
@@ -28,12 +28,9 @@
 {
   mp_size_t op_size, root_size, rem_size;
   mp_ptr root_ptr, op_ptr;
-  mp_ptr free_me;
-  mp_size_t free_me_size;
   TMP_DECL;
 
   TMP_MARK;
-  free_me = NULL;
   op_size = SIZ (op);
   if (op_size <= 0)
     {
@@ -54,16 +51,13 @@
 
   if (ALLOC (root) < root_size)
     {
-      if (root_ptr == op_ptr)
-	{
-	  free_me = root_ptr;
-	  free_me_size = ALLOC (root);
-	}
-      else
-	(*__gmp_free_func) (root_ptr, ALLOC (root) * BYTES_PER_MP_LIMB);
+      /* From size relations, we can tell ROOT != OP.  */
+      ASSERT (root_ptr != op_ptr);
+
+      __GMP_FREE_FUNC_LIMBS (root_ptr, ALLOC (root));
 
       ALLOC (root) = root_size;
-      root_ptr = (mp_ptr) (*__gmp_allocate_func) (root_size * BYTES_PER_MP_LIMB);
+      root_ptr = __GMP_ALLOCATE_FUNC_LIMBS (root_size);
       PTR (root) = root_ptr;
     }
   else
@@ -87,8 +81,5 @@
      give only the square root remainder, if the user calls if with
      ROOT == REM.  */
   SIZ (rem) = rem_size;
-
-  if (free_me != NULL)
-    (*__gmp_free_func) (free_me, free_me_size * BYTES_PER_MP_LIMB);
   TMP_FREE;
 }


More information about the gmp-commit mailing list