Skip to content

Commit 291ec1e

Browse files
committed
SPU recompiler: minor optimization
1 parent b24eb62 commit 291ec1e

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

rpcs3/Emu/Cell/SPUAnalyser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ std::shared_ptr<spu_function_t> SPUDatabase::analyse(const be_t<u32>* ls, u32 en
328328
m_db.emplace(key, func);
329329
}
330330

331-
LOG_SUCCESS(SPU, "Function detected [0x%05x-0x%05x] (size=0x%x)", func->addr, func->addr + func->size, func->size);
331+
LOG_NOTICE(SPU, "Function detected [0x%05x-0x%05x] (size=0x%x)", func->addr, func->addr + func->size, func->size);
332332

333333
return func;
334334
}

rpcs3/Emu/Cell/SPURecompiler.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "SPUThread.h"
66
#include "SPURecompiler.h"
77
#include "SPUASMJITRecompiler.h"
8+
#include <algorithm>
89

910
extern u64 get_system_time();
1011

@@ -23,20 +24,12 @@ void spu_recompiler_base::enter(SPUThread& spu)
2324
const auto _ls = vm::ps3::_ptr<u32>(spu.offset);
2425

2526
// Search if cached data matches
26-
bool found = false;
2727
auto func = spu.compiled_cache[spu.pc / 4];
2828

29-
if (func)
30-
{
31-
const be_t<u32>* base = _ls + spu.pc / 4;
32-
if (std::memcmp(base, func->data.data(), func->size) == 0)
33-
found = true;
34-
}
35-
3629
// Check shared db if we dont have a match
37-
if (!found)
30+
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; }))
3831
{
39-
func = spu.spu_db->analyse(_ls, spu.pc);
32+
func = spu.spu_db->analyse(_ls, spu.pc).get();
4033
spu.compiled_cache[spu.pc / 4] = func;
4134
}
4235

rpcs3/Emu/Cell/SPUThread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ class SPUThread : public cpu_thread
582582

583583
std::exception_ptr pending_exception;
584584

585-
std::array<std::shared_ptr<struct spu_function_t>, 65536> compiled_cache;
585+
std::array<struct spu_function_t*, 65536> compiled_cache{};
586586
std::shared_ptr<class SPUDatabase> spu_db;
587587
std::shared_ptr<class spu_recompiler_base> spu_rec;
588588
u32 recursion_level = 0;

0 commit comments

Comments
 (0)