mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-27 00:00:07 -06:00
first steps in bringing over the JIT refactor/fastmem
This commit is contained in:
@ -301,24 +301,6 @@ Compiler::Compiler()
|
||||
RET();
|
||||
}
|
||||
|
||||
{
|
||||
CPSRDirty = true;
|
||||
BranchStub[0] = GetWritableCodePtr();
|
||||
SaveCPSR();
|
||||
MOV(64, R(ABI_PARAM1), R(RCPU));
|
||||
CALL((u8*)ARMJIT::LinkBlock<0>);
|
||||
LoadCPSR();
|
||||
JMP((u8*)ARM_Ret, true);
|
||||
|
||||
CPSRDirty = true;
|
||||
BranchStub[1] = GetWritableCodePtr();
|
||||
SaveCPSR();
|
||||
MOV(64, R(ABI_PARAM1), R(RCPU));
|
||||
CALL((u8*)ARMJIT::LinkBlock<1>);
|
||||
LoadCPSR();
|
||||
JMP((u8*)ARM_Ret, true);
|
||||
}
|
||||
|
||||
// move the region forward to prevent overwriting the generated functions
|
||||
CodeMemSize -= GetWritableCodePtr() - ResetStart;
|
||||
ResetStart = GetWritableCodePtr();
|
||||
@ -520,6 +502,11 @@ void Compiler::Reset()
|
||||
FarCode = FarStart;
|
||||
}
|
||||
|
||||
bool Compiler::IsJITFault(u64 addr)
|
||||
{
|
||||
return addr >= (u64)CodeMemory && addr < (u64)CodeMemory + sizeof(CodeMemory);
|
||||
}
|
||||
|
||||
void Compiler::Comp_SpecialBranchBehaviour(bool taken)
|
||||
{
|
||||
if (taken && CurInstr.BranchFlags & branch_IdleBranch)
|
||||
@ -531,32 +518,11 @@ void Compiler::Comp_SpecialBranchBehaviour(bool taken)
|
||||
RegCache.PrepareExit();
|
||||
|
||||
SUB(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm32(ConstantCycles));
|
||||
|
||||
if (Config::JIT_BrancheOptimisations == 2 && !(CurInstr.BranchFlags & branch_IdleBranch)
|
||||
&& (!taken || (CurInstr.BranchFlags & branch_StaticTarget)))
|
||||
{
|
||||
FixupBranch ret = J_CC(CC_S);
|
||||
CMP(32, MDisp(RCPU, offsetof(ARM, StopExecution)), Imm8(0));
|
||||
FixupBranch ret2 = J_CC(CC_NZ);
|
||||
|
||||
u8* rewritePart = GetWritableCodePtr();
|
||||
NOP(5);
|
||||
|
||||
MOV(32, R(ABI_PARAM2), Imm32(rewritePart - ResetStart));
|
||||
JMP((u8*)BranchStub[Num], true);
|
||||
|
||||
SetJumpTarget(ret);
|
||||
SetJumpTarget(ret2);
|
||||
JMP((u8*)ARM_Ret, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
JMP((u8*)&ARM_Ret, true);
|
||||
}
|
||||
JMP((u8*)&ARM_Ret, true);
|
||||
}
|
||||
}
|
||||
|
||||
JitBlockEntry Compiler::CompileBlock(u32 translatedAddr, ARM* cpu, bool thumb, FetchedInstr instrs[], int instrsCount)
|
||||
JitBlockEntry Compiler::CompileBlock(ARM* cpu, bool thumb, FetchedInstr instrs[], int instrsCount)
|
||||
{
|
||||
if (NearSize - (NearCode - NearStart) < 1024 * 32) // guess...
|
||||
{
|
||||
@ -575,7 +541,7 @@ JitBlockEntry Compiler::CompileBlock(u32 translatedAddr, ARM* cpu, bool thumb, F
|
||||
CodeRegion = instrs[0].Addr >> 24;
|
||||
CurCPU = cpu;
|
||||
// CPSR might have been modified in a previous block
|
||||
CPSRDirty = Config::JIT_BrancheOptimisations == 2;
|
||||
CPSRDirty = false;
|
||||
|
||||
JitBlockEntry res = (JitBlockEntry)GetWritableCodePtr();
|
||||
|
||||
@ -685,31 +651,7 @@ JitBlockEntry Compiler::CompileBlock(u32 translatedAddr, ARM* cpu, bool thumb, F
|
||||
RegCache.Flush();
|
||||
|
||||
SUB(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm32(ConstantCycles));
|
||||
|
||||
if (Config::JIT_BrancheOptimisations == 2
|
||||
&& !(instrs[instrsCount - 1].BranchFlags & branch_IdleBranch)
|
||||
&& (!instrs[instrsCount - 1].Info.Branches()
|
||||
|| instrs[instrsCount - 1].BranchFlags & branch_FollowCondNotTaken
|
||||
|| (instrs[instrsCount - 1].BranchFlags & branch_FollowCondTaken && instrs[instrsCount - 1].BranchFlags & branch_StaticTarget)))
|
||||
{
|
||||
FixupBranch ret = J_CC(CC_S);
|
||||
CMP(32, MDisp(RCPU, offsetof(ARM, StopExecution)), Imm8(0));
|
||||
FixupBranch ret2 = J_CC(CC_NZ);
|
||||
|
||||
u8* rewritePart = GetWritableCodePtr();
|
||||
NOP(5);
|
||||
|
||||
MOV(32, R(ABI_PARAM2), Imm32(rewritePart - ResetStart));
|
||||
JMP((u8*)BranchStub[Num], true);
|
||||
|
||||
SetJumpTarget(ret);
|
||||
SetJumpTarget(ret2);
|
||||
JMP((u8*)ARM_Ret, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
JMP((u8*)ARM_Ret, true);
|
||||
}
|
||||
JMP((u8*)ARM_Ret, true);
|
||||
|
||||
/*FILE* codeout = fopen("codeout", "a");
|
||||
fprintf(codeout, "beginning block argargarg__ %x!!!", instrs[0].Addr);
|
||||
@ -720,22 +662,6 @@ JitBlockEntry Compiler::CompileBlock(u32 translatedAddr, ARM* cpu, bool thumb, F
|
||||
return res;
|
||||
}
|
||||
|
||||
void Compiler::LinkBlock(u32 offset, JitBlockEntry entry)
|
||||
{
|
||||
u8* curPtr = GetWritableCodePtr();
|
||||
SetCodePtr(ResetStart + offset);
|
||||
JMP((u8*)entry, true);
|
||||
SetCodePtr(curPtr);
|
||||
}
|
||||
|
||||
void Compiler::UnlinkBlock(u32 offset)
|
||||
{
|
||||
u8* curPtr = GetWritableCodePtr();
|
||||
SetCodePtr(ResetStart + offset);
|
||||
NOP(5);
|
||||
SetCodePtr(curPtr);
|
||||
}
|
||||
|
||||
void Compiler::Comp_AddCycles_C(bool forceNonConstant)
|
||||
{
|
||||
s32 cycles = Num ?
|
||||
|
Reference in New Issue
Block a user