From 18b63272b3c04d7767ad8d075e11c4c08de50a10 Mon Sep 17 00:00:00 2001 From: James Sandri <7078671+jlsandri@users.noreply.github.com> Date: Mon, 6 Apr 2026 02:14:21 +1000 Subject: [PATCH] Fix branch codegen to use GPR_S64 for EE sign comparisons BLEZ/BGTZ/BLTZ/BGEZ and their likely/link variants were comparing GPR_S32, but the EE evaluates the full 64-bit register for these sign-tested branches. Switch the emitted comparisons to GPR_S64. --- ps2xRecomp/src/lib/code_generator.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/ps2xRecomp/src/lib/code_generator.cpp b/ps2xRecomp/src/lib/code_generator.cpp index 666a59e7..a919ca61 100644 --- a/ps2xRecomp/src/lib/code_generator.cpp +++ b/ps2xRecomp/src/lib/code_generator.cpp @@ -478,10 +478,10 @@ namespace ps2recomp conditionStr = fmt::format("GPR_U64(ctx, {}) != GPR_U64(ctx, {})", rs_reg, rt_reg); break; case OPCODE_BLEZ: - conditionStr = fmt::format("GPR_S32(ctx, {}) <= 0", rs_reg); + conditionStr = fmt::format("GPR_S64(ctx, {}) <= 0", rs_reg); break; case OPCODE_BGTZ: - conditionStr = fmt::format("GPR_S32(ctx, {}) > 0", rs_reg); + conditionStr = fmt::format("GPR_S64(ctx, {}) > 0", rs_reg); break; case OPCODE_BEQL: conditionStr = fmt::format("GPR_U64(ctx, {}) == GPR_U64(ctx, {})", rs_reg, rt_reg); @@ -490,40 +490,40 @@ namespace ps2recomp conditionStr = fmt::format("GPR_U64(ctx, {}) != GPR_U64(ctx, {})", rs_reg, rt_reg); break; case OPCODE_BLEZL: - conditionStr = fmt::format("GPR_S32(ctx, {}) <= 0", rs_reg); + conditionStr = fmt::format("GPR_S64(ctx, {}) <= 0", rs_reg); break; case OPCODE_BGTZL: - conditionStr = fmt::format("GPR_S32(ctx, {}) > 0", rs_reg); + conditionStr = fmt::format("GPR_S64(ctx, {}) > 0", rs_reg); break; case OPCODE_REGIMM: switch (rt_reg) { case REGIMM_BLTZ: - conditionStr = fmt::format("GPR_S32(ctx, {}) < 0", rs_reg); + conditionStr = fmt::format("GPR_S64(ctx, {}) < 0", rs_reg); break; case REGIMM_BGEZ: - conditionStr = fmt::format("GPR_S32(ctx, {}) >= 0", rs_reg); + conditionStr = fmt::format("GPR_S64(ctx, {}) >= 0", rs_reg); break; case REGIMM_BLTZL: - conditionStr = fmt::format("GPR_S32(ctx, {}) < 0", rs_reg); + conditionStr = fmt::format("GPR_S64(ctx, {}) < 0", rs_reg); break; case REGIMM_BGEZL: - conditionStr = fmt::format("GPR_S32(ctx, {}) >= 0", rs_reg); + conditionStr = fmt::format("GPR_S64(ctx, {}) >= 0", rs_reg); break; case REGIMM_BLTZAL: - conditionStr = fmt::format("GPR_S32(ctx, {}) < 0", rs_reg); + conditionStr = fmt::format("GPR_S64(ctx, {}) < 0", rs_reg); unconditionalLinkCode = fmt::format("SET_GPR_U32(ctx, 31, 0x{:X}u);", fallthroughPc); break; case REGIMM_BGEZAL: - conditionStr = fmt::format("GPR_S32(ctx, {}) >= 0", rs_reg); + conditionStr = fmt::format("GPR_S64(ctx, {}) >= 0", rs_reg); unconditionalLinkCode = fmt::format("SET_GPR_U32(ctx, 31, 0x{:X}u);", fallthroughPc); break; case REGIMM_BLTZALL: - conditionStr = fmt::format("GPR_S32(ctx, {}) < 0", rs_reg); + conditionStr = fmt::format("GPR_S64(ctx, {}) < 0", rs_reg); conditionalLinkCode = fmt::format("SET_GPR_U32(ctx, 31, 0x{:X}u);", fallthroughPc); break; case REGIMM_BGEZALL: - conditionStr = fmt::format("GPR_S32(ctx, {}) >= 0", rs_reg); + conditionStr = fmt::format("GPR_S64(ctx, {}) >= 0", rs_reg); conditionalLinkCode = fmt::format("SET_GPR_U32(ctx, 31, 0x{:X}u);", fallthroughPc); break; default: