[Gmp-commit] /home/hgfiles/gmp: Support nails in invert and mulmod.

mercurial at gmplib.org mercurial at gmplib.org
Sat Dec 19 05:42:58 CET 2009


details:   /home/hgfiles/gmp/rev/cd997c18c6b7
changeset: 13131:cd997c18c6b7
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Dec 19 05:42:53 2009 +0100
description:
Support nails in invert and mulmod.

diffstat:

 ChangeLog                 |   5 +++++
 mpn/generic/invert.c      |   4 ++--
 mpn/generic/invertappr.c  |  12 ++++++------
 mpn/generic/mulmod_bnm1.c |   2 +-
 mpn/generic/sqrmod_bnm1.c |   2 +-
 5 files changed, 15 insertions(+), 10 deletions(-)

diffs (115 lines):

diff -r 262bb5b4cbf5 -r cd997c18c6b7 ChangeLog
--- a/ChangeLog	Fri Dec 18 19:36:00 2009 +0100
+++ b/ChangeLog	Sat Dec 19 05:42:53 2009 +0100
@@ -25,6 +25,11 @@
 
 2009-12-18  Marco Bodrato <bodrato at mail.dm.unipi.it>
 
+	* mpn/generic/invert.c: Nailify.
+	* mpn/generic/invertappr.c: Nailify.
+	* mpn/generic/mulmod_bnm1.c: Nailify.
+	* mpn/generic/sqrmod_bnm1.c: Nailify.
+
 	* tests/mpn/t-invert.c: New test program.
 
 	* mpn/generic/toom63_mul.c: New file.
diff -r 262bb5b4cbf5 -r cd997c18c6b7 mpn/generic/invert.c
--- a/mpn/generic/invert.c	Fri Dec 18 19:36:00 2009 +0100
+++ b/mpn/generic/invert.c	Sat Dec 19 05:42:53 2009 +0100
@@ -39,7 +39,7 @@
 mpn_invert (mp_ptr ip, mp_srcptr dp, mp_size_t n, mp_ptr scratch)
 {
   ASSERT (n > 0);
-  ASSERT (dp[n-1] & GMP_LIMB_HIGHBIT);
+  ASSERT (dp[n-1] & GMP_NUMB_HIGHBIT);
   ASSERT (! MPN_OVERLAP_P (ip, n, dp, n));
   ASSERT (! MPN_OVERLAP_P (ip, n, scratch, mpn_invertappr_itch(n)));
   ASSERT (! MPN_OVERLAP_P (dp, n, scratch, mpn_invertappr_itch(n)));
@@ -60,7 +60,7 @@
 
       xp = scratch + n + 2;				/* 2 * n limbs */
       for (i = n - 1; i >= 0; i--)
-	xp[i] = ~CNST_LIMB(0);
+	xp[i] = GMP_NUMB_MAX;
       mpn_com_n (xp + n, dp, n);
       mpn_tdiv_qr (scratch, ip, 0, xp, 2 * n, dp, n);
       MPN_COPY (ip, scratch, n);
diff -r 262bb5b4cbf5 -r cd997c18c6b7 mpn/generic/invertappr.c
--- a/mpn/generic/invertappr.c	Fri Dec 18 19:36:00 2009 +0100
+++ b/mpn/generic/invertappr.c	Sat Dec 19 05:42:53 2009 +0100
@@ -1,5 +1,5 @@
 /* mpn_invertappr and helper functions.  Compute I such that
-   floor((B^{2n}-1)/U - 1 <= I <= floor((B^{2n}-1)/U.
+   floor((B^{2n}-1)/U - 1 <= I + B^n <= floor((B^{2n}-1)/U.
 
    Contributed to the GNU project by Marco Bodrato.
 
@@ -91,7 +91,7 @@
   mp_ptr xp;
 
   ASSERT (n > 0);
-  ASSERT (dp[n-1] & GMP_LIMB_HIGHBIT);
+  ASSERT (dp[n-1] & GMP_NUMB_HIGHBIT);
   ASSERT (! MPN_OVERLAP_P (ip, n, dp, n));
   ASSERT (! MPN_OVERLAP_P (ip, n, tp, mpn_invertappr_itch(n)));
   ASSERT (! MPN_OVERLAP_P (dp, n, tp, mpn_invertappr_itch(n)));
@@ -104,7 +104,7 @@
     xp = tp + n + 2;				/* 2 * n limbs */
 
     for (i = n - 1; i >= 0; i--)
-      xp[i] = ~CNST_LIMB(0);
+      xp[i] = GMP_NUMB_MAX;
     mpn_com_n (xp + n, dp, n);
 
     /* Now xp contains B^2n - {dp,n}*B^n - 1 */
@@ -166,7 +166,7 @@
 #define rp scratch
 
   ASSERT (n > 2);
-  ASSERT (dp[n-1] & GMP_LIMB_HIGHBIT);
+  ASSERT (dp[n-1] & GMP_NUMB_HIGHBIT);
   ASSERT (! MPN_OVERLAP_P (ip, n, dp, n));
   ASSERT (! MPN_OVERLAP_P (ip, n, scratch, mpn_invertappr_itch(n)));
   ASSERT (! MPN_OVERLAP_P (dp, n, scratch, mpn_invertappr_itch(n)));
@@ -272,7 +272,7 @@
     if (sizp == sizes) { /* Get out of the cycle */
       /* Check for possible carry propagation from below. */
       cy = rp[3*rn - n - 1] > GMP_NUMB_MAX - 7; /* Be conservative. */
-/*    cy = mpn_add_1 (rp + rn, rp + rn, 2*rn - n, 6); */
+/*    cy = mpn_add_1 (rp + rn, rp + rn, 2*rn - n, 4); */
       break;
     }
     rn = n;
@@ -287,7 +287,7 @@
 mpn_invertappr (mp_ptr ip, mp_srcptr dp, mp_size_t n, mp_ptr scratch)
 {
   ASSERT (n > 0);
-  ASSERT (dp[n-1] & GMP_LIMB_HIGHBIT);
+  ASSERT (dp[n-1] & GMP_NUMB_HIGHBIT);
   ASSERT (! MPN_OVERLAP_P (ip, n, dp, n));
   ASSERT (! MPN_OVERLAP_P (ip, n, scratch, mpn_invertappr_itch(n)));
   ASSERT (! MPN_OVERLAP_P (dp, n, scratch, mpn_invertappr_itch(n)));
diff -r 262bb5b4cbf5 -r cd997c18c6b7 mpn/generic/mulmod_bnm1.c
--- a/mpn/generic/mulmod_bnm1.c	Fri Dec 18 19:36:00 2009 +0100
+++ b/mpn/generic/mulmod_bnm1.c	Sat Dec 19 05:42:53 2009 +0100
@@ -246,7 +246,7 @@
 
       cy = mpn_rshift (rp+n, xp, n, 1);
       if (hi != cy)
-	rp[2*n-1] |= GMP_LIMB_HIGHBIT;
+	rp[2*n-1] |= GMP_NUMB_HIGHBIT;
       if (hi < cy)
 	/* Underflow */
 	hi = mpn_add_1 (rp+n, rp+n, n, 1);
diff -r 262bb5b4cbf5 -r cd997c18c6b7 mpn/generic/sqrmod_bnm1.c
--- a/mpn/generic/sqrmod_bnm1.c	Fri Dec 18 19:36:00 2009 +0100
+++ b/mpn/generic/sqrmod_bnm1.c	Sat Dec 19 05:42:53 2009 +0100
@@ -201,7 +201,7 @@
 
       cy = mpn_rshift (rp+n, xp, n, 1);
       if (hi != cy)
-	rp[2*n-1] |= GMP_LIMB_HIGHBIT;
+	rp[2*n-1] |= GMP_NUMB_HIGHBIT;
       if (hi < cy)
 	/* Underflow */
 	hi = mpn_add_1 (rp+n, rp+n, n, 1);


More information about the gmp-commit mailing list