feat(libc): export _FDsign/_Dsign like MSVC CRT (PPSA34015) #6085

Merged
notaxeltv merged 3 commits from upstream-pr/6085 into main 2026-11-02 07:55:26 +00:00
notaxeltv commented 2026-10-14 21:33:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by notaxeltv on 2026-10-14T21:33:08Z.


What

tools/import_audit.py on PPSA34015 lists absent libc.prx imports 6ei1eQn2WIc (_FDsign) and zvl6nrvd0sE (_Dsign). Match MSVC/Dinkumware: return 0x8000 when the IEEE sign bit is set, otherwise 0. Null pointers throw.

Tested

Windows 10, WinLibs GCC 15.2.0, guest_dsign passes. tools/check_conventions.py --base upstream/main passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source (none)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA34015 (absent libc imports)
  • GPUs tested: n/a
  • AI-assisted: yes

Made with Cursor

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4864837811 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6085). Originally posted by [notaxeltv](https://github.com/notaxeltv) on 2026-10-14T21:33:08Z. --- ### What `tools/import_audit.py` on PPSA34015 lists absent `libc.prx` imports `6ei1eQn2WIc` (`_FDsign`) and `zvl6nrvd0sE` (`_Dsign`). Match MSVC/Dinkumware: return `0x8000` when the IEEE sign bit is set, otherwise `0`. Null pointers throw. ### Tested Windows 10, WinLibs GCC 15.2.0, `guest_dsign` passes. `tools/check_conventions.py --base upstream/main` passes. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source (none) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA34015 (absent libc imports) - [x] GPUs tested: n/a - [x] AI-assisted: yes Made with [Cursor](https://cursor.com)
isnisk commented 2026-10-16 00:14:00 +00:00 (Migrated from github.com)

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 onto main 489466d3f (clean merge).

  • With the change: guest_dsign and guest_math pass, 3 rounds; no compiler warnings.
  • Without it (main's Math.cpp): the test does not link (undefined reference to _Dsign_nid_postfix, _FDsign_nid_postfix).
  • check_conventions.py --base origin/main passes.

Not checked: macOS, the title.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6205013493 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6085#issuecomment-6205013493). Originally posted by [isnisk](https://github.com/isnisk) on 2026-10-16T00:14:00Z. --- Checked on Linux: Ubuntu 26.04 (WSL2), GCC 15.2.0, Release, this head (`ffea0b7c1`) merged onto `main` `489466d3f` (clean merge). - With the change: `guest_dsign` and `guest_math` pass, 3 rounds; no compiler warnings. - Without it (`main`'s `Math.cpp`): the test does not link (`undefined reference to _Dsign_nid_postfix`, `_FDsign_nid_postfix`). - `check_conventions.py --base origin/main` passes. Not checked: macOS, the title. AI-assisted: yes (Claude Code).
adriadam10 commented 2026-10-16 22:40:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T22:40:22Z.


Checked on Linux (PR merged onto current main): guest_dsign and guest_math pass; without the change the test doesn't link (undefined _Dsign/_FDsign). Semantics match Dinkumware/MS STL (0x8000 when 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6226043648 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6085#issuecomment-6226043648). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-16T22:40:22Z. --- Checked on Linux (PR merged onto current main): `guest_dsign` and `guest_math` pass; without the change the test doesn't link (undefined `_Dsign`/`_FDsign`). Semantics match Dinkumware/MS STL (`0x8000` when 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.
oneandonlydean commented 2026-10-18 15:22:49 +00:00 (Migrated from github.com)

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/_fdsign take the value. If the console's _Dsign/_FDsign take 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/_FDsign call 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251627755 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6085#issuecomment-6251627755). Originally posted by [oneandonlydean](https://github.com/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`/`_fdsign` take the value. If the console's `_Dsign`/`_FDsign` take 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`/`_FDsign` call 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.
xXPBSXx commented 2026-10-21 01:16:03 +00:00 (Migrated from github.com)

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.prx of two different retail titles' modules (two different builds of the module, same result in both): _Dsign and _FDsign take the value, not a pointer. The double or float arrives in xmm0, the function stores it in a stack slot, derives the most significant 16-bit word of it and returns that word masked with 0x8000. Nothing is taken from rdi as an argument, so the const double* / const float* signatures of this head do not match that.

Based on its head (ffea0b7c1d), in case it is useful to @notaxeltv: commit 45925a18e9 on xXPBSXx:fix/dsign-by-value changes both functions to take double / float by 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:

  • With the follow-up: guest_dsign passes 3 of 3 runs, guest_math passes 3 of 3.
  • Without it (this head's Math.cpp, the new test): guest_dsign fails 3 of 3 (0xc0000409).
  • tools/check_conventions.py and merge-tree against current main: 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).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6305567424 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6085#issuecomment-6305567424). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T01:16:03Z. --- @oneandonlydean thanks for the question. I read the two exports from the `libc.prx` of two different retail titles' modules (two different builds of the module, same result in both): `_Dsign` and `_FDsign` take the value, not a pointer. The `double` or `float` arrives in `xmm0`, the function stores it in a stack slot, derives the most significant 16-bit word of it and returns that word masked with `0x8000`. Nothing is taken from `rdi` as an argument, so the `const double*` / `const float*` signatures of this head do not match that. Based on its head (`ffea0b7c1d`), in case it is useful to @notaxeltv: commit `45925a18e9` on `xXPBSXx:fix/dsign-by-value` changes both functions to take `double` / `float` by 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: - With the follow-up: `guest_dsign` passes 3 of 3 runs, `guest_math` passes 3 of 3. - Without it (this head's `Math.cpp`, the new test): `guest_dsign` fails 3 of 3 (`0xc0000409`). - `tools/check_conventions.py` and merge-tree against current `main`: 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).
oneandonlydean commented 2026-10-21 01:29:32 +00:00 (Migrated from github.com)

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.prx from PPSA21564, _Dsign stores xmm0 to the stack, takes the top 16-bit word of the double and returns it & 0x8000, and _FDsign does the same with a float. That matches what @xXPBSXx found in two other retail builds. With const double* / const float*, the function reads a pointer from rdi that the caller never set.

Your sign logic is right, so only the signature needs to change: short _Dsign(double) and short _FDsign(float), with the tests calling them by value (the null checks go away). @xXPBSXx's commit 45925a18e9 on xXPBSXx:fix/dsign-by-value does 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6305754105 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6085#issuecomment-6305754105). Originally posted by [oneandonlydean](https://github.com/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.prx` from PPSA21564, `_Dsign` stores `xmm0` to the stack, takes the top 16-bit word of the double and returns it `& 0x8000`, and `_FDsign` does the same with a float. That matches what @xXPBSXx found in two other retail builds. With `const double*` / `const float*`, the function reads a pointer from `rdi` that the caller never set. Your sign logic is right, so only the signature needs to change: `short _Dsign(double)` and `short _FDsign(float)`, with the tests calling them by value (the null checks go away). @xXPBSXx's commit `45925a18e9` on `xXPBSXx:fix/dsign-by-value` does 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.
THEMANnt commented 2026-10-26 13:19:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-26T13:19:18Z.

Review: APPROVED


Reviewed ffea0b7c1d088005e99ee30256c4decf2834d34d against f59d91ffc35b99502f7106ffd800190a974c31c1. 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5652591024 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6085#pullrequestreview-5652591024). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-26T13:19:18Z. **Review:** APPROVED --- Reviewed `ffea0b7c1d088005e99ee30256c4decf2834d34d` against `f59d91ffc35b99502f7106ffd800190a974c31c1`. 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.
ahmadmuj commented 2026-11-01 17:12:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-11-01T17:12:21Z.

Review: APPROVED


Reviewed head abbd3bd22ab8 merged onto main f2d874c1fdcc (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 on ffea0b7c (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.
  • Red control: main's Math.cpp/Api.hpp with this test doesn't build ('_FDsign_nid_postfix' was not declared in this scope).
  • objdump of the built libc.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:
    _FDsign: movd eax,xmm0 ; shr eax,0x10 ; and ax,0x8000 ; ret
    _Dsign:  movq rax,xmm0 ; shr rax,0x30 ; and ax,0x8000 ; ret
    
  • Scratch caller against the built 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:

  • NIDs: the tools/nid_names.py hash gives _FDsign -> 6ei1eQn2WIc and _Dsign -> zvl6nrvd0sE, matching the description.
  • Wine's msvcrt _fdsign/_dsign (dlls/msvcrt/math.c) do the same >> 16 / >> 48 & 0x8000. Returning short -32768 matches the existing _LDsign (MathExact.cpp:252) and its test.
  • No other _Dsign/_FDsign on 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, in docs/dev/debt/libc.md: "_Dsign/_FDsign take 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).

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5729294458 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6085#pullrequestreview-5729294458). Originally posted by [ahmadmuj](https://github.com/ahmadmuj) on 2026-11-01T17:12:21Z. **Review:** APPROVED --- Reviewed head `abbd3bd22ab8` merged onto main `f2d874c1fdcc` (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 on `ffea0b7c` (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. - Red control: main's `Math.cpp`/`Api.hpp` with this test doesn't build (`'_FDsign_nid_postfix' was not declared in this scope`). - `objdump` of the built `libc.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: ``` _FDsign: movd eax,xmm0 ; shr eax,0x10 ; and ax,0x8000 ; ret _Dsign: movq rax,xmm0 ; shr rax,0x30 ; and ax,0x8000 ; ret ``` - Scratch caller against the built `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: - NIDs: the `tools/nid_names.py` hash gives `_FDsign` -> `6ei1eQn2WIc` and `_Dsign` -> `zvl6nrvd0sE`, matching the description. - Wine's msvcrt `_fdsign`/`_dsign` (`dlls/msvcrt/math.c`) do the same `>> 16` / `>> 48` & 0x8000. Returning `short` -32768 matches the existing `_LDsign` (`MathExact.cpp:252`) and its test. - No other `_Dsign`/`_FDsign` on 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, in `docs/dev/debt/libc.md`: "`_Dsign`/`_FDsign` take 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).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!6085
No description provided.