aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/ieee754
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-04-05 14:49:47 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-12-13 09:02:30 -0300
commit7fe0ace3e289c88cab5014cef94e946fd695221f (patch)
treee632319b2e03c36e85271d8561c9a7b1019de232 /sysdeps/ieee754
parent5afe4c0d6903027bf7835da4711a9f75b750a64d (diff)
downloadglibc-7fe0ace3e289c88cab5014cef94e946fd695221f.zip
glibc-7fe0ace3e289c88cab5014cef94e946fd695221f.tar.gz
glibc-7fe0ace3e289c88cab5014cef94e946fd695221f.tar.bz2
math: Simplify hypotf implementation
Use a more optimized comparison for check for NaN and infinite and add an inlined issignaling implementation for float. With gcc it results in 2 FP comparisons. The file Copyright is also changed to use GPL, the implementation was completely changed by 7c10fd3515f to use double precision instead of scaling and this change removes all the GET_FLOAT_WORD usage. Checked on x86_64-linux-gnu.
Diffstat (limited to 'sysdeps/ieee754')
-rw-r--r--sysdeps/ieee754/flt-32/e_hypotf.c63
-rw-r--r--sysdeps/ieee754/flt-32/math_config.h9
2 files changed, 37 insertions, 35 deletions
diff --git a/sysdeps/ieee754/flt-32/e_hypotf.c b/sysdeps/ieee754/flt-32/e_hypotf.c
index e770947..323cbb0 100644
--- a/sysdeps/ieee754/flt-32/e_hypotf.c
+++ b/sysdeps/ieee754/flt-32/e_hypotf.c
@@ -1,46 +1,39 @@
-/* e_hypotf.c -- float version of e_hypot.c.
- */
+/* Euclidean distance function. Float/Binary32 version.
+ Copyright (C) 2012-2021 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunPro, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice
- * is preserved.
- * ====================================================
- */
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <libm-alias-finite.h>
#include <math.h>
+#include <math-narrow-eval.h>
#include <math_private.h>
-#include <libm-alias-finite.h>
float
-__ieee754_hypotf(float x, float y)
+__ieee754_hypotf (float x, float y)
{
- double d_x, d_y;
- int32_t ha, hb;
-
- GET_FLOAT_WORD(ha,x);
- ha &= 0x7fffffff;
- GET_FLOAT_WORD(hb,y);
- hb &= 0x7fffffff;
- if (ha == 0x7f800000 && !issignaling (y))
- return fabsf(x);
- else if (hb == 0x7f800000 && !issignaling (x))
- return fabsf(y);
- else if (ha > 0x7f800000 || hb > 0x7f800000)
- return fabsf(x) * fabsf(y);
- else if (ha == 0)
- return fabsf(y);
- else if (hb == 0)
- return fabsf(x);
-
- d_x = (double) x;
- d_y = (double) y;
+ if (!isfinite (x) || !isfinite (y))
+ {
+ if ((isinf (x) || isinf (y))
+ && !issignaling (x) && !issignaling (y))
+ return INFINITY;
+ return x + y;
+ }
- return (float) sqrt(d_x * d_x + d_y * d_y);
+ return math_narrow_eval ((float) sqrt ((double) x * (double) x
+ + (double) y * (double) y));
}
#ifndef __ieee754_hypotf
libm_alias_finite (__ieee754_hypotf, __hypotf)
diff --git a/sysdeps/ieee754/flt-32/math_config.h b/sysdeps/ieee754/flt-32/math_config.h
index 513454a..daa8a82 100644
--- a/sysdeps/ieee754/flt-32/math_config.h
+++ b/sysdeps/ieee754/flt-32/math_config.h
@@ -101,6 +101,15 @@ asdouble (uint64_t i)
return u.f;
}
+static inline int
+issignalingf_inline (float x)
+{
+ uint32_t ix = asuint (x);
+ if (HIGH_ORDER_BIT_IS_SET_FOR_SNAN)
+ return (ix & 0x7fc00000) == 0x7fc00000;
+ return 2 * (ix ^ 0x00400000) > 2 * 0x7fc00000UL;
+}
+
#define NOINLINE __attribute__ ((noinline))
attribute_hidden float __math_oflowf (uint32_t);