Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MathUtil.Denormals with clang 15/16 #11485

Merged
merged 2 commits into from
Apr 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/test/mathutiltest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,26 @@ TEST_F(MathUtilTest, Denormal) {
_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_OFF);
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_OFF);

volatile float fDenormal = std::numeric_limits<float>::min() / 2.0f;
// Note: The volatile keyword makes sure that the division is executed on the target
// and not by the pre-processor. In case of clang >= 15 the pre-processor flushes to
// zero with -ffast-math enabled.
volatile float fDenormal = std::numeric_limits<float>::min();
fDenormal /= 2.0f;
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you! Please add a comment why the operations are written in this style including the volatile keyword.

EXPECT_NE(0.0f, fDenormal);

volatile double dDenormal = std::numeric_limits<double>::min() / 2.0;
volatile double dDenormal = std::numeric_limits<double>::min();
dDenormal /= 2.0;
EXPECT_NE(0.0, dDenormal);

_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);

fDenormal = std::numeric_limits<float>::min() / 2.0f;
fDenormal = std::numeric_limits<float>::min();
fDenormal /= 2.0f;
EXPECT_EQ(0.0f, fDenormal);

dDenormal = std::numeric_limits<double>::min() / 2.0;
dDenormal = std::numeric_limits<double>::min();
dDenormal /= 2.0;
EXPECT_EQ(0.0, dDenormal);

#endif
Expand Down