Repository navigation
Conversation
On the R5900, SQRT.S fd, ft takes its source from the ft field (the fs field is 0 in the encoding). The translator read fs, so a real "sqrt.s $f2, $f2" (word 0x46020084) became FPU_SQRT_S(f[0]). Read ft instead. FPU_SQRT_S already ignores the sign of its input, as the hardware does. Add a code generator test for the encoding. RSQRT.S had the same kind of bug and was fixed in ran-j#272. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HhodgessnwK5k3pipLwFp3
yanm1103
force-pushed
the
fix/fpu-sqrt-rsqrt-operands
branch
from
October 19, 2026 18:24
9a7ca59 to
cb3a848
Compare
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
FpuTranslatorreads the wrong operand forSQRT.S:On the R5900,
SQRT.S fd, fttakes its source from the ft field; the fs field is 0 in the encoding. For examplesqrt.s $f2, $f2is the word0x46020084(fmt=S, ft=2, fs=0, fd=2, funct=4), and it is translated toctx->f[2] = FPU_SQRT_S(ctx->f[0]);, the square root of the wrong register.Fix
Read
ft.FPU_SQRT_S(ps2_fsqrt, from #272) already takes the magnitude of its input, so nothing else changes.Scope
This PR originally also fixed
RSQRT.S(1/sqrt(fs)instead offs/sqrt(ft)). #272 fixed that part in the meantime, so it has been rebased onto currentmainand reduced toSQRT.Sonly. #218 proposed the sameSQRT.Schange earlier.Verification
ps2x_testscase incode_generator_tests.cppforsqrt.s $f2, $f2(0x46020084). Full suite on Linux (GCC, Release): 446/446 pass with the fix; without it, this new case is the only failure.sqrt.sin 108 functions. An original function and an independent reimplementation, both recompiled with PS2Recomp, disagreed in 300/300 random states without the fix and matched 300/300 with it.🤖 Generated with Claude Code
https://claude.ai/code/session_01HhodgessnwK5k3pipLwFp3