fix(libc): format %La like titles' libc.prx does #9958

Merged
JJenkx merged 1 commit from upstream-pr/9958 into main 2026-10-26 15:30:59 +00:00
JJenkx commented 2026-10-23 00:07:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-23T00:07:16Z.


What

A long double %La or %LA still went to the host after #9699, as that PR records. MinGW's printf on Windows writes the 64-bit significand with its explicit integer bit as the leading hexadecimal digit. The libc.prx that titles ship normalises a long double the way it does a double: a leading 1, then the other 63 bits as 16 hexadecimal digits with the last bit zero. Console vs main on Windows (both columns measured):

Call Console main
%La of 0.1L 0x1.999999999999999ap-4 0xc.ccccccccccccccdp-7
%La of 1.0L 0x1p+0 0x8p-3
%.0La of 1.5L 0x2p+0 0xcp-3
%.15La of 0x1.fffffffffffffffep0L 0x2.000000000000000p+0 0xf.fffffffffffffffp-3
%La of 0x1p-16445L (smallest subnormal) 0x1p-16445 0x0.000000000000001p-16385
%010La of 1.5L 0x001.8p+0 0x0000cp-3

A shorter precision rounds half up on the dropped digits. A carry stays in the leading digit, as #9699 does for double.

This PR splits #9699's HexFloat into HexDigits, which holds the digit, rounding, flag and width code, and two front ends. The double one is unchanged in behaviour. The new long double one normalises with frexp. Finite long double %a/%A now use it in the narrow and wide families, next to #9916's DecimalFloat. Infinities and NaN keep their current paths.

Tested

Latest review refresh: afa58432f356bd5d481cc6fa99b9b736e5a80dba, the sole authored topic on main 035ac96edd092773a5ba0131453de80084a23533 after #9927 merged. Linux Release: formatting, wide formatting and variadic groups each pass three runs before and after restoration (9 passes per arm). Restoring only main production with the PR tests retained fails both expected %La regressions; the variadic control passes. Conventions, whitespace and main sync pass; the authored patch is unchanged. Exact-head evidence, SHA-256 9cba098a67264de658442a500905e4196e20f50d666c132bc7eaeb308061e0dd. Earlier reports below retain their original source pins and platform limits.

Refreshed exact head, 2026-10-25: 98992248b272e3729a4aaa76118ea2298ab1c80a. One own final commit directly on refreshed #9927 at 2def057898f2d0d857bed1579e14b6930adf4cd2, with main 49d1f9b07ec7f6f989ace1c504bbe9dd6748dcbb underneath. Its original final patch and debt explanation are preserved. No merge commits or duplicated merged prerequisites. All added/removed line multisets for this topic's code, tests and debt match the former public patch. Conventions and whitespace pass. Both stack heads merge cleanly with newer main b76f08cf33ea280d6155f16a84c1555701c3b2af, which changes only libSceNet export/tests/debt since the tested base; that is a merge preview, not another build.

Fresh Linux GCC 16.2.1 Release: rebuilt libc and all 12 selected CPU test executables. Exact main, candidate and restored candidate each pass 12 groups × 3 repetitions (36 passes per arm), zero skips. This includes complete guest_formatting, guest_wide_formatting and guest_stdio_variadic executables, plus wide strings/conversion/stream scanning, scan counts, strings, allocating strings, allocator failures, multibyte locale and character checks.

Restoring only #9927's WindowsFormatting.hpp and FormattingWide.cpp while retaining the leaf tests fails both formatting groups: narrow %La of 0.1L gives the host's explicit-integer-bit form, and the wide long-double hexadecimal check fails. Those parent-production controls fail both expected groups. Restoring this exact head passes all 36 executions again and reproduces identical hashes for libc and all 12 tested executables.

Both pinned heads, full source-preservation checks, patches, build/test logs, parent controls and restoration hashes. SHA-256: 7da9766761e33dbc0bd05a7462cda802cb6b2d9a096516324133055079f9e151; downloaded copy verified.

These are CPU regression results, not a fresh Windows run, converted title-libc differential, physical-console measurement, game/performance run or full-suite build. Earlier evidence below retains its original revisions and platforms.

Historical pinned validation

Earlier Linux refresh: 252b1593b85d3c1fdef3822c795bce98666b8e6d on main 637220db112a3daf4960984290a82fcf65ba7061. The stack is rebuilt linearly in the order #9699 → #9916 → #9927 → #9958 → #10379, with no merge commits or duplicated prerequisite commits. This PR adds one long-double hexadecimal commit. Fresh Release libc/fixture build and guest_formatting, guest_wide_formatting, guest_stdio_variadic pass (3/3) on this exact head; conventions against the tested main and whitespace checks pass. Final-stack conventions against origin/main have zero errors (six inherited debt-length warnings). All five heads also merge cleanly with newer main c8d34aa8f4d8058d57169cc1e423ba6db00faaf0; that merge preview is not an additional runtime test. The original double and long-double hexadecimal helper bodies are preserved byte for byte, including their output-length bounds. All five pinned heads, patches, checks and control logs (SHA-256 9cda806ab2a54a4a0ce012517eafb7db0441ab2665d2e49884c3d1fc5b9e0c8a). No fresh Windows, title-library comparison, physical-console, game or performance result is claimed; Windows testing remains paused. The requested fresh Windows validation on #9699 is still outstanding.

