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

mercurial at gmplib.org mercurial at gmplib.org
Sat Oct 17 10:03:13 UTC 2020


details:   /var/hg/gmp/rev/48e192069210
changeset: 18094:48e192069210
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Oct 17 11:54:35 2020 +0200
description:
Better support for make check-mini-gmp on wine or cygwin (from Niels)

details:   /var/hg/gmp/rev/ec265ced5f9d
changeset: 18095:ec265ced5f9d
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Oct 17 11:55:31 2020 +0200
description:
bootstrap.c (mpz_invert_2exp): Simplify.

details:   /var/hg/gmp/rev/d186cc86bc60
changeset: 18096:d186cc86bc60
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Oct 17 12:02:59 2020 +0200
description:
mpz/stronglucas.c (mpz_oddjacobi_ui): New helper function.

diffstat:

 Makefile.am              |   2 +-
 bootstrap.c              |  25 +++++----------------
 mini-gmp/tests/run-tests |  30 ++++++++++++++++---------
 mpz/stronglucas.c        |  57 ++++++++++++++++++++++++++++++++---------------
 4 files changed, 65 insertions(+), 49 deletions(-)

diffs (235 lines):

diff -r 67331aac1932 -r d186cc86bc60 Makefile.am
--- a/Makefile.am	Thu Oct 15 23:51:15 2020 +0200
+++ b/Makefile.am	Sat Oct 17 12:02:59 2020 +0200
@@ -436,7 +436,7 @@
 	abs_srcdir="`cd $(srcdir) && pwd`" ; \
 	$(MKDIR_P) mini-gmp/tests \
 	&& cd mini-gmp/tests \
-	&& TEST_LIBRARY_PATH="../../.libs"  \
+	&& TEST_SHLIB_DIR="${abs_top_builddir}/.libs" \
 	   $(MAKE) -f "$$abs_srcdir/mini-gmp/tests/Makefile" \
 		VPATH="$$abs_srcdir/mini-gmp/tests" \
 		srcdir="$$abs_srcdir/mini-gmp/tests" \
diff -r 67331aac1932 -r d186cc86bc60 bootstrap.c
--- a/bootstrap.c	Thu Oct 15 23:51:15 2020 +0200
+++ b/bootstrap.c	Sat Oct 17 12:02:59 2020 +0200
@@ -105,33 +105,20 @@
   mpz_clear (t);
 }
 
-/* Calculate r satisfying r*d == 1 mod 2^n. */
+/* Calculate r satisfying r*a == 1 mod 2^n. */
 void
 mpz_invert_2exp (mpz_t r, const mpz_t a, unsigned long n)
 {
-  unsigned long  i;
-  mpz_t  inv, prod;
+  mpz_t  mod;
 
   assert (mpz_odd_p (a));
 
-  mpz_init_set_ui (inv, 1L);
-  mpz_init (prod);
+  mpz_init (mod);
+  mpz_setbit (mod, n);
 
-  for (i = 1; i < n; i++)
-    {
-      mpz_mul (prod, inv, a);
-      if (mpz_tstbit (prod, i) != 0)
-	mpz_setbit (inv, i);
-    }
+  mpz_invert (r, a, mod);
 
-  mpz_mul (prod, inv, a);
-  mpz_tdiv_r_2exp (prod, prod, n);
-  assert (mpz_cmp_ui (prod, 1L) == 0);
-
-  mpz_set (r, inv);
-
-  mpz_clear (inv);
-  mpz_clear (prod);
+  mpz_clear (mod);
 }
 
 /* Calculate inv satisfying r*a == 1 mod 2^n. */
diff -r 67331aac1932 -r d186cc86bc60 mini-gmp/tests/run-tests
--- a/mini-gmp/tests/run-tests	Thu Oct 15 23:51:15 2020 +0200
+++ b/mini-gmp/tests/run-tests	Sat Oct 17 12:02:59 2020 +0200
@@ -1,6 +1,6 @@
 #! /bin/sh
 
