Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 8 Mar 2021 09:44:09 GMT
From:      Alex Richardson <arichardson@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 221622ec0c8e - main - lib/msun: Avoid FE_INEXACT for x86 log2l/log10l
Message-ID:  <202103080944.1289i9R8024248@gitrepo.freebsd.org>

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

URL: https://cgit.FreeBSD.org/src/commit/?id=221622ec0c8e184dd1ea7e1f77fb45d2d32cb6e2

commit 221622ec0c8e184dd1ea7e1f77fb45d2d32cb6e2
Author:     Alex Richardson <arichardson@FreeBSD.org>
AuthorDate: 2021-03-08 09:39:29 +0000
Commit:     Alex Richardson <arichardson@FreeBSD.org>
CommitDate: 2021-03-08 09:39:32 +0000

    lib/msun: Avoid FE_INEXACT for x86 log2l/log10l
    
    This fixes tests/lib/msun/logarithm_test after compiling the test with
    -fno-builtin (D28577). Adding invln10_lo + invln10_10 results in
    FE_INEXACT (for all inputs) and the same for the log2l invln2_lo + invln2_hi.
    This patch avoids FE_INEXACT (for exact results such as 0) by defining a
    constant and using that.
    
    Reviewed By:    dim
    Differential Revision: https://reviews.freebsd.org/D28786
---
 lib/msun/ld128/s_logl.c | 18 +++++++++---------
 lib/msun/ld80/s_logl.c  |  9 ++++++---
 2 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/lib/msun/ld128/s_logl.c b/lib/msun/ld128/s_logl.c
index 93a2a7c35ff5..4774a271e7ad 100644
--- a/lib/msun/ld128/s_logl.c
+++ b/lib/msun/ld128/s_logl.c
@@ -697,14 +697,15 @@ invln10_hi =  4.3429448176175356e-1,		/*  0x1bcb7b15000000.0p-54 */
 invln2_hi =  1.4426950402557850e0;		/*  0x17154765000000.0p-52 */
 static const long double
 invln10_lo =  1.41498268538580090791605082294397000e-10L,	/*  0x137287195355baaafad33dc323ee3.0p-145L */
-invln2_lo =  6.33178418956604368501892137426645911e-10L;	/*  0x15c17f0bbbe87fed0691d3e88eb57.0p-143L */
+invln2_lo =  6.33178418956604368501892137426645911e-10L,	/*  0x15c17f0bbbe87fed0691d3e88eb57.0p-143L */
+invln10_lo_plus_hi = invln10_lo + invln10_hi,
+invln2_lo_plus_hi = invln2_lo + invln2_hi;
 
 long double
 log10l(long double x)
 {
 	struct ld r;
-	long double lo;
-	float hi;
+	long double hi, lo;
 
 	ENTERI();
 	DOPRINT_START(&x);
@@ -712,18 +713,17 @@ log10l(long double x)
 	if (!r.lo_set)
 		RETURNPI(r.hi);
 	_2sumF(r.hi, r.lo);
-	hi = r.hi;
+	hi = (float)r.hi;
 	lo = r.lo + (r.hi - hi);
 	RETURN2PI(invln10_hi * hi,
-	    (invln10_lo + invln10_hi) * lo + invln10_lo * hi);
+	    invln10_lo_plus_hi * lo + invln10_lo * hi);
 }
 
 long double
 log2l(long double x)
 {
 	struct ld r;
-	long double lo;
-	float hi;
+	long double hi, lo;
 
 	ENTERI();
 	DOPRINT_START(&x);
@@ -731,10 +731,10 @@ log2l(long double x)
 	if (!r.lo_set)
 		RETURNPI(r.hi);
 	_2sumF(r.hi, r.lo);
-	hi = r.hi;
+	hi = (float)r.hi;
 	lo = r.lo + (r.hi - hi);
 	RETURN2PI(invln2_hi * hi,
-	    (invln2_lo + invln2_hi) * lo + invln2_lo * hi);
+	    invln2_lo_plus_hi * lo + invln2_lo * hi);
 }
 
 #endif /* STRUCT_RETURN */
diff --git a/lib/msun/ld80/s_logl.c b/lib/msun/ld80/s_logl.c
index 0a220f2a2403..d787b953fedb 100644
--- a/lib/msun/ld80/s_logl.c
+++ b/lib/msun/ld80/s_logl.c
@@ -677,8 +677,11 @@ logl(long double x)
 static const double
 invln10_hi =  4.3429448190317999e-1,		/*  0x1bcb7b1526e000.0p-54 */
 invln10_lo =  7.1842412889749798e-14,		/*  0x1438ca9aadd558.0p-96 */
+invln10_lo_plus_hi = invln10_lo + invln10_hi,
 invln2_hi =  1.4426950408887933e0,		/*  0x171547652b8000.0p-52 */
-invln2_lo =  1.7010652264631490e-13;		/*  0x17f0bbbe87fed0.0p-95 */
+invln2_lo =  1.7010652264631490e-13,		/*  0x17f0bbbe87fed0.0p-95 */
+invln2_lo_plus_hi = invln2_lo + invln2_hi;
+
 
 long double
 log10l(long double x)
@@ -695,7 +698,7 @@ log10l(long double x)
 	hi = (float)r.hi;
 	lo = r.lo + (r.hi - hi);
 	RETURN2PI(invln10_hi * hi,
-	    (invln10_lo + invln10_hi) * lo + invln10_lo * hi);
+	    invln10_lo_plus_hi * lo + invln10_lo * hi);
 }
 
 long double
@@ -713,7 +716,7 @@ log2l(long double x)
 	hi = (float)r.hi;
 	lo = r.lo + (r.hi - hi);
 	RETURN2PI(invln2_hi * hi,
-	    (invln2_lo + invln2_hi) * lo + invln2_lo * hi);
+	    invln2_lo_plus_hi * lo + invln2_lo * hi);
 }
 
 #endif /* STRUCT_RETURN */



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