-
Notifications
You must be signed in to change notification settings - Fork 60
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
Add USE_FLOAT_EXCEPTIONS
to enable floating point exceptions
#1451
base: master
Are you sure you want to change the base?
Conversation
I have not tested the Apple and MSVC code. |
f05b27f
to
4993a7f
Compare
USE_DEBUG_FPE
to enable floating point exceptionsUSE_FLOAT_EXCEPTIONS
to enable floating point exceptions
4993a7f
to
8687854
Compare
I renamed the cmake option to |
b878d3a
to
7c60e69
Compare
src/engine/framework/System.cpp
Outdated
@@ -276,6 +298,69 @@ static void CloseSingletonSocket() | |||
#endif | |||
} | |||
|
|||
static void SetFloatingPointExceptions() | |||
{ | |||
// Must be done after Sys::Init() to read cvars from command line. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong comment
static void SetFloatingPointExceptions() | ||
{ | ||
// Must be done after Sys::Init() to read cvars from command line. | ||
#if defined(DAEMON_USE_FLOAT_EXCEPTIONS_AVAILABLE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our code style is to have these on the left side and never indent them based on indentation of non-preprocessor code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's bad practice within a block, really.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What? This style is used very consistently in our code and is common in other code bases too. Preprocessor and non-preprocessor lines do not syntactically nest with each other, so it makes a sort of sense that neither one affects the other's indentation.
unsigned int exceptions = 0; | ||
#endif | ||
|
||
// Operations with NaN. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not very accurate, cos(1.001)
also does this for example
@@ -148,13 +148,20 @@ else() | |||
set(WARNMODE "no-") | |||
endif() | |||
|
|||
# Compiler options | |||
option(USE_FLOAT_EXCEPTIONS "Use floating point exceptions" OFF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use description of this is not quite accurate. It doesn't turn on exceptions; it alters compiler options in a way that makes the exceptions more likely to be useful. Maybe you could call it USE_FLOAT_DEBUG_MODE or something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I think the name is fine but it would be good to mention the cvars. Enable floating point exceptions with common.floatException.* cvars
7c60e69
to
a65cdc7
Compare
Hmm, my mac doesn't support more than Catalina, so no more than macOS 10.15.7 with Clang 12.0.0, and I get these errors:
So I cannot test macOS right now. |
10070cb
to
4086988
Compare
I face a weird cmake bug, if I do that: if (USE_FLOAT_EXCEPTIONS)
message(STATUS "test true")
# Floating point exceptions requires trapping math
# to avoid false positives on architectures with SSE.
set_c_cxx_flag("-ffp-model=strict")
endif() The “test true” message is printed, but the But if I do: set_c_cxx_flag("-ffp-model=strict")
if (USE_FLOAT_EXCEPTIONS)
message(STATUS "test true")
# Floating point exceptions requires trapping math
# to avoid false positives on architectures with SSE.
endif() The flag is set. So to sum it up:
but the whole combination doesn't work… |
If I do instead: if (USE_FLOAT_EXCEPTIONS)
message(STATUS "test true")
try_c_cxx_flag(FFP_MODEL_STRICT "-ffp-model=strict")
# Floating point exceptions requires trapping math
# to avoid false positives on architectures with SSE.
endif() I get this printed:
But the flag is not added to the compiler command line. On the contrary if I do that: try_c_cxx_flag(FFP_MODEL_STRICT "-ffp-model=strict")
if (USE_FLOAT_EXCEPTIONS)
message(STATUS "test true")
# Floating point exceptions requires trapping math
# to avoid false positives on architectures with SSE.
endif() I get this printed:
And the flag is added to the compiler command line. |
USE_FLOAT_EXCEPTIONS
to enable floating point exceptions (disabled by default)USE_FAST_MATH
to enable or disable fast math (enabled by default)When
USE_DEBUG_FPE
is used, nothing is done unless some of those cvars are enabled:common.floatExceptions.invalid
common.floatExceptions.divByZero
common.floatExceptions.overflow
The
USE_FLOAT_EXCEPTIONS
option is required to specialize the build to make it possible to enable them.