2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 Free
3 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_and_n
27 #define func __gmpn_and_n
28 #define reffunc refmpn_and_n
29 #define funcname "mpn_and_n"
32 #ifdef OPERATION_andn_n
33 #define func __gmpn_andn_n
34 #define reffunc refmpn_andn_n
35 #define funcname "mpn_andn_n"
38 #ifdef OPERATION_nand_n
39 #define func __gmpn_nand_n
40 #define reffunc refmpn_nand_n
41 #define funcname "mpn_nand_n"
44 #ifdef OPERATION_ior_n
45 #define func __gmpn_ior_n
46 #define reffunc refmpn_ior_n
47 #define funcname "mpn_ior_n"
50 #ifdef OPERATION_iorn_n
51 #define func __gmpn_iorn_n
52 #define reffunc refmpn_iorn_n
53 #define funcname "mpn_iorn_n"
56 #ifdef OPERATION_nior_n
57 #define func __gmpn_nior_n
58 #define reffunc refmpn_nior_n
59 #define funcname "mpn_nior_n"
62 #ifdef OPERATION_xor_n
63 #define func __gmpn_xor_n
64 #define reffunc refmpn_xor_n
65 #define funcname "mpn_xor_n"
68 #ifdef OPERATION_xnor_n
69 #define func __gmpn_xnor_n
70 #define reffunc refmpn_xnor_n
71 #define funcname "mpn_xnor_n"
74 #if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux)
80 if (CLOCKS_PER_SEC < 100000)
81 return clock () * 1000 / CLOCKS_PER_SEC;
82 return clock () / (CLOCKS_PER_SEC / 1000);
85 #include <sys/types.h>
87 #include <sys/resource.h>
95 return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000;
99 static void mpn_print (mp_ptr, mp_size_t);
104 #error "Don't know CLOCK of your machine"
108 #define OPS (CLOCK/5)
114 #define TIMES OPS/(SIZE+1)
118 main (int argc, char **argv)
120 mp_ptr s1, s2, dx, dy;
127 s1 = malloc (SIZE * sizeof (mp_limb_t));
128 s2 = malloc (SIZE * sizeof (mp_limb_t));
129 dx = malloc ((SIZE + 2) * sizeof (mp_limb_t));
130 dy = malloc ((SIZE + 2) * sizeof (mp_limb_t));
132 ntests = ~(unsigned) 0;
134 ntests = strtol (argv[1], 0, 0);
136 for (test = 1; test <= ntests; test++)
138 #if TIMES == 1 && ! defined (PRINT)
139 if (test % (SIZE > 100000 ? 1 : 100000 / SIZE) == 0)
141 printf ("\r%d", test);
147 size = random () % SIZE + 1;
154 dx[size+1] = 0x12345678;
155 dy[size+1] = 0x12345678;
158 mpn_random (s1, size);
159 mpn_random (s2, size);
162 for (i = 0; i < TIMES; i++)
163 func (dx+1, s1, s2, size);
165 printf (funcname ": %5ldms (%.3f cycles/limb)\n",
166 t, ((double) t * CLOCK) / (TIMES * size * 1000.0));
170 mpn_random2 (s1, size);
171 mpn_random2 (s2, size);
174 mpn_print (s1, size);
175 mpn_print (s2, size);
178 /* Put garbage in the destination. */
179 for (i = 0; i < size; i++)
185 reffunc (dx+1, s1, s2, size);
186 func (dy+1, s1, s2, size);
188 mpn_print (dx+1, size);
189 mpn_print (dy+1, size);
191 if (mpn_cmp (dx, dy, size+2) != 0
192 || dx[0] != 0x87654321 || dx[size+1] != 0x12345678)
195 mpn_print (dx+1, size);
196 mpn_print (dy+1, size);
199 if (dy[0] != 0x87654321)
200 printf ("clobbered at low end\n");
201 if (dy[size+1] != 0x12345678)
202 printf ("clobbered at high end\n");
203 printf ("TEST NUMBER %u\n", test);
212 mpn_print (mp_ptr p, mp_size_t size)
216 for (i = size - 1; i >= 0; i--)
218 #ifdef _LONG_LONG_LIMB
219 printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)),
220 (unsigned long) (p[i] >> (GMP_LIMB_BITS/2)),
221 (int) (sizeof(mp_limb_t)), (unsigned long) (p[i]));
223 printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]);