GeezerVison is showing github.com — Merge pull request #19479 from seberg/fixup-clang-flag-try · numpy/numpy@6388471
File treeExpand file treeCollapse file tree Open diff view settings doc/release/upcoming_changes
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +7Lines changed: 7 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 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. |
Collapse file Copy file name to clipboardExpand all lines: numpy/core/src/umath/loops_exponent_log.dispatch.c.src +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -149,8 +149,8 @@ fma_get_exponent(__m256 x) | 149 | 149 | __m256 normal_mask = _mm256_cmp_ps(x, _mm256_set1_ps(FLT_MIN), _CMP_GE_OQ); | 150 | 150 |
| 151 | 151 | /* | 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 | 154 | 154 | */ | 155 | 155 | volatile __m256 temp1 = _mm256_blendv_ps(x, _mm256_set1_ps(0.0f), normal_mask); | 156 | 156 | __m256 temp = _mm256_mul_ps(temp1, two_power_100); | @@ -180,8 +180,8 @@ fma_get_mantissa(__m256 x) | 180 | 180 | __m256 normal_mask = _mm256_cmp_ps(x, _mm256_set1_ps(FLT_MIN), _CMP_GE_OQ); | 181 | 181 |
| 182 | 182 | /* | 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 | 185 | 185 | */ | 186 | 186 | volatile __m256 temp1 = _mm256_blendv_ps(x, _mm256_set1_ps(0.0f), normal_mask); | 187 | 187 | __m256 temp = _mm256_mul_ps(temp1, two_power_100); | |
Collapse file Copy file name to clipboardExpand all lines: numpy/distutils/ccompiler.py +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -388,7 +388,8 @@ def CCompiler_customize_cmd(self, cmd, ignore=()): | 388 | 388 | if hasattr(self, 'compiler') and 'clang' in self.compiler[0]: | 389 | 389 | # clang defaults to a non-strict floating error point model. | 390 | 390 | # 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') | 392 | 393 |
| 393 | 394 | def allow(attr): | 394 | 395 | return getattr(cmd, attr, None) is not None and attr not in ignore | |
|