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.
This commit is contained in:
Adhemerval Zanella 2021-04-06 14:33:14 -03:00
parent 2f44eef584
commit 104d2005d5
36 changed files with 132 additions and 16 deletions

View File

@ -628,5 +628,7 @@ libm {
fminimum_numf64x; fminimum_numf128; fminimum_numf64x; fminimum_numf128;
fminimum_magf64x; fminimum_magf128; fminimum_magf64x; fminimum_magf128;
fminimum_mag_numf64x; fminimum_mag_numf128; fminimum_mag_numf64x; fminimum_mag_numf128;
# No SVID compatible error handling.
hypotf; hypot;
} }
} }

8
math/w_hypot.c Normal file
View File

@ -0,0 +1,8 @@
#include <math-type-macros-float.h>
#undef __USE_WRAPPER_TEMPLATE
#define __USE_WRAPPER_TEMPLATE 1
#undef declare_mgen_alias
#define declare_mgen_alias(a, b)
#include <w_hypot_template.c>
versioned_symbol (libm, __hypot, hypot, GLIBC_2_35);
libm_alias_float_other (__hypot, hypot)

View File

@ -20,9 +20,9 @@
#include <libm-alias-double.h> #include <libm-alias-double.h>
#if LIBM_SVID_COMPAT #if LIBM_SVID_COMPAT && SHLIB_COMPAT (libm, GLIBC_2_0, GLIBC_2_35)
double double
__hypot (double x, double y) __hypot_compat (double x, double y)
{ {
double z = __ieee754_hypot(x,y); double z = __ieee754_hypot(x,y);
if(__builtin_expect(!isfinite(z), 0) if(__builtin_expect(!isfinite(z), 0)
@ -31,5 +31,12 @@ __hypot (double x, double y)
return z; return z;
} }
libm_alias_double (__hypot, hypot) compat_symbol (libm, __hypot_compat, hypot, GLIBC_2_0);
# ifdef NO_LONG_DOUBLE
weak_alias (__hypot_compat, hypotl)
# endif
# ifdef LONG_DOUBLE_COMPAT
LONG_DOUBLE_COMPAT_CHOOSE_libm_hypotl (
compat_symbol (libm, __hypot_compat, hypotl, FIRST_VERSION_libm_hypotl), );
# endif
#endif #endif

8
math/w_hypotf.c Normal file
View File

@ -0,0 +1,8 @@
#include <math-type-macros-float.h>
#undef __USE_WRAPPER_TEMPLATE
#define __USE_WRAPPER_TEMPLATE 1
#undef declare_mgen_alias
#define declare_mgen_alias(a, b)
#include <w_hypot_template.c>
versioned_symbol (libm, __hypotf, hypotf, GLIBC_2_35);
libm_alias_float_other (__hypotf, hypotf)

View File

@ -22,9 +22,9 @@
#include <libm-alias-float.h> #include <libm-alias-float.h>
#if LIBM_SVID_COMPAT #if LIBM_SVID_COMPAT && SHLIB_COMPAT (libm, GLIBC_2_0, GLIBC_2_35)
float float
__hypotf(float x, float y) __hypotf_compat (float x, float y)
{ {
float z = __ieee754_hypotf(x,y); float z = __ieee754_hypotf(x,y);
if(__builtin_expect(!isfinite(z), 0) if(__builtin_expect(!isfinite(z), 0)
@ -34,5 +34,5 @@ __hypotf(float x, float y)
return z; return z;
} }
libm_alias_float (__hypot, hypot) compat_symbol (libm, __hypotf_compat, hypotf, GLIBC_2_0);
#endif #endif

View File

@ -29,7 +29,7 @@
hypot implementation, since internal multiplication and sqrt is carried hypot implementation, since internal multiplication and sqrt is carried
with 80-bit FP type. */ with 80-bit FP type. */
double double
__ieee754_hypot (double x, double y) __hypot (double x, double y)
{ {
if (!isfinite (x) || !isfinite (y)) if (!isfinite (x) || !isfinite (y))
{ {
@ -43,6 +43,15 @@ __ieee754_hypot (double x, double y)
long double ly = y; long double ly = y;
double r = math_narrow_eval ((double) sqrtl (lx * lx + ly * ly)); double r = math_narrow_eval ((double) sqrtl (lx * lx + ly * ly));
math_check_force_underflow_nonneg (r); math_check_force_underflow_nonneg (r);
if (isinf (r))
__set_errno (ERANGE);
return r; return r;
} }
strong_alias (__hypot, __ieee754_hypot)
#if LIBM_SVID_COMPAT
versioned_symbol (libm, __hypot, hypot, GLIBC_2_35);
libm_alias_finite (__ieee754_hypot, __hypot) libm_alias_finite (__ieee754_hypot, __hypot)
libm_alias_double_other (__hypot, hypot)
#else
libm_alias_double (__hypot, hypot)
#endif

View File

@ -34,12 +34,15 @@
[1] https://arxiv.org/pdf/1904.09481.pdf */ [1] https://arxiv.org/pdf/1904.09481.pdf */
#include <errno.h>
#include <math.h> #include <math.h>
#include <math_private.h> #include <math_private.h>
#include <math-underflow.h> #include <math-underflow.h>
#include <math-narrow-eval.h> #include <math-narrow-eval.h>
#include <math-use-builtins.h> #include <math-use-builtins.h>
#include <math-svid-compat.h>
#include <libm-alias-finite.h> #include <libm-alias-finite.h>
#include <libm-alias-double.h>
#include "math_config.h" #include "math_config.h"
#define SCALE 0x1p-600 #define SCALE 0x1p-600
@ -47,6 +50,14 @@
#define TINY_VAL 0x1p-459 #define TINY_VAL 0x1p-459
#define EPS 0x1p-54 #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 /* Hypot kernel. The inputs must be adjusted so that ax >= ay >= 0
and squaring ax, ay and (ax - ay) does not overflow or underflow. */ and squaring ax, ay and (ax - ay) does not overflow or underflow. */
static inline double static inline double
@ -83,7 +94,7 @@ kernel (double ax, double ay)
} }
double double
__ieee754_hypot (double x, double y) __hypot (double x, double y)
{ {
if (!isfinite(x) || !isfinite(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 (ax > LARGE_VAL))
{ {
if (__glibc_unlikely (ay <= ax * EPS)) 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. */ /* If ay is tiny, scale both inputs up. */
@ -125,6 +137,11 @@ __ieee754_hypot (double x, double y)
return kernel (ax, ay); return kernel (ax, ay);
} }
#ifndef __ieee754_hypot strong_alias (__hypot, __ieee754_hypot)
libm_alias_finite (__ieee754_hypot, __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 #endif

View File

@ -0,0 +1 @@
/* Not needed. */

View File

@ -16,13 +16,16 @@
License along with the GNU C Library; if not, see License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */ <https://www.gnu.org/licenses/>. */
#include <errno.h>
#include <libm-alias-finite.h> #include <libm-alias-finite.h>
#include <libm-alias-float.h>
#include <math-svid-compat.h>
#include <math.h> #include <math.h>
#include <math-narrow-eval.h> #include <math-narrow-eval.h>
#include <math_private.h> #include <math_private.h>
float float
__ieee754_hypotf (float x, float y) __hypotf (float x, float y)
{ {
if (!isfinite (x) || !isfinite (y)) if (!isfinite (x) || !isfinite (y))
{ {
@ -32,9 +35,17 @@ __ieee754_hypotf (float x, float y)
return x + y; return x + y;
} }
return math_narrow_eval ((float) sqrt ((double) x * (double) x float r = math_narrow_eval ((float) sqrt ((double) x * (double) x
+ (double) y * (double) y)); + (double) y * (double) y));
if (!isfinite (r))
__set_errno (ERANGE);
return r;
} }
#ifndef __ieee754_hypotf strong_alias (__hypotf, __ieee754_hypotf)
libm_alias_finite (__ieee754_hypotf, __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 #endif
libm_alias_finite (__ieee754_hypotf, __hypotf)

View File

@ -0,0 +1 @@
/* Not needed. */

View File

@ -1179,3 +1179,5 @@ GLIBC_2.35 fminimumf64x F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F

View File

@ -1144,3 +1144,5 @@ GLIBC_2.35 fminimumf64x F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F

View File

@ -1201,6 +1201,8 @@ GLIBC_2.35 fminimumf64x F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F
GLIBC_2.4 __clog10l F GLIBC_2.4 __clog10l F
GLIBC_2.4 __finitel F GLIBC_2.4 __finitel F
GLIBC_2.4 __fpclassifyl F GLIBC_2.4 __fpclassifyl F

View File

@ -531,6 +531,8 @@ GLIBC_2.35 fminimumf64 F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F
GLIBC_2.4 _LIB_VERSION D 0x4 GLIBC_2.4 _LIB_VERSION D 0x4
GLIBC_2.4 __clog10 F GLIBC_2.4 __clog10 F
GLIBC_2.4 __clog10f F GLIBC_2.4 __clog10f F

View File

@ -531,6 +531,8 @@ GLIBC_2.35 fminimumf64 F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F
GLIBC_2.4 _LIB_VERSION D 0x4 GLIBC_2.4 _LIB_VERSION D 0x4
GLIBC_2.4 __clog10 F GLIBC_2.4 __clog10 F
GLIBC_2.4 __clog10f F GLIBC_2.4 __clog10f F

View File

@ -842,4 +842,6 @@ GLIBC_2.35 fminimumf64 F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F
GLIBC_2.4 exp2l F GLIBC_2.4 exp2l F

View File

@ -1186,3 +1186,5 @@ GLIBC_2.35 fminimumf64x F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F

View File

@ -531,6 +531,8 @@ GLIBC_2.35 fminimumf64 F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F
GLIBC_2.4 _LIB_VERSION D 0x4 GLIBC_2.4 _LIB_VERSION D 0x4
GLIBC_2.4 __clog10 F GLIBC_2.4 __clog10 F
GLIBC_2.4 __clog10f F GLIBC_2.4 __clog10f F

View File

@ -882,3 +882,5 @@ GLIBC_2.35 fminimumf64 F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F

View File

@ -843,3 +843,5 @@ GLIBC_2.35 fminimumf64 F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F

View File

@ -843,3 +843,5 @@ GLIBC_2.35 fminimumf64 F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F

View File

@ -842,4 +842,6 @@ GLIBC_2.35 fminimumf64 F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F
GLIBC_2.4 exp2l F GLIBC_2.4 exp2l F

View File

@ -1144,3 +1144,5 @@ GLIBC_2.35 fminimumf64x F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F

View File

@ -843,3 +843,5 @@ GLIBC_2.35 fminimumf64 F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F

View File

@ -888,6 +888,8 @@ GLIBC_2.35 fminimumf64 F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F
GLIBC_2.4 __clog10l F GLIBC_2.4 __clog10l F
GLIBC_2.4 __finitel F GLIBC_2.4 __finitel F
GLIBC_2.4 __fpclassifyl F GLIBC_2.4 __fpclassifyl F

View File

@ -887,6 +887,8 @@ GLIBC_2.35 fminimumf64 F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F
GLIBC_2.4 __clog10l F GLIBC_2.4 __clog10l F
GLIBC_2.4 __finitel F GLIBC_2.4 __finitel F
GLIBC_2.4 __fpclassifyl F GLIBC_2.4 __fpclassifyl F

View File

@ -881,6 +881,8 @@ GLIBC_2.35 fminimumf64 F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F
GLIBC_2.4 __clog10l F GLIBC_2.4 __clog10l F
GLIBC_2.4 __finitel F GLIBC_2.4 __finitel F
GLIBC_2.4 __fpclassifyl F GLIBC_2.4 __fpclassifyl F

View File

@ -1316,3 +1316,5 @@ GLIBC_2.35 fminimumf64x F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F

View File

@ -1145,6 +1145,8 @@ GLIBC_2.35 fminimumf64x F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F
GLIBC_2.4 __clog10l F GLIBC_2.4 __clog10l F
GLIBC_2.4 __finitel F GLIBC_2.4 __finitel F
GLIBC_2.4 __fpclassifyl F GLIBC_2.4 __fpclassifyl F

View File

@ -1145,6 +1145,8 @@ GLIBC_2.35 fminimumf64x F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F
GLIBC_2.4 __clog10l F GLIBC_2.4 __clog10l F
GLIBC_2.4 __finitel F GLIBC_2.4 __finitel F
GLIBC_2.4 __fpclassifyl F GLIBC_2.4 __fpclassifyl F

View File

@ -842,4 +842,6 @@ GLIBC_2.35 fminimumf64 F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F
GLIBC_2.4 exp2l F GLIBC_2.4 exp2l F

View File

@ -842,4 +842,6 @@ GLIBC_2.35 fminimumf64 F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F
GLIBC_2.4 exp2l F GLIBC_2.4 exp2l F

View File

@ -1152,6 +1152,8 @@ GLIBC_2.35 fminimumf64x F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F
GLIBC_2.4 __clog10l F GLIBC_2.4 __clog10l F
GLIBC_2.4 __finitel F GLIBC_2.4 __finitel F
GLIBC_2.4 __fpclassifyl F GLIBC_2.4 __fpclassifyl F

View File

@ -1144,3 +1144,5 @@ GLIBC_2.35 fminimumf64x F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F

View File

@ -1177,3 +1177,5 @@ GLIBC_2.35 fminimumf64x F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F

View File

@ -1177,3 +1177,5 @@ GLIBC_2.35 fminimumf64x F
GLIBC_2.35 fminimuml F GLIBC_2.35 fminimuml F
GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrt F
GLIBC_2.35 fsqrtl F GLIBC_2.35 fsqrtl F
GLIBC_2.35 hypot F
GLIBC_2.35 hypotf F