8000 Merge pull request #19479 from seberg/fixup-clang-flag-try · numpy/numpy@6388471 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6388471

Browse files
authored
Merge pull request #19479 from seberg/fixup-clang-flag-try
BLD: Add clang `-ftrapping-math` also for `compiler_so`
2 parents 131b6bf + f1d082c commit 6388471

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Distutils forces strict floating point model on clang
2+
-----------------------------------------------------
3+
NumPy now sets the ``-ftrapping-math`` option on clang to enforce correct
4+
floating point error handling for universal functions.
5+
Clang defaults to non-IEEE and C99 conform behaviour otherwise.
6+
This change (using the equivalent but newer ``-ffp-exception-behavior=strict``)
7+
was attempted in NumPy 1.21, but was effectively never used.

numpy/core/src/umath/loops_exponent_log.dispatch.c.src

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ fma_get_exponent(__m256 x)
149149
__m256 normal_mask = _mm256_cmp_ps(x, _mm256_set1_ps(FLT_MIN), _CMP_GE_OQ);
150150

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

182182
/*
183-
* It is necessary for temp1 to be volatile, a bug in clang optimizes it out which leads
184-
* to an overflow warning in some cases. See https://github.com/numpy/numpy/issues/18005
183+
* The volatile is probably unnecessary now since we compile clang with
184+
* `-ftrapping-math`: https://github.com/numpy/numpy/issues/18005
185185
*/
186186
volatile __m256 temp1 = _mm256_blendv_ps(x, _mm256_set1_ps(0.0f), normal_mask);
187187
__m256 temp = _mm256_mul_ps(temp1, two_power_100);

numpy/distutils/ccompiler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ def CCompiler_customize_cmd(self, cmd, ignore=()):
388388
if hasattr(self, 'compiler') and 'clang' in self.compiler[0]:
389389
# clang defaults to a non-strict floating error point model.
390390
# Since NumPy and most Python libs give warnings for these, override:
391-
self.compiler.append('-ffp-exception-behavior=strict')
391+
self.compiler.append('-ftrapping-math')
392+
self.compiler_so.append('-ftrapping-math')
392393

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

0 commit comments

Comments
 (0)
0