[Gmp-commit] /var/hg/gmp: mini-gmp/mini-gmp.c (mpz_div_[rq]_2exp): Improve ad...

mercurial at gmplib.org mercurial at gmplib.org
Mon Jun 25 09:54:57 CEST 2012


details:   /var/hg/gmp/rev/e6a681273d54
changeset: 15066:e6a681273d54
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Jun 25 09:54:52 2012 +0200
description:
mini-gmp/mini-gmp.c (mpz_div_[rq]_2exp): Improve adjustment condition.

diffstat:

 ChangeLog           |   3 +++
 mini-gmp/mini-gmp.c |  11 +++++------
 2 files changed, 8 insertions(+), 6 deletions(-)

diffs (50 lines):

diff -r 99b3ed7de276 -r e6a681273d54 ChangeLog
--- a/ChangeLog	Sun Jun 24 20:11:18 2012 +0200
+++ b/ChangeLog	Mon Jun 25 09:54:52 2012 +0200
@@ -18,6 +18,9 @@
 	* mpn/generic/powlo.c: Likewise.
 	* mpn/generic/powm.c: Likewise.
 
+	* mini-gmp/mini-gmp.c (mpz_div_r_2exp, mpz_div_q_2exp): Improve
+	adjustment condition.
+
 2012-06-23  Marc Glisse  <marc.glisse at inria.fr>
 
 	* gmpxx.h (numeric_limits): Make content public.
diff -r 99b3ed7de276 -r e6a681273d54 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Sun Jun 24 20:11:18 2012 +0200
+++ b/mini-gmp/mini-gmp.c	Mon Jun 25 09:54:52 2012 +0200
@@ -2232,12 +2232,11 @@
   qn = GMP_ABS (un) - limb_cnt;
   bit_index %= GMP_LIMB_BITS;
 
-  adjust = 0;
-  if ( (mode == DIV_FLOOR && un < 0) || (mode == DIV_CEIL && un > 0))
+  if (mode == ((un > 0) ? DIV_CEIL : DIV_FLOOR)) /* un != 0 here. */
     /* Note: Below, the final indexing at limb_cnt is valid because at
        that point we have qn > 0. */
-    adjust = (!mpn_zero_p (u->_mp_d, limb_cnt)
-	      || qn <= 0
+    adjust = (qn <= 0
+	      || !mpn_zero_p (u->_mp_d, limb_cnt)
 	      || (u->_mp_d[limb_cnt]
 		  & (((mp_limb_t) 1 << bit_index) - 1)));
   else
@@ -2294,7 +2293,7 @@
     {
       /* Quotient (with truncation) is zero, and remainder is
 	 non-zero */
-      if ( (mode == DIV_FLOOR && us < 0) || (mode == DIV_CEIL && us > 0))
+      if (mode == ((us > 0) ? DIV_CEIL : DIV_FLOOR)) /* us != 0 here. */
 	{
 	  /* Have to negate and sign extend. */
 	  mp_size_t i;
@@ -2329,7 +2328,7 @@
 
       rp[rn-1] = u->_mp_d[rn-1] & mask;
 
-      if ( (mode == DIV_FLOOR && us < 0) || (mode == DIV_CEIL && us > 0))
+      if (mode == ((us > 0) ? DIV_CEIL : DIV_FLOOR)) /* us != 0 here. */
 	{
 	  /* If r != 0, compute 2^{bit_count} - r. */
 	  mp_size_t i;


More information about the gmp-commit mailing list