powerpc: Add optimized llogb* for POWER9
[glibc.git] / sysdeps / powerpc / powerpc64 / le / fpu / w_llogb_template.c
blobd00b71d2a34e28da2742a2788c49f4b442c472ef
1 #include <math.h>
2 #include <errno.h>
3 #include <limits.h>
4 #include <math_private.h>
5 #include <fenv.h>
7 #if _GL_HAS_BUILTIN_ILOGB
8 long int
9 M_DECL_FUNC (__llogb) (FLOAT x)
11 int r;
12 /* Check for exceptional cases. */
13 if (! M_SUF(__builtin_test_dc_ilogb) (x, 0x7f))
14 r = M_SUF (__builtin_ilogb) (x);
15 else
16 /* Fallback to the generic ilogb if x is NaN, Inf or subnormal. */
17 r = M_SUF (__ieee754_ilogb) (x);
18 long int lr = r;
19 if (__glibc_unlikely (r == FP_ILOGB0)
20 || __glibc_unlikely (r == FP_ILOGBNAN)
21 || __glibc_unlikely (r == INT_MAX))
23 #if LONG_MAX != INT_MAX
24 if (r == FP_ILOGB0)
25 lr = FP_LLOGB0;
26 else if (r == FP_ILOGBNAN)
27 lr = FP_LLOGBNAN;
28 else
29 lr = LONG_MAX;
30 #endif
31 __set_errno (EDOM);
32 __feraiseexcept (FE_INVALID);
34 return lr;
36 declare_mgen_alias (__llogb, llogb)
37 #else
38 #include <math/w_llogb_template.c>
39 #endif