Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
benchmarks_utils.h
Go to the documentation of this file.
1#ifndef BENCHMARKS_UTILS_C
2#define BENCHMARKS_UTILS_C
3
4#include <time.h>
5#include "cycle.h"
6#include "common/hal.h"
7#include <utilities.h>
8
9static inline void hal_init_perfcounters(int do_reset, int enable_divider);
10static unsigned long long get_nanos(void);
11static unsigned long long get_timestamp(void);
12
13
15
16static unsigned long long get_timestamp(void) {
17
18 unsigned long long timestamp = 0;
19#if (defined(CYCLES) && (defined(AARCH64) || defined(ARMV7l)))
20 timestamp = (unsigned long long) hal_get_time();
21#elif (defined(CYCLES) && defined(x8664))
22 timestamp = (unsigned long long) getticks();
23#elif defined(TIME)
24 timestamp = get_nanos();
25#endif
26 return timestamp;
27}
28
29
30static unsigned long long get_nanos(void)
31{
32 struct timespec ts;
33 timespec_get(&ts, TIME_UTC);
34 return (unsigned long long)ts.tv_sec * 1000000000ull + ts.tv_nsec;
35}
36
37void printStatisticsFile(const char* file_name, ticks* two_isogeny_walk, ticks* three_isogeny_walk) {
38
39 FILE* statsFile;
40 //char fileNameBuffer[100];
41 statsFile = fopen(file_name, "w+");
42
43 fprintf(statsFile, "No.,2-isogeny-walk,3-isogeny-walk\n");
44
45 for (int i = 0; i < NUMBER_OF_BENCHMARK_EXPERIMENTS; i++)
46 {
47 fprintf(statsFile, "%d,%llu,%llu\n", i, (unsigned long long)two_isogeny_walk[i], (unsigned long long)three_isogeny_walk[i]);
48 }
49
50 fclose(statsFile);
51
52}
53
54static inline void hal_init_perfcounters(int do_reset, int enable_divider)
55{
56
57#if defined(CYCLES)
58
59 #if defined(AARCH64)
60 printf("%d, %d\n", do_reset, enable_divider);
61 #elif defined(ARMV7l)
62
63 // in general enable all counters (including cycle counter)
64 int value = 1;
65
66 // perform reset:
67 if (do_reset)
68 {
69 value |= 2; // reset all counters to zero.
70 value |= 4; // reset cycle counter to zero.
71 }
72
73 if (enable_divider)
74 value |= 8; // enable "by 64" divider for CCNT.
75
76 value |= 16;
77
78 // program the performance-counter control-register:
79 asm volatile ("MCR p15, 0, %0, c9, c12, 0\t\n" :: "r"(value));
80
81 // enable all counters:
82 asm volatile ("MCR p15, 0, %0, c9, c12, 1\t\n" :: "r"(0x8000000f));
83
84 // clear overflows:
85 asm volatile ("MCR p15, 0, %0, c9, c12, 3\t\n" :: "r"(0x8000000f));
86
87#endif
88
89#endif
90}
91
92
93#endif
void printStatisticsFile(const char *file_name, ticks *two_isogeny_walk, ticks *three_isogeny_walk)
uint64_t hal_get_time()
Definition hal-cortexa.c:10
for i
#define NUMBER_OF_BENCHMARK_EXPERIMENTS
Definition utilities.h:15