Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Jun 2021 17:32:29 GMT
From:      Dimitry Andric <dim@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 856f1fd6c360 - stable/13 - Fix failures in libm's lround_test after clang 12 import
Message-ID:  <202106251732.15PHWTkh098950@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by dim:

URL: https://cgit.FreeBSD.org/src/commit/?id=856f1fd6c3607e1b77c97ca6830f230b876d2bce

commit 856f1fd6c3607e1b77c97ca6830f230b876d2bce
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2021-06-22 16:38:27 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2021-06-25 17:30:50 +0000

    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)
---
 lib/msun/src/s_lround.c      | 8 +++++---
 lib/msun/tests/lround_test.c | 7 +------
 2 files changed, 6 insertions(+), 9 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
diff --git a/lib/msun/tests/lround_test.c b/lib/msun/tests/lround_test.c
index a6daa5459c7b..ddb2b2cea9b3 100644
--- a/lib/msun/tests/lround_test.c
+++ b/lib/msun/tests/lround_test.c
@@ -40,14 +40,9 @@ __FBSDID("$FreeBSD$");
 
 #define	IGNORE	0x12345
 
-/*
- * XXX The volatile here is to avoid gcc's bogus constant folding and work
- *     around the lack of support for the FENV_ACCESS pragma.
- */
 #define	test(func, x, result, excepts)	do {					\
-	volatile double _d = x;							\
 	ATF_REQUIRE_EQ(0, feclearexcept(FE_ALL_EXCEPT));			\
-	volatile double _r = (func)(_d);					\
+	long long _r = (func)(x);						\
 	CHECK_FP_EXCEPTIONS_MSG(excepts, FE_ALL_EXCEPT, "for %s(%s)",		\
 	    #func, #x);								\
 	if ((excepts & FE_INVALID) != 0) {					\



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202106251732.15PHWTkh098950>