Skip to content

fix(libc): honor strtod flush-to-zero with DAZ enabled - #2064

Open
Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/28284
Open

Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/28284

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#28284, originally opened by ibrahimmaq14.

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.

@coderabbitai

coderabbitai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Explain Change →

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

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 2
  • Waived: $0.50 (charged $0.00)
  • View usage details

Note

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants