feat(libc): export the std::__sce_v2 float classification, integer-part and normalization helpers #14955

Merged
Danigamer05 merged 1 commit from upstream-pr/14955 into main 2026-11-03 05:12:25 +00:00
Danigamer05 commented 2026-11-02 04:30:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Danigamer05 on 2026-11-02T04:30:00Z.


What

Export eight std::__sce_v2 Dinkumware floating-point helpers from libc, each forwarding to the unversioned helper already in MathExact.cpp and Math.cpp:

Export NID Forwards to
_ZNSt8__sce_v26_DtestEPd Q4jbwEbIBkU _Dtest
_ZNSt8__sce_v27_FDtestEPf N1UVzJiqJcw _FDtest
_ZNSt8__sce_v27_LDtestEPe JWcsTyLhh4E _Dtest
_ZNSt8__sce_v25_DintEPds Lk4tA4JXn6w _Dint
_ZNSt8__sce_v26_FDintEPfs EZGGXQTe+O4 _FDint
_ZNSt8__sce_v26_LDintEPes PtChgopsIV0 _Dint
_ZNSt8__sce_v26_DnormEPNS_5_DvalE yUpZZbVLg-w _Dnorm
_ZNSt8__sce_v27_FDnormEPNS_5_FvalE eMWrDzXms5E _FDnorm

The behaviour comes from the libc.prx bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6), which exports all eight at RVAs 0xCB580, 0xCF280, 0x10C100, 0xCB230, 0xCF040, 0x10C0F0, 0xCA2B0 and 0xCA150. Its __sce_v2 long double forms take an 8-byte double: _LDtest calls the unversioned _Dtest, and _LDint calls std::__sce_v2::_Dint. The declarations here use double* for them. In that module the two _Dtest and the two _FDtest are byte-identical across namespaces; the other forms are separate compilations, so all eight were compared by running them.

Other __sce_v2 math helpers in the same module (_Dscale, _Dunscale, _Exp, _Cosh, _Sinh, _Feraise and their float forms) differ from the unversioned helpers here for subnormal inputs, NaN signs, errno or exception flags. They need their own implementations and are not part of this change.

Tested

