Repository navigation
fix(libc): match title libc.prx for hexadecimal strtod underflow - #12291
oneandonlydean merged 4 commits into
Conversation
Classify hexadecimal strtod and wcstod input from its own digits rather than a long double approximation. As measured on God of War Ragnarok's bundled libc.prx, ERANGE is set only on overflow or when the exact value is below 2^-1074, and a value between 2^-1075 and 2^-1074 becomes the smallest subnormal only from 2^-1075 * (1 + 2^-52) up. Refs boykopovar#9691 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep only the gaps: the rule is measured on one title-bundled libc.prx, and on Linux glibc 2.35's strtod rounds some hexadecimal subnormal results a unit low. Refs boykopovar#9691 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The explicit binary exponent stopped accumulating near 1e9 while the digits add 4 per character without bound, so a subject with a few hundred million digits was classified against the wrong exponent: 0x1 followed by 3e8 zeros and p-1200000005000 kept errno, and a long zero fraction with p+1000000000000 underflowed instead of overflowing. Saturate the explicit exponent at 2^62, beyond what any addressable digit run can offset, so the sum never overflows or changes sign. Record that _Stod and _Stodx follow the title libc.prx rule for hexadecimal underflow, unverified for libSceLibcInternal. Refs boykopovar#9691 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed the hexadecimal subject parser and underflow decision against the documented title-bundled libc.prx rule. The 64-bit significand plus sticky bit and saturated exponent retain the boundary information needed for the measured threshold; the tests cover below/at/above the cutoff, signed zero, normal transition, overflow, very long runs, and matching wcstod bits/end pointers/errno. The author reports a direct module comparison over 260,055 inputs and Windows/WSL focused runs; hosted Windows, registration, relinker, ASan, and write-watch checks pass, while hosted Linux is skipped. The PR clearly limits the claim to one title build run on a host, not a console. No blocking issue found.
|
@B-Howell the code and the measurement look right to me. One conventions point: docs/dev/debt/libc.md names the game ("God of War Ragnarök") in both the |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@oneandonlydean Done in a252638. Both debt entries ( AI-assisted (Claude Code). |
|
Manual follow-up to the skipped comparisons in the overlap report (comment6463890106). Reviewed target head: I inspected the listed shared-file patches for all 26 candidates. No duplicate target export/implementation was found in this scoped review. The table records the specific shared-file changes and integration requirements; shared debt/header changes still need to preserve both sides. This is not a claim that every pair merges cleanly or that a combined branch has been built/tested. This follow-up addresses the skipped-comparison request only. Existing CI limitations, dependency ordering and outstanding re-review requirements remain in force; approvals or tests from older heads do not become current-head evidence through this audit. Delta review: added #10002 ( Candidate heads, shared files and manual dispositions
AI-assisted: yes (Codex). |
|
Follow-up to the actual compared conflicts in overlap comment6463890106, for this PR at I inspected the listed shared-file patches for 1 compared candidate at the heads below. This is separate from the earlier skipped-comparison review.
These scoped findings do not establish clean pairwise merges or a successful combined build/test. They do not clear other review, CI, dependency or current-head verification obligations. @JJenkx For the shared strtod paragraph I propose #11892 first, then I will reconcile this PR onto it, preserve both decimal and hexadecimal qualifications, and rerun the focused narrow/wide regressions. Please confirm or propose another order. I will record the confirmed ordering dependency; the current landing watch remains active and this proposal is not an agreement. AI-assisted: yes (Codex). |
What
Hexadecimal
strtodandwcstodnow follow thelibc.prxthat titles ship when the exact value is below 2^-1074, the last open item of #9691. The rule, measured from God of War Ragnarök's (PPSA08329) bundledlibc.prx(SHA-256a485b34ef160ee635d357f21f4a93586bed1cf499b82918c734dcfd78b04e443):errnois left alone (unless it overflows, which setsERANGE).ERANGE. Between 2^-1075 and 2^-1074 the result is 2^-1074 only from 2^-1075 * (1 + 2^-52) up, otherwise a signed zero. So0x1.8p-1075and0x1.0000000000001p-1075give 2^-1074, but0x1p-1075,0x1.00000000000001p-1075and0x1.0000000000000fp-1075give 0.wcstodgives the same bits, end positions anderrnoasstrtod.How it was measured: a small loader maps that decrypted
libc.prx, applies its relocations, supplies__errorand calls itsstrtodandwcstodnatively in a Linux (WSL2) host process. This is a title-shipped SDK module run on a PC, not a console measurement. An exact rational model of the rule above matches every result of thatlibc.prxon 260,055 hexadecimal inputs (200,046 hand-built edge and boundary cases plus 60,009 random forms; 9,735 of them between 2^-1075 and 2^-1074), with 0 mismatches.wcstodoutput was byte-identical tostrtodon both sets.The main bug: the old check classified only results equal to 2^-1074, and used
std::strtoldto recover the exact value. That keeps 64 bits, so0x1.fffffffffffffffffp-1075looked like 2^-1074 and kepterrno, and values just above 2^-1075 were rounded by the host instead of truncated to zero. The new code reads the subject itself: the first 64 significant bits plus a sticky bit, and an exponent that saturates at 2^62 (digit runs add at most about ±2^59, so the sum cannot overflow).strtof,strtoldand decimal input are unchanged.docs/dev/debt/libc.md: thestrtodentry records that the hex rule rests on one title'slibc.prx, and that results of at least 2^-1074 come from the hoststrtod, where glibc 2.35 rounds some a unit low (for example0x3ffffffffffff5p-1077). The_Stod/_Stodxentry records thatlibSceLibcInternal.sprxis unverified for hexadecimal underflow and follows this rule here.Tested
mainb99bbeb):guest_strtod_subnormal,guest_math,guest_dinkumware_internals,guest_wide_strings4/4 passed. Strings.cpp and GuestStrtodSubnormal.cpp rebuilt with 0 warnings.main's Strings.cpp with the new tests abortsguest_strtod_subnormalat "long hexadecimal just below the smallest subnormal".strtodandwcstod) passed in 20.25 s. A further 36 boundary inputs (endptr,0xwith no digits,0x.p1, uppercaseP/X, signs,-0x0p0, leading and fraction zeros, the band edges with sticky bits) passed. They gave the same results as thatlibc.prxrun directly.strtodrounds the glibc cases from the debt entry (0x3ffffffffffff5p-1077,0x20000000000003p-1076and four others) the same as thatlibc.prx.main660a0b3 (82c8a51), which only changes libkernel_sys files.tools/check_conventions.py --base origin/mainpasses.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)🤖 Generated with Claude Code