Skip to content

feat(libc): implement floating-point rounding and exception flags - #6985

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
Lorkydey:feat/libc-floating-point-controls
Oct 19, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
Lorkydey:feat/libc-floating-point-controls

Conversation

@Lorkydey

Copy link
Copy Markdown
Contributor

What

Adds six missing libSceLibcInternal exports to libc: fegetround, fesetround, fetestexcept, feclearexcept, fegetexceptflag and fesetexceptflag.

Rounding changes apply to both x87 and SSE. Exception queries combine both units, and masked flag updates preserve unrelated flags and control bits. The implementation follows the FreeBSD 11.4 amd64 contract used by the existing fegetenv, including the denormal flag and the 16-bit fexcept_t; the unverified console ABI and null-pointer behavior are recorded in libc's technical debt.

A dedicated test checks actual x87/SSE conversions in all four rounding modes, invalid-mode rejection without state changes, flag save/restore/clear, two-byte writes with canaries, preservation of exception masks and isolation between threads. No title-unblocking or performance claim.

Tested

Windows x86-64, WinLibs MinGW-w64 GCC 15.2, Ninja, Release, BUILD_TESTING=ON, rebased onto e1ac3300d (baseline check on fd9e577d; focused tests rerun after rebase).

  • Built the actual libc on main first. Adding only the new test fails to link with all six missing exports (undefined reference); adding the implementation makes the same test link and pass.
  • cmake --build build --target guest_floating_point_tests guest_math_tests --parallel 2: passed.
  • ctest --test-dir build -R '^guest_(floating_point|math)$' --output-on-failure: 2/2 passed; the new test takes about 0.04 s.
  • Built nid_patcher, patched the resulting libc.prx, and verified all six NIDs in its export table.
  • python tools/check_conventions.py --base origin/main and git diff --check: passed.
  • tools/progress.py: libraries 3318/3712 (89.39%) on main, 3324/3718 (89.40%) with this change.

Linux execution, a full-project build and title runs have not been performed locally. Automatic PR checks do not replace the project's manually dispatched full Linux/Windows builds.

Overlap review: ran tools/pr_overlap.py --branch feat/libc-floating-point-controls and rechecked the final documentation placement against all 36 PRs changing that file. No duplicate exports, new files or confirmed line conflicts remain. The stale branches #5021, #5303, #5668, #6044, #6222 and #6565 share build/debt files and cannot be fully compared automatically; their available diffs were reviewed manually. They do not implement these exports. #6044 reorganizes existing tests, so this new test may need the same organization when that work lands. None is a prerequisite for this implementation.

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
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Codex)

@github-actions

Copy link
Copy Markdown

Progress report (e1ac330 → 4e7e8ac)

📈 System libraries: 89.4% (+0.01%, +6 implemented functions)

✅ 6 implemented
Library Name
libc feclearexcept_nid_postfix
libc fegetexceptflag_nid_postfix
libc fegetround_nid_postfix
libc fesetexceptflag_nid_postfix
libc fesetround_nid_postfix
libc fetestexcept_nid_postfix

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

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 5021 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 6044 core/libs/prx/libc/CMakeLists.txt
PR 6079 core/libs/prx/libc/CMakeLists.txt
PR 6226 docs/dev/debt/libc.md
PR 6469 docs/dev/debt/libc.md
PR 7081 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 7201 core/libs/prx/libc/CMakeLists.txt
PR 7332 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 7417 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 7473 docs/dev/debt/libc.md
PR 7525 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 7715 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md

@jotitadev jotitadev 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.

Linux run, since the description notes Linux execution has not been performed.

Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON, full build.
Head 4e7e8ac1a merged onto main 40315fcf8 (clean merge; the branch is based on e1ac3300d).

  • guest_floating_point and guest_math pass with the PR.
  • Non-GPU suite (ctest -E "^agc|gpu|vulkan|video_out"): 683/683, the 682 tests of main plus guest_floating_point.

I did not repeat the test-only check on main: the test needs the new exports to link, which the description already covers.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

@adriadam10 adriadam10 self-assigned this Oct 19, 2026
@adriadam10
adriadam10 merged commit 0fbfd91 into boykopovar:main Oct 19, 2026
15 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked against FreeBSD x86/fenv.h and amd64/fenv.c (rounding bits, FE_ALL_EXCEPT with denormals, 16-bit fexcept_t, fesetround rejection, x87+MXCSR handling), the new test (it needs the exports to link, covers all four modes on x87 and SSE, state preservation, threads) and the TechnicalDebt entry; Linux run by @jotitadev; merged.

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.

3 participants