From 0c0e857a6c0c9e758a5433941506c215952a306c Mon Sep 17 00:00:00 2001 From: Simone <91993281+SimoneN64@users.noreply.github.com> Date: Wed, 22 Jan 2025 10:42:35 +0100 Subject: [PATCH] [JIT]: Constant propagation doesn't need 2 layers + fix JUMP --- src/backend/core/jit/instructions.cpp | 10 ++--- src/backend/core/registers/Registers.cpp | 48 ++++++++---------------- 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/src/backend/core/jit/instructions.cpp b/src/backend/core/jit/instructions.cpp index 22a1c302..34041400 100644 --- a/src/backend/core/jit/instructions.cpp +++ b/src/backend/core/jit/instructions.cpp @@ -10,8 +10,7 @@ using namespace Xbyak::util; void JIT::lui(const u32 instr) { u64 val = static_cast(static_cast(instr)); val <<= 16; - regs.gpr[RT(instr)] = val; - regs.gprIsConstant[RT(instr)] = true; + regs.Write(RT(instr), val, true); } void JIT::add(const u32 instr) { @@ -835,10 +834,9 @@ void JIT::dsubu(u32 instr) { void JIT::j(const u32 instr) { const s32 target = (instr & 0x3ffffff) << 2; - code.mov(code.rax, REG(qword, oldPC)); - code.and_(code.rax, ~0xfffffff); - code.or_(code.rax, target); - branch_abs(target, mp); + const s64 oldPC = branchPC - 8; + const s64 address = (oldPC & ~0xfffffff) | target; + branch_abs_constant(true, address); } void JIT::jr(const u32 instr) { diff --git a/src/backend/core/registers/Registers.cpp b/src/backend/core/registers/Registers.cpp index fa201f98..953e99a0 100644 --- a/src/backend/core/registers/Registers.cpp +++ b/src/backend/core/registers/Registers.cpp @@ -126,11 +126,9 @@ void Registers::Write(size_t idx, bool v, bool isConstant) { if (idx == 0) return; - bool oldIsConstant = gprIsConstant[idx]; - gprIsConstant[idx] = isConstant; - if (jit) { - if (oldIsConstant) { + gprIsConstant[idx] = isConstant; + if (isConstant) { gpr[idx] = v; return; } @@ -153,11 +151,9 @@ void Registers::Write(size_t idx, u64 v, bool isConstant) { if (idx == 0) return; - bool oldIsConstant = gprIsConstant[idx]; - gprIsConstant[idx] = isConstant; - if (jit) { - if (oldIsConstant) { + gprIsConstant[idx] = isConstant; + if (isConstant) { gpr[idx] = v; return; } @@ -185,11 +181,9 @@ void Registers::Write(size_t idx, u32 v, bool isConstant) { if (idx == 0) return; - bool oldIsConstant = gprIsConstant[idx]; - gprIsConstant[idx] = isConstant; - if (jit) { - if (oldIsConstant) { + gprIsConstant[idx] = isConstant; + if (isConstant) { gpr[idx] = v; return; } @@ -213,11 +207,9 @@ void Registers::Write(size_t idx, s32 v, bool isConstant) { if (idx == 0) return; - bool oldIsConstant = gprIsConstant[idx]; - gprIsConstant[idx] = isConstant; - if (jit) { - if (oldIsConstant) { + gprIsConstant[idx] = isConstant; + if (isConstant) { gpr[idx] = v; return; } @@ -240,11 +232,9 @@ void Registers::Write(size_t idx, u16 v, bool isConstant) { if (idx == 0) return; - bool oldIsConstant = gprIsConstant[idx]; - gprIsConstant[idx] = isConstant; - if (jit) { - if (oldIsConstant) { + gprIsConstant[idx] = isConstant; + if (isConstant) { gpr[idx] = v; return; } @@ -268,11 +258,9 @@ void Registers::Write(size_t idx, s16 v, bool isConstant) { if (idx == 0) return; - bool oldIsConstant = gprIsConstant[idx]; - gprIsConstant[idx] = isConstant; - if (jit) { - if (oldIsConstant) { + gprIsConstant[idx] = isConstant; + if (isConstant) { gpr[idx] = v; return; } @@ -295,11 +283,9 @@ void Registers::Write(size_t idx, u8 v, bool isConstant) { if (idx == 0) return; - bool oldIsConstant = gprIsConstant[idx]; - gprIsConstant[idx] = isConstant; - if (jit) { - if (oldIsConstant) { + gprIsConstant[idx] = isConstant; + if (isConstant) { gpr[idx] = v; return; } @@ -323,11 +309,9 @@ void Registers::Write(size_t idx, s8 v, bool isConstant) { if (idx == 0) return; - bool oldIsConstant = gprIsConstant[idx]; - gprIsConstant[idx] = isConstant; - if (jit) { - if (oldIsConstant) { + gprIsConstant[idx] = isConstant; + if (isConstant) { gpr[idx] = v; return; }