2
Copyright 1996, 1997, 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,
27
#if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux)
33
if (CLOCKS_PER_SEC < 100000)
34
return clock () * 1000 / CLOCKS_PER_SEC;
35
return clock () / (CLOCKS_PER_SEC / 1000);
38
#include <sys/types.h>
40
#include <sys/resource.h>
48
return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000;
55
#if defined (__m88k__)
57
#elif defined (__i386__)
58
#define CLOCK (16666667)
59
#elif defined (__m68k__)
61
#elif defined (_IBMR2)
63
#elif defined (__sparc__)
65
#elif defined (__sun__)
67
#elif defined (__mips)
69
#elif defined (__hppa__)
71
#elif defined (__alpha)
74
#error "Don't know CLOCK of your machine"
85
#define TIMES OPS/SIZE
88
#define OPS (SIZE*TIMES)
92
refmpn_mul_1 (res_ptr, s1_ptr, s1_size, s2_limb)
93
register mp_ptr res_ptr;
94
register mp_srcptr s1_ptr;
96
register mp_limb_t s2_limb;
98
register mp_limb_t cy_limb;
100
register mp_limb_t prod_high, prod_low;
102
/* The loop counter and index J goes from -S1_SIZE to -1. This way
103
the loop becomes faster. */
106
/* Offset the base pointers to compensate for the negative indices. */
113
umul_ppmm (prod_high, prod_low, s1_ptr[j], s2_limb);
116
cy_limb = (prod_low < cy_limb) + prod_high;
118
res_ptr[j] = prod_low;
130
mp_limb_t dx[SIZE+2];
131
mp_limb_t dy[SIZE+2];
140
for (test = 0; ; test++)
142
#if TIMES == 1 && ! defined (PRINT)
143
if (test % (SIZE > 10000 ? 1 : 10000 / SIZE) == 0)
145
printf ("\r%d", test);
151
size = random () % SIZE + 1;
156
dy[size+1] = 0x12345678;
159
mpn_random2 (&xlimb, 1);
162
mpn_random (s1, size);
163
mpn_random (dy+1, size);
166
MPN_COPY (dx, dy, size+2);
168
for (i = 0; i < TIMES; i++)
169
refmpn_mul_1 (dx+1, s1, size, xlimb);
171
cyc = ((double) t * CLOCK) / (OPS * 1000.0);
172
printf ("refmpn_mul_1: %5ldms (%.2f cycles/limb) [%.2f Gb/s]\n",
174
CLOCK/cyc*BITS_PER_MP_LIMB*BITS_PER_MP_LIMB/1e9);
177
MPN_COPY (dx, dy, size+2);
179
for (i = 0; i < TIMES; i++)
180
mpn_mul_1 (dx+1, s1, size, xlimb);
182
cyc = ((double) t * CLOCK) / (OPS * 1000.0);
183
printf ("mpn_mul_1: %5ldms (%.2f cycles/limb) [%.2f Gb/s]\n",
185
CLOCK/cyc*BITS_PER_MP_LIMB*BITS_PER_MP_LIMB/1e9);
188
mpn_random2 (s1, size);
189
mpn_random2 (dy+1, size);
190
#if defined (PRINT) || defined (XPRINT)
192
mpn_print (&xlimb, 1);
195
printf ("%*s ", (int) (2 * sizeof(mp_limb_t)), "");
196
mpn_print (s1, size);
199
MPN_COPY (dx, dy, size+2);
200
cyx = refmpn_mul_1 (dx+1, s1, size, xlimb);
201
cyy = mpn_mul_1 (dy+1, s1, size, xlimb);
204
printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx);
205
mpn_print (dx+1, size);
206
printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy);
207
mpn_print (dy+1, size);
211
if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0
212
|| dx[size+1] != 0x12345678 || dx[0] != 0x87654321)
216
printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx);
217
mpn_print (dx+1, size);
218
printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy);
219
mpn_print (dy+1, size);
221
printf ("%*s ", (int) (2 * sizeof(mp_limb_t)), "DIFF:");
222
for (i = size; i != 0; i--)
224
mp_limb_t diff = dy[i] ^ dx[i];
226
printf ("%*lX", (int) (2 * sizeof(mp_limb_t)), diff);
228
printf ("%*s", (int) (2 * sizeof(mp_limb_t)), "");
234
printf ("\nTEST NUMBER %d\n", test);
244
mpn_print (mp_ptr p, mp_size_t size)
248
for (i = size - 1; i >= 0; i--)
250
#ifdef _LONG_LONG_LIMB
251
printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)),
252
(unsigned long) (p[i] >> (BITS_PER_MP_LIMB/2)),
253
(int) (sizeof(mp_limb_t)), (unsigned long) (p[i]));
255
printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]);