Skip to content

feat(libc): implement feholdexcept - #8863

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
UnhealthyKraken:feat/libc-feholdexcept
Oct 24, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
UnhealthyKraken:feat/libc-feholdexcept

Conversation

@UnhealthyKraken

@UnhealthyKraken UnhealthyKraken commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What

Provide feholdexcept (1kduKXMqx7k, libSceLibcInternal implemented by shared libc). It saves the current thread's 32-byte x87/MXCSR environment, clears pending exceptions and masks traps in both units while retaining other controls. Null output throws before any state changes.

The public SDK declaration and amd64 layout, public 3.20 symbol table and independently matching NID database establish interface evidence. Behavior follows FreeBSD 11 amd64 fenv.c, alongside the existing fegetenv implementation. Console equivalence and module/library versions remain unverified and are recorded in libc debt. No proprietary module or capture is included.

Tested

Windows x86-64, GCC 15.2, Release. No games or GPU execution.

  • Added regression before implementation; baseline 05f9995704ce700749880024243469924ad1db9a fails on the missing export. Exactly the same test binaries, swapping only saved baseline/candidate libc, yield baseline one expected failure plus two passing math suites; candidate three passing suites.
  • Existing guest_floating_point now checks 1,024 combinations of x87/SSE masks, independently set rounding controls, DAZ/FTZ and pending masked flags. Checks the complete saved environment, cleared flags, masked traps, unchanged other controls/tags/instruction state, errno preservation, output sentinels and a trailing no-access page. Also checks null rejection before state changes and concurrent thread isolation. Size32/alignment4/MXCSR offset28 are asserted.
  • Full Windows libs target built; patched NID verified. Final patched_libraries (354 loaded), guest_floating_point, guest_math and guest_math_exact: 4/4 pass, no skips. Library loading verifies linkage, not every library's behavior.
  • Independent read-only review found no actionable ABI, bounds, state or test issue; reviewer did not rerun tests. No PS5 hardware or Linux/macOS execution, so reference behavior is not described as console-measured.
  • Conventions, whitespace and test-registration checks passed. Required pr_overlap completed twice: no confirmed duplicate export or merge collision. It could not compare shared files for 17 already-conflicted PRs; saved and manually inspected those shared-file diffs. None implements feholdexcept. test: organize library tests and label CTest suites #6044 reorganizes tests, and feat(wasm): run relinked titles in the browser with WebGPU #6879 adds WebAssembly handling beside fegetenv; these need integration if they land later. feat(libkernel): enumerate archived app directories #8520 has multiple merge bases, so its saved diff uses Git's selected base. This is not an unconditional clean-overlap claim.
  • Rebased onto the overlap check's main snapshot 4f24b6a64c4d62ce01da251820d159a25d6b23fb. The libc sources/test/debt did not change from the original tested base; subsequent main changes were AGC, VideoOut and SystemService work.

Independent Windows validation by xXPBSXx, Windows10 Pro/Ryzen7 5800X3D/WinLibs GCC15.2 Release: the existing guest_floating_point case passes three runs on this PR, and the identical test fails three runs after replacing only Math.cpp with merge-base4f24b6a64c. Only that test target was built. This is attributed reviewer evidence, not an own rerun or a full-suite/other-platform/console result.

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 (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Progress report (3fcb5e4 → cba2f88)

📈 System libraries: 48.53% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libc feholdexcept_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libc 1310/1319 (99.32%) 1311/1320 (99.32%) +0.00 pp

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 9850 docs/dev/debt/libc.md L21

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 3965 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 5021 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 7201 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/Math.cpp
PR 7544 core/libs/prx/libc/src/Math.cpp
docs/dev/debt/libc.md
PR 7715 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 8150 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 8417 core/libs/prx/libc/src/Math.cpp
docs/dev/debt/libc.md
PR 9133 docs/dev/debt/libc.md
PR 9170 docs/dev/debt/libc.md
PR 9371 docs/dev/debt/libc.md
PR 9447 docs/dev/debt/libc.md
PR 9526 docs/dev/debt/libc.md
PR 9527 docs/dev/debt/libc.md
PR 9552 docs/dev/debt/libc.md
PR 9648 core/libs/prx/libc/src/Math.cpp
docs/dev/debt/libc.md
PR 9669 docs/dev/debt/libc.md
PR 9873 core/libs/prx/libc/src/Math.cpp
docs/dev/debt/libc.md
PR 9929 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 10615 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 10648 docs/dev/debt/libc.md

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the x87/MXCSR save and mask sequence and the test matrix. fnstenv captures the x87 environment before its masking side effect, the explicit fnclex clears x87 pending exceptions, and the saved MXCSR is restored into the output before the new masked/cleared MXCSR is installed. The tests exercise bounds, null handling, errno, flags, controls and thread isolation. The implementation appropriately records that console equivalence is not measured. I found no blocking issue in the diff.

@xXPBSXx

xXPBSXx commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Independent Windows run of this PR (data only).

Environment: Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against main is clean. I built only guest_floating_point_tests; ctest -N -R guest_floating_point lists exactly one test.

Results (3 runs each):

  • PR head: guest_floating_point passes 3/3.
  • Baseline: I kept the PR's test and replaced only core/libs/prx/libc/src/Math.cpp with the version from the PR's merge base (4f24b6a64c), then rebuilt. The test fails 3/3 (exit 0xc0000409). I restored the PR's files afterwards.

Not run: other platforms, the other tests in the same family, the full repository CTest, and any title or console run.

AI-assisted (Claude Code).

@UnhealthyKraken

Copy link
Copy Markdown
Contributor Author

Recorded the independent Windows result and its limits: guest_floating_point passes three runs on the PR and fails three runs with the same test against merge-base Math.cpp. This corroborates the regression separately from my original Windows/full-library validation. It is not a full-suite, other-platform or console result. The review and test report identify no further implementation change.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 23, 2026
@oneandonlydean oneandonlydean self-assigned this Oct 23, 2026
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 24, 2026
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 24, 2026
@oneandonlydean
oneandonlydean merged commit 0ea0f25 into boykopovar:main Oct 24, 2026
17 checks passed
@oneandonlydean

Copy link
Copy Markdown
Collaborator

@UnhealthyKraken the new guest_floating_point check "feholdexcept workers preserve the main environment" failed once on the Linux lane after this merged (run 40125254831, a PR that doesn't touch libc; Subprocess aborted after 0.38 s), and passed in the other recent runs, so it looks intermittent. Could the worker threads observe or change the environment before the main thread's feholdexcept state is settled, or the check run before the workers have finished? A join before the check, or a barrier between the workers' setup and the comparison, would make it deterministic.

@UnhealthyKraken

Copy link
Copy Markdown
Contributor Author

The reported assertion is addressed by the already-merged #11191, which is included in the main snapshot 47f9cee2cd77ac7b7f98782de4836c41205e3bf9 used here. Both worker barriers and both joins were already present; the evidence in #10899 identifies changing x87 pointer/opcode metadata across context switches rather than a missing join. The merged fix compares the relevant control/status state for that assertion.

I built only the focused floating-point target and its dependencies on a hosted Linux AMD EPYC 7763 runner, with matching libraries and parallelism 1. guest_floating_point passed once and then passed --repeat until-fail:300: job/log. The earlier cases in that batch contain separate selector/FreeType failures, so the overall job is red; the floating-point case itself executed successfully. This is current-main stress evidence, not a reproduction of the old failure or console validation.

The remaining full-save comparisons around individual calls are already being addressed in #10937. I have not submitted a competing fix or treated these 300 repetitions as proof that every floating-point intermittency is gone. AI-assisted investigation and validation; no local builds were run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants