public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Raphael Moreira Zinsly <rzinsly@linux.ibm.com>
To: libc-alpha@sourceware.org
Cc: murphyp@linux.ibm.com, tuliom@linux.ibm.com,
	Raphael Moreira Zinsly <rzinsly@linux.ibm.com>
Subject: [PATCH v2 2/3] powerpc: Add optimized llogb* for POWER9
Date: Mon,  1 Mar 2021 14:51:39 -0300	[thread overview]
Message-ID: <20210301175140.29109-2-rzinsly@linux.ibm.com> (raw)
In-Reply-To: <20210301175140.29109-1-rzinsly@linux.ibm.com>

Changes since v1:
	- Check if the correct GCC version is used.

--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       | 40 +++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 sysdeps/powerpc/powerpc64/le/fpu/w_llogb_template.c

diff --git a/sysdeps/powerpc/powerpc64/le/fpu/w_llogb_template.c b/sysdeps/powerpc/powerpc64/le/fpu/w_llogb_template.c
new file mode 100644
index 0000000000..4c1642274f
--- /dev/null
+++ b/sysdeps/powerpc/powerpc64/le/fpu/w_llogb_template.c
@@ -0,0 +1,40 @@
+/* The builtins used are only available with GCC 8.0 or newer.  */
+#if defined _ARCH_PWR9 && __GNUC_PREREQ (8, 0)
+#include <math.h>
+#include <errno.h>
+#include <limits.h>
+#include <math_private.h>
+#include <fenv.h>
+
+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
-- 
2.29.2


  reply	other threads:[~2021-03-01 17:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-01 17:51 [PATCH v2 1/3] powerpc: Add optimized ilogb* " Raphael Moreira Zinsly
2021-03-01 17:51 ` Raphael Moreira Zinsly [this message]
2021-03-01 17:51 ` [PATCH v2 3/3] benchtests: Add ilogb* tests Raphael Moreira Zinsly
2021-03-02  1:27 ` [PATCH v2 1/3] powerpc: Add optimized ilogb* for POWER9 Paul A. Clarke
2021-03-03 16:23   ` Raphael M Zinsly
2021-03-03 17:20     ` Paul A. Clarke
2021-03-02 17:46 ` Paul E Murphy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210301175140.29109-2-rzinsly@linux.ibm.com \
    --to=rzinsly@linux.ibm.com \
    --cc=libc-alpha@sourceware.org \
    --cc=murphyp@linux.ibm.com \
    --cc=tuliom@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).