[Gmp-commit] /home/hgfiles/gmp: 2 new changesets

mercurial at gmplib.org mercurial at gmplib.org
Fri Dec 25 16:26:41 CET 2009


details:   /home/hgfiles/gmp/rev/a99d8a4affd9
changeset: 13218:a99d8a4affd9
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Fri Dec 25 14:49:32 2009 +0100
description:
Fix typo.

details:   /home/hgfiles/gmp/rev/591ffefde19c
changeset: 13219:591ffefde19c
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Fri Dec 25 14:56:48 2009 +0100
description:
Handle 2n/n properly.

diffstat:

 ChangeLog                     |   3 +++
 mpn/generic/dcpi1_divappr_q.c |  26 +++++++++++++++++---------
 mpn/generic/mod_1_2.c         |   2 +-
 mpn/generic/mod_1_3.c         |   2 +-
 mpn/generic/mod_1_4.c         |   2 +-
 5 files changed, 23 insertions(+), 12 deletions(-)

diffs (121 lines):

diff -r 407cbfda4591 -r 591ffefde19c ChangeLog
--- a/ChangeLog	Fri Dec 25 00:37:43 2009 +0100
+++ b/ChangeLog	Fri Dec 25 14:56:48 2009 +0100
@@ -1,5 +1,8 @@
 2009-12-25  Torbjorn Granlund  <tege at gmplib.org>
 
+	* mpn/generic/dcpi1_divappr_q.c: Handle 2n/n properly.  Don't use full
+	precision in mpn_sbpi1_divappr_q call.  Misc cleanup.
+
 	* tune/tuneup.c (tune_mod_1): Add a check_size for
 	PREINV_MOD_1_TO_MOD_1_THRESHOLD.
 
diff -r 407cbfda4591 -r 591ffefde19c mpn/generic/dcpi1_divappr_q.c
--- a/mpn/generic/dcpi1_divappr_q.c	Fri Dec 25 00:37:43 2009 +0100
+++ b/mpn/generic/dcpi1_divappr_q.c	Fri Dec 25 14:56:48 2009 +0100
@@ -86,14 +86,12 @@
   ASSERT (nn > dn);
   ASSERT (dp[dn-1] & GMP_NUMB_HIGHBIT);
 
-  tp = TMP_SALLOC_LIMBS (dn+1);
-
   qn = nn - dn;
   qp += qn;
   np += nn;
   dp += dn;
 
-  if (qn > dn)
+  if (qn >= dn)
     {
       qn++;			/* pretend we'll need an extra limb */
       /* Reduce qn mod dn without division, optimizing small operations.  */
@@ -104,6 +102,8 @@
       qp -= qn;			/* point at low limb of next quotient block */
       np -= qn;			/* point in the middle of partial remainder */
 
+      tp = TMP_SALLOC_LIMBS (dn);
+
       /* Perform the typically smaller block first.  */
       if (qn == 1)
 	{
@@ -206,8 +206,10 @@
       MPN_COPY_INCR (qp, qp + 1, qn);
       qp[qn] = qsave;
     }
-  else
+  else    /* (qn < dn) */
     {
+      mp_ptr q2p;
+#if 0				/* not possible since we demand nn > dn */
       if (qn == 0)
 	{
 	  qh = mpn_cmp (np - dn, dp - dn, dn) >= 0;
@@ -216,21 +218,27 @@
 	  TMP_FREE;
 	  return qh;
 	}
+#endif
 
       qp -= qn;			/* point at low limb of next quotient block */
       np -= qn;			/* point in the middle of partial remainder */
 
+      q2p = TMP_SALLOC_LIMBS (qn + 1);
+      /* Should we at all check DC_DIVAPPR_Q_THRESHOLD here, or reply on
+	 callers not to be silly?  */
       if (BELOW_THRESHOLD (qn, DC_DIVAPPR_Q_THRESHOLD))
-	 /* Full precision.  Optimal?  */
-	qh = mpn_sbpi1_divappr_q (qp, np - dn, nn, dp - dn, dn, dinv->inv32);
+	{
+	  qh = mpn_sbpi1_divappr_q (q2p, np - qn - 2, 2 * (qn + 1),
+				    dp - (qn + 1), qn + 1, dinv->inv32);
+	}
       else
 	{
 	  /* It is tempting to use qp for recursive scratch and put quotient in
 	     tp, but the recursive scratch needs one limb too many.  */
-	  mp_ptr qp2 = TMP_SALLOC_LIMBS (qn + 1);
-	  qh = mpn_dcpi1_divappr_q_n (qp2, np - qn - 2, dp - (qn + 1), qn + 1, dinv, tp);
-	  MPN_COPY (qp, qp2 + 1, qn);
+	  tp = TMP_SALLOC_LIMBS (qn + 1);
+	  qh = mpn_dcpi1_divappr_q_n (q2p, np - qn - 2, dp - (qn + 1), qn + 1, dinv, tp);
 	}
+      MPN_COPY (qp, q2p + 1, qn);
     }
 
   TMP_FREE;
diff -r 407cbfda4591 -r 591ffefde19c mpn/generic/mod_1_2.c
--- a/mpn/generic/mod_1_2.c	Fri Dec 25 00:37:43 2009 +0100
+++ b/mpn/generic/mod_1_2.c	Fri Dec 25 14:56:48 2009 +0100
@@ -36,7 +36,7 @@
   mp_limb_t B1modb, B2modb, B3modb;
   int cnt;
 
-  ASSERT (b <= GMP_LIMB_MAX / 2);
+  ASSERT (b <= (~(mp_limb_t) 0) / 2);
 
   count_leading_zeros (cnt, b);
 
diff -r 407cbfda4591 -r 591ffefde19c mpn/generic/mod_1_3.c
--- a/mpn/generic/mod_1_3.c	Fri Dec 25 00:37:43 2009 +0100
+++ b/mpn/generic/mod_1_3.c	Fri Dec 25 14:56:48 2009 +0100
@@ -36,7 +36,7 @@
   mp_limb_t B1modb, B2modb, B3modb, B4modb;
   int cnt;
 
-  ASSERT (b <= GMP_LIMB_MAX / 3);
+  ASSERT (b <= (~(mp_limb_t) 0) / 3);
 
   count_leading_zeros (cnt, b);
 
diff -r 407cbfda4591 -r 591ffefde19c mpn/generic/mod_1_4.c
--- a/mpn/generic/mod_1_4.c	Fri Dec 25 00:37:43 2009 +0100
+++ b/mpn/generic/mod_1_4.c	Fri Dec 25 14:56:48 2009 +0100
@@ -36,7 +36,7 @@
   mp_limb_t B1modb, B2modb, B3modb, B4modb, B5modb;
   int cnt;
 
-  ASSERT (b <= GMP_LIMB_MAX / 4);
+  ASSERT (b <= (~(mp_limb_t) 0) / 4);
 
   count_leading_zeros (cnt, b);
 


More information about the gmp-commit mailing list