-# Copyright (C) 2000-2002, 2004, 2005, 2011, 2012, 2016  Niels Möller
+# Copyright (C) 2000-2002, 2004, 2005, 2011, 2012, 2016, 2020  Niels Möller
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -28,6 +28,22 @@
 
 export srcdir
 
+if [ -n "$TEST_SHLIB_DIR" ] ; then
+  # Prepend to LD_LIBRARY_PATH, if it is alredy set.
+  LD_LIBRARY_PATH="${TEST_SHLIB_DIR}${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
+  # For MACOS
+  DYLD_LIBRARY_PATH="$TEST_SHLIB_DIR"
+  # For Windows
+  PATH="${TEST_SHLIB_DIR}:${PATH}"
+  # For Wine
+  WINEPATH="${TEST_SHLIB_DIR}"
+
+  export LD_LIBRARY_PATH
+  export DYLD_LIBRARY_PATH
+  export PATH
+  export WINEPATH
+fi
+
 # When used in make rules, we sometimes get the filenames VPATH
 # expanded, but usually not.
 find_program () {
@@ -38,6 +54,8 @@
 	*)
 	  if [ -x "$1" ] ; then
 	      echo "./$1"
+	  elif [ -x "$1.exe" ] ; then
+	      echo "./$1.exe"
 	  else
 	      echo "$srcdir/$1"
 	  fi
@@ -54,20 +72,10 @@
   fi
 }
 
-TEST_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
-TEST_DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH"
-
-if [ "$TEST_LIBRARY_PATH" ] ; then
-  TEST_LD_LIBRARY_PATH="$TEST_LIBRARY_PATH:$TEST_LD_LIBRARY_PATH"
-  TEST_DYLD_LIBRARY_PATH="$TEST_LIBRARY_PATH:$TEST_DYLD_LIBRARY_PATH"
-fi
-
 test_program () {
   testname=`basename "$1" .exe`
   testname=`basename "$testname" -test`
   if [ -z "$EMULATOR" ] || head -1 "$1" | grep '^#!' > /dev/null; then
-    LD_LIBRARY_PATH="$TEST_LD_LIBRARY_PATH" \
-    DYLD_LIBRARY_PATH="$TEST_DYLD_LIBRARY_PATH" \
     "$1" $testflags
   else
     $EMULATOR "$1" $testflags
diff -r 67331aac1932 -r d186cc86bc60 mpz/stronglucas.c
--- a/mpz/stronglucas.c	Thu Oct 15 23:51:15 2020 +0200
+++ b/mpz/stronglucas.c	Sat Oct 17 12:02:59 2020 +0200
@@ -55,6 +55,26 @@
   return ((CNST_LIMB(1) << s) + (x >> s)) >> 1;
 }
 
+static int
+mpz_oddjacobi_ui (mpz_t b, mp_limb_t a)
+{
+  mp_limb_t  b_rem;
+  int        result_bit1;
+
+  ASSERT (a & 1);
+  ASSERT (a > 1);
+  ASSERT (SIZ (b) > 0);
+  ASSERT ((*PTR (b) & 1) == 1);
+
+  result_bit1 = 0;
+  JACOBI_MOD_OR_MODEXACT_1_ODD (result_bit1, b_rem, PTR (b), SIZ (b), a);
+  if (UNLIKELY (b_rem == 0))
+    return 0;
+  else
+    return mpn_jacobi_base (b_rem, a, result_bit1);
+}
+
+
 /* Performs strong Lucas' test on x, with parameters suggested */
 /* for the BPSW test. Qk and V are passed to recycle variables. */
 /* Requires GCD (x,6) = 1.*/
@@ -64,6 +84,7 @@
   mp_bitcnt_t b0;
   mpz_t n;
   mp_limb_t D; /* The absolute value is stored. */
+  mp_limb_t g;
   long Q;
   mpz_t T1, T2;
 
@@ -74,25 +95,25 @@
   /* ASSERT (mpz_gcd_ui (NULL, n, 6) == 1);	*/
 #if GMP_NUMB_BITS % 16 == 0
   /* (2^12 - 1) | (2^{GMP_NUMB_BITS*3/4} - 1)	*/
-  D = mpn_mod_34lsub1 (PTR (n), SIZ (n));
+  g = mpn_mod_34lsub1 (PTR (n), SIZ (n));
   /* (2^12 - 1) = 3^2 * 5 * 7 * 13		*/
-  ASSERT (D % 3 != 0 && D % 5 != 0 && D % 7 != 0);
-  if ((D % 5 & 2) != 0)
+  ASSERT (g % 3 != 0 && g % 5 != 0 && g % 7 != 0);
+  if ((g % 5 & 2) != 0)
     /* (5/n) = -1, iff n = 2 or 3 (mod 5)	*/
     /* D = 5; Q = -1 */
     return mpn_strongfibo (PTR (n), SIZ (n), PTR (V));
-  else if (! POW2_P (D % 7))
+  else if (! POW2_P (g % 7))
     /* (-7/n) = -1, iff n = 3,5 or 6 (mod 7)	*/
     D = 7; /* Q = 2 */
     /* (9/n) = -1, never: 9 = 3^2	*/
-  else if (mpz_kronecker_ui (n, 11) == -1)
+  else if (mpz_oddjacobi_ui (n, 11) == -1)
     /* (-11/n) = (n/11)	*/
     D = 11; /* Q = 3 */
-  else if ((((D % 13 - (D % 13 >> 3)) & 7) > 4) ||
-	   (((D % 13 - (D % 13 >> 3)) & 7) == 2))
+  else if ((((g % 13 - (g % 13 >> 3)) & 7) > 4) ||
+	   (((g % 13 - (g % 13 >> 3)) & 7) == 2))
     /* (13/n) = -1, iff n = 2,5,6,7,8 or 11 (mod 13)	*/
     D = 13; /* Q = -3 */
-  else if (D % 3 == 2)
+  else if (g % 3 == 2)
     /* (-15/n) = (n/15) = (n/5)*(n/3)	*/
     /* Here, (n/5) = 1, and		*/
     /* (n/3) = -1, iff n = 2 (mod 3)	*/
@@ -100,20 +121,20 @@
 #if GMP_NUMB_BITS % 32 == 0
   /* (2^24 - 1) | (2^{GMP_NUMB_BITS*3/4} - 1)	*/
   /* (2^24 - 1) = (2^12 - 1) * 17 * 241		*/
-  else if (! POW2_P (D % 17) && ! POW2_P (17 - D % 17))
+  else if (! POW2_P (g % 17) && ! POW2_P (17 - g % 17))
     D = 17; /* Q = -4 */
 #endif
 #else
-  if (mpz_kronecker_ui (n, 5) == -1)
+  if (mpz_oddjacobi_ui (n, 5) == -1)
     return mpn_strongfibo (PTR (n), SIZ (n), PTR (V));
 #endif
   else
   {
-    mp_limb_t tl;
     mp_limb_t maxD;
-    int jac_bit1;
+    int jac;
 
-    if (UNLIKELY (mpz_perfect_square_p (n)))
+    /* n is odd, to possibly be a square, n % 8 = 1 is needed. */
+    if (((*PTR (n) & 6) == 0) && UNLIKELY (mpz_perfect_square_p (n)))
       return 0; /* A square is composite. */
 
     /* Check Ds up to square root (in case, n is prime)
@@ -137,12 +158,12 @@
 	if (UNLIKELY (D >= maxD))
 	  return 1;
 	D += 2;
-	jac_bit1 = 0;
-	JACOBI_MOD_OR_MODEXACT_1_ODD (jac_bit1, tl, PTR (n), SIZ (n), D);
-	if (UNLIKELY (tl == 0))
-	  return 0;
+	jac = mpz_oddjacobi_ui (n, D);
       }
-    while (mpn_jacobi_base (tl, D, jac_bit1) == 1);
+    while (jac == 1);
+
+    if (UNLIKELY (jac == 0))
+      return 0;
   }
 
   /* D= P^2 - 4Q; P = 1; Q = (1-D)/4 */



More information about the gmp-commit mailing list