8a984d
commit a7d88506c260e7a0e4268803e76fc19e38ed041f
8a984d
Author: Raphael Moreira Zinsly <rzinsly@linux.ibm.com>
8a984d
Date:   Thu Feb 25 09:58:52 2021 -0300
8a984d
8a984d
    powerpc: Add optimized llogb* for POWER9
8a984d
    
8a984d
    The POWER9 builtins used to improve the ilogb* functions can be
8a984d
    used in the llogb* functions as well.
8a984d
8a984d
diff --git a/sysdeps/powerpc/powerpc64/le/fpu/w_llogb_template.c b/sysdeps/powerpc/powerpc64/le/fpu/w_llogb_template.c
8a984d
new file mode 100644
8a984d
index 0000000000000000..d00b71d2a34e28da
8a984d
--- /dev/null
8a984d
+++ b/sysdeps/powerpc/powerpc64/le/fpu/w_llogb_template.c
8a984d
@@ -0,0 +1,39 @@
8a984d
+#include <math.h>
8a984d
+#include <errno.h>
8a984d
+#include <limits.h>
8a984d
+#include <math_private.h>
8a984d
+#include <fenv.h>
8a984d
+
8a984d
+#if _GL_HAS_BUILTIN_ILOGB
8a984d
+long int
8a984d
+M_DECL_FUNC (__llogb) (FLOAT x)
8a984d
+{
8a984d
+  int r;
8a984d
+  /* Check for exceptional cases.  */
8a984d
+  if (! M_SUF(__builtin_test_dc_ilogb) (x, 0x7f))
8a984d
+    r = M_SUF (__builtin_ilogb) (x);
8a984d
+  else
8a984d
+    /* Fallback to the generic ilogb if x is NaN, Inf or subnormal.  */
8a984d
+    r = M_SUF (__ieee754_ilogb) (x);
8a984d
+  long int lr = r;
8a984d
+  if (__glibc_unlikely (r == FP_ILOGB0)
8a984d
+      || __glibc_unlikely (r == FP_ILOGBNAN)
8a984d
+      || __glibc_unlikely (r == INT_MAX))
8a984d
+    {
8a984d
+#if LONG_MAX != INT_MAX
8a984d
+      if (r == FP_ILOGB0)
8a984d
+	lr = FP_LLOGB0;
8a984d
+      else if (r == FP_ILOGBNAN)
8a984d
+	lr = FP_LLOGBNAN;
8a984d
+      else
8a984d
+	lr = LONG_MAX;
8a984d
+#endif
8a984d
+      __set_errno (EDOM);
8a984d
+      __feraiseexcept (FE_INVALID);
8a984d
+    }
8a984d
+  return lr;
8a984d
+}
8a984d
+declare_mgen_alias (__llogb, llogb)
8a984d
+#else
8a984d
+#include <math/w_llogb_template.c>
8a984d
+#endif
8a984d
diff --git a/sysdeps/powerpc/powerpc64/le/fpu/w_llogbl.c b/sysdeps/powerpc/powerpc64/le/fpu/w_llogbl.c
8a984d
new file mode 100644
8a984d
index 0000000000000000..69477a37ae82c476
8a984d
--- /dev/null
8a984d
+++ b/sysdeps/powerpc/powerpc64/le/fpu/w_llogbl.c
8a984d
@@ -0,0 +1,4 @@
8a984d
+/* Skip the optimization for long double as ibm128 does not provide an
8a984d
+   optimized builtin. */
8a984d
+#include <math-type-macros-ldouble.h>
8a984d
+#include <math/w_llogb_template.c>