1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2025-01-31 12:31:45 +01:00

SPU recs: implement spu_runtime::find

Use this function to link to existing functions from branch patchpoints.
Don't compile from branch patchpoints.
This commit is contained in:
Nekotekina 2019-03-18 19:40:51 +03:00
parent 31304f4234
commit 1880a17f79
2 changed files with 46 additions and 2 deletions

View File

@ -551,6 +551,42 @@ void spu_runtime::add(std::pair<const std::vector<u32>, spu_function_t>& where,
m_cond.notify_all();
}
spu_function_t spu_runtime::find(const se_t<u32, false>* ls, u32 addr)
{
std::unique_lock lock(m_mutex);
const u32 start = addr * (g_cfg.core.spu_block_size != spu_block_size_type::giga);
addrv[0] = addr;
const auto beg = m_map.lower_bound(addrv);
addrv[0] += 4;
const auto _end = m_map.lower_bound(addrv);
for (auto it = beg; it != _end; ++it)
{
bool bad = false;
for (u32 i = 1; i < it->first.size(); ++i)
{
const u32 x = it->first[i];
const u32 y = ls[start / 4 + i - 1];
if (x && x != y)
{
bad = true;
break;
}
}
if (!bad)
{
return it->second;
}
}
return nullptr;
}
spu_function_t spu_runtime::make_branch_patchpoint(u32 target) const
{
u8* const raw = jit_runtime::alloc(16, 16);
@ -649,8 +685,13 @@ void spu_recompiler_base::dispatch(spu_thread& spu, void*, u8* rip)
void spu_recompiler_base::branch(spu_thread& spu, void*, u8* rip)
{
// Compile (TODO: optimize search of the existing functions)
const auto func = verify(HERE, spu.jit->compile(spu.jit->block(spu._ptr<u32>(0), *(u16*)(rip + 6) * 4)));
// Find function
const auto func = spu.jit->get_runtime().find(spu._ptr<se_t<u32, false>>(0), *(u16*)(rip + 6) * 4);
if (!func)
{
return;
}
// Overwrite jump to this function with jump to the compiled function
const s64 rel = reinterpret_cast<u64>(func) - reinterpret_cast<u64>(rip) - 5;

View File

@ -76,6 +76,9 @@ public:
// Add compiled function and generate trampoline if necessary
void add(std::pair<const std::vector<u32>, spu_function_t>& where, spu_function_t compiled);
// Find existing function
spu_function_t find(const se_t<u32, false>* ls, u32 addr);
// Generate a patchable trampoline to spu_recompiler_base::branch
spu_function_t make_branch_patchpoint(u32 target) const;