Skip to content

Fix signed int64 conversion under fast math - #3514

Merged
copybara-service[bot] merged 2 commits into
google:masterfrom
MokiMeow:fix/prevent-i64-conversion-reassociation
Oct 27, 2026
Merged

copybara-service[bot] merged 2 commits into
google:masterfrom
MokiMeow:fix/prevent-i64-conversion-reassociation

Conversation

@MokiMeow

Copy link
Copy Markdown
Contributor

Fixes #3513.

Under -ffast-math, the emulated signed int64-to-double conversion can reassociate rounding-sensitive arithmetic. SSE4 then converts -13 to 0, making Log(1.0 / 4098) return approximately -0.000488 instead of -8.318254.

Preserve intermediate rounding with a scoped Clang FP policy or GCC association barrier. Older GCC uses a volatile intermediate only under associative math. Add a dedicated fast-math regression target to CMake, Bazel and Meson.

Validation on Linux x86-64:

  • New SSE4 regression fails on the original code and passes with this fix.
  • GCC 14: all 7 enabled targets pass. Clang 19: all 8 enabled targets pass.
  • CMake/GTest: 8/8 pass. Meson: 1/1 pass.
  • Ordinary conversion and contributed math test executables pass across enabled targets.
  • clang-format and buildifier pass.
  • Older-GCC fallback exercised through a private header overlay on GCC 14.

Bazel execution, actual older GCC, Windows, macOS and non-x86 architectures were not tested locally. No performance claim is made.

@google-cla

google-cla Bot commented Oct 24, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@jan-wassenberg jan-wassenberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing and adding the new test.

@copybara-service
copybara-service Bot merged commit 1673a1c into google:master Oct 27, 2026
49 of 50 checks passed
@MokiMeow
MokiMeow deleted the fix/prevent-i64-conversion-reassociation branch November 6, 2026 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect int64-to-double conversion with fast-math

2 participants