-
Notifications
You must be signed in to change notification settings - Fork 63
/
matt-benches.cpp
96 lines (74 loc) · 2 KB
/
matt-benches.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
/*
* default_benches.cpp
*
* Various "default" benchmarks.
*/
#include "benchmark.hpp"
#include "util.hpp"
#if !UARCH_BENCH_PORTABLE
#define BUF_SIZE (64*1024)
static char buf[BUF_SIZE];
void __clear_mov_imm(void *addr)
{
long __d0;
asm volatile("movq $0,(%[dst])\n"
: [dst] "=&D" (__d0)
: "[dst]"(addr));
}
void __clear_mov_reg(void *addr)
{
long __d0;
asm volatile("movq %[zero],(%[dst])\n"
: [dst] "=&D" (__d0)
: "[dst]"(addr), [zero] "r" (0UL));
}
HEDLEY_NEVER_INLINE
long BM_mov_reg(uint64_t iters, void *arg) {
do {
__clear_mov_reg(buf);
} while (--iters);
return 0;
}
HEDLEY_NEVER_INLINE
long BM_mov_imm(uint64_t iters, void *arg) {
do {
__clear_mov_imm(buf);
} while (--iters);
return 0;
}
HEDLEY_NEVER_INLINE
long BM_mov_reg_inline(uint64_t iters, void *arg) {
do {
long __d0;
asm volatile("movq %[zero],(%[dst])\n"
: [dst] "=&D" (__d0)
: "[dst]"(buf), [zero] "r" (0UL));
} while (--iters);
return 0;
}
HEDLEY_NEVER_INLINE
long BM_mov_imm_inline(uint64_t iters, void *arg) {
do {
long __d0;
asm volatile("movq $0,(%[dst])\n"
: [dst] "=&D" (__d0)
: "[dst]"(buf));
} while (--iters);
return 0;
}
template <typename TIMER>
void register_matt(GroupList& list) {
std::shared_ptr<BenchmarkGroup> group = std::make_shared<BenchmarkGroup>("misc/matt", "From Twitter");
auto maker = DeltaMaker<TIMER>(group.get(), 100 * 1000);
maker.template make<BM_mov_reg>("BM_mov_reg", "BM_mov_reg", 1);
maker.template make<BM_mov_imm>("BM_mov_imm", "BM_mov_imm", 1);
maker.template make<BM_mov_reg_inline>("BM_mov_reg_inline", "BM_mov_reg_inline", 1);
maker.template make<BM_mov_imm_inline>("BM_mov_imm_inline", "BM_mov_imm_inline", 1);
list.push_back(group);
}
#else // #if !UARCH_BENCH_PORTABLE
template <typename TIMER>
void register_matt(GroupList& list) {}
#endif
#define REG_MATT(CLOCK) template void register_matt<CLOCK>(GroupList& list);
ALL_TIMERS_X(REG_MATT)