diff options
author | RSDuck <RSDuck@users.noreply.github.com> | 2019-07-14 04:33:36 +0200 |
---|---|---|
committer | RSDuck <rsduck@users.noreply.github.com> | 2020-06-16 11:53:21 +0200 |
commit | d13d625f7363449c3fdc041b0a22005b92c83229 (patch) | |
tree | 87301a5bbba93924facf329761257cc2607afe61 | |
parent | 0ff79ea2ad645f85f3a4878be3717ffda44f9cbe (diff) |
jit: make everything configurable
-rw-r--r-- | src/ARM.cpp | 127 | ||||
-rw-r--r-- | src/ARM.h | 3 | ||||
-rw-r--r-- | src/ARMJIT.cpp | 21 | ||||
-rw-r--r-- | src/ARMJIT.h | 2 | ||||
-rw-r--r-- | src/ARMJIT_x64/ARMJIT_Compiler.cpp | 14 | ||||
-rw-r--r-- | src/ARMJIT_x64/ARMJIT_Compiler.h | 2 | ||||
-rw-r--r-- | src/Config.cpp | 6 | ||||
-rw-r--r-- | src/Config.h | 3 | ||||
-rw-r--r-- | src/NDS.cpp | 26 | ||||
-rw-r--r-- | src/frontend/qt_sdl/PlatformConfig.cpp | 1 |
10 files changed, 171 insertions, 34 deletions
diff --git a/src/ARM.cpp b/src/ARM.cpp index baf8468..1cd4bb2 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -532,7 +532,7 @@ void ARMv5::Execute() while (NDS::ARM9Timestamp < NDS::ARM9Target) { - /*if (CPSR & 0x20) // THUMB + if (CPSR & 0x20) // THUMB { // prefetch R[15] += 2; @@ -565,14 +565,8 @@ void ARMv5::Execute() } else AddCycles_C(); - }*/ - - /*if (!ARMJIT::IsMapped(0, R[15] - ((CPSR&0x20)?2:4))) - printf("aaarg ungempappter raum %x\n", R[15]);*/ - - ARMJIT::CompiledBlock block = ARMJIT::LookUpBlock(0, R[15] - ((CPSR&0x20)?2:4)); - Cycles += (block ? block : ARMJIT::CompileBlock(this))(); - + } + // TODO optimize this shit!!! if (Halted) { @@ -597,6 +591,58 @@ void ARMv5::Execute() Halted = 0; } +void ARMv5::ExecuteJIT() +{ + if (Halted) + { + if (Halted == 2) + { + Halted = 0; + } + else if (NDS::HaltInterrupted(0)) + { + Halted = 0; + if (NDS::IME[0] & 0x1) + TriggerIRQ(); + } + else + { + NDS::ARM9Timestamp = NDS::ARM9Target; + return; + } + } + + while (NDS::ARM9Timestamp < NDS::ARM9Target) + { + u32 instrAddr = R[15] - ((CPSR&0x20)?2:4); + if (!ARMJIT::IsMapped(0, instrAddr)) + { + NDS::ARM9Timestamp = NDS::ARM9Target; + printf("ARMv5 PC in non executable region %08X\n", R[15]); + return; + } + + ARMJIT::CompiledBlock block = ARMJIT::LookUpBlock(0, instrAddr); + Cycles += (block ? block : ARMJIT::CompileBlock(this))(); + + if (Halted) + { + if (Halted == 1 && NDS::ARM9Timestamp < NDS::ARM9Target) + { + NDS::ARM9Timestamp = NDS::ARM9Target; + } + break; + } + if (IRQ) TriggerIRQ(); + + NDS::ARM9Timestamp += Cycles; + Cycles = 0; + } + + if (Halted == 2) + Halted = 0; +} + void ARMv4::Execute() { if (Halted) @@ -620,7 +666,7 @@ void ARMv4::Execute() while (NDS::ARM7Timestamp < NDS::ARM7Target) { - /*if (CPSR & 0x20) // THUMB + if (CPSR & 0x20) // THUMB { // prefetch R[15] += 2; @@ -648,13 +694,7 @@ void ARMv4::Execute() } else AddCycles_C(); - }*/ - - /*if (!ARMJIT::IsMapped(1, R[15] - ((CPSR&0x20)?2:4))) - printf("aaarg ungempappter raum %x\n", R[15]);*/ - - ARMJIT::CompiledBlock block = ARMJIT::LookUpBlock(1, R[15] - ((CPSR&0x20)?2:4)); - Cycles += (block ? block : ARMJIT::CompileBlock(this))(); + } // TODO optimize this shit!!! if (Halted) @@ -679,3 +719,56 @@ void ARMv4::Execute() if (Halted == 2) Halted = 0; } + +void ARMv4::ExecuteJIT() +{ + if (Halted) + { + if (Halted == 2) + { + Halted = 0; + } + else if (NDS::HaltInterrupted(1)) + { + Halted = 0; + if (NDS::IME[1] & 0x1) + TriggerIRQ(); + } + else + { + NDS::ARM7Timestamp = NDS::ARM7Target; + return; + } + } + + while (NDS::ARM7Timestamp < NDS::ARM7Target) + { + u32 instrAddr = R[15] - ((CPSR&0x20)?2:4); + if (!ARMJIT::IsMapped(1, instrAddr)) + { + NDS::ARM7Timestamp = NDS::ARM7Target; + printf("ARMv4 PC in non executable region %08X\n", R[15]); + return; + } + ARMJIT::CompiledBlock block = ARMJIT::LookUpBlock(1, instrAddr); + Cycles += (block ? block : ARMJIT::CompileBlock(this))(); + + // TODO optimize this shit!!! + if (Halted) + { + if (Halted == 1 && NDS::ARM7Timestamp < NDS::ARM7Target) + { + NDS::ARM7Timestamp = NDS::ARM7Target; + } + break; + } + + if (IRQ) TriggerIRQ(); + + NDS::ARM7Timestamp += Cycles; + Cycles = 0; + } + + if (Halted == 2) + Halted = 0; +}
\ No newline at end of file @@ -52,6 +52,7 @@ public: } virtual void Execute() = 0; + virtual void ExecuteJIT() = 0; bool CheckCondition(u32 code) { @@ -159,6 +160,7 @@ public: void DataAbort(); void Execute(); + void ExecuteJIT(); // all code accesses are forced nonseq 32bit u32 CodeRead32(u32 addr, bool branch); @@ -281,6 +283,7 @@ public: void JumpTo(u32 addr, bool restorecpsr = false); void Execute(); + void ExecuteJIT(); u16 CodeRead16(u32 addr) { diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 47b425f..e8e6be0 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -2,6 +2,8 @@ #include <string.h> +#include "Config.h" + #include "ARMJIT_x64/ARMJIT_Compiler.h" namespace ARMJIT @@ -125,18 +127,21 @@ CompiledBlock CompileBlock(ARM* cpu) { bool thumb = cpu->CPSR & 0x20; - FetchedInstr instrs[12]; + if (Config::JIT_MaxBlockSize < 1) + Config::JIT_MaxBlockSize = 1; + if (Config::JIT_MaxBlockSize > 32) + Config::JIT_MaxBlockSize = 32; + + FetchedInstr instrs[Config::JIT_MaxBlockSize]; int i = 0; - u32 r15Initial = cpu->R[15]; + u32 blockAddr = cpu->R[15] - (thumb ? 2 : 4); u32 r15 = cpu->R[15]; u32 nextInstr[2] = {cpu->NextInstr[0], cpu->NextInstr[1]}; - //printf("block %x %d\n", r15, thumb); do { r15 += thumb ? 2 : 4; instrs[i].Instr = nextInstr[0]; - //printf("%x %x\n", instrs[i].Instr, r15); instrs[i].NextInstr[0] = nextInstr[0] = nextInstr[1]; if (cpu->Num == 0) @@ -166,16 +171,16 @@ CompiledBlock CompileBlock(ARM* cpu) instrs[i].Info = ARMInstrInfo::Decode(thumb, cpu->Num, instrs[i].Instr); i++; - } while(!instrs[i - 1].Info.Branches() && i < 10); + } while(!instrs[i - 1].Info.Branches() && i < Config::JIT_MaxBlockSize); CompiledBlock block = compiler->CompileBlock(cpu, instrs, i); - InsertBlock(cpu->Num, r15Initial - (thumb ? 2 : 4), block); + InsertBlock(cpu->Num, blockAddr, block); return block; } -void ResetBlocks() +void InvalidateBlockCache() { memset(cache.MainRAM, 0, sizeof(cache.MainRAM)); memset(cache.SWRAM, 0, sizeof(cache.SWRAM)); @@ -185,6 +190,8 @@ void ResetBlocks() memset(cache.ARM7_BIOS, 0, sizeof(cache.ARM7_BIOS)); memset(cache.ARM7_WRAM, 0, sizeof(cache.ARM7_WRAM)); memset(cache.ARM7_WVRAM, 0, sizeof(cache.ARM7_WVRAM)); + + compiler->Reset(); } }
\ No newline at end of file diff --git a/src/ARMJIT.h b/src/ARMJIT.h index 45bb4ed..004256c 100644 --- a/src/ARMJIT.h +++ b/src/ARMJIT.h @@ -111,7 +111,7 @@ void DeInit(); CompiledBlock CompileBlock(ARM* cpu); -void ResetBlocks(); +void InvalidateBlockCache(); } diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index 2b7ccd2..fe23859 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -336,13 +336,15 @@ const Compiler::CompileFunc T_Comp[ARMInstrInfo::tk_Count] = { }; #undef F +void Compiler::Reset() +{ + SetCodePtr((u8*)ResetStart); +} + CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrsCount) { if (IsAlmostFull()) - { - ResetBlocks(); - SetCodePtr((u8*)ResetStart); - } + InvalidateBlockCache(); CompiledBlock res = (CompiledBlock)GetWritableCodePtr(); @@ -355,7 +357,7 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs bool mergedThumbBL = false; - ABI_PushRegistersAndAdjustStack(BitSet32(ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS & ~RSP), 8); + ABI_PushRegistersAndAdjustStack(BitSet32(ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS & ~BitSet32({RSP})), 8); MOV(64, R(RCPU), ImmPtr(cpu)); @@ -469,7 +471,7 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs MOV(32, R(RAX), Imm32(ConstantCycles)); - ABI_PopRegistersAndAdjustStack(BitSet32(ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS & ~RSP), 8); + ABI_PopRegistersAndAdjustStack(BitSet32(ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS & ~BitSet32({RSP})), 8); RET(); return res; diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index e04f96a..cd58012 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -22,6 +22,8 @@ class Compiler : public Gen::X64CodeBlock public: Compiler(); + void Reset(); + CompiledBlock CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrsCount); void LoadReg(int reg, Gen::X64Reg nativeReg); diff --git a/src/Config.cpp b/src/Config.cpp index 5745f34..5c0892a 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -37,6 +37,9 @@ char DSiBIOS7Path[1024]; char DSiFirmwarePath[1024]; char DSiNANDPath[1024]; +bool JIT_Enable = false; +int JIT_MaxBlockSize = 12; + ConfigEntry ConfigFile[] = { {"BIOS9Path", 1, BIOS9Path, 0, "", 1023}, @@ -48,6 +51,9 @@ ConfigEntry ConfigFile[] = {"DSiFirmwarePath", 1, DSiFirmwarePath, 0, "", 1023}, {"DSiNANDPath", 1, DSiNANDPath, 0, "", 1023}, + {"JIT_Enable", 0, &JIT_Enable, 0, NULL, 0}, + {"JIT_MaxBlockSize", 0, &JIT_MaxBlockSize, 10, NULL, 0}, + {"", -1, NULL, 0, NULL, 0} }; diff --git a/src/Config.h b/src/Config.h index 3947598..9dda157 100644 --- a/src/Config.h +++ b/src/Config.h @@ -51,6 +51,9 @@ extern char DSiBIOS7Path[1024]; extern char DSiFirmwarePath[1024]; extern char DSiNANDPath[1024]; +extern bool JIT_Enable; +extern int JIT_MaxBlockSize; + } #endif // CONFIG_H diff --git a/src/NDS.cpp b/src/NDS.cpp index 4073536..cb85d13 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -566,7 +566,7 @@ void Reset() KeyCnt = 0; RCnt = 0; - ARMJIT::ResetBlocks(); + ARMJIT::InvalidateBlockCache(); NDSCart::Reset(); GBACart::Reset(); @@ -794,6 +794,11 @@ bool DoSavestate(Savestate* file) GPU::SetPowerCnt(PowerControl9); } + if (!file->Saving) + { + ARMJIT::InvalidateBlockCache(); + } + return true; } @@ -884,6 +889,7 @@ void RunSystem(u64 timestamp) } } +template <bool EnableJIT> u32 RunFrame() { FrameStartTimestamp = SysTimestamp; @@ -917,7 +923,10 @@ u32 RunFrame() } else { - ARM9->Execute(); + if (EnableJIT) + ARM9->ExecuteJIT(); + else + ARM9->Execute(); } RunTimers(0); @@ -940,7 +949,10 @@ u32 RunFrame() } else { - ARM7->Execute(); + if (EnableJIT) + ARM7->ExecuteJIT(); + else + ARM7->Execute(); } RunTimers(1); @@ -970,6 +982,14 @@ u32 RunFrame() return GPU::TotalScanlines; } +u32 RunFrame() +{ + if (Config::JIT_Enable) + return RunFrame<true>(); + else + return RunFrame<false>(); +} + void Reschedule(u64 target) { if (CurCPU == 0) diff --git a/src/frontend/qt_sdl/PlatformConfig.cpp b/src/frontend/qt_sdl/PlatformConfig.cpp index 06128d7..bfb3f97 100644 --- a/src/frontend/qt_sdl/PlatformConfig.cpp +++ b/src/frontend/qt_sdl/PlatformConfig.cpp @@ -72,6 +72,7 @@ char MicWavPath[1024]; char LastROMFolder[1024]; +bool EnableJIT; ConfigEntry PlatformConfigFile[] = { |