fix(libc): compute remainder and remquo with fprem1, as titles' libc.prx does #10349
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10349"
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 JJenkx on 2026-10-23T18:47:45Z.
What
remainder,remainderf,remquoandremquofreturned the host's functions. Thelibc.prxthat titles ship does not use msun's C versions for these. It uses FreeBSD's amd64 assembly,e_remainder.S,e_remainderf.S,s_remquo.Sands_remquof.S: an x87fprem1loop. That differs from the host's results in three places:remquo's quotient: the assembly stores the sign and the three low bits of the quotient, from C0, C3 and C1. For example,remquo(1e300, 1e-300)gives a quotient of 2 there and 8,054,146 on Windows (UCRT). Both are allowed by C, but titles see 2.0xfff8000000000000. For example,remquo(1, 0)andremquof(1, 0)are negative NaNs there and positive ones on Windows.errno: Sony's wrapper setsEDOMfor a zero divisor or an infinite dividend when neither argument is a NaN, and leaves it alone otherwise.Against 4,000,196 sampled pairs,
maindiffers from the titles' copies on 1,548remainderpairs, 2,910,271remquopairs and 2,388,665remquofpairs. It matches onremainderf.All four now run the same
fprem1loop in one helper. GCC's documented"=t"/"u"constraints are used for it, as in itsfpremexample.remquoandremquoftake the quotient bits from the status word as the assembly does, and all four setEDOMby that rule.Tested
Current-main integration (2026-11-02):
904fbdca7e9fa6f54f2f70af6724304d9ad7113fincludes maina4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8and retains the existing public commits. Conflicts preserve main’s math implementations, regression checks and debt entries alongside this topic. Linux x86-64 Release, GCC 16.2.1: rebuilt libc and the three math executables;guest_math,guest_math_exactandguest_dinkumware_internalseach pass three times (9 passes, zero skips), andpublic_headerspasses. The same baseline groups pass on main; conventions and whitespace pass. Source and dependency blobs, executable/library hashes, raw logs and JUnit are retained. This refresh adds no new console, Windows, title, GPU or numerical-reference measurement. Qualification evidence, SHA-25622866bd2a060ba69cd4387d471605afe20ed644e3257174b2d1488635f8c9b52(download verified).Current-main conflict qualification (task 2026-11-01; execution UTC recorded in logs). Published exact head
3ae4cd1429f670352b038174a45719759bf0ead1is linear above pinned main93dbd0f82aea684e95f15f06e7d42c0064af18cf. One topic commit on current main, with original JJenkx authorship preserved. All measured remainder/remquo helper bodies and the existing remainder regression are unchanged. The test conflict preserves main’s complete tanhf/expm1f fixtures and adds the exact existing remainder fixture once; all current-main debt remains.Actual Linux libc and selected test executables rebuilt from the final public input tree.
guest_math,guest_math_exact,guest_dinkumware_internalseach passed three consecutive runs: 9 runtime passes, zero skips, plus public_headers. Conventions against pinned origin/main and whitespace pass. The same pinned main passes all ten selected numeric/formatting/stream/CRT/string groups three times (30 passes), plus public_headers. Source and public-header blobs, preserved fixtures, commit authorship, source cleanliness, explicit old-SHA push leases and postpush head checks are attached. 33 recursive dependency trees / 18,032 tracked blobs verify before/after with zero errors; QuickJS’s update=none test262 corpus is explicitly excluded and is not a libc build input.Environment: Linux-7.2.11-arch1-1-x86_64-with-glibc2.44, Ryzen 9 7950X, GCC16.2.1, Ninja Release, BUILD_TESTING=ON. This is focused Linux CPU qualification; earlier Windows/module/reference reports keep their original pins. No fresh Windows/macOS, SDK-module, console, title/GPU or performance execution is claimed. AI-assisted: yes (Codex).
Evidence: https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/math-three-main93db-linux-20261101.tar.gz; SHA-256 e2f9eeee734f73fd6a3a7e944c742e860c04d937accff9b4bb532229fb38df6a.
Earlier dated qualification and reference reports below remain historical at their recorded source pins.
Current-main conflict refresh, 2026-10-27 UTC: exact head
436622ee3c3de1779d6a513b015d5f78687209b5on tested main74acfad65b3f0fd4eab653f3a3989d298fba1157. Resolved overlapping test/debt context while preserving this branch's authored production/test edits and main's nextafter environment implementation and coverage. Existing prerequisite commits remain in their original series order.Linux focused rebuild of
libcand selected test executables passesguest_mathandguest_math_exact, each three times: 6 passes, zero skips. Conventions and whitespace checks pass. Final fetched maincb45ae2ddf6e113a4619e8fed91fe7b9333c5c0fmerges cleanly; its later change is an unrelated Windows crash-test pattern, and the executed qualification remains pinned to the stated base. No new Windows, console, GPU, title, full-suite or negative-control run is claimed. Earlier reference/Windows evidence keeps its original pins.Exact pins, branch patches, preservation proofs, build/test logs, JUnit and lease-push receipts for this refresh batch. SHA-256:
e33f98cc467f038af662cc5fa491c3acc1806bb47171cf77b748f0d4d052c1f2; downloaded copy verified.Refreshed onto main
8a29e0883470b827f7eb7081196d0518c2aef0ecas63b201aac1dec7669e71792184ee890ec962412f, one topic commit with no merge commits. The only conflict was an additive debt-file append: main's child-process registry entry and this PR's remainder/remquo entry are both retained. All seven production/helper function bodies andCheckRemainderConsoleBitsare byte-identical to previous public head70b22d401552ac3c90dc85826e42bc8d9de7031b.Fresh Linux
libc,guest_math_testsandguest_math_exact_testsbuilds pass; both CTest groups pass three times (6 passes). Conventions and local merge-tree checks pass. This is rebase qualification, not a new Windows/console comparison or exception-flag claim; earlier measurements keep their original head attribution.Refresh patch, preservation hashes and build/test logs — SHA256
0110f192a55f17b8130543f4bc0cc44442d5933bdcd96fa0be8d66b655c30618; archive downloaded and hash-verified.Earlier Windows report, retained from public head
53d65b3e37before this refresh; Windows was not rerun for the rebased head:Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON,main606999f3ab.Comparison: a scratch loader runs the decrypted
libc.prxof eleven titles natively and supplies__error: PPSA04158, PPSA05916, PPSA07923, PPSA09614, PPSA13934, PPSA20423, PPSA25636, PPSA26528, PPSA33655, PPSA34008 and PPSA35169. It compared their four functions with this PR's code, checking result bits (NaN payloads included), theremquoquotient anderrno, on 4,000,196 pairs per title:All eleven give identical results, quotients and
errnoon all of them, with this PR built at-O3, and at-O0for PPSA07923.EDOMis set on 36 of the double pairs and 21 of the float ones.guest_math: the newCheckRemainderConsoleBitshas 15 double and 15 float cases, each checked through bothremainderandremquo, with the console's results, quotients anderrno:EDOM);The quotient is not checked when the result is a NaN. There it is whatever
fprem1leaves in the condition codes, which Intel documents as undefined. This PR matches the console's code on the same host CPU in those cases, which the comparison above checks, but another CPU might differ.main's existingremainderandremquochecks still pass.guest_mathandguest_dinkumware_internalspass in three runs out of three on the exact head.Negative control: with
main'sMath.cppand these tests,guest_mathaborts in aRequire, whileguest_dinkumware_internalsstill passes.python tools/check_conventions.py --base origin/mainandgit diff --checkpass.Order: this PR adds a test and a debt entry at the same anchors as my other libc PRs, so it conflicts with them textually only and lands in any order.
Not tested: macOS build of the inline assembly, a physical console, the floating-point exception flags, and
remainderl/remquol.Current-main Linux refresh
Refreshed as
70b22d401552ac3c90dc85826e42bc8d9de7031b, one topic commit directly on main1da5d1a757f18e04847557ce98953935f028a229, with no merge commits. All seven implementation functions andCheckRemainderConsoleBitsare unchanged from previous public head8e0051f69a7ab0041a5e3638b1f0f96d9bf52f04. Main's newer math implementations, test calls and canonical public declarations are retained. Both sides' debt entries are retained. This refresh adds no behavior change.Fresh Linux x86-64 Release validation:
guest_math,guest_math_exact,guest_dinkumware_internalsandpublic_headerseach pass three consecutive runs, then all four pass three more after the negative-control restoration. With only productionMath.cppreplaced by main,guest_mathaborts as expected whileguest_math_exactandguest_dinkumware_internalspass. Restoring the candidate produces a byte-identicallibc.prx. Conventions and whitespace checks pass. The historical Windows/title-library comparisons above were not rerun; no title, console, exception-flag or performance claim is added.Exact-head Linux logs, negative control and preservation proof (SHA-256
fb2cfc42ceebfc84d0a12cd0abf00ac2fbdfd9a8db1bcb3fb99a5a2342455a1e).Current Linux qualification (2026-10-28)
Rebased onto
main2227f1366188cda5699dd20e2e756a18006a5d4b. Linux CPU validation on 2026-10-28 at71a6a726c99b18c241f9dbdca1a859ac852e1c61(Arch Linux 7.2.9, AMD Ryzen 9 7950X, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON).libc,guest_math_testsandguest_math_exact_testsrebuilt from this exact source.guest_mathandguest_math_exacteach passed three consecutive runs (6/6, no skips); the same two suites each passed three runs on the pinned main (6/6). Conventions and whitespace checks pass.Exact source pins, preservation proofs, dependency checks, build logs and JUnit, SHA-256
1176269c9e6948b5252a5db9e660978d7f978fb2d9f4ed6c68bc050b10b5ae68. This is focused Linux CPU qualification; earlier Windows/title/reference measurements retain their original pins. No new title or performance result is claimed.Qualification update — 2026-10-30, repeat 2
Integrated pinned main
e471817c68d4e1b1e44b0ce369ed88bafe4ae8edatd473b63d051a1345aa8860868a5f18ea498835fc, retaining original topic commits as ancestors.Actual Linux libc/focused binaries rebuilt from this final head;
guest_math,guest_math_exact,guest_dinkumware_internalseach pass three consecutive runs (9 runtime passes), plus public_headers. Conventions against current origin/main and whitespace pass. Pinned main passed all seven runtime groups plus the header audit three times (24 runs). Full source/function/test/debt/header and 31 recursive dependency / 17,742 tracked-blob proofs are attached. Later main1c6b316cf762has 17 off-topic commits, no relevant libc/numeric/qsort/gitlink changes, and all 9 merge previews are clean; those preview trees were not executed.Focused Linux CPU scope only: prior Windows/SDK/reference reports keep original pins. No fresh Windows, console, SDK-module, title/GPU or speed measurement is claimed by this report. AI-assisted: yes. Evidence: https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/owned-math9-maine471-linux-20261030-repeat2.tar.gz (SHA256 5da4ce1732b45bb3fc566c31078c8c9ae8bf0c403654dfc60d15ee28490e20bf).
AI-assisted: yes (Codex).
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T18:56:07Z.
Review: APPROVED
Reviewed the shared
fprem1helper, quotient extraction, domain-error condition, and the added bit-pattern regressions. The x87 status-word extraction follows the cited FreeBSD amd64 implementation, and theerrnocondition excludes NaN operands as described. The tests cover signed quotient cases, subnormals, infinities, NaN payload preservation, and both precisions; the PR also reports matching results against eleven titlelibc.prxcopies over 4,000,196 input pairs each.The focused local test cannot run on this host: it lacks the CPU features required by the project’s test guard. I confirmed this host limitation independently; I am relying on the reported Windows test runs and the passing hosted conventions/relinker checks, not claiming a local runtime pass. The hosted full Linux and Windows product jobs are skipped under the repository’s PR workflow policy. I found no blocking issue in the inspected diff.