Skip to content

Recompiler: resume in the delay slot of an always-taken branch at the target - #451

Open
M-Rocchinotti wants to merge 1 commit into
ran-j:mainfrom
M-Rocchinotti:fix/260-resume-delay-slot-always-taken
Open

M-Rocchinotti wants to merge 1 commit into
ran-j:mainfrom
M-Rocchinotti:fix/260-resume-delay-slot-always-taken

Conversation

@M-Rocchinotti

Copy link
Copy Markdown

Fixes #260

What

ControlFlowEmitter::emitResumeFromDelaySlotEntry() always continued at branch + 8 after running the delay slot. That's right for a conditional branch that wasn't taken, but an always-taken encoding never falls through. So when the recompiler put a resume entry in the delay slot of a b, resuming there left the loop. In Ridge Racer V this made the main game loop return and the game exit (details in #260).

Change

  • New isAlwaysTakenBranch(): beq/beql with rs == rt (this covers b = beq $0,$0), blez/blezl $0 and bgez/bgezl $0.
  • For these, the resume entry continues at the branch target: emitInternalTarget() when the target is in the function, otherwise ctx->pc = target; return;, the same as the taken path of emitConditionalBranch().
  • label_fallthrough_0x... isn't emitted for them any more, since nothing jumps to it.
  • Not changed: the linking form bgezal $0 (bal), which I left to the call path. j/jal/jr resume entries are unchanged too.

Tests

Two new cases in code_generator_tests.cpp:

  • an always-taken b whose delay slot is an entry point: the resume entry must goto the target and must not fall through. It fails on main and passes with this change.
  • the same layout with a conditional beq $1,$2: the resume entry still falls through.

Full ps2x_tests on Windows (MSVC 14.5x, Ninja, Release): 523/525 pass. The 2 failures are the GS row-band parallel rasterization tests, which fail the same way on unchanged main. main doesn't build with MSVC right now, so I built with #446 applied locally. #446 is not part of this PR.

Disclosure

I used an AI coding assistant (Claude) to help write this change and the tests. I reviewed the change and ran the tests above myself.

… target

emitResumeFromDelaySlotEntry() always continued at branch+8 after the
delay slot. That is right for a conditional branch that was not taken,
but an always-taken encoding (b = beq $x,$x, blez $0, bgez $0 and their
likely forms) never falls through, so the resume entry left the loop.
In Ridge Racer V this made the main game loop return and the game exit.

The resume entry now continues at the branch target for these encodings,
and the unused label_fallthrough is no longer emitted for them.

Fixes ran-j#260

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recompiler: resuming inside the delay slot of an always-taken branch falls through instead of continuing at the target

1 participant