codegen: use GPR_S64 for EE sign-tested branches (BLEZ/BGTZ/BLTZ/BGEZ + variants)#114
Closed
jlsandri wants to merge 1 commit intoran-j:mainfrom
Closed
codegen: use GPR_S64 for EE sign-tested branches (BLEZ/BGTZ/BLTZ/BGEZ + variants)#114jlsandri wants to merge 1 commit intoran-j:mainfrom
jlsandri wants to merge 1 commit intoran-j:mainfrom
Conversation
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.
e8c4e50 to
18b6327
Compare
Author
|
Closing as part of a batch cleanup after #107 landed. The runtime ecosystem refactor in #107 substantially reworked the files this PR touched, and I would like to re-audit the underlying fix against the new code structure before putting it back in front of you. If the fix is still needed after that re-audit, I will re-open as a focused PR rebased onto current main. Thanks for your patience. |
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.
Problem
The codegen for EE sign-tested branches —
BLEZ,BGTZ,BLTZ,BGEZ, and all of their*L(likely) and*AL(link) variants — was comparingGPR_S32, i.e. only the low 32 bits of the register treated as signed.The PS2 EE evaluates these branches against the full 64-bit GPR. A GPR with non-zero upper bits whose low 32 bits happened to look positive (or negative) under truncation would branch the opposite way from how real hardware does.
Fix
Switch the comparisons for all eight instructions (
BLEZ,BGTZ,BLTZ,BGEZ,BLEZL,BGTZL,BLTZL,BGEZL— plusBLTZAL,BGEZALand their likely variants) fromGPR_S32toGPR_S64.Scope
ps2xRecomp/src/lib/code_generator.cppRationale
The EE's GPRs are 64-bit, and
blez/bgtz/bltz/bgezsign-test the whole register per the R5900 Core User's Manual. TheGPR_S32emission was a latent bug that only manifests when a register legitimately holds a value whose 32-bit truncation flips the sign — uncommon in hand-written asm, but not rare in compiler output that manipulates 64-bit quantities.Fully standalone; no dependencies on other PRs.