[Gmp-commit] /var/hg/gmp: Collapse some macros.

mercurial at gmplib.org mercurial at gmplib.org
Fri Feb 24 09:57:16 CET 2012


details:   /var/hg/gmp/rev/ceb146131bff
changeset: 14667:ceb146131bff
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Feb 24 09:57:10 2012 +0100
description:
Collapse some macros.

diffstat:

 ChangeLog     |   8 ++++++++
 mpz/abs.c     |   3 +--
 mpz/aors_ui.h |   3 +--
 mpz/com.c     |   6 ++----
 mpz/invert.c  |  10 ++++------
 mpz/neg.c     |   3 +--
 6 files changed, 17 insertions(+), 16 deletions(-)

diffs (119 lines):

diff -r 93ce1bb5430a -r ceb146131bff ChangeLog
--- a/ChangeLog	Thu Feb 23 21:17:47 2012 +0100
+++ b/ChangeLog	Fri Feb 24 09:57:10 2012 +0100
@@ -1,3 +1,11 @@
+2012-02-24 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpz/invert.c: Use ABSIZ, MPZ_EQUAL_1_P.
+	* mpz/abs.c: Collapse MPZ_REALLOC(x,.) and PTR(x).
+	* mpz/aors_ui.h: Likewise.
+	* mpz/com.c: Likewise.
+        * mpz/neg.c: Likewise.
+
 2012-02-23  Marc Glisse  <marc.glisse at inria.fr>
 
 	* mpz/abs.c: Use ALLOC, SIZ, ABSIZ, PTR, MPZ_REALLOC.
diff -r 93ce1bb5430a -r ceb146131bff mpz/abs.c
--- a/mpz/abs.c	Thu Feb 23 21:17:47 2012 +0100
+++ b/mpz/abs.c	Fri Feb 24 09:57:10 2012 +0100
@@ -33,9 +33,8 @@
 
   if (u != w)
     {
-      MPZ_REALLOC (w, size);
+      wp = MPZ_REALLOC (w, size);
 
-      wp = PTR (w);
       up = PTR (u);
 
       MPN_COPY (wp, up, size);
diff -r 93ce1bb5430a -r ceb146131bff mpz/aors_ui.h
--- a/mpz/aors_ui.h	Thu Feb 23 21:17:47 2012 +0100
+++ b/mpz/aors_ui.h	Fri Feb 24 09:57:10 2012 +0100
@@ -71,11 +71,10 @@
 
   /* If not space for W (and possible carry), increase space.  */
   wsize = abs_usize + 1;
-  MPZ_REALLOC (w, wsize);
+  wp = MPZ_REALLOC (w, wsize);
 
   /* These must be after realloc (U may be the same as W).  */
   up = PTR (u);
-  wp = PTR (w);
 
   if (abs_usize == 0)
     {
diff -r 93ce1bb5430a -r ceb146131bff mpz/com.c
--- a/mpz/com.c	Thu Feb 23 21:17:47 2012 +0100
+++ b/mpz/com.c	Fri Feb 24 09:57:10 2012 +0100
@@ -34,10 +34,9 @@
 	 But this can be simplified using the identity -x = ~x + 1.
 	 So we're going to compute (~~x) + 1 = x + 1!  */
 
-      MPZ_REALLOC (dst, size + 1);
+      dst_ptr = MPZ_REALLOC (dst, size + 1);
 
       src_ptr = PTR (src);
-      dst_ptr = PTR (dst);
 
       if (UNLIKELY (size == 0))
 	{
@@ -68,10 +67,9 @@
 	 So we're going to compute ~~(x - 1) = x - 1!  */
       size = -size;
 
-      MPZ_REALLOC (dst, size);
+      dst_ptr = MPZ_REALLOC (dst, size);
 
       src_ptr = PTR (src);
-      dst_ptr = PTR (dst);
 
       mpn_sub_1 (dst_ptr, src_ptr, size, (mp_limb_t) 1);
       size -= dst_ptr[size - 1] == 0;
diff -r 93ce1bb5430a -r ceb146131bff mpz/invert.c
--- a/mpz/invert.c	Thu Feb 23 21:17:47 2012 +0100
+++ b/mpz/invert.c	Fri Feb 24 09:57:10 2012 +0100
@@ -30,17 +30,15 @@
   mp_size_t xsize, nsize, size;
   TMP_DECL;
 
-  xsize = SIZ (x);
-  nsize = SIZ (n);
-  xsize = ABS (xsize);
-  nsize = ABS (nsize);
-  size = MAX (xsize, nsize) + 1;
+  xsize = ABSIZ (x);
+  nsize = ABSIZ (n);
 
   /* No inverse exists if the leftside operand is 0.  Likewise, no
      inverse exists if the mod operand is 1.  */
   if (xsize == 0 || (nsize == 1 && (PTR (n))[0] == 1))
     return 0;
 
+  size = MAX (xsize, nsize) + 1;
   TMP_MARK;
 
   MPZ_TMP_INIT (gcd, size);
@@ -48,7 +46,7 @@
   mpz_gcdext (gcd, tmp, (mpz_ptr) 0, x, n);
 
   /* If no inverse existed, return with an indication of that.  */
-  if (SIZ (gcd) != 1 || PTR(gcd)[0] != 1)
+  if (MPZ_EQUAL_1_P (gcd))
     {
       TMP_FREE;
       return 0;
diff -r 93ce1bb5430a -r ceb146131bff mpz/neg.c
--- a/mpz/neg.c	Thu Feb 23 21:17:47 2012 +0100
+++ b/mpz/neg.c	Fri Feb 24 09:57:10 2012 +0100
@@ -34,9 +34,8 @@
     {
       size = ABS (usize);
 
-      MPZ_REALLOC (w, size);
+      wp = MPZ_REALLOC (w, size);
 
-      wp = PTR (w);
       up = PTR (u);
 
       MPN_COPY (wp, up, size);


More information about the gmp-commit mailing list