[Gmp-commit] /home/hgfiles/gmp: Slight reorganization of new mpn_jacobi_base.

mercurial at gmplib.org mercurial at gmplib.org
Thu Mar 11 16:20:21 CET 2010


details:   /home/hgfiles/gmp/rev/9bd5285aaab5
changeset: 13480:9bd5285aaab5
user:      Niels M?ller <nisse at lysator.liu.se>
date:      Thu Mar 11 16:20:16 2010 +0100
description:
Slight reorganization of new mpn_jacobi_base.

diffstat:

 ChangeLog             |   5 +++++
 mpn/generic/jacbase.c |  20 +++++++++++++-------
 2 files changed, 18 insertions(+), 7 deletions(-)

diffs (68 lines):

diff -r 525c5d4a7082 -r 9bd5285aaab5 ChangeLog
--- a/ChangeLog	Thu Mar 11 10:06:57 2010 +0100
+++ b/ChangeLog	Thu Mar 11 16:20:16 2010 +0100
@@ -1,3 +1,8 @@
+2010-03-11  Niels Möller  <nisse at lysator.liu.se>
+
+	* mpn/generic/jacbase.c (mpn_jacobi_base): Reorganized the
+	JACOBI_BASE_METHOD 4 slightly. Now requires that b > 1.
+
 2010-03-11  Torbjorn Granlund  <tege at gmplib.org>
 
 	* doc/gmp.texi (Language Bindings): Update Python site, add Ruby.
diff -r 525c5d4a7082 -r 9bd5285aaab5 mpn/generic/jacbase.c
--- a/mpn/generic/jacbase.c	Thu Mar 11 10:06:57 2010 +0100
+++ b/mpn/generic/jacbase.c	Thu Mar 11 16:20:16 2010 +0100
@@ -169,7 +169,7 @@
 #endif
 
 #if JACOBI_BASE_METHOD == 4
-/* Computes (a/b) for odd b and any a. The initial bit is taken as a
+/* Computes (a/b) for odd b > 1 and any a. The initial bit is taken as a
  * parameter. We have no need for the convention that the sign is in
  * bit 1, internally we use bit 0. */
 
@@ -180,11 +180,12 @@
   int c;
 
   ASSERT (b & 1);
+  ASSERT (b > 1);
 
   if (a == 0)
-    /* Ok, here we use that the sign is bit 1, after all. */
-    return b == 1 ? (1-(bit & 2)) : 0;
-  
+    /* This is the only line which depends on b > 1 */
+    return 0;
+
   bit >>= 1;
 
   /* Below, we represent a and b shifted right so that the least
@@ -199,11 +200,14 @@
   a >>= c;
   a >>= 1;
 
-  while (a != b)
+  do 
     {
       mp_limb_t t = a - b;
       mp_limb_t bgta = LIMB_HIGHBIT_TO_MASK (t);
 
+      if (t == 0)
+	return 0;
+
       /* If b > a, invoke reciprocity */
       bit ^= (bgta & a & b);
       
@@ -220,7 +224,9 @@
       /* (2/b) = -1 if b = 3 or 5 mod 8 */
       bit ^= c & (b ^ (b >> 1));
       a >>= c;
-    }
-  return a == 0 ? 1-2*(bit & 1) : 0;
+    }    
+  while (b > 0);
+
+  return 1-2*(bit & 1);
 }  
 #endif /* JACOBI_BASE_METHOD == 4 */


More information about the gmp-commit mailing list