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
This commit is contained in:
Alex Richardson 2021-03-08 09:39:29 +00:00
parent 0b86424c31
commit 221622ec0c
2 changed files with 15 additions and 12 deletions

View File

@ -697,14 +697,15 @@ invln10_hi = 4.3429448176175356e-1, /* 0x1bcb7b15000000.0p-54 */
invln2_hi = 1.4426950402557850e0; /* 0x17154765000000.0p-52 */ invln2_hi = 1.4426950402557850e0; /* 0x17154765000000.0p-52 */
static const long double static const long double
invln10_lo = 1.41498268538580090791605082294397000e-10L, /* 0x137287195355baaafad33dc323ee3.0p-145L */ 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 long double
log10l(long double x) log10l(long double x)
{ {
struct ld r; struct ld r;
long double lo; long double hi, lo;
float hi;
ENTERI(); ENTERI();
DOPRINT_START(&x); DOPRINT_START(&x);
@ -712,18 +713,17 @@ log10l(long double x)
if (!r.lo_set) if (!r.lo_set)
RETURNPI(r.hi); RETURNPI(r.hi);
_2sumF(r.hi, r.lo); _2sumF(r.hi, r.lo);
hi = r.hi; hi = (float)r.hi;
lo = r.lo + (r.hi - hi); lo = r.lo + (r.hi - hi);
RETURN2PI(invln10_hi * hi, RETURN2PI(invln10_hi * hi,
(invln10_lo + invln10_hi) * lo + invln10_lo * hi); invln10_lo_plus_hi * lo + invln10_lo * hi);
} }
long double long double
log2l(long double x) log2l(long double x)
{ {
struct ld r; struct ld r;
long double lo; long double hi, lo;
float hi;
ENTERI(); ENTERI();
DOPRINT_START(&x); DOPRINT_START(&x);
@ -731,10 +731,10 @@ log2l(long double x)
if (!r.lo_set) if (!r.lo_set)
RETURNPI(r.hi); RETURNPI(r.hi);
_2sumF(r.hi, r.lo); _2sumF(r.hi, r.lo);
hi = r.hi; hi = (float)r.hi;
lo = r.lo + (r.hi - hi); lo = r.lo + (r.hi - hi);
RETURN2PI(invln2_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 */ #endif /* STRUCT_RETURN */

View File

@ -677,8 +677,11 @@ logl(long double x)
static const double static const double
invln10_hi = 4.3429448190317999e-1, /* 0x1bcb7b1526e000.0p-54 */ invln10_hi = 4.3429448190317999e-1, /* 0x1bcb7b1526e000.0p-54 */
invln10_lo = 7.1842412889749798e-14, /* 0x1438ca9aadd558.0p-96 */ invln10_lo = 7.1842412889749798e-14, /* 0x1438ca9aadd558.0p-96 */
invln10_lo_plus_hi = invln10_lo + invln10_hi,
invln2_hi = 1.4426950408887933e0, /* 0x171547652b8000.0p-52 */ 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 long double
log10l(long double x) log10l(long double x)
@ -695,7 +698,7 @@ log10l(long double x)
hi = (float)r.hi; hi = (float)r.hi;
lo = r.lo + (r.hi - hi); lo = r.lo + (r.hi - hi);
RETURN2PI(invln10_hi * hi, RETURN2PI(invln10_hi * hi,
(invln10_lo + invln10_hi) * lo + invln10_lo * hi); invln10_lo_plus_hi * lo + invln10_lo * hi);
} }
long double long double
@ -713,7 +716,7 @@ log2l(long double x)
hi = (float)r.hi; hi = (float)r.hi;
lo = r.lo + (r.hi - hi); lo = r.lo + (r.hi - hi);
RETURN2PI(invln2_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 */ #endif /* STRUCT_RETURN */