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_submul_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;
89 /* The loop counter and index J goes from -SIZE to -1. This way
90 the loop becomes faster. */
93 /* Offset the base pointers to compensate for the negative indices. */
100 umul_ppmm (prod_high, prod_low, s1_ptr[j], s2_limb);
103 cy_limb = (prod_low < cy_limb) + prod_high;
106 prod_low = x - prod_low;
107 cy_limb += (prod_low > x);
108 res_ptr[j] = prod_low;
120 mp_limb_t dx[SIZE+2];
121 mp_limb_t dy[SIZE+2];
129 for (test = 0; ; test++)
132 size = (random () % SIZE + 1);
137 mpn_random2 (s1, size);
138 mpn_random2 (dy+1, size);
140 if (random () % 0x100 == 0)
143 mpn_random2 (&xlimb, 1);
145 dy[size+1] = 0x12345678;
148 #if defined (PRINT) || defined (XPRINT)
149 printf ("xlimb=%*lX\n", (int) (2 * sizeof(mp_limb_t)), xlimb);
152 mpn_print (dy+1, size);
153 mpn_print (s1, size);
156 MPN_COPY (dx, dy, size+2);
158 for (i = 0; i < TIMES; i++)
159 cyx = refmpn_submul_1 (dx+1, s1, size, xlimb);
162 printf ("refmpn_submul_1: %5ldms (%.2f cycles/limb)\n",
164 ((double) t * CLOCK) / (OPS * 1000.0));
167 MPN_COPY (dx, dy, size+2);
169 for (i = 0; i < TIMES; i++)
170 cyy = mpn_submul_1 (dx+1, s1, size, xlimb);
173 printf ("mpn_submul_1: %5ldms (%.2f cycles/limb)\n",
175 ((double) t * CLOCK) / (OPS * 1000.0));
178 MPN_COPY (dx, dy, size+2);
179 cyx = refmpn_submul_1 (dx+1, s1, size, xlimb);
180 cyy = mpn_submul_1 (dy+1, s1, size, xlimb);
183 printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx);
184 mpn_print (dx+1, size);
185 printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy);
186 mpn_print (dy+1, size);
190 if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0
191 || dx[size+1] != 0x12345678 || dx[0] != 0x87654321)
194 printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx);
195 mpn_print (dx+1, size);
196 printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy);
197 mpn_print (dy+1, size);
205 mpn_print (mp_ptr p, mp_size_t size)
209 for (i = size - 1; i >= 0; i--)
211 printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]);