feat(libc): export _FDsign/_Dsign like MSVC CRT (PPSA34015) #6085
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6085"
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 notaxeltv on 2026-10-14T21:33:08Z.
What
tools/import_audit.pyon PPSA34015 lists absentlibc.prximports6ei1eQn2WIc(_FDsign) andzvl6nrvd0sE(_Dsign). Match MSVC/Dinkumware: return0x8000when the IEEE sign bit is set, otherwise0. Null pointers throw.Tested
Windows 10, WinLibs GCC 15.2.0,
guest_dsignpasses.tools/check_conventions.py --base upstream/mainpasses.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)Made with Cursor
Imported from boykopovar/AnyPS5. Originally posted by isnisk on 2026-10-16T00:14:00Z.
Checked on Linux: Ubuntu 26.04 (WSL2), GCC 15.2.0, Release, this head (
ffea0b7c1) merged ontomain489466d3f(clean merge).guest_dsignandguest_mathpass, 3 rounds; no compiler warnings.main'sMath.cpp): the test does not link (undefined reference to _Dsign_nid_postfix,_FDsign_nid_postfix).check_conventions.py --base origin/mainpasses.Not checked: macOS, the title.
AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T22:40:22Z.
Checked on Linux (PR merged onto current main):
guest_dsignandguest_mathpass; without the change the test doesn't link (undefined_Dsign/_FDsign). Semantics match Dinkumware/MS STL (0x8000when the sign bit is set, including -0 and -inf), null throws like_Dtest. Confirmed on Linux by @isnisk. Merging once the full Build is green.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T15:22:49Z.
Thanks for this. One question about the signature before it can merge:
The PR declares
_Dsign(const double*)and_FDsign(const float*). In MSVC's CRT the test functions take a pointer (_dtest(double*), like main's_Dtest), but the sign functions_dsign/_fdsigntake the value. If the console's_Dsign/_FDsigntake the value too, the guest passes it in xmm0 and this implementation dereferences whatever is in rdi.Could you confirm from a call site? A disassembly of a
_Dsign/_FDsigncall in the title you saw it in (or libc.prx's export) would show whether the argument is a pointer in rdi or the value in xmm0. If it's by value, switching the signatures (and the tests) to by-value fixes it.Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T01:16:03Z.
@oneandonlydean thanks for the question. I read the two exports from the
libc.prxof two different retail titles' modules (two different builds of the module, same result in both):_Dsignand_FDsigntake the value, not a pointer. Thedoubleorfloatarrives inxmm0, the function stores it in a stack slot, derives the most significant 16-bit word of it and returns that word masked with0x8000. Nothing is taken fromrdias an argument, so theconst double*/const float*signatures of this head do not match that.Based on its head (
ffea0b7c1d), in case it is useful to @notaxeltv: commit45925a18e9onxXPBSXx:fix/dsign-by-valuechanges both functions to takedouble/floatby value. The test passes the values directly (1, -1, 0, -0, +-inf, a NaN with the sign bit set). Happy to drop it if the PR is updated instead.Windows 10 19045, WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON, this head with the follow-up on top:guest_dsignpasses 3 of 3 runs,guest_mathpasses 3 of 3.Math.cpp, the new test):guest_dsignfails 3 of 3 (0xc0000409).tools/check_conventions.pyand merge-tree against currentmain: clean.Not tested: Linux/macOS, and no title run (PPSA34015 is not available to me). I only disassembled the two exports, I did not run the module's code.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T01:29:32Z.
@notaxeltv thanks for waiting on this. The signature question is settled: on the console both functions take the value, not a pointer. In the PS5
libc.prxfrom PPSA21564,_Dsignstoresxmm0to the stack, takes the top 16-bit word of the double and returns it& 0x8000, and_FDsigndoes the same with a float. That matches what @xXPBSXx found in two other retail builds. Withconst double*/const float*, the function reads a pointer fromrdithat the caller never set.Your sign logic is right, so only the signature needs to change:
short _Dsign(double)andshort _FDsign(float), with the tests calling them by value (the null checks go away). @xXPBSXx's commit45925a18e9onxXPBSXx:fix/dsign-by-valuedoes exactly that on top of your head, and you're welcome to take it as is, keeping their authorship. Once the head moves, we'll run CI and take it from there.Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-26T13:19:18Z.
Review: APPROVED
Reviewed
ffea0b7c1d088005e99ee30256c4decf2834d34dagainstf59d91ffc35b99502f7106ffd800190a974c31c1. Recommend approval; no actionable findings in the complete three-file patch.Both exports use memcpy to read the IEEE representation, preserving NaN payloads and signed zero, and move only the sign bit into the short return's 0x8000 position. Null pointers throw std::invalid_argument, consistent with the neighboring classification helpers. The added CMake test registration uses the project Windows unwind and DLL-path setup.
Validation: Rechecked the existing exact-pinned candidate/base source-built checkouts and incremental build graphs with WinLibs GCC 15.3. The candidate's guest_math and guest_dsign tests pass 2/2; baseline guest_math passes 1/1. Both new symbols appear in the candidate DLL export table and are absent from the baseline. A newly compiled review-only caller passes 28 float/double edge patterns, including signed zero, subnormal boundaries, normal boundaries, infinities, signaling and quiet NaNs, verifying input bits remain unchanged and FE_INVALID is not raised. Linking that caller against baseline fails specifically for the two missing exports; this is an expected missing-symbol control, not a baseline runtime failure. Source conventions and whitespace checks pass.
Scope: Native Windows execution with the actual branch-built libc DLL; no Linux/macOS or game run. Existing source-built artifacts from Luna's completed build were reused after verifying commit pins, clean tracked source and CMake target freshness; no claim is made that this second pass rebuilt every object from scratch. Parent hosted native product jobs remain skipped and are not counted as runtime passes.
Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-11-01T17:12:21Z.
Review: APPROVED
Reviewed head
abbd3bd22ab8merged onto mainf2d874c1fdcc(clean merge). As far as I can tell this is the first Linux run of the by-value head; the earlier Linux runs here were onffea0b7c(pointer version).What I ran (WSL2 Ubuntu 24.04, GCC 13.3, Release,
BUILD_TESTING=ON):ctest -R '^guest_(dsign|math|math_exact)$' --repeat until-fail:3: all 3 pass, 3 of 3 rounds.Math.cpp/Api.hppwith this test doesn't build ('_FDsign_nid_postfix' was not declared in this scope).objdumpof the builtlibc.prx: value comes from xmm0, nothing is read through rdi, result is the top word & 0x8000 in ax. Same shape as the retail disassembly described above:libc.prx(not part of the PR): +/-qNaN, +sNaN, -NaN with payload (0xFFC00123,0xFFF8000000000123), +/-denorm_min, +/-max,0x7FFFFFFF: all as expected, input bits unchanged.tools/check_conventions.py --base origin/main: pass.Sources checked:
tools/nid_names.pyhash gives_FDsign->6ei1eQn2WIcand_Dsign->zvl6nrvd0sE, matching the description._fdsign/_dsign(dlls/msvcrt/math.c) do the same>> 16/>> 48& 0x8000. Returningshort-32768 matches the existing_LDsign(MathExact.cpp:252) and its test._Dsign/_FDsignon main, so no duplicate export.Looks good to me. One small non-blocking nit:
docs/dev/REVERSE_ENGINEERING.md("Citing it") asks for a debt entry when behaviour comes from disassembly. For example, indocs/dev/debt/libc.md: "_Dsign/_FDsigntake the value in xmm0 and return the sign bit as 0x8000; read from libc.prx disassembly, not measured on a console."Not checked: Windows, macOS, the title (no dump here).