[Gmp-commit] /var/hg/gmp: Rewrite operand randomisation to use fixed ranges.
mercurial at gmplib.org
mercurial at gmplib.org
Sun Nov 27 17:53:04 UTC 2016
details: /var/hg/gmp/rev/580c088fd836
changeset: 17141:580c088fd836
user: Torbjorn Granlund <tg at gmplib.org>
date: Sun Nov 27 18:51:58 2016 +0100
description:
Rewrite operand randomisation to use fixed ranges.
diffstat:
tests/mpz/reuse.c | 55 ++++++++++++++++++++++++-------------------------------
1 files changed, 24 insertions(+), 31 deletions(-)
diffs (89 lines):
diff -r 3068f1d85563 -r 580c088fd836 tests/mpz/reuse.c
--- a/tests/mpz/reuse.c Sun Nov 27 07:59:15 2016 +0100
+++ b/tests/mpz/reuse.c Sun Nov 27 18:51:58 2016 +0100
@@ -6,7 +6,8 @@
mpz_mul_si
mpz_addmul_ui (should this really allow a+=a*c?)
-Copyright 1996, 1999-2002, 2009, 2012, 2013 Free Software Foundation, Inc.
+Copyright 1996, 1999-2002, 2009, 2012, 2013, 2016 Free Software Foundation,
+Inc.
This file is part of the GNU MP Library test suite.
@@ -200,7 +201,7 @@
main (int argc, char **argv)
{
int i;
- int pass, reps = 400;
+ unsigned int pass, reps = 400;
mpz_t in1, in2, in3;
unsigned long int in2i;
mp_size_t size;
@@ -232,45 +233,37 @@
for (pass = 1; pass <= reps; pass++)
{
+#ifndef VERBOSE
if (isatty (fileno (stdout)))
{
printf ("\r%d/%d passes", pass, reps);
fflush (stdout);
}
+#endif
mpz_urandomb (bs, rands, 32);
- size_range = mpz_get_ui (bs) % 21 + 2;
-
- if ((pass & 1) == 0)
- {
- /* Make all input operands have quite different sizes */
- mpz_urandomb (bs, rands, 32);
- size = mpz_get_ui (bs) % size_range;
- mpz_rrandomb (in1, rands, size);
-
- mpz_urandomb (bs, rands, 32);
- size = mpz_get_ui (bs) % size_range;
- mpz_rrandomb (in2, rands, size);
+ /* Make size_range gradually bigger with each pass. */
+ size_range = mpz_get_ui (bs) % (pass * 15 / reps + 1) + 8;
- mpz_urandomb (bs, rands, 32);
- size = mpz_get_ui (bs) % size_range;
- mpz_rrandomb (in3, rands, size);
- }
- else
- {
- /* Make all input operands have about the same size */
- mpz_urandomb (bs, rands, size_range);
- size = mpz_get_ui (bs);
- mpz_rrandomb (in1, rands, size);
+#define MAKE_RANDOM_OP(in, size_range, s) \
+ do { \
+ mpz_urandomb (bs, rands, size_range); \
+ if (((pass >> s) & 3) == 3) /* conditional exponential dist */ \
+ mpz_urandomb (bs, rands, mpz_get_ui (bs) % (size_range - 7) + 7); \
+ mpz_rrandomb (in, rands, mpz_get_ui (bs)); \
+ } while (0)
- mpz_urandomb (bs, rands, size_range);
- size = mpz_get_ui (bs);
- mpz_rrandomb (in2, rands, size);
+ MAKE_RANDOM_OP (in1, size_range, 0);
+ MAKE_RANDOM_OP (in2, size_range, 2);
+ MAKE_RANDOM_OP (in3, size_range, 4);
+#undef MAKE_RANDOM_OP
- mpz_urandomb (bs, rands, size_range);
- size = mpz_get_ui (bs);
- mpz_rrandomb (in3, rands, size);
- }
+#ifdef VERBOSE
+ printf("%9d%9d%8d\n",
+ mpz_sizeinbase(in1,2),
+ mpz_sizeinbase(in2,2),
+ mpz_sizeinbase(in3,2));
+#endif
mpz_urandomb (bs, rands, 3);
bsi = mpz_get_ui (bs);
More information about the gmp-commit
mailing list