[Gmp-commit] /var/hg/gmp: mpn/generic/rootrem.c: Division by variable only if...

mercurial at gmplib.org mercurial at gmplib.org
Wed Aug 5 20:25:37 UTC 2015


details:   /var/hg/gmp/rev/7d1055c12a1d
changeset: 16751:7d1055c12a1d
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Aug 05 22:25:21 2015 +0200
description:
mpn/generic/rootrem.c: Division by variable only if needed.

diffstat:

 mpn/generic/rootrem.c |  15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)

diffs (43 lines):

diff -r e40e30414801 -r 7d1055c12a1d mpn/generic/rootrem.c
--- a/mpn/generic/rootrem.c	Tue Jul 28 20:24:53 2015 +0200
+++ b/mpn/generic/rootrem.c	Wed Aug 05 22:25:21 2015 +0200
@@ -90,13 +90,12 @@
 mpn_rootrem (mp_ptr rootp, mp_ptr remp,
 	     mp_srcptr up, mp_size_t un, mp_limb_t k)
 {
-  mp_size_t m;
   ASSERT (un > 0);
   ASSERT (up[un - 1] != 0);
   ASSERT (k > 1);
 
-  m = (un - 1) / k;		/* ceil(un/k) - 1 */
-  if (remp == NULL && m > 2)
+  /* (un-1)/k > 2 <=> un > 3k <=> (un + 2)/3 > k */
+  if (remp == NULL && (un + 2) / 3 > k)
     /* Pad {up,un} with k zero limbs.  This will produce an approximate root
        with one more limb, allowing us to compute the exact integral result. */
     {
@@ -105,7 +104,7 @@
       TMP_DECL;
       TMP_MARK;
       wn = un + k;
-      sn = m + 2; /* ceil(un/k) + 1 */
+      sn = (un - 1) / k + 2; /* ceil(un/k) + 1 */
       TMP_ALLOC_LIMBS_2 (wp, wn, /* will contain the padded input */
 			 sp, sn); /* approximate root of padded input */
       MPN_COPY (wp + k, up, un);
@@ -134,10 +133,10 @@
   mp_ptr qp, rp, sp, wp, scratch;
   mp_size_t qn, rn, sn, wn, nl, bn;
   mp_limb_t save, save2, cy;
-  unsigned long int unb; /* number of significant bits of {up,un} */
-  unsigned long int xnb; /* number of significant bits of the result */
-  unsigned long b, kk;
-  unsigned long sizes[GMP_NUMB_BITS + 1];
+  mp_bitcnt_t unb; /* number of significant bits of {up,un} */
+  mp_bitcnt_t xnb; /* number of significant bits of the result */
+  mp_bitcnt_t b, kk;
+  mp_bitcnt_t sizes[GMP_NUMB_BITS + 1];
   int ni, i;
   int c, perf_pow;
   int logk;


More information about the gmp-commit mailing list