Define and use libm_alias_float128.
[glibc.git] / sysdeps / powerpc / fpu / e_hypotf.c
blob8502ca962a307d94dea6e693d50b1eadee11e76c
1 /* Pythagorean addition using floats
2 Copyright (C) 2011-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Adhemerval Zanella <azanella@br.ibm.com>, 2011
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If
18 not, see <http://www.gnu.org/licenses/>. */
20 #include <math.h>
21 #include <math_private.h>
22 #include <stdint.h>
24 /* __ieee754_hypotf(x,y)
26 This a FP only version without any FP->INT conversion.
27 It is similar to default C version, making appropriates
28 overflow and underflows checks as using double precision
29 instead of scaling. */
31 #ifdef _ARCH_PWR7
32 /* POWER7 isinf and isnan optimizations are fast. */
33 # define TEST_INF_NAN(x, y) \
34 if ((isinff(x) || isinff(y)) \
35 && !issignaling (x) && !issignaling (y)) \
36 return INFINITY; \
37 if (isnanf(x) || isnanf(y)) \
38 return x + y;
39 # else
40 /* For POWER6 and below isinf/isnan triggers LHS and PLT calls are
41 * costly (especially for POWER6). */
42 # define GET_TWO_FLOAT_WORD(f1,f2,i1,i2) \
43 do { \
44 ieee_float_shape_type gf_u1; \
45 ieee_float_shape_type gf_u2; \
46 gf_u1.value = (f1); \
47 gf_u2.value = (f2); \
48 (i1) = gf_u1.word & 0x7fffffff; \
49 (i2) = gf_u2.word & 0x7fffffff; \
50 } while (0)
52 # define TEST_INF_NAN(x, y) \
53 do { \
54 uint32_t hx, hy; \
55 GET_TWO_FLOAT_WORD(x, y, hx, hy); \
56 if (hy > hx) { \
57 uint32_t ht = hx; hx = hy; hy = ht; \
58 } \
59 if (hx >= 0x7f800000) { \
60 if ((hx == 0x7f800000 || hy == 0x7f800000) \
61 && !issignaling (x) && !issignaling (y)) \
62 return INFINITY; \
63 return x + y; \
64 } \
65 } while (0)
66 #endif
69 float
70 __ieee754_hypotf (float x, float y)
72 TEST_INF_NAN (x, y);
74 return __ieee754_sqrt ((double) x * x + (double) y * y);
76 strong_alias (__ieee754_hypotf, __hypotf_finite)