[Gmp-commit] /home/hgfiles/gmp: Rewrite operand generation code.
mercurial at gmplib.org
mercurial at gmplib.org
Sun Jan 3 00:54:33 CET 2010
details: /home/hgfiles/gmp/rev/edfe946a4af6
changeset: 13304:edfe946a4af6
user: Torbjorn Granlund <tege at gmplib.org>
date: Sun Jan 03 00:53:53 2010 +0100
description:
Rewrite operand generation code.
diffstat:
ChangeLog | 4 ++++
tests/mpn/t-bdiv.c | 2 +-
tests/mpn/t-div.c | 51 ++++++++++++++++++++++++++++++++++++---------------
3 files changed, 41 insertions(+), 16 deletions(-)
diffs (119 lines):
diff -r 79782b5e74c8 -r edfe946a4af6 ChangeLog
--- a/ChangeLog Sat Jan 02 23:57:51 2010 +0100
+++ b/ChangeLog Sun Jan 03 00:53:53 2010 +0100
@@ -1,3 +1,7 @@
+2010-01-03 Torbjorn Granlund <tege at gmplib.org>
+
+ * tests/mpn/t-div.c: Rewrite operand generation code.
+
2010-01-02 Torbjorn Granlund <tege at gmplib.org>
* gmp-impl.h (MUL_TO_MULMOD_BNM1_FOR_2NXN_THRESHOLD): Default to
diff -r 79782b5e74c8 -r edfe946a4af6 tests/mpn/t-bdiv.c
--- a/tests/mpn/t-bdiv.c Sat Jan 02 23:57:51 2010 +0100
+++ b/tests/mpn/t-bdiv.c Sun Jan 03 00:53:53 2010 +0100
@@ -83,7 +83,7 @@
cmp = cy != rh || mpn_cmp (tp, np, nn) != 0;
}
else
- cmp = mpn_cmp (tp, np, nn - dn) != 0;
+ cmp = mpn_cmp (tp, np, nn - dn) != 0;
if (cmp != 0)
{
diff -r 79782b5e74c8 -r edfe946a4af6 tests/mpn/t-div.c
--- a/tests/mpn/t-div.c Sat Jan 02 23:57:51 2010 +0100
+++ b/tests/mpn/t-div.c Sun Jan 03 00:53:53 2010 +0100
@@ -140,7 +140,7 @@
{
gmp_randstate_ptr rands;
unsigned long maxnbits, maxdbits, nbits, dbits;
- mpz_t n, d, tz;
+ mpz_t n, d, q, r, tz;
mp_size_t maxnn, maxdn, nn, dn, clearn, i;
mp_ptr np, dp, qp, rp, qrefp, rrefp;
mp_limb_t t;
@@ -172,6 +172,8 @@
mpz_init (n);
mpz_init (d);
+ mpz_init (q);
+ mpz_init (r);
mpz_init (tz);
maxnn = maxnbits / GMP_NUMB_BITS + 1;
@@ -189,11 +191,15 @@
for (test = 0; test < count;)
{
- nbits = random_word (rands) % (maxnbits - GMP_NUMB_BITS) + 2 * GMP_NUMB_BITS;
- if (maxdbits > nbits)
- dbits = random_word (rands) % nbits + 1;
- else
- dbits = random_word (rands) % maxdbits + 1;
+ do
+ {
+ nbits = random_word (rands) % (maxnbits - GMP_NUMB_BITS) + 2 * GMP_NUMB_BITS;
+ if (maxdbits > nbits)
+ dbits = random_word (rands) % nbits + 1;
+ else
+ dbits = random_word (rands) % maxdbits + 1;
+ }
+ while (nbits < dbits);
#if RAND_UNIFORM
#define RANDFUNC mpz_urandomb
@@ -202,22 +208,35 @@
#endif
do
+ RANDFUNC (d, rands, dbits);
+ while (mpz_sgn (d) == 0);
+ dn = SIZ (d);
+ dp = PTR (d);
+ dp[dn - 1] |= GMP_NUMB_HIGHBIT;
+
+ if (test % 2 == 0)
{
RANDFUNC (n, rands, nbits);
+ nn = SIZ (n);
+ ASSERT_ALWAYS (nn >= dn);
+ }
+ else
+ {
do
{
- RANDFUNC (d, rands, dbits);
+ RANDFUNC (q, rands, random_word (rands) % (nbits - dbits + 1));
+ RANDFUNC (r, rands, random_word (rands) % mpz_sizeinbase (d, 2));
+ mpz_mul (n, q, d);
+ mpz_add (n, n, r);
+ nn = SIZ (n);
}
- while (mpz_sgn (d) == 0);
+ while (nn > maxnn || nn < dn);
+ }
- np = PTR (n);
- dp = PTR (d);
- nn = SIZ (n);
- dn = SIZ (d);
- }
- while (nn < dn);
+ ASSERT_ALWAYS (nn <= maxnn);
+ ASSERT_ALWAYS (dn <= maxdn);
- dp[dn - 1] |= GMP_NUMB_HIGHBIT;
+ np = PTR (n);
mpz_urandomb (tz, rands, 32);
t = mpz_get_ui (tz);
@@ -387,6 +406,8 @@
mpz_clear (n);
mpz_clear (d);
+ mpz_clear (q);
+ mpz_clear (r);
mpz_clear (tz);
tests_end ();
More information about the gmp-commit
mailing list