Skip to content

add scoped flush-to-zero and denormals-are-zero flags - #1111

Closed
msoud2509 wants to merge 4 commits into
quantumlib:mainfrom
msoud2509:fix-denormals-flags
Closed

add scoped flush-to-zero and denormals-are-zero flags#1111
msoud2509 wants to merge 4 commits into
quantumlib:mainfrom
msoud2509:fix-denormals-flags

Conversation

@msoud2509

Copy link
Copy Markdown

Fixes #666 (denormals_are_zeros setting has unexpected side effects) by making making MXCSR flag changes scoped to class intialization, follows closely by changes done by @mhucka in a previous draft PR

@google-cla

google-cla Bot commented Sep 7, 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.

@github-actions github-actions Bot added the size: M 50< lines changed <250 label Sep 7, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces ScopedFlushToZeroAndDenormalsAreZeros, an RAII guard class in lib/util_cpu.h to manage and automatically restore MXCSR control flags (flush-to-zero and denormals-are-zeros). This guard is adopted across various simulation paths in pybind_interface/pybind_main.cpp and stubbed in GPU-specific pybind files. A new test is also added to verify the restoration of these flags. Feedback on the changes includes adding the missing Apache 2.0 license header and fixing line-length violations in the new Python test file, as well as shortening a variable name in pybind_main.cpp to adhere to the 80-character limit for C++ files.

Comment thread qsimcirq_tests/denormals_are_zeros_test.py Outdated
Comment thread pybind_interface/pybind_main.cpp Outdated
@msoud2509
msoud2509 marked this pull request as draft September 8, 2026 01:56
@msoud2509 msoud2509 closed this Sep 8, 2026
@msoud2509
msoud2509 deleted the fix-denormals-flags branch September 10, 2026 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: M 50< lines changed <250

Projects

None yet

Development

Successfully merging this pull request may close these issues.

denormals_are_zeros setting has unexpected side effects

1 participant