[v3,2/3] powerpc: Add optimized llogb* for POWER9
Commit Message
Changes since v2:
- Removed the GCC version test and used the _GL_HAS_BUILTIN_ILOGB.
- Removed the optimization from long double as it was converting
ibm128 to float128.
---8<---
The POWER9 builtins used to improve the ilogb* functions can be
used in the llogb* functions as well.
---
.../powerpc64/le/fpu/w_llogb_template.c | 39 +++++++++++++++++++
sysdeps/powerpc/powerpc64/le/fpu/w_llogbl.c | 3 ++
2 files changed, 42 insertions(+)
create mode 100644 sysdeps/powerpc/powerpc64/le/fpu/w_llogb_template.c
create mode 100644 sysdeps/powerpc/powerpc64/le/fpu/w_llogbl.c
Comments
On 3/4/21 9:00 AM, Raphael Moreira Zinsly wrote:
> Changes since v2:
> - Removed the GCC version test and used the _GL_HAS_BUILTIN_ILOGB.
> - Removed the optimization from long double as it was converting
> ibm128 to float128.
>
> ---8<---
>
> The POWER9 builtins used to improve the ilogb* functions can be
> used in the llogb* functions as well.
> ---
This patch looks OK.
new file mode 100644
@@ -0,0 +1,39 @@
+#include <math.h>
+#include <errno.h>
+#include <limits.h>
+#include <math_private.h>
+#include <fenv.h>
+
+#if _GL_HAS_BUILTIN_ILOGB
+long int
+M_DECL_FUNC (__llogb) (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);
+ long int lr = r;
+ if (__glibc_unlikely (r == FP_ILOGB0)
+ || __glibc_unlikely (r == FP_ILOGBNAN)
+ || __glibc_unlikely (r == INT_MAX))
+ {
+#if LONG_MAX != INT_MAX
+ if (r == FP_ILOGB0)
+ lr = FP_LLOGB0;
+ else if (r == FP_ILOGBNAN)
+ lr = FP_LLOGBNAN;
+ else
+ lr = LONG_MAX;
+#endif
+ __set_errno (EDOM);
+ __feraiseexcept (FE_INVALID);
+ }
+ return lr;
+}
+declare_mgen_alias (__llogb, llogb)
+#else
+#include <math/w_llogb_template.c>
+#endif
new file mode 100644
@@ -0,0 +1,3 @@
+/* Skip the optimization for long double as it uses ibm128. */
+#include <math-type-macros-ldouble.h>
+#include <math/w_llogb_template.c>