Historical validation on previous public head 89f761f7aba4a50a874b43893ee83f22636f33cc is retained below with its original scope; references there to ‘exact head’ refer to that historical run.

Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, BUILD_TESTING=ON. Head 8283798a60, on #9927's head 72e9e54e15 (main 895f47f4ee).

  • Differential run: a scratch loader runs a title's decrypted libc.prx natively and compares its snprintf with this build's snprintf_nid_postfix.

    • Fixed cases: [%La], [%LA], [%.3La], [%.0La], [%#.0La], [%20La], [%-+20.2La] and [%.20La], each on eleven values: 0.1, 1, 1.5, -2, the smallest subnormal and normal, the largest finite, +0, -0, π and 1e-4000.
    • Random cases: 100,000 random long double values in %La and %.0La…%.19La.
    • On main 72 of the 88 fixed cases and all 100,000 random ones differ. With this change none differ, on the copies bundled with PPSA07923, PPSA05916 and PPSA13934.
  • guest_formatting: the new CheckLongDoubleHexFloat has 13 console results, covering ties and carries, #, +, - and 0, ±0, the subnormal and largest values, and a long precision. guest_wide_formatting gains a swprintf %La check. The libc formatting, scanning, stream, wide-character and string tests (34) pass in three runs out of three. With #9927's WindowsFormatting.hpp and FormattingWide.cpp and these tests, guest_formatting and guest_wide_formatting fail.

  • python tools/check_conventions.py --base origin/main and git diff --check pass.

  • Not tested on a physical console.

  • Linux (reviewer run): MarcZX10 ran a focused Linux check in an existing configured Release build with GCC 12: guest_formatting and guest_wide_formatting passed 2/2 with this PR head's formatting and test sources. That reused an older configured tree with the PR's sources overlaid, so it is a focused Linux run, not a clean CI build.

  • Linux (exact PR commit): 8283798a603b845204cb5efe95c85344ce1be56a in a fresh detached worktree with initialized submodules and a newly configured Ninja Release build (BUILD_TESTING=ON, ANYPS5_RELINKER_CLI=ON, ANYPS5_ENABLE_SPIRV_TOOLS=OFF), GCC 16.2.1 20260810, glibc 2.44. Built guest_formatting_tests and guest_wide_formatting_tests; ctest --test-dir <build> -R '^guest_(wide_)?formatting$' -V --no-tests=error --timeout 120 passed 2/2 in each of three runs, with no skipped tests. This verifies the complete two focused executables at this PR commit; it is not a full product build, a new console differential run, or a test against latest main. No negative control was run in this Linux job.

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 (#9699, #9916 and #9927 are merged; #9927 landed from 2def057898f2d0d857bed1579e14b6930adf4cd2)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a (CPU libc tests)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4975824533 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9958). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-23T00:07:16Z. --- ### What A `long double` `%La` or `%LA` still went to the host after #9699, as that PR records. MinGW's printf on Windows writes the 64-bit significand with its explicit integer bit as the leading hexadecimal digit. The `libc.prx` that titles ship normalises a `long double` the way it does a `double`: a leading 1, then the other 63 bits as 16 hexadecimal digits with the last bit zero. Console vs `main` on Windows (both columns measured): | Call | Console | `main` | |---|---|---| | `%La` of 0.1L | `0x1.999999999999999ap-4` | `0xc.ccccccccccccccdp-7` | | `%La` of 1.0L | `0x1p+0` | `0x8p-3` | | `%.0La` of 1.5L | `0x2p+0` | `0xcp-3` | | `%.15La` of `0x1.fffffffffffffffep0L` | `0x2.000000000000000p+0` | `0xf.fffffffffffffffp-3` | | `%La` of `0x1p-16445L` (smallest subnormal) | `0x1p-16445` | `0x0.000000000000001p-16385` | | `%010La` of 1.5L | `0x001.8p+0` | `0x0000cp-3` | A shorter precision rounds half up on the dropped digits. A carry stays in the leading digit, as #9699 does for `double`. This PR splits #9699's `HexFloat` into `HexDigits`, which holds the digit, rounding, flag and width code, and two front ends. The `double` one is unchanged in behaviour. The new `long double` one normalises with `frexp`. Finite `long double` `%a`/`%A` now use it in the narrow and wide families, next to #9916's `DecimalFloat`. Infinities and NaN keep their current paths. ### Tested <!-- review-refresh-20261026-pr9958 --> Latest review refresh: `afa58432f356bd5d481cc6fa99b9b736e5a80dba`, the sole authored topic on main `035ac96edd092773a5ba0131453de80084a23533` after #9927 merged. Linux Release: formatting, wide formatting and variadic groups each pass three runs before and after restoration (9 passes per arm). Restoring only main production with the PR tests retained fails both expected `%La` regressions; the variadic control passes. Conventions, whitespace and main sync pass; the authored patch is unchanged. [Exact-head evidence](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/pr9958-headafa58432-main035ac9-linux-refresh.tar.gz), SHA-256 `9cba098a67264de658442a500905e4196e20f50d666c132bc7eaeb308061e0dd`. Earlier reports below retain their original source pins and platform limits. <!-- 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. --> **Refreshed exact head, 2026-10-25: `98992248b272e3729a4aaa76118ea2298ab1c80a`.** One own final commit directly on refreshed #9927 at `2def057898f2d0d857bed1579e14b6930adf4cd2`, with main `49d1f9b07ec7f6f989ace1c504bbe9dd6748dcbb` underneath. Its original final patch and debt explanation are preserved. No merge commits or duplicated merged prerequisites. All added/removed line multisets for this topic's code, tests and debt match the former public patch. Conventions and whitespace pass. Both stack heads merge cleanly with newer main `b76f08cf33ea280d6155f16a84c1555701c3b2af`, which changes only libSceNet export/tests/debt since the tested base; that is a merge preview, not another build. Fresh Linux GCC 16.2.1 Release: rebuilt libc and all 12 selected CPU test executables. Exact main, candidate and restored candidate each pass **12 groups × 3 repetitions (36 passes per arm), zero skips**. This includes complete `guest_formatting`, `guest_wide_formatting` and `guest_stdio_variadic` executables, plus wide strings/conversion/stream scanning, scan counts, strings, allocating strings, allocator failures, multibyte locale and character checks. Restoring only #9927's `WindowsFormatting.hpp` and `FormattingWide.cpp` while retaining the leaf tests fails both formatting groups: narrow `%La` of `0.1L` gives the host's explicit-integer-bit form, and the wide long-double hexadecimal check fails. Those parent-production controls fail both expected groups. Restoring this exact head passes all 36 executions again and reproduces identical hashes for libc and all 12 tested executables. [Both pinned heads, full source-preservation checks, patches, build/test logs, parent controls and restoration hashes](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/format-stack-head2def0578-head98992248-main49d-linux-validation.tar.gz). SHA-256: `7da9766761e33dbc0bd05a7462cda802cb6b2d9a096516324133055079f9e151`; downloaded copy verified. These are CPU regression results, not a fresh Windows run, converted title-libc differential, physical-console measurement, game/performance run or full-suite build. Earlier evidence below retains its original revisions and platforms. ### Historical pinned validation Earlier Linux refresh: `252b1593b85d3c1fdef3822c795bce98666b8e6d` on main `637220db112a3daf4960984290a82fcf65ba7061`. The stack is rebuilt linearly in the order #9699 → #9916 → #9927 → #9958 → #10379, with no merge commits or duplicated prerequisite commits. This PR adds one long-double hexadecimal commit. Fresh Release libc/fixture build and `guest_formatting`, `guest_wide_formatting`, `guest_stdio_variadic` pass (3/3) on this exact head; conventions against the tested main and whitespace checks pass. Final-stack conventions against origin/main have zero errors (six inherited debt-length warnings). All five heads also merge cleanly with newer main `c8d34aa8f4d8058d57169cc1e423ba6db00faaf0`; that merge preview is not an additional runtime test. The original double and long-double hexadecimal helper bodies are preserved byte for byte, including their output-length bounds. [All five pinned heads, patches, checks and control logs](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/format-stack-main637220db-five-heads-linux-20261024.tar.gz) (SHA-256 `9cda806ab2a54a4a0ce012517eafb7db0441ab2665d2e49884c3d1fc5b9e0c8a`). No fresh Windows, title-library comparison, physical-console, game or performance result is claimed; Windows testing remains paused. The requested fresh Windows validation on #9699 is still outstanding. Historical validation on previous public head `89f761f7aba4a50a874b43893ee83f22636f33cc` is retained below with its original scope; references there to ‘exact head’ refer to that historical run. Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, `BUILD_TESTING=ON`. Head 8283798a60, on #9927's head 72e9e54e15 (`main` 895f47f4ee). - **Differential run:** a scratch loader runs a title's decrypted `libc.prx` natively and compares its `snprintf` with this build's `snprintf_nid_postfix`. - Fixed cases: `[%La]`, `[%LA]`, `[%.3La]`, `[%.0La]`, `[%#.0La]`, `[%20La]`, `[%-+20.2La]` and `[%.20La]`, each on eleven values: 0.1, 1, 1.5, -2, the smallest subnormal and normal, the largest finite, +0, -0, π and 1e-4000. - Random cases: 100,000 random `long double` values in `%La` and `%.0La`…`%.19La`. - On `main` 72 of the 88 fixed cases and all 100,000 random ones differ. With this change none differ, on the copies bundled with PPSA07923, PPSA05916 and PPSA13934. - **`guest_formatting`:** the new `CheckLongDoubleHexFloat` has 13 console results, covering ties and carries, `#`, `+`, `-` and `0`, ±0, the subnormal and largest values, and a long precision. `guest_wide_formatting` gains a `swprintf` `%La` check. The libc formatting, scanning, stream, wide-character and string tests (34) pass in three runs out of three. With #9927's `WindowsFormatting.hpp` and `FormattingWide.cpp` and these tests, `guest_formatting` and `guest_wide_formatting` fail. - `python tools/check_conventions.py --base origin/main` and `git diff --check` pass. - Not tested on a physical console. - **Linux (reviewer run):** [MarcZX10 ran a focused Linux check](https://github.com/boykopovar/AnyPS5/pull/9958#issuecomment-6354379800) in an existing configured Release build with GCC 12: `guest_formatting` and `guest_wide_formatting` passed 2/2 with this PR head's formatting and test sources. That reused an older configured tree with the PR's sources overlaid, so it is a focused Linux run, not a clean CI build. - **Linux (exact PR commit):** `8283798a603b845204cb5efe95c85344ce1be56a` in a fresh detached worktree with initialized submodules and a newly configured Ninja Release build (`BUILD_TESTING=ON`, `ANYPS5_RELINKER_CLI=ON`, `ANYPS5_ENABLE_SPIRV_TOOLS=OFF`), GCC 16.2.1 20260810, glibc 2.44. Built `guest_formatting_tests` and `guest_wide_formatting_tests`; `ctest --test-dir <build> -R '^guest_(wide_)?formatting$' -V --no-tests=error --timeout 120` passed **2/2 in each of three runs**, with no skipped tests. This verifies the complete two focused executables at this PR commit; it is not a full product build, a new console differential run, or a test against latest main. No negative control was run in this Linux job. ### 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 (#9699, #9916 and #9927 are merged; #9927 landed from `2def057898f2d0d857bed1579e14b6930adf4cd2`) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a (CPU libc tests) - [x] AI-assisted: yes
MarcZX10 commented 2026-10-23 05:35:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T05:35:40Z.

Review: DISMISSED


The added exact-head Linux evidence resolves my earlier platform-coverage request: the fresh detached build reports both focused formatting executables passing 2/2 in each of three runs, in addition to the Windows title-libc differential and test results. Current hosted conventions, eligibility, intake, labels, relinker matrix, ASan, register-context, and write-watch checks pass; hosted full Linux/Windows product builds are skipped. Local current-main conventions, diff, and 171-script registration checks pass.

I cannot approve this stack as currently based: tools/check_main_sync.py --base upstream/main --head refs/reviews/pr-9958 reports 8 commits ahead /259 behind. This branch depends on #9927, which is itself still awaiting its current-main refresh, and #9927/#9916 affect the formatting implementation underneath this change. Please coordinate the stack refresh after those dependencies are integrated, retain this PR's own final commit and its debt explanation, then rerun the two focused tests and conventions on the refreshed exact head. This request is for the repository's current-main branch rule, not queue volume.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5624333327 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9958#pullrequestreview-5624333327). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T05:35:40Z. **Review:** DISMISSED --- The added exact-head Linux evidence resolves my earlier platform-coverage request: the fresh detached build reports both focused formatting executables passing 2/2 in each of three runs, in addition to the Windows title-libc differential and test results. Current hosted conventions, eligibility, intake, labels, relinker matrix, ASan, register-context, and write-watch checks pass; hosted full Linux/Windows product builds are skipped. Local current-main conventions, diff, and 171-script registration checks pass. I cannot approve this stack as currently based: `tools/check_main_sync.py --base upstream/main --head refs/reviews/pr-9958` reports 8 commits ahead /259 behind. This branch depends on #9927, which is itself still awaiting its current-main refresh, and #9927/#9916 affect the formatting implementation underneath this change. Please coordinate the stack refresh after those dependencies are integrated, retain this PR's own final commit and its debt explanation, then rerun the two focused tests and conventions on the refreshed exact head. This request is for the repository's current-main branch rule, not queue volume.
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!9958
No description provided.