feat(libc): implement the std::__sce_v2 num_get virtuals for char floating point #16944

Open
Danigamer05 wants to merge 19 commits from upstream-pr/16944 into main
Danigamer05 commented 2026-11-08 00:00:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Danigamer05 on 2026-11-08T00:00:44Z.


What

Builds on #16919: this branch contains its commits, and through it #16560, #16516, #16214, #16178 and #15923, with current main merged in. Until they merge, only the last commit is this PR's change.

Implement the three floating-point do_get virtuals of std::__sce_v2::num_get<char>, the last slots of the facet that still threw NotImplemented_nid_no_patch: float, double and long double. These slots are not exports, so this PR adds no NID. The wchar_t facet of #16924 keeps throwing in these slots.

The behavior comes from the libc.prx bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6), read from its disassembly and run. The module reads these fields in two generations of Dinkumware code, and this PR keeps both where it does:

  • float and double (0xD24C0, 0xD2710) read the field with the current reader (0xD4D80, microsoft/STL's _Parse_fp_with_locale). It takes up to 768 significant digits and turns later ones into a power of ten. It reads 0x hex fields with p exponents whatever the flags say, takes the decimal point from numpunct and writes the C locale's, and checks groups as the integer reader does. It folds the power into a clamped exponent that it writes into the field. The field is converted with _Stof or _Stod with errno saved and restored. A failure assigns failbit and stores the converted value, or 0 when nothing converted. A bad grouping fails but keeps the value.
  • long double (0xD2960) uses the older reader (0xD69A0). Without hexfloat it keeps 48 significant digits, rounds up on a nonzero lost digit, carries into the backstop digit with an extra power of ten, keeps 8 exponent digits and returns the power for _Stoldx. A double separator or a separator at the start ends the field, and a bad grouping empties it. With hexfloat it calls the current reader with 36 significant digits and empties the field on a failure or a bad grouping. The value is always stored, eofbit and then failbit are added to the state rather than assigned, and the grouping does not set failbit by itself.

The _Makeloc debt entry now lists all of num_get<char>, and the num_get entry names the conversion functions and the module's 768-byte buffer, which a field of about 760 significant digits overruns there.

Tested

Windows 11, MinGW GCC 15.2, Release, head on top of #16919. Not run on Linux or macOS, not run in a title.

  • guest_sce_v2_num_get_char now also covers the three slots: decimal and hex fields, exponents, a lone zero, point or e without digits, leading fraction zeros, overflow to infinity with errno restored, digits past 768, the numpunct decimal point, good and bad groups for both readers, hexfloat for long double, its added failbit, and the carry into the backstop. Each of these inputs was also run against the module. The test passes, as do guest_sce_v2_num_put_char, guest_sce_v2_num_put_wide, guest_sce_v2_char_facet_virtuals, guest_sce_v2_makeloc, guest_sce_v2_locale, guest_sce_v2_locale_basics, guest_sce_v2_locimp_references, guest_sce_v2_facet_ids, guest_locale, guest_sce_v2_exceptions, guest_sce_v2_string_to_integer and public_headers (13 of 13).
  • The differential harness of #16919 on the three slots, with texts that mix decimal and hex numbers, points, exponents and separators, fields of up to 700 digits, random decimal points, separators and groupings, and hexfloat on a quarter of the calls. It compares the value bytes, the state, errno, the stream's fields, the iterator and buffer state, and the order of the ctype, numpunct, underflow and uflow calls.
    • With the module's _Sto*x, _Stof, _Stod and _Stoldx redirected to this library's: 400,000 calls over 2 seeds, 0 differences.
    • With the module's own conversion functions: 114 of 200,000 calls differ, all in the last bit of a float (97) or double (17), which the strtof debt entry already describes.
  • Integer, bool and pointer regression on the harness of #16919: 50,000 calls, 0 differences.
  • Negative control: 34 single-change mutations of the new code. The harness catches 24 and the final test 23, 26 together. The first test run missed 9 that the harness caught, so the test was strengthened and those were rerun; the harness alone still catches 3 (kept leading zeros and the two significant-digit limits of the current reader). The other 8 make no visible difference: the trailing separator skip cannot run because the digit loop already consumes separators. Putting back a zero before a fraction or an exponent, a missing 0 after 0x, storing leading fraction zeros, and two more exponent digits give the same converted value. The 48-digit limit and the lost-digit nudge would need a field that decides rounding past those digits.
  • check_conventions, git diff --check: clean. Merges cleanly with main. pr_overlap finds no open PR with the same functions. It lists #16924, which builds on #16919 like this PR and adds the wchar_t virtuals. Merging the two branches conflicts only in the two debt entries both rewrite; the code merges cleanly, and the wchar_t floating-point slots keep throwing after it. Whichever merges second needs main merged in. It could not compare 34 PRs that conflict with main on shared files; of those, the 4 that touch LocaleSupport.cpp (#9526, #11172, #12518, #12704) do not add these virtuals.

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: #16919
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5207035105 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16944). Originally posted by [Danigamer05](https://github.com/Danigamer05) on 2026-11-08T00:00:44Z. --- ### What Builds on #16919: this branch contains its commits, and through it #16560, #16516, #16214, #16178 and #15923, with current `main` merged in. Until they merge, only the last commit is this PR's change. Implement the three floating-point `do_get` virtuals of `std::__sce_v2::num_get<char>`, the last slots of the facet that still threw `NotImplemented_nid_no_patch`: `float`, `double` and `long double`. These slots are not exports, so this PR adds no NID. The `wchar_t` facet of #16924 keeps throwing in these slots. The behavior comes from the `libc.prx` bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 `483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6`), read from its disassembly and run. The module reads these fields in two generations of Dinkumware code, and this PR keeps both where it does: - `float` and `double` (`0xD24C0`, `0xD2710`) read the field with the current reader (`0xD4D80`, microsoft/STL's `_Parse_fp_with_locale`). It takes up to 768 significant digits and turns later ones into a power of ten. It reads `0x` hex fields with `p` exponents whatever the flags say, takes the decimal point from `numpunct` and writes the C locale's, and checks groups as the integer reader does. It folds the power into a clamped exponent that it writes into the field. The field is converted with `_Stof` or `_Stod` with `errno` saved and restored. A failure assigns `failbit` and stores the converted value, or 0 when nothing converted. A bad grouping fails but keeps the value. - `long double` (`0xD2960`) uses the older reader (`0xD69A0`). Without `hexfloat` it keeps 48 significant digits, rounds up on a nonzero lost digit, carries into the backstop digit with an extra power of ten, keeps 8 exponent digits and returns the power for `_Stoldx`. A double separator or a separator at the start ends the field, and a bad grouping empties it. With `hexfloat` it calls the current reader with 36 significant digits and empties the field on a failure or a bad grouping. The value is always stored, `eofbit` and then `failbit` are added to the state rather than assigned, and the grouping does not set `failbit` by itself. The `_Makeloc` debt entry now lists all of `num_get<char>`, and the `num_get` entry names the conversion functions and the module's 768-byte buffer, which a field of about 760 significant digits overruns there. ### 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 11, MinGW GCC 15.2, Release, head on top of #16919. Not run on Linux or macOS, not run in a title. - `guest_sce_v2_num_get_char` now also covers the three slots: decimal and hex fields, exponents, a lone zero, point or `e` without digits, leading fraction zeros, overflow to infinity with `errno` restored, digits past 768, the `numpunct` decimal point, good and bad groups for both readers, `hexfloat` for `long double`, its added `failbit`, and the carry into the backstop. Each of these inputs was also run against the module. The test passes, as do `guest_sce_v2_num_put_char`, `guest_sce_v2_num_put_wide`, `guest_sce_v2_char_facet_virtuals`, `guest_sce_v2_makeloc`, `guest_sce_v2_locale`, `guest_sce_v2_locale_basics`, `guest_sce_v2_locimp_references`, `guest_sce_v2_facet_ids`, `guest_locale`, `guest_sce_v2_exceptions`, `guest_sce_v2_string_to_integer` and `public_headers` (13 of 13). - The differential harness of #16919 on the three slots, with texts that mix decimal and hex numbers, points, exponents and separators, fields of up to 700 digits, random decimal points, separators and groupings, and `hexfloat` on a quarter of the calls. It compares the value bytes, the state, `errno`, the stream's fields, the iterator and buffer state, and the order of the `ctype`, `numpunct`, `underflow` and `uflow` calls. - With the module's `_Sto*x`, `_Stof`, `_Stod` and `_Stoldx` redirected to this library's: 400,000 calls over 2 seeds, 0 differences. - With the module's own conversion functions: 114 of 200,000 calls differ, all in the last bit of a `float` (97) or `double` (17), which the `strtof` debt entry already describes. - Integer, `bool` and pointer regression on the harness of #16919: 50,000 calls, 0 differences. - Negative control: 34 single-change mutations of the new code. The harness catches 24 and the final test 23, 26 together. The first test run missed 9 that the harness caught, so the test was strengthened and those were rerun; the harness alone still catches 3 (kept leading zeros and the two significant-digit limits of the current reader). The other 8 make no visible difference: the trailing separator skip cannot run because the digit loop already consumes separators. Putting back a zero before a fraction or an exponent, a missing `0` after `0x`, storing leading fraction zeros, and two more exponent digits give the same converted value. The 48-digit limit and the lost-digit nudge would need a field that decides rounding past those digits. - `check_conventions`, `git diff --check`: clean. Merges cleanly with `main`. `pr_overlap` finds no open PR with the same functions. It lists #16924, which builds on #16919 like this PR and adds the `wchar_t` virtuals. Merging the two branches conflicts only in the two debt entries both rewrite; the code merges cleanly, and the `wchar_t` floating-point slots keep throwing after it. Whichever merges second needs `main` merged in. It could not compare 34 PRs that conflict with `main` on shared files; of those, the 4 that touch `LocaleSupport.cpp` (#9526, #11172, #12518, #12704) do not add these virtuals. ### 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: #16919 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-20 12:48:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T12:48:33Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

Changes are required before merge: prevent out-of-bounds access when rounding a field whose significant digits were all discarded.

What I ran

  • Reviewed head 9f337f9b9bde0fc05ff6261781bbe1e2c417f807 using repo_read.py.
  • No tests or build commands were run in this review.

Results

Check Result Note
Source review failed Found a verified out-of-bounds write
Tests not run Author-reported tests were not run here

Findings

Blocking

  • core/libs/prx/libc/src/LocaleSupport.cpp:3041: When the integer part has at least maxSignificant digits but all are zero, significant remains zero while out still points after the initial 0. If the fraction then contains a nonzero digit, the fraction loop reaches the limit and sets lost = true without writing a fraction digit. The rounding code then selects out[-1] (or out[-2] if that is the decimal point) and increments it. For input such as 0. followed by 769 zeros and then 1, this modifies the decimal point or the leading zero instead of a retained significant digit. Handle this all-zero retained prefix before applying the lost-digit rounding adjustment; add a regression test for a tiny nonzero value beyond the significant-digit limit.

Non-blocking

None.

Not verified

  • Read the prepared description, commits, manifest and diff, and targeted ranges in LocaleSupport.cpp. The full text for changed files was excluded from the review bundle; source inspection used the pinned reader. Other changed files and behavior outside the cited code were not fully reviewed.
  • Did not run the author-reported Windows test suite or differential harness; Linux, macOS and console behavior were not verified.

To get this to a good state

  • Fix the rounding path for an all-zero retained prefix and add a regression test for a nonzero digit discarded after the significant-digit limit. Rerun the relevant floating-point tests and differential harness on the new head.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5992907886 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16944#pullrequestreview-5992907886). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T12:48:33Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested Changes are required before merge: prevent out-of-bounds access when rounding a field whose significant digits were all discarded. ## What I ran - Reviewed head `9f337f9b9bde0fc05ff6261781bbe1e2c417f807` using `repo_read.py`. - No tests or build commands were run in this review. ## Results | Check | Result | Note | |---|---|---| | Source review | failed | Found a verified out-of-bounds write | | Tests | not run | Author-reported tests were not run here | ## Findings ### Blocking - `core/libs/prx/libc/src/LocaleSupport.cpp:3041`: When the integer part has at least `maxSignificant` digits but all are zero, `significant` remains zero while `out` still points after the initial `0`. If the fraction then contains a nonzero digit, the fraction loop reaches the limit and sets `lost = true` without writing a fraction digit. The rounding code then selects `out[-1]` (or `out[-2]` if that is the decimal point) and increments it. For input such as `0.` followed by 769 zeros and then `1`, this modifies the decimal point or the leading zero instead of a retained significant digit. Handle this all-zero retained prefix before applying the lost-digit rounding adjustment; add a regression test for a tiny nonzero value beyond the significant-digit limit. ### Non-blocking None. ## Not verified - Read the prepared description, commits, manifest and diff, and targeted ranges in `LocaleSupport.cpp`. The full text for changed files was excluded from the review bundle; source inspection used the pinned reader. Other changed files and behavior outside the cited code were not fully reviewed. - Did not run the author-reported Windows test suite or differential harness; Linux, macOS and console behavior were not verified. ## To get this to a good state - Fix the rounding path for an all-zero retained prefix and add a regression test for a nonzero digit discarded after the significant-digit limit. Rerun the relevant floating-point tests and differential harness on the new head.
MarcZX10 commented 2026-11-20 21:00:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T21:00:06Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change based on the code reviewed; the points below are optional.

What I ran

Reviewed head a856bf56c1b41b6eca62a0c835cca7498bfe6531. No commands or tests were run. The reported Windows and harness results are author supplied; no merged preview was run.

Results

Check Result Note
Code review passed Floating point paths inspected
Tests not run Results supplied by author
Build not run No local build performed

Findings

Blocking

None.

Non-blocking

None.

Not verified

Read: core/libs/prx/libc/CMakeLists.txt, core/libs/prx/libc/include/GuestLocale.hpp, core/libs/prx/libc/src/LocaleSupport.cpp, core/libs/tests/GuestSceV2CharFacetVirtuals.cpp, core/libs/tests/GuestSceV2NumGetChar.cpp, core/libs/tests/GuestSceV2NumPutChar.cpp, core/libs/tests/GuestSceV2NumPutWide.cpp, and docs/dev/debt/libc.md. These are all files listed as reviewed in the manifest; no changed files were excluded. Only relevant portions of the larger files were inspected. Build and runtime behavior were not independently confirmed, including Linux, macOS, and title execution.

To get this to a good state

Nothing is required. The author supplied detailed differential and regression test results; these were not independently rerun.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5999317586 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16944#pullrequestreview-5999317586). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T21:00:06Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change based on the code reviewed; the points below are optional. ## What I ran Reviewed head `a856bf56c1b41b6eca62a0c835cca7498bfe6531`. No commands or tests were run. The reported Windows and harness results are author supplied; no merged preview was run. ## Results | Check | Result | Note | |---|---|---| | Code review | passed | Floating point paths inspected | | Tests | not run | Results supplied by author | | Build | not run | No local build performed | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Read: `core/libs/prx/libc/CMakeLists.txt`, `core/libs/prx/libc/include/GuestLocale.hpp`, `core/libs/prx/libc/src/LocaleSupport.cpp`, `core/libs/tests/GuestSceV2CharFacetVirtuals.cpp`, `core/libs/tests/GuestSceV2NumGetChar.cpp`, `core/libs/tests/GuestSceV2NumPutChar.cpp`, `core/libs/tests/GuestSceV2NumPutWide.cpp`, and `docs/dev/debt/libc.md`. These are all files listed as reviewed in the manifest; no changed files were excluded. Only relevant portions of the larger files were inspected. Build and runtime behavior were not independently confirmed, including Linux, macOS, and title execution. ## To get this to a good state Nothing is required. The author supplied detailed differential and regression test results; these were not independently rerun.
ligmaSec commented 2026-12-03 13:12:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:12:42Z.

Review: COMMENTED


Built the branch’s locale implementation and matching headers against the existing Linux runtime. The focused GuestSceV2NumGetChar fixture passed.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6170472451 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16944#pullrequestreview-6170472451). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T13:12:42Z. **Review:** COMMENTED --- Built the branch’s locale implementation and matching headers against the existing Linux runtime. The focused `GuestSceV2NumGetChar` fixture passed. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/16944:upstream-pr/16944'
git switch 'upstream-pr/16944'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/16944'
git switch 'upstream-pr/16944'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/16944'
git switch 'upstream-pr/16944'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/16944'
git switch 'main'
git merge --squash 'upstream-pr/16944'
git switch 'main'
git merge --ff-only 'upstream-pr/16944'
git switch 'main'
git merge 'upstream-pr/16944'
git push origin 'main'
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!16944
No description provided.