Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / powerpc / fpu / e_hypotf.c
blobb76131af28343fe3d9d13f24c793f0a42ed02689
1 /* Pythagorean addition using floats
2 Copyright (C) 2011-2014 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 static const float two30 = 1.0737418e09;
26 /* __ieee754_hypotf(x,y)
28 This a FP only version without any FP->INT conversion.
29 It is similar to default C version, making appropriates
30 overflow and underflows checks as using double precision
31 instead of scaling. */
33 #ifdef _ARCH_PWR7
34 /* POWER7 isinf and isnan optimizations are fast. */
35 # define TEST_INF_NAN(x, y) \
36 if (isinff(x) || isinff(y)) \
37 return INFINITY; \
38 if (isnanf(x) || isnanf(y)) \
39 return NAN;
40 # else
41 /* For POWER6 and below isinf/isnan triggers LHS and PLT calls are
42 * costly (especially for POWER6). */
43 # define GET_TWO_FLOAT_WORD(f1,f2,i1,i2) \
44 do { \
45 ieee_float_shape_type gf_u1; \
46 ieee_float_shape_type gf_u2; \
47 gf_u1.value = (f1); \
48 gf_u2.value = (f2); \
49 (i1) = gf_u1.word & 0x7fffffff; \
50 (i2) = gf_u2.word & 0x7fffffff; \
51 } while (0)
53 # define TEST_INF_NAN(x, y) \
54 do { \
55 uint32_t hx, hy; \
56 GET_TWO_FLOAT_WORD(x, y, hx, hy); \
57 if (hy > hx) { \
58 uint32_t ht = hx; hx = hy; hy = ht; \
59 } \
60 if (hx >= 0x7f800000) { \
61 if (hx == 0x7f800000 || hy == 0x7f800000) \
62 return INFINITY; \
63 return NAN; \
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)