Repository navigation
Recompiler: resume in the delay slot of an always-taken branch at the target - #451
Open
M-Rocchinotti wants to merge 1 commit into
Open
M-Rocchinotti wants to merge 1 commit into
M-Rocchinotti wants to merge 1 commit into
Conversation
… 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #260
What
ControlFlowEmitter::emitResumeFromDelaySlotEntry()always continued atbranch + 8after 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 ab, resuming there left the loop. In Ridge Racer V this made the main game loop return and the game exit (details in #260).Change
isAlwaysTakenBranch():beq/beqlwithrs == rt(this coversb=beq $0,$0),blez/blezl $0andbgez/bgezl $0.emitInternalTarget()when the target is in the function, otherwisectx->pc = target; return;, the same as the taken path ofemitConditionalBranch().label_fallthrough_0x...isn't emitted for them any more, since nothing jumps to it.bgezal $0(bal), which I left to the call path.j/jal/jrresume entries are unchanged too.Tests
Two new cases in
code_generator_tests.cpp:bwhose delay slot is an entry point: the resume entry mustgotothe target and must not fall through. It fails onmainand passes with this change.beq $1,$2: the resume entry still falls through.Full
ps2x_testson 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 unchangedmain.maindoesn'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.