-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
slow_sin3.cpp
66 lines (56 loc) · 1.02 KB
/
slow_sin3.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
/*
fast
cl /EHsc /Ox /fp:fast slow_sin3.cpp
second bench is slow
cl /EHsc /Ox /fp:fast /arch:AVX slow_sin3.cpp
*/
#include <stdio.h>
#include <math.h>
#include <time.h>
#ifdef USE_XBYAK
#define XBYAK_NO_OP_NAMES
#include <xbyak/xbyak.h>
#endif
void bench()
{
double x = 1;
double begin = clock();
for (int i = 0; i < 50000000; i++) {
x = sin(x + 0.5);
}
double end = clock();
printf("%.2fsec %f\n", (end - begin) / CLOCKS_PER_SEC, x);
}
static float a[8];
#ifdef USE_XBYAK
const struct Code : Xbyak::CodeGenerator {
Code()
{
vzeroupper();
ret();
}
} code;
void (*call_vzeroupper)() = code.getCode<void (*)()>();
#endif
int main(int argc, char *[])
{
bench();
/*
this generates an optimized code using vinsertf128 without vzeroupper
under /arch:AVX option .
Therefore, second bench() is slow.
*/
float x = (float)argc;
for (int i = 0; i < 8; i++) {
a[i] = x;
}
#ifdef USE_XBYAK
if (argc == 1) {
puts("not call vzeroupper");
} else {
puts("call vzeroupper");
call_vzeroupper();
}
#endif
bench();
}