[Gmp-commit] /var/hg/gmp: 6 new changesets

mercurial at gmplib.org mercurial at gmplib.org
Thu Feb 8 12:14:00 UTC 2018


details:   /var/hg/gmp/rev/8e3eb98d5ee6
changeset: 17551:8e3eb98d5ee6
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Feb 08 12:50:18 2018 +0100
description:
primesieve.c (fill_bitpattern): Use MPN_FILL.

details:   /var/hg/gmp/rev/8e0a2a0fdbaa
changeset: 17552:8e0a2a0fdbaa
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Feb 08 12:52:26 2018 +0100
description:
mpz/divegcd.c (mpz_divexact_limb): Use MPN_DIVREM_OR_DIVEXACT_1.

details:   /var/hg/gmp/rev/a2d0fcbee255
changeset: 17553:a2d0fcbee255
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Feb 08 12:53:59 2018 +0100
description:
mpz/bin_uiui.c: Details on unused code...

details:   /var/hg/gmp/rev/f4a1f32eaf5f
changeset: 17554:f4a1f32eaf5f
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Feb 08 12:58:28 2018 +0100
description:
gmp-impl.h (popc_limb): Use fewer constants (GMP_LIMB_BITS == 16)

details:   /var/hg/gmp/rev/d6b57abdad8e
changeset: 17555:d6b57abdad8e
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Feb 08 13:07:16 2018 +0100
description:
printf/snprntffuns.c: report -1 as an error.
acinclude.m4: Refuse -1 as a normal return value.

details:   /var/hg/gmp/rev/c9ee97d5775c
changeset: 17556:c9ee97d5775c
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Feb 08 13:11:17 2018 +0100
description:
mpz/bin_uiui.c (mpz_smallk_bin_uiui): One more shortcut for small k.

diffstat:

 acinclude.m4         |   4 ++--
 gmp-impl.h           |   6 +++---
 mpz/bin_uiui.c       |  37 ++++++++++++++++++++++---------------
 mpz/divegcd.c        |   4 ++--
 primesieve.c         |   2 +-
 printf/snprntffuns.c |   7 ++-----
 6 files changed, 32 insertions(+), 28 deletions(-)

diffs (167 lines):

diff -r df4f222d213c -r c9ee97d5775c acinclude.m4
--- a/acinclude.m4	Fri Feb 02 17:00:53 2018 +0100
+++ b/acinclude.m4	Thu Feb 08 13:11:17 2018 +0100
@@ -3729,11 +3729,11 @@
 
   ret = vsnprintf (buf, 4, fmt, ap);
 
-  if (strcmp (buf, "hel") != 0)
+  if (ret == -1 || strcmp (buf, "hel") != 0)
     return 1;
 
   /* allowed return values */
-  if (ret != -1 && ret != 3 && ret != 11)
+  if (ret != 3 && ret != 11)
     return 2;
 
   return 0;
diff -r df4f222d213c -r c9ee97d5775c gmp-impl.h
--- a/gmp-impl.h	Fri Feb 02 17:00:53 2018 +0100
+++ b/gmp-impl.h	Thu Feb 08 13:11:17 2018 +0100
@@ -3711,9 +3711,9 @@
     mp_limb_t  __x = (input);						\
     __x -= (__x >> 1) & MP_LIMB_T_MAX/3;				\
     __x = ((__x >> 2) & MP_LIMB_T_MAX/5) + (__x & MP_LIMB_T_MAX/5);	\
-    __x = ((__x >> 4) + __x) & MP_LIMB_T_MAX/17;			\
-    __x = ((__x >> 8) + __x);						\
-    (result) = __x & 0xff;						\
+    __x += (__x >> 4);							\
+    __x = ((__x >> 8) & MP_LIMB_T_MAX/4369)+(__x & MP_LIMB_T_MAX/4369);	\
+    (result) = __x;							\
   } while (0)
 #endif
 
diff -r df4f222d213c -r c9ee97d5775c mpz/bin_uiui.c
--- a/mpz/bin_uiui.c	Fri Feb 02 17:00:53 2018 +0100
+++ b/mpz/bin_uiui.c	Thu Feb 08 13:11:17 2018 +0100
@@ -151,7 +151,7 @@
 static mp_limb_t
 mul9 (mp_limb_t m)
 {
-  return (m + 8) * (mul8 (m) >> 1) ;
+  return (m + 8) * mul8 (m) ;
 }
 
 static mp_limb_t
@@ -171,7 +171,7 @@
 #define M (numberof(mulfunc))
 
 /* Number of factors-of-2 removed by the corresponding mulN function.  */
-static const unsigned char tcnttab[] = {0, 1, 1, 2, 2, 4, 4, 6 /*,7 ,8*/};
+static const unsigned char tcnttab[] = {0, 1, 1, 2, 2, 4, 4, 6 /*,6,8*/};
 
 #if 1
 /* This variant is inaccurate but share the code with other functions.  */
@@ -324,40 +324,47 @@
   mp_ptr rp;
   mp_size_t rn, alloc;
   mp_limb_t i, iii, cy;
