[Gmp-commit] /var/hg/gmp: mpq/get_d.c: compare (zeros > 0) just once, not 3 t...

mercurial at gmplib.org mercurial at gmplib.org
Mon Feb 19 15:21:42 UTC 2018


details:   /var/hg/gmp/rev/7d8cf5cb5203
changeset: 17565:7d8cf5cb5203
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Feb 19 16:21:34 2018 +0100
description:
mpq/get_d.c: compare (zeros > 0) just once, not 3 times...

diffstat:

 ChangeLog   |   1 +
 mpq/get_d.c |  36 ++++++++++++++----------------------
 2 files changed, 15 insertions(+), 22 deletions(-)

diffs (74 lines):

diff -r 7ee2050a3572 -r 7d8cf5cb5203 ChangeLog
--- a/ChangeLog	Mon Feb 19 10:04:01 2018 +0100
+++ b/ChangeLog	Mon Feb 19 16:21:34 2018 +0100
@@ -3,6 +3,7 @@
 	* tune/Makefile.am: Disallow parallel make (thanks Vincent Lefevre).
 	* mpq/swap.c: Use *_SWAP_* macros.
 	* mpq/cmp_ui.c: One more little shortcut, comparing fractions to 1.
+	* mpq/get_d.c: compare (zeros > 0) just once.
 
 2018-02-09  Torbjörn Granlund  <tg at gmplib.org>
 
diff -r 7ee2050a3572 -r 7d8cf5cb5203 mpq/get_d.c
--- a/mpq/get_d.c	Mon Feb 19 10:04:01 2018 +0100
+++ b/mpq/get_d.c	Mon Feb 19 16:21:34 2018 +0100
@@ -104,10 +104,10 @@
 {
   double res;
   mp_srcptr np, dp;
-  mp_ptr remp, tp;
+  mp_ptr remp;
   mp_size_t nsize = SIZ(NUM(src));
   mp_size_t dsize = SIZ(DEN(src));
-  mp_size_t qsize, prospective_qsize, zeros, chop, tsize;
+  mp_size_t qsize, prospective_qsize, zeros;
   mp_size_t sign_quotient = nsize;
   long exp;
 #define N_QLIMBS (1 + (sizeof (double) + GMP_LIMB_BYTES-1) / GMP_LIMB_BYTES)
@@ -133,34 +133,26 @@
   zeros = qsize - prospective_qsize;       /* padding n to get qsize */
   exp = (long) -zeros * GMP_NUMB_BITS;     /* relative to low of qp */
 
-  chop = MAX (-zeros, 0);                  /* negative zeros means shorten n */
-  np += chop;
-  nsize -= chop;
-  zeros += chop;                           /* now zeros >= 0 */
-
-  tsize = nsize + zeros;                   /* size for possible copy of n */
-
-  if (WANT_TMP_DEBUG)
-    {
-      /* separate blocks, for malloc debugging */
-      remp = TMP_ALLOC_LIMBS (dsize);
-      tp = (zeros > 0 ? TMP_ALLOC_LIMBS (tsize) : NULL);
-    }
-  else
-    {
-      /* one block with conditionalized size, for efficiency */
-      remp = TMP_ALLOC_LIMBS (dsize + (zeros > 0 ? tsize : 0));
-      tp = remp + dsize;
-    }
-
   /* zero extend n into temporary space, if necessary */
   if (zeros > 0)
     {
+      mp_ptr tp;
+      mp_size_t tsize;
+      tsize = nsize + zeros;                   /* size for copy of n */
+
+      TMP_ALLOC_LIMBS_2 (remp, dsize, tp, tsize);
       MPN_ZERO (tp, zeros);
       MPN_COPY (tp+zeros, np, nsize);
       np = tp;
       nsize = tsize;
     }
+  else /* negative zeros means shorten n */
+    {
+      np -= zeros;
+      nsize += zeros;
+
+      remp = TMP_ALLOC_LIMBS (dsize);
+    }
 
   ASSERT (qsize == nsize - dsize + 1);
   mpn_tdiv_qr (qp, remp, (mp_size_t) 0, np, nsize, dp, dsize);


More information about the gmp-commit mailing list