aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/powerpc
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2016-12-07 01:16:36 +0000
committerJoseph Myers <joseph@codesourcery.com>2016-12-07 01:16:36 +0000
commit58307649fb51a3a6adc29a8659d3301393f24671 (patch)
tree2594a547d195e7f2231fcfaec9fa5fdaa2d70df4 /sysdeps/powerpc
parenta91fd168a0db38563528dab1a13180fda2a5040c (diff)
downloadglibc-58307649fb51a3a6adc29a8659d3301393f24671.zip
glibc-58307649fb51a3a6adc29a8659d3301393f24671.tar.gz
glibc-58307649fb51a3a6adc29a8659d3301393f24671.tar.bz2
Fix hypot sNaN handling (bug 20940).
TS 18661-1 generally defines libm functions taking sNaN arguments to return qNaN and raise "invalid", even for the cases where a corresponding qNaN argument would not result in a qNaN return. This includes hypot with one argument being an infinity and the other being an sNaN. This patch duly fixes hypot implementatations in glibc (generic and powerpc) to ensure qNaN, computed by arithmetic on the arguments, is returned in that case. Various implementations do their checks for infinities and NaNs inline by manipulating the representations of the arguments. For simplicity, this patch just uses issignaling to check for sNaN arguments. This could be inlined like the existing code (with due care about reversed quiet NaN conventions, for implementations where that is relevant), but given that all these checks are in cases where it's already known at least one argument is not finite, which should be the uncommon case, that doesn't seem worthwhile unless performance issues are observed in practice. Tested for x86_64, x86, mips64 and powerpc. [BZ #20940] * sysdeps/ieee754/dbl-64/e_hypot.c (__ieee754_hypot): Do not return Inf for arguments Inf and sNaN. * sysdeps/ieee754/flt-32/e_hypotf.c (__ieee754_hypotf): Likewise. * sysdeps/ieee754/ldbl-128/e_hypotl.c (__ieee754_hypotl): Likewise. * sysdeps/ieee754/ldbl-128ibm/e_hypotl.c (__ieee754_hypotl): Likewise. * sysdeps/ieee754/ldbl-96/e_hypotl.c (__ieee754_hypotl): Likewise. * sysdeps/powerpc/fpu/e_hypot.c (TEST_INF_NAN): Do not return Inf for arguments Inf and sNaN. When returning a NaN, compute it by arithmetic on the arguments. * sysdeps/powerpc/fpu/e_hypotf.c (TEST_INF_NAN): Likewise. * math/libm-test.inc (pow_test_data): Add tests of sNaN arguments.
Diffstat (limited to 'sysdeps/powerpc')
-rw-r--r--sysdeps/powerpc/fpu/e_hypot.c10
-rw-r--r--sysdeps/powerpc/fpu/e_hypotf.c10
2 files changed, 12 insertions, 8 deletions
diff --git a/sysdeps/powerpc/fpu/e_hypot.c b/sysdeps/powerpc/fpu/e_hypot.c
index da0f2da..65314c6 100644
--- a/sysdeps/powerpc/fpu/e_hypot.c
+++ b/sysdeps/powerpc/fpu/e_hypot.c
@@ -41,10 +41,11 @@ static const double pdnum = 2.225073858507201e-308;
#ifdef _ARCH_PWR7
/* POWER7 isinf and isnan optimization are fast. */
# define TEST_INF_NAN(x, y) \
- if (isinf(x) || isinf(y)) \
+ if ((isinf(x) || isinf(y)) \
+ && !issignaling (x) && !issignaling (y)) \
return INFINITY; \
if (isnan(x) || isnan(y)) \
- return NAN;
+ return x + y;
# else
/* For POWER6 and below isinf/isnan triggers LHS and PLT calls are
* costly (especially for POWER6). */
@@ -66,9 +67,10 @@ static const double pdnum = 2.225073858507201e-308;
uint32_t ht = hx; hx = hy; hy = ht; \
} \
if (hx >= 0x7ff00000) { \
- if (hx == 0x7ff00000 || hy == 0x7ff00000) \
+ if ((hx == 0x7ff00000 || hy == 0x7ff00000) \
+ && !issignaling (x) && !issignaling (y)) \
return INFINITY; \
- return NAN; \
+ return x + y; \
} \
} while (0)
diff --git a/sysdeps/powerpc/fpu/e_hypotf.c b/sysdeps/powerpc/fpu/e_hypotf.c
index 4836082..c182815 100644
--- a/sysdeps/powerpc/fpu/e_hypotf.c
+++ b/sysdeps/powerpc/fpu/e_hypotf.c
@@ -31,10 +31,11 @@
#ifdef _ARCH_PWR7
/* POWER7 isinf and isnan optimizations are fast. */
# define TEST_INF_NAN(x, y) \
- if (isinff(x) || isinff(y)) \
+ if ((isinff(x) || isinff(y)) \
+ && !issignaling (x) && !issignaling (y)) \
return INFINITY; \
if (isnanf(x) || isnanf(y)) \
- return NAN;
+ return x + y;
# else
/* For POWER6 and below isinf/isnan triggers LHS and PLT calls are
* costly (especially for POWER6). */
@@ -56,9 +57,10 @@
uint32_t ht = hx; hx = hy; hy = ht; \
} \
if (hx >= 0x7f800000) { \
- if (hx == 0x7f800000 || hy == 0x7f800000) \
+ if ((hx == 0x7f800000 || hy == 0x7f800000) \
+ && !issignaling (x) && !issignaling (y)) \
return INFINITY; \
- return NAN; \
+ return x + y; \
} \
} while (0)
#endif