fix(libc): preserve acoshf domain errno and exception flags #10610

Merged
JJenkx merged 3 commits from upstream-pr/10610 into main 2026-10-26 07:14:12 +00:00
JJenkx commented 2026-10-24 12:39:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-24T12:39:26Z.


What

Follow-up to merged #10003. The existing acoshf domain branch returns the measured NaN bits, but leaves errno unchanged and relies on arithmetic that raises invalid only in SSE. In both supplied bundled copies, that same domain branch sets EDOM and raises invalid in SSE and x87; negative quiet NaNs also raise invalid although NaN arithmetic alone need not do so.

Call the existing _Feraise_nid_postfix(0x01) and set errno = EDOM in that branch, retaining its return expression and all numerical range handling. Positive NaNs/infinity keep their existing separate path. Add a 576-call regression (12 cases × four rounding modes × four DAZ/FTZ combinations × three sticky seeds), including payloads and positive non-domain controls; update the older errno expectation. This introduces no new export or runtime dependency.

The separately observed finite directed-rounding result-bit differences remain recorded in debt. This change does not claim to correct them.

Tested

Current-main refresh: 02d48b3bc394375bb5d10d81c5875599f90cd14b, two linear topic commits directly on main e7e3e9c1984c293f06bff08428b8c89b7b932ac2. Removed obsolete local declarations now supplied by the public API, including _Feraise; the complete acoshf implementation and both regression functions are preserved.

Fresh Linux Release: rebuilt libc and the three math test targets. guest_math, guest_math_exact, guest_dinkumware_internals and public_headers each pass three repeats. A production-only main-Math control fails the new domain check on +0; exact-math/Dinkumware controls pass. Restored candidate passes all four groups three times and restores a byte-identical libc. Conventions and whitespace checks pass. These are current-head regression checks; the earlier reference-copy matrix below retains its original pins. No new Windows/title or performance result is claimed.

Current-head logs, negative/restoration checks, pins and patch, SHA-256 f91e8735d1f1eef09bf2917dec7a301927312611d6ac544d205c94689a4d8e91.

Arch Linux 7.2.9, GCC 16.2.1 Release, Ryzen 9 7950X, x86-64 masked exceptions. Earlier matrix qualification: main b930da950d5d076c19d8e6a025805f3799cadbc5, candidate 2620b766049ef97e96cd8ee45c35c488035e4475.

  • Full relevant libc and guest_math, guest_math_exact, guest_dinkumware_internals targets build; all three test groups pass. Same-test main control 93229fd1192cde4ed804743e642aa4d90aa8770a fails specifically at acoshf domain: on +0: errno stays 1234 and x87 invalid is absent; the other two groups pass.
  • Actual fresh control/candidate libraries and two supplied bundled copies (FAR PPSA03766, Tetris PPSA07923): 270 inputs × 48 environments = 12,960 calls per arm, recording result bits, errno, SSE/x87 flags and controls. Both originals agree. Control differs on errno in 9,312 observations, x87 flags in 6,208 and SSE/combined flags in 64. Candidate has zero differences in all those environment/error fields.
  • Candidate changes no control result bits. 36 pre-existing result-bit differences remain for positive inputs 0x40000002/0x40000003 under directed rounding; they are explicitly excluded from the correction and retained in the artifact/debt. The comparison is sampled, not exhaustive.
  • Raw/converted acoshf bodies are byte-identical for each original (195 bytes each), with different code hashes between the two supplied modules. Both module hashes remain unchanged after the runs. The CPU probe rejects AGC/VideoOut/Vulkan mappings. No game or GPU execution, title/FPS gain, physical PS5, other SDK release, Windows/macOS or unmasked-trap behavior is claimed.
  • Conventions and whitespace pass. An initial standalone probe compile lacked the core/libs include path; the failed and corrected logs are retained. The initial local overlap invocation lacked GitHub authentication; the authenticated scan result is retained separately. It reports 22 conflict-incomplete shared-file comparisons. Manual changed-line/export review finds no competing acoshf implementation; #6044 relocates GuestMath.cpp to core/libs/tests/runtime/GuestMath.cpp, so this regression must be preserved at the moved path if that layout lands first. Adjacent math and additive debt/test insertions remain separate topics.

