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

mercurial at gmplib.org mercurial at gmplib.org
Fri Jun 1 13:21:17 CEST 2012


details:   /var/hg/gmp/rev/317e30037440
changeset: 15036:317e30037440
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Jun 01 13:17:14 2012 +0200
description:
tests/mpn/t-bdiv.c: Test also mpn_bdiv_qr.

details:   /var/hg/gmp/rev/8354a1abcd5c
changeset: 15037:8354a1abcd5c
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Jun 01 13:18:01 2012 +0200
description:
mpn/generic/bdiv_qr.c: Add an ASSERT.

details:   /var/hg/gmp/rev/0bac450f0eaf
changeset: 15038:0bac450f0eaf
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Jun 01 13:20:07 2012 +0200
description:
mpn/generic/remove.c: Add a zero limb to use bdiv_qr...

diffstat:

 ChangeLog             |   7 ++++++-
 mpn/generic/bdiv_qr.c |   1 +
 mpn/generic/remove.c  |  12 +++++++-----
 mpz/remove.c          |   2 +-
 tests/mpn/t-bdiv.c    |  21 +++++++++++++++++++++
 5 files changed, 36 insertions(+), 7 deletions(-)

diffs (121 lines):

diff -r 5be212beb8e9 -r 0bac450f0eaf ChangeLog
--- a/ChangeLog	Fri Jun 01 12:36:50 2012 +0200
+++ b/ChangeLog	Fri Jun 01 13:20:07 2012 +0200
@@ -11,7 +11,12 @@
 
 	* gmp-impl.h (LIMBS): Removed, was an alias for PTR.
 	* mpz/combit.c: Use PTR and CNST_LIMB.
-	
+
+	* tests/mpn/t-bdiv.c: Test also mpn_bdiv_qr.
+	* mpn/generic/bdiv_qr.c: Add an ASSERT.
+
+	* mpn/generic/remove.c: Add a zero limb to use bdiv_qr...
+
 2012-05-31  Marc Glisse  <marc.glisse at inria.fr>
 
 	* gmpxx.h (mpq_class::mpq_class): Handle mpq_class(0,1).
diff -r 5be212beb8e9 -r 0bac450f0eaf mpn/generic/bdiv_qr.c
--- a/mpn/generic/bdiv_qr.c	Fri Jun 01 12:36:50 2012 +0200
+++ b/mpn/generic/bdiv_qr.c	Fri Jun 01 13:20:07 2012 +0200
@@ -40,6 +40,7 @@
   mp_limb_t di;
   mp_limb_t rh;
 
