feat(libc): implement C99 numeric helpers #2280

Closed
obojeoboje wants to merge 1 commit from upstream-pr/2280 into main
obojeoboje commented 2026-10-09 14:29:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by obojeoboje on 2026-10-09T14:29:21Z.


What

Add 24 missing C99 numeric exports to libc in a separate translation unit:

  • sqrtf, fabsf, ceilf, truncf, nearbyint.
  • remquo, remquof, copysign, copysignf.
  • nan, nanf, nanl.
  • nextafter, nexttoward, nexttowardf.
  • fdim, fdimf, fmax, fmaxf, fmin, fminf, fmaf.
  • scalbln, scalblnf.

Min/max implement FreeBSD's signed-zero ordering and NaN handling directly, including no new exceptions when selecting the numeric operand against a signaling NaN. Bit classification avoids arithmetic on the NaN operand. nexttoward retains the extended-precision target rather than narrowing it to the result type. Neighbor operations normalize missing MinGW overflow/underflow flags and ERANGE at representation boundaries.

Guest long exponents are 64-bit on Windows too. scalbln bounds the exponent before calling the native int-exponent operation; the bounds exceed the full float/double exponent range. Compile only the new implementation and fixture with -frounding-math.

Contracts and signatures follow FreeBSD math(3), fmax(3), and scalbn(3). All 24 names occur in the shadPS4 aerolib table.

Checked current open PR descriptions, existing exports across libraries, and relevant libc patches in #2193, #2192 and #2167. #2192 implements nextafterf; this branch adds nextafter and nexttoward*. This branch is independent of #2235 and #2271 and excludes their exports. Shared CMake insertion points may need both independent registrations preserved when rebasing.

The progress scanner changes from 2578/3044 (84.69%) to 2602/3068 (84.81%). Both counts grow because these are newly declared exports.

