This commit is contained in:
irisz64
2025-12-23 14:51:59 +01:00
parent 817616ca88
commit 945c5f40ac
3 changed files with 45 additions and 45 deletions

View File

@@ -72,40 +72,40 @@ std::optional<u32> JIT::FetchInstruction(s64 vaddr) {
}
void JIT::SetPC32(const s32 val) {
code.mov(code.SCR1, code.ptr[PC_OFFSET()]);
code.mov(code.ptr[OLD_PC_OFFSET()], code.SCR1);
code.mov(code.SCR1, code.qword[code.rbp + PC_OFFSET]);
code.mov(code.qword[code.rbp + OLD_PC_OFFSET], code.SCR1);
code.mov(code.SCR1.cvt32(), val);
code.movsxd(code.SCR1.cvt64(), code.SCR1.cvt32());
code.mov(code.ptr[PC_OFFSET()], code.SCR1);
code.mov(code.qword[code.rbp + PC_OFFSET], code.SCR1);
code.mov(code.SCR1.cvt32(), val + 4);
code.movsxd(code.SCR1.cvt64(), code.SCR1.cvt32());
code.mov(code.ptr[NEXT_PC_OFFSET()], code.SCR1);
code.mov(code.qword[code.rbp + NEXT_PC_OFFSET], code.SCR1);
}
void JIT::SetPC64(const s64 val) {
code.mov(code.SCR1, code.ptr[PC_OFFSET()]);
code.mov(code.ptr[OLD_PC_OFFSET()], code.SCR1);
code.mov(code.SCR1, code.qword[code.rbp + PC_OFFSET]);
code.mov(code.qword[code.rbp + OLD_PC_OFFSET], code.SCR1);
code.mov(code.SCR1, val);
code.mov(code.ptr[PC_OFFSET()], code.SCR1);
code.mov(code.qword[code.rbp + PC_OFFSET], code.SCR1);
code.mov(code.SCR1, val + 4);
code.mov(code.ptr[NEXT_PC_OFFSET()], code.SCR1);
code.mov(code.qword[code.rbp + NEXT_PC_OFFSET], code.SCR1);
}
void JIT::SetPC32(const Xbyak::Reg32& val) {
code.mov(code.SCR1, code.ptr[PC_OFFSET()]);
code.mov(code.ptr[OLD_PC_OFFSET()], code.SCR1);
code.mov(code.SCR1, code.qword[code.rbp + PC_OFFSET]);
code.mov(code.qword[code.rbp + OLD_PC_OFFSET], code.SCR1);
code.movsxd(val.cvt64(), val);
code.mov(code.ptr[PC_OFFSET()], val);
code.mov(code.qword[code.rbp + PC_OFFSET], val);
code.add(val, 4);
code.mov(code.ptr[NEXT_PC_OFFSET()], val);
code.mov(code.qword[code.rbp + NEXT_PC_OFFSET], val);
}
void JIT::SetPC64(const Xbyak::Reg64& val) {
code.mov(code.SCR1, code.ptr[PC_OFFSET()]);
code.mov(code.ptr[OLD_PC_OFFSET()], code.SCR1);
code.mov(code.ptr[PC_OFFSET()], val);
code.mov(code.SCR1, code.qword[code.rbp + PC_OFFSET]);
code.mov(code.qword[code.rbp + OLD_PC_OFFSET], code.SCR1);
code.mov(code.qword[code.rbp + PC_OFFSET], val);
code.add(val, 4);
code.mov(code.ptr[NEXT_PC_OFFSET()], val);
code.mov(code.qword[code.rbp + NEXT_PC_OFFSET], val);
}
u32 JIT::Step() {
@@ -194,15 +194,15 @@ u32 JIT::Step() {
if(!branch_taken) {
Xbyak::Label runtime_branch_taken;
code.mov(code.SCR1, code.byte[code.rbp + BRANCH_TAKEN_OFFSET()]);
code.mov(code.SCR1, code.byte[code.rbp + BRANCH_TAKEN_OFFSET]);
code.cmp(code.SCR1, 0);
code.jne(runtime_branch_taken);
code.mov(code.SCR1, blockOldPC);
code.mov(code.ptr[OLD_PC_OFFSET()], code.SCR1);
code.mov(code.qword[code.rbp + OLD_PC_OFFSET], code.SCR1);
code.mov(code.SCR1, blockPC);
code.mov(code.ptr[PC_OFFSET()], code.SCR1);
code.mov(code.qword[code.rbp + PC_OFFSET], code.SCR1);
code.mov(code.SCR1, blockNextPC);
code.mov(code.ptr[NEXT_PC_OFFSET()], code.SCR1);
code.mov(code.qword[code.rbp + NEXT_PC_OFFSET], code.SCR1);
code.L(runtime_branch_taken);
}

View File

@@ -16,13 +16,14 @@ static constexpr u32 kUpperSize = kAddressSpaceSize >> kUpperShift; // 0x800000
static constexpr u32 kLowerSize = 0x100; // 0x80
static constexpr u32 kCodeCacheSize = 32_mb;
static constexpr u32 kCodeCacheAllocSize = kCodeCacheSize + 4_kb;
#define OLD_PC_OFFSET() (reinterpret_cast<uintptr_t>(&regs.oldPC))
#define PC_OFFSET() (reinterpret_cast<uintptr_t>(&regs.pc))
#define NEXT_PC_OFFSET() (reinterpret_cast<uintptr_t>(&regs.nextPC))
#define GPR_OFFSET(x) (reinterpret_cast<uintptr_t>(&regs.gpr[(x)]))
#define BRANCH_TAKEN_OFFSET() (reinterpret_cast<uintptr_t>(&branch_taken) - reinterpret_cast<uintptr_t>(this))
#define HI_OFFSET() (reinterpret_cast<uintptr_t>(&regs.hi))
#define LO_OFFSET() (reinterpret_cast<uintptr_t>(&regs.lo))
#define OLD_PC_OFFSET (reinterpret_cast<uintptr_t>(&regs.oldPC) - reinterpret_cast<uintptr_t>(this))
#define PC_OFFSET (reinterpret_cast<uintptr_t>(&regs.pc) - reinterpret_cast<uintptr_t>(this))
#define NEXT_PC_OFFSET (reinterpret_cast<uintptr_t>(&regs.nextPC) - reinterpret_cast<uintptr_t>(this))
#define GPR_OFFSET(x) (reinterpret_cast<uintptr_t>(&regs.gpr[(x)]) - reinterpret_cast<uintptr_t>(this))
#define BRANCH_TAKEN_OFFSET (reinterpret_cast<uintptr_t>(&branch_taken) - reinterpret_cast<uintptr_t>(this))
#define HI_OFFSET (reinterpret_cast<uintptr_t>(&regs.hi) - reinterpret_cast<uintptr_t>(this))
#define LO_OFFSET (reinterpret_cast<uintptr_t>(&regs.lo) - reinterpret_cast<uintptr_t>(this))
#ifdef __aarch64__
struct JIT : BaseCPU {};
@@ -56,20 +57,19 @@ private:
friend struct Registers;
using BlockFn = int (*)();
std::vector<std::vector<BlockFn>> blockCache;
Xbyak::Label branch_likely_not_taken;
bool branch_taken;
csh disassemblerMips{}, disassemblerX86{};
template <typename T>
Xbyak::Address GPR(const size_t index) {
if constexpr (sizeof(T) == 1) {
return code.byte[GPR_OFFSET(index)];
return code.byte[code.rbp + GPR_OFFSET(index)];
} else if constexpr (sizeof(T) == 2) {
return code.word[GPR_OFFSET(index)];
return code.word[code.rbp + GPR_OFFSET(index)];
} else if constexpr (sizeof(T) == 4) {
return code.dword[GPR_OFFSET(index)];
return code.dword[code.rbp + GPR_OFFSET(index)];
} else if constexpr (sizeof(T) == 8) {
return code.ptr[GPR_OFFSET(index)];
return code.qword[code.rbp + GPR_OFFSET(index)];
}
Util::Error::GetInstance().Throw(

View File

@@ -194,13 +194,13 @@ void JIT::blfc1(const Instruction instr) {
void JIT::BranchNotTaken() {}
void JIT::BranchTaken(const s64 offs) {
code.mov(code.SCR2, code.qword[PC_OFFSET()]);
code.mov(code.SCR2, code.qword[code.rbp + PC_OFFSET]);
code.add(code.SCR2, offs);
SetPC64(code.SCR2);
}
void JIT::BranchTaken(const Xbyak::Reg64 &offs) {
code.mov(code.SCR2, code.qword[PC_OFFSET()]);
code.mov(code.SCR2, code.qword[code.rbp + PC_OFFSET]);
code.add(code.SCR2, offs);
SetPC64(code.SCR2);
}
@@ -245,7 +245,7 @@ void JIT::branch_likely_constant(const bool cond, const s64 offset) {
code.jmp(not_taken); \
code.L(taken); \
BranchTaken(offs); \
code.mov(code.byte[code.rbp + BRANCH_TAKEN_OFFSET()], 1); \
code.mov(code.byte[code.rbp + BRANCH_TAKEN_OFFSET], 1); \
code.L(not_taken); \
} while(0)
@@ -255,7 +255,7 @@ void JIT::branch_likely_constant(const bool cond, const s64 offset) {
code.jmp(not_taken); \
code.L(taken); \
BranchAbsTaken(addr); \
code.mov(code.byte[code.rbp + BRANCH_TAKEN_OFFSET()], 1); \
code.mov(code.byte[code.rbp + BRANCH_TAKEN_OFFSET], 1); \
code.L(not_taken); \
} while(0)
@@ -265,7 +265,7 @@ void JIT::branch_likely_constant(const bool cond, const s64 offset) {
code.jmp(not_taken); \
code.L(taken); \
BranchTaken(offs); \
code.mov(code.byte[code.rbp + BRANCH_TAKEN_OFFSET()], 1); \
code.mov(code.byte[code.rbp + BRANCH_TAKEN_OFFSET], 1); \
code.jmp(end); \
code.L(not_taken); \
SetPC64(blockNextPC); \
@@ -1064,7 +1064,7 @@ void JIT::lhu(const Instruction instr) {
code.mov(code.ARG4, reinterpret_cast<uintptr_t>(&paddr));
emitMemberFunctionCall(&Cop0::MapVAddr, &regs.cop0);
code.mov(code.ARG2, code.ptr[code.ARG4]);
code.mov(code.ARG2, code.qword[code.ARG4]);
emitMemberFunctionCall(&Mem::Read<u16>, &mem);
regs.Write<u16>(instr.rt(), code.rax);
}
@@ -1107,7 +1107,7 @@ void JIT::lw(const Instruction instr) {
code.mov(code.ARG4, reinterpret_cast<uintptr_t>(&paddr));
emitMemberFunctionCall(&Cop0::MapVAddr, &regs.cop0);
code.mov(code.ARG2, code.ptr[code.ARG4]);
code.mov(code.ARG2, code.qword[code.ARG4]);
emitMemberFunctionCall(&Mem::Read<u32>, &mem);
regs.Write<s32>(instr.rt(), code.rax);
}
@@ -1124,7 +1124,7 @@ void JIT::mfhi(const Instruction instr) {
if (regs.GetHIConstant()) {
regs.Write(instr.rd(), regs.hi);
} else {
code.mov(code.SCR1, code.ptr[HI_OFFSET()]);
code.mov(code.SCR1, code.qword[HI_OFFSET]);
regs.Write<s64>(instr.rd(), code.SCR1);
}
}
@@ -1133,7 +1133,7 @@ void JIT::mflo(const Instruction instr) {
if (regs.GetLOConstant()) {
regs.Write(instr.rd(), regs.lo);
} else {
code.mov(code.SCR1, code.ptr[LO_OFFSET()]);
code.mov(code.SCR1, code.qword[LO_OFFSET]);
regs.Write<s64>(instr.rd(), code.SCR1);
}
}
@@ -1172,7 +1172,7 @@ void JIT::mthi(const Instruction instr) {
regs.SetHIConstant();
} else {
regs.Read<s64>(instr.rs(), code.SCR1);
code.mov(code.ptr[HI_OFFSET()], code.SCR1);
code.mov(code.qword[HI_OFFSET], code.SCR1);
regs.UnsetHIConstant();
}
}
@@ -1183,7 +1183,7 @@ void JIT::mtlo(const Instruction instr) {
regs.SetLOConstant();
} else {
regs.Read<s64>(instr.rs(), code.SCR1);
code.mov(code.ptr[LO_OFFSET()], code.SCR1);
code.mov(code.qword[LO_OFFSET], code.SCR1);
regs.UnsetLOConstant();
}
}
@@ -1395,7 +1395,7 @@ void JIT::sw(const Instruction instr) {
code.mov(code.ARG4, reinterpret_cast<uintptr_t>(&physical));
emitMemberFunctionCall(&Cop0::MapVAddr, &regs.cop0);
code.mov(code.ARG2, code.ptr[code.ARG4]);
code.mov(code.ARG2, code.qword[code.ARG4]);
regs.Read<s64>(instr.rt(), code.ARG3);
emitMemberFunctionCall(&Mem::WriteJIT<u32>, &mem);
@@ -1411,7 +1411,7 @@ void JIT::sw(const Instruction instr) {
code.mov(code.ARG4, reinterpret_cast<uintptr_t>(&physical));
emitMemberFunctionCall(&Cop0::MapVAddr, &regs.cop0);
code.mov(code.ARG2, code.ptr[code.ARG4]);
code.mov(code.ARG2, code.qword[code.ARG4]);
regs.Read<s64>(instr.rt(), code.ARG3);
emitMemberFunctionCall(&Mem::WriteJIT<u32>, &mem);
}