]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/powerpc/fpu/e_hypotf.c
Update copyright notices with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / powerpc / fpu / e_hypotf.c
CommitLineData
77a2a8b4 1/* Pythagorean addition using floats
d4697bc9 2 Copyright (C) 2011-2014 Free Software Foundation, Inc.
77a2a8b4
AZ
3 This file is part of the GNU C Library.
4 Contributed by Adhemerval Zanella <azanella@br.ibm.com>, 2011
5
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.
10
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.
15
16 You should have received a copy of the GNU Library General Public
59ba27a6
PE
17 License along with the GNU C Library; see the file COPYING.LIB. If
18 not, see <http://www.gnu.org/licenses/>. */
77a2a8b4 19
1ed0291c
RH
20#include <math.h>
21#include <math_private.h>
e054f494 22#include <stdint.h>
77a2a8b4
AZ
23
24static const float two30 = 1.0737418e09;
77a2a8b4
AZ
25
26/* __ieee754_hypotf(x,y)
11e0098e
AS
27
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. */
77a2a8b4
AZ
32
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); \
13d3b41a
AZ
49 (i1) = gf_u1.word & 0x7fffffff; \
50 (i2) = gf_u2.word & 0x7fffffff; \
77a2a8b4
AZ
51 } while (0)
52
53# define TEST_INF_NAN(x, y) \
54 do { \
13d3b41a 55 uint32_t hx, hy; \
77a2a8b4
AZ
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
67
68
69float
70__ieee754_hypotf (float x, float y)
71{
77a2a8b4
AZ
72 TEST_INF_NAN (x, y);
73
11e0098e 74 return __ieee754_sqrt ((double) x * x + (double) y * y);
77a2a8b4 75}
0ac5ae23 76strong_alias (__ieee754_hypotf, __hypotf_finite)