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

mercurial at gmplib.org mercurial at gmplib.org
Thu Nov 29 01:33:41 UTC 2018


details:   /var/hg/gmp/rev/718766ee46d6
changeset: 17716:718766ee46d6
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Nov 28 22:43:27 2018 +0100
description:
mpn/generic/powm.c: Special code for one-limb modulus.

details:   /var/hg/gmp/rev/80949837f4c1
changeset: 17717:80949837f4c1
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Nov 28 23:18:30 2018 +0100
description:
tests/mpz/: Use TESTS_REPS.

diffstat:

 mpn/generic/powm.c      |  43 +++++++++++++++++++++++++++++++++++++++----
 tests/mpz/bit.c         |   3 +--
 tests/mpz/dive_ui.c     |   3 +--
 tests/mpz/io.c          |   3 +--
 tests/mpz/logic.c       |   3 +--
 tests/mpz/t-addsub.c    |   3 +--
 tests/mpz/t-aorsmul.c   |   3 +--
 tests/mpz/t-cdiv_ui.c   |   3 +--
 tests/mpz/t-cong.c      |   3 +--
 tests/mpz/t-div_2exp.c  |   3 +--
 tests/mpz/t-fdiv.c      |   3 +--
 tests/mpz/t-fdiv_ui.c   |   3 +--
 tests/mpz/t-nextprime.c |   3 +--
 tests/mpz/t-perfpow.c   |   4 ++--
 tests/mpz/t-perfsqr.c   |   3 +--
 tests/mpz/t-pow.c       |   3 +--
 tests/mpz/t-remove.c    |   3 +--
 tests/mpz/t-tdiv_ui.c   |   3 +--
 18 files changed, 57 insertions(+), 38 deletions(-)

diffs (truncated from 310 to 300 lines):

diff -r a42aebaf893d -r 80949837f4c1 mpn/generic/powm.c
--- a/mpn/generic/powm.c	Wed Nov 28 21:31:44 2018 +0100
+++ b/mpn/generic/powm.c	Wed Nov 28 23:18:30 2018 +0100
@@ -84,6 +84,20 @@
 #include "gmp-impl.h"
 #include "longlong.h"
 
+#undef MPN_REDC_0
+#define MPN_REDC_0(rp, up, mp, invm)					\
+  do {									\
+    mp_limb_t p1, r0, u0, _dummy;					\
+    u0 = *(up);								\
+    umul_ppmm (p1, _dummy, *(mp), (u0 * (invm)) & GMP_NUMB_MASK);	\
+    ASSERT (((u0 + _dummy) & GMP_NUMB_MASK) == 0);			\
+    p1 += (u0 != 0);							\
+    r0 = (up)[1] + p1;							\
+    if (p1 > r0)							\
+      r0 -= *(mp);							\
+    *(rp) = r0;								\
+  } while (0)
+
 #undef MPN_REDC_1
 #define MPN_REDC_1(rp, up, mp, n, invm)					\
   do {									\
@@ -236,6 +250,11 @@
 
   /* Store b^2 at rp.  */
   mpn_sqr (tp, this_pp, n);
+#if 0
+  if (n == 1) {
+    MPN_REDC_0 (rp, tp, mp, mip[0]);
+  } else
+#endif
 #if WANT_REDC_2
   if (BELOW_THRESHOLD (n, REDC_1_TO_REDC_2_THRESHOLD))
     MPN_REDC_1 (rp, tp, mp, n, mip[0]);
@@ -250,6 +269,13 @@
 
   /* Precompute odd powers of b and put them in the temporary area at pp.  */
   for (i = (1 << (windowsize - 1)) - 1; i > 0; i--)
+#if 1
+    if (n == 1) {
+      umul_ppmm((tp)[1], *(tp), *(this_pp), *(rp));
+      ++this_pp ;
+      MPN_REDC_0 (this_pp, tp, mp, mip[0]);
+    } else
+#endif
     {
       mpn_mul_n (tp, this_pp, rp, n);
       this_pp += n;
@@ -285,8 +311,7 @@
 	{								\
 	  MPN_SQR (tp, rp, n);						\
 	  MPN_REDUCE (rp, tp, mp, n, mip);				\
-	  ebi--;							\
-	  if (ebi == 0)							\
+	  if (--ebi == 0)						\
 	    goto done;							\
 	}								\
 									\
@@ -313,15 +338,25 @@
 	{								\
 	  MPN_SQR (tp, rp, n);						\
 	  MPN_REDUCE (rp, tp, mp, n, mip);				\
-	  this_windowsize--;						\
 	}								\
-      while (this_windowsize != 0);					\
+      while (--this_windowsize != 0);					\
 									\
       MPN_MUL_N (tp, rp, pp + n * (expbits >> 1), n);			\
       MPN_REDUCE (rp, tp, mp, n, mip);					\
     }
 
 
+  if (n == 1)
+    {
+#undef MPN_MUL_N
+#undef MPN_SQR
+#undef MPN_REDUCE
+#define MPN_MUL_N(r,a,b,n)		umul_ppmm((r)[1], *(r), *(a), *(b))
+#define MPN_SQR(r,a,n)			umul_ppmm((r)[1], *(r), *(a), *(a))
+#define MPN_REDUCE(rp,tp,mp,n,mip)	MPN_REDC_0(rp, tp, mp, mip[0])
+      INNERLOOP;
+    }
+  else
 #if WANT_REDC_2
   if (REDC_1_TO_REDC_2_THRESHOLD < MUL_TOOM22_THRESHOLD)
     {
diff -r a42aebaf893d -r 80949837f4c1 tests/mpz/bit.c
--- a/tests/mpz/bit.c	Wed Nov 28 21:31:44 2018 +0100
+++ b/tests/mpz/bit.c	Wed Nov 28 23:18:30 2018 +0100
@@ -289,8 +289,7 @@
   unsigned long int bitindex;
   const char  *s = "";
 
-  if (argc == 2)
-    reps = atoi (argv[1]);
+  TESTS_REPS (reps, argv, argc);
 
   mpz_init (x);
   mpz_init (s0);
diff -r a42aebaf893d -r 80949837f4c1 tests/mpz/dive_ui.c
--- a/tests/mpz/dive_ui.c	Wed Nov 28 21:31:44 2018 +0100
+++ b/tests/mpz/dive_ui.c	Wed Nov 28 23:18:30 2018 +0100
@@ -33,8 +33,7 @@
   int    i, qneg;
   unsigned long  d;
 
-  if (argc == 2)
-    reps = atoi (argv[1]);
+  TESTS_REPS (reps, argv, argc);
 
   mpz_init (a);
   mpz_init (q);
diff -r a42aebaf893d -r 80949837f4c1 tests/mpz/io.c
--- a/tests/mpz/io.c	Wed Nov 28 21:31:44 2018 +0100
+++ b/tests/mpz/io.c	Wed Nov 28 23:18:30 2018 +0100
@@ -55,8 +55,7 @@
 
   mpz_init (bs);
 
-  if (argc == 2)
-    reps = atoi (argv[1]);
+  TESTS_REPS (reps, argv, argc);
 
   mpz_init (op1);
   mpz_init (op2);
diff -r a42aebaf893d -r 80949837f4c1 tests/mpz/logic.c
--- a/tests/mpz/logic.c	Wed Nov 28 21:31:44 2018 +0100
+++ b/tests/mpz/logic.c	Wed Nov 28 23:18:30 2018 +0100
@@ -43,8 +43,7 @@
 
   mpz_init (bs);
 
-  if (argc == 2)
-     reps = atoi (argv[1]);
+  TESTS_REPS (reps, argv, argc);
 
   mpz_init (x);
   mpz_init (y);
diff -r a42aebaf893d -r 80949837f4c1 tests/mpz/t-addsub.c
--- a/tests/mpz/t-addsub.c	Wed Nov 28 21:31:44 2018 +0100
+++ b/tests/mpz/t-addsub.c	Wed Nov 28 23:18:30 2018 +0100
@@ -44,8 +44,7 @@
 
   mpz_init (bs);
 
-  if (argc == 2)
-     reps = atoi (argv[1]);
+  TESTS_REPS (reps, argv, argc);
 
   mpz_init (op1);
   mpz_init (op2);
diff -r a42aebaf893d -r 80949837f4c1 tests/mpz/t-aorsmul.c
--- a/tests/mpz/t-aorsmul.c	Wed Nov 28 21:31:44 2018 +0100
+++ b/tests/mpz/t-aorsmul.c	Wed Nov 28 23:18:30 2018 +0100
@@ -382,8 +382,7 @@
   mpz_init (x);
   mpz_init (y);
 
-  if (argc == 2)
-    reps = atoi (argv[1]);
+  TESTS_REPS (reps, argv, argc);
 
   for (i = 0; i < reps; i++)
     {
diff -r a42aebaf893d -r 80949837f4c1 tests/mpz/t-cdiv_ui.c
--- a/tests/mpz/t-cdiv_ui.c	Wed Nov 28 21:31:44 2018 +0100
+++ b/tests/mpz/t-cdiv_ui.c	Wed Nov 28 23:18:30 2018 +0100
@@ -48,8 +48,7 @@
 
   mpz_init (bs);
 
-  if (argc == 2)
-     reps = atoi (argv[1]);
+  TESTS_REPS (reps, argv, argc);
 
   mpz_init (dividend);
   mpz_init (quotient);
diff -r a42aebaf893d -r 80949837f4c1 tests/mpz/t-cong.c
--- a/tests/mpz/t-cong.c	Wed Nov 28 21:31:44 2018 +0100
+++ b/tests/mpz/t-cong.c	Wed Nov 28 23:18:30 2018 +0100
@@ -141,8 +141,7 @@
   mpz_t bs;
   unsigned long size_range, size;
 
-  if (argc >= 2)
-    reps = atoi (argv[1]);
+  TESTS_REPS (reps, argv, argc);
 
   mpz_init (bs);
 
diff -r a42aebaf893d -r 80949837f4c1 tests/mpz/t-div_2exp.c
--- a/tests/mpz/t-div_2exp.c	Wed Nov 28 21:31:44 2018 +0100
+++ b/tests/mpz/t-div_2exp.c	Wed Nov 28 23:18:30 2018 +0100
@@ -191,8 +191,7 @@
   unsigned long  d;
   int            i;
 
-  if (argc == 2)
-    reps = atoi (argv[1]);
+  TESTS_REPS (reps, argv, argc);
 
   mpz_init (a);
 
diff -r a42aebaf893d -r 80949837f4c1 tests/mpz/t-fdiv.c
--- a/tests/mpz/t-fdiv.c	Wed Nov 28 21:31:44 2018 +0100
+++ b/tests/mpz/t-fdiv.c	Wed Nov 28 23:18:30 2018 +0100
@@ -46,8 +46,7 @@
 
   mpz_init (bs);
 
-  if (argc == 2)
-     reps = atoi (argv[1]);
+  TESTS_REPS (reps, argv, argc);
 
   mpz_init (dividend);
   mpz_init (divisor);
diff -r a42aebaf893d -r 80949837f4c1 tests/mpz/t-fdiv_ui.c
--- a/tests/mpz/t-fdiv_ui.c	Wed Nov 28 21:31:44 2018 +0100
+++ b/tests/mpz/t-fdiv_ui.c	Wed Nov 28 23:18:30 2018 +0100
@@ -48,8 +48,7 @@
 
   mpz_init (bs);
 
-  if (argc == 2)
-     reps = atoi (argv[1]);
+  TESTS_REPS (reps, argv, argc);
 
   mpz_init (dividend);
   mpz_init (quotient);
diff -r a42aebaf893d -r 80949837f4c1 tests/mpz/t-nextprime.c
--- a/tests/mpz/t-nextprime.c	Wed Nov 28 21:31:44 2018 +0100
+++ b/tests/mpz/t-nextprime.c	Wed Nov 28 23:18:30 2018 +0100
@@ -106,8 +106,7 @@
   mpz_init (nxtp);
   mpz_init (ref_nxtp);
 
-  if (argc == 2)
-     reps = atoi (argv[1]);
+  TESTS_REPS (reps, argv, argc);
 
   for (i = 0; i < reps; i++)
     {
diff -r a42aebaf893d -r 80949837f4c1 tests/mpz/t-perfpow.c
--- a/tests/mpz/t-perfpow.c	Wed Nov 28 21:31:44 2018 +0100
+++ b/tests/mpz/t-perfpow.c	Wed Nov 28 23:18:30 2018 +0100
@@ -238,8 +238,8 @@
   check_tests ();
 
   n_tests = 500;
-  if (argc == 2)
-    n_tests = atoi (argv[1]);
+  TESTS_REPS (n_tests, argv, argc);
+
   check_random (n_tests);
 
   tests_end ();
diff -r a42aebaf893d -r 80949837f4c1 tests/mpz/t-perfsqr.c
--- a/tests/mpz/t-perfsqr.c	Wed Nov 28 21:31:44 2018 +0100
+++ b/tests/mpz/t-perfsqr.c	Wed Nov 28 23:18:30 2018 +0100
@@ -143,8 +143,7 @@
   tests_start ();
   mp_trace_base = -16;
 
-  if (argc == 2)
-     reps = atoi (argv[1]);
+  TESTS_REPS (reps, argv, argc);
 
   check_modulo ();
   check_sqrt (reps);
diff -r a42aebaf893d -r 80949837f4c1 tests/mpz/t-pow.c
--- a/tests/mpz/t-pow.c	Wed Nov 28 21:31:44 2018 +0100
+++ b/tests/mpz/t-pow.c	Wed Nov 28 23:18:30 2018 +0100
@@ -206,8 +206,7 @@
   tests_start ();
   mp_trace_base = -16;
 
-  if (argc == 2)
-     reps = atoi (argv[1]);
+  TESTS_REPS (reps, argv, argc);
 
   check_various ();
   check_random (reps);
diff -r a42aebaf893d -r 80949837f4c1 tests/mpz/t-remove.c
--- a/tests/mpz/t-remove.c	Wed Nov 28 21:31:44 2018 +0100
+++ b/tests/mpz/t-remove.c	Wed Nov 28 23:18:30 2018 +0100
@@ -43,8 +43,7 @@
   tests_start ();
   rands = RANDS;
 
-  if (argc == 2)
-    reps = atoi (argv[1]);
+  TESTS_REPS (reps, argv, argc);
 
   mpz_inits (bs, t, dest, refdest, dividend, divisor, NULL);
 
diff -r a42aebaf893d -r 80949837f4c1 tests/mpz/t-tdiv_ui.c
--- a/tests/mpz/t-tdiv_ui.c	Wed Nov 28 21:31:44 2018 +0100
+++ b/tests/mpz/t-tdiv_ui.c	Wed Nov 28 23:18:30 2018 +0100


More information about the gmp-commit mailing list