Skip to content

feat(libc): implement C99 numeric helpers - #2280

Closed
obojeoboje wants to merge 1 commit into
boykopovar:mainfrom
obojeoboje:feat/libc-numeric-helpers
Closed

obojeoboje wants to merge 1 commit into
boykopovar:mainfrom
obojeoboje:feat/libc-numeric-helpers

Conversation

@obojeoboje

Copy link
Copy Markdown

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

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

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

@oneandonlydean

Copy link
Copy Markdown
Collaborator

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

ycbuzi pushed a commit to ycbuzi/AnyPS5 that referenced this pull request Oct 10, 2026
Harvested from upstream (closed unmerged); library completion 2886/3260 -> 2904/3278. Additive conflicts resolved by keeping both sides: core/libs/prx/libc/CMakeLists.txt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011krDVCnnMQPaEFEqCDnKmA
@babyhuey

Copy link
Copy Markdown
Contributor

@obojeoboje nanf from this PR is now a title's next stop on main 52ce9b8. 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

Amoenus commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

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

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 bdf94e0 and #1770 c5107d5 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, bdf94e0)

I fetched and Git-blob-verified the original NumericHelpers.cpp and full GuestNumericHelpers.cpp at this PR's bdf94e0 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 bdf94e0 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.

danielradosa added a commit to danielradosa/AnyPS5 that referenced this pull request Oct 13, 2026
Conflicts: GuestMath.cpp kept both new checks; ceilf/truncf now only in Math.cpp as on main (our NumericHelpers.cpp copies came from boykopovar#2280, which main never 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.

4 participants