feat(libc): implement floating minmax #1770

Closed
MarcZX10 wants to merge 1 commit from upstream-pr/1770 into main
MarcZX10 commented 2026-10-08 18:48:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T18:48:20Z.


What

Add the missing fmin, fmax, fminf, and fmaxf exports with C floating-point NaN-selection semantics. Cover finite ordering, one and two NaN operands, and infinities.

Tested

Linux: built libc and guest_math_tests; ctest --test-dir build -R ^guest_math$ --output-on-failure passed. python3 tools/check_conventions.py --base upstream/main passed. Windows and PS5 hardware not tested.

Checklist

  • Based on current main; no other open PR implements these functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no stub added
  • No notes, investigation files or images added
  • No third-party code added
  • Generic behavior
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4791355439 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1770). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-08T18:48:20Z. --- ### What Add the missing `fmin`, `fmax`, `fminf`, and `fmaxf` exports with C floating-point NaN-selection semantics. Cover finite ordering, one and two NaN operands, and infinities. ### Tested Linux: built `libc` and `guest_math_tests`; `ctest --test-dir build -R ^guest_math$ --output-on-failure` passed. `python3 tools/check_conventions.py --base upstream/main` passed. Windows and PS5 hardware not tested. ### Checklist - [x] Based on current `main`; no other open PR implements these functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no stub added - [x] No notes, investigation files or images added - [x] No third-party code added - [x] Generic behavior - [x] Depends on: none - [x] AI-assisted: yes
oneandonlydean commented 2026-10-08 19:22:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T19:22:30Z.


No title reaches fmin/fmax/fminf/fmaxf on main yet: the homebrew audit lists the import, but those titles stop earlier at other missing imports. Closing for now; reopen when it's a title's next stop on main, with the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6067365002 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1770#issuecomment-6067365002). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-08T19:22:30Z. --- No title reaches `fmin`/`fmax`/`fminf`/`fmaxf` on main yet: the homebrew audit lists the import, but those titles stop earlier at other missing imports. Closing for now; reopen when it's a title's next stop on main, with the log line.
Amoenus commented 2026-10-11 09:43:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-11T09:43:39Z.


Additional fminf startup target, implementation not yet tested (2026-10-11, e22af772)

Controlled Windows loader evidence for this PR's fminf: PPSA99902 Sonic Unleashed Recompiled01.003.000. Original ELF SHA c34f5b0848ef49e96a855076d8254254047e966e4fe56589d0e504fe13828479 preserved. With fixed fresh f609 converter/guest and validated local unlocked-I/O+localeconv prerequisites (experimental fork e22af772), five libc-only controlled launches (121other hashes unchanged) and five complete-runtime launches all stop:

FAIL: unresolved ELF import uVRcM2yFdP4 from libSceLibcInternal.prx

All10 runs 0xC0000139,0.116–0.125 s,no timeout,beforeguestentry. NID database + independent name hash both identify fminf; audit of all122 built libraries finds no provider. Exact baseline123 libraries/guest restored and original hashes verified. #3249/#1578 track prerequisites and prior localeconv stop; this is an experimental integration, not unmodified main or gameplay.

Found existing unmerged implementations #1770 (c5107d50, host std::fmin/std::fmax wrappers) and #2280 (bdf94e0e, explicit bit/NaN/signed-zero numeric helpers). Neither has been built or behavior-tested by us yet. Next validation should compare finite/NaN/signed-zero and FP exception behavior against the declared primary source, then replay before/after. This comment establishes a reproducible missing-import target, not approval of either implementation. No new PR; AI-assisted validation: Codex.

Independent min/max tests and host differences (2026-10-11, maina73)

Follow-up: the original #1770 production patch applies to newer main a73a1af9; its exact added test lines need only context relocation. Windows11/GCC15.2 WinLibs r7/Release guest_math passes5/5, max0.01s; an independent native ABI probe against built libc also passes 18,432/18,432 bit-result/FP-flag/rounding cases, with actual guest errno unchanged. On Ubuntu24.04 WSL/GCC13.3/glibc2.39, the original added assertions pass5/5 in a standalone fixture, but the extended production-source probe diverges from the selected FreeBSD source behavior:

Restricted input set Cases Result-bit differences FP-flag differences
Signed zeros 128 32 0
Numeric + signaling NaN, both orders 2560 2560 2560
Both quiet NaNs, sign/payload selection 128 64 0

Examples: Linux fminf(-0,+0) returns+0; FreeBSD returns-0. Linux fminf(0, bits0x7f812345) returns quiet NaN0x7fc12345 and raises FE_INVALID; the FreeBSD source returns0 without a new exception. Four min/max float/double functions,24 sampled raw input values per precision,all ordered pairs,four rounding modes and two initial exception states give18,432 total cases; total extended divergences2976 result bits/2944 flags. Counts overlap; not2976+2944 distinct failures. Both-NaN bit selection is a source-representation comparison, not a portable-C payload requirement. Default Windows does not reproduce these Linux differences.

Oracle: pinned FreeBSD11.4 d1060029 fminf source, corresponding fmin/fmax/fmaxf and contract. Independent integer bit-order fixtures also pass18,432/18,432 against the unmodified four FreeBSD function bodies compiled on Linux, with name/source-ID/endian/header adapters only. This is source validation, not running FreeBSD OS or measuring PS5.

Existing #2280's explicit NaN/zero logic is a useful alternative: its original production file and complete original fixture (Git blobs verified) pass five native Linux runs; its four min/max functions pass the extended probe5/5. A focused adaptation of those four functions into existing Math/GuestMath files now passes Windows guest_math/native probes5/5 and Linux native production probes5/5; all six deliberately broken variants are caught (NaN selection,zero ordering,infinity classification,new invalid,cleared existing flags,constant result). Linux guest errno/full system runtime not tested; Windows actual guest errno is checked.

These observations explain gaps in #1770's current coverage; they do not demonstrate a PS5/title behavior failure. Full Windows build/runtime suite and controlled title replay are pending. Credit: #1770 original topic, #2280 exact bit-selection helper logic; AI-assisted adaptation/tests/report: Codex. No new PR.

Fork fix, full Windows builds and controlled startup limitation (2026-10-11, a73)

The focused four-export adaptation is now available on our fork: 59c6d5e, based on main a73a1af9. It carries #2280's explicit NaN/zero-selection helper into existing Math/GuestMath files, retains #1770's added assertions and adds source-derived edge cases. No new PR. Credits, AI assistance and console-equivalence limits are recorded in the commit/debt entry.

Windows/WinLibs GCC15.2 r7/Release, bundled dependencies, SPIRV-Tools disabled, RTX5080 explicitly selected, Vulkan/MSAA required, no shader cache: full build and all122 configured system libraries succeed. Full ctest -j4 --timeout30: 823 tests,810 passed,5 skipped,8 failed. Relevant guest_math/native ABI probes passed5/5 as reported above. Failures are windows_exceptions, guest_ampr_markers, depth_fast_clear_submit and flat_apertures0/2/3/4/5. A newer-main integration containing the same math and validated locale code builds all122; its full run is 811 passed,5 skipped,7 failed, with Ampr passing; guest_math/guest_locale/guest_standard_streams/file_streams each pass five repeats. Full suite is not green.

Control: replacing only Math.cpp with exact unmodified a73 source and rebuilding native libc, with the same test executables/other libraries, still fails windows_exceptions (through runtime frames,0xc0000409) and depth_fast_clear_submit (fence timeout/device lost); Ampr passes. Focused serial control also fails windows_exceptions but passes depth/Ampr. This does not isolate a math-caused suite regression; relevant existing reports are #3411,#3371,#3291. No root-cause claim for variable GPU outcomes.

PPSA99902 title validation on the newer whole runtime is inconclusive for math progress: one no-minmax control and five minmax runs all fail at missing qiL4fFObAxM/sceKernelGetCpuTemperature before guest entry. The older diagnostic integration supplied this throwing export; its prerequisites have not yet been carried onto a73. The controls retain locale support and differ only in patched libc; they are not unmodified-main title runs. We will carry the previously verified throwing prerequisites and replay. No gameplay or title execution of fminf has been demonstrated. Original ELF/guest module and saved runtime baseline remain preserved; logs/manifests are retained outside the repo. AI-assisted validation/report: Codex.

Completed controlled title comparison: guest entry reached (2026-10-11, 5cd5ea)

The earlier prerequisite limitation is resolved on fork integration5cd5ea, current-main basea73 + focused math59c6d5e + locale + previously validated throwing temperatures/link/symlink/pathconf/truncate and #1912 pthread-attribute proposal/query-scope correction. No older pending graphics or signal changes carried; no new PR. The focused standalone math commit remains 59c6d5e.

Controlled PPSA99902 comparison: two frozen122-library sets differ only in libc.prx; same other121 libraries, same f609 production-relinker executable (SHA256920f13ce...) and freshly converted guest libc (994a5ab8...), default filtering. Control Math.cpp is exact unmodifieda73 source while retaining the locale overlay and all integration prerequisites.

  • No-minmax control: unresolved uVRcM2yFdP4/fminf from libSceLibcInternal.prx,0xc0000139,0.199s, before guest entry.
  • Minmax profile: 5/5 reaches Transferring control to ELF entry point then [videoout] presentation failed: AGC graphics: unsupported color tile mode,6.215–6.759s; no timeout. Four exits0xc0000409, one0xc0000374; the different termination code is recorded without diagnosing its cause.
  • Two temporary diagnostic replays, changing only the AGC driver and logging already computed fields immediately before its unchanged refusing guard, confirm attrib3=0x0dc68000/mode0x1a/fmask0x18/resourceType1 at6.183/6.274s. This matches existing #2970. Logging source restored byte-for-byte and rebuilt; seven math/kernel/graphics behavioral groups each pass5repeats afterward.

Final integration full build/all122 libraries pass; ctest824 tests: 812 passed,5 skipped,7 failed (windows_exceptions,depth_fast_clear_submit,flat_apertures0/2/3/4/5). Eight relevant groups pass5repeats each. Existing failures remain reported on #3411/#3291; Ampr passes this run. This is a conditional integration result, not startup on unmodified main, proof that each math function executes, or PS5 NaN-payload equivalence. No presented frames/gameplay verified. The earlier filtered-stack progress depended on a subsequently removed guest-libc zero-return fallback; this new comparison uses the guarded production f609 conversion and no such bypass.

Original ELF c34f5b08... and guest module cbcf7024... unchanged; exact123-file runtime baseline and saved guest libc restored/hash-verified after all runs. Experimental and focused branches pushed only to our fork; remote commit/changed Git blobs verified. AI-assisted validation/report: Codex.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107701260 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1770#issuecomment-6107701260). Originally posted by [Amoenus](https://github.com/Amoenus) on 2026-10-11T09:43:39Z. --- ### Additional fminf startup target, implementation not yet tested (2026-10-11, e22af772) Controlled Windows loader evidence for this PR's `fminf`: **PPSA99902 Sonic Unleashed Recompiled01.003.000**. Original ELF SHA c34f5b0848ef49e96a855076d8254254047e966e4fe56589d0e504fe13828479 preserved. With fixed fresh f609 converter/guest and validated local unlocked-I/O+localeconv prerequisites ([experimental fork e22af772](https://github.com/Amoenus/AnyPS5/commit/e22af7723dc132d205c0eb0599da8634449d6251)), five libc-only controlled launches (121other hashes unchanged) and five complete-runtime launches all stop: ```text FAIL: unresolved ELF import uVRcM2yFdP4 from libSceLibcInternal.prx ``` All10 runs `0xC0000139`,0.116–0.125 s,no timeout,beforeguestentry. NID database + independent name hash both identify `fminf`; audit of all122 built libraries finds no provider. Exact baseline123 libraries/guest restored and original hashes verified. #3249/#1578 track prerequisites and prior localeconv stop; this is an experimental integration, not unmodified main or gameplay. Found existing unmerged implementations #1770 (c5107d50, host std::fmin/std::fmax wrappers) and #2280 (bdf94e0e, explicit bit/NaN/signed-zero numeric helpers). **Neither has been built or behavior-tested by us yet.** Next validation should compare finite/NaN/signed-zero and FP exception behavior against the declared primary source, then replay before/after. This comment establishes a reproducible missing-import target, not approval of either implementation. No new PR; AI-assisted validation: Codex. ### Independent min/max tests and host differences (2026-10-11, maina73) Follow-up: the original #1770 production patch applies to newer main `a73a1af9`; its exact added test lines need only context relocation. Windows11/GCC15.2 WinLibs r7/Release **guest_math passes5/5**, max0.01s; an independent native ABI probe against built libc also passes **18,432/18,432** bit-result/FP-flag/rounding cases, with actual guest errno unchanged. On Ubuntu24.04 WSL/GCC13.3/glibc2.39, the original added assertions pass5/5 in a standalone fixture, but the extended production-source probe diverges from the selected FreeBSD source behavior: | Restricted input set | Cases | Result-bit differences | FP-flag differences | |---|---:|---:|---:| | Signed zeros |128|32|0| | Numeric + signaling NaN, both orders |2560|2560|2560| | Both quiet NaNs, sign/payload selection |128|64|0| Examples: Linux `fminf(-0,+0)` returns+0; FreeBSD returns-0. Linux `fminf(0, bits0x7f812345)` returns quiet NaN0x7fc12345 and raises FE_INVALID; the FreeBSD source returns0 without a new exception. Four min/max float/double functions,24 sampled raw input values per precision,all ordered pairs,four rounding modes and two initial exception states give18,432 total cases; total extended divergences2976 result bits/2944 flags. Counts overlap; not2976+2944 distinct failures. Both-NaN bit selection is a source-representation comparison, not a portable-C payload requirement. **Default Windows does not reproduce these Linux differences.** Oracle: pinned FreeBSD11.4 `d1060029` [fminf source](https://github.com/freebsd/freebsd-src/blob/d106002967eff712894ab8b5337bbbff106ce5e0/lib/msun/src/s_fminf.c), corresponding fmin/fmax/fmaxf and [contract](https://github.com/freebsd/freebsd-src/blob/d106002967eff712894ab8b5337bbbff106ce5e0/lib/msun/man/fmax.3). Independent integer bit-order fixtures also pass18,432/18,432 against the **unmodified four FreeBSD function bodies compiled on Linux**, with name/source-ID/endian/header adapters only. This is source validation, not running FreeBSD OS or measuring PS5. Existing #2280's explicit NaN/zero logic is a useful alternative: its original production file and complete original fixture (Git blobs verified) pass five native Linux runs; its four min/max functions pass the extended probe5/5. A focused adaptation of those four functions into existing Math/GuestMath files now passes Windows guest_math/native probes5/5 and Linux native production probes5/5; all six deliberately broken variants are caught (NaN selection,zero ordering,infinity classification,new invalid,cleared existing flags,constant result). Linux guest errno/full system runtime **not** tested; Windows actual guest errno is checked. These observations explain gaps in #1770's current coverage; they do not demonstrate a PS5/title behavior failure. Full Windows build/runtime suite and controlled title replay are pending. Credit: #1770 original topic, #2280 exact bit-selection helper logic; AI-assisted adaptation/tests/report: Codex. No new PR. ### Fork fix, full Windows builds and controlled startup limitation (2026-10-11, a73) The focused four-export adaptation is now available on our fork: [59c6d5e](https://github.com/Amoenus/AnyPS5/commit/59c6d5e1344e73ceddbab12b1e95ce0941025b8c), based on main `a73a1af9`. It carries #2280's explicit NaN/zero-selection helper into existing Math/GuestMath files, retains #1770's added assertions and adds source-derived edge cases. No new PR. Credits, AI assistance and console-equivalence limits are recorded in the commit/debt entry. Windows/WinLibs GCC15.2 r7/Release, bundled dependencies, SPIRV-Tools disabled, RTX5080 explicitly selected, Vulkan/MSAA required, no shader cache: **full build and all122 configured system libraries succeed**. Full ctest `-j4 --timeout30`: **823 tests,810 passed,5 skipped,8 failed**. Relevant guest_math/native ABI probes passed5/5 as reported above. Failures are windows_exceptions, guest_ampr_markers, depth_fast_clear_submit and flat_apertures0/2/3/4/5. A newer-main integration containing the same math and validated locale code builds all122; its full run is **811 passed,5 skipped,7 failed**, with Ampr passing; guest_math/guest_locale/guest_standard_streams/file_streams each pass five repeats. Full suite is not green. Control: replacing only Math.cpp with exact unmodified a73 source and rebuilding native libc, with the same test executables/other libraries, still fails windows_exceptions (`through runtime frames`,0xc0000409) and depth_fast_clear_submit (fence timeout/device lost); Ampr passes. Focused serial control also fails windows_exceptions but passes depth/Ampr. This does not isolate a math-caused suite regression; relevant existing reports are #3411,#3371,#3291. No root-cause claim for variable GPU outcomes. PPSA99902 title validation on the newer whole runtime is **inconclusive for math progress**: one no-minmax control and five minmax runs all fail at missing `qiL4fFObAxM`/sceKernelGetCpuTemperature **before guest entry**. The older diagnostic integration supplied this throwing export; its prerequisites have not yet been carried onto a73. The controls retain locale support and differ only in patched libc; they are not unmodified-main title runs. We will carry the previously verified throwing prerequisites and replay. No gameplay or title execution of fminf has been demonstrated. Original ELF/guest module and saved runtime baseline remain preserved; logs/manifests are retained outside the repo. AI-assisted validation/report: Codex. ### Completed controlled title comparison: guest entry reached (2026-10-11, 5cd5ea) The earlier prerequisite limitation is resolved on [fork integration5cd5ea](https://github.com/Amoenus/AnyPS5/commit/5cd5ea13302db187a7131eda8825c1bd3a48defc), current-main basea73 + focused math59c6d5e + locale + previously validated throwing temperatures/link/symlink/pathconf/truncate and #1912 pthread-attribute proposal/query-scope correction. No older pending graphics or signal changes carried; no new PR. The focused standalone math commit remains [59c6d5e](https://github.com/Amoenus/AnyPS5/commit/59c6d5e1344e73ceddbab12b1e95ce0941025b8c). **Controlled PPSA99902 comparison:** two frozen122-library sets differ **only in libc.prx**; same other121 libraries, same f609 production-relinker executable (SHA256920f13ce...) and freshly converted guest libc (994a5ab8...), default filtering. Control Math.cpp is exact unmodifieda73 source while retaining the locale overlay and all integration prerequisites. - No-minmax control: unresolved `uVRcM2yFdP4`/fminf from libSceLibcInternal.prx,0xc0000139,0.199s, **before guest entry**. - Minmax profile: **5/5 reaches `Transferring control to ELF entry point`** then `[videoout] presentation failed: AGC graphics: unsupported color tile mode`,6.215–6.759s; no timeout. Four exits0xc0000409, one0xc0000374; the different termination code is recorded without diagnosing its cause. - Two temporary diagnostic replays, changing only the AGC driver and logging already computed fields immediately before its **unchanged refusing guard**, confirm attrib3=0x0dc68000/mode0x1a/fmask0x18/resourceType1 at6.183/6.274s. This matches existing #2970. Logging source restored byte-for-byte and rebuilt; seven math/kernel/graphics behavioral groups each pass5repeats afterward. Final integration full build/all122 libraries pass; ctest824 tests: **812 passed,5 skipped,7 failed** (windows_exceptions,depth_fast_clear_submit,flat_apertures0/2/3/4/5). Eight relevant groups pass5repeats each. Existing failures remain reported on #3411/#3291; Ampr passes this run. This is a conditional integration result, **not startup on unmodified main**, proof that each math function executes, or PS5 NaN-payload equivalence. No presented frames/gameplay verified. The earlier filtered-stack progress depended on a subsequently removed guest-libc zero-return fallback; this new comparison uses the guarded production f609 conversion and no such bypass. Original ELF c34f5b08... and guest module cbcf7024... unchanged; exact123-file runtime baseline and saved guest libc restored/hash-verified after all runs. Experimental and focused branches pushed only to our fork; remote commit/changed Git blobs verified. AI-assisted validation/report: Codex.

Pull request closed

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!1770
No description provided.