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_mul_1 (res_ptr, s1_ptr, s1_size, s2_limb)
79 register mp_ptr res_ptr;
80 register mp_srcptr s1_ptr;
82 register mp_limb_t s2_limb;
84 register mp_limb_t cy_limb;
86 register mp_limb_t prod_high, prod_low;
88 /* The loop counter and index J goes from -S1_SIZE to -1. This way
89 the loop becomes faster. */
92 /* Offset the base pointers to compensate for the negative indices. */
99 umul_ppmm (prod_high, prod_low, s1_ptr[j], s2_limb);
102 cy_limb = (prod_low < cy_limb) + prod_high;
104 res_ptr[j] = prod_low;
116 mp_limb_t dx[SIZE+2];
117 mp_limb_t dy[SIZE+2];
125 for (test = 0; ; test++)
128 size = (random () % SIZE + 1);
133 mpn_random2 (s1, size);
134 mpn_random2 (dy+1, size);
136 if (random () % 0x100 == 0)
139 mpn_random2 (&xlimb, 1);
141 dy[size+1] = 0x12345678;
144 #if defined (PRINT) || defined (XPRINT)
145 printf ("xlimb=%*lX\n", (int) (2 * sizeof(mp_limb_t)), xlimb);
148 mpn_print (s1, size);
151 MPN_COPY (dx, dy, size+2);
153 for (i = 0; i < TIMES; i++)
154 cyx = refmpn_mul_1 (dx+1, s1, size, xlimb);
157 printf ("refmpn_mul_1: %5ldms (%.2f cycles/limb)\n",
159 ((double) t * CLOCK) / (OPS * 1000.0));
162 MPN_COPY (dx, dy, size+2);
164 for (i = 0; i < TIMES; i++)
165 cyy = mpn_mul_1 (dx+1, s1, size, xlimb);
168 printf ("mpn_mul_1: %5ldms (%.2f cycles/limb)\n",
170 ((double) t * CLOCK) / (OPS * 1000.0));
173 cyx = refmpn_mul_1 (dx+1, s1, size, xlimb);
174 cyy = mpn_mul_1 (dy+1, s1, size, xlimb);
177 printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx);
178 mpn_print (dx+1, size);
179 printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy);
180 mpn_print (dy+1, size);
184 if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0
185 || dx[size+1] != 0x12345678 || dx[0] != 0x87654321)
188 printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx);
189 mpn_print (dx+1, size);
190 printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy);
191 mpn_print (dy+1, size);
199 mpn_print (mp_ptr p, mp_size_t size)
203 for (i = size - 1; i >= 0; i--)
205 printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]);