forked from asmjit/asmjit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasmjit_bench_x86.cpp
More file actions
146 lines (113 loc) · 3.84 KB
/
asmjit_bench_x86.cpp
File metadata and controls
146 lines (113 loc) · 3.84 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// [AsmJit]
// Complete x86/x64 JIT and Remote Assembler for C++.
//
// [License]
// Zlib - See LICENSE.md file in the package.
// [Dependencies]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "./asmjit.h"
#include "./asmjit_test_misc.h"
#include "./asmjit_test_opcode.h"
using namespace asmjit;
// ============================================================================
// [Configuration]
// ============================================================================
static const uint32_t kNumRepeats = 10;
static const uint32_t kNumIterations = 5000;
// ============================================================================
// [Performance]
// ============================================================================
struct Performance {
static inline uint32_t now() {
return OSUtils::getTickCount();
}
inline void reset() {
tick = 0;
best = 0xFFFFFFFF;
}
inline uint32_t start() { return (tick = now()); }
inline uint32_t diff() const { return now() - tick; }
inline uint32_t end() {
tick = diff();
if (best > tick)
best = tick;
return tick;
}
uint32_t tick;
uint32_t best;
};
static double mbps(uint32_t time, size_t outputSize) {
if (!time) return 0.0;
double bytesTotal = static_cast<double>(outputSize);
return (bytesTotal * 1000) / (static_cast<double>(time) * 1024 * 1024);
}
// ============================================================================
// [Main]
// ============================================================================
#if defined(ASMJIT_BUILD_X86)
static void benchX86(uint32_t archType) {
CodeHolder code;
Performance perf;
X86Assembler a;
X86Compiler cc;
uint32_t r, i;
const char* archName = archType == ArchInfo::kTypeX86 ? "X86" : "X64";
// --------------------------------------------------------------------------
// [Bench - Assembler]
// --------------------------------------------------------------------------
size_t asmOutputSize = 0;
size_t cmpOutputSize = 0;
perf.reset();
for (r = 0; r < kNumRepeats; r++) {
asmOutputSize = 0;
perf.start();
for (i = 0; i < kNumIterations; i++) {
code.init(CodeInfo(archType));
code.attach(&a);
asmtest::generateOpcodes(a);
asmOutputSize += code.getCodeSize();
code.reset(false); // Detaches `a`.
}
perf.end();
}
printf("%-12s (%s) | Time: %-6u [ms] | Speed: %7.3f [MB/s]\n",
"X86Assembler", archName, perf.best, mbps(perf.best, asmOutputSize));
// --------------------------------------------------------------------------
// [Bench - CodeBuilder]
// --------------------------------------------------------------------------
// TODO:
// --------------------------------------------------------------------------
// [Bench - CodeCompiler]
// --------------------------------------------------------------------------
perf.reset();
for (r = 0; r < kNumRepeats; r++) {
cmpOutputSize = 0;
perf.start();
for (i = 0; i < kNumIterations; i++) {
// NOTE: Since we don't have JitRuntime we don't know anything about
// function calling conventions, which is required by generateAlphaBlend.
// So we must setup this manually.
CodeInfo ci(archType);
ci.setCdeclCallConv(archType == ArchInfo::kTypeX86 ? CallConv::kIdX86CDecl : CallConv::kIdX86SysV64);
code.init(ci);
code.attach(&cc);
asmtest::generateAlphaBlend(cc);
cc.finalize();
cmpOutputSize += code.getCodeSize();
code.reset(false); // Detaches `cc`.
}
perf.end();
}
printf("%-12s (%s) | Time: %-6u [ms] | Speed: %7.3f [MB/s]\n",
"X86Compiler", archName, perf.best, mbps(perf.best, cmpOutputSize));
}
#endif
int main(int argc, char* argv[]) {
#if defined(ASMJIT_BUILD_X86)
benchX86(ArchInfo::kTypeX86);
benchX86(ArchInfo::kTypeX64);
#endif // ASMJIT_BUILD_X86
return 0;
}