]>
Commit | Line | Data |
---|---|---|
777b1eea | 1 | /* logbl(). PowerPC/POWER7 version. |
04277e02 | 2 | Copyright (C) 2012-2019 Free Software Foundation, Inc. |
777b1eea AZ |
3 | This file is part of the GNU C Library. |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
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/>. */ | |
18 | ||
19 | #include <math.h> | |
20 | #include <math_private.h> | |
21 | #include <math_ldbl_opt.h> | |
22 | ||
23 | /* This implementation avoids FP to INT conversions by using VSX | |
24 | bitwise instructions over FP values. */ | |
25 | ||
26 | static const double two1div52 = 2.220446049250313e-16; /* 1/2**52 */ | |
27 | static const double two10m1 = -1023.0; /* 2**10 -1 */ | |
28 | ||
29 | /* FP mask to extract the exponent. */ | |
30 | static const union { | |
31 | unsigned long long mask; | |
32 | double d; | |
33 | } mask = { 0x7ff0000000000000ULL }; | |
34 | ||
35 | long double | |
36 | __logbl (long double x) | |
37 | { | |
c064f6a6 | 38 | double xh, xl; |
777b1eea | 39 | double ret; |
c064f6a6 | 40 | int64_t hx; |
777b1eea AZ |
41 | |
42 | if (__builtin_expect (x == 0.0L, 0)) | |
43 | /* Raise FE_DIVBYZERO and return -HUGE_VAL[LF]. */ | |
44 | return -1.0L / __builtin_fabsl (x); | |
45 | ||
c064f6a6 TMQMF |
46 | ldbl_unpack (x, &xh, &xl); |
47 | EXTRACT_WORDS64 (hx, xh); | |
777b1eea AZ |
48 | /* ret = x & 0x7ff0000000000000; */ |
49 | asm ( | |
50 | "xxland %x0,%x1,%x2\n" | |
51 | "fcfid %0,%0" | |
52 | : "=f" (ret) | |
53 | : "f" (xh), "f" (mask.d)); | |
54 | /* ret = (ret >> 52) - 1023.0; */ | |
55 | ret = (ret * two1div52) + two10m1; | |
56 | if (__builtin_expect (ret > -two10m1, 0)) | |
57 | /* Multiplication is used to set logb (+-INF) = INF. */ | |
58 | return (xh * xh); | |
59 | else if (__builtin_expect (ret == two10m1, 0)) | |
60 | { | |
25dbcb27 AS |
61 | /* POSIX specifies that denormal number is treated as |
62 | though it were normalized. */ | |
c064f6a6 TMQMF |
63 | return (long double) (- (__builtin_clzll (hx & 0x7fffffffffffffffLL) \ |
64 | - 12) - 1023); | |
65 | } | |
66 | else if ((hx & 0x000fffffffffffffLL) == 0) | |
67 | { | |
68 | /* If the high part is a power of 2, and the low part is nonzero | |
69 | with the opposite sign, the low part affects the | |
70 | exponent. */ | |
71 | int64_t lx, rhx; | |
72 | EXTRACT_WORDS64 (lx, xl); | |
73 | rhx = (hx & 0x7ff0000000000000LL) >> 52; | |
74 | if ((hx ^ lx) < 0 && (lx & 0x7fffffffffffffffLL) != 0) | |
75 | rhx--; | |
76 | return (long double) (rhx - 1023); | |
777b1eea AZ |
77 | } |
78 | /* Test to avoid logb_downward (0.0) == -0.0. */ | |
79 | return ret == -0.0 ? 0.0 : ret; | |
80 | } | |
2d9470b2 | 81 | #ifndef __logbl |
777b1eea | 82 | long_double_symbol (libm, __logbl, logbl); |
2d9470b2 | 83 | #endif |