8 #include <sys/resource.h>
16 return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000;
21 #ifndef CLOCKS_PER_SEC
22 #define CLOCKS_PER_SEC 1000000
25 #if CLOCKS_PER_SEC >= 10000
26 #define CLOCK_TO_MILLISEC(cl) ((cl) / (CLOCKS_PER_SEC / 1000))
28 #define CLOCK_TO_MILLISEC(cl) ((cl) * 1000 / CLOCKS_PER_SEC)
34 return CLOCK_TO_MILLISEC (clock ());
41 #if defined (__m88k__)
43 #elif defined (__i386__)
44 #define CLOCK (16.666667 M)
45 #elif defined (__m68k__)
47 #elif defined (_IBMR2)
49 #elif defined (__sparc__)
51 #elif defined (__sun__)
53 #elif defined (__mips)
55 #elif defined (__hppa__)
57 #elif defined (__alpha)
60 #error "Don't know CLOCK of your machine"
71 #define TIMES OPS/SIZE
74 #define OPS (SIZE*TIMES)
78 refmpn_rshift (wp, up, usize, cnt)
80 register mp_srcptr up;
82 register unsigned int cnt;
84 register mp_limb_t high_limb, low_limb;
85 register unsigned sh_1, sh_2;
90 if (usize == 0 || cnt == 0)
100 /* Copy from low end to high end, to allow specified input/output
102 for (i = 0; i < usize; i++)
110 sh_2 = BITS_PER_MP_LIMB - sh_1;
112 retval = high_limb << sh_2;
113 low_limb = high_limb;
115 for (i = 1; i < usize; i++)
118 wp[i] = (low_limb >> sh_1) | (high_limb << sh_2);
119 low_limb = high_limb;
136 mp_limb_t dx[SIZE+2];
137 mp_limb_t dy[SIZE+2];
145 for (test = 0; ; test++)
148 size = (random () % SIZE + 1);
152 mpn_random2 (s1, size);
154 dx[size+1] = 0x12345678;
155 dy[size+1] = 0x12345678;
160 mpn_print (s1, size);
163 for (i = 0; i < TIMES; i++)
164 cyx = refmpn_rshift (dx+1, s1, size, cnt);
167 printf ("refmpn_rshift: %5ldms (%.2f cycles/limb)\n",
169 ((double) t * CLOCK) / (OPS * 1000.0));
172 printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx); mpn_print (dx+1, size);
176 for (i = 0; i < TIMES; i++)
177 cyy = mpn_rshift (dx+1, s1, size, cnt);
180 printf ("mpn_rshift: %5ldms (%.2f cycles/limb)\n",
182 ((double) t * CLOCK) / (OPS * 1000.0));
185 printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy); mpn_print (dx+1, size);
189 /* Put garbage in the destination. */
190 for (i = 1; i <= size; i++)
196 cyx = refmpn_rshift (dx+1, s1, size, cnt);
197 cyy = mpn_rshift (dy+1, s1, size, cnt);
199 if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0
200 || dx[size+1] != 0x12345678 || dx[0] != 0x87654321)
203 printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx);
204 mpn_print (dx+1, size);
205 printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy);
206 mpn_print (dy+1, size);
214 mpn_print (mp_ptr p, mp_size_t size)
218 for (i = size - 1; i >= 0; i--)
220 printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]);