Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
bench.c
Go to the documentation of this file.
1#if GLOBAL_COUNTERS != 0
2#include <time.h>
3#include <math.h>
4
5#include "csidh.h"
6#include "cycle.h"
7
8#define NUM_FUNCTIONS 7
9
10#if defined AVX2
11#define TYPE "AVX2"
12#elif defined GMP
13#ifdef KARATSUBA
14 #define TYPE "KARATSUBA"
15#else
16 #define TYPE "GMP"
17#endif
18#else
19#define TYPE "MULX"
20#endif
21
22#if defined P2047m1l226
23#define PRIME "I"
24
25#elif defined P4095m27l262
26#define PRIME "II"
27
28#elif defined P5119m46l244
29#define PRIME "III"
30
31#elif defined P6143m59l262
32#define PRIME "IV"
33
34#elif defined P8191m78l338
35#define PRIME "V"
36
37#elif defined P9215m85l389
38#define PRIME "VI"
39#else
40#error BITS must be 2047m1l226 or 4095m27l262 or 5119m46l244 or 6143m59l262 or 8191m78l338 or 9215m85l389
41#endif
42
43static inline void fp_inv_wrapper(fp c, const fp a, const fp b)
44{
45 (void)a;
46 (void)b;
47 fp_inv(c);
48}
49
50static inline void fp_sqr_wrapper(fp c, const fp a, const fp b)
51{
52 (void)b;
53 fp_sqr(c, a);
54}
55
56static inline void fp_issquare_wrapper(fp c, const fp a, const fp b)
57{
58 (void)a;
59 (void)b;
60 fp_issquare(c);
61}
62
63#if defined AVX2
64static inline void carry32_wrapper(fp c, const fp a, const fp b)
65{
66 int32_t carryover = 0;
67 (void) carryover;
68 (void)a;
69 (void)b;
70 carry32(c, NUMBER_OF_LIMBS, RADIX, &carryover);
71 // for(int i=0; i<NUMBER_OF_LIMBS; i++)
72 // c[i] = 67219975;
73 // for(int i=0; i<8; i++)
74 // c[i] += i << 26;
75 // carry32_avx2(c, 32);
76
77}
78#else
79static inline void carry32_wrapper(fp c, const fp a, const fp b)
80{
81 (void)a;
82 (void)b;
83 (void)c;
84}
85#endif
86
87int main(int argc, char *argv[])
88{
89 if (argc != 2)
90 {
91 printf("Usage: %s <iters>\n", argv[0]);
92 return 1;
93 }
94
95 int i, its = atoi(argv[1]); // number of iterations
96 if (its < 2)
97 {
98 printf("Number of iterations needs to be > 1\n");
99 return 1;
100 }
101
102 // --------------------------
103 // For measuring clock cycles
104 ticks cc_mean = 0;
105 ticks cc_sample[its], cc0, cc1;
106
107 uint64_t add_mean = 0, sqr_mean = 0, mul_mean = 0;
108
109 uint64_t add_sample[its],
110 sqr_sample[its],
111 mul_sample[its];
112
113 // todo : "struct it"
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"};
116
117 for (int j = 0; j < NUM_FUNCTIONS; j++)
118 {
119 for (i = 0; i < its; i++)
120 {
121 fp t0, t1, t2;
122 fp_random(t1);
123 fp_random(t2);
124 fp_random(t0);
125 init_counters();
126
127 cc0 = getticks();
128 (*fptr[j])(t0, t1, t2);
129 cc1 = getticks();
130
131 // ---------------------------------
132 // storing the measured clock cycles
133 cc_sample[i] = cc1 - cc0;
134 // Average value
135 cc_mean += cc_sample[i];
136
137 // storing the meausred running-time
138 add_sample[i] = fpadd;
139 sqr_sample[i] = fpsqr;
140 mul_sample[i] = fpmul;
141 // Average values
142 add_mean += add_sample[i];
143 sqr_mean += sqr_sample[i];
144 mul_mean += mul_sample[i];
145 };
146 // printf("[%3d%%] Done experiments\n", 100 * i / its);
147
148 cc_mean = cc_mean / its;
149 add_mean = add_mean / its;
150 sqr_mean = sqr_mean / its;
151 mul_mean = mul_mean / its;
152
153 printf("\\newcommand{\\res" TYPE PRIME "%s}{%2.lf}\n", fname[j], (1.0 * cc_mean));
154 }
155
156 return 0;
157}
158#else
159#include <stdio.h>
160
161int main(int argc, char *argv[])
162{
163 fprintf(stderr, "Benchmarking is disabled because it requires global counters.\n");
164
165 (void)argc; // suppress unused variable warnings
166 (void)argv; // suppress unused variable warnings
167
168 return 1;
169}
170#endif
int main(void)
Definition checkct.c:52
#define fp_sqr
Definition fp-gmp.h:73
uint64_t fp[NUMBER_OF_WORDS]
Definition fp-gmp.h:22
#define fp_sub
Definition fp-gmp.h:67
#define fp_mul
Definition fp-gmp.h:70
#define fp_inv
Definition fp-gmp.h:88
#define fp_issquare
Definition fp-gmp.h:76
#define fp_add
Definition fp-gmp.h:64
#define fp_random
Definition fp-gmp.h:85
for i
for j
f a
Definition to_model.m:12