summaryrefslogtreecommitdiff
path: root/tests/devel
diff options
context:
space:
mode:
authorTorbjorn Granlund <tege@gmplib.org>2011-10-16 15:50:49 +0200
committerTorbjorn Granlund <tege@gmplib.org>2011-10-16 15:50:49 +0200
commit10b35af7f1b1b20973ca12c9fad655902da2938b (patch)
treec88fe71aaaba02e78386f29292c1191da3202e02 /tests/devel
parent23e28626dcc670b12a23d9dc626698ed42a88116 (diff)
downloadgmp-10b35af7f1b1b20973ca12c9fad655902da2938b.tar.gz
Overhaul low-level mpn test code.
Diffstat (limited to 'tests/devel')
-rw-r--r--tests/devel/addmul_N.c34
-rw-r--r--tests/devel/addsub_n.c25
-rw-r--r--tests/devel/anymul_1.c14
-rw-r--r--tests/devel/aors_n.c48
-rw-r--r--tests/devel/copy.c44
-rw-r--r--tests/devel/mul_N.c34
-rw-r--r--tests/devel/shift.c47
7 files changed, 200 insertions, 46 deletions
diff --git a/tests/devel/addmul_N.c b/tests/devel/addmul_N.c
index 435810cd0..39108c6d0 100644
--- a/tests/devel/addmul_N.c
+++ b/tests/devel/addmul_N.c
@@ -1,6 +1,6 @@
/*
-Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2007 Free
-Software Foundation, Inc.
+Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2007 Free Software
+Foundation, Inc.
This file is part of the GNU MP Library.
@@ -49,8 +49,12 @@ cputime ()
}
#endif
+#ifndef NOCHECK
static void print_posneg (mp_limb_t);
+#endif
+#ifdef PRINT
static void mpn_print (mp_ptr, mp_size_t);
+#endif
#define LXW ((int) (2 * sizeof (mp_limb_t)))
#define M * 1000000
@@ -108,10 +112,12 @@ main (int argc, char **argv)
mp_limb_t vp[N];
mp_limb_t cy_ref, cy_try;
int i;
+#if TIMES != 1
long t0, t;
+ double cyc;
+#endif
unsigned test;
mp_size_t size;
- double cyc;
unsigned ntests;
ntests = ~(unsigned) 0;
@@ -129,7 +135,7 @@ main (int argc, char **argv)
#endif
#ifdef RANDOM
- size = random () % SIZE + 1;
+ size = random () % (SIZE - N + 1) + N;
#else
size = SIZE;
#endif
@@ -149,20 +155,26 @@ main (int argc, char **argv)
mpn_addmul_N (ref, up, size, vp);
t = cputime() - t0;
cyc = ((double) t * CLOCK) / (TIMES * size * 1000.0) / N;
- printf ("mpn_addmul_N: %5ldms (%.3f cycles/limb) [%.2f Gb/s]\n",
- t, cyc, CLOCK/cyc*GMP_LIMB_BITS*GMP_LIMB_BITS/1e9);
+ printf ("mpn_addmul_%d: %5ldms (%.3f cycles/limb) [%.2f Gb/s]\n",
+ N, t, cyc, CLOCK/cyc*GMP_LIMB_BITS*GMP_LIMB_BITS/1e9);
+#endif
+
+#ifdef PLAIN_RANDOM
+#define MPN_RANDOM mpn_random
+#else
+#define MPN_RANDOM mpn_random2
#endif
#ifdef ZEROu
MPN_ZERO (up, size);
#else
- mpn_random2 (up, size);
+ MPN_RANDOM (up, size);
#endif
- mpn_random2 (vp, N);
+ MPN_RANDOM (vp, N);
#ifdef ZERO
MPN_ZERO (rp, size + N - 1);
#else
- mpn_random2 (rp, size + N - 1);
+ MPN_RANDOM (rp, size + N - 1);
#endif
#if defined (PRINT) || defined (PRINTV)
@@ -217,6 +229,7 @@ main (int argc, char **argv)
exit (0);
}
+#ifndef NOCHECK
static void
print_posneg (mp_limb_t d)
{
@@ -234,7 +247,9 @@ print_posneg (mp_limb_t d)
printf ("%*s+%s", LXW - (int) strlen (buf), "", buf);
}
}
+#endif
+#ifdef PRINT
static void
mpn_print (mp_ptr p, mp_size_t size)
{
@@ -256,3 +271,4 @@ mpn_print (mp_ptr p, mp_size_t size)
}
puts ("");
}
+#endif
diff --git a/tests/devel/addsub_n.c b/tests/devel/addsub_n.c
index e00bcba19..f6315b7a2 100644
--- a/tests/devel/addsub_n.c
+++ b/tests/devel/addsub_n.c
@@ -149,10 +149,10 @@ main (int argc, char **argv)
cyx = refmpn_add_n_sub_n (d1x+1, d2x+1, s1, s2, size);
cyy = mpn_add_n_sub_n (d1y+1, d2y+1, s1, s2, size);
#ifdef PRINT
- printf ("%d ", cyx); mpn_print (d1x+1, size);
- printf ("%d ", cyx); mpn_print (d2x+1, size);
- printf ("%d ", cyy); mpn_print (d1y+1, size);
- printf ("%d ", cyy); mpn_print (d2y+1, size);
+ printf ("ref add %d ", cyx); mpn_print (d1x+1, size);
+ printf (" add %d ", cyy); mpn_print (d1y+1, size);
+ printf ("ref sub %d ", cyx); mpn_print (d2x+1, size);
+ printf (" sub %d ", cyy); mpn_print (d2y+1, size);
#endif
if (cyx != cyy
|| mpn_cmp (d1x, d1y, size+2) != 0
@@ -161,11 +161,20 @@ main (int argc, char **argv)
|| d2x[0] != 0x87654321 || d2x[size+1] != 0x12345678)
{
#ifndef PRINT
- printf ("%d ", cyx); mpn_print (d1x+1, size);
- printf ("%d ", cyx); mpn_print (d2x+1, size);
- printf ("%d ", cyy); mpn_print (d1y+1, size);
- printf ("%d ", cyy); mpn_print (d2y+1, size);
+ printf ("ref add %d ", cyx); mpn_print (d1x+1, size);
+ printf (" add %d ", cyy); mpn_print (d1y+1, size);
+ printf ("ref sub %d ", cyx); mpn_print (d2x+1, size);
+ printf (" sub %d ", cyy); mpn_print (d2y+1, size);
#endif
+ printf ("\n");
+ if (d1y[0] != 0x87654321)
+ printf ("add clobbered at low end\n");
+ if (d1y[size+1] != 0x12345678)
+ printf ("add clobbered at high end\n");
+ if (d2y[0] != 0x87654321)
+ printf ("sub clobbered at low end\n");
+ if (d2y[size+1] != 0x12345678)
+ printf ("sub clobbered at high end\n");
printf ("TEST NUMBER %d\n", test);
abort();
}
diff --git a/tests/devel/anymul_1.c b/tests/devel/anymul_1.c
index 27a1a7464..81c55e240 100644
--- a/tests/devel/anymul_1.c
+++ b/tests/devel/anymul_1.c
@@ -23,7 +23,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
-#include "tests.h"
+#include "tests/tests.h"
#ifdef OPERATION_mul_1
#define func __gmpn_mul_1
@@ -120,6 +120,12 @@ main (int argc, char **argv)
}
#endif
+#ifdef PLAIN_RANDOM
+#define MPN_RANDOM mpn_random
+#else
+#define MPN_RANDOM mpn_random2
+#endif
+
#ifdef RANDOM
size = random () % SIZE + 1;
#else
@@ -132,7 +138,7 @@ main (int argc, char **argv)
#ifdef FIXED_XLIMB
xlimb = FIXED_XLIMB;
#else
- mpn_random2 (&xlimb, 1);
+ MPN_RANDOM (&xlimb, 1);
#endif
#if TIMES != 1
@@ -151,11 +157,11 @@ main (int argc, char **argv)
#endif
#ifndef NOCHECK
- mpn_random2 (s1, size);
+ MPN_RANDOM (s1, size);
#ifdef ZERO
memset (rp, 0, size * sizeof *rp);
#else
- mpn_random2 (rp, size);
+ MPN_RANDOM (rp, size);
#endif
#if defined (PRINT) || defined (XPRINT)
printf ("xlimb=");
diff --git a/tests/devel/aors_n.c b/tests/devel/aors_n.c
index 99069f2ed..c6a871b5d 100644
--- a/tests/devel/aors_n.c
+++ b/tests/devel/aors_n.c
@@ -1,5 +1,5 @@
/*
-Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009
+Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009, 2011
Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -18,6 +18,7 @@ You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
#include <stdlib.h>
+#include <string.h>
#include <stdio.h>
#include "gmp.h"
#include "gmp-impl.h"
@@ -84,8 +85,10 @@ cputime ()
}
#endif
+static void print_posneg (mp_limb_t);
static void mpn_print (mp_ptr, mp_size_t);
+#define LXW ((int) (2 * sizeof (mp_limb_t)))
#define M * 1000000
#ifndef CLOCK
@@ -186,11 +189,26 @@ main (int argc, char **argv)
if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0
|| dx[0] != 0x87654321 || dx[size+1] != 0x12345678)
{
+ mp_size_t s, e;
+ for (s = 0;; s++)
+ if ((unsigned long long) (dx+1)[s] != (unsigned long long) (dy+1)[s])
+ break;
+ for (e = size - 1;; e--)
+ if ((unsigned long long) (dx+1)[e] != (unsigned long long) (dy+1)[e])
+ break;
#ifndef PRINT
- mpn_print (&cyx, 1);
- mpn_print (dx+1, size);
- mpn_print (&cyy, 1);
- mpn_print (dy+1, size);
+ for (i = s; i <= e; i++)
+ {
+ printf ("%6d: ", i);
+ printf ("%0*llX ", LXW, (unsigned long long) (dx+1)[i]);
+ printf ("%0*llX ", LXW, (unsigned long long) (dy+1)[i]);
+ print_posneg ((dy+1)[i] - (dx+1)[i]);
+ printf ("\n");
+ }
+ printf ("%6s: ", "retval");
+ printf ("%0*llX ", LXW, (unsigned long long) cyx);
+ printf ("%0*llX ", LXW, (unsigned long long) cyy);
+ print_posneg (cyx - cyy);
#endif
printf ("\n");
if (dy[0] != 0x87654321)
@@ -206,6 +224,24 @@ main (int argc, char **argv)
}
static void
+print_posneg (mp_limb_t d)
+{
+ char buf[LXW + 2];
+ if (d == 0)
+ printf (" %*X", LXW, 0);
+ else if (-d < d)
+ {
+ sprintf (buf, "%llX", (unsigned long long) -d);
+ printf ("%*s-%s", LXW - (int) strlen (buf), "", buf);
+ }
+ else
+ {
+ sprintf (buf, "%llX", (unsigned long long) d);
+ printf ("%*s+%s", LXW - (int) strlen (buf), "", buf);
+ }
+}
+
+static void
mpn_print (mp_ptr p, mp_size_t size)
{
mp_size_t i;
@@ -215,7 +251,7 @@ mpn_print (mp_ptr p, mp_size_t size)
#ifdef _LONG_LONG_LIMB
printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)),
(unsigned long) (p[i] >> (GMP_LIMB_BITS/2)),
- (int) (sizeof(mp_limb_t)), (unsigned long) (p[i]));
+ (int) (sizeof(mp_limb_t)), (unsigned long) (p[i]));
#else
printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]);
#endif
diff --git a/tests/devel/copy.c b/tests/devel/copy.c
index d8cbbd968..c925b72d2 100644
--- a/tests/devel/copy.c
+++ b/tests/devel/copy.c
@@ -1,5 +1,5 @@
/*
-Copyright 1999, 2000, 2001, 2004, 2009 Free Software Foundation, Inc.
+Copyright 1999, 2000, 2001, 2004, 2009, 2011 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -17,6 +17,7 @@ You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
#include <stdlib.h>
+#include <string.h>
#include <stdio.h>
#include "gmp.h"
#include "gmp-impl.h"
@@ -59,8 +60,10 @@ cputime ()
}
#endif
+static void print_posneg (mp_limb_t);
static void mpn_print (mp_ptr, mp_size_t);
+#define LXW ((int) (2 * sizeof (mp_limb_t)))
#define M * 1000000
#ifndef CLOCK
@@ -68,7 +71,7 @@ static void mpn_print (mp_ptr, mp_size_t);
#endif
#ifndef OPS
-#define OPS (CLOCK/2)
+#define OPS (CLOCK/5)
#endif
#ifndef SIZE
#define SIZE 496
@@ -152,9 +155,22 @@ main (int argc, char **argv)
if (mpn_cmp (dx, dy, size+2) != 0
|| dx[0] != 0x87654321 || dx[size+1] != 0x12345678)
{
+ mp_size_t s, e;
+ for (s = 0;; s++)
+ if ((unsigned long long) (dx+1)[s] != (unsigned long long) (dy+1)[s])
+ break;
+ for (e = size - 1;; e--)
+ if ((unsigned long long) (dx+1)[e] != (unsigned long long) (dy+1)[e])
+ break;
#ifndef PRINT
- mpn_print (dx+1, size);
- mpn_print (dy+1, size);
+ for (i = s; i <= e; i++)
+ {
+ printf ("%6d: ", i);
+ printf ("%0*llX ", LXW, (unsigned long long) (dx+1)[i]);
+ printf ("%0*llX ", LXW, (unsigned long long) (dy+1)[i]);
+ print_posneg ((dy+1)[i] - (dx+1)[i]);
+ printf ("\n");
+ }
#endif
printf ("\n");
if (dy[0] != 0x87654321)
@@ -170,6 +186,24 @@ main (int argc, char **argv)
}
static void
+print_posneg (mp_limb_t d)
+{
+ char buf[LXW + 2];
+ if (d == 0)
+ printf (" %*X", LXW, 0);
+ else if (-d < d)
+ {
+ sprintf (buf, "%llX", (unsigned long long) -d);
+ printf ("%*s-%s", LXW - (int) strlen (buf), "", buf);
+ }
+ else
+ {
+ sprintf (buf, "%llX", (unsigned long long) d);
+ printf ("%*s+%s", LXW - (int) strlen (buf), "", buf);
+ }
+}
+
+static void
mpn_print (mp_ptr p, mp_size_t size)
{
mp_size_t i;
@@ -179,7 +213,7 @@ mpn_print (mp_ptr p, mp_size_t size)
#ifdef _LONG_LONG_LIMB
printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)),
(unsigned long) (p[i] >> (GMP_LIMB_BITS/2)),
- (int) (sizeof(mp_limb_t)), (unsigned long) (p[i]));
+ (int) (sizeof(mp_limb_t)), (unsigned long) (p[i]));
#else
printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]);
#endif
diff --git a/tests/devel/mul_N.c b/tests/devel/mul_N.c
index cd33b5a0f..44a02decb 100644
--- a/tests/devel/mul_N.c
+++ b/tests/devel/mul_N.c
@@ -49,8 +49,12 @@ cputime ()
}
#endif
+#ifndef NOCHECK
static void print_posneg (mp_limb_t);
+#endif
+#ifdef PRINT
static void mpn_print (mp_ptr, mp_size_t);
+#endif
#define LXW ((int) (2 * sizeof (mp_limb_t)))
#define M * 1000000
@@ -111,10 +115,12 @@ main (int argc, char **argv)
mp_limb_t vp[N];
mp_limb_t cy_ref, cy_try;
int i;
+#if TIMES != 1
long t0, t;
+ double cyc;
+#endif
unsigned test;
mp_size_t size;
- double cyc;
unsigned ntests;
ntests = ~(unsigned) 0;
@@ -132,7 +138,7 @@ main (int argc, char **argv)
#endif
#ifdef RANDOM
- size = random () % SIZE + 1;
+ size = random () % (SIZE - N + 1) + N;
#else
size = SIZE;
#endif
@@ -151,17 +157,24 @@ main (int argc, char **argv)
mpn_mul_N (ref, up, size, vp);
t = cputime() - t0;
cyc = ((double) t * CLOCK) / (TIMES * size * 1000.0) / N;
- printf ("mpn_mul_N: %5ldms (%.3f cycles/limb) [%.2f Gb/s]\n",
- t, cyc, CLOCK/cyc*GMP_LIMB_BITS*GMP_LIMB_BITS/1e9);
+ printf ("mpn_mul_%d: %5ldms (%.3f cycles/limb) [%.2f Gb/s]\n",
+ N, t, cyc, CLOCK/cyc*GMP_LIMB_BITS*GMP_LIMB_BITS/1e9);
+#endif
+
+#ifdef PLAIN_RANDOM
+#define MPN_RANDOM mpn_random
+#else
+#define MPN_RANDOM mpn_random2
#endif
#ifdef ZEROu
MPN_ZERO (up, size);
#else
- mpn_random2 (up, size);
+ MPN_RANDOM (up, size);
#endif
- mpn_random2 (vp, N);
- mpn_random2 (rp, size + N - 1);
+ MPN_RANDOM (vp, N);
+ /* vp[0] = vp[1] = vp[2] = vp[3] = vp[4] = vp[5] = 0; */
+ MPN_RANDOM (rp, size + N - 1);
#if defined (PRINT) || defined (PRINTV)
printf ("vp=");
@@ -169,8 +182,6 @@ main (int argc, char **argv)
#endif
#ifdef PRINT
printf ("%*s ", 3 + N * LXW, "");
- mpn_print (rp, size);
- printf ("%*s ", 3 + N * LXW, "");
mpn_print (up, size);
#endif
@@ -187,6 +198,7 @@ main (int argc, char **argv)
#ifndef NOCHECK
if (cy_ref != cy_try || mpn_cmp (ref, rp, size + N - 1) != 0
+// if (cy_ref != cy_try || mpn_cmp (ref + 5, rp + 5, size + N - 1 - 6) != 0
|| rp[size + N - 1] != 0x12345678 || rp[-1] != 0x87654321)
{
printf ("\n ref%*s try%*s diff\n", LXW - 3, "", 2 * LXW - 6, "");
@@ -215,6 +227,7 @@ main (int argc, char **argv)
exit (0);
}
+#ifndef NOCHECK
static void
print_posneg (mp_limb_t d)
{
@@ -232,7 +245,9 @@ print_posneg (mp_limb_t d)
printf ("%*s+%s", LXW - (int) strlen (buf), "", buf);
}
}
+#endif
+#ifdef PRINT
static void
mpn_print (mp_ptr p, mp_size_t size)
{
@@ -254,3 +269,4 @@ mpn_print (mp_ptr p, mp_size_t size)
}
puts ("");
}
+#endif
diff --git a/tests/devel/shift.c b/tests/devel/shift.c
index 089edd3ac..5561c1349 100644
--- a/tests/devel/shift.c
+++ b/tests/devel/shift.c
@@ -1,5 +1,5 @@
/*
-Copyright 1996, 1998, 1999, 2000, 2001, 2004, 2007, 2009 Free Software
+Copyright 1996, 1998, 1999, 2000, 2001, 2004, 2007, 2009, 2011 Free Software
Foundation, Inc.
This file is part of the GNU MP Library.
@@ -18,6 +18,7 @@ You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
#include <stdlib.h>
+#include <string.h>
#include <stdio.h>
#include "gmp.h"
#include "gmp-impl.h"
@@ -60,8 +61,10 @@ cputime ()
}
#endif
+static void print_posneg (mp_limb_t);
static void mpn_print (mp_ptr, mp_size_t);
+#define LXW ((int) (2 * sizeof (mp_limb_t)))
#define M * 1000000
#ifndef CLOCK
@@ -166,11 +169,27 @@ main (int argc, char **argv)
if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0
|| dx[0] != 0x87654321 || dx[size+1] != 0x12345678)
{
+ mp_size_t s, e;
+ for (s = 0;; s++)
+ if ((unsigned long long) (dx+1)[s] != (unsigned long long) (dy+1)[s])
+ break;
+ for (e = size - 1;; e--)
+ if ((unsigned long long) (dx+1)[e] != (unsigned long long) (dy+1)[e])
+ break;
#ifndef PRINT
- mpn_print (&cyx, 1);
- mpn_print (dx+1, size);
- mpn_print (&cyy, 1);
- mpn_print (dy+1, size);
+ printf ("cnt=%-*d\n", (int) (2 * sizeof(mp_limb_t)) - 4, cnt);
+ for (i = s; i <= e; i++)
+ {
+ printf ("%6d: ", i);
+ printf ("%0*llX ", LXW, (unsigned long long) (dx+1)[i]);
+ printf ("%0*llX ", LXW, (unsigned long long) (dy+1)[i]);
+ print_posneg ((dy+1)[i] - (dx+1)[i]);
+ printf ("\n");
+ }
+ printf ("%6s: ", "retval");
+ printf ("%0*llX ", LXW, (unsigned long long) cyx);
+ printf ("%0*llX ", LXW, (unsigned long long) cyy);
+ print_posneg (cyx - cyy);
#endif
printf ("\n");
if (dy[0] != 0x87654321)
@@ -186,6 +205,24 @@ main (int argc, char **argv)
}
static void
+print_posneg (mp_limb_t d)
+{
+ char buf[LXW + 2];
+ if (d == 0)
+ printf (" %*X", LXW, 0);
+ else if (-d < d)
+ {
+ sprintf (buf, "%llX", (unsigned long long) -d);
+ printf ("%*s-%s", LXW - (int) strlen (buf), "", buf);
+ }
+ else
+ {
+ sprintf (buf, "%llX", (unsigned long long) d);
+ printf ("%*s+%s", LXW - (int) strlen (buf), "", buf);
+ }
+}
+
+static void
mpn_print (mp_ptr p, mp_size_t size)
{
mp_size_t i;