Annotation of OpenXM_contrib/gmp/tests/devel/mul_1.c, Revision 1.1.1.1
1.1 ohara 1: /*
2: Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation,
3: Inc.
4:
5: This file is part of the GNU MP Library.
6:
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.
11:
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.
16:
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,
20: MA 02111-1307, USA.
21: */
22:
23: #include <stdio.h>
24: #include "gmp.h"
25: #include "gmp-impl.h"
26: #include "longlong.h"
27:
28: #if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux)
29: #include <time.h>
30:
31: int
32: cputime ()
33: {
34: if (CLOCKS_PER_SEC < 100000)
35: return clock () * 1000 / CLOCKS_PER_SEC;
36: return clock () / (CLOCKS_PER_SEC / 1000);
37: }
38: #else
39: #include <sys/types.h>
40: #include <sys/time.h>
41: #include <sys/resource.h>
42:
43: int
44: cputime ()
45: {
46: struct rusage rus;
47:
48: getrusage (0, &rus);
49: return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000;
50: }
51: #endif
52:
53: #define M * 1000000
54:
55: #ifndef CLOCK
56: #error "Don't know CLOCK of your machine"
57: #endif
58:
59: #ifndef OPS
60: #define OPS (CLOCK/5)
61: #endif
62: #ifndef SIZE
63: #define SIZE 496
64: #endif
65: #ifndef TIMES
66: #define TIMES OPS/SIZE
67: #else
68: #undef OPS
69: #define OPS (SIZE*TIMES)
70: #endif
71:
72: mp_limb_t
73: refmpn_mul_1 (res_ptr, s1_ptr, s1_size, s2_limb)
74: register mp_ptr res_ptr;
75: register mp_srcptr s1_ptr;
76: mp_size_t s1_size;
77: register mp_limb_t s2_limb;
78: {
79: register mp_limb_t cy_limb;
80: register mp_size_t j;
81: register mp_limb_t prod_high, prod_low;
82:
83: /* The loop counter and index J goes from -S1_SIZE to -1. This way
84: the loop becomes faster. */
85: j = -s1_size;
86:
87: /* Offset the base pointers to compensate for the negative indices. */
88: res_ptr -= j;
89: s1_ptr -= j;
90:
91: cy_limb = 0;
92: s2_limb <<= GMP_NAIL_BITS;
93: do
94: {
95: umul_ppmm (prod_high, prod_low, s1_ptr[j], s2_limb);
96: prod_low >>= GMP_NAIL_BITS;
97:
98: prod_low = (prod_low + cy_limb) & GMP_NUMB_MASK;
99: cy_limb = (prod_low < cy_limb) + prod_high;
100:
101: res_ptr[j] = prod_low;
102: }
103: while (++j != 0);
104:
105: return cy_limb;
106: }
107:
108: main (argc, argv)
109: int argc;
110: char **argv;
111: {
112: mp_limb_t s1[SIZE];
113: mp_limb_t dx[SIZE+2];
114: mp_limb_t dy[SIZE+2];
115: mp_limb_t cyx, cyy;
116: int i;
117: long t0, t;
118: unsigned int test;
119: mp_limb_t xlimb;
120: mp_size_t size;
121: double cyc;
122: unsigned int ntests;
123:
124: ntests = ~(unsigned) 0;
125: if (argc == 2)
126: ntests = strtol (argv[1], 0, 0);
127:
128: for (test = 1; test <= ntests; test++)
129: {
130: #if TIMES == 1 && ! defined (PRINT)
131: if (test % (SIZE > 10000 ? 1 : 10000 / SIZE) == 0)
132: {
133: printf ("\r%u", test);
134: fflush (stdout);
135: }
136: #endif
137:
138: #ifdef RANDOM
139: size = random () % SIZE + 1;
140: #else
141: size = SIZE;
142: #endif
143:
144: dy[size+1] = 0x12345678;
145: dy[0] = 0x87654321;
146:
147: #ifdef FIXED_XLIMB
148: xlimb = FIXED_XLIMB;
149: #else
150: mpn_random2 (&xlimb, 1);
151: #endif
152:
153: #if TIMES != 1
154: mpn_random (s1, size);
155: mpn_random (dy+1, size);
156:
157: #ifndef NOCHECK
158: MPN_COPY (dx, dy, size+2);
159: t0 = cputime();
160: for (i = 0; i < TIMES; i++)
161: refmpn_mul_1 (dx+1, s1, size, xlimb);
162: t = cputime() - t0;
163: cyc = ((double) t * CLOCK) / (OPS * 1000.0);
164: printf ("refmpn_mul_1: %5ldms (%.2f cycles/limb) [%.2f Gb/s]\n",
165: t, cyc,
166: CLOCK/cyc*BITS_PER_MP_LIMB*BITS_PER_MP_LIMB/1e9);
167: #endif
168:
169: MPN_COPY (dx, dy, size+2);
170: t0 = cputime();
171: for (i = 0; i < TIMES; i++)
172: mpn_mul_1 (dx+1, s1, size, xlimb);
173: t = cputime() - t0;
174: cyc = ((double) t * CLOCK) / (OPS * 1000.0);
175: printf ("mpn_mul_1: %5ldms (%.2f cycles/limb) [%.2f Gb/s]\n",
176: t, cyc,
177: CLOCK/cyc*BITS_PER_MP_LIMB*BITS_PER_MP_LIMB/1e9);
178: #endif
179:
180: mpn_random2 (s1, size);
181: mpn_random2 (dy+1, size);
182: #if defined (PRINT) || defined (XPRINT)
183: printf ("xlimb=");
184: mpn_print (&xlimb, 1);
185: #endif
186: #ifdef PRINT
187: printf ("%*s ", (int) (2 * sizeof(mp_limb_t)), "");
188: mpn_print (s1, size);
189: #endif
190:
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);
194:
195: #ifdef PRINT
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);
200: #endif
201:
202: #ifndef NOCHECK
203: if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0
204: || dx[size+1] != 0x12345678 || dx[0] != 0x87654321)
205: {
206: printf ("\n");
207: #ifndef PRINT
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);
212: #endif
213: printf ("%*s ", (int) (2 * sizeof(mp_limb_t)), "DIFF:");
214: for (i = size; i != 0; i--)
215: {
216: mp_limb_t diff = dy[i] ^ dx[i];
217: if (diff != 0)
218: printf ("%*lX", (int) (2 * sizeof(mp_limb_t)), diff);
219: else
220: printf ("%*s", (int) (2 * sizeof(mp_limb_t)), "");
221: #ifdef SPACE
222: if (i != 0)
223: printf (" ");
224: #endif
225: }
226: printf ("\n");
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);
232: abort();
233: }
234: #endif
235: #ifdef ONE
236: return 0;
237: #endif
238: }
239: }
240:
241: mpn_print (mp_ptr p, mp_size_t size)
242: {
243: mp_size_t i;
244:
245: for (i = size - 1; i >= 0; i--)
246: {
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]));
251: #else
252: printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]);
253: #endif
254: #ifdef SPACE
255: if (i != 0)
256: printf (" ");
257: #endif
258: }
259: puts ("");
260: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>