-
Notifications
You must be signed in to change notification settings - Fork 0
/
6_3_5.cpp
120 lines (112 loc) · 3.25 KB
/
6_3_5.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include"5_refactored_allcaches.cpp"
#include<vector>
#include<random>
#include<chrono>
using namespace std::chrono;
using std::vector;
using std::size_t;
using std::cout;
using std::endl;
constexpr int genpoly = 0x11d;
using GF2 = GF2Five::GF2<genpoly>;
auto makeRandomInts(int howmany){
vector<int> ret(howmany);
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<int> dis(1,214800000);
for(size_t i=0;i<howmany;++i){
ret[i]= dis(gen);
if(ret[i]%2==0) ret[i]--;
}
return ret;
}
auto makeRandomPairs(int howmany){
vector<GF2> ret(howmany);
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<int> dis(1,255);
for(size_t i=0;i<howmany;++i){
ret[i] = GF2(dis(gen));
}
return ret; // is RVO applied here?
}
int main(){
int howmany = 20000000;
auto testees = makeRandomPairs(howmany);
GF2 sum {GF2(1)};
for(size_t i=0;i<howmany;i++){
sum *= testees[i];
}
cout << "actual result of multiplication is:" << sum << endl;
GF2 sum1 {GF2(1)};
GF2 sum2 {GF2(1)};
GF2 sum3 {GF2(1)};
GF2 sum4 {GF2(1)};
GF2 sum5 {GF2(1)};
GF2 sum6 {GF2(1)};
GF2 sum7 {GF2(1)};
GF2 sum8 {GF2(1)};
GF2 sum9 {GF2(1)};
GF2 sum10 {GF2(1)};
GF2 sum11 {GF2(1)};
GF2 sum12 {GF2(1)};
GF2 sum13 {GF2(1)};
GF2 sum14 {GF2(1)};
GF2 sum15 {GF2(1)};
GF2 sum16 {GF2(1)};
GF2 sum17 {GF2(1)};
GF2 sum18 {GF2(1)};
GF2 sum19 {GF2(1)};
GF2 sum20 {GF2(1)};
GF2 sum21 {GF2(1)};
GF2 sum22 {GF2(1)};
GF2 sum23 {GF2(1)};
GF2 sum24 {GF2(1)};
GF2 sum25 {GF2(1)};
GF2 sum26 {GF2(1)};
GF2 sum27 {GF2(1)};
GF2 sum28 {GF2(1)};
GF2 sum29 {GF2(1)};
GF2 sum30 {GF2(1)};
GF2 sum31 {GF2(1)};
GF2 sum32 {GF2(1)};
auto aa = system_clock::now();
for(size_t i=0;i<howmany;i+=32){
sum1 *= testees[i];
sum2 *= testees[i+1];
sum3 *= testees[i+2];
sum4 *= testees[i+3];
sum5 *= testees[i+4];
sum6 *= testees[i+5];
sum7 *= testees[i+6];
sum8 *= testees[i+7];
sum9 *= testees[i+8];
sum10 *= testees[i+9];
sum11 *= testees[i+10];
sum12 *= testees[i+11];
sum13 *= testees[i+12];
sum14 *= testees[i+13];
sum15 *= testees[i+14];
sum16 *= testees[i+15];
sum17 *= testees[i+16];
sum18 *= testees[i+17];
sum19 *= testees[i+18];
sum20 *= testees[i+19];
sum21 *= testees[i+20];
sum22 *= testees[i+21];
sum23 *= testees[i+22];
sum24 *= testees[i+23];
sum25 *= testees[i+24];
sum26 *= testees[i+25];
sum27 *= testees[i+26];
sum28 *= testees[i+27];
sum29 *= testees[i+28];
sum30 *= testees[i+29];
sum31 *= testees[i+30];
sum32 *= testees[i+31];
}
sum1 = sum1*sum2*sum3*sum4*sum5*sum6*sum7*sum8*sum9*sum10*sum11*sum12*sum13*sum14*sum15*sum16*sum17*sum18*sum19*sum20*sum21*sum22*sum23*sum24*sum25*sum26*sum27*sum28*sum29*sum30*sum31*sum32;
auto bb = system_clock::now();
cout << "result(should be the same as above): " << sum1 << endl;
cout << duration_cast<microseconds>(bb-aa).count() << " us (loop unrolled manually)" << endl;
}