]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/powerpc/fpu/s_logbf.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/flt-32/s_logbf.c>
25 # include <libm-alias-float.h>
26 /* This implementation avoids FP to INT conversions by using VSX
27 bitwise instructions over FP values. */
31 /* VSX operation are all done internally as double. */
34 if (__glibc_unlikely (x
== 0.0))
35 /* Raise FE_DIVBYZERO and return -HUGE_VAL[LF]. */
36 return -1.0 / fabs (x
);
38 /* mask to extract the exponent. */
39 asm ("xxland %x0,%x1,%x2\n"
42 : "d" (x
), "d" (0x7ff0000000000000ULL
));
43 /* ret = (ret >> 52) - 1023.0, since ret is double. */
44 ret
= (ret
* 0x1p
-52) - 1023.0;
46 /* Multiplication is used to set logb (+-INF) = INF. */
48 /* Since operations are done with double we don't need
49 additional tests for subnormal numbers.
50 The test is to avoid logb_downward (0.0) == -0.0. */
51 return ret
== -0.0 ? 0.0 : ret
;
54 libm_alias_float (__logb
, logb
)