fix(libc): return fetestexcept's unmasked status bits as measured on a PS5 #10175

Merged
orezraey merged 2 commits from upstream-pr/10175 into main 2026-10-26 19:57:54 +00:00
orezraey commented 2026-10-23 12:02:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-23T12:02:29Z.


What

fetestexcept measured on a retail PS5 (firmware 13.60) with a homebrew probe calling libSceLibcInternal.sprx from a payload process. The source and console log are in this gist (fenv). Split from #10129.

fetestexcept. The console returns the x87 status word and MXCSR ORed and masked only by its argument: fetestexcept(0xffff) gave 0x9fc1. Before, the result was also masked to 0x3f. Everything else measured already matched: the rounding constants (0, 0x400, 0x800, 0xc00), fesetround returning -1 and changing nothing for 1, 0x401, 0x1000 and -1, fegetround reading the x87 bits, the exception values and the 2-byte fexcept_t. The debt entry now says they are measured.

Tested

Windows 11, MinGW (winlibs).

  • guest_floating_point checks fetestexcept(0xffff). It fails on main and passes three runs in a row with the change.
  • tools/check_conventions.py passes.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4982416039 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10175). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-23T12:02:29Z. --- ### What `fetestexcept` measured on a retail PS5 (firmware 13.60) with a homebrew probe calling `libSceLibcInternal.sprx` from a payload process. The source and console log are in [this gist](https://gist.github.com/orezraey/d3a3271c811a0d5cb6294cf73dd67564) (`fenv`). Split from #10129. **`fetestexcept`.** The console returns the x87 status word and MXCSR ORed and masked only by its argument: `fetestexcept(0xffff)` gave `0x9fc1`. Before, the result was also masked to 0x3f. Everything else measured already matched: the rounding constants (0, 0x400, 0x800, 0xc00), `fesetround` returning -1 and changing nothing for 1, 0x401, 0x1000 and -1, `fegetround` reading the x87 bits, the exception values and the 2-byte `fexcept_t`. The debt entry now says they are measured. ### 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 (winlibs). - `guest_floating_point` checks `fetestexcept(0xffff)`. It fails on `main` and passes three runs in a row with the change. - `tools/check_conventions.py` passes. ### 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
MarcZX10 commented 2026-10-23 12:16:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T12:16:42Z.

Review: APPROVED


Reviewed exact head 815a9e0289a8f4af11e6dc669dcdd0e8876427ad. The implementation removes only the additional 0x3f clamp after combining x87 status and MXCSR and applying the caller mask; the regression checks the full requested mask against the captured machine state while existing tests continue to cover the six exception flags. The reported PS5 probe result is 0x9fc1 for mask 0xffff. All policy checks and relinker jobs on Ubuntu, Windows and both macOS architectures pass, as do ASAN and the register-context/write-watch jobs; Linux/Windows product jobs were skipped by path policy. The author reports the focused Windows test fails on main and passes three runs with the patch; I could not independently run the C++ suite because no build tree is configured here.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5628078787 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10175#pullrequestreview-5628078787). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T12:16:42Z. **Review:** APPROVED --- Reviewed exact head `815a9e0289a8f4af11e6dc669dcdd0e8876427ad`. The implementation removes only the additional `0x3f` clamp after combining x87 status and MXCSR and applying the caller mask; the regression checks the full requested mask against the captured machine state while existing tests continue to cover the six exception flags. The reported PS5 probe result is `0x9fc1` for mask `0xffff`. All policy checks and relinker jobs on Ubuntu, Windows and both macOS architectures pass, as do ASAN and the register-context/write-watch jobs; Linux/Windows product jobs were skipped by path policy. The author reports the focused Windows test fails on main and passes three runs with the patch; I could not independently run the C++ suite because no build tree is configured here.
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!10175
No description provided.