1#if GLOBAL_COUNTERS != 0
14 #define TYPE "KARATSUBA"
22#if defined P2047m1l226
25#elif defined P4095m27l262
28#elif defined P5119m46l244
31#elif defined P6143m59l262
34#elif defined P8191m78l338
37#elif defined P9215m85l389
40#error BITS must be 2047m1l226 or 4095m27l262 or 5119m46l244 or 6143m59l262 or 8191m78l338 or 9215m85l389
43static inline void fp_inv_wrapper(
fp c,
const fp a,
const fp b)
50static inline void fp_sqr_wrapper(
fp c,
const fp a,
const fp b)
56static inline void fp_issquare_wrapper(
fp c,
const fp a,
const fp b)
64static inline void carry32_wrapper(
fp c,
const fp a,
const fp b)
66 int32_t carryover = 0;
70 carry32(c, NUMBER_OF_LIMBS, RADIX, &carryover);
79static inline void carry32_wrapper(
fp c,
const fp a,
const fp b)
87int main(
int argc,
char *argv[])
91 printf(
"Usage: %s <iters>\n", argv[0]);
95 int i, its = atoi(argv[1]);
98 printf(
"Number of iterations needs to be > 1\n");
105 ticks cc_sample[its], cc0, cc1;
107 uint64_t add_mean = 0, sqr_mean = 0, mul_mean = 0;
109 uint64_t add_sample[its],
114 void (*fptr[])(
fp c,
const fp a,
const fp b) = {
fp_add,
fp_sub,
fp_mul, fp_sqr_wrapper, carry32_wrapper, fp_inv_wrapper, fp_issquare_wrapper};
115 char * fname[NUM_FUNCTIONS] = {
"add",
"sub",
"mul",
"sqr",
"carry",
"inv",
"issquare"};
117 for (
int j = 0;
j < NUM_FUNCTIONS;
j++)
119 for (
i = 0;
i < its;
i++)
128 (*fptr[
j])(t0, t1, t2);
133 cc_sample[
i] = cc1 - cc0;
135 cc_mean += cc_sample[
i];
138 add_sample[
i] = fpadd;
139 sqr_sample[
i] = fpsqr;
140 mul_sample[
i] = fpmul;
142 add_mean += add_sample[
i];
143 sqr_mean += sqr_sample[
i];
144 mul_mean += mul_sample[
i];
148 cc_mean = cc_mean / its;
149 add_mean = add_mean / its;
150 sqr_mean = sqr_mean / its;
151 mul_mean = mul_mean / its;
153 printf(
"\\newcommand{\\res" TYPE PRIME
"%s}{%2.lf}\n", fname[
j], (1.0 * cc_mean));
161int main(
int argc,
char *argv[])
163 fprintf(stderr,
"Benchmarking is disabled because it requires global counters.\n");
uint64_t fp[NUMBER_OF_WORDS]