Repository navigation
R5900: MOVZ/MOVN move the low 64 bits and keep rd's upper half - #445
Open
Fructose0517 wants to merge 1 commit into
Open
Fructose0517 wants to merge 1 commit into
Fructose0517 wants to merge 1 commit into
Conversation
MOVZ and MOVN are 64-bit conditional moves on the R5900: they copy the low doubleword of rs into rd and leave rd's upper 64 bits unchanged (PCSX2: GPR.r[rd].UD[0] = GPR.r[rs].UD[0]). The translator emitted a full 128-bit copy (SET_GPR_VEC), which also replaced the upper half of rd with the upper half of rs. Emit SET_GPR_U64 instead, and test both the generated text and that the emitted statements keep the destination's upper 64 bits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fructose0517
added a commit
to Fructose0517/falena-reborn
that referenced
this pull request
Dec 2, 2026
First of the fixes offered upstream: the translator emits a 64-bit move instead of a 128-bit copy. Upstream's tests pass (the 6 failures are the same on unchanged main), and with the patched translator our generated code is identical byte for byte, with no MOVZ/MOVN site left for our rewrite. 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.
What
On the R5900,
MOVZandMOVNare 64-bit conditional moves: when the condition holds they copy the low doubleword ofrsintordand leave the upper 64 bits ofrdunchanged (PCSX2:cpuRegs.GPR.r[_Rd_].UD[0] = cpuRegs.GPR.r[_Rs_].UD[0]).The translator emitted a full 128-bit copy:
so the upper half of
rdwas replaced by the upper half ofrs. Code that keeps 128-bit data in a register and later uses its upper half (MMI,sq) then reads the wrong value.This change emits
SET_GPR_U64, which writes only the low 64 bits:Tests
code_generator_tests.cpp: the generated text forMOVZandMOVNusesSET_GPR_U64and noSET_GPR_VEC.ps2_runtime_expansion_tests.cpp: the emitted statements, run on anR5900Context, movers's low 64 bits and keeprd's upper 64 bits for both instructions.Built and run on Windows with MSVC 19.51 the way the CI job builds (
cmake -B build,cmake --build build --config Release), with #446 on top becausemaindoes not compile with MSVC as is:ps2x_testspasses 525 of 525, the two new tests included. (ps2xStudiofails to build for an unrelated reason, fixed by #450.)Edit: an earlier version of this description said 6 tests failed on unchanged
main. That came from my local build, not from upstream: my flags replaced CMake's default MSVC flags (the VU0 macro-mapping test then fails), and a NinjaReleasebuild adds/fp:fast /arch:AVX2 /GLthroughEnableFastReleaseMode(four GS parallel-drawing tests then fail). Built the CI way, everything passes.Checked on a game
Found while porting a game (about 1,020
MOVZ/MOVNsites). Its port has carried an equivalent fix as a post-translation rewrite of the generated code; with this change the translator's output, after that port's other rewrites, is identical file for file to what it ships today, and the rewrite finds nothing left to fix.Related
#135 includes the same fix together with a larger set of changes; this PR is only the
MOVZ/MOVNpart, so it can be reviewed on its own.🤖 Generated with Claude Code