-
Notifications
You must be signed in to change notification settings - Fork 1
/
avxSpeed.cpp
80 lines (65 loc) · 1.56 KB
/
avxSpeed.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
// #define DIV
using Float = float;
// using Float = double;
namespace {
inline
Float _sum0(Float const * x,
Float const * y, Float const * z, int n) {
Float sum=0;
#pragma GCC ivdep
for (int i=0; i!=n; ++i)
#ifdef DIV
sum += z[i]+x[i]/y[i];
#else
sum += z[i]+x[i]*y[i];
#endif
return sum;
}
}
Float __attribute__ ((target ("default")))
sum(Float const * x, Float const * y, Float const * z, int n) {
return _sum0(x,y,z,n);
}
Float __attribute__ ((__target__ ("skylake")))
sum(Float const * x, Float const * y, Float const * z, int n) {
return _sum0(x,y,z,n);
}
Float __attribute__ ((__target__ ("arch=haswell")))
sum(Float const * x, Float const * y, Float const * z, int n) {
return _sum0(x,y,z,n);
}
Float __attribute__ ((__target__ ("arch=sandybridge")))
sum(Float const * x,
Float const * y, Float const * z, int n) {
return _sum0(x,y,z,n);
}
Float __attribute__ ((__target__ ("arch=nehalem")))
sum(Float const * x, Float const * y, Float const * z, int n) {
return _sum0(x,y,z,n);
}
#include<cstdlib>
#include <fstream>
#include <iostream>
int main(int npar, char * par[]) {
Float s=0;
alignas(32) Float x[10240],y[10240],z[10240];
for (int i=0; i!=10240; ++i)
x[i]=y[i]=z[i]=(1+i)*0.1;
while (1) {
{
std::ifstream in("endAvx");
if (in) return 0;
in.close();
}
std::ifstream in("goAvx");
if(in) {
for (int i=0; i<1000; ++i)
s += sum(x,y,z,10240);
} else {
for (int i=0; i<1000; ++i)
s += _sum0(x,y,z,10240);
}
in.close();
}
return 0;
}