aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2021-06-22 16:38:27 +0000
committerDimitry Andric <dim@FreeBSD.org>2021-06-25 17:31:32 +0000
commit7356681c6c28a02f29f529a353938707d312109e (patch)
tree73b7208a4642c1ab03dcbcd1fd34645bafeb817e
parent1adf1b31582d9c311ff9166994bd6e4db7fb7e9e (diff)
downloadsrc-7356681c6c28a02f29f529a353938707d312109e.tar.gz
src-7356681c6c28a02f29f529a353938707d312109e.zip
Fix failures in libm's lround_test after clang 12 import
It turned out that the (type)DTYPE_MAX conversions at the top of s_lround.c are now emitted as cvtsi2sd instructions, at least on SSE capable CPUs. This caused the FE_INEXACT flag to always be set, at least for the double and float variants. Under clang 11, the whole INRANGE() comparisons were still optimized away, but this has "improved" in clang 12, due to stricter adherence to the -ffp-exception-behavior=maytrap compiler flag. To avoid run-time integer to float conversions, use static constants instead, so they are computed at compile time, and the INRANGE() statements are optimized away again, if applicable. While here, use an integer instead of a floating type to store the test results in lround_test.c, as this is more appropriate, and we can also drop the volatile hack. Reported by: arichardson (cherry picked from commit df3b437c1e073eb83e9a93af1c417f3ee8d0de3b)
-rw-r--r--lib/msun/src/s_lround.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/msun/src/s_lround.c b/lib/msun/src/s_lround.c
index 66d9183a74bc..c4d305401ac8 100644
--- a/lib/msun/src/s_lround.c
+++ b/lib/msun/src/s_lround.c
@@ -49,9 +49,11 @@ __FBSDID("$FreeBSD$");
* that everything is in range. At compile time, INRANGE(x) should reduce to
* two floating-point comparisons in the former case, or TRUE otherwise.
*/
-static const type dtype_min = (type)DTYPE_MIN - 0.5;
-static const type dtype_max = (type)DTYPE_MAX + 0.5;
-#define INRANGE(x) (dtype_max - (type)DTYPE_MAX != 0.5 || \
+static const type type_min = (type)DTYPE_MIN;
+static const type type_max = (type)DTYPE_MAX;
+static const type dtype_min = type_min - 0.5;
+static const type dtype_max = type_max + 0.5;
+#define INRANGE(x) (dtype_max - type_max != 0.5 || \
((x) > dtype_min && (x) < dtype_max))
dtype