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