2 Copyright 1999, 2000, 2001, 2004, 2009 Free Software Foundation, Inc.
4 This file is part of the GNU MP Library.
6 The GNU MP Library is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or (at your
9 option) any later version.
11 The GNU MP Library is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
25 #ifdef OPERATION_copyi
26 #define func MPN_COPY_INCR
27 #define reffunc refmpn_copyi
28 #define funcname "MPN_COPY_INCR"
31 #ifdef OPERATION_copyd
32 #define func MPN_COPY_DECR
33 #define reffunc refmpn_copyd
34 #define funcname "MPN_COPY_DECR"
37 #if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux)
43 if (CLOCKS_PER_SEC < 100000)
44 return clock () * 1000 / CLOCKS_PER_SEC;
45 return clock () / (CLOCKS_PER_SEC / 1000);
48 #include <sys/types.h>
50 #include <sys/resource.h>
58 return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000;
62 static void mpn_print (mp_ptr, mp_size_t);
67 #error "Don't know CLOCK of your machine"
77 #define TIMES OPS/(SIZE+1)
81 main (int argc, char **argv)
90 s1 = malloc (SIZE * sizeof (mp_limb_t));
91 dx = malloc ((SIZE + 2) * sizeof (mp_limb_t));
92 dy = malloc ((SIZE + 2) * sizeof (mp_limb_t));
94 ntests = ~(unsigned) 0;
96 ntests = strtol (argv[1], 0, 0);
98 for (test = 1; test <= ntests; test++)
100 #if TIMES == 1 && ! defined (PRINT)
101 if (test % (SIZE > 100000 ? 1 : 100000 / SIZE) == 0)
103 printf ("\r%u", test);
109 size = random () % SIZE + 1;
116 dx[size+1] = 0x12345678;
117 dy[size+1] = 0x12345678;
120 mpn_random (s1, size);
123 for (i = 0; i < TIMES; i++)
124 func (dx+1, s1, size);
126 printf (funcname ": %5ldms (%.3f cycles/limb)\n",
127 t, ((double) t * CLOCK) / (TIMES * size * 1000.0));
131 mpn_random2 (s1, size);
134 mpn_print (s1, size);
137 /* Put garbage in the destination. */
138 for (i = 0; i < size; i++)
144 reffunc (dx+1, s1, size);
145 func (dy+1, s1, size);
148 mpn_print (dx+1, size);
149 mpn_print (dy+1, size);
152 if (mpn_cmp (dx, dy, size+2) != 0
153 || dx[0] != 0x87654321 || dx[size+1] != 0x12345678)
156 mpn_print (dx+1, size);
157 mpn_print (dy+1, size);
160 if (dy[0] != 0x87654321)
161 printf ("clobbered at low end\n");
162 if (dy[size+1] != 0x12345678)
163 printf ("clobbered at high end\n");
164 printf ("TEST NUMBER %u\n", test);
173 mpn_print (mp_ptr p, mp_size_t size)
177 for (i = size - 1; i >= 0; i--)
179 #ifdef _LONG_LONG_LIMB
180 printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)),
181 (unsigned long) (p[i] >> (GMP_LIMB_BITS/2)),
182 (int) (sizeof(mp_limb_t)), (unsigned long) (p[i]));
184 printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]);