]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/powerpc/fpu/s_logbl.c
1 /* Get exponent of a floating-point value. PowerPC version.
2 Copyright (C) 2012-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 /* ISA 2.07 provides fast GPR to FP instruction (mfvsr{d,wz}) which make
20 generic implementation faster. */
21 #if defined(_ARCH_PWR8) || !defined(_ARCH_PWR7)
22 # include <./sysdeps/ieee754/ldbl-128ibm/s_logbl.c>
25 # include <math_private.h>
26 # include <math_ldbl_opt.h>
28 /* This implementation avoids FP to INT conversions by using VSX
29 bitwise instructions over FP values. */
31 __logbl (long double x
)
37 if (__glibc_unlikely (x
== 0.0))
38 /* Raise FE_DIVBYZERO and return -HUGE_VAL[LF]. */
39 return -1.0L / __builtin_fabsl (x
);
41 ldbl_unpack (x
, &xh
, &xl
);
42 EXTRACT_WORDS64 (hx
, xh
);
44 /* Mask to extract the exponent. */
45 asm ("xxland %x0,%x1,%x2\n"
48 : "d" (xh
), "d" (0x7ff0000000000000ULL
));
49 ret
= (ret
* 0x1p
-52) - 1023.0;
51 /* Multiplication is used to set logb (+-INF) = INF. */
53 else if (ret
== -1023.0)
55 /* POSIX specifies that denormal number is treated as
56 though it were normalized. */
57 return (long double) (- (__builtin_clzll (hx
& 0x7fffffffffffffffLL
) \
60 else if ((hx
& 0x000fffffffffffffLL
) == 0)
62 /* If the high part is a power of 2, and the low part is nonzero
63 with the opposite sign, the low part affects the
66 EXTRACT_WORDS64 (lx
, xl
);
67 rhx
= (hx
& 0x7ff0000000000000LL
) >> 52;
68 if ((hx
^ lx
) < 0 && (lx
& 0x7fffffffffffffffLL
) != 0)
70 return (long double) (rhx
- 1023);
72 /* Test to avoid logb_downward (0.0) == -0.0. */
73 return ret
== -0.0 ? 0.0 : ret
;
76 long_double_symbol (libm
, __logbl
, logbl
);