Annotation of OpenXM_contrib/gmp/tests/devel/copy.c, Revision 1.1.1.1
1.1 ohara 1: /*
2: Copyright 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:
22: #include <stdio.h>
23: #include "gmp.h"
24: #include "gmp-impl.h"
25:
26: #if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux)
27: #include <time.h>
28:
29: int
30: cputime ()
31: {
32: if (CLOCKS_PER_SEC < 100000)
33: return clock () * 1000 / CLOCKS_PER_SEC;
34: return clock () / (CLOCKS_PER_SEC / 1000);
35: }
36: #else
37: #include <sys/types.h>
38: #include <sys/time.h>
39: #include <sys/resource.h>
40:
41: int
42: cputime ()
43: {
44: struct rusage rus;
45:
46: getrusage (0, &rus);
47: return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000;
48: }
49: #endif
50:
51: #define M * 1000000
52:
53: #ifndef CLOCK
54: #error "Don't know CLOCK of your machine"
55: #endif
56:
57: #ifndef OPS
58: #define OPS (CLOCK/2)
59: #endif
60: #ifndef SIZE
61: #define SIZE 328
62: #endif
63: #ifndef TIMES
64: #define TIMES (OPS/SIZE)
65: #else
66: #undef OPS
67: #define OPS (SIZE*TIMES)
68: #endif
69:
70:
71: void
72: #if __STDC__
73: refmpn_copyi (mp_ptr rptr, mp_srcptr sptr, mp_size_t n)
74: #else
75: refmpn_copyi (rptr, sptr, n)
76: register mp_ptr rptr;
77: register mp_srcptr sptr;
78: mp_size_t n;
79: #endif
80: {
81: mp_size_t i;
82:
83: for (i = 0; i < n; i++)
84: rptr[i] = sptr[i];
85: }
86:
87: main (argc, argv)
88: int argc;
89: char **argv;
90: {
91: mp_limb_t s1[SIZE];
92: mp_limb_t dx[SIZE+2];
93: mp_limb_t dy[SIZE+2];
94: int i;
95: long t0, t;
96: int test;
97: mp_size_t size;
98:
99: for (test = 0; ; test++)
100: {
101: #if TIMES == 1 && ! defined (PRINT)
102: if (test % (SIZE > 10000 ? 1 : 10000 / SIZE) == 0)
103: {
104: printf ("\r%d", test);
105: fflush (stdout);
106: }
107: #endif
108:
109: #ifdef RANDOM
110: size = (random () % SIZE + 1);
111: #else
112: size = SIZE;
113: #endif
114:
115: dx[0] = 0x87654321;
116: dy[0] = 0x87654321;
117: dx[size+1] = 0x12345678;
118: dy[size+1] = 0x12345678;
119:
120: #if TIMES != 1
121: mpn_random (s1, size);
122:
123: #ifndef NOCHECK
124: t0 = cputime();
125: for (i = 0; i < TIMES; i++)
126: refmpn_copyi (dx+1, s1, size);
127: t = cputime() - t0;
128: printf ("refmpn_copyi: %ldms (%.2f cycles/limb)\n",
129: t, ((double) t * CLOCK) / (OPS * 1000.0));
130: #endif
131:
132: t0 = cputime();
133: for (i = 0; i < TIMES; i++)
134: MPN_COPY_INCR (dx+1, s1, size);
135: t = cputime() - t0;
136: printf ("MPN_COPY_INCR: %ldms (%.2f cycles/limb)\n",
137: t, ((double) t * CLOCK) / (OPS * 1000.0));
138: #endif
139:
140: #ifndef NOCHECK
141: mpn_random2 (s1, size);
142:
143: #ifdef PRINT
144: mpn_print (s1, size);
145: #endif
146:
147: /* Put garbage in the destination. */
148: for (i = 0; i < size; i++)
149: {
150: dx[i+1] = 0xdead;
151: dy[i+1] = 0xbeef;
152: }
153:
154: refmpn_copyi (dx+1, s1, size);
155: MPN_COPY_INCR (dy+1, s1, size);
156: #ifdef PRINT
157: mpn_print (dx+1, size);
158: mpn_print (dy+1, size);
159: #endif
160: if (mpn_cmp (dx, dy, size+2) != 0
161: || dx[0] != 0x87654321 || dx[size+1] != 0x12345678)
162: {
163: #ifndef PRINT
164: mpn_print (dx+1, size);
165: mpn_print (dy+1, size);
166: #endif
167: printf ("TEST NUMBER %d\n", test);
168: abort();
169: }
170: #endif
171: }
172: }
173:
174: mpn_print (mp_ptr p, mp_size_t size)
175: {
176: mp_size_t i;
177:
178: for (i = size - 1; i >= 0; i--)
179: {
180: #ifdef _LONG_LONG_LIMB
181: printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)),
182: (unsigned long) (p[i] >> (BITS_PER_MP_LIMB/2)),
183: (int) (sizeof(mp_limb_t)), (unsigned long) (p[i]));
184: #else
185: printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]);
186: #endif
187: #ifdef SPACE
188: if (i != 0)
189: printf (" ");
190: #endif
191: }
192: puts ("");
193: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>