fix(libc): parse scaled NaN subjects without numeric conversion #12659

Merged
JJenkx merged 3 commits from upstream-pr/12659 into main 2026-10-30 12:45:38 +00:00
JJenkx commented 2026-10-29 00:46:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-29T00:46:49Z.


What

The six scaled floating conversion helpers now recognize NaN subjects before numeric conversion. _Stodx("-nan", ...) previously returned a negative NaN and raised FE_INVALID; a malformed payload such as nan(1.0) could also consume past nan. Both bundled SDK references instead return the default positive quiet NaN, preserve floating flags, and consume a parenthesized payload only when all its characters are alphanumeric or underscore and it closes.

This shares the existing FindNanSubject/NanSequenceEnd lexer through a host-only helper. The shared scaled parser uses its stop pointer and a typed quiet-NaN constant. Tests cover all six helpers, extreme 64-bit scales, rounding, sticky flags and null outputs.

Tested

Head f7b17598798ddae9f2b83c6a860ac6a332538f39, based on main 3a2b91981651569163768854a1fcdc7193b6667b.

  • Linux 7.2.9 / Arch, Ryzen 7950X, GCC 16.2.1, Release: guest_dinkumware_internals, guest_wide_conversion, guest_strtod_subnormal, guest_strings, each three times: 12 passes.
  • Actual Windows 11 Enterprise 22621, Ryzen 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, Vulkan hidden: the same four groups three times: 12 passes. Independent source/build; the prior validation checkout is unchanged.
  • Both owned bundled libc.prx references, PPSA03766 and PPSA07923, agree on all 1,050 rows, covering all six helpers, 25 token spellings and seven scales including INT64_MIN/MAX. The candidate matches every field: value bits, stop, errno, error output and floating flags. Main differs on 280/525 primary-helper rows.
  • Negative control: the new regression executable explicitly loads main's libc (verified with LD_DEBUG) and fails scaled NaN value bits. Its two AGC-only Bendy prerequisites do not alter libc.
  • Conventions pass. The overlap scan found no comparable conflicting hunks. Manually scoped stale shared-code PRs concern ARM64 (#5021), threads (#9447), _LLog (#11270), wcstod (#11892), or timingsafe_bcmp (#12586), rather than this token correction; remaining uncomparable entries share debt text.

Raw oracle rows, comparer, probes, patch, both-host logs and JUnit, SHA256 eef37c20aa6fac972d25bf48a024c72baf52c5a6104c986d7b0fc5a71e1981ef (download verified). No SDK/game binaries or disassembly are distributed. The references ran in Linux host processes, not on a console. Non-C locales, other SDK variants and unmasked exceptions remain unverified. Nonzero hexadecimal scaling remains documented and unimplemented. No title-unblock or speed claim.

Current qualification — 2026-10-30

Integrated upstream main 08a10d225306ad102b57408e2ef7566bcfb829b2 at 58fddd82c67ac084cb2d8ca6a3aff862910e7daf, retaining the actual previous head and main as parents. Manual conflict resolution changes only debt documentation; production and test files equal the automatic merge output. Both parents' added test lines and main gitlinks are preserved.

Linux CPU: 6 passes (guest_dinkumware_internals, guest_crt); public_headers 3 passes; no skips. MinGW source syntax and conventions pass.

Dependency #11270 has merged; its history and current-main LLog implementation remain, and the active Depends row may be cleared.

No new Windows/macOS runtime, native SDK, game, GPU or performance claim. The Windows user pause remains in force.

Evidence: immutable source and qualification receipts, SHA-256 61f5500e7526ea4e107159927de78c37db7e0ac1cb7ebd8625b22ab0ad5d9bd7 (download verified).

Independent Windows evidence from bunbeans2-arch: Windows 11 Pro, MSYS2 UCRT64 GCC 16.1.0, Release; head 58fddd82c67ac084cb2d8ca6a3aff862910e7daf integrated with main 98ddd9c179. guest_dinkumware_internals: change passed 5/5; reverting only production changes while retaining the regression tests failed 5/5 at scaled NaN value bits; plain main passed 3/3. This is the reporter's execution, not a new local Windows run.

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 (#11270 has merged; its fulfilled debt-entry ordering and earlier measurements retain their history)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5060097246 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12659). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-29T00:46:49Z. --- ### What The six scaled floating conversion helpers now recognize NaN subjects before numeric conversion. `_Stodx("-nan", ...)` previously returned a negative NaN and raised `FE_INVALID`; a malformed payload such as `nan(1.0)` could also consume past `nan`. Both bundled SDK references instead return the default positive quiet NaN, preserve floating flags, and consume a parenthesized payload only when all its characters are alphanumeric or underscore and it closes. This shares the existing `FindNanSubject`/`NanSequenceEnd` lexer through a host-only helper. The shared scaled parser uses its stop pointer and a typed quiet-NaN constant. Tests cover all six helpers, extreme 64-bit scales, rounding, sticky flags and null outputs. ### Tested Head `f7b17598798ddae9f2b83c6a860ac6a332538f39`, based on main `3a2b91981651569163768854a1fcdc7193b6667b`. - Linux 7.2.9 / Arch, Ryzen 7950X, GCC 16.2.1, Release: `guest_dinkumware_internals`, `guest_wide_conversion`, `guest_strtod_subnormal`, `guest_strings`, each three times: **12 passes**. - Actual Windows 11 Enterprise 22621, Ryzen 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, Vulkan hidden: the same four groups three times: **12 passes**. Independent source/build; the prior validation checkout is unchanged. - Both owned bundled `libc.prx` references, PPSA03766 and PPSA07923, agree on all **1,050 rows**, covering all six helpers, 25 token spellings and seven scales including `INT64_MIN/MAX`. The candidate matches every field: value bits, stop, errno, error output and floating flags. Main differs on **280/525** primary-helper rows. - Negative control: the new regression executable explicitly loads main's libc (verified with `LD_DEBUG`) and fails `scaled NaN value bits`. Its two AGC-only Bendy prerequisites do not alter libc. - Conventions pass. The overlap scan found no comparable conflicting hunks. Manually scoped stale shared-code PRs concern ARM64 (#5021), threads (#9447), `_LLog` (#11270), `wcstod` (#11892), or `timingsafe_bcmp` (#12586), rather than this token correction; remaining uncomparable entries share debt text. [Raw oracle rows, comparer, probes, patch, both-host logs and JUnit](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/libc-scaled-nan-linux-windows-20261028.tar.gz), SHA256 `eef37c20aa6fac972d25bf48a024c72baf52c5a6104c986d7b0fc5a71e1981ef` (download verified). No SDK/game binaries or disassembly are distributed. The references ran in Linux host processes, not on a console. Non-C locales, other SDK variants and unmasked exceptions remain unverified. Nonzero hexadecimal scaling remains documented and unimplemented. No title-unblock or speed claim. <!-- 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. --> <!-- codex-maintenance-20261030-repeat-12659 --> **Current qualification — 2026-10-30** Integrated upstream main `08a10d225306ad102b57408e2ef7566bcfb829b2` at `58fddd82c67ac084cb2d8ca6a3aff862910e7daf`, retaining the actual previous head and main as parents. Manual conflict resolution changes only debt documentation; production and test files equal the automatic merge output. Both parents' added test lines and main gitlinks are preserved. Linux CPU: 6 passes (guest_dinkumware_internals, guest_crt); public_headers 3 passes; no skips. MinGW source syntax and conventions pass. Dependency #11270 has merged; its history and current-main LLog implementation remain, and the active Depends row may be cleared. No new Windows/macOS runtime, native SDK, game, GPU or performance claim. The Windows user pause remains in force. Evidence: [immutable source and qualification receipts](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/cpu-seven-current-main-linux-20261030.tar.gz), SHA-256 `61f5500e7526ea4e107159927de78c37db7e0ac1cb7ebd8625b22ab0ad5d9bd7` (download verified). Independent Windows evidence from [bunbeans2-arch](https://github.com/boykopovar/AnyPS5/pull/12659#issuecomment-6519499338): Windows 11 Pro, MSYS2 UCRT64 GCC 16.1.0, Release; head `58fddd82c67ac084cb2d8ca6a3aff862910e7daf` integrated with main `98ddd9c179`. `guest_dinkumware_internals`: change passed 5/5; reverting only production changes while retaining the regression tests failed 5/5 at `scaled NaN value bits`; plain main passed 3/3. This is the reporter's execution, not a new local Windows run. ### 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 (#11270 has merged; its fulfilled debt-entry ordering and earlier measurements retain their history) - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
rooklz commented 2026-10-29 01:26:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T01:26:29Z.

Review: COMMENTED


I checked this on macOS 26 (x86_64 under Rosetta, Apple clang, ASan+UBSan) at head f7b1759879. I built DinkumwareInternals.cpp and Strings.cpp by themselves with a small shim (__error → host errno, an aborting NotImplemented_nid_no_patch, host sin/cos/log*/tolower). I ran TestFloatErrors and the new TestScaledNan. The full main() stops early at _Exp subnormal result classification, which comes from the shim's host math and doesn't involve this PR.

  • Head: green, with no sanitizer reports (0.2 s).
  • Main's DinkumwareInternals.cpp with the new test: RED at scaled NaN value bits, as the body says.
  • Merges cleanly into 3a2b919816; check_conventions --base upstream/main passes.

Mutants. Killed: dropping the *end store, returning a negative quiet NaN, returning a signalling NaN, returning parse(text, nullptr), moving *error = 0 below the NaN return (caught by the existing _Stodx in range), NanSubjectEnd returning the bare tail, dropping _ from the payload set, accepting an unclosed payload, accepting any character up to ), dropping digit 0, and only accepting hex letters in the payload. Equivalent: restoring errno = saved before the NaN return (it was never changed).

Surviving, all in the shared FindNanSubject/NanSequenceEnd lexer that the scaled helpers now depend on:

  1. leading whitespace limited to ' ' (no \t…\r),
  2. + sign not accepted,
  3. payload letters limited to lowercase ((*cursor | 0x20) dropped).

No row in the case table has a non-space leading character, a + sign, or an uppercase payload letter. One extra row kills all three, and head stays green with it:

-    const Case cases[] = {{"nan", 3}, {"  -NaNtail", 6}, {"-nan(0x123)", 11}, {"nan(a_b9)", 9}, {"nan()", 5}, {"nan(abc", 3}, {"nan(1.0)", 3}, {"nan(a b)", 3}, {"nan((a))", 3}};
+    const Case cases[] = {{"nan", 3}, {"  -NaNtail", 6}, {"-nan(0x123)", 11}, {"nan(a_b9)", 9}, {"nan()", 5}, {"nan(abc", 3}, {"nan(1.0)", 3}, {"nan(a b)", 3}, {"nan((a))", 3}, {"\t+NAN(Az_0)", 11}};

I got the expected stop for that row from the lexer's own rule, which strtod already uses. Could you confirm "\t+NAN(Az_0)" → stop 11 against your two libc.prx references before adding it?

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5691777753 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12659#pullrequestreview-5691777753). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-29T01:26:29Z. **Review:** COMMENTED --- I checked this on macOS 26 (x86_64 under Rosetta, Apple clang, ASan+UBSan) at head `f7b1759879`. I built `DinkumwareInternals.cpp` and `Strings.cpp` by themselves with a small shim (`__error` → host `errno`, an aborting `NotImplemented_nid_no_patch`, host `sin`/`cos`/`log*`/`tolower`). I ran `TestFloatErrors` and the new `TestScaledNan`. The full `main()` stops early at `_Exp subnormal result classification`, which comes from the shim's host math and doesn't involve this PR. - Head: green, with no sanitizer reports (0.2 s). - Main's `DinkumwareInternals.cpp` with the new test: RED at `scaled NaN value bits`, as the body says. - Merges cleanly into `3a2b919816`; `check_conventions --base upstream/main` passes. Mutants. **Killed:** dropping the `*end` store, returning a negative quiet NaN, returning a signalling NaN, returning `parse(text, nullptr)`, moving `*error = 0` below the NaN return (caught by the existing `_Stodx in range`), `NanSubjectEnd` returning the bare tail, dropping `_` from the payload set, accepting an unclosed payload, accepting any character up to `)`, dropping digit `0`, and only accepting hex letters in the payload. **Equivalent:** restoring `errno = saved` before the NaN return (it was never changed). **Surviving**, all in the shared `FindNanSubject`/`NanSequenceEnd` lexer that the scaled helpers now depend on: 1. leading whitespace limited to `' '` (no `\t`…`\r`), 2. `+` sign not accepted, 3. payload letters limited to lowercase (`(*cursor | 0x20)` dropped). No row in the case table has a non-space leading character, a `+` sign, or an uppercase payload letter. One extra row kills all three, and head stays green with it: ```diff - const Case cases[] = {{"nan", 3}, {" -NaNtail", 6}, {"-nan(0x123)", 11}, {"nan(a_b9)", 9}, {"nan()", 5}, {"nan(abc", 3}, {"nan(1.0)", 3}, {"nan(a b)", 3}, {"nan((a))", 3}}; + const Case cases[] = {{"nan", 3}, {" -NaNtail", 6}, {"-nan(0x123)", 11}, {"nan(a_b9)", 9}, {"nan()", 5}, {"nan(abc", 3}, {"nan(1.0)", 3}, {"nan(a b)", 3}, {"nan((a))", 3}, {"\t+NAN(Az_0)", 11}}; ``` I got the expected stop for that row from the lexer's own rule, which `strtod` already uses. Could you confirm `"\t+NAN(Az_0)"` → stop 11 against your two `libc.prx` references before adding it? AI-assisted: yes
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!12659
No description provided.