From 3e8d08ce7168ba20afe92d0598c97abbeec26fdb Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 23 Sep 2023 11:19:27 -0700 Subject: [PATCH] unittest: Add jit compare for jit IR. --- unittest/JitHarness.cpp | 32 ++++++++++++++++++++++++++++---- unittest/UnitTest.cpp | 3 +++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/unittest/JitHarness.cpp b/unittest/JitHarness.cpp index 4ad53fc65c1a..088416e2bcd8 100644 --- a/unittest/JitHarness.cpp +++ b/unittest/JitHarness.cpp @@ -34,6 +34,7 @@ #include "Core/MemMap.h" #include "Core/Core.h" #include "Core/CoreTiming.h" +#include "Core/Config.h" #include "Core/HLE/HLE.h" // Temporary hacks around annoying linking errors. Copied from Headless. @@ -55,9 +56,15 @@ HLEFunction UnitTestFakeSyscalls[] = { {0x1234BEEF, &UnitTestTerminator, "UnitTestTerminator"}, }; -double ExecCPUTest() { +double ExecCPUTest(bool clearCache = true) { int blockTicks = 1000000; int total = 0; + + if (MIPSComp::jit) { + currentMIPS->pc = PSP_GetUserMemoryBase(); + MIPSComp::JitAt(); + } + double st = time_now_d(); do { for (int j = 0; j < 1000; ++j) { @@ -73,6 +80,17 @@ double ExecCPUTest() { while (time_now_d() - st < 0.5); double elapsed = time_now_d() - st; + if (MIPSComp::jit) { + JitBlockCacheDebugInterface *cache = MIPSComp::jit->GetBlockCacheDebugInterface(); + if (cache) { + JitBlockDebugInfo block = cache->GetBlockDebugInfo(0); + WARN_LOG(JIT, "Executed %d target instrs, %d IR, for %d orig", (int)block.targetDisasm.size(), (int)block.irDisasm.size(), (int)block.origDisasm.size()); + } + + if (clearCache) + MIPSComp::jit->ClearCache(); + } + return total / elapsed; } @@ -108,6 +126,7 @@ static void DestroyJitHarness() { bool TestJit() { SetupJitHarness(); + g_Config.bFastMemory = true; currentMIPS->pc = PSP_GetUserMemoryBase(); u32 *p = (u32 *)Memory::GetPointer(currentMIPS->pc); @@ -158,6 +177,7 @@ bool TestJit() { *p++ = MIPS_MAKE_SYSCALL("UnitTestFakeSyscalls", "UnitTestTerminator"); *p++ = MIPS_MAKE_BREAK(1); + *p++ = MIPS_MAKE_JR_RA(); // Dogfood. addr = currentMIPS->pc; @@ -170,11 +190,15 @@ bool TestJit() { printf("\n"); - double jit_speed = 0.0, interp_speed = 0.0; + double jit_speed = 0.0, jit_ir_speed = 0.0, ir_speed = 0.0, interp_speed = 0.0; if (compileSuccess) { interp_speed = ExecCPUTest(); + mipsr4k.UpdateCore(CPUCore::IR_INTERPRETER); + ir_speed = ExecCPUTest(); mipsr4k.UpdateCore(CPUCore::JIT); jit_speed = ExecCPUTest(); + mipsr4k.UpdateCore(CPUCore::JIT_IR); + jit_ir_speed = ExecCPUTest(false); // Disassemble JitBlockCacheDebugInterface *cache = MIPSComp::jit->GetBlockCacheDebugInterface(); @@ -182,14 +206,14 @@ bool TestJit() { JitBlockDebugInfo block = cache->GetBlockDebugInfo(0); // Should only be one block. std::vector &lines = block.targetDisasm; // Cut off at 25 due to the repetition above. Might need tweaking for large instructions. - const int cutoff = 25; + const int cutoff = 50; for (int i = 0; i < std::min((int)lines.size(), cutoff); i++) { printf("%s\n", lines[i].c_str()); } if (lines.size() > cutoff) printf("...\n"); } - printf("Jit was %fx faster than interp.\n\n", jit_speed / interp_speed); + 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); } printf("\n"); diff --git a/unittest/UnitTest.cpp b/unittest/UnitTest.cpp index ac7b5ba76339..92ed78760e4b 100644 --- a/unittest/UnitTest.cpp +++ b/unittest/UnitTest.cpp @@ -58,6 +58,7 @@ #include "Common/Render/DrawBuffer.h" #include "Common/System/NativeApp.h" #include "Common/System/System.h" +#include "Common/Thread/ThreadUtil.h" #include "Common/ArmEmitter.h" #include "Common/BitScan.h" @@ -1038,6 +1039,8 @@ TestItem availableTests[] = { }; int main(int argc, const char *argv[]) { + SetCurrentThreadName("UnitTest"); + cpu_info.bNEON = true; cpu_info.bVFP = true; cpu_info.bVFPv3 = true;