[JIT]: Constant propagation doesn't need 2 layers + fix JUMP

This commit is contained in:
Simone
2025-01-22 10:42:35 +01:00
committed by GitHub
parent 043e20c517
commit 0c0e857a6c
2 changed files with 20 additions and 38 deletions

View File

@@ -10,8 +10,7 @@ using namespace Xbyak::util;
void JIT::lui(const u32 instr) { void JIT::lui(const u32 instr) {
u64 val = static_cast<s64>(static_cast<s16>(instr)); u64 val = static_cast<s64>(static_cast<s16>(instr));
val <<= 16; val <<= 16;
regs.gpr[RT(instr)] = val; regs.Write<s64>(RT(instr), val, true);
regs.gprIsConstant[RT(instr)] = true;
} }
void JIT::add(const u32 instr) { void JIT::add(const u32 instr) {
@@ -835,10 +834,9 @@ void JIT::dsubu(u32 instr) {
void JIT::j(const u32 instr) { void JIT::j(const u32 instr) {
const s32 target = (instr & 0x3ffffff) << 2; const s32 target = (instr & 0x3ffffff) << 2;
code.mov(code.rax, REG(qword, oldPC)); const s64 oldPC = branchPC - 8;
code.and_(code.rax, ~0xfffffff); const s64 address = (oldPC & ~0xfffffff) | target;
code.or_(code.rax, target); branch_abs_constant(true, address);
branch_abs(target, mp);
} }
void JIT::jr(const u32 instr) { void JIT::jr(const u32 instr) {

View File

@@ -126,11 +126,9 @@ void Registers::Write<bool>(size_t idx, bool v, bool isConstant) {
if (idx == 0) if (idx == 0)
return; return;
bool oldIsConstant = gprIsConstant[idx];
gprIsConstant[idx] = isConstant;
if (jit) { if (jit) {
if (oldIsConstant) { gprIsConstant[idx] = isConstant;
if (isConstant) {
gpr[idx] = v; gpr[idx] = v;
return; return;
} }
@@ -153,11 +151,9 @@ void Registers::Write<u64>(size_t idx, u64 v, bool isConstant) {
if (idx == 0) if (idx == 0)
return; return;
bool oldIsConstant = gprIsConstant[idx];
gprIsConstant[idx] = isConstant;
if (jit) { if (jit) {
if (oldIsConstant) { gprIsConstant[idx] = isConstant;
if (isConstant) {
gpr[idx] = v; gpr[idx] = v;
return; return;
} }
@@ -185,11 +181,9 @@ void Registers::Write<u32>(size_t idx, u32 v, bool isConstant) {
if (idx == 0) if (idx == 0)
return; return;
bool oldIsConstant = gprIsConstant[idx];
gprIsConstant[idx] = isConstant;
if (jit) { if (jit) {
if (oldIsConstant) { gprIsConstant[idx] = isConstant;
if (isConstant) {
gpr[idx] = v; gpr[idx] = v;
return; return;
} }
@@ -213,11 +207,9 @@ void Registers::Write<s32>(size_t idx, s32 v, bool isConstant) {
if (idx == 0) if (idx == 0)
return; return;
bool oldIsConstant = gprIsConstant[idx];
gprIsConstant[idx] = isConstant;
if (jit) { if (jit) {
if (oldIsConstant) { gprIsConstant[idx] = isConstant;
if (isConstant) {
gpr[idx] = v; gpr[idx] = v;
return; return;
} }
@@ -240,11 +232,9 @@ void Registers::Write<u16>(size_t idx, u16 v, bool isConstant) {
if (idx == 0) if (idx == 0)
return; return;
bool oldIsConstant = gprIsConstant[idx];
gprIsConstant[idx] = isConstant;
if (jit) { if (jit) {
if (oldIsConstant) { gprIsConstant[idx] = isConstant;
if (isConstant) {
gpr[idx] = v; gpr[idx] = v;
return; return;
} }
@@ -268,11 +258,9 @@ void Registers::Write<s16>(size_t idx, s16 v, bool isConstant) {
if (idx == 0) if (idx == 0)
return; return;
bool oldIsConstant = gprIsConstant[idx];
gprIsConstant[idx] = isConstant;
if (jit) { if (jit) {
if (oldIsConstant) { gprIsConstant[idx] = isConstant;
if (isConstant) {
gpr[idx] = v; gpr[idx] = v;
return; return;
} }
@@ -295,11 +283,9 @@ void Registers::Write<u8>(size_t idx, u8 v, bool isConstant) {
if (idx == 0) if (idx == 0)
return; return;
bool oldIsConstant = gprIsConstant[idx];
gprIsConstant[idx] = isConstant;
if (jit) { if (jit) {
if (oldIsConstant) { gprIsConstant[idx] = isConstant;
if (isConstant) {
gpr[idx] = v; gpr[idx] = v;
return; return;
} }
@@ -323,11 +309,9 @@ void Registers::Write<s8>(size_t idx, s8 v, bool isConstant) {
if (idx == 0) if (idx == 0)
return; return;
bool oldIsConstant = gprIsConstant[idx];
gprIsConstant[idx] = isConstant;
if (jit) { if (jit) {
if (oldIsConstant) { gprIsConstant[idx] = isConstant;
if (isConstant) {
gpr[idx] = v; gpr[idx] = v;
return; return;
} }