aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Kargl <kargl@FreeBSD.org>2023-07-31 22:32:54 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2023-08-10 02:57:29 +0000
commit1d488ee57aa193bb10337972c9ced440017806de (patch)
tree74ba1e6ba218f307b92015ad7352f695b9bbe85f
parentfd2b36319c1fee3ac8f914548705cfc0a79011d9 (diff)
downloadsrc-1d488ee57aa193bb10337972c9ced440017806de.tar.gz
src-1d488ee57aa193bb10337972c9ced440017806de.zip
Cleanup debugging code in libm
PR: 272765 (cherry picked from commit c66a499e037efd268a744e487e7d0c45a4944a9b)
-rw-r--r--lib/msun/ld128/s_expl.c28
-rw-r--r--lib/msun/ld128/s_logl.c24
-rw-r--r--lib/msun/ld80/s_expl.c28
-rw-r--r--lib/msun/ld80/s_logl.c26
-rw-r--r--lib/msun/src/math_private.h115
5 files changed, 49 insertions, 172 deletions
diff --git a/lib/msun/ld128/s_expl.c b/lib/msun/ld128/s_expl.c
index 5fc43802b950..0274a8f302db 100644
--- a/lib/msun/ld128/s_expl.c
+++ b/lib/msun/ld128/s_expl.c
@@ -65,8 +65,6 @@ expl(long double x)
int k;
uint16_t hx, ix;
- DOPRINT_START(&x);
-
/* Filter out exceptional cases. */
u.e = x;
hx = u.xbits.expsign;
@@ -74,15 +72,15 @@ expl(long double x)
if (ix >= BIAS + 13) { /* |x| >= 8192 or x is NaN */
if (ix == BIAS + LDBL_MAX_EXP) {
if (hx & 0x8000) /* x is -Inf or -NaN */
- RETURNP(-1 / x);
- RETURNP(x + x); /* x is +Inf or +NaN */
+ RETURNF(-1 / x);
+ RETURNF(x + x); /* x is +Inf or +NaN */
}
if (x > o_threshold)
- RETURNP(huge * huge);
+ RETURNF(huge * huge);
if (x < u_threshold)
- RETURNP(tiny * tiny);
+ RETURNF(tiny * tiny);
} else if (ix < BIAS - 114) { /* |x| < 0x1p-114 */
- RETURN2P(1, x); /* 1 with inexact iff x != 0 */
+ RETURNF(1 + x); /* 1 with inexact iff x != 0 */
}
ENTERI();
@@ -210,8 +208,6 @@ expm1l(long double x)
int k, n, n2;
uint16_t hx, ix;
- DOPRINT_START(&x);
-
/* Filter out exceptional cases. */
u.e = x;
hx = u.xbits.expsign;
@@ -219,11 +215,11 @@ expm1l(long double x)
if (ix >= BIAS + 7) { /* |x| >= 128 or x is NaN */
if (ix == BIAS + LDBL_MAX_EXP) {
if (hx & 0x8000) /* x is -Inf or -NaN */
- RETURNP(-1 / x - 1);
- RETURNP(x + x); /* x is +Inf or +NaN */
+ RETURNF(-1 / x - 1);
+ RETURNF(x + x); /* x is +Inf or +NaN */
}
if (x > o_threshold)
- RETURNP(huge * huge);
+ RETURNF(huge * huge);
/*
* expm1l() never underflows, but it must avoid
* unrepresentable large negative exponents. We used a
@@ -232,7 +228,7 @@ expm1l(long double x)
* in the same way as large ones here.
*/
if (hx & 0x8000) /* x <= -128 */
- RETURN2P(tiny, -1); /* good for x < -114ln2 - eps */
+ RETURNF(tiny - 1); /* good for x < -114ln2 - eps */
}
ENTERI();
@@ -244,7 +240,7 @@ expm1l(long double x)
if (x < T3) {
if (ix < BIAS - 113) { /* |x| < 0x1p-113 */
/* x (rounded) with inexact if x != 0: */
- RETURNPI(x == 0 ? x :
+ RETURNI(x == 0 ? x :
(0x1p200 * x + fabsl(x)) * 0x1p-200);
}
q = x * x2 * C3 + x2 * x2 * (C4 + x * (C5 + x * (C6 +
@@ -265,9 +261,9 @@ expm1l(long double x)
hx2_hi = x_hi * x_hi / 2;
hx2_lo = x_lo * (x + x_hi) / 2;
if (ix >= BIAS - 7)
- RETURN2PI(hx2_hi + x_hi, hx2_lo + x_lo + q);
+ RETURNI((hx2_hi + x_hi) + (hx2_lo + x_lo + q));
else
- RETURN2PI(x, hx2_lo + q + hx2_hi);
+ RETURNI(x + (hx2_lo + q + hx2_hi));
}
/* Reduce x to (k*ln2 + endpoint[n2] + r1 + r2). */
diff --git a/lib/msun/ld128/s_logl.c b/lib/msun/ld128/s_logl.c
index 40a22c0f1a8c..bc538840a760 100644
--- a/lib/msun/ld128/s_logl.c
+++ b/lib/msun/ld128/s_logl.c
@@ -573,24 +573,23 @@ log1pl(long double x)
int i, k;
int16_t ax, hx;
- DOPRINT_START(&x);
EXTRACT_LDBL128_WORDS(hx, lx, llx, x);
if (hx < 0x3fff) { /* x < 1, or x neg NaN */
ax = hx & 0x7fff;
if (ax >= 0x3fff) { /* x <= -1, or x neg NaN */
if (ax == 0x3fff && (lx | llx) == 0)
- RETURNP(-1 / zero); /* log1p(-1) = -Inf */
+ RETURNF(-1 / zero); /* log1p(-1) = -Inf */
/* log1p(x < 1, or x NaN) = qNaN: */
- RETURNP((x - x) / (x - x));
+ RETURNF((x - x) / (x - x));
}
if (ax <= 0x3f8d) { /* |x| < 2**-113 */
if ((int)x == 0)
- RETURNP(x); /* x with inexact if x != 0 */
+ RETURNF(x); /* x with inexact if x != 0 */
}
f_hi = 1;
f_lo = x;
} else if (hx >= 0x7fff) { /* x +Inf or non-neg NaN */
- RETURNP(x + x); /* log1p(Inf or NaN) = Inf or qNaN */
+ RETURNF(x + x); /* log1p(Inf or NaN) = Inf or qNaN */
} else if (hx < 0x40e1) { /* 1 <= x < 2**226 */
f_hi = x;
f_lo = 1;
@@ -669,7 +668,7 @@ log1pl(long double x)
#endif
_3sumF(val_hi, val_lo, F_hi(i) + dk * ln2_hi);
- RETURN2PI(val_hi, val_lo);
+ RETURNI(val_hi + val_lo);
}
#ifdef STRUCT_RETURN
@@ -680,7 +679,6 @@ logl(long double x)
struct ld r;
ENTERI();
- DOPRINT_START(&x);
k_logl(x, &r);
RETURNSPI(&r);
}
@@ -708,15 +706,13 @@ log10l(long double x)
long double hi, lo;
ENTERI();
- DOPRINT_START(&x);
k_logl(x, &r);
if (!r.lo_set)
- RETURNPI(r.hi);
+ RETURNI(r.hi);
_2sumF(r.hi, r.lo);
hi = (float)r.hi;
lo = r.lo + (r.hi - hi);
- RETURN2PI(invln10_hi * hi,
- invln10_lo_plus_hi * lo + invln10_lo * hi);
+ RETURNI(invln10_hi * hi + (invln10_lo_plus_hi * lo + invln10_lo * hi));
}
long double
@@ -726,15 +722,13 @@ log2l(long double x)
long double hi, lo;
ENTERI();
- DOPRINT_START(&x);
k_logl(x, &r);
if (!r.lo_set)
- RETURNPI(r.hi);
+ RETURNI(r.hi);
_2sumF(r.hi, r.lo);
hi = (float)r.hi;
lo = r.lo + (r.hi - hi);
- RETURN2PI(invln2_hi * hi,
- invln2_lo_plus_hi * lo + invln2_lo * hi);
+ RETURNI(invln2_hi * hi + (invln2_lo_plus_hi * lo + invln2_lo * hi));
}
#endif /* STRUCT_RETURN */
diff --git a/lib/msun/ld80/s_expl.c b/lib/msun/ld80/s_expl.c
index 0571377a3f8d..a41de4d6d1d8 100644
--- a/lib/msun/ld80/s_expl.c
+++ b/lib/msun/ld80/s_expl.c
@@ -77,8 +77,6 @@ expl(long double x)
int k;
uint16_t hx, ix;
- DOPRINT_START(&x);
-
/* Filter out exceptional cases. */
u.e = x;
hx = u.xbits.expsign;
@@ -86,15 +84,15 @@ expl(long double x)
if (ix >= BIAS + 13) { /* |x| >= 8192 or x is NaN */
if (ix == BIAS + LDBL_MAX_EXP) {
if (hx & 0x8000) /* x is -Inf, -NaN or unsupported */
- RETURNP(-1 / x);
- RETURNP(x + x); /* x is +Inf, +NaN or unsupported */
+ RETURNF(-1 / x);
+ RETURNF(x + x); /* x is +Inf, +NaN or unsupported */
}
if (x > o_threshold)
- RETURNP(huge * huge);
+ RETURNF(huge * huge);
if (x < u_threshold)
- RETURNP(tiny * tiny);
+ RETURNF(tiny * tiny);
} else if (ix < BIAS - 75) { /* |x| < 0x1p-75 (includes pseudos) */
- RETURN2P(1, x); /* 1 with inexact iff x != 0 */
+ RETURNF(1 + x); /* 1 with inexact iff x != 0 */
}
ENTERI();
@@ -168,8 +166,6 @@ expm1l(long double x)
int k, n, n2;
uint16_t hx, ix;
- DOPRINT_START(&x);
-
/* Filter out exceptional cases. */
u.e = x;
hx = u.xbits.expsign;
@@ -177,11 +173,11 @@ expm1l(long double x)
if (ix >= BIAS + 6) { /* |x| >= 64 or x is NaN */
if (ix == BIAS + LDBL_MAX_EXP) {
if (hx & 0x8000) /* x is -Inf, -NaN or unsupported */
- RETURNP(-1 / x - 1);
- RETURNP(x + x); /* x is +Inf, +NaN or unsupported */
+ RETURNF(-1 / x - 1);
+ RETURNF(x + x); /* x is +Inf, +NaN or unsupported */
}
if (x > o_threshold)
- RETURNP(huge * huge);
+ RETURNF(huge * huge);
/*
* expm1l() never underflows, but it must avoid
* unrepresentable large negative exponents. We used a
@@ -190,7 +186,7 @@ expm1l(long double x)
* in the same way as large ones here.
*/
if (hx & 0x8000) /* x <= -64 */
- RETURN2P(tiny, -1); /* good for x < -65ln2 - eps */
+ RETURNF(tiny - 1); /* good for x < -65ln2 - eps */
}
ENTERI();
@@ -198,7 +194,7 @@ expm1l(long double x)
if (T1 < x && x < T2) {
if (ix < BIAS - 74) { /* |x| < 0x1p-74 (includes pseudos) */
/* x (rounded) with inexact if x != 0: */
- RETURNPI(x == 0 ? x :
+ RETURNI(x == 0 ? x :
(0x1p100 * x + fabsl(x)) * 0x1p-100);
}
@@ -219,9 +215,9 @@ expm1l(long double x)
hx2_hi = x_hi * x_hi / 2;
hx2_lo = x_lo * (x + x_hi) / 2;
if (ix >= BIAS - 7)
- RETURN2PI(hx2_hi + x_hi, hx2_lo + x_lo + q);
+ RETURNI((hx2_hi + x_hi) + (hx2_lo + x_lo + q));
else
- RETURN2PI(x, hx2_lo + q + hx2_hi);
+ RETURNI(x + (hx2_lo + q + hx2_hi));
}
/* Reduce x to (k*ln2 + endpoint[n2] + r1 + r2). */
diff --git a/lib/msun/ld80/s_logl.c b/lib/msun/ld80/s_logl.c
index dac5bfb9e25e..abe778249549 100644
--- a/lib/msun/ld80/s_logl.c
+++ b/lib/msun/ld80/s_logl.c
@@ -560,24 +560,23 @@ log1pl(long double x)
int i, k;
int16_t ax, hx;
- DOPRINT_START(&x);
EXTRACT_LDBL80_WORDS(hx, lx, x);
if (hx < 0x3fff) { /* x < 1, or x neg NaN */
ax = hx & 0x7fff;
if (ax >= 0x3fff) { /* x <= -1, or x neg NaN */
if (ax == 0x3fff && lx == 0x8000000000000000ULL)
- RETURNP(-1 / zero); /* log1p(-1) = -Inf */
+ RETURNF(-1 / zero); /* log1p(-1) = -Inf */
/* log1p(x < 1, or x [pseudo-]NaN) = qNaN: */
- RETURNP((x - x) / (x - x));
+ RETURNF((x - x) / (x - x));
}
if (ax <= 0x3fbe) { /* |x| < 2**-64 */
if ((int)x == 0)
- RETURNP(x); /* x with inexact if x != 0 */
+ RETURNF(x); /* x with inexact if x != 0 */
}
f_hi = 1;
f_lo = x;
} else if (hx >= 0x7fff) { /* x +Inf or non-neg NaN */
- RETURNP(x + x); /* log1p(Inf or NaN) = Inf or qNaN */
+ RETURNF(x + x); /* log1p(Inf or NaN) = Inf or qNaN */
/* log1p(pseudo-Inf) = qNaN */
/* log1p(pseudo-NaN) = qNaN */
/* log1p(unnormal) = qNaN */
@@ -658,7 +657,7 @@ log1pl(long double x)
#endif
_3sumF(val_hi, val_lo, F_hi(i) + dk * ln2_hi);
- RETURN2PI(val_hi, val_lo);
+ RETURNI(val_hi + val_lo);
}
#ifdef STRUCT_RETURN
@@ -669,7 +668,6 @@ logl(long double x)
struct ld r;
ENTERI();
- DOPRINT_START(&x);
k_logl(x, &r);
RETURNSPI(&r);
}
@@ -690,15 +688,14 @@ log10l(long double x)
long double hi, lo;
ENTERI();
- DOPRINT_START(&x);
k_logl(x, &r);
if (!r.lo_set)
- RETURNPI(r.hi);
+ RETURNI(r.hi);
_2sumF(r.hi, r.lo);
hi = (float)r.hi;
lo = r.lo + (r.hi - hi);
- RETURN2PI(invln10_hi * hi,
- invln10_lo_plus_hi * lo + invln10_lo * hi);
+ RETURNI(invln10_hi * hi +
+ (invln10_lo_plus_hi * lo + invln10_lo * hi));
}
long double
@@ -708,15 +705,14 @@ log2l(long double x)
long double hi, lo;
ENTERI();
- DOPRINT_START(&x);
k_logl(x, &r);
if (!r.lo_set)
- RETURNPI(r.hi);
+ RETURNI(r.hi);
_2sumF(r.hi, r.lo);
hi = (float)r.hi;
lo = r.lo + (r.hi - hi);
- RETURN2PI(invln2_hi * hi,
- invln2_lo_plus_hi * lo + invln2_lo * hi);
+ RETURNI(invln2_hi * hi +
+ (invln2_lo_plus_hi * lo + invln2_lo * hi));
}
#endif /* STRUCT_RETURN */
diff --git a/lib/msun/src/math_private.h b/lib/msun/src/math_private.h
index 33f790c13a6b..429b9c70b215 100644
--- a/lib/msun/src/math_private.h
+++ b/lib/msun/src/math_private.h
@@ -698,127 +698,22 @@ irintl(long double x)
#endif
#endif
-/* Write a pari script to test things externally. */
-#ifdef DOPRINT
-#include <stdio.h>
-
-#ifndef DOPRINT_SWIZZLE
-#define DOPRINT_SWIZZLE 0
-#endif
-
-#ifdef DOPRINT_LD80
-
-#define DOPRINT_START(xp) do { \
- uint64_t __lx; \
- uint16_t __hx; \
- \
- /* Hack to give more-problematic args. */ \
- EXTRACT_LDBL80_WORDS(__hx, __lx, *xp); \
- __lx ^= DOPRINT_SWIZZLE; \
- INSERT_LDBL80_WORDS(*xp, __hx, __lx); \
- printf("x = %.21Lg; ", (long double)*xp); \
-} while (0)
-#define DOPRINT_END1(v) \
- printf("y = %.21Lg; z = 0; show(x, y, z);\n", (long double)(v))
-#define DOPRINT_END2(hi, lo) \
- printf("y = %.21Lg; z = %.21Lg; show(x, y, z);\n", \
- (long double)(hi), (long double)(lo))
-
-#elif defined(DOPRINT_D64)
-
-#define DOPRINT_START(xp) do { \
- uint32_t __hx, __lx; \
- \
- EXTRACT_WORDS(__hx, __lx, *xp); \
- __lx ^= DOPRINT_SWIZZLE; \
- INSERT_WORDS(*xp, __hx, __lx); \
- printf("x = %.21Lg; ", (long double)*xp); \
-} while (0)
-#define DOPRINT_END1(v) \
- printf("y = %.21Lg; z = 0; show(x, y, z);\n", (long double)(v))
-#define DOPRINT_END2(hi, lo) \
- printf("y = %.21Lg; z = %.21Lg; show(x, y, z);\n", \
- (long double)(hi), (long double)(lo))
-
-#elif defined(DOPRINT_F32)
-
-#define DOPRINT_START(xp) do { \
- uint32_t __hx; \
- \
- GET_FLOAT_WORD(__hx, *xp); \
- __hx ^= DOPRINT_SWIZZLE; \
- SET_FLOAT_WORD(*xp, __hx); \
- printf("x = %.21Lg; ", (long double)*xp); \
-} while (0)
-#define DOPRINT_END1(v) \
- printf("y = %.21Lg; z = 0; show(x, y, z);\n", (long double)(v))
-#define DOPRINT_END2(hi, lo) \
- printf("y = %.21Lg; z = %.21Lg; show(x, y, z);\n", \
- (long double)(hi), (long double)(lo))
-
-#else /* !DOPRINT_LD80 && !DOPRINT_D64 (LD128 only) */
-
-#ifndef DOPRINT_SWIZZLE_HIGH
-#define DOPRINT_SWIZZLE_HIGH 0
-#endif
-
-#define DOPRINT_START(xp) do { \
- uint64_t __lx, __llx; \
- uint16_t __hx; \
- \
- EXTRACT_LDBL128_WORDS(__hx, __lx, __llx, *xp); \
- __llx ^= DOPRINT_SWIZZLE; \
- __lx ^= DOPRINT_SWIZZLE_HIGH; \
- INSERT_LDBL128_WORDS(*xp, __hx, __lx, __llx); \
- printf("x = %.36Lg; ", (long double)*xp); \
-} while (0)
-#define DOPRINT_END1(v) \
- printf("y = %.36Lg; z = 0; show(x, y, z);\n", (long double)(v))
-#define DOPRINT_END2(hi, lo) \
- printf("y = %.36Lg; z = %.36Lg; show(x, y, z);\n", \
- (long double)(hi), (long double)(lo))
-
-#endif /* DOPRINT_LD80 */
-
-#else /* !DOPRINT */
-#define DOPRINT_START(xp)
-#define DOPRINT_END1(v)
-#define DOPRINT_END2(hi, lo)
-#endif /* DOPRINT */
-
-#define RETURNP(x) do { \
- DOPRINT_END1(x); \
- RETURNF(x); \
-} while (0)
-#define RETURNPI(x) do { \
- DOPRINT_END1(x); \
- RETURNI(x); \
-} while (0)
-#define RETURN2P(x, y) do { \
- DOPRINT_END2((x), (y)); \
- RETURNF((x) + (y)); \
-} while (0)
-#define RETURN2PI(x, y) do { \
- DOPRINT_END2((x), (y)); \
- RETURNI((x) + (y)); \
-} while (0)
#ifdef STRUCT_RETURN
#define RETURNSP(rp) do { \
if (!(rp)->lo_set) \
- RETURNP((rp)->hi); \
- RETURN2P((rp)->hi, (rp)->lo); \
+ RETURNF((rp)->hi); \
+ RETURNF((rp)->hi + (rp)->lo); \
} while (0)
#define RETURNSPI(rp) do { \
if (!(rp)->lo_set) \
- RETURNPI((rp)->hi); \
- RETURN2PI((rp)->hi, (rp)->lo); \
+ RETURNI((rp)->hi); \
+ RETURNI((rp)->hi + (rp)->lo); \
} while (0)
#endif
+
#define SUM2P(x, y) ({ \
const __typeof (x) __x = (x); \
const __typeof (y) __y = (y); \
- \
- DOPRINT_END2(__x, __y); \
__x + __y; \
})