mirror of
https://sourceware.org/git/glibc.git
synced 2025-08-07 06:43:00 +03:00
The instructions xsxexpdp and xsxexpqp introduced on POWER9 extract the exponent from a double-precision and quad-precision floating-point respectively, thus they can be used to improve ilogb, ilogbf and ilogbf128.
31 lines
724 B
C
31 lines
724 B
C
#include <math.h>
|
|
#include <errno.h>
|
|
#include <limits.h>
|
|
#include <math_private.h>
|
|
#include <fenv.h>
|
|
|
|
#if _GL_HAS_BUILTIN_ILOGB
|
|
int
|
|
M_DECL_FUNC (__ilogb) (FLOAT x)
|
|
{
|
|
int r;
|
|
/* Check for exceptional cases. */
|
|
if (! M_SUF(__builtin_test_dc_ilogb) (x, 0x7f))
|
|
r = M_SUF (__builtin_ilogb) (x);
|
|
else
|
|
/* Fallback to the generic ilogb if x is NaN, Inf or subnormal. */
|
|
r = M_SUF (__ieee754_ilogb) (x);
|
|
if (__builtin_expect (r == FP_ILOGB0, 0)
|
|
|| __builtin_expect (r == FP_ILOGBNAN, 0)
|
|
|| __builtin_expect (r == INT_MAX, 0))
|
|
{
|
|
__set_errno (EDOM);
|
|
__feraiseexcept (FE_INVALID);
|
|
}
|
|
return r;
|
|
}
|
|
declare_mgen_alias (__ilogb, ilogb)
|
|
#else
|
|
#include <math/w_ilogb_template.c>
|
|
#endif
|