Repository navigation
fix(libc): honor strtod flush-to-zero with DAZ enabled - #28284
ibrahimmaq14 wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Change: Bug fix Merge Risk:
|
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 8a70bddf1e:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_strtod_subnormal_testsbuilt cleanly. - CTest (
guest_strtod_subnormal):1/1 Test #1333: guest_strtod_subnormal ........... Passed 0.09 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libc/src/Strings.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #1333: guest_strtod_subnormal ........... Passed 0.09 sec 100% tests passed, 0 tests failed out of 1 - Code reading:
- Verified that std::bit_cast(bits & signMask) correctly preserves the sign bit and produces +0.0 or -0.0 without invoking any floating-point arithmetic or triggering DAZ flush-to-zero in Strings.cpp:585.
- Verified bitwise check 'magnitude - 1 < minimumNormalBits - 1' correctly identifies non-zero subnormal double values in magnitude range [1, 0x000fffffffffffff] when minimumNormalBits is 0x0010000000000000. Zero magnitude wraps to UINT64_MAX, so 0.0 is correctly excluded.
- Verified errno is properly set to ERANGE upon flushing to zero in ParseFloat, conforming to C/POSIX and PS5 libc strtod/wcstod specifications.
- Verified no floating-point comparisons are performed that could be affected by Apple Clang or x86/ARM MXCSR DAZ/FTZ optimization passes.
- Verified GuestStrtodSubnormal.cpp adds comprehensive verification for signed negative subnormal flushing across both strtod and wcstod via CheckBoth.
- Verified strict compliance with AGENTS.md conventions (no disallowed comments, no made-up error codes, no special-casing of title IDs).
Looks Good To Me
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing blocks this change; the inspected implementation compares the parsed double’s magnitude bits to the normal-range boundary and returns a zero carrying the original sign when flush-to-zero is enabled.
What I ran
- Reviewed head
8a70bddf1e137336045fb9f49c29b467e0cc2f72and the prepared diff; no checks were run. - Read
core/libs/prx/libc/src/Strings.cpp(lines 525–610) andcore/libs/tests/GuestStrtodSubnormal.cpp(full file). The full text of both changed files was included; no changed files were excluded.
Results
| Check | Result | Note |
|---|---|---|
| Patch review | passed | Two changed files inspected |
| Tests | not run | Author reports local runs |
Findings
Blocking
None.
Non-blocking
None.
Not verified
The author-reported test and convention-check results were not independently run or confirmed.
To get this to a good state
Nothing is required.
|
Linux check at exact head
AI-assisted: yes |
|
Tested
AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports. |
|
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.
|
NobleBrains
left a comment
There was a problem hiding this comment.
Confirmed on macOS 15.
Setup: Apple M4, macOS 15.7.9, Apple clang 17.0.0 (clang-1700.6.3.2), x86_64 Release under Rosetta, BUILD_TESTING=ON. These are the OS and compiler generation of the macos-15 runner; the description tested macOS 27.
Tree: main 93d64f2d1e + the open macOS build fixes #27201, #27739, #27843, #17425, #27827, #27767 (main does not build on macOS without them, see #28168) + #22091 + #28369, then #28075, #28076 and #28284 merged one after another. Each merged cleanly.
guest_strtod_subnormal |
failures |
|---|---|
| before this PR (same tree) | 3/3 |
with this PR at 8a70bddf1e |
0/5 |
Full ctest -j 6 with all of them merged: 7038/7066 pass. Compared with the same tree before these PRs, no test fails that passed before. jsc_wtf_cpu_time aborted once under the parallel load, then passed 5/5 on its own; it is unrelated JavaScriptCore CPU-time code.
AI-assisted: yes (Claude Code)
ligmaSec
left a comment
There was a problem hiding this comment.
Built and ran the complete GuestStrtodSubnormal fixture on Linux at 8a70bddf1e. The setup tested subnormal results with the MXCSR flush-to-zero and denormals-are-zero settings, including the newly covered call with both settings enabled. The existing parsing and end-pointer cases also passed.
AI-assisted: yes.
Plyxen
left a comment
There was a problem hiding this comment.
I read the diff at 8a70bddf1e. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), merged into main at 6c6b29320fe together with other open PRs (so not an isolated build).
guest_strtod_subnormal: pass on both.- Control (the same tree with only this PR's source change taken out): it passes too on both, as expected: the body describes an Apple Clang optimization, and GCC did not have the problem. So this shows no regression, not the fix.
Not checked: macOS.
AI-assisted: yes (Claude Code)
|
Host: macOS 15.7.9, Apple M4, x86_64 Release build under Rosetta 2,
The full AI-assisted: yes (Claude Code) |
What
Addresses the
guest_strtod_subnormalfailure in #27647. Apple Clang optimized the masked nonzero check into a floating-point comparison. With MXCSR denormals-are-zero enabled, that comparison sees a subnormal as zero and the flush-to-zero branch is skipped.Compare the unsigned significand and exponent bits as a single range between zero and the smallest normal double. When FTZ is enabled and the magnitude is in that range, return signed zero with
ERANGE. Add a negative decimal case for bothstrtodandwcstod.Tested
GuestStrtodSubnormal.cpptest withStrings.cppat-O3 -DNDEBUG. The test aborts onmainat “FTZ flushes an inexact decimal subnormal” and passes with this change.libc/src/exception/Runtime.cppbecause the macOS C++ ABI headers lack__class_type_info::__contained_virtual_maskand related members.tools/check_conventions.pyandgit diff --checkpassed. I compared both changed files against the open PRs and found no overlapping edits.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)Summary by CodeRabbit