2
Copyright 1996, 1998, 1999, 2000, 2001 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 2.1 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; see the file COPYING.LIB. If not, write to
18
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
26
#if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux)
32
if (CLOCKS_PER_SEC < 100000)
33
return clock () * 1000 / CLOCKS_PER_SEC;
34
return clock () / (CLOCKS_PER_SEC / 1000);
37
#include <sys/types.h>
39
#include <sys/resource.h>
47
return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000;
54
#error "Don't know CLOCK of your machine"
64
#define TIMES OPS/SIZE
67
#define OPS (SIZE*TIMES)
71
refmpn_rshift (wp, up, usize, cnt)
73
register mp_srcptr up;
75
register unsigned int cnt;
77
register mp_limb_t high_limb, low_limb;
78
register unsigned sh_1, sh_2;
83
if (usize == 0 || cnt == 0)
93
/* Copy from low end to high end, to allow specified input/output
95
for (i = 0; i < usize; i++)
103
sh_2 = BITS_PER_MP_LIMB - sh_1;
105
retval = high_limb << sh_2;
106
low_limb = high_limb;
108
for (i = 1; i < usize; i++)
111
wp[i] = (low_limb >> sh_1) | (high_limb << sh_2);
112
low_limb = high_limb;
129
mp_limb_t dx[SIZE+2];
130
mp_limb_t dy[SIZE+2];
138
for (test = 0; ; test++)
140
#if TIMES == 1 && ! defined (PRINT)
141
if (test % (SIZE > 10000 ? 1 : 10000 / SIZE) == 0)
143
printf ("\r%d", test);
149
cnt = random () % (BITS_PER_MP_LIMB - 1) + 1;
153
size = random () % SIZE + 1;
157
mpn_random2 (s1, size);
159
dx[size+1] = 0x12345678;
160
dy[size+1] = 0x12345678;
165
mpn_random (s1, size);
169
for (i = 0; i < TIMES; i++)
170
refmpn_rshift (dx+1, s1, size, cnt);
172
printf ("refmpn_rshift: %5ldms (%.2f cycles/limb)\n",
173
t, ((double) t * CLOCK) / (OPS * 1000.0));
177
for (i = 0; i < TIMES; i++)
178
mpn_rshift (dx+1, s1, size, cnt);
180
printf ("mpn_rshift: %5ldms (%.2f cycles/limb)\n",
181
t, ((double) t * CLOCK) / (OPS * 1000.0));
185
mpn_random2 (s1, size);
188
printf ("%-*d ", (int) (2 * sizeof(mp_limb_t)), cnt); mpn_print (s1, size);
191
/* Put garbage in the destination. */
192
for (i = 0; i < size; i++)
198
cyx = refmpn_rshift (dx+1, s1, size, cnt);
199
cyy = mpn_rshift (dy+1, s1, size, cnt);
201
printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx);
202
mpn_print (dx+1, size);
203
printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy);
204
mpn_print (dy+1, size);
206
if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0
207
|| dx[0] != 0x87654321 || dx[size+1] != 0x12345678)
210
printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx);
211
mpn_print (dx+1, size);
212
printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy);
213
mpn_print (dy+1, size);
216
if (dy[0] != 0x87654321)
217
printf ("clobbered at low end\n");
218
if (dy[size+1] != 0x12345678)
219
printf ("clobbered at high end\n");
220
printf ("TEST NUMBER %u\n", test);
227
mpn_print (mp_ptr p, mp_size_t size)
231
for (i = size - 1; i >= 0; i--)
233
#ifdef _LONG_LONG_LIMB
234
printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)),
235
(unsigned long) (p[i] >> (BITS_PER_MP_LIMB/2)),
236
(int) (sizeof(mp_limb_t)), (unsigned long) (p[i]));
238
printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]);