Repository navigation
Conversation
On the R5900, SQRT.S fd, ft takes its source from the ft field (the fs field is 0), and RSQRT.S fd, fs, ft computes fs / sqrt(ft). The translator read fs for SQRT.S (so a real "sqrt.s $f2, $f2", word 0x46020084, became FPU_SQRT_S(f[0])) and emitted 1/sqrt(fs) for RSQRT.S, ignoring ft and the numerator. Use ft for SQRT.S and fs / sqrt(ft) for RSQRT.S. Like PCSX2, take the magnitude of ft so negative inputs do not produce NaN. Add a code generator test for both encodings. Co-Authored-By: Claude Sonnet 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.
Problem
FpuTranslatorpicks the wrong operands for two COP1.S instructions:SQRT.Swas emitted asctx->f[fd] = FPU_SQRT_S(ctx->f[fs]);RSQRT.Swas emitted asctx->f[fd] = 1.0f / sqrtf(ctx->f[fs]);R5900 rule
SQRT.S fd, ft: the source operand is the ft field. The fs field is 0 in the encoding.RSQRT.S fd, fs, ft: the result isfs / sqrt(ft), not1 / sqrt(fs).FPU.cppdoes:SQRT_SandRSQRT_Sapplysqrt(fabs(ft))for negative ft, andRSQRT_Sdividesfsby it).For example
sqrt.s $f2, $f2is the word0x46020084(fmt=S, ft=2, fs=0, fd=2, funct=4). It was translated toctx->f[2] = FPU_SQRT_S(ctx->f[0]);, i.e. the square root of the wrong register.Fix
Scope is these two cases only. Zero and denormal handling and the FPU flag updates that PCSX2 models are not touched here.
Verification
sqrt.s) and 76 functions (rsqrt.s).$f2was ignored). With the fix they matched 300/300.ps2xTestcase incode_generator_tests.cppthat checks the emitted code forsqrt.s $f2, $f2(0x46020084) and forrsqrt.s $f1, $f3, $f4. I could not run the full CMake test suite locally; I compiledfpu_translator.cppstandalone and checked that it emits exactly the strings the test expects.🤖 Generated with Claude Code