diff --git a/src/backend/core/JIT.cpp b/src/backend/core/JIT.cpp index 77f98012..83698513 100644 --- a/src/backend/core/JIT.cpp +++ b/src/backend/core/JIT.cpp @@ -72,40 +72,40 @@ std::optional 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); } diff --git a/src/backend/core/JIT.hpp b/src/backend/core/JIT.hpp index cd302ca6..d662dcf6 100644 --- a/src/backend/core/JIT.hpp +++ b/src/backend/core/JIT.hpp @@ -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(®s.oldPC)) -#define PC_OFFSET() (reinterpret_cast(®s.pc)) -#define NEXT_PC_OFFSET() (reinterpret_cast(®s.nextPC)) -#define GPR_OFFSET(x) (reinterpret_cast(®s.gpr[(x)])) -#define BRANCH_TAKEN_OFFSET() (reinterpret_cast(&branch_taken) - reinterpret_cast(this)) -#define HI_OFFSET() (reinterpret_cast(®s.hi)) -#define LO_OFFSET() (reinterpret_cast(®s.lo)) + +#define OLD_PC_OFFSET (reinterpret_cast(®s.oldPC) - reinterpret_cast(this)) +#define PC_OFFSET (reinterpret_cast(®s.pc) - reinterpret_cast(this)) +#define NEXT_PC_OFFSET (reinterpret_cast(®s.nextPC) - reinterpret_cast(this)) +#define GPR_OFFSET(x) (reinterpret_cast(®s.gpr[(x)]) - reinterpret_cast(this)) +#define BRANCH_TAKEN_OFFSET (reinterpret_cast(&branch_taken) - reinterpret_cast(this)) +#define HI_OFFSET (reinterpret_cast(®s.hi) - reinterpret_cast(this)) +#define LO_OFFSET (reinterpret_cast(®s.lo) - reinterpret_cast(this)) #ifdef __aarch64__ struct JIT : BaseCPU {}; @@ -56,20 +57,19 @@ private: friend struct Registers; using BlockFn = int (*)(); std::vector> blockCache; - Xbyak::Label branch_likely_not_taken; bool branch_taken; csh disassemblerMips{}, disassemblerX86{}; template 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( diff --git a/src/backend/core/jit/instructions.cpp b/src/backend/core/jit/instructions.cpp index 1a07c54b..1d2b04fa 100644 --- a/src/backend/core/jit/instructions.cpp +++ b/src/backend/core/jit/instructions.cpp @@ -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(&paddr)); emitMemberFunctionCall(&Cop0::MapVAddr, ®s.cop0); - code.mov(code.ARG2, code.ptr[code.ARG4]); + code.mov(code.ARG2, code.qword[code.ARG4]); emitMemberFunctionCall(&Mem::Read, &mem); regs.Write(instr.rt(), code.rax); } @@ -1107,7 +1107,7 @@ void JIT::lw(const Instruction instr) { code.mov(code.ARG4, reinterpret_cast(&paddr)); emitMemberFunctionCall(&Cop0::MapVAddr, ®s.cop0); - code.mov(code.ARG2, code.ptr[code.ARG4]); + code.mov(code.ARG2, code.qword[code.ARG4]); emitMemberFunctionCall(&Mem::Read, &mem); regs.Write(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(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(instr.rd(), code.SCR1); } } @@ -1172,7 +1172,7 @@ void JIT::mthi(const Instruction instr) { regs.SetHIConstant(); } else { regs.Read(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(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(&physical)); emitMemberFunctionCall(&Cop0::MapVAddr, ®s.cop0); - code.mov(code.ARG2, code.ptr[code.ARG4]); + code.mov(code.ARG2, code.qword[code.ARG4]); regs.Read(instr.rt(), code.ARG3); emitMemberFunctionCall(&Mem::WriteJIT, &mem); @@ -1411,7 +1411,7 @@ void JIT::sw(const Instruction instr) { code.mov(code.ARG4, reinterpret_cast(&physical)); emitMemberFunctionCall(&Cop0::MapVAddr, ®s.cop0); - code.mov(code.ARG2, code.ptr[code.ARG4]); + code.mov(code.ARG2, code.qword[code.ARG4]); regs.Read(instr.rt(), code.ARG3); emitMemberFunctionCall(&Mem::WriteJIT, &mem); }