[Gmp-commit] /var/hg/gmp: Ensure all sizes are seen.

mercurial at gmplib.org mercurial at gmplib.org
Mon Jan 30 16:31:21 CET 2012


details:   /var/hg/gmp/rev/2b74427c67b0
changeset: 14591:2b74427c67b0
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Mon Jan 30 16:30:26 2012 +0100
description:
Ensure all sizes are seen.

diffstat:

 ChangeLog          |   4 ++++
 tests/mpz/t-powm.c |  27 ++++++++++++++++++++++++---
 2 files changed, 28 insertions(+), 3 deletions(-)

diffs (84 lines):

diff -r e4f8d0f38df0 -r 2b74427c67b0 ChangeLog
--- a/ChangeLog	Mon Jan 30 12:04:40 2012 +0100
+++ b/ChangeLog	Mon Jan 30 16:30:26 2012 +0100
@@ -1,3 +1,7 @@
+2012-01-30  Torbjorn Granlund  <tege at gmplib.org>
+
+	* tests/mpz/t-powm.c: Ensure all sizes are seen.
+
 2012-01-30  Marc Glisse  <marc.glisse at inria.fr>
 
 	* gmpxx.h (__gmp_binary_expr): Let things happen in place: d=a+b+c
diff -r e4f8d0f38df0 -r 2b74427c67b0 tests/mpz/t-powm.c
--- a/tests/mpz/t-powm.c	Mon Jan 30 12:04:40 2012 +0100
+++ b/tests/mpz/t-powm.c	Mon Jan 30 16:30:26 2012 +0100
@@ -1,6 +1,6 @@
 /* Test mpz_powm, mpz_mul, mpz_mod, mpz_mod_ui, mpz_div_ui.
 
-Copyright 1991, 1993, 1994, 1996, 1999, 2000, 2001, 2009 Free Software
+Copyright 1991, 1993, 1994, 1996, 1999, 2000, 2001, 2009, 2012 Free Software
 Foundation, Inc.
 
 This file is part of the GNU MP Library.
@@ -20,6 +20,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "gmp.h"
 #include "gmp-impl.h"
@@ -27,6 +28,21 @@
 
 void debug_mp __GMP_PROTO ((mpz_t, int));
 
+#define SIZEM 13
+
+/* Check that all sizes up to just above MUL_TOOM22_THRESHOLD have been tested
+   a few times.  FIXME: If SIZEM is set too low, this will never happen.  */
+int
+allsizes_seen (int *allsizes)
+{
+  mp_size_t i;
+
+  for (i = 1; i < MUL_TOOM22_THRESHOLD + 4; i++)
+    if (allsizes[i] < 4)
+      return 0;
+  return 1;
+}
+
 int
 main (int argc, char **argv)
 {
@@ -38,6 +54,7 @@
   gmp_randstate_ptr rands;
   mpz_t bs;
   unsigned long bsi, size_range;
+  unsigned int allsizes[1 << (SIZEM + 2 - 1)];
 
   tests_start ();
   TESTS_REPS (reps, argv, argc);
@@ -55,10 +72,12 @@
   mpz_init (exp2);
   mpz_init (base2);
 
-  for (i = 0; i < reps; i++)
+  memset (allsizes, 0, (1 << (SIZEM + 2 - 1)) * sizeof (int));
+
+  for (i = 0; i < reps || ! allsizes_seen (allsizes); i++)
     {
       mpz_urandomb (bs, rands, 32);
-      size_range = mpz_get_ui (bs) % 13 + 2;
+      size_range = mpz_get_ui (bs) % SIZEM + 2;
 
       do  /* Loop until mathematically well-defined.  */
 	{
@@ -80,6 +99,8 @@
 	}
       while (mpz_cmp_ui (mod, 0) == 0);
 
+      allsizes[SIZ(mod)] += 1;
+
       mpz_urandomb (bs, rands, 2);
       bsi = mpz_get_ui (bs);
       if ((bsi & 1) != 0)


More information about the gmp-commit mailing list