2
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation,
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 2.1 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; see the file COPYING.LIB. If not, write to
19
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28
#if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux)
34
if (CLOCKS_PER_SEC < 100000)
35
return clock () * 1000 / CLOCKS_PER_SEC;
36
return clock () / (CLOCKS_PER_SEC / 1000);
39
#include <sys/types.h>
41
#include <sys/resource.h>
49
return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000;
56
#error "Don't know CLOCK of your machine"
66
#define TIMES OPS/SIZE
69
#define OPS (SIZE*TIMES)
73
refmpn_mul_1 (res_ptr, s1_ptr, s1_size, s2_limb)
74
register mp_ptr res_ptr;
75
register mp_srcptr s1_ptr;
77
register mp_limb_t s2_limb;
79
register mp_limb_t cy_limb;
81
register mp_limb_t prod_high, prod_low;
83
/* The loop counter and index J goes from -S1_SIZE to -1. This way
84
the loop becomes faster. */
87
/* Offset the base pointers to compensate for the negative indices. */
92
s2_limb <<= GMP_NAIL_BITS;
95
umul_ppmm (prod_high, prod_low, s1_ptr[j], s2_limb);
96
prod_low >>= GMP_NAIL_BITS;
98
prod_low = (prod_low + cy_limb) & GMP_NUMB_MASK;
99
cy_limb = (prod_low < cy_limb) + prod_high;
101
res_ptr[j] = prod_low;
113
mp_limb_t dx[SIZE+2];
114
mp_limb_t dy[SIZE+2];
124
ntests = ~(unsigned) 0;
126
ntests = strtol (argv[1], 0, 0);
128
for (test = 1; test <= ntests; test++)
130
#if TIMES == 1 && ! defined (PRINT)
131
if (test % (SIZE > 10000 ? 1 : 10000 / SIZE) == 0)
133
printf ("\r%u", test);
139
size = random () % SIZE + 1;
144
dy[size+1] = 0x12345678;
150
mpn_random2 (&xlimb, 1);
154
mpn_random (s1, size);
155
mpn_random (dy+1, size);
158
MPN_COPY (dx, dy, size+2);
160
for (i = 0; i < TIMES; i++)
161
refmpn_mul_1 (dx+1, s1, size, xlimb);
163
cyc = ((double) t * CLOCK) / (OPS * 1000.0);
164
printf ("refmpn_mul_1: %5ldms (%.2f cycles/limb) [%.2f Gb/s]\n",
166
CLOCK/cyc*BITS_PER_MP_LIMB*BITS_PER_MP_LIMB/1e9);
169
MPN_COPY (dx, dy, size+2);
171
for (i = 0; i < TIMES; i++)
172
mpn_mul_1 (dx+1, s1, size, xlimb);
174
cyc = ((double) t * CLOCK) / (OPS * 1000.0);
175
printf ("mpn_mul_1: %5ldms (%.2f cycles/limb) [%.2f Gb/s]\n",
177
CLOCK/cyc*BITS_PER_MP_LIMB*BITS_PER_MP_LIMB/1e9);
180
mpn_random2 (s1, size);
181
mpn_random2 (dy+1, size);
182
#if defined (PRINT) || defined (XPRINT)
184
mpn_print (&xlimb, 1);
187
printf ("%*s ", (int) (2 * sizeof(mp_limb_t)), "");
188
mpn_print (s1, size);
191
MPN_COPY (dx, dy, size+2);
192
cyx = refmpn_mul_1 (dx+1, s1, size, xlimb);
193
cyy = mpn_mul_1 (dy+1, s1, size, xlimb);
196
printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx);
197
mpn_print (dx+1, size);
198
printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy);
199
mpn_print (dy+1, size);
203
if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0
204
|| dx[size+1] != 0x12345678 || dx[0] != 0x87654321)
208
printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx);
209
mpn_print (dx+1, size);
210
printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy);
211
mpn_print (dy+1, size);
213
printf ("%*s ", (int) (2 * sizeof(mp_limb_t)), "DIFF:");
214
for (i = size; i != 0; i--)
216
mp_limb_t diff = dy[i] ^ dx[i];
218
printf ("%*lX", (int) (2 * sizeof(mp_limb_t)), diff);
220
printf ("%*s", (int) (2 * sizeof(mp_limb_t)), "");
227
if (dy[0] != 0x87654321)
228
printf ("clobbered at low end\n");
229
if (dy[size+1] != 0x12345678)
230
printf ("clobbered at high end\n");
231
printf ("TEST NUMBER %u\n", test);
241
mpn_print (mp_ptr p, mp_size_t size)
245
for (i = size - 1; i >= 0; i--)
247
#ifdef _LONG_LONG_LIMB
248
printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)),
249
(unsigned long) (p[i] >> (BITS_PER_MP_LIMB/2)),
250
(int) (sizeof(mp_limb_t)), (unsigned long) (p[i]));
252
printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]);