+  ASSERT (nn > dn);
   if (BELOW_THRESHOLD (dn, DC_BDIV_QR_THRESHOLD) ||
       BELOW_THRESHOLD (nn - dn, DC_BDIV_QR_THRESHOLD))
     {
diff -r 5be212beb8e9 -r 0bac450f0eaf mpn/generic/remove.c
--- a/mpn/generic/remove.c	Fri Jun 01 12:36:50 2012 +0200
+++ b/mpn/generic/remove.c	Fri Jun 01 13:20:07 2012 +0200
@@ -68,8 +68,8 @@
   TMP_MARK;
 
   tp = TMP_ALLOC_LIMBS ((un + vn) / 2); /* remainder */
-  qp = TMP_ALLOC_LIMBS (un);		/* quotient, alternating */
-  qp2 = TMP_ALLOC_LIMBS (un);		/* quotient, alternating */
+  qp = TMP_ALLOC_LIMBS (un + 1);	/* quotient, alternating */
+  qp2 = TMP_ALLOC_LIMBS (un + 1);	/* quotient, alternating */
   np = TMP_ALLOC_LIMBS (un + LOG);	/* powers of V */
   pp = vp;
   pn = vn;
@@ -77,7 +77,7 @@
   /* FIXME: This allocation need indicate a flaw in the current itch mechanism:
      Which operands not greater than un,un will incur the worst itch?  We need
      a parallel foo_maxitch set of functions.  */
-  scratch_out = TMP_ALLOC_LIMBS (mpn_bdiv_qr_itch (un, un >> 1));
+  scratch_out = TMP_ALLOC_LIMBS (mpn_bdiv_qr_itch (un + 1, (un + 1) >> 1));
 
   MPN_COPY (qp, up, un);
   qn = un;
@@ -85,7 +85,8 @@
   npowers = 0;
   while (qn >= pn)
     {
-      mpn_bdiv_qr (qp2, tp, qp, qn, pp, pn, scratch_out);
+      qp[qn] = 0;
+      mpn_bdiv_qr (qp2, tp, qp, qn + 1, pp, pn, scratch_out);
       if (!mpn_zero_p (tp, pn))
 	break;			/* could not divide by V^npowers */
 
@@ -115,6 +116,7 @@
 
   for (i = npowers - 1; i >= 0; i--)
     {
+      qp[qn] = 0;
       pp = pwpsp[i];
       pn = pwpsn[i];
       if (qn < pn)
@@ -123,7 +125,7 @@
       if (pwr + ((mp_bitcnt_t) 1 << i) > cap)
 	continue;		/* V^i would bring us past cap */
 
-      mpn_bdiv_qr (qp2, tp, qp, qn, pp, pn, scratch_out);
+      mpn_bdiv_qr (qp2, tp, qp, qn + 1, pp, pn, scratch_out);
       if (!mpn_zero_p (tp, pn))
 	continue;		/* could not divide by V^i */
 
diff -r 5be212beb8e9 -r 0bac450f0eaf mpz/remove.c
--- a/mpz/remove.c	Fri Jun 01 12:36:50 2012 +0200
+++ b/mpz/remove.c	Fri Jun 01 13:20:07 2012 +0200
@@ -51,7 +51,7 @@
     dn = ABS (sn);
     dp = MPZ_REALLOC (dest, dn);
 
-    pwr = mpn_remove (dp, &dn, PTR(src), dn, fp, afn, ~(mp_bitcnt_t) 0);
+    pwr = mpn_remove (dp, &dn, PTR(src), dn, PTR(f), afn, ~(mp_bitcnt_t) 0);
 
     SIZ (dest) = ((pwr & (fn < 0)) ^ (sn < 0)) ? -dn : dn;
   } else
diff -r 5be212beb8e9 -r 0bac450f0eaf tests/mpn/t-bdiv.c
--- a/tests/mpn/t-bdiv.c	Fri Jun 01 12:36:50 2012 +0200
+++ b/tests/mpn/t-bdiv.c	Fri Jun 01 13:20:07 2012 +0200
@@ -296,6 +296,27 @@
 	  check_one (qp, NULL, 0, np, nn, dp, dn, "mpn_dcpi1_bdiv_q");
 	}
 
+      if (nn > dn)
+	{
+	  /* Test mpn_bdiv_qr */
+	  itch = mpn_bdiv_qr_itch (nn, dn);
+	  if (itch + 1 > alloc)
+	    {
+	      scratch = __GMP_REALLOCATE_FUNC_LIMBS (scratch, alloc, itch + 1);
+	      alloc = itch + 1;
+	    }
+	  scratch[itch] = ran;
+	  MPN_ZERO (qp, nn - dn);
+	  MPN_ZERO (rp, dn);
+	  rp[dn] = rran1;
+	  rh = mpn_bdiv_qr (qp, rp, np, nn, dp, dn, scratch);
+	  ASSERT_ALWAYS (ran == scratch[itch]);
+	  ASSERT_ALWAYS (qp[-1] == qran0);  ASSERT_ALWAYS (qp[nn - dn + 1] == qran1);
+	  ASSERT_ALWAYS (rp[-1] == rran0);  ASSERT_ALWAYS (rp[dn] == rran1);
+
+	  check_one (qp, rp, rh, np, nn, dp, dn, "mpn_bdiv_qr");
+	}
+
       if (nn - dn < 2 || dn < 2)
 	continue;
 


More information about the gmp-commit mailing list