Reproduction probes, matrices, exact patches, build/test logs and code hashes, SHA256 d3231a3793d42173812c49b2db5c2074c67d90c6ac0016310b4c5c7abc24b5c1. No SDK binaries, code bytes or game assets are included.

Independent exact-head check: MarcZX10 reports a Release CMake build with GCC 12.2 and all three focused groups (guest_math, guest_math_exact, guest_dinkumware_internals) passing 3/3 at 2620b766049ef97e96cd8ee45c35c488035e4475. This is the reporter's focused build/test result; it does not claim a full application build or reproduce the supplied-module matrix.

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 (CPU libc math only)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4995453118 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10610). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-24T12:39:26Z. --- ### What Follow-up to merged #10003. The existing `acoshf` domain branch returns the measured NaN bits, but leaves errno unchanged and relies on arithmetic that raises invalid only in SSE. In both supplied bundled copies, that same domain branch sets EDOM and raises invalid in SSE and x87; negative quiet NaNs also raise invalid although NaN arithmetic alone need not do so. Call the existing `_Feraise_nid_postfix(0x01)` and set `errno = EDOM` in that branch, retaining its return expression and all numerical range handling. Positive NaNs/infinity keep their existing separate path. Add a 576-call regression (12 cases × four rounding modes × four DAZ/FTZ combinations × three sticky seeds), including payloads and positive non-domain controls; update the older errno expectation. This introduces no new export or runtime dependency. The separately observed finite directed-rounding result-bit differences remain recorded in debt. This change does not claim to correct them. ### Tested Current-main refresh: `02d48b3bc394375bb5d10d81c5875599f90cd14b`, two linear topic commits directly on main `e7e3e9c1984c293f06bff08428b8c89b7b932ac2`. Removed obsolete local declarations now supplied by the public API, including `_Feraise`; the complete acoshf implementation and both regression functions are preserved. Fresh Linux Release: rebuilt libc and the three math test targets. `guest_math`, `guest_math_exact`, `guest_dinkumware_internals` and `public_headers` each pass three repeats. A production-only main-Math control fails the new domain check on +0; exact-math/Dinkumware controls pass. Restored candidate passes all four groups three times and restores a byte-identical libc. Conventions and whitespace checks pass. These are current-head regression checks; the earlier reference-copy matrix below retains its original pins. No new Windows/title or performance result is claimed. [Current-head logs, negative/restoration checks, pins and patch](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/pr10610-head02d48b3b-maine7e3-linux-validation.tar.gz), SHA-256 `f91e8735d1f1eef09bf2917dec7a301927312611d6ac544d205c94689a4d8e91`. Arch Linux 7.2.9, GCC 16.2.1 Release, Ryzen 9 7950X, x86-64 masked exceptions. Earlier matrix qualification: main `b930da950d5d076c19d8e6a025805f3799cadbc5`, candidate `2620b766049ef97e96cd8ee45c35c488035e4475`. - Full relevant libc and `guest_math`, `guest_math_exact`, `guest_dinkumware_internals` targets build; all three test groups pass. Same-test main control `93229fd1192cde4ed804743e642aa4d90aa8770a` fails specifically at `acoshf domain:` on +0: errno stays 1234 and x87 invalid is absent; the other two groups pass. - Actual fresh control/candidate libraries and two supplied bundled copies (FAR PPSA03766, Tetris PPSA07923): 270 inputs × 48 environments = **12,960 calls per arm**, recording result bits, errno, SSE/x87 flags and controls. Both originals agree. Control differs on errno in 9,312 observations, x87 flags in 6,208 and SSE/combined flags in 64. Candidate has **zero differences in all those environment/error fields**. - Candidate changes no control result bits. **36 pre-existing result-bit differences** remain for positive inputs `0x40000002`/`0x40000003` under directed rounding; they are explicitly excluded from the correction and retained in the artifact/debt. The comparison is sampled, not exhaustive. - Raw/converted acoshf bodies are byte-identical for each original (195 bytes each), with different code hashes between the two supplied modules. Both module hashes remain unchanged after the runs. The CPU probe rejects AGC/VideoOut/Vulkan mappings. No game or GPU execution, title/FPS gain, physical PS5, other SDK release, Windows/macOS or unmasked-trap behavior is claimed. - Conventions and whitespace pass. An initial standalone probe compile lacked the core/libs include path; the failed and corrected logs are retained. The initial local overlap invocation lacked GitHub authentication; the authenticated scan result is retained separately. It reports 22 conflict-incomplete shared-file comparisons. Manual changed-line/export review finds no competing acoshf implementation; #6044 relocates `GuestMath.cpp` to `core/libs/tests/runtime/GuestMath.cpp`, so this regression must be preserved at the moved path if that layout lands first. Adjacent math and additive debt/test insertions remain separate topics. [Reproduction probes, matrices, exact patches, build/test logs and code hashes](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/libc-acoshf-domain-head2620b766-linux-validation.tar.gz), SHA256 `d3231a3793d42173812c49b2db5c2074c67d90c6ac0016310b4c5c7abc24b5c1`. No SDK binaries, code bytes or game assets are included. <!-- 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. --> Independent exact-head check: [MarcZX10 reports](https://github.com/boykopovar/AnyPS5/pull/10610#issuecomment-6384414198) a Release CMake build with GCC 12.2 and all three focused groups (`guest_math`, `guest_math_exact`, `guest_dinkumware_internals`) passing 3/3 at `2620b766049ef97e96cd8ee45c35c488035e4475`. This is the reporter's focused build/test result; it does not claim a full application build or reproduce the supplied-module matrix. ### 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 (CPU libc math only) - [x] AI-assisted: yes
MarcZX10 commented 2026-10-24 12:45:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T12:45:09Z.

