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

mercurial at gmplib.org mercurial at gmplib.org
Fri Dec 11 07:13:54 UTC 2015


details:   /var/hg/gmp/rev/538a15c4b114
changeset: 16989:538a15c4b114
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Dec 10 14:03:29 2015 +0100
description:
mpn/generic/toom_interpolate_*.c: Use rsh1 also for negatives.

details:   /var/hg/gmp/rev/e369019855a4
changeset: 16990:e369019855a4
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Dec 10 14:15:39 2015 +0100
description:
ChangeLog

details:   /var/hg/gmp/rev/d25803384a6e
changeset: 16991:d25803384a6e
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Dec 11 07:59:50 2015 +0100
description:
bootstrap.c: Use clrbit and roinit.

details:   /var/hg/gmp/rev/f82576033450
changeset: 16992:f82576033450
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Dec 11 08:00:19 2015 +0100
description:
gen-bases.c: Use clrbit and swap

details:   /var/hg/gmp/rev/79f1ce97a698
changeset: 16993:79f1ce97a698
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Dec 11 08:07:15 2015 +0100
description:
mpn/generic/tdiv_qr.c: Save a variable.

details:   /var/hg/gmp/rev/e011dbf58644
changeset: 16994:e011dbf58644
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Dec 11 08:08:20 2015 +0100
description:
mpn/generic/toom3*.c: Use _ip1 when available

details:   /var/hg/gmp/rev/d33e967c4853
changeset: 16995:d33e967c4853
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Dec 11 08:09:49 2015 +0100
description:
mpz/set_d.c: Newalloc, when size is known

details:   /var/hg/gmp/rev/357e76e2fd3d
changeset: 16996:357e76e2fd3d
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Dec 11 08:13:46 2015 +0100
description:
mpz/pprime_p.c: Check for parity where it is needed only.

diffstat:

 ChangeLog                            |  10 ++++++++++
 bootstrap.c                          |  16 ++++++----------
 gen-bases.c                          |  16 ++++++----------
 mpn/generic/tdiv_qr.c                |  12 +++++-------
 mpn/generic/toom33_mul.c             |  10 +++++-----
 mpn/generic/toom3_sqr.c              |  10 +++++-----
 mpn/generic/toom_interpolate_12pts.c |  12 +++++++++++-
 mpn/generic/toom_interpolate_16pts.c |  17 ++++++++++++++++-
 mpn/generic/toom_interpolate_7pts.c  |   8 +++++++-
 mpz/pprime_p.c                       |  14 ++++++++------
 mpz/set_d.c                          |   7 ++-----
 mpz/sqrt.c                           |   6 +++---
 mpz/sqrtrem.c                        |   6 +++---
 13 files changed, 87 insertions(+), 57 deletions(-)

diffs (truncated from 461 to 300 lines):

diff -r 89f8e0980aef -r 357e76e2fd3d ChangeLog
--- a/ChangeLog	Thu Dec 10 06:12:51 2015 +0100
+++ b/ChangeLog	Fri Dec 11 08:13:46 2015 +0100
@@ -1,3 +1,13 @@
+2015-11-21 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* tests/misc/t-printf.c: Test a sequence of '%'.
+	* printf/doprnt.c: Avoid buffer overread with long long limbs.
+
+	* mpn/generic/toom_interpolate_7.c: Use the rsh1 functions,
+	  when available, also for negatives (clearing the carry).
+	* mpn/generic/toom_interpolate_12.c: Likewise.
+	* mpn/generic/toom_interpolate_16.c: Likewise.
+
 2015-12-06  Torbjörn Granlund  <torbjorng at google.com>
 
 	* configure.ac (arm*): Conditionally define NOTHUMB.
diff -r 89f8e0980aef -r 357e76e2fd3d bootstrap.c
--- a/bootstrap.c	Thu Dec 10 06:12:51 2015 +0100
+++ b/bootstrap.c	Fri Dec 11 08:13:46 2015 +0100
@@ -1,6 +1,6 @@
 /* Functions needed for bootstrapping the gmp build, based on mini-gmp.
 
-Copyright 2001, 2002, 2004, 2011, 2012 Free Software Foundation, Inc.
+Copyright 2001, 2002, 2004, 2011, 2012, 2015 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -88,7 +88,7 @@
 /* Set inv to the inverse of d, in the style of invert_limb, ie. for
    udiv_qrnnd_preinv.  */
 void
