This repository has been archived by the owner on Aug 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_inner.cpp
81 lines (67 loc) · 1.93 KB
/
main_inner.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include "main.h"
#include "src.h"
#ifndef CONFIG_SET
constexpr uint32_t BENCHES = 5;
constexpr uint32_t BENCHESMULT = 100000;
constexpr uint32_t n = 20;
constexpr uint32_t r = 30;
constexpr uint32_t m = 2;
constexpr uint32_t threads = 1;
// standard config.
// constexpr uint32_t s = 100;
// constexpr uint32_t t = 40;
// IMPORTANT. Make sure r is dividable by 3
constexpr uint32_t s = uint32_t(1) << r/3;
constexpr uint32_t t = uint32_t(1) << r/3;
#endif
static constexpr ConfigPrecompute configLegendre(n, r, s, t, m, threads);
static constexpr ConfigPrecomputeDLog configDLog(n, r, s, t, m, threads);
Precompute<configLegendre> leg;
PrecomputeDlog<configDLog> dlog;
void InnerFuntion() {
double ltime = 0., dtime = 0.;
#ifndef BENCHMODE
leg.info();
dlog.info();
#endif
leg.generate_instance ();
dlog.generate_instance();
// Some helper functions
mpz_t y, tmp;
mpz_init(y); mpz_init(tmp);
gmp_randstate_t rstate;
gmp_randinit_mt(rstate);
mpz_urandomb(y, rstate, r);
uint64_t as = leg.KeyedLegendreSequence(y, 0);
for (uint32_t i = 0; i < BENCHESMULT; i++) {
double t0 = ((double)clock()/CLOCKS_PER_SEC);
mpz_set(tmp, y);
leg.f(y, as);
mpz_add(y, y, tmp);
mpz_mod(y, y, leg.p);
as = leg.KeyedLegendreSequence(y, 0);
ltime += ((double)clock()/CLOCKS_PER_SEC) - t0;
}
for (uint32_t i = 0; i < BENCHESMULT; i++) {
double t1 = ((double)clock()/CLOCKS_PER_SEC);
mpz_powm(tmp, dlog.g, y, dlog.p);
mpz_mul(y, tmp, dlog.h[0]);
mpz_mod(y, y, dlog.p);
dlog.f(tmp, y);
dtime += ((double)clock()/CLOCKS_PER_SEC) - t1;
}
#ifdef BENCHMODE
std::cout << r << "," << BENCHESMULT << "," << ltime << "," << dtime << "\n";
#else
std::cout << "leg Time: " << ltime/BENCHESMULT << "\n";
std::cout << "log Time: " << dtime/BENCHESMULT << "\n";
std::cout << "coeff : " << ltime/dtime << " leg slower than log\n";
#endif
mpz_clear(y); mpz_clear(tmp);
gmp_randclear(rstate);
}
int main() {
InnerFuntion();
return 0;
}