Tested

  • Windows, WinLibs GCC 15.2, Release with testing enabled: full default build and libs target passed.
  • Full CTest run, four workers, 30-second per-test limit: 507 passed, one skipped (guest_video_out_wqhd_detection_no_vulkan), zero failures; 41.04 seconds total.
  • The new runtime fixture exercises every new export: all four rounding modes, 64-bit exponent overflow/underflow with directed rounding, exact subnormals, exception flags, signed zeros, quiet/signaling NaNs for extrema, NaN payload preservation for sign operations, quiet NaN constructors, fused single rounding, remainder quotient bits/ties, neighboring representations and extended target precision.
  • Linux, Ubuntu 24.04 under WSL, GCC 13.3: built the implementation as an optimized shared library and ran the same complete fixture with UndefinedBehaviorSanitizer; passed. This is a focused runtime check, not a full Linux project build or a NID-patched library run.
  • Test registration, conventions and whitespace checks passed. No game tested.
  • Full Linux/Windows Build and the relinker matrix still require a collaborator to dispatch the workflow for this PR head.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4801803622 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2280). Originally posted by [obojeoboje](https://github.com/obojeoboje) on 2026-10-09T14:29:21Z. --- ### What Add 24 missing C99 numeric exports to libc in a separate translation unit: - `sqrtf`, `fabsf`, `ceilf`, `truncf`, `nearbyint`. - `remquo`, `remquof`, `copysign`, `copysignf`. - `nan`, `nanf`, `nanl`. - `nextafter`, `nexttoward`, `nexttowardf`. - `fdim`, `fdimf`, `fmax`, `fmaxf`, `fmin`, `fminf`, `fmaf`. - `scalbln`, `scalblnf`. Min/max implement FreeBSD's signed-zero ordering and NaN handling directly, including no new exceptions when selecting the numeric operand against a signaling NaN. Bit classification avoids arithmetic on the NaN operand. `nexttoward` retains the extended-precision target rather than narrowing it to the result type. Neighbor operations normalize missing MinGW overflow/underflow flags and `ERANGE` at representation boundaries. Guest `long` exponents are 64-bit on Windows too. `scalbln` bounds the exponent before calling the native int-exponent operation; the bounds exceed the full float/double exponent range. Compile only the new implementation and fixture with `-frounding-math`. Contracts and signatures follow FreeBSD [math(3)](https://man.freebsd.org/cgi/man.cgi?query=math&sektion=3&manpath=FreeBSD+15.0-RELEASE), [fmax(3)](https://man.freebsd.org/cgi/man.cgi?query=fmax&sektion=3&manpath=FreeBSD+14.0-RELEASE), and [scalbn(3)](https://man.freebsd.org/cgi/man.cgi?query=scalbn&sektion=3&manpath=FreeBSD+14.0-RELEASE). All 24 names occur in the [shadPS4 aerolib table](https://github.com/shadps4-emu/shadPS4/blob/0fe263a4760dfbfa973366890061749b4af0de97/src/core/aerolib/aerolib.inl). Checked current open PR descriptions, existing exports across libraries, and relevant libc patches in #2193, #2192 and #2167. #2192 implements `nextafterf`; this branch adds `nextafter` and `nexttoward*`. This branch is independent of #2235 and #2271 and excludes their exports. Shared CMake insertion points may need both independent registrations preserved when rebasing. The progress scanner changes from 2578/3044 (84.69%) to 2602/3068 (84.81%). Both counts grow because these are newly declared exports. ### Tested - Windows, WinLibs GCC 15.2, Release with testing enabled: full default build and `libs` target passed. - Full CTest run, four workers, 30-second per-test limit: 507 passed, one skipped (`guest_video_out_wqhd_detection_no_vulkan`), zero failures; 41.04 seconds total. - The new runtime fixture exercises every new export: all four rounding modes, 64-bit exponent overflow/underflow with directed rounding, exact subnormals, exception flags, signed zeros, quiet/signaling NaNs for extrema, NaN payload preservation for sign operations, quiet NaN constructors, fused single rounding, remainder quotient bits/ties, neighboring representations and extended target precision. - Linux, Ubuntu 24.04 under WSL, GCC 13.3: built the implementation as an optimized shared library and ran the same complete fixture with UndefinedBehaviorSanitizer; passed. This is a focused runtime check, not a full Linux project build or a NID-patched library run. - Test registration, conventions and whitespace checks passed. No game tested. - Full Linux/Windows Build and the relinker matrix still require a collaborator to dispatch the workflow for this PR head. ### Checklist - [x] Based on current `main`; no other open PR implements the same 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 (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source: none added - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-09 14:34:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T14:34:53Z.


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
#2170 core/libs/prx/libc/CMakeLists.txt L48
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6083050213 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2280#issuecomment-6083050213). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T14:34:53Z. --- <!-- pr-overlap --> 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 | |---|---|---|---| | #2170 | `core/libs/prx/libc/CMakeLists.txt` [L48](https://github.com/boykopovar/AnyPS5/blob/8b393b6e9a8ade9188d4f74a0293e0efd9828597/core/libs/prx/libc/CMakeLists.txt#L48) | | |
oneandonlydean commented 2026-10-09 20:11:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:11:17Z.


Same as #2271: closing until a title is shown to reach these on main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088461251 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2280#issuecomment-6088461251). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T20:11:17Z. --- Same as #2271: closing until a title is shown to reach these on main.
babyhuey commented 2026-10-11 06:39:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-11T06:39:17Z.


@obojeoboje nanf from this PR is now a title's next stop on main 52ce9b8a. With strsep (#3192) merged, VLC (PPSA85300) reports this on Linux (catalog build, sce_module/libc.prx unwrapped as #2605 requires):

app.elf: symbol lookup error: app.elf: undefined symbol: DZU+K1wozGI

With nanf added to main, VLC goes on to daemon (Wn6I3wVATUE, #2842), which is also where Windows stops first.

Since functions go in when a title reaches them, a resubmission would carry the nan family from here (nan, nanf, nanl) and leave the rest for later; sqrtf is already in through #3233. Intake needs 10 merged PRs to open a new one. If you'd like, I can open it as a carry that keeps your authorship. I'll wait for your yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106321948 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2280#issuecomment-6106321948). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-11T06:39:17Z. --- @obojeoboje `nanf` from this PR is now a title's next stop on `main` 52ce9b8a. With `strsep` (#3192) merged, VLC (PPSA85300) reports this on Linux (catalog build, `sce_module/libc.prx` unwrapped as #2605 requires): `app.elf: symbol lookup error: app.elf: undefined symbol: DZU+K1wozGI` With `nanf` added to `main`, VLC goes on to `daemon` (`Wn6I3wVATUE`, #2842), which is also where Windows stops first. Since functions go in when a title reaches them, a resubmission would carry the `nan` family from here (`nan`, `nanf`, `nanl`) and leave the rest for later; `sqrtf` is already in through #3233. Intake needs 10 merged PRs to open a new one. If you'd like, I can open it as a carry that keeps your authorship. I'll wait for your yes.
Amoenus commented 2026-10-11 09:43:41 +00:00 (Migrated from github.com)

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


Additional fminf validation target (2026-10-11, e22af772)

Controlled PPSA99902 launches with validated unlocked-I/O and localeconv prerequisites now reproduce missing fminf/uVRcM2yFdP4 before guest entry in10/10 runs. Exact procedure, hashes, limits and comparison candidates. This PR bdf94e0e and #1770 c5107d50 are identified alternatives; neither implementation has been tested by us yet. FP signed-zero/NaN/exception validation and another title replay are next. No new PR; AI-assisted investigation: Codex.

Independent original Linux fixture and min/max validation (2026-10-11, bdf94e0e)

I fetched and Git-blob-verified the original NumericHelpers.cpp and full GuestNumericHelpers.cpp at this PR's bdf94e0e head. Native standalone Ubuntu24.04 WSL/GCC13.3/glibc2.39, -O2 -frounding-math: the complete original fixture passes5/5. The original four min/max functions additionally pass18,432 source-checked bit-result/FP-flag/rounding cases on each of5 runs. This is not a full Linux AnyPS5 system-runtime/GPU build; the broader20 exports are covered only by your original fixture, not by the min/max matrix.

The matrix matches separately compiled unmodified FreeBSD11.4 d1060029 function bodies (build adapters disclosed), and demonstrates Linux glibc divergences in #1770's host wrappers for signed zero and signaling NaNs; its default Windows build passes the same matrix. Exact counts, examples, provenance and limits. Your explicit IsNan/Extremum logic has been carried unchanged for the four focused min/max exports into current maina73 Math/GuestMath; relevant Windows and Linux probes pass, six mutants caught. Full build and PPSA99902 replay still pending. Other parts of this24-function PR have not been integrated or tested on Windows by us.

Credit to this original PR. No new PR; AI-assisted tests/adaptation/report: Codex. No PS5 console-equivalence claim.

Original Windows fixture and focused fork validation (2026-10-11, a73)

Additional validation: the complete original bdf94e0e GuestNumericHelpers fixture, linked to its Git-blob-verified original production file, passes five native standalone Windows runs using WinLibs GCC15.2 r7, -O2 -frounding-math -fno-asynchronous-unwind-tables. This extends the earlier Linux standalone fixture result. It is not full integration of this24-export PR, and the extended18,432-case oracle still targets only four min/max exports; it does not establish complete behavior for the other20 functions.

The focused four-function adaptation is on our fork59c6d5e, preserving your helper logic. Full Windows build/all122 libraries pass; full suite823 tests:810 pass/5 skip/8 fail, and math+locale integration811/5/7. Relevant tests/native minmax probes pass repeatedly. Failure controls and the newer-runtime title limitation: both before/after title profiles stop earlier at missing sceKernelGetCpuTemperature, so no minmax startup improvement is claimed yet. No new PR. Credit to this PR; AI-assisted tests/adaptation/report: Codex.

Controlled title milestone after prerequisite restoration (2026-10-11)

Fork experimental integration5cd5ea carries the focused four min/max exports, locale and validated kernel prerequisites onto maina73. The no-minmax libc control stops at missing fminf; replacing only libc in the same122-library profile reaches guest entry 5/5, then the independently retraced0x1a color-target guard tracked by #2970. Full control hashes, exact counts, source/termination limits and final812/824 full-suite result. No full integration of the other20 exports, console equivalence or gameplay claim; no new PR. Your explicit selection logic remains credited in focused59c6d5e. AI-assisted report: Codex.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107701498 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2280#issuecomment-6107701498). Originally posted by [Amoenus](https://github.com/Amoenus) on 2026-10-11T09:43:41Z. --- ### Additional fminf validation target (2026-10-11, e22af772) Controlled PPSA99902 launches with validated unlocked-I/O and localeconv prerequisites now reproduce missing fminf/uVRcM2yFdP4 before guest entry in10/10 runs. [Exact procedure, hashes, limits and comparison candidates](https://github.com/boykopovar/AnyPS5/pull/1770#issuecomment-6107701260). This PR bdf94e0e and #1770 c5107d50 are identified alternatives; neither implementation has been tested by us yet. FP signed-zero/NaN/exception validation and another title replay are next. No new PR; AI-assisted investigation: Codex. ### Independent original Linux fixture and min/max validation (2026-10-11, bdf94e0e) I fetched and Git-blob-verified the original NumericHelpers.cpp and full GuestNumericHelpers.cpp at this PR's bdf94e0e head. Native standalone Ubuntu24.04 WSL/GCC13.3/glibc2.39, -O2 -frounding-math: **the complete original fixture passes5/5**. The original four min/max functions additionally pass18,432 source-checked bit-result/FP-flag/rounding cases on each of5 runs. This is not a full Linux AnyPS5 system-runtime/GPU build; the broader20 exports are covered only by your original fixture, not by the min/max matrix. The matrix matches separately compiled unmodified FreeBSD11.4 d1060029 function bodies (build adapters disclosed), and demonstrates Linux glibc divergences in #1770's host wrappers for signed zero and signaling NaNs; its default Windows build passes the same matrix. [Exact counts, examples, provenance and limits](https://github.com/boykopovar/AnyPS5/pull/1770#issuecomment-6107701260). Your explicit IsNan/Extremum logic has been carried unchanged for the four focused min/max exports into current maina73 Math/GuestMath; relevant Windows and Linux probes pass, six mutants caught. Full build and PPSA99902 replay still pending. Other parts of this24-function PR have not been integrated or tested on Windows by us. Credit to this original PR. No new PR; AI-assisted tests/adaptation/report: Codex. No PS5 console-equivalence claim. ### Original Windows fixture and focused fork validation (2026-10-11, a73) Additional validation: the **complete original bdf94e0e GuestNumericHelpers fixture**, linked to its Git-blob-verified original production file, passes **five native standalone Windows runs** using WinLibs GCC15.2 r7, `-O2 -frounding-math -fno-asynchronous-unwind-tables`. This extends the earlier Linux standalone fixture result. It is not full integration of this24-export PR, and the extended18,432-case oracle still targets only four min/max exports; it does not establish complete behavior for the other20 functions. The focused four-function adaptation is on [our fork59c6d5e](https://github.com/Amoenus/AnyPS5/commit/59c6d5e1344e73ceddbab12b1e95ce0941025b8c), preserving your helper logic. Full Windows build/all122 libraries pass; full suite823 tests:810 pass/5 skip/8 fail, and math+locale integration811/5/7. Relevant tests/native minmax probes pass repeatedly. [Failure controls and the newer-runtime title limitation](https://github.com/boykopovar/AnyPS5/pull/1770#issuecomment-6107701260): both before/after title profiles stop earlier at missing sceKernelGetCpuTemperature, so no minmax startup improvement is claimed yet. No new PR. Credit to this PR; AI-assisted tests/adaptation/report: Codex. ### Controlled title milestone after prerequisite restoration (2026-10-11) [Fork experimental integration5cd5ea](https://github.com/Amoenus/AnyPS5/commit/5cd5ea13302db187a7131eda8825c1bd3a48defc) carries the focused four min/max exports, locale and validated kernel prerequisites onto maina73. The no-minmax libc control stops at missing fminf; replacing only libc in the same122-library profile reaches guest entry **5/5**, then the independently retraced0x1a color-target guard tracked by #2970. [Full control hashes, exact counts, source/termination limits and final812/824 full-suite result](https://github.com/boykopovar/AnyPS5/pull/1770#issuecomment-6107701260). No full integration of the other20 exports, console equivalence or gameplay claim; no new PR. Your explicit selection logic remains credited in [focused59c6d5e](https://github.com/Amoenus/AnyPS5/commit/59c6d5e1344e73ceddbab12b1e95ce0941025b8c). AI-assisted 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!2280
No description provided.