Review: APPROVED


Reviewed exact head 2620b766049ef97e96cd8ee45c35c488035e4475. The change preserves the existing result expression and numerical path while explicitly setting EDOM and raising FE_INVALID only in the invalid-domain branch; the positive NaN/infinity path remains separate. The new regression checks signed zero, below-domain finite values, negative infinity and negative NaNs across all four rounding modes, DAZ/FTZ combinations, and pre-existing sticky flags; positive boundary/NaN/infinity cases guard the unaffected path. The PR reports targeted Linux libc tests and comparisons against both supplied binaries; I did not reproduce those locally. Hosted eligibility, conventions, intake, labels, report, the Ubuntu/Windows/macOS relinker matrix, ASan, register-context and write-watch checks pass. Hosted Linux and Windows product builds are skipped by the eligibility gate. I found no blocking issue in this diff.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638281857 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10610#pullrequestreview-5638281857). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T12:45:09Z. **Review:** APPROVED --- Reviewed exact head `2620b766049ef97e96cd8ee45c35c488035e4475`. The change preserves the existing result expression and numerical path while explicitly setting `EDOM` and raising `FE_INVALID` only in the invalid-domain branch; the positive NaN/infinity path remains separate. The new regression checks signed zero, below-domain finite values, negative infinity and negative NaNs across all four rounding modes, DAZ/FTZ combinations, and pre-existing sticky flags; positive boundary/NaN/infinity cases guard the unaffected path. The PR reports targeted Linux libc tests and comparisons against both supplied binaries; I did not reproduce those locally. Hosted eligibility, conventions, intake, labels, report, the Ubuntu/Windows/macOS relinker matrix, ASan, register-context and write-watch checks pass. Hosted Linux and Windows product builds are skipped by the eligibility gate. I found no blocking issue in this diff.
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!10610
No description provided.