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

BLD: Add clang -ftrapping-math also for compiler_so #19479

Merged
merged 3 commits into from
Jul 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/release/upcoming_changes/19479.compatibility.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Distutils forces strict floating point model on clang
-----------------------------------------------------
NumPy now sets the ``-ftrapping-math`` option on clang to enforce correct
floating point error handling for universal functions.
Clang defaults to non-IEEE and C99 conform behaviour otherwise.
This change (using the equivalent but newer ``-ffp-exception-behavior=strict``)
was attempted in NumPy 1.21, but was effectively never used.
8 changes: 4 additions & 4 deletions numpy/core/src/umath/loops_exponent_log.dispatch.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ fma_get_exponent(__m256 x)
__m256 normal_mask = _mm256_cmp_ps(x, _mm256_set1_ps(FLT_MIN), _CMP_GE_OQ);

/*
* It is necessary for temp1 to be volatile, a bug in clang optimizes it out which leads
* to an overflow warning in some cases. See https://github.com/numpy/numpy/issues/18005
* The volatile is probably unnecessary now since we compile clang with
* `-ftrapping-math`: https://github.com/numpy/numpy/issues/18005
*/
volatile __m256 temp1 = _mm256_blendv_ps(x, _mm256_set1_ps(0.0f), normal_mask);
__m256 temp = _mm256_mul_ps(temp1, two_power_100);
Expand Down Expand Up @@ -180,8 +180,8 @@ fma_get_mantissa(__m256 x)
__m256 normal_mask = _mm256_cmp_ps(x, _mm256_set1_ps(FLT_MIN), _CMP_GE_OQ);

/*
* It is necessary for temp1 to be volatile, a bug in clang optimizes it out which leads
* to an overflow warning in some cases. See https://github.com/numpy/numpy/issues/18005
* The volatile is probably unnecessary now since we compile clang with
* `-ftrapping-math`: https://github.com/numpy/numpy/issues/18005
*/
volatile __m256 temp1 = _mm256_blendv_ps(x, _mm256_set1_ps(0.0f), normal_mask);
__m256 temp = _mm256_mul_ps(temp1, two_power_100);
Expand Down
3 changes: 2 additions & 1 deletion numpy/distutils/ccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ def CCompiler_customize_cmd(self, cmd, ignore=()):
if hasattr(self, 'compiler') and 'clang' in self.compiler[0]:
# clang defaults to a non-strict floating error point model.
# Since NumPy and most Python libs give warnings for these, override:
self.compiler.append('-ffp-exception-behavior=strict')
self.compiler.append('-ftrapping-math')
self.compiler_so.append('-ftrapping-math')

def allow(attr):
return getattr(cmd, attr, None) is not None and attr not in ignore
Expand Down