[Gmp-commit] /home/hgfiles/gmp: Misc cleanups.

mercurial at gmplib.org mercurial at gmplib.org
Tue Dec 1 18:03:55 CET 2009


details:   /home/hgfiles/gmp/rev/60825eb47636
changeset: 12949:60825eb47636
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Tue Dec 01 18:03:52 2009 +0100
description:
Misc cleanups.

diffstat:

 ChangeLog                  |   3 ++-
 mpn/generic/dcpi1_bdiv_q.c |  50 ++++++++++++++++++++++++++++++++------------------
 2 files changed, 34 insertions(+), 19 deletions(-)

diffs (115 lines):

diff -r 82194081eb2f -r 60825eb47636 ChangeLog
--- a/ChangeLog	Tue Dec 01 17:13:30 2009 +0100
+++ b/ChangeLog	Tue Dec 01 18:03:52 2009 +0100
@@ -4,7 +4,8 @@
 
 2009-12-01  Torbjorn Granlund  <tege at gmplib.org>
 
-	* mpn/generic/dcpi1_bdiv_q.c: Get final mpn_sbpi1_bdiv_q call right.
+	* mpn/generic/dcpi1_bdiv_q.c: Get the mpn_sbpi1_bdiv_q call right.
+	Misc cleanups.
 
 	* tune/speed.c (routine): Fix typo in last change.
 	Add mpn_redc_2.
diff -r 82194081eb2f -r 60825eb47636 mpn/generic/dcpi1_bdiv_q.c
--- a/mpn/generic/dcpi1_bdiv_q.c	Tue Dec 01 17:13:30 2009 +0100
+++ b/mpn/generic/dcpi1_bdiv_q.c	Tue Dec 01 18:03:52 2009 +0100
@@ -28,7 +28,6 @@
 #include "gmp-impl.h"
 
 
-/* Computes Q = N / D mod B^n, destroys N. */
 
 mp_size_t
 mpn_dcpi1_bdiv_q_n_itch (mp_size_t n)
@@ -37,6 +36,12 @@
   return n;
 }
 
+/* Computes Q = N / D mod B^n, destroys N.
+
+   N = {np,n}
+   D = {dp,n}
+*/
+
 void
 mpn_dcpi1_bdiv_q_n (mp_ptr qp,
 		    mp_ptr np, mp_srcptr dp, mp_size_t n,
@@ -44,29 +49,35 @@
 {
   while (ABOVE_THRESHOLD (n, DC_BDIV_Q_THRESHOLD))
     {
-      mp_limb_t l, h;
+      mp_size_t lo, hi;
       mp_limb_t cy;
 
-      l = n >> 1;
-      h = n - l;
+      lo = n >> 1;			/* floor(n/2) */
+      hi = n - lo;			/* ceil(n/2) */
 
-      cy = mpn_dcpi1_bdiv_qr_n (qp, np, dp, l, dinv, tp);
+      cy = mpn_dcpi1_bdiv_qr_n (qp, np, dp, lo, dinv, tp);
 
-      mpn_mullow_n (tp, qp, dp + h, l);
-      mpn_sub_n (np + h, np + h, tp, l);
+      mpn_mullow_n (tp, qp, dp + hi, lo);
+      mpn_sub_n (np + hi, np + hi, tp, lo);
 
-      if (l < h)
+      if (lo < hi)
 	{
-	  cy += mpn_submul_1 (np + l, qp, l, dp[l]);
+	  cy += mpn_submul_1 (np + lo, qp, lo, dp[lo]);
 	  np[n - 1] -= cy;
 	}
-      qp += l;
-      np += l;
-      n -= l;
+      qp += lo;
+      np += lo;
+      n -= lo;
     }
   mpn_sbpi1_bdiv_q (qp, np, n, dp, n, dinv);
 }
 
+/* Computes Q = N / D mod B^nn, destroys N.
+
+   N = {np,nn}
+   D = {dp,dn}
+*/
+
 void
 mpn_dcpi1_bdiv_q (mp_ptr qp,
 		  mp_ptr np, mp_size_t nn,
@@ -80,6 +91,9 @@
 
   TMP_MARK;
 
+  ASSERT (nn >= dn);
+  ASSERT (dn > 0);
+
   tp = TMP_SALLOC_LIMBS (dn);
 
   qn = nn;
@@ -123,14 +137,14 @@
 	}
       mpn_sub_1 (np + dn, np + dn, qn, cy);
       mpn_dcpi1_bdiv_q_n (qp, np, dp, dn, dinv, tp);
-      TMP_FREE;
-      return;
     }
-
-  if (BELOW_THRESHOLD (qn, DC_BDIV_Q_THRESHOLD))
-    mpn_sbpi1_bdiv_q (qp, np, qn, dp, qn, dinv);
   else
-    mpn_dcpi1_bdiv_q_n (qp, np, dp, qn, dinv, tp);
+    {
+      if (BELOW_THRESHOLD (qn, DC_BDIV_Q_THRESHOLD))
+	mpn_sbpi1_bdiv_q (qp, np, qn, dp, qn, dinv);
+      else
+	mpn_dcpi1_bdiv_q_n (qp, np, dp, qn, dinv, tp);
+    }
 
   TMP_FREE;
 }


More information about the gmp-commit mailing list