diff options
author | Raghuveer Devulapalli <me.raghuveer@gmail.com> | 2020-12-19 07:53:09 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-19 09:53:09 -0600 |
commit | dc3fe03617103814d56941b74f4ebbf9b33cf3b2 (patch) | |
tree | 790e2da37740f3276a8f2c117d1c84ab35660846 | |
parent | b2f29f2751a8c9fcd83bb106d5e020d1901377d6 (diff) | |
download | numpy-dc3fe03617103814d56941b74f4ebbf9b33cf3b2.tar.gz |
BUG: make a variable volatile to work around clang compiler bug (#18030)
* BUG: make a variable volatile to work around clang compiler bug
* Adding comments for relevance
* TST: Adding test to check for no overflow warnings in log
Fixes #18005
-rw-r--r-- | numpy/core/src/umath/simd.inc.src | 12 | ||||
-rw-r--r-- | numpy/core/tests/test_umath.py | 5 |
2 files changed, 15 insertions, 2 deletions
diff --git a/numpy/core/src/umath/simd.inc.src b/numpy/core/src/umath/simd.inc.src index a118fb0d0..c2104810f 100644 --- a/numpy/core/src/umath/simd.inc.src +++ b/numpy/core/src/umath/simd.inc.src @@ -1549,7 +1549,11 @@ fma_get_exponent(__m256 x) __m256 denormal_mask = _mm256_cmp_ps(x, _mm256_set1_ps(FLT_MIN), _CMP_LT_OQ); __m256 normal_mask = _mm256_cmp_ps(x, _mm256_set1_ps(FLT_MIN), _CMP_GE_OQ); - __m256 temp1 = _mm256_blendv_ps(x, _mm256_set1_ps(0.0f), normal_mask); + /* + * 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 + */ + volatile __m256 temp1 = _mm256_blendv_ps(x, _mm256_set1_ps(0.0f), normal_mask); __m256 temp = _mm256_mul_ps(temp1, two_power_100); x = _mm256_blendv_ps(x, temp, denormal_mask); @@ -1576,7 +1580,11 @@ fma_get_mantissa(__m256 x) __m256 denormal_mask = _mm256_cmp_ps(x, _mm256_set1_ps(FLT_MIN), _CMP_LT_OQ); __m256 normal_mask = _mm256_cmp_ps(x, _mm256_set1_ps(FLT_MIN), _CMP_GE_OQ); - __m256 temp1 = _mm256_blendv_ps(x, _mm256_set1_ps(0.0f), normal_mask); + /* + * 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 + */ + volatile __m256 temp1 = _mm256_blendv_ps(x, _mm256_set1_ps(0.0f), normal_mask); __m256 temp = _mm256_mul_ps(temp1, two_power_100); x = _mm256_blendv_ps(x, temp, denormal_mask); diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py index 8162e52bd..bc72aa862 100644 --- a/numpy/core/tests/test_umath.py +++ b/numpy/core/tests/test_umath.py @@ -926,6 +926,11 @@ class TestSpecialFloats: assert_raises(FloatingPointError, np.log, np.float32(-np.inf)) assert_raises(FloatingPointError, np.log, np.float32(-1.0)) + # See https://github.com/numpy/numpy/issues/18005 + with assert_no_warnings(): + a = np.array(1e9, dtype='float32') + np.log(a) + def test_sincos_values(self): with np.errstate(all='ignore'): x = [np.nan, np.nan, np.nan, np.nan] |