summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authortege <tege@gmplib.org>2004-10-10 03:33:35 +0200
committertege <tege@gmplib.org>2004-10-10 03:33:35 +0200
commitdc52c66b15414f54facfd233d0e0bb4399b047dd (patch)
tree23d5a2d287df7ba83ba75190923d283024fd63c5 /tests
parent2061a15dc1d4d2b796e8af21b8f67e72de4fa0be (diff)
downloadgmp-dc52c66b15414f54facfd233d0e0bb4399b047dd.tar.gz
Handle both MPN_COPY_INCR and MPN_COPY_DECR.
Diffstat (limited to 'tests')
-rw-r--r--tests/devel/copy.c98
1 files changed, 49 insertions, 49 deletions
diff --git a/tests/devel/copy.c b/tests/devel/copy.c
index d4defde48..df4f76834 100644
--- a/tests/devel/copy.c
+++ b/tests/devel/copy.c
@@ -1,5 +1,5 @@
/*
-Copyright 1999, 2000 Free Software Foundation, Inc.
+Copyright 1999, 2000, 2001, 2004 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -19,10 +19,23 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
*/
+#include <stdlib.h>
#include <stdio.h>
#include "gmp.h"
#include "gmp-impl.h"
+#ifdef OPERATION_copyi
+#define func MPN_COPY_INCR
+#define reffunc refmpn_copyi
+#define funcname "MPN_COPY_INCR"
+#endif
+
+#ifdef OPERATION_copyd
+#define func MPN_COPY_DECR
+#define reffunc refmpn_copyd
+#define funcname "MPN_COPY_DECR"
+#endif
+
#if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux)
#include <time.h>
@@ -48,6 +61,8 @@ cputime ()
}
#endif
+static void mpn_print (mp_ptr, mp_size_t);
+
#define M * 1000000
#ifndef CLOCK
@@ -58,56 +73,41 @@ cputime ()
#define OPS (CLOCK/2)
#endif
#ifndef SIZE
-#define SIZE 328
+#define SIZE 496
#endif
#ifndef TIMES
-#define TIMES (OPS/SIZE)
-#else
-#undef OPS
-#define OPS (SIZE*TIMES)
+#define TIMES OPS/(SIZE+1)
#endif
-
-void
-#if __STDC__
-refmpn_copyi (mp_ptr rptr, mp_srcptr sptr, mp_size_t n)
-#else
-refmpn_copyi (rptr, sptr, n)
- register mp_ptr rptr;
- register mp_srcptr sptr;
- mp_size_t n;
-#endif
-{
- mp_size_t i;
-
- for (i = 0; i < n; i++)
- rptr[i] = sptr[i];
-}
-
-main (argc, argv)
- int argc;
- char **argv;
+main (int argc, char **argv)
{
- mp_limb_t s1[SIZE];
- mp_limb_t dx[SIZE+2];
- mp_limb_t dy[SIZE+2];
+ mp_ptr s1, dx, dy;
int i;
long t0, t;
- int test;
+ unsigned int test;
mp_size_t size;
+ unsigned int ntests;
+
+ s1 = malloc (SIZE * sizeof (mp_limb_t));
+ dx = malloc ((SIZE + 2) * sizeof (mp_limb_t));
+ dy = malloc ((SIZE + 2) * sizeof (mp_limb_t));
- for (test = 0; ; test++)
+ ntests = ~(unsigned) 0;
+ if (argc == 2)
+ ntests = strtol (argv[1], 0, 0);
+
+ for (test = 1; test <= ntests; test++)
{
#if TIMES == 1 && ! defined (PRINT)
- if (test % (SIZE > 10000 ? 1 : 10000 / SIZE) == 0)
+ if (test % (SIZE > 100000 ? 1 : 100000 / SIZE) == 0)
{
- printf ("\r%d", test);
+ printf ("\r%u", test);
fflush (stdout);
}
#endif
#ifdef RANDOM
- size = (random () % SIZE + 1);
+ size = random () % SIZE + 1;
#else
size = SIZE;
#endif
@@ -120,21 +120,12 @@ main (argc, argv)
#if TIMES != 1
mpn_random (s1, size);
-#ifndef NOCHECK
- t0 = cputime();
- for (i = 0; i < TIMES; i++)
- refmpn_copyi (dx+1, s1, size);
- t = cputime() - t0;
- printf ("refmpn_copyi: %ldms (%.2f cycles/limb)\n",
- t, ((double) t * CLOCK) / (OPS * 1000.0));
-#endif
-
t0 = cputime();
for (i = 0; i < TIMES; i++)
- MPN_COPY_INCR (dx+1, s1, size);
+ func (dx+1, s1, size);
t = cputime() - t0;
- printf ("MPN_COPY_INCR: %ldms (%.2f cycles/limb)\n",
- t, ((double) t * CLOCK) / (OPS * 1000.0));
+ printf (funcname ": %5ldms (%.3f cycles/limb)\n",
+ t, ((double) t * CLOCK) / (TIMES * size * 1000.0));
#endif
#ifndef NOCHECK
@@ -151,12 +142,14 @@ main (argc, argv)
dy[i+1] = 0xbeef;
}
- refmpn_copyi (dx+1, s1, size);
- MPN_COPY_INCR (dy+1, s1, size);
+ reffunc (dx+1, s1, size);
+ func (dy+1, s1, size);
+
#ifdef PRINT
mpn_print (dx+1, size);
mpn_print (dy+1, size);
#endif
+
if (mpn_cmp (dx, dy, size+2) != 0
|| dx[0] != 0x87654321 || dx[size+1] != 0x12345678)
{
@@ -164,13 +157,20 @@ main (argc, argv)
mpn_print (dx+1, size);
mpn_print (dy+1, size);
#endif
- printf ("TEST NUMBER %d\n", test);
+ printf ("\n");
+ if (dy[0] != 0x87654321)
+ printf ("clobbered at low end\n");
+ if (dy[size+1] != 0x12345678)
+ printf ("clobbered at high end\n");
+ printf ("TEST NUMBER %u\n", test);
abort();
}
#endif
}
+ exit (0);
}
+static void
mpn_print (mp_ptr p, mp_size_t size)
{
mp_size_t i;