-mpz_preinv_invert (mpz_t inv, mpz_t d, int numb_bits)
+mpz_preinv_invert (mpz_t inv, const mpz_t d, int numb_bits)
 {
   mpz_t  t;
   int    norm;
@@ -99,16 +99,14 @@
   mpz_init_set_ui (t, 1L);
   mpz_mul_2exp (t, t, 2*numb_bits - norm);
   mpz_tdiv_q (inv, t, d);
-  mpz_set_ui (t, 1L);
-  mpz_mul_2exp (t, t, numb_bits);
-  mpz_sub (inv, inv, t);
+  mpz_clrbit (inv, numb_bits);
 
   mpz_clear (t);
 }
 
 /* Calculate r satisfying r*d == 1 mod 2^n. */
 void
-mpz_invert_2exp (mpz_t r, mpz_t a, unsigned long n)
+mpz_invert_2exp (mpz_t r, const mpz_t a, unsigned long n)
 {
   unsigned long  i;
   mpz_t  inv, prod;
@@ -137,10 +135,8 @@
 
 /* Calculate inv satisfying r*a == 1 mod 2^n. */
 void
-mpz_invert_ui_2exp (mpz_t r, unsigned long a, unsigned long n)
+mpz_invert_ui_2exp (mpz_t r, mp_limb_t a, unsigned long n)
 {
   mpz_t  az;
-  mpz_init_set_ui (az, a);
-  mpz_invert_2exp (r, az, n);
-  mpz_clear (az);
+  mpz_invert_2exp (r, mpz_roinit_n (az, &a, 1), n);
 }
diff -r 89f8e0980aef -r 357e76e2fd3d gen-bases.c
--- a/gen-bases.c	Thu Dec 10 06:12:51 2015 +0100
+++ b/gen-bases.c	Fri Dec 11 08:13:46 2015 +0100
@@ -1,7 +1,7 @@
 /* Generate mp_bases data.
 
-Copyright 1991, 1993, 1994, 1996, 2000, 2002, 2004, 2011, 2012 Free Software
-Foundation, Inc.
+Copyright 1991, 1993, 1994, 1996, 2000, 2002, 2004, 2011, 2012, 2015
+Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -57,13 +57,11 @@
 
   mpz_set_ui (t, 1L);
   mpz_mul_2exp (t, t, numb_bits);
-  mpz_set_ui (big_base, 1L);
+  mpz_set_ui (big_base, (long) base);
   chars_per_limb = 0;
-  for (;;)
+  while (mpz_cmp (big_base, t) <= 0)
     {
       mpz_mul_ui (big_base, big_base, (long) base);
-      if (mpz_cmp (big_base, t) > 0)
-        break;
       chars_per_limb++;
     }
 
@@ -74,9 +72,7 @@
   mpz_set_ui (t, 1L);
   mpz_mul_2exp (t, t, 2*limb_bits - normalization_steps);
   mpz_tdiv_q (big_base_inverted, t, big_base);
-  mpz_set_ui (t, 1L);
-  mpz_mul_2exp (t, t, limb_bits);
-  mpz_sub (big_base_inverted, big_base_inverted, t);
+  mpz_clrbit (big_base_inverted, limb_bits);
 }
 
 void
@@ -137,7 +133,7 @@
       if (mpz_cmp (t2, two) < 0)	/* not too large? */
 	{
 	  mpz_setbit (r, i);		/* set next less significant bit */
-	  mpz_set (t, t2);		/* new value acceptable */
+	  mpz_swap (t, t2);		/* new value acceptable */
 	}
     }
 
diff -r 89f8e0980aef -r 357e76e2fd3d mpn/generic/tdiv_qr.c
--- a/mpn/generic/tdiv_qr.c	Thu Dec 10 06:12:51 2015 +0100
+++ b/mpn/generic/tdiv_qr.c	Fri Dec 11 08:13:46 2015 +0100
@@ -5,13 +5,13 @@
    operands are unaffected.
 
    Preconditions:
-   1. The most significant limb of of the divisor must be non-zero.
+   1. The most significant limb of the divisor must be non-zero.
    2. nn >= dn, even if qxn is non-zero.  (??? relax this ???)
 
    The time complexity of this is O(qn*qn+M(dn,qn)), where M(m,n) is the time
    complexity of multiplication.
 
