From 104d2005d5b7fb13a970905ca3f4a7e7e783cf1a Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Tue, 6 Apr 2021 14:33:14 -0300 Subject: math: Remove the error handling wrapper from hypot and hypotf The error handling is moved to sysdeps/ieee754 version with no SVID support. The compatibility symbol versions still use the wrapper with SVID error handling around the new code. There is no new symbol version nor compatibility code on !LIBM_SVID_COMPAT targets (e.g. riscv). Only ia64 is unchanged, since it still uses the arch specific __libm_error_region on its implementation. Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. --- sysdeps/ieee754/dbl-64/e_hypot.c | 25 +++++++++++++++++++++---- sysdeps/ieee754/dbl-64/w_hypot.c | 1 + sysdeps/ieee754/flt-32/e_hypotf.c | 21 ++++++++++++++++----- sysdeps/ieee754/flt-32/w_hypotf.c | 1 + 4 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 sysdeps/ieee754/dbl-64/w_hypot.c create mode 100644 sysdeps/ieee754/flt-32/w_hypotf.c (limited to 'sysdeps/ieee754') diff --git a/sysdeps/ieee754/dbl-64/e_hypot.c b/sysdeps/ieee754/dbl-64/e_hypot.c index 0bdab989e4..a822ec2065 100644 --- a/sysdeps/ieee754/dbl-64/e_hypot.c +++ b/sysdeps/ieee754/dbl-64/e_hypot.c @@ -34,12 +34,15 @@ [1] https://arxiv.org/pdf/1904.09481.pdf */ +#include #include #include #include #include #include +#include #include +#include #include "math_config.h" #define SCALE 0x1p-600 @@ -47,6 +50,14 @@ #define TINY_VAL 0x1p-459 #define EPS 0x1p-54 +static inline double +handle_errno (double r) +{ + if (isinf (r)) + __set_errno (ERANGE); + return r; +} + /* Hypot kernel. The inputs must be adjusted so that ax >= ay >= 0 and squaring ax, ay and (ax - ay) does not overflow or underflow. */ static inline double @@ -83,7 +94,7 @@ kernel (double ax, double ay) } double -__ieee754_hypot (double x, double y) +__hypot (double x, double y) { if (!isfinite(x) || !isfinite(y)) { @@ -103,9 +114,10 @@ __ieee754_hypot (double x, double y) if (__glibc_unlikely (ax > LARGE_VAL)) { if (__glibc_unlikely (ay <= ax * EPS)) - return math_narrow_eval (ax + ay); + return handle_errno (math_narrow_eval (ax + ay)); - return math_narrow_eval (kernel (ax * SCALE, ay * SCALE) / SCALE); + return handle_errno (math_narrow_eval (kernel (ax * SCALE, ay * SCALE) + / SCALE)); } /* If ay is tiny, scale both inputs up. */ @@ -125,6 +137,11 @@ __ieee754_hypot (double x, double y) return kernel (ax, ay); } -#ifndef __ieee754_hypot +strong_alias (__hypot, __ieee754_hypot) libm_alias_finite (__ieee754_hypot, __hypot) +#if LIBM_SVID_COMPAT +versioned_symbol (libm, __hypot, hypot, GLIBC_2_35); +libm_alias_double_other (__hypot, hypot) +#else +libm_alias_double (__hypot, hypot) #endif diff --git a/sysdeps/ieee754/dbl-64/w_hypot.c b/sysdeps/ieee754/dbl-64/w_hypot.c new file mode 100644 index 0000000000..1cc8931700 --- /dev/null +++ b/sysdeps/ieee754/dbl-64/w_hypot.c @@ -0,0 +1 @@ +/* Not needed. */ diff --git a/sysdeps/ieee754/flt-32/e_hypotf.c b/sysdeps/ieee754/flt-32/e_hypotf.c index 323cbb0cd0..1d79d35797 100644 --- a/sysdeps/ieee754/flt-32/e_hypotf.c +++ b/sysdeps/ieee754/flt-32/e_hypotf.c @@ -16,13 +16,16 @@ License along with the GNU C Library; if not, see . */ +#include #include +#include +#include #include #include #include float -__ieee754_hypotf (float x, float y) +__hypotf (float x, float y) { if (!isfinite (x) || !isfinite (y)) { @@ -32,9 +35,17 @@ __ieee754_hypotf (float x, float y) return x + y; } - return math_narrow_eval ((float) sqrt ((double) x * (double) x - + (double) y * (double) y)); + float r = math_narrow_eval ((float) sqrt ((double) x * (double) x + + (double) y * (double) y)); + if (!isfinite (r)) + __set_errno (ERANGE); + return r; } -#ifndef __ieee754_hypotf -libm_alias_finite (__ieee754_hypotf, __hypotf) +strong_alias (__hypotf, __ieee754_hypotf) +#if LIBM_SVID_COMPAT +versioned_symbol (libm, __hypotf, hypotf, GLIBC_2_35); +libm_alias_float_other (__hypot, hypot) +#else +libm_alias_float (__hypot, hypot) #endif +libm_alias_finite (__ieee754_hypotf, __hypotf) diff --git a/sysdeps/ieee754/flt-32/w_hypotf.c b/sysdeps/ieee754/flt-32/w_hypotf.c new file mode 100644 index 0000000000..1cc8931700 --- /dev/null +++ b/sysdeps/ieee754/flt-32/w_hypotf.c @@ -0,0 +1 @@ +/* Not needed. */ -- cgit 1.4.1