Windows x86-64, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, main 926f7dd492b0b432d9287f4d6faaaf1c9d3c86c5.

  • Built libc, libkernel, their NID-patched production libraries and the guest_sce_v2_float_helpers, guest_dinkumware_float_bits and guest_math_exact tests. All three pass, as does public_headers.

  • The new test checks 56 double and 48 float classification inputs, 84 double and 60 float integer-part cases and 18 normalization cases. Each expected code and output was taken from the original module, not from this implementation.

  • The original functions were loaded from the bundled module with its relocations applied. Its __error import was bound to this libc and __stack_chk_guard to a local value; __stack_chk_fail and every other import would have stopped the run, and none was called. They then ran side by side with the patched production library, called by NID, on 32,269,675 vectors:

    • special values, every binary exponent from -1100 to 1100 and random bit patterns;
    • scales from -32768 to 32767;
    • random subnormals for the normalizers.

    Return code, output bits, errno, and MXCSR and x87 exception flags agree for all eight exports. The long double forms were run on 8-byte doubles.

  • Negative control: three forwarders were temporarily altered (_Dint and _LDint with an off-by-one scale, _LDtest negating the code, _FDnorm adding one). The new CTest failed, and the side-by-side run flagged exactly those four exports while the other four still agreed. The source was then restored byte for byte (SHA-256 checked), rebuilt, and all four tests and all 32,269,675 vectors passed again.

  • Code conventions and git diff --check pass. All tests and the side-by-side run were repeated at the submitted commit a99455ab20bfc4dd5f57a6509cf910838dea81ef.

  • tools/pr_overlap.py read 1,895 open PRs and reports no confirmed overlap. It keeps exit 2 for 18 branches that already conflict with main (#5021, #7081, #7386, #7447, #7715, #8150, #8965, #9340, #9371, #9447, #9526, #9929, #10405, #10987, #11332, #11831, #12560, #14212). None of their added lines contains the eight names, their NIDs or the new test. Each was merged with this branch and with main using git merge-tree. This branch adds no conflict block to any of them. Only #14212, which re-spaces every debt file, already conflicts with main at the nearbyint entry next to the new debt line. The debt entry was moved there from an earlier place, where it would have added a conflict with #11332. Merging the 155 open PRs that edit docs/dev/debt/libc.md against this placement adds no conflict.

Not tested: Linux, macOS, another SDK, a game, GPU or console. No game compatibility claim. No original module, extracted bytes, oracle or log is committed or uploaded.

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
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5114972713 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14955). Originally posted by [Danigamer05](https://github.com/Danigamer05) on 2026-11-02T04:30:00Z. --- ### What Export eight `std::__sce_v2` Dinkumware floating-point helpers from libc, each forwarding to the unversioned helper already in `MathExact.cpp` and `Math.cpp`: | Export | NID | Forwards to | | --- | --- | --- | | `_ZNSt8__sce_v26_DtestEPd` | `Q4jbwEbIBkU` | `_Dtest` | | `_ZNSt8__sce_v27_FDtestEPf` | `N1UVzJiqJcw` | `_FDtest` | | `_ZNSt8__sce_v27_LDtestEPe` | `JWcsTyLhh4E` | `_Dtest` | | `_ZNSt8__sce_v25_DintEPds` | `Lk4tA4JXn6w` | `_Dint` | | `_ZNSt8__sce_v26_FDintEPfs` | `EZGGXQTe+O4` | `_FDint` | | `_ZNSt8__sce_v26_LDintEPes` | `PtChgopsIV0` | `_Dint` | | `_ZNSt8__sce_v26_DnormEPNS_5_DvalE` | `yUpZZbVLg-w` | `_Dnorm` | | `_ZNSt8__sce_v27_FDnormEPNS_5_FvalE` | `eMWrDzXms5E` | `_FDnorm` | The behaviour comes from the `libc.prx` bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 `483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6`), which exports all eight at RVAs `0xCB580`, `0xCF280`, `0x10C100`, `0xCB230`, `0xCF040`, `0x10C0F0`, `0xCA2B0` and `0xCA150`. Its `__sce_v2` `long double` forms take an 8-byte `double`: `_LDtest` calls the unversioned `_Dtest`, and `_LDint` calls `std::__sce_v2::_Dint`. The declarations here use `double*` for them. In that module the two `_Dtest` and the two `_FDtest` are byte-identical across namespaces; the other forms are separate compilations, so all eight were compared by running them. Other `__sce_v2` math helpers in the same module (`_Dscale`, `_Dunscale`, `_Exp`, `_Cosh`, `_Sinh`, `_Feraise` and their float forms) differ from the unversioned helpers here for subnormal inputs, NaN signs, `errno` or exception flags. They need their own implementations and are not part of this change. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows x86-64, WinLibs GCC 15.2.0, Release, `BUILD_TESTING=ON`, main `926f7dd492b0b432d9287f4d6faaaf1c9d3c86c5`. - Built libc, libkernel, their NID-patched production libraries and the `guest_sce_v2_float_helpers`, `guest_dinkumware_float_bits` and `guest_math_exact` tests. All three pass, as does `public_headers`. - The new test checks 56 double and 48 float classification inputs, 84 double and 60 float integer-part cases and 18 normalization cases. Each expected code and output was taken from the original module, not from this implementation. - The original functions were loaded from the bundled module with its relocations applied. Its `__error` import was bound to this libc and `__stack_chk_guard` to a local value; `__stack_chk_fail` and every other import would have stopped the run, and none was called. They then ran side by side with the patched production library, called by NID, on 32,269,675 vectors: - special values, every binary exponent from -1100 to 1100 and random bit patterns; - scales from -32768 to 32767; - random subnormals for the normalizers. Return code, output bits, `errno`, and MXCSR and x87 exception flags agree for all eight exports. The `long double` forms were run on 8-byte doubles. - Negative control: three forwarders were temporarily altered (`_Dint` and `_LDint` with an off-by-one scale, `_LDtest` negating the code, `_FDnorm` adding one). The new CTest failed, and the side-by-side run flagged exactly those four exports while the other four still agreed. The source was then restored byte for byte (SHA-256 checked), rebuilt, and all four tests and all 32,269,675 vectors passed again. - Code conventions and `git diff --check` pass. All tests and the side-by-side run were repeated at the submitted commit `a99455ab20bfc4dd5f57a6509cf910838dea81ef`. - `tools/pr_overlap.py` read 1,895 open PRs and reports no confirmed overlap. It keeps exit 2 for 18 branches that already conflict with main (#5021, #7081, #7386, #7447, #7715, #8150, #8965, #9340, #9371, #9447, #9526, #9929, #10405, #10987, #11332, #11831, #12560, #14212). None of their added lines contains the eight names, their NIDs or the new test. Each was merged with this branch and with main using `git merge-tree`. This branch adds no conflict block to any of them. Only #14212, which re-spaces every debt file, already conflicts with main at the `nearbyint` entry next to the new debt line. The debt entry was moved there from an earlier place, where it would have added a conflict with #11332. Merging the 155 open PRs that edit `docs/dev/debt/libc.md` against this placement adds no conflict. Not tested: Linux, macOS, another SDK, a game, GPU or console. No game compatibility claim. No original module, extracted bytes, oracle or log is committed or uploaded. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/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 - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
BunnyFl commented 2026-11-02 16:08:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T16:08:31Z.

Review: APPROVED


Cross-checked against firmware 13.42's system libSceLibcInternal.sprx (sha256 a01795ab49df639dd40abd6194956ada062244826824ce486c9acab227bf5285) as well as the title's bundled libc.prx. Read from disassembly only, not measured on a console:

  • All eight NIDs are exported there too.
  • _LDtest (0x11cf30) is call 0x4ee10, the unversioned _Dtest.
  • _LDint (0x11cf20) is call 0xdc380, which is std::__sce_v2::_Dint.

So the long double-takes-double forwarding in the PR matches the system module as well. The versioned _Dtest, _FDtest and _FDnorm bodies are byte-identical to the unversioned ones in this module. The _Dint and _FDint pairs differ in bytes, so the run-based comparison in the PR is what settles those two. I didn't re-run that comparison against the system module.

Build and test on Windows (WinLibs GCC, BUILD_TESTING=ON), PR merged into current main: guest_sce_v2_float_helpers and guest_math_exact pass. On main the exports don't exist, and the test doesn't link.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5739523146 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14955#pullrequestreview-5739523146). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-02T16:08:31Z. **Review:** APPROVED --- Cross-checked against firmware 13.42's system `libSceLibcInternal.sprx` (sha256 `a01795ab49df639dd40abd6194956ada062244826824ce486c9acab227bf5285`) as well as the title's bundled `libc.prx`. Read from disassembly only, not measured on a console: - All eight NIDs are exported there too. - `_LDtest` (`0x11cf30`) is `call 0x4ee10`, the unversioned `_Dtest`. - `_LDint` (`0x11cf20`) is `call 0xdc380`, which is `std::__sce_v2::_Dint`. So the `long double`-takes-`double` forwarding in the PR matches the system module as well. The versioned `_Dtest`, `_FDtest` and `_FDnorm` bodies are byte-identical to the unversioned ones in this module. The `_Dint` and `_FDint` pairs differ in bytes, so the run-based comparison in the PR is what settles those two. I didn't re-run that comparison against the system module. Build and test on Windows (WinLibs GCC, `BUILD_TESTING=ON`), PR merged into current `main`: `guest_sce_v2_float_helpers` and `guest_math_exact` pass. On `main` the exports don't exist, and the test doesn't link.
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!14955
No description provided.