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