-  mp_bitcnt_t i2cnt, cnt;
-
-  count_leading_zeros (cnt, (mp_limb_t) n);
-  cnt = GMP_LIMB_BITS - cnt;
-  alloc = cnt * k / GMP_NUMB_BITS + 3;	/* FIXME: ensure rounding is enough. */
-  rp = MPZ_NEWALLOC (r, alloc);
+  unsigned i2cnt, cnt;
 
   MAXFACS (nmax, n);
   nmax = MIN (nmax, M);
 
   i = n - k + 1;
 
-  nmax = MIN (nmax, k);
+  i2cnt = __gmp_fac2cnt_table[k / 2 - 1];		/* low zeros count */
+  if (nmax >= k)
+    {
+      MPZ_NEWALLOC (r, 1) [0] = mulfunc[k - 1] (i) * facinv[k - 2] >>
+	(i2cnt - tcnttab[k - 1]);
+      SIZ(r) = 1;
+      return;
+    }
+
+  count_leading_zeros (cnt, (mp_limb_t) n);
+  cnt = GMP_LIMB_BITS - cnt;
+  alloc = cnt * k / GMP_NUMB_BITS + 3;	/* FIXME: ensure rounding is enough. */
+  rp = MPZ_NEWALLOC (r, alloc);
+
   rp[0] = mulfunc[nmax - 1] (i);
   rn = 1;
   i += nmax;				/* number of factors used */
-  i2cnt = tcnttab[nmax - 1];		/* low zeros count */
+  i2cnt -= tcnttab[nmax - 1];		/* low zeros count */
   numfac = k - nmax;
-  while (numfac != 0)
+  do
     {
       nmax = MIN (nmax, numfac);
       iii = mulfunc[nmax - 1] (i);
       i += nmax;			/* number of factors used */
-      i2cnt += tcnttab[nmax - 1];	/* update low zeros count */
+      i2cnt -= tcnttab[nmax - 1];	/* update low zeros count */
       cy = mpn_mul_1 (rp, rp, rn, iii);	/* accumulate new factors */
       rp[rn] = cy;
       rn += cy != 0;
       numfac -= nmax;
-    }
+    } while (numfac != 0);
 
   ASSERT (rn < alloc);
 
-  mpn_pi1_bdiv_q_1 (rp, rp, rn, __gmp_oddfac_table[k], facinv[k - 2],
-		    __gmp_fac2cnt_table[k / 2 - 1] - i2cnt);
+  mpn_pi1_bdiv_q_1 (rp, rp, rn, __gmp_oddfac_table[k], facinv[k - 2], i2cnt);
   /* A two-fold, branch-free normalisation is possible :*/
   /* rn -= rp[rn - 1] == 0; */
   /* rn -= rp[rn - 1] == 0; */
diff -r df4f222d213c -r c9ee97d5775c mpz/divegcd.c
--- a/mpz/divegcd.c	Fri Feb 02 17:00:53 2018 +0100
+++ b/mpz/divegcd.c	Thu Feb 08 13:11:17 2018 +0100
@@ -97,10 +97,10 @@
 
   qp = MPZ_REALLOC (q, abs_size);
 
-  mpn_divexact_1 (qp, PTR(a), abs_size, d);
+  MPN_DIVREM_OR_DIVEXACT_1 (qp, PTR(a), abs_size, d);
 
   abs_size -= (qp[abs_size-1] == 0);
-  SIZ(q) = (size>0 ? abs_size : -abs_size);
+  SIZ(q) = (size > 0 ? abs_size : -abs_size);
 }
 
 void
diff -r df4f222d213c -r c9ee97d5775c primesieve.c
--- a/primesieve.c	Fri Feb 02 17:00:53 2018 +0100
+++ b/primesieve.c	Thu Feb 08 13:11:17 2018 +0100
@@ -235,7 +235,7 @@
   } while (--limbs != 0);
   return 2;
 #else
-  MPN_ZERO (bit_array, limbs);
+  MPN_FILL (bit_array, limbs, CNST_LIMB(0));
   return 0;
 #endif
 #endif
diff -r df4f222d213c -r c9ee97d5775c printf/snprntffuns.c
--- a/printf/snprntffuns.c	Fri Feb 02 17:00:53 2018 +0100
+++ b/printf/snprntffuns.c	Thu Feb 08 13:11:17 2018 +0100
@@ -75,10 +75,7 @@
       va_copy (ap, orig_ap);
       ret = vsnprintf (d->buf, avail, fmt, ap);
       if (ret == -1)
-        {
-          ASSERT (strlen (d->buf) == avail-1);
-          ret = avail-1;
-        }
+        return ret;
 
       step = MIN (ret, avail-1);
       d->size -= step;
@@ -104,7 +101,7 @@
       ret = vsnprintf (p, alloc, fmt, ap);
       __GMP_FREE_FUNC_TYPE (p, alloc, char);
     }
-  while (ret == alloc-1 || ret == -1);
+  while (ret == alloc-1);
 
   return ret;
 }


More information about the gmp-commit mailing list