mirror of
https://github.com/asmjit/asmjit.git
synced 2025-12-18 13:04:36 +03:00
AsmJit cleanup and refactoring
This commit is contained in:
@@ -37,7 +37,7 @@ using namespace asmjit;
|
||||
// [Configuration]
|
||||
// ============================================================================
|
||||
|
||||
static constexpr uint32_t kNumRepeats = 25;
|
||||
static constexpr uint32_t kNumRepeats = 20;
|
||||
static constexpr uint32_t kNumIterations = 1000;
|
||||
|
||||
// ============================================================================
|
||||
@@ -80,12 +80,12 @@ namespace BenchUtils {
|
||||
}
|
||||
|
||||
template<typename EmitterT, typename FuncT>
|
||||
static void bench(CodeHolder& code, uint32_t archId, const char* testName, const FuncT& func) noexcept {
|
||||
static void bench(CodeHolder& code, uint32_t arch, const char* testName, const FuncT& func) noexcept {
|
||||
EmitterT emitter;
|
||||
|
||||
const char* archName =
|
||||
archId == ArchInfo::kIdX86 ? "X86" :
|
||||
archId == ArchInfo::kIdX64 ? "X64" : "???";
|
||||
arch == Environment::kArchX86 ? "X86" :
|
||||
arch == Environment::kArchX64 ? "X64" : "???";
|
||||
|
||||
const char* emitterName =
|
||||
emitter.isAssembler() ? "Assembler" :
|
||||
@@ -95,14 +95,13 @@ namespace BenchUtils {
|
||||
Performance perf;
|
||||
uint64_t codeSize = 0;
|
||||
|
||||
CodeInfo codeInfo(archId);
|
||||
codeInfo.setCdeclCallConv(archId == ArchInfo::kIdX86 ? CallConv::kIdX86CDecl : CallConv::kIdX86SysV64);
|
||||
Environment env(arch);
|
||||
|
||||
for (uint32_t r = 0; r < kNumRepeats; r++) {
|
||||
perf.start();
|
||||
codeSize = 0;
|
||||
for (uint32_t i = 0; i < kNumIterations; i++) {
|
||||
code.init(codeInfo);
|
||||
code.init(env);
|
||||
code.attach(&emitter);
|
||||
|
||||
func(emitter);
|
||||
@@ -113,7 +112,7 @@ namespace BenchUtils {
|
||||
perf.end();
|
||||
}
|
||||
|
||||
printf("[%s] %-9s %-8s | Time:%6u [ms] | ", archName, emitterName, testName, perf.best);
|
||||
printf("[%s] %-9s %-10s | Time:%6u [ms] | ", archName, emitterName, testName, perf.best);
|
||||
if (codeSize)
|
||||
printf("Speed: %7.3f [MB/s]", mbps(perf.best, codeSize));
|
||||
else
|
||||
@@ -127,30 +126,35 @@ namespace BenchUtils {
|
||||
// ============================================================================
|
||||
|
||||
#ifdef ASMJIT_BUILD_X86
|
||||
static void benchX86(uint32_t archId) noexcept {
|
||||
static void benchX86(uint32_t arch) noexcept {
|
||||
CodeHolder code;
|
||||
|
||||
BenchUtils::bench<x86::Assembler>(code, archId, "[raw]", [](x86::Assembler& a) {
|
||||
BenchUtils::bench<x86::Assembler>(code, arch, "[fast]", [](x86::Assembler& a) {
|
||||
asmtest::generateOpcodes(a.as<x86::Emitter>());
|
||||
});
|
||||
|
||||
BenchUtils::bench<x86::Assembler>(code, arch, "[validate]", [](x86::Assembler& a) {
|
||||
a.addValidationOptions(BaseEmitter::kValidationOptionAssembler);
|
||||
asmtest::generateOpcodes(a.as<x86::Emitter>());
|
||||
});
|
||||
|
||||
#ifndef ASMJIT_NO_BUILDER
|
||||
BenchUtils::bench<x86::Builder>(code, archId, "[raw]", [](x86::Builder& cb) {
|
||||
BenchUtils::bench<x86::Builder>(code, arch, "[no-asm]", [](x86::Builder& cb) {
|
||||
asmtest::generateOpcodes(cb.as<x86::Emitter>());
|
||||
});
|
||||
|
||||
BenchUtils::bench<x86::Builder>(code, archId, "[final]", [](x86::Builder& cb) {
|
||||
BenchUtils::bench<x86::Builder>(code, arch, "[asm]", [](x86::Builder& cb) {
|
||||
asmtest::generateOpcodes(cb.as<x86::Emitter>());
|
||||
cb.finalize();
|
||||
});
|
||||
#endif
|
||||
|
||||
#ifndef ASMJIT_NO_COMPILER
|
||||
BenchUtils::bench<x86::Compiler>(code, archId, "[raw]", [](x86::Compiler& cc) {
|
||||
BenchUtils::bench<x86::Compiler>(code, arch, "[no-asm]", [](x86::Compiler& cc) {
|
||||
asmtest::generateAlphaBlend(cc);
|
||||
});
|
||||
|
||||
BenchUtils::bench<x86::Compiler>(code, archId, "[final]", [](x86::Compiler& cc) {
|
||||
BenchUtils::bench<x86::Compiler>(code, arch, "[asm]", [](x86::Compiler& cc) {
|
||||
asmtest::generateAlphaBlend(cc);
|
||||
cc.finalize();
|
||||
});
|
||||
@@ -160,8 +164,8 @@ static void benchX86(uint32_t archId) noexcept {
|
||||
|
||||
int main() {
|
||||
#ifdef ASMJIT_BUILD_X86
|
||||
benchX86(ArchInfo::kIdX86);
|
||||
benchX86(ArchInfo::kIdX64);
|
||||
benchX86(Environment::kArchX86);
|
||||
benchX86(Environment::kArchX64);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user