Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Apr 2021 11:08:34 GMT
From:      Alex Richardson <arichardson@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 47950e427c5f - stable/13 - Fix lib/msun/tests/csqrt_test on platforms with 128-bit long double
Message-ID:  <202104221108.13MB8YQk088820@gitrepo.freebsd.org>

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

URL: https://cgit.FreeBSD.org/src/commit/?id=47950e427c5ffada65d639fb1107bf6a3ab85b7f

commit 47950e427c5ffada65d639fb1107bf6a3ab85b7f
Author:     Alex Richardson <arichardson@FreeBSD.org>
AuthorDate: 2021-03-22 16:54:02 +0000
Commit:     Alex Richardson <arichardson@FreeBSD.org>
CommitDate: 2021-04-22 09:44:52 +0000

    Fix lib/msun/tests/csqrt_test on platforms with 128-bit long double
    
    If long double has more than 64 mantissa bits, using uint64_t to hold the
    mantissa bits will truncate the value and result in test failures. To fix
    this problem use __uint128_t since all platforms that have
    __LDBL_MANT_DIG__ > 64 also have compiler support for 128-bit integers.
    
    Reviewed By:    rlibby
    Differential Revision: https://reviews.freebsd.org/D29076
    
    (cherry picked from commit ce88eb476b86cac63cef7466bd71f14b611ab03a)
---
 lib/msun/tests/csqrt_test.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/lib/msun/tests/csqrt_test.c b/lib/msun/tests/csqrt_test.c
index a46d0ddd45c5..895aec481b60 100644
--- a/lib/msun/tests/csqrt_test.c
+++ b/lib/msun/tests/csqrt_test.c
@@ -257,17 +257,24 @@ test_precision(int maxexp, int mantdig)
 {
 	long double b, x;
 	long double complex result;
-	uint64_t mantbits, sq_mantbits;
+#if LDBL_MANT_DIG <= 64
+	typedef uint64_t ldbl_mant_type;
+#elif LDBL_MANT_DIG <= 128
+	typedef __uint128_t ldbl_mant_type;
+#else
+#error "Unsupported long double format"
+#endif
+	ldbl_mant_type mantbits, sq_mantbits;
 	int exp, i;
 
-	ATF_CHECK(maxexp > 0 && maxexp % 2 == 0);
-	ATF_CHECK(mantdig <= 64);
+	ATF_REQUIRE(maxexp > 0 && maxexp % 2 == 0);
+	ATF_REQUIRE(mantdig <= LDBL_MANT_DIG);
 	mantdig = rounddown(mantdig, 2);
 
 	for (exp = 0; exp <= maxexp; exp += 2) {
-		mantbits = ((uint64_t)1 << (mantdig / 2 )) - 1;
-		for (i = 0;
-		     i < 100 && mantbits > ((uint64_t)1 << (mantdig / 2 - 1));
+		mantbits = ((ldbl_mant_type)1 << (mantdig / 2)) - 1;
+		for (i = 0; i < 100 &&
+		     mantbits > ((ldbl_mant_type)1 << (mantdig / 2 - 1));
 		     i++, mantbits--) {
 			sq_mantbits = mantbits * mantbits;
 			/*
@@ -283,10 +290,10 @@ test_precision(int maxexp, int mantdig)
 			b = ldexpl((long double)sq_mantbits,
 			    exp - 1 - mantdig);
 			x = ldexpl(mantbits, (exp - 2 - mantdig) / 2);
-			ATF_CHECK_EQ(b, x * x * 2);
+			CHECK_FPEQUAL(b, x * x * 2);
 			result = t_csqrt(CMPLXL(0, b));
-			ATF_CHECK_EQ(x, creall(result));
-			ATF_CHECK_EQ(x, cimagl(result));
+			CHECK_FPEQUAL(x, creall(result));
+			CHECK_FPEQUAL(x, cimagl(result));
 		}
 	}
 }
@@ -345,6 +352,7 @@ ATF_TC_BODY(csqrtl, tc)
 
 	test_overflow(LDBL_MAX_EXP);
 
+	/* i386 is configured to use 53-bit rounding precision for long double. */
 	test_precision(LDBL_MAX_EXP,
 #ifndef __i386__
 	    LDBL_MANT_DIG



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