2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009
3 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
12 The GNU MP Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
26 #ifdef OPERATION_add_n
27 #define func __gmpn_add_n
28 #define reffunc refmpn_add_n
29 #define funcname "mpn_add_n"
32 #ifdef OPERATION_sub_n
33 #define func __gmpn_sub_n
34 #define reffunc refmpn_sub_n
35 #define funcname "mpn_sub_n"
38 #ifdef OPERATION_addlsh1_n
39 #define func __gmpn_addlsh1_n
40 #define reffunc refmpn_addlsh1_n
41 #define funcname "mpn_addlsh1_n"
44 #ifdef OPERATION_sublsh1_n
45 #define func __gmpn_sublsh1_n
46 #define reffunc refmpn_sublsh1_n
47 #define funcname "mpn_sublsh1_n"
50 #ifdef OPERATION_rsh1add_n
51 #define func __gmpn_rsh1add_n
52 #define reffunc refmpn_rsh1add_n
53 #define funcname "mpn_rsh1add_n"
56 #ifdef OPERATION_rsh1sub_n
57 #define func __gmpn_rsh1sub_n
58 #define reffunc refmpn_rsh1sub_n
59 #define funcname "mpn_rsh1sub_n"
62 #if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux)
68 if (CLOCKS_PER_SEC < 100000)
69 return clock () * 1000 / CLOCKS_PER_SEC;
70 return clock () / (CLOCKS_PER_SEC / 1000);
73 #include <sys/types.h>
75 #include <sys/resource.h>
83 return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000;
87 static void mpn_print (mp_ptr, mp_size_t);
92 #error "Don't know CLOCK of your machine"
102 #define TIMES OPS/(SIZE+1)
106 main (int argc, char **argv)
108 mp_ptr s1, s2, dx, dy;
118 s1 = malloc (SIZE * sizeof (mp_limb_t));
119 s2 = malloc (SIZE * sizeof (mp_limb_t));
120 dx = malloc ((SIZE + 2) * sizeof (mp_limb_t));
121 dy = malloc ((SIZE + 2) * sizeof (mp_limb_t));
123 ntests = ~(unsigned) 0;
125 ntests = strtol (argv[1], 0, 0);
127 for (test = 1; test <= ntests; test++)
129 #if TIMES == 1 && ! defined (PRINT)
130 if (test % (SIZE > 100000 ? 1 : 100000 / SIZE) == 0)
132 printf ("\r%u", test);
138 size = random () % SIZE + 1;
145 dx[size+1] = 0x12345678;
146 dy[size+1] = 0x12345678;
149 mpn_random (s1, size);
150 mpn_random (s2, size);
153 for (i = 0; i < TIMES; i++)
154 func (dx+1, s1, s2, size);
156 printf (funcname ": %5ldms (%.3f cycles/limb)\n",
157 t, ((double) t * CLOCK) / (TIMES * size * 1000.0));
161 mpn_random2 (s1, size);
162 mpn_random2 (s2, size);
165 mpn_print (s1, size);
166 mpn_print (s2, size);
169 /* Put garbage in the destination. */
170 for (i = 0; i < size; i++)
176 cyx = reffunc (dx+1, s1, s2, size);
177 cyy = func (dy+1, s1, s2, size);
181 mpn_print (dx+1, size);
183 mpn_print (dy+1, size);
186 if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0
187 || dx[0] != 0x87654321 || dx[size+1] != 0x12345678)
191 mpn_print (dx+1, size);
193 mpn_print (dy+1, size);
196 if (dy[0] != 0x87654321)
197 printf ("clobbered at low end\n");
198 if (dy[size+1] != 0x12345678)
199 printf ("clobbered at high end\n");
200 printf ("TEST NUMBER %u\n", test);
209 mpn_print (mp_ptr p, mp_size_t size)
213 for (i = size - 1; i >= 0; i--)
215 #ifdef _LONG_LONG_LIMB
216 printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)),
217 (unsigned long) (p[i] >> (GMP_LIMB_BITS/2)),
218 (int) (sizeof(mp_limb_t)), (unsigned long) (p[i]));
220 printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]);