mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-12-28 00:18:23 +00:00
spu_runtime::add minor optimization
Use preallocated vectors in trampoline generation subroutine
This commit is contained in:
parent
2b66abaf10
commit
58358e85dd
@ -7,6 +7,14 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
enum class jit_class
|
||||||
|
{
|
||||||
|
ppu_code,
|
||||||
|
ppu_data,
|
||||||
|
spu_code,
|
||||||
|
spu_data,
|
||||||
|
};
|
||||||
|
|
||||||
// ASMJIT runtime for emitting code in a single 2G region
|
// ASMJIT runtime for emitting code in a single 2G region
|
||||||
struct jit_runtime final : asmjit::HostRuntime
|
struct jit_runtime final : asmjit::HostRuntime
|
||||||
{
|
{
|
||||||
|
@ -257,6 +257,8 @@ spu_runtime::spu_runtime()
|
|||||||
fs::file(m_cache_path + "spu.log", fs::rewrite);
|
fs::file(m_cache_path + "spu.log", fs::rewrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
workload.reserve(250);
|
||||||
|
|
||||||
LOG_SUCCESS(SPU, "SPU Recompiler Runtime initialized...");
|
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;
|
where.second = compiled;
|
||||||
|
|
||||||
// Generate a dispatcher (übertrampoline)
|
// Generate a dispatcher (übertrampoline)
|
||||||
std::vector<u32> addrv{func[0]};
|
addrv[0] = func[0];
|
||||||
const auto beg = m_map.lower_bound(addrv);
|
const auto beg = m_map.lower_bound(addrv);
|
||||||
addrv[0] += 4;
|
addrv[0] += 4;
|
||||||
const auto _end = m_map.lower_bound(addrv);
|
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
|
else
|
||||||
{
|
{
|
||||||
// Allocate some writable executable memory
|
// 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
|
// Raw assembly pointer
|
||||||
u8* raw = wxptr;
|
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
|
// Write jump instruction with rel32 immediate
|
||||||
auto make_jump = [&](u8 op, auto target)
|
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;
|
raw += 4;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<work> workload;
|
workload.clear();
|
||||||
workload.reserve(size0);
|
workload.reserve(size0);
|
||||||
workload.emplace_back();
|
workload.emplace_back();
|
||||||
workload.back().size = size0;
|
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++)
|
for (std::size_t i = 0; i < workload.size(); i++)
|
||||||
{
|
{
|
||||||
// Get copy of the workload info
|
// Get copy of the workload info
|
||||||
work w = workload[i];
|
spu_runtime::work w = workload[i];
|
||||||
|
|
||||||
// Split range in two parts
|
// Split range in two parts
|
||||||
auto it = w.beg;
|
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));
|
g_dispatcher[func[0] / 4] = reinterpret_cast<spu_function_t>(reinterpret_cast<u64>(wxptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,22 @@ public:
|
|||||||
// Debug module output location
|
// Debug module output location
|
||||||
std::string m_cache_path;
|
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:
|
private:
|
||||||
|
// Scratch vector
|
||||||
|
std::vector<work> workload;
|
||||||
|
|
||||||
|
// Scratch vector
|
||||||
|
std::vector<u32> addrv{u32{0}};
|
||||||
|
|
||||||
// Trampoline to spu_recompiler_base::dispatch
|
// Trampoline to spu_recompiler_base::dispatch
|
||||||
spu_function_t tr_dispatch = nullptr;
|
spu_function_t tr_dispatch = nullptr;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user