You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(libc): honor strtod flush-to-zero with DAZ enabled - #2064
Source commit: 8a70bddf1e137336045fb9f49c29b467e0cc2f72. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.
What
Addresses the guest_strtod_subnormal failure in boykopovar#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 both strtod and wcstod.
Tested
macOS 27.2.1, Apple M1, x86-64 under Rosetta, Apple Clang 17. Built the existing GuestStrtodSubnormal.cpp test with Strings.cpp at -O3 -DNDEBUG. The test aborts on main at “FTZ flushes an inexact decimal subnormal” and passes with this change.
Linked the CMake Release objects for the same source and test into a standalone executable and ran it successfully. The standard CTest build stops in unchanged libc/src/exception/Runtime.cpp because the macOS C++ ABI headers lack __class_type_info::__contained_virtual_mask and related members.
tools/check_conventions.py and git diff --check passed. I compared both changed files against the open PRs and found no overlapping edits.
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 and the licence notice of code adapted from upstream (see AGENTS.md)
Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
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
Generic behaviour, not specific to one title
Depends on: none
Fixes: none
Unblocks: none
GPUs tested: n/a
AI-assisted: yes
Summary by CodeRabbit
Bug Fixes
Improved handling of subnormal floating-point values when flush-to-zero is enabled. Values too small to represent normally now produce signed zero and report a range error, including negative values.
No actionable comments were generated in the recent review.
Walkthrough
Changes: Flush-to-zero handling
Layer / File(s)
Summary
Detect and test signed zero core/libs/prx/libc/src/Strings.cpp, core/libs/tests/GuestStrtodSubnormal.cpp
The parser now detects zero-magnitude results below the minimum-normal threshold and returns signed zero with ERANGE. The test checks negative zero for -1e-310.
Change: Bug fix
Merge Risk: Minimal · up to 8a70b
This change makes flush-to-zero parsing of decimal subnormals return a signed zero and set ERANGE consistently. It also adds a negative-input test. No merge-blocking risk was found in the supplied context.
Security architecture risk: Minimal · up to 8a70b
Guest libc now reliably returns signed zero and reports underflow for decimal subnormals when flush-to-zero is enabled. The fix does not broaden what guest callers can access or change how the emulator is deployed.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: f198caee-d475-4edb-ba27-3209ce0a6a1b
Commits
Reviewing files that changed from the base of the PR and between 4131f51 and 8a70bdd.
Files selected for processing: 2
core/libs/prx/libc/src/Strings.cpp
core/libs/tests/GuestStrtodSubnormal.cpp
Limit details: You’ve used all 10 included reviews currently available.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Addresses the
guest_strtod_subnormalfailure in boykopovar#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