Skip to content

Commit 3e8d08c

Browse files
unittest: Add jit compare for jit IR.
1 parent 638192b commit 3e8d08c

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

unittest/JitHarness.cpp

+28-4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "Core/MemMap.h"
3535
#include "Core/Core.h"
3636
#include "Core/CoreTiming.h"
37+
#include "Core/Config.h"
3738
#include "Core/HLE/HLE.h"
3839

3940
// Temporary hacks around annoying linking errors. Copied from Headless.
@@ -55,9 +56,15 @@ HLEFunction UnitTestFakeSyscalls[] = {
5556
{0x1234BEEF, &UnitTestTerminator, "UnitTestTerminator"},
5657
};
5758

58-
double ExecCPUTest() {
59+
double ExecCPUTest(bool clearCache = true) {
5960
int blockTicks = 1000000;
6061
int total = 0;
62+
63+
if (MIPSComp::jit) {
64+
currentMIPS->pc = PSP_GetUserMemoryBase();
65+
MIPSComp::JitAt();
66+
}
67+
6168
double st = time_now_d();
6269
do {
6370
for (int j = 0; j < 1000; ++j) {
@@ -73,6 +80,17 @@ double ExecCPUTest() {
7380
while (time_now_d() - st < 0.5);
7481
double elapsed = time_now_d() - st;
7582

83+
if (MIPSComp::jit) {
84+
JitBlockCacheDebugInterface *cache = MIPSComp::jit->GetBlockCacheDebugInterface();
85+
if (cache) {
86+
JitBlockDebugInfo block = cache->GetBlockDebugInfo(0);
87+
WARN_LOG(JIT, "Executed %d target instrs, %d IR, for %d orig", (int)block.targetDisasm.size(), (int)block.irDisasm.size(), (int)block.origDisasm.size());
88+
}
89+
90+
if (clearCache)
91+
MIPSComp::jit->ClearCache();
92+
}
93+
7694
return total / elapsed;
7795
}
7896

@@ -108,6 +126,7 @@ static void DestroyJitHarness() {
108126
bool TestJit() {
109127
SetupJitHarness();
110128

129+
g_Config.bFastMemory = true;
111130
currentMIPS->pc = PSP_GetUserMemoryBase();
112131
u32 *p = (u32 *)Memory::GetPointer(currentMIPS->pc);
113132

@@ -158,6 +177,7 @@ bool TestJit() {
158177

159178
*p++ = MIPS_MAKE_SYSCALL("UnitTestFakeSyscalls", "UnitTestTerminator");
160179
*p++ = MIPS_MAKE_BREAK(1);
180+
*p++ = MIPS_MAKE_JR_RA();
161181

162182
// Dogfood.
163183
addr = currentMIPS->pc;
@@ -170,26 +190,30 @@ bool TestJit() {
170190

171191
printf("\n");
172192

173-
double jit_speed = 0.0, interp_speed = 0.0;
193+
double jit_speed = 0.0, jit_ir_speed = 0.0, ir_speed = 0.0, interp_speed = 0.0;
174194
if (compileSuccess) {
175195
interp_speed = ExecCPUTest();
196+
mipsr4k.UpdateCore(CPUCore::IR_INTERPRETER);
197+
ir_speed = ExecCPUTest();
176198
mipsr4k.UpdateCore(CPUCore::JIT);
177199
jit_speed = ExecCPUTest();
200+
mipsr4k.UpdateCore(CPUCore::JIT_IR);
201+
jit_ir_speed = ExecCPUTest(false);
178202

179203
// Disassemble
180204
JitBlockCacheDebugInterface *cache = MIPSComp::jit->GetBlockCacheDebugInterface();
181205
if (cache) {
182206
JitBlockDebugInfo block = cache->GetBlockDebugInfo(0); // Should only be one block.
183207
std::vector<std::string> &lines = block.targetDisasm;
184208
// Cut off at 25 due to the repetition above. Might need tweaking for large instructions.
185-
const int cutoff = 25;
209+
const int cutoff = 50;
186210
for (int i = 0; i < std::min((int)lines.size(), cutoff); i++) {
187211
printf("%s\n", lines[i].c_str());
188212
}
189213
if (lines.size() > cutoff)
190214
printf("...\n");
191215
}
192-
printf("Jit was %fx faster than interp.\n\n", jit_speed / interp_speed);
216+
printf("Jit was %fx faster than interp, IR was %fx faster, JIT IR %fx.\n\n", jit_speed / interp_speed, ir_speed / interp_speed, jit_ir_speed / interp_speed);
193217
}
194218

195219
printf("\n");

unittest/UnitTest.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "Common/Render/DrawBuffer.h"
5959
#include "Common/System/NativeApp.h"
6060
#include "Common/System/System.h"
61+
#include "Common/Thread/ThreadUtil.h"
6162

6263
#include "Common/ArmEmitter.h"
6364
#include "Common/BitScan.h"
@@ -1038,6 +1039,8 @@ TestItem availableTests[] = {
10381039
};
10391040

10401041
int main(int argc, const char *argv[]) {
1042+
SetCurrentThreadName("UnitTest");
1043+
10411044
cpu_info.bNEON = true;
10421045
cpu_info.bVFP = true;
10431046
cpu_info.bVFPv3 = true;

0 commit comments

Comments
 (0)