summaryrefslogtreecommitdiff
path: root/tune
diff options
context:
space:
mode:
authorMarco Bodrato <bodrato@mail.dm.unipi.it>2019-11-16 08:19:39 +0100
committerMarco Bodrato <bodrato@mail.dm.unipi.it>2019-11-16 08:19:39 +0100
commit9b59491c1f583db940c0064495672bacc6ca24e7 (patch)
treed1a4faf6d9ab0c9eee25519b1efc464910f63a75 /tune
parentc63a25695be076e90849fda8275295c786c12458 (diff)
downloadgmp-9b59491c1f583db940c0064495672bacc6ca24e7.tar.gz
tune/: tune/speed support for mpz_nextprime (by Seth Troisi)
Diffstat (limited to 'tune')
-rw-r--r--tune/common.c5
-rw-r--r--tune/speed.c3
-rw-r--r--tune/speed.h42
3 files changed, 50 insertions, 0 deletions
diff --git a/tune/common.c b/tune/common.c
index e6f60613b..e803d046e 100644
--- a/tune/common.c
+++ b/tune/common.c
@@ -1763,6 +1763,11 @@ speed_mpn_gcd_22 (struct speed_params *s)
SPEED_ROUTINE_MPN_GCD_22 (mpn_gcd_22);
}
+double
+speed_mpz_nextprime (struct speed_params *s)
+{
+ SPEED_ROUTINE_MPZ_NEXTPRIME (mpz_nextprime);
+}
double
speed_mpz_jacobi (struct speed_params *s)
diff --git a/tune/speed.c b/tune/speed.c
index d6c1d98ab..b9fe23cad 100644
--- a/tune/speed.c
+++ b/tune/speed.c
@@ -313,6 +313,9 @@ const struct routine_t {
#if 0
{ "mpn_gcdext_lehmer", speed_mpn_gcdext_lehmer },
#endif
+
+ { "mpz_nextprime", speed_mpz_nextprime },
+
{ "mpz_jacobi", speed_mpz_jacobi },
{ "mpn_jacobi_base", speed_mpn_jacobi_base },
{ "mpn_jacobi_base_1", speed_mpn_jacobi_base_1 },
diff --git a/tune/speed.h b/tune/speed.h
index 4bc73c9ac..41170e901 100644
--- a/tune/speed.h
+++ b/tune/speed.h
@@ -406,6 +406,7 @@ double speed_mpz_fib_ui (struct speed_params *);
double speed_mpz_fib2_ui (struct speed_params *);
double speed_mpz_init_clear (struct speed_params *);
double speed_mpz_init_realloc_clear (struct speed_params *);
+double speed_mpz_nextprime (struct speed_params *);
double speed_mpz_jacobi (struct speed_params *);
double speed_mpz_lucnum_ui (struct speed_params *);
double speed_mpz_lucnum2_ui (struct speed_params *);
@@ -3162,6 +3163,47 @@ int speed_routine_count_zeros_setup (struct speed_params *, mp_ptr, int, int);
return t; \
}
+/* Calculate nextprime(n) for random n of s->size bits (not limbs). */
+#define SPEED_ROUTINE_MPZ_NEXTPRIME(function) \
+ { \
+ unsigned i, j; \
+ mpz_t wp, n; \
+ double t; \
+ \
+ SPEED_RESTRICT_COND (s->size >= 10); \
+ \
+ mpz_init (wp); \
+ mpz_init_set_n (n, s->xp, s->size); \
+ /* limit to s->size bits, as this function is very slow */ \
+ mpz_tdiv_r_2exp (n, n, s->size); \
+ /* set high bits so operand and result are genaral s->size bits */ \
+ mpz_setbit (n, s->size - 1); \
+ mpz_clrbit (n, s->size - 2); \
+ \
+ speed_starttime (); \
+ i = s->reps; \
+ do \
+ { \
+ /* nextprime timing is variable, so average over many calls */ \
+ j = SPEED_BLOCK_SIZE - 1; \
+ /* starts on random, after measures prime to next prime */ \
+ function (wp, n); \
+ do \
+ { \
+ function (wp, wp); \
+ } \
+ while (--j != 0); \
+ } \
+ while (--i != 0); \
+ t = speed_endtime (); \
+ \
+ mpz_clear (wp); \
+ mpz_clear (n); \
+ \
+ s->time_divisor = SPEED_BLOCK_SIZE; \
+ return t; \
+ }
+
#define SPEED_ROUTINE_MPZ_JACOBI(function) \
{ \
mpz_t a, b; \