fix(relinker): lower scalar RCPSS and RSQRTSS #11192
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11192"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by RINNECODER on 2026-10-25T21:17:25Z.
What
--to-intel(and--to-rosettaon top of it) lowered only the packed reciprocal register forms. The scalar RCPSS, RSQRTSS, VRCPSS and VRSQRTSS were left native, so they kept the host's approximation, while the packed forms right next to them got the exact value.docs/dev/debt/relinker.mdlisted this gap.The register forms of all four now go through the same stub as the packed forms: SQRTSS (RSQRTSS only), then DIVSS into 1.0. The upper lanes are merged the way the instructions define them. The legacy forms keep the destination's lanes 1-3 and its upper YMM bits. The VEX forms take lanes 1-3 from the first source (VEX.vvvv) and clear the upper YMM bits. VEX.L is ignored, as it is for these LIG instructions. Memory forms and the 256-bit packed forms still keep the native instruction, as before. The debt entry is cut to match. The two VEX scalar names are added to the per-name stub summary in
Conversion.cpp, the same as VRSQRTPS and VRCPPS.Title evidence: PPSA04203 (Sid Meier's Civilization VII) has 231 of these in its eboot, all VEX register forms (225 VRSQRTSS, 6 VRCPSS, no memory forms, no legacy forms). With this change,
--macos --to-rosettaon that eboot reports:On
mainthese sites stay native. I have not observed a visible wrong result in that title that this change fixes, so the Unblocks line is none.tools/check_conventions.pyreports one warning,debt-length, on the edited entry: 1068 characters. Onmainthe entry is already 1065 characters, and this change makes it 3 characters longer.Tested
macOS 27 arm64, Apple clang, relinker-only Release build (
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON):amd64_only_converter(native arm64) runs the decoder and converter checks. It fails onmainwith the new cases (Scalar reciprocal was not lowered) and passes with this change.amd64_only_converterbuilt with-DCMAKE_OSX_ARCHITECTURES=x86_64and run under Rosetta also executes the stubs. It fails onmain(Register form stub was not produced) and passes with this change. The execution checks cover legacy and VEX encodings, distinct and identical registers, a VEX first source equal to the destination and equal to the source, and 1/sqrt(1.0) == 1.0. Each lane is compared bit for bit with1.0f / std::sqrt(x)or1.0f / x. I also broke the stub on purpose twice (MULSS in place of DIVSS, and MOVAPS in place of the final MOVSS), and each break failed the test.tools/check_conventions.py --base upstream/main: 0 errors and 1 warning (see above).relinkertarget builds. Not tested on Linux or Windows, and not tested in a title run.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T21:23:50Z.
Review: COMMENTED
Independent local check at head
825fed94f823600bbffba440d8d5e26a7b7b14a7: the relinker-only Release build completes, and the isolatedreciprocalOperands,reciprocalExecutionandconverterReciprocaltests pass, including execution of the generated scalar stubs. The fullamd64_only_converterCTest stops earlier in the existingxsaveoptExecutiontest with SIGILL on this host;/proc/cpuinfoexposes XSAVE but not OSXSAVE, so I cannot count that full-suite run as evidence against this change. Conventions report zero errors and the disclosed debt-length warning (1,068 characters). Hosted Ubuntu relinker and ASan checks pass; Windows and macOS checks are still pending.Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-26T18:07:35Z.
Review: COMMENTED
Reviewed
825fed94fmerged ontomain570089a80(2026-10-26); the merge is clean. Windows 11, i9-12900H, WinLibs GCC 15.2, relinker-only Release.Results
ctest: 308 of 309 pass;patch_advisor_unitfails the same way on plainmain.amd64_only_converterpasses, but on Windows it runs only the decode and convert checks. The execution checks compile only for Linux and macOS x86-64 (Amd64OnlyConverterTests.cpp:1505), so this run executes no stub.main'sReciprocalOperands.cpp,ReciprocalLowering.cppandAmd64OnlyInstructionMatcher.cpp(headers kept), the test fails at "VEX2 VRSQRTSS was not decoded". Reverting only the matcher gives your "Scalar reciprocal was not lowered", and reverting the headers too doesn't compile. With your files it passes.Should fix (text): see the inline comment on the debt entry. The RSQRT forms are not correctly rounded.
Minor: see the inline comment on
ReciprocalLowering.cpp. The stub differs from the native instruction in MXCSR behaviour, and the debt entry doesn't record it.Nits
Several wrong variants pass the execution checks, because those use only xmm2 and xmm5 and read only the low 128 bits:
_vex;Sites with vvvv ≥ 8 (e.g.
C5 A2 53 D5), a VEX3 destination and source ≥ 8 (e.g.C4 C1 0A 52 D7), and a check of bits 128-255 would catch them.Debt wording:
Body:
mainand 1068 here, so the PR adds 4, not 3.Not checked: what Zen 2's RCPSS and RSQRTSS return; the MXCSR that ordinary threads of relinked output run with on Windows and Linux; PPSA04203 or any title run; Linux and macOS x86-64, where the execution checks compile.
For disclosure: my open PRs #11061, #11045, #10971 and #10947 also edit
docs/dev/debt/relinker.md; each merges cleanly with this one.Written with AI assistance (Claude Code). I ran the build, the counter-check and the native probes above on my Windows 11 machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T09:40:57Z.
Review: APPROVED
Re-checked — approved
The previously reviewed reciprocal-lowering implementation is unchanged in the current branch; the latest merge brings in current
mainand retains the debt update. The register/flag probe and focused implementation review remain applicable, and the exact current head's hosted relinker matrix passes on Linux, macOS (including x86_64), and Windows. The conventions, labels and eligibility checks pass as well.The full Linux product job is skipped. The Windows product job passes, but its
amd64_only_convertertarget does not execute the scalar stubs; the earlier reviewer probe is the reported native execution comparison. I did not rerun the probe locally. No blocking issue found; approval covers exact head2750fe2657c3b723cc82b12691586eaf10d29cce.