From 12c83b340d311eeb45a679afbeb70a81b1b93669 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sun, 23 Jan 2022 15:20:07 +0300 Subject: [PATCH] Remove built_function With today's branch prediction techniques, it's hardly useful. --- Utilities/JIT.h | 94 ---------------------------- Utilities/Thread.cpp | 2 +- rpcs3/Emu/Cell/PPUFunction.cpp | 2 +- rpcs3/Emu/Cell/PPUThread.cpp | 6 +- rpcs3/Emu/Cell/SPURecompiler.cpp | 2 +- rpcs3/Emu/Cell/SPURecompiler.h | 3 +- rpcs3/Emu/Cell/SPUThread.cpp | 6 +- rpcs3/Emu/Memory/vm.cpp | 2 +- rpcs3/Emu/RSX/Common/BufferUtils.cpp | 5 +- rpcs3/Emu/RSX/Common/BufferUtils.h | 5 +- rpcs3/util/simd.hpp | 2 +- 11 files changed, 17 insertions(+), 112 deletions(-) diff --git a/Utilities/JIT.h b/Utilities/JIT.h index 6d9a70e432..d18901dd1c 100644 --- a/Utilities/JIT.h +++ b/Utilities/JIT.h @@ -263,100 +263,6 @@ inline FT build_function_asm(std::string_view name, F&& builder) return reinterpret_cast(uptr(result)); } -#if !defined(ARCH_X64) || defined(__APPLE__) -template -class built_function -{ - FT m_func; - -public: - built_function(const built_function&) = delete; - - built_function& operator=(const built_function&) = delete; - - template - built_function(std::string_view name, F&& builder, - u32 line = __builtin_LINE(), - u32 col = __builtin_COLUMN(), - const char* file = __builtin_FILE(), - const char* func = __builtin_FUNCTION()) - : m_func(ensure(build_function_asm(name, std::forward(builder)), const_str(), line, col, file, func)) - { - } - - operator FT() const noexcept - { - return m_func; - } - - template - auto operator()(Args&&... args) const noexcept - { - return m_func(std::forward(args)...); - } -}; -#else -template -class built_function -{ - alignas(4096) uchar m_data[Size]; - -public: - built_function(const built_function&) = delete; - - built_function& operator=(const built_function&) = delete; - - template - built_function(std::string_view name, F&& builder) - { - using namespace asmjit; - - inline_runtime rt(m_data, Size); - - CodeHolder code; - code.init(rt.environment()); - -#if defined(ARCH_X64) - native_args args; - #ifdef _WIN32 - args[0] = x86::rcx; - args[1] = x86::rdx; - args[2] = x86::r8; - args[3] = x86::r9; - #else - args[0] = x86::rdi; - args[1] = x86::rsi; - args[2] = x86::rdx; - args[3] = x86::rcx; - #endif -#elif defined(ARCH_ARM64) - native_args args; - args[0] = a64::x0; - args[1] = a64::x1; - args[2] = a64::x2; - args[3] = a64::x3; -#endif - - native_asm compiler(&code); - compiler.addEncodingOptions(EncodingOptions::kOptimizedAlign); - builder(compiler, args); - rt.dump_name = name; - jit_announce(rt._add(&code), code.codeSize(), name); - } - - operator FT() const noexcept - { - return FT(+m_data); - } - - template - auto operator()(Args&&... args) const noexcept - { - return FT(+m_data)(std::forward(args)...); - } -}; -#endif - #ifdef LLVM_AVAILABLE namespace llvm diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index a69985de98..87bb3a0f95 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -2250,7 +2250,7 @@ thread_base::native_entry thread_base::finalize(u64 _self) noexcept thread_base::native_entry thread_base::make_trampoline(u64(*entry)(thread_base* _base)) { - return build_function_asm("thread_base_trampoline", [&](native_asm& c, auto& args) + return build_function_asm("", [&](native_asm& c, auto& args) { using namespace asmjit; diff --git a/rpcs3/Emu/Cell/PPUFunction.cpp b/rpcs3/Emu/Cell/PPUFunction.cpp index 750058b5de..511881cf0d 100644 --- a/rpcs3/Emu/Cell/PPUFunction.cpp +++ b/rpcs3/Emu/Cell/PPUFunction.cpp @@ -1947,7 +1947,7 @@ u32 ppu_function_manager::add_function(ppu_intrp_func_t function) // Generate trampoline #if defined(ARCH_X64) - list2.push_back(build_function_asm("ppu_trampolinea", [&](native_asm& c, auto& args) + list2.push_back(build_function_asm("", [&](native_asm& c, auto& args) { using namespace asmjit; diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index 57f425c5e9..fa009d06a3 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -146,7 +146,7 @@ static void ppu_break(ppu_thread&, ppu_opcode_t, be_t*, ppu_intrp_func*); extern void do_cell_atomic_128_store(u32 addr, const void* to_write); -const auto ppu_gateway = built_function("ppu_gateway", [](native_asm& c, auto& args) +const auto ppu_gateway = build_function_asm("ppu_gateway", [](native_asm& c, auto& args) { // Gateway for PPU, converts from native to GHC calling convention, also saves RSP value for escape using namespace asmjit; @@ -268,7 +268,7 @@ const extern auto ppu_escape = build_function_asm("ppu_esc void ppu_recompiler_fallback(ppu_thread& ppu); #if defined(ARCH_X64) -const auto ppu_recompiler_fallback_ghc = build_function_asm("ppu_trampolineb", [](native_asm& c, auto& args) +const auto ppu_recompiler_fallback_ghc = build_function_asm("", [](native_asm& c, auto& args) { using namespace asmjit; @@ -1743,7 +1743,7 @@ extern u64 ppu_ldarx(ppu_thread& ppu, u32 addr) return ppu_load_acquire_reservation(ppu, addr); } -const auto ppu_stcx_accurate_tx = built_function("ppu_stcx_accurate_tx", [](native_asm& c, auto& args) +const auto ppu_stcx_accurate_tx = build_function_asm("ppu_stcx_accurate_tx", [](native_asm& c, auto& args) { using namespace asmjit; diff --git a/rpcs3/Emu/Cell/SPURecompiler.cpp b/rpcs3/Emu/Cell/SPURecompiler.cpp index b2e8db8246..64ba48884f 100644 --- a/rpcs3/Emu/Cell/SPURecompiler.cpp +++ b/rpcs3/Emu/Cell/SPURecompiler.cpp @@ -157,7 +157,7 @@ DECLARE(spu_runtime::tr_all) = [] return reinterpret_cast(trptr); }(); -DECLARE(spu_runtime::g_gateway) = built_function("spu_gateway", [](native_asm& c, auto& args) +DECLARE(spu_runtime::g_gateway) = build_function_asm("spu_gateway", [](native_asm& c, auto& args) { // Gateway for SPU dispatcher, converts from native to GHC calling convention, also saves RSP value for spu_escape using namespace asmjit; diff --git a/rpcs3/Emu/Cell/SPURecompiler.h b/rpcs3/Emu/Cell/SPURecompiler.h index 031e4d666c..551e73a13a 100644 --- a/rpcs3/Emu/Cell/SPURecompiler.h +++ b/rpcs3/Emu/Cell/SPURecompiler.h @@ -1,7 +1,6 @@ #pragma once #include "Utilities/File.h" -#include "Utilities/JIT.h" #include "Utilities/lockless.h" #include "SPUThread.h" #include @@ -133,7 +132,7 @@ public: static std::array, (1 << 20)>* const g_dispatcher; // Recompiler entry point - static const built_function g_gateway; + static const spu_function_t g_gateway; // Longjmp to the end of the gateway function (native CC) static void(*const g_escape)(spu_thread*); diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index deaec570b0..d112862f90 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -439,7 +439,7 @@ std::array op_branch_targets(u32 pc, spu_opcode_t op) return res; } -const auto spu_putllc_tx = built_function("spu_putllc_tx", [](native_asm& c, auto& args) +const auto spu_putllc_tx = build_function_asm("spu_putllc_tx", [](native_asm& c, auto& args) { using namespace asmjit; @@ -701,7 +701,7 @@ const auto spu_putllc_tx = built_function("spu_putlluc_tx", [](native_asm& c, auto& args) +const auto spu_putlluc_tx = build_function_asm("spu_putlluc_tx", [](native_asm& c, auto& args) { using namespace asmjit; @@ -831,7 +831,7 @@ const auto spu_putlluc_tx = built_function("spu_getllar_tx", [](native_asm& c, auto& args) +const auto spu_getllar_tx = build_function_asm("spu_getllar_tx", [](native_asm& c, auto& args) { using namespace asmjit; diff --git a/rpcs3/Emu/Memory/vm.cpp b/rpcs3/Emu/Memory/vm.cpp index 474ac84d3c..128de98ecb 100644 --- a/rpcs3/Emu/Memory/vm.cpp +++ b/rpcs3/Emu/Memory/vm.cpp @@ -7,11 +7,11 @@ #include "Utilities/mutex.h" #include "Utilities/Thread.h" #include "Utilities/address_range.h" +#include "Utilities/JIT.h" #include "Emu/CPU/CPUThread.h" #include "Emu/RSX/RSXThread.h" #include "Emu/Cell/SPURecompiler.h" #include "Emu/perf_meter.hpp" -#include #include #include diff --git a/rpcs3/Emu/RSX/Common/BufferUtils.cpp b/rpcs3/Emu/RSX/Common/BufferUtils.cpp index 1593f0d922..ddd93ba85d 100644 --- a/rpcs3/Emu/RSX/Common/BufferUtils.cpp +++ b/rpcs3/Emu/RSX/Common/BufferUtils.cpp @@ -5,6 +5,7 @@ #include "util/to_endian.hpp" #include "util/sysinfo.hpp" +#include "Utilities/JIT.h" #include "util/asm.hpp" #if defined(ARCH_X64) @@ -284,9 +285,9 @@ namespace #endif } -built_function copy_data_swap_u32("copy_data_swap_u32", &build_copy_data_swap_u32); +DECLARE(copy_data_swap_u32) = build_function_asm("copy_data_swap_u32", &build_copy_data_swap_u32); -built_function copy_data_swap_u32_cmp("copy_data_swap_u32_cmp", &build_copy_data_swap_u32); +DECLARE(copy_data_swap_u32_cmp) = build_function_asm("copy_data_swap_u32_cmp", &build_copy_data_swap_u32); namespace { diff --git a/rpcs3/Emu/RSX/Common/BufferUtils.h b/rpcs3/Emu/RSX/Common/BufferUtils.h index ad02e72f42..4ab11cc363 100644 --- a/rpcs3/Emu/RSX/Common/BufferUtils.h +++ b/rpcs3/Emu/RSX/Common/BufferUtils.h @@ -1,7 +1,6 @@ #pragma once #include "../gcm_enums.h" -#include "Utilities/JIT.h" #include @@ -51,7 +50,7 @@ void stream_vector(void *dst, u32 x, u32 y, u32 z, u32 w); void stream_vector_from_memory(void *dst, void *src); // Copy and swap data in 32-bit units -extern built_function copy_data_swap_u32; +extern void(*const copy_data_swap_u32)(u32*, const u32*, u32); // Copy and swap data in 32-bit units, return true if changed -extern built_function copy_data_swap_u32_cmp; +extern bool(*const copy_data_swap_u32_cmp)(u32*, const u32*, u32); diff --git a/rpcs3/util/simd.hpp b/rpcs3/util/simd.hpp index 54fcac8020..6d2e912e63 100644 --- a/rpcs3/util/simd.hpp +++ b/rpcs3/util/simd.hpp @@ -2265,7 +2265,7 @@ namespace utils #if defined(ARCH_X64) template -inline built_function<__m128(*)(__m128)> sse41_roundf("sse41_roundf", [](native_asm& c, native_args&) +const auto sse41_roundf = build_function_asm<__m128(*)(__m128)>("sse41_roundf", [](native_asm& c, native_args&) { static_assert(Mode < 4); using namespace asmjit;