From 58358e85ddc864d42de081307f13f49a256ced0d Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Mon, 28 Jan 2019 20:23:26 +0300 Subject: [PATCH] spu_runtime::add minor optimization Use preallocated vectors in trampoline generation subroutine --- Utilities/JIT.h | 8 ++++++++ rpcs3/Emu/Cell/SPURecompiler.cpp | 20 +++++++------------- rpcs3/Emu/Cell/SPURecompiler.h | 15 +++++++++++++++ 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/Utilities/JIT.h b/Utilities/JIT.h index 8060c86a5c..ce66a9dbc1 100644 --- a/Utilities/JIT.h +++ b/Utilities/JIT.h @@ -7,6 +7,14 @@ #include #include +enum class jit_class +{ + ppu_code, + ppu_data, + spu_code, + spu_data, +}; + // ASMJIT runtime for emitting code in a single 2G region struct jit_runtime final : asmjit::HostRuntime { diff --git a/rpcs3/Emu/Cell/SPURecompiler.cpp b/rpcs3/Emu/Cell/SPURecompiler.cpp index 261ef759ac..1093309afe 100644 --- a/rpcs3/Emu/Cell/SPURecompiler.cpp +++ b/rpcs3/Emu/Cell/SPURecompiler.cpp @@ -257,6 +257,8 @@ spu_runtime::spu_runtime() fs::file(m_cache_path + "spu.log", fs::rewrite); } + workload.reserve(250); + LOG_SUCCESS(SPU, "SPU Recompiler Runtime initialized..."); } @@ -274,7 +276,7 @@ void spu_runtime::add(std::pair, spu_function_t>& where, where.second = compiled; // Generate a dispatcher (übertrampoline) - std::vector addrv{func[0]}; + addrv[0] = func[0]; const auto beg = m_map.lower_bound(addrv); addrv[0] += 4; const auto _end = m_map.lower_bound(addrv); @@ -287,20 +289,11 @@ void spu_runtime::add(std::pair, spu_function_t>& where, else { // Allocate some writable executable memory - u8* const wxptr = jit_runtime::alloc(size0 * 20, 16); + u8* const wxptr = verify(HERE, jit_runtime::alloc(size0 * 20, 16)); // Raw assembly pointer u8* raw = wxptr; - struct work - { - u32 size; - u32 level; - u8* rel32; - std::map, spu_function_t>::iterator beg; - std::map, spu_function_t>::iterator end; - }; - // Write jump instruction with rel32 immediate auto make_jump = [&](u8 op, auto target) { @@ -343,7 +336,7 @@ void spu_runtime::add(std::pair, spu_function_t>& where, raw += 4; }; - std::vector workload; + workload.clear(); workload.reserve(size0); workload.emplace_back(); workload.back().size = size0; @@ -355,7 +348,7 @@ void spu_runtime::add(std::pair, spu_function_t>& where, for (std::size_t i = 0; i < workload.size(); i++) { // Get copy of the workload info - work w = workload[i]; + spu_runtime::work w = workload[i]; // Split range in two parts auto it = w.beg; @@ -523,6 +516,7 @@ void spu_runtime::add(std::pair, spu_function_t>& where, } } + workload.clear(); g_dispatcher[func[0] / 4] = reinterpret_cast(reinterpret_cast(wxptr)); } diff --git a/rpcs3/Emu/Cell/SPURecompiler.h b/rpcs3/Emu/Cell/SPURecompiler.h index 10f3cbbced..3dc3d54328 100644 --- a/rpcs3/Emu/Cell/SPURecompiler.h +++ b/rpcs3/Emu/Cell/SPURecompiler.h @@ -47,7 +47,22 @@ public: // Debug module output location std::string m_cache_path; + // Trampoline generation workload helper + struct work + { + u32 size; + u32 level; + u8* rel32; + std::map, spu_function_t>::iterator beg; + std::map, spu_function_t>::iterator end; + }; private: + // Scratch vector + std::vector workload; + + // Scratch vector + std::vector addrv{u32{0}}; + // Trampoline to spu_recompiler_base::dispatch spu_function_t tr_dispatch = nullptr;