Skip to content

fix(libc): return Dinkumware codes from __fpclassifyf - #11277

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
AlexFigas:fix/libc-fpclassifyf-dinkumware-codes
Oct 27, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
AlexFigas:fix/libc-fpclassifyf-dinkumware-codes

Conversation

@AlexFigas

Copy link
Copy Markdown
Contributor

What

__fpclassifyf returned FreeBSD's <math.h> codes: FP_INFINITE 0x01, FP_NAN 0x02, FP_NORMAL 0x04, FP_SUBNORMAL 0x08 and FP_ZERO 0x10. #1987 took them from FreeBSD's fpclassify.c. The console's own __fpclassifyf returns the Dinkumware codes instead: 0 zero, −2 subnormal, −1 normal, 1 infinite and 2 NaN. Those are the codes that AnyPS5's __fpclassifyd, __fpclassifyl and _FDtest already return.

So a title's fpclassify on a float gave the wrong answer for every finite value, while the same call on a double was right. Only infinities and NaNs agreed, because FreeBSD and Dinkumware happen to share 1 and 2 there.

The evidence is the libc.prx bundled with PPSA21564, which exports __fpclassifyf (z7aCCd9hMsI) at 0x54790. That code is the library's own:

vmovd ecx, xmm0
eax = ecx >> 23; if al == 0xff: return (ecx & 0x7fffff) != 0 ? 2 : 1
if al != 0: return -1
return (ecx & 0x7fffff) == 0 ? 0 : -2

This is _FDtest for every input, so __fpclassifyf now forwards to it.

Tested

On Ubuntu 24.04 under WSL2 (GCC 13.3, Release):

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

@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 exact head 40619ba1cc683093d75fd6450e052a258673522c. The one-line forwarding change makes __fpclassifyf return the same Dinkumware codes as the existing _FDtest helper, and the updated guest test checks that mapping. The PR reports an exhaustive comparison against the bundled libc.prx across all 2^32 float encodings; I did not independently rerun that harness. No blocking code finding. Policy and conventions checks pass; full product builds were skipped under the PR path policy, and my documented manual dispatch attempt was rejected by GitHub because this account lacks repository admin rights.

@github-actions

github-actions Bot commented Oct 25, 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 6085 core/libs/prx/libc/src/Math.cpp
PR 6295 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 8417 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 9867 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 9873 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 10113 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 10222 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 10226 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 10229 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 10245 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 10247 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 10250 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 10253 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 10265 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 10274 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 10283 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 10328 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 10345 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 10349 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 10510 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 10529 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 11109 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp

@wachi35676

Copy link
Copy Markdown
Contributor

Windows run of head 40619ba1c merged onto main 0f34ebb85, WinLibs GCC 15.2.0, Release. The description's runs are under WSL.

AI-assisted: yes (Claude Code); results above were run on this machine.

@babyhuey

Copy link
Copy Markdown
Contributor

Windows run of this head 40619ba1cc6, merged onto main 0a570f617d8 (clean merge, local only), with the selection CI's skipped Windows product job uses: Windows 11, Ryzen 7 5800X, RTX 3080, WinLibs GCC 15.2, Release, BUILD_TESTING=ON. The tree was configured fresh after the merge, then select_tests.py select / ninja -f select.ninja selected / --target libs / select_tests.py ctest --parallel 4 --timeout 120.

  • Selected 2547 tests: 1838 pass, 1 fails, guest_raise_exception, which also fails on 0a570f617d8 itself on this machine (crash or timeout under --parallel 4; it passed on 27ad7244d22, and I'm narrowing that down separately), 708 skip. No failures from this PR.

AI-assisted: yes (Claude Code)

@oneandonlydean
oneandonlydean merged commit fd4a4ca into boykopovar:main Oct 27, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants