spu_runtime::add minor optimization

Use preallocated vectors in trampoline generation subroutine
This commit is contained in:
Nekotekina 2019-01-28 20:23:26 +03:00
parent 2b66abaf10
commit 58358e85dd
3 changed files with 30 additions and 13 deletions

View File

@ -7,6 +7,14 @@
#include <array>
#include <functional>
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
{

View File

@ -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<const std::vector<u32>, spu_function_t>& where,
where.second = compiled;
// Generate a dispatcher (übertrampoline)
std::vector<u32> 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<const std::vector<u32>, 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<std::vector<u32>, spu_function_t>::iterator beg;
std::map<std::vector<u32>, 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<const std::vector<u32>, spu_function_t>& where,
raw += 4;
};
std::vector<work> workload;
workload.clear();
workload.reserve(size0);
workload.emplace_back();
workload.back().size = size0;
@ -355,7 +348,7 @@ void spu_runtime::add(std::pair<const std::vector<u32>, 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<const std::vector<u32>, spu_function_t>& where,
}
}
workload.clear();
g_dispatcher[func[0] / 4] = reinterpret_cast<spu_function_t>(reinterpret_cast<u64>(wxptr));
}

View File

@ -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<std::vector<u32>, spu_function_t>::iterator beg;
std::map<std::vector<u32>, spu_function_t>::iterator end;
};
private:
// Scratch vector
std::vector<work> workload;
// Scratch vector
std::vector<u32> addrv{u32{0}};
// Trampoline to spu_recompiler_base::dispatch
spu_function_t tr_dispatch = nullptr;