[Gmp-commit] /home/hgfiles/gmp: Simplify loops, indexing.

mercurial at gmplib.org mercurial at gmplib.org
Fri Dec 4 17:20:55 CET 2009


details:   /home/hgfiles/gmp/rev/4100c447728f
changeset: 12976:4100c447728f
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Fri Dec 04 17:20:45 2009 +0100
description:
Simplify loops, indexing.

diffstat:

 ChangeLog                  |   4 ++++
 mpn/generic/sbpi1_bdiv_q.c |  39 +++++++++++++++++++--------------------
 2 files changed, 23 insertions(+), 20 deletions(-)

diffs (70 lines):

diff -r a60282a2d7c3 -r 4100c447728f ChangeLog
--- a/ChangeLog	Thu Dec 03 22:50:45 2009 +0100
+++ b/ChangeLog	Fri Dec 04 17:20:45 2009 +0100
@@ -1,3 +1,7 @@
+2009-12-04  Torbjorn Granlund  <tege at gmplib.org>
+
+	* mpn/generic/sbpi1_bdiv_q.c: Simplify loops, indexing.
+
 2009-12-03  Torbjorn Granlund  <tege at gmplib.org>
 
 	* configure.in: Move intptr_t test into common AC_CHECK_TYPES.
diff -r a60282a2d7c3 -r 4100c447728f mpn/generic/sbpi1_bdiv_q.c
--- a/mpn/generic/sbpi1_bdiv_q.c	Thu Dec 03 22:50:45 2009 +0100
+++ b/mpn/generic/sbpi1_bdiv_q.c	Fri Dec 04 17:20:45 2009 +0100
@@ -53,36 +53,35 @@
 		  mp_limb_t dinv)
 {
   mp_size_t i;
-  mp_limb_t qh;
+  mp_limb_t cy, q;
 
   ASSERT (dn > 0);
   ASSERT (nn >= dn);
   ASSERT ((dp[0] & 1) != 0);
 
-  for (i = 0; i < nn - dn; i++)
+  for (i = nn - dn; i > 0; i--)
     {
-      mp_limb_t cy;
-      mp_limb_t q;
-
-      q = dinv * np[i];
-      qp[i] = ~q;
-      cy = mpn_addmul_1 (np + i, dp, dn, q);
-      mpn_add_1 (np + i + dn, np + i + dn, nn - i - dn, cy);
-      ASSERT (np[i] == 0);
+      q = dinv * np[0];
+      qp[0] = ~q;
+      qp++;
+      cy = mpn_addmul_1 (np, dp, dn, q);
+      mpn_add_1 (np + dn, np + dn, i, cy);
+      ASSERT (np[0] == 0);
+      np++;
     }
 
-  for (; i < nn - 1; i++)
+  for (i = dn; i > 1; i--)
     {
-      mp_limb_t q;
-
-      q = dinv * np[i];
-      qp[i] = ~q;
-      mpn_addmul_1 (np + i, dp, nn - i, q);
-
-      ASSERT (np[i] == 0);
+      q = dinv * np[0];
+      qp[0] = ~q;
+      qp++;
+      mpn_addmul_1 (np, dp, i, q);
+      ASSERT (np[0] == 0);
+      np++;
     }
 
   /* Final limb */
-  qp[nn - 1] = ~(dinv * np[nn - 1]);
-  qh = mpn_add_1 (qp, qp, nn, 1); /* FIXME: can we get carry? */
+  q = dinv * np[0];
+  qp[0] = ~q;
+  mpn_add_1 (qp - nn + 1, qp - nn + 1, nn, 1);
 }


More information about the gmp-commit mailing list