// This file is part of AsmJit project // // See asmjit.h or LICENSE.md for license and copyright information // SPDX-License-Identifier: Zlib #include #if !defined(ASMJIT_NO_X86) #include #endif // !ASMJIT_NO_X86 #if !defined(ASMJIT_NO_AARCH64) #include #endif // !ASMJIT_NO_AARCH64 #include #if !defined(ASMJIT_NO_COMPILER) #include #include #include #endif #include #include #include #include #include using namespace asmjit; static void print_app_info() { printf("AsmJit Benchmark RegAlloc v%u.%u.%u [Arch=%s] [Mode=%s]\n\n", unsigned((ASMJIT_LIBRARY_VERSION >> 16) ), unsigned((ASMJIT_LIBRARY_VERSION >> 8) & 0xFF), unsigned((ASMJIT_LIBRARY_VERSION ) & 0xFF), asmjit_arch_as_string(Arch::kHost), asmjit_build_type() ); } #if !defined(ASMJIT_NO_COMPILER) class BenchRegAllocApp { public: const char* _arch = nullptr; bool _help_only = false; bool _verbose = false; uint32_t _maximum_complexity = 65536; BenchRegAllocApp() noexcept : _arch("all") {} ~BenchRegAllocApp() noexcept {} template inline void add_t() { T::add(*this); } int handle_args(int argc, const char* const* argv); void show_info(); bool should_run_arch(Arch arch) const noexcept; void emit_code(BaseCompiler* cc, uint32_t complexity, uint32_t reg_count); #if !defined(ASMJIT_NO_X86) void emit_code_x86(x86::Compiler* cc, uint32_t complexity, uint32_t reg_count); #endif // !ASMJIT_NO_X86 #if !defined(ASMJIT_NO_AARCH64) void emit_code_aarch64(a64::Compiler* cc, uint32_t complexity, uint32_t reg_count); #endif // !ASMJIT_NO_AARCH64 int run(); bool run_arch(Arch arch); }; int BenchRegAllocApp::handle_args(int argc, const char* const* argv) { CmdLine cmd(argc, argv); _arch = cmd.value_of("--arch", "all"); _maximum_complexity = cmd.value_as_uint("--complexity", _maximum_complexity); if (cmd.has_arg("--help")) _help_only = true; if (cmd.has_arg("--verbose")) _verbose = true; return 0; } void BenchRegAllocApp::show_info() { print_app_info(); printf("Usage:\n"); printf(" asmjit_bench_regalloc [arguments]\n"); printf("\n"); printf("Arguments:\n"); printf(" --help Show usage only\n"); printf(" --arch= Select architecture to run ('all' by default)\n"); printf(" --verbose Verbose output\n"); printf(" --complexity= Maximum complexity to test (%u)\n", _maximum_complexity); printf("\n"); printf("Architectures:\n"); #if !defined(ASMJIT_NO_X86) printf(" --arch=x86 32-bit X86 architecture (X86)\n"); printf(" --arch=x64 64-bit X86 architecture (X86_64)\n"); #endif #if !defined(ASMJIT_NO_AARCH64) printf(" --arch=aarch64 64-bit ARM architecture (AArch64)\n"); #endif printf("\n"); } bool BenchRegAllocApp::should_run_arch(Arch arch) const noexcept { if (strcmp(_arch, "all") == 0) { return true; } if (strcmp(_arch, "x86") == 0 && arch == Arch::kX86) { return true; } if (strcmp(_arch, "x64") == 0 && arch == Arch::kX64) { return true; } if (strcmp(_arch, "aarch64") == 0 && arch == Arch::kAArch64) { return true; } return false; } void BenchRegAllocApp::emit_code(BaseCompiler* cc, uint32_t complexity, uint32_t reg_count) { #if !defined(ASMJIT_NO_X86) if (cc->arch() == Arch::kX86 || cc->arch() == Arch::kX64) { emit_code_x86(cc->as(), complexity, reg_count); } #endif #if !defined(ASMJIT_NO_AARCH64) if (cc->arch() == Arch::kAArch64) { emit_code_aarch64(cc->as(), complexity, reg_count); } #endif } constexpr size_t kLocalRegCount = 3; constexpr size_t kLocalOpCount = 15; #if !defined(ASMJIT_NO_X86) void BenchRegAllocApp::emit_code_x86(x86::Compiler* cc, uint32_t complexity, uint32_t reg_count) { TestUtils::Random rnd(0x1234); std::vector