-Copyright 1997, 2000-2002, 2005, 2009 Free Software Foundation, Inc.
+Copyright 1997, 2000-2002, 2005, 2009, 2015 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -69,17 +69,16 @@
 
     case 2:
       {
-	mp_ptr n2p, d2p;
+	mp_ptr n2p;
 	mp_limb_t qhl, cy;
 	TMP_DECL;
 	TMP_MARK;
 	if ((dp[1] & GMP_NUMB_HIGHBIT) == 0)
 	  {
 	    int cnt;
-	    mp_limb_t dtmp[2];
+	    mp_limb_t d2p[2];
 	    count_leading_zeros (cnt, dp[1]);
 	    cnt -= GMP_NAIL_BITS;
-	    d2p = dtmp;
 	    d2p[1] = (dp[1] << cnt) | (dp[0] >> (GMP_NUMB_BITS - cnt));
 	    d2p[0] = (dp[0] << cnt) & GMP_NUMB_MASK;
 	    n2p = TMP_ALLOC_LIMBS (nn + 1);
@@ -94,10 +93,9 @@
 	  }
 	else
 	  {
-	    d2p = (mp_ptr) dp;
 	    n2p = TMP_ALLOC_LIMBS (nn);
 	    MPN_COPY (n2p, np, nn);
-	    qhl = mpn_divrem_2 (qp, 0L, n2p, nn, d2p);
+	    qhl = mpn_divrem_2 (qp, 0L, n2p, nn, dp);
 	    qp[nn - 2] = qhl;	/* always store nn-2+1 quotient limbs */
 	    rp[0] = n2p[0];
 	    rp[1] = n2p[1];
diff -r 89f8e0980aef -r 357e76e2fd3d mpn/generic/toom33_mul.c
--- a/mpn/generic/toom33_mul.c	Thu Dec 10 06:12:51 2015 +0100
+++ b/mpn/generic/toom33_mul.c	Fri Dec 11 08:13:46 2015 +0100
@@ -8,7 +8,7 @@
    SAFE TO REACH IT THROUGH DOCUMENTED INTERFACES.  IN FACT, IT IS ALMOST
    GUARANTEED THAT IT WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
 
-Copyright 2006-2008, 2010, 2012 Free Software Foundation, Inc.
+Copyright 2006-2008, 2010, 2012, 2015 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -283,8 +283,8 @@
     }
   else if (as1[n] != 0)
     {
-#if HAVE_NATIVE_mpn_addlsh1_n
-      cy = 2 * bs1[n] + mpn_addlsh1_n (v1 + n, v1 + n, bs1, n);
+#if HAVE_NATIVE_mpn_addlsh1_n_ip1
+      cy = 2 * bs1[n] + mpn_addlsh1_n_ip1 (v1 + n, bs1, n);
 #else
       cy = 2 * bs1[n] + mpn_addmul_1 (v1 + n, bs1, n, CNST_LIMB(2));
 #endif
@@ -297,8 +297,8 @@
     }
   else if (bs1[n] != 0)
     {
-#if HAVE_NATIVE_mpn_addlsh1_n
-      cy += mpn_addlsh1_n (v1 + n, v1 + n, as1, n);
+#if HAVE_NATIVE_mpn_addlsh1_n_ip1
+      cy += mpn_addlsh1_n_ip1 (v1 + n, as1, n);
 #else
       cy += mpn_addmul_1 (v1 + n, as1, n, CNST_LIMB(2));
 #endif
diff -r 89f8e0980aef -r 357e76e2fd3d mpn/generic/toom3_sqr.c
--- a/mpn/generic/toom3_sqr.c	Thu Dec 10 06:12:51 2015 +0100
+++ b/mpn/generic/toom3_sqr.c	Fri Dec 11 08:13:46 2015 +0100
@@ -7,7 +7,7 @@
    SAFE TO REACH IT THROUGH DOCUMENTED INTERFACES.  IN FACT, IT IS ALMOST
    GUARANTEED THAT IT WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
 
-Copyright 2006-2010, 2012 Free Software Foundation, Inc.
+Copyright 2006-2010, 2012, 2015 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -193,8 +193,8 @@
     }
   else if (as1[n] != 0)
     {
-#if HAVE_NATIVE_mpn_addlsh1_n
-      cy = 2 * as1[n] + mpn_addlsh1_n (v1 + n, v1 + n, as1, n);
+#if HAVE_NATIVE_mpn_addlsh1_n_ip1
+      cy = 2 * as1[n] + mpn_addlsh1_n_ip1 (v1 + n, as1, n);
 #else
       cy = 2 * as1[n] + mpn_addmul_1 (v1 + n, as1, n, CNST_LIMB(2));
 #endif
@@ -207,8 +207,8 @@
     }
   else if (as1[n] != 0)
     {
-#if HAVE_NATIVE_mpn_addlsh1_n
-      cy += mpn_addlsh1_n (v1 + n, v1 + n, as1, n);
+#if HAVE_NATIVE_mpn_addlsh1_n_ip1
+      cy += mpn_addlsh1_n_ip1 (v1 + n, as1, n);
 #else
       cy += mpn_addmul_1 (v1 + n, as1, n, CNST_LIMB(2));
 #endif
diff -r 89f8e0980aef -r 357e76e2fd3d mpn/generic/toom_interpolate_12pts.c
--- a/mpn/generic/toom_interpolate_12pts.c	Thu Dec 10 06:12:51 2015 +0100
+++ b/mpn/generic/toom_interpolate_12pts.c	Fri Dec 11 08:13:46 2015 +0100
@@ -6,7 +6,7 @@
    SAFE TO REACH IT THROUGH DOCUMENTED INTERFACES.  IN FACT, IT IS ALMOST
    GUARANTEED THAT IT WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
 
-Copyright 2009, 2010, 2012 Free Software Foundation, Inc.
+Copyright 2009, 2010, 2012, 2015 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -287,12 +287,22 @@
 
   ASSERT_NOCARRY(mpn_sub_n (r3, r3, r2, n3p1));
 
+#ifdef HAVE_NATIVE_mpn_rsh1sub_n
+  mpn_rsh1sub_n (r4, r2, r4, n3p1);
+  r4 [n3p1 - 1] &= GMP_NUMB_MASK >> 1;
+#else
   mpn_sub_n (r4, r2, r4, n3p1);
   ASSERT_NOCARRY(mpn_rshift(r4, r4, n3p1, 1));
+#endif
   ASSERT_NOCARRY(mpn_sub_n (r2, r2, r4, n3p1));
 
+#ifdef HAVE_NATIVE_mpn_rsh1add_n
+  mpn_rsh1add_n (r5, r5, r1, n3p1);
+  r5 [n3p1 - 1] &= GMP_NUMB_MASK >> 1;
+#else
   mpn_add_n (r5, r5, r1, n3p1);
   ASSERT_NOCARRY(mpn_rshift(r5, r5, n3p1, 1));
+#endif
 
   /* last interpolation steps... */
   ASSERT_NOCARRY(mpn_sub_n (r3, r3, r1, n3p1));
diff -r 89f8e0980aef -r 357e76e2fd3d mpn/generic/toom_interpolate_16pts.c
--- a/mpn/generic/toom_interpolate_16pts.c	Thu Dec 10 06:12:51 2015 +0100
+++ b/mpn/generic/toom_interpolate_16pts.c	Fri Dec 11 08:13:46 2015 +0100
@@ -6,7 +6,7 @@
    SAFE TO REACH IT THROUGH DOCUMENTED INTERFACES.  IN FACT, IT IS ALMOST
    GUARANTEED THAT IT WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
 
-Copyright 2009, 2010, 2012 Free Software Foundation, Inc.
+Copyright 2009, 2010, 2012, 2015 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -439,16 +439,31 @@
   ASSERT_NOCARRY(mpn_sub_n (r4, r4, r3, n3p1));
   ASSERT_NOCARRY(mpn_sub_n (r4, r4, r2, n3p1));
 
+#ifdef HAVE_NATIVE_mpn_rsh1add_n
+  mpn_rsh1add_n (r6, r2, r6, n3p1);
+  r6 [n3p1 - 1] &= GMP_NUMB_MASK >> 1;
+#else
   mpn_add_n (r6, r2, r6, n3p1);
   ASSERT_NOCARRY(mpn_rshift(r6, r6, n3p1, 1));
+#endif
   ASSERT_NOCARRY(mpn_sub_n (r2, r2, r6, n3p1));
 
+#ifdef HAVE_NATIVE_mpn_rsh1sub_n
+  mpn_rsh1sub_n (r5, r3, r5, n3p1);
+  r5 [n3p1 - 1] &= GMP_NUMB_MASK >> 1;


More information about the gmp-commit mailing list