7 #include <sys/resource.h>
15 return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000;
20 #ifndef CLOCKS_PER_SEC
21 #define CLOCKS_PER_SEC 1000000
24 #if CLOCKS_PER_SEC >= 10000
25 #define CLOCK_TO_MILLISEC(cl) ((cl) / (CLOCKS_PER_SEC / 1000))
27 #define CLOCK_TO_MILLISEC(cl) ((cl) * 1000 / CLOCKS_PER_SEC)
33 return CLOCK_TO_MILLISEC (clock ());
40 #if defined (__m88k__)
42 #elif defined (__i386__)
43 #define CLOCK (16.666667 M)
44 #elif defined (__m68k__)
46 #elif defined (_IBMR2)
48 #elif defined (__sparc__)
50 #elif defined (__sun__)
52 #elif defined (__mips)
54 #elif defined (__hppa__)
56 #elif defined (__alpha)
59 #error "Don't know CLOCK of your machine"
70 #define TIMES OPS/SIZE
73 #define OPS (SIZE*TIMES)
79 refmpn_sub_n (mp_ptr res_ptr,
80 mp_srcptr s1_ptr, mp_srcptr s2_ptr, mp_size_t size)
82 refmpn_sub_n (res_ptr, s1_ptr, s2_ptr, size)
83 register mp_ptr res_ptr;
84 register mp_srcptr s1_ptr;
85 register mp_srcptr s2_ptr;
89 register mp_limb_t x, y, cy;
92 /* The loop counter and index J goes from -SIZE to -1. This way
93 the loop becomes faster. */
96 /* Offset the base pointers to compensate for the negative indices. */
106 y += cy; /* add previous carry to subtrahend */
107 cy = (y < cy); /* get out carry from that addition */
108 y = x - y; /* main subtract */
109 cy = (y > x) + cy; /* get out carry from the subtract, combine */
123 mp_limb_t dx[SIZE+1];
124 mp_limb_t dy[SIZE+1];
131 for (test = 0; ; test++)
134 size = (random () % SIZE + 1);
139 mpn_random2 (s1, size);
140 mpn_random2 (s2, size);
142 dx[size] = 0x12345678;
143 dy[size] = 0x12345678;
146 mpn_print (s1, size);
147 mpn_print (s2, size);
150 for (i = 0; i < TIMES; i++)
151 cyx = refmpn_sub_n (dx, s1, s2, size);
154 printf ("refmpn_sub_n: %ldms (%.2f cycles/limb)\n",
156 ((double) t * CLOCK) / (OPS * 1000.0));
159 printf ("%d ", cyx); mpn_print (dx, size);
163 for (i = 0; i < TIMES; i++)
164 cyx = mpn_sub_n (dx, s1, s2, size);
167 printf ("mpn_sub_n: %ldms (%.2f cycles/limb)\n",
169 ((double) t * CLOCK) / (OPS * 1000.0));
172 printf ("%d ", cyx); mpn_print (dx, size);
176 /* Put garbage in the destination. */
177 for (i = 0; i < size; i++)
183 cyx = refmpn_sub_n (dx, s1, s2, size);
184 cyy = mpn_sub_n (dy, s1, s2, size);
185 if (cyx != cyy || mpn_cmp (dx, dy, size) != 0
186 || dx[size] != 0x12345678 || dy[size] != 0x12345678)
189 printf ("%d ", cyx); mpn_print (dx, size);
190 printf ("%d ", cyy); mpn_print (dy, size);
198 mpn_print (mp_ptr p, mp_size_t size)
202 for (i = size - 1; i >= 0; i--)
204 printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]);