SPU: minor optimization

This commit is contained in:
Nekotekina 2017-07-29 16:07:03 +03:00
parent aeb01bd216
commit f564a72d03
3 changed files with 7 additions and 7 deletions

View File

@ -5,7 +5,7 @@
const spu_decoder<spu_itype> s_spu_itype;
std::shared_ptr<spu_function_t> SPUDatabase::find(const be_t<u32>* data, u64 key, u32 max_size)
spu_function_t* SPUDatabase::find(const be_t<u32>* data, u64 key, u32 max_size)
{
for (auto found = m_db.equal_range(key); found.first != found.second; found.first++)
{
@ -14,7 +14,7 @@ std::shared_ptr<spu_function_t> SPUDatabase::find(const be_t<u32>* data, u64 key
// Compare binary data explicitly (TODO: optimize)
if (LIKELY(func->size <= max_size) && std::memcmp(func->data.data(), data, func->size) == 0)
{
return func;
return func.get();
}
}
@ -33,7 +33,7 @@ SPUDatabase::~SPUDatabase()
// TODO: serialize database
}
std::shared_ptr<spu_function_t> SPUDatabase::analyse(const be_t<u32>* ls, u32 entry, u32 max_limit)
spu_function_t* SPUDatabase::analyse(const be_t<u32>* ls, u32 entry, u32 max_limit)
{
// Check arguments (bounds and alignment)
if (max_limit > 0x40000 || entry >= max_limit || entry % 4 || max_limit % 4)
@ -330,5 +330,5 @@ std::shared_ptr<spu_function_t> SPUDatabase::analyse(const be_t<u32>* ls, u32 en
LOG_NOTICE(SPU, "Function detected [0x%05x-0x%05x] (size=0x%x)", func->addr, func->addr + func->size, func->size);
return func;
return func.get();
}

View File

@ -289,12 +289,12 @@ class SPUDatabase final : spu_itype
std::unordered_multimap<u64, std::shared_ptr<spu_function_t>> m_db;
// For internal use
std::shared_ptr<spu_function_t> find(const be_t<u32>* data, u64 key, u32 max_size);
spu_function_t* find(const be_t<u32>* data, u64 key, u32 max_size);
public:
SPUDatabase();
~SPUDatabase();
// Try to retrieve SPU function information
std::shared_ptr<spu_function_t> analyse(const be_t<u32>* ls, u32 entry, u32 limit = 0x40000);
spu_function_t* analyse(const be_t<u32>* ls, u32 entry, u32 limit = 0x40000);
};

View File

@ -29,7 +29,7 @@ void spu_recompiler_base::enter(SPUThread& spu)
// Check shared db if we dont have a match
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).get();
func = spu.spu_db->analyse(_ls, spu.pc);
spu.compiled_cache[spu.pc / 4] = func;
}