SPU recompiler: minor optimization

This commit is contained in:
Nekotekina 2017-07-20 17:20:28 +03:00
parent b24eb621ae
commit 291ec1eeb2
3 changed files with 5 additions and 12 deletions

View File

@ -328,7 +328,7 @@ std::shared_ptr<spu_function_t> SPUDatabase::analyse(const be_t<u32>* ls, u32 en
m_db.emplace(key, func);
}
LOG_SUCCESS(SPU, "Function detected [0x%05x-0x%05x] (size=0x%x)", func->addr, func->addr + func->size, func->size);
LOG_NOTICE(SPU, "Function detected [0x%05x-0x%05x] (size=0x%x)", func->addr, func->addr + func->size, func->size);
return func;
}

View File

@ -5,6 +5,7 @@
#include "SPUThread.h"
#include "SPURecompiler.h"
#include "SPUASMJITRecompiler.h"
#include <algorithm>
extern u64 get_system_time();
@ -23,20 +24,12 @@ void spu_recompiler_base::enter(SPUThread& spu)
const auto _ls = vm::ps3::_ptr<u32>(spu.offset);
// Search if cached data matches
bool found = false;
auto func = spu.compiled_cache[spu.pc / 4];
if (func)
{
const be_t<u32>* base = _ls + spu.pc / 4;
if (std::memcmp(base, func->data.data(), func->size) == 0)
found = true;
}
// Check shared db if we dont have a match
if (!found)
if (!func || !std::equal(func->data.begin(), func->data.end(), _ls + spu.pc / 4, [](const be_t<u32>& l, const be_t<u32>& r) { return *(u32*)(u8*)&l == *(u32*)(u8*)&r; }))
{
func = spu.spu_db->analyse(_ls, spu.pc);
func = spu.spu_db->analyse(_ls, spu.pc).get();
spu.compiled_cache[spu.pc / 4] = func;
}

View File

@ -582,7 +582,7 @@ public:
std::exception_ptr pending_exception;
std::array<std::shared_ptr<struct spu_function_t>, 65536> compiled_cache;
std::array<struct spu_function_t*, 65536> compiled_cache{};
std::shared_ptr<class SPUDatabase> spu_db;
std::shared_ptr<class spu_recompiler_base> spu_rec;
u32 recursion_level = 0;