feat(libc): implement floating minmax #1770
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1770"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T18:48:20Z.
What
Add the missing
fmin,fmax,fminf, andfmaxfexports with C floating-point NaN-selection semantics. Cover finite ordering, one and two NaN operands, and infinities.Tested
Linux: built
libcandguest_math_tests;ctest --test-dir build -R ^guest_math$ --output-on-failurepassed.python3 tools/check_conventions.py --base upstream/mainpassed. Windows and PS5 hardware not tested.Checklist
main; no other open PR implements these functionsImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T19:22:30Z.
No title reaches
fmin/fmax/fminf/fmaxfon 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.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:All10 runs
0xC0000139,0.116–0.125 s,no timeout,beforeguestentry. NID database + independent name hash both identifyfminf; 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:Examples: Linux
fminf(-0,+0)returns+0; FreeBSD returns-0. Linuxfminf(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
d1060029fminf 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.
uVRcM2yFdP4/fminf from libSceLibcInternal.prx,0xc0000139,0.199s, before guest entry.Transferring control to ELF entry pointthen[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.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