2 Copyright 1996, 1998, 2000, 2001, 2007 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 #if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux)
31 if (CLOCKS_PER_SEC < 100000)
32 return clock () * 1000 / CLOCKS_PER_SEC;
33 return clock () / (CLOCKS_PER_SEC / 1000);
36 #include <sys/types.h>
38 #include <sys/resource.h>
46 return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000;
50 static void mpn_print (mp_ptr, mp_size_t);
55 #error "Don't know CLOCK of your machine"
65 #define TIMES OPS/SIZE
76 mp_limb_t dx[SIZE + FSIZE + 2];
77 mp_limb_t dy[SIZE + FSIZE + 2];
88 for (test = 0; ; test++)
90 #if TIMES == 1 && ! defined (PRINT)
91 if (test % (SIZE > 100000 ? 1 : 100000 / SIZE) == 0)
93 printf ("\r%u", test);
99 nn = random () % (SIZE + 1);
100 fn = random () % (FSIZE + 1);
107 dx[nn + fn + 1] = 0x12345678;
109 dy[nn + fn + 1] = 0x12345678;
110 mpn_random2 (np, nn);
117 mpn_random2 (&dlimb, 1);
119 dlimb |= GMP_NUMB_HIGHBIT;
122 dlimb &= GMP_NUMB_MAX >> 1;
128 #if defined (PRINT) || defined (XPRINT)
132 mpn_print (&dlimb, 1);
133 printf ("nn=%ld\n", (long) nn);
138 for (i = 0; i < TIMES; i++)
139 mpn_divrem_1 (dx + 1, 0L, np, nn, dlimb);
141 cyc = ((double) t * CLOCK) / (TIMES * nn * 1000.0);
142 printf ("mpn_divrem_1 int: %5ldms (%.3f cycles/limb) [%.2f Gb/s]\n",
144 CLOCK/cyc*GMP_LIMB_BITS*GMP_LIMB_BITS/1e9);
146 for (i = 0; i < TIMES; i++)
147 mpn_divrem_1 (dx + 1, fn, np, 0, dlimb);
149 cyc = ((double) t * CLOCK) / (TIMES * fn * 1000.0);
150 printf ("mpn_divrem_1 frac: %5ldms (%.3f cycles/limb) [%.2f Gb/s]\n",
152 CLOCK/cyc*GMP_LIMB_BITS*GMP_LIMB_BITS/1e9);
155 retx = refmpn_divrem_1 (dx + 1, fn, np, nn, dlimb);
156 rety = mpn_divrem_1 (dy + 1, fn, np, nn, dlimb);
159 if (retx != rety || mpn_cmp (dx, dy, fn + nn + 2) != 0)
161 printf ("ERROR in test %d, nn=%ld, fn=%ld\n", test, nn, fn);
163 mpn_print (&dlimb, 1);
165 mpn_print (dx + 1, nn + fn);
166 printf ("rr: %*lX\n", (int) (2 * sizeof(mp_limb_t)), retx);
168 mpn_print (dy + 1, nn + fn);
169 printf (" r: %*lX\n", (int) (2 * sizeof(mp_limb_t)), rety);
170 if (dy[0] != 0x87654321)
171 printf ("clobbered at low end %*lX\n", (int) (2 * sizeof(mp_limb_t)), dy[0]);
172 if (dy[nn + fn + 1] != 0x12345678)
173 printf ("clobbered at high end\n");
181 mpn_print (mp_ptr p, mp_size_t size)
185 for (i = size - 1; i >= 0; i--)
187 #ifdef _LONG_LONG_LIMB
188 printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)),
189 (unsigned long) (p[i] >> (GMP_LIMB_BITS/2)),
190 (int) (sizeof(mp_limb_t)), (unsigned long) (p[i]));
192 printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]);