public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "Christoph Müllner" <christoph.muellner@vrull.eu>
To: libc-alpha@sourceware.org,
	Adhemerval Zanella <adhemerval.zanella@linaro.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Darius Rad <darius@bluespec.com>,
	Andrew Waterman <andrew@sifive.com>,
	Philipp Tomsich <philipp.tomsich@vrull.eu>,
	Evan Green <evan@rivosinc.com>, DJ Delorie <dj@redhat.com>,
	Vineet Gupta <vineetg@rivosinc.com>,
	Kito Cheng <kito.cheng@sifive.com>,
	Jeff Law <jeffreyalaw@gmail.com>
Cc: "Christoph Müllner" <christoph.muellner@vrull.eu>
Subject: [PATCH v2 08/15] RISC-V: string-fz[a,i].h: Make orc.b optimization explicit
Date: Mon, 27 May 2024 13:18:53 +0200	[thread overview]
Message-ID: <20240527111900.1060546-9-christoph.muellner@vrull.eu> (raw)
In-Reply-To: <20240527111900.1060546-1-christoph.muellner@vrull.eu>

RISC-V Zbb has the orc.b instruction, which can be used
in find_zero_all. T-Head has a similar instruction (th.tstnbz)
in their XTheadBb extension.

Currently, we pick the optimized code, whenever the corresponding
extension test macros are enabled (e.g. __riscv_zbb for Zbb).
However, these test macros are not set in case the extensions
are enabled via function attributes.

This patch adds a mechanism to enable the optimization explicitly
to overcome this limitation.  The old behavior (enabled optimization
via __riscv_zbb) remains the same.

By evaluating the value (instead of just checking if these macros are
defined) we could also explicitly disable the optimization by defining
the macros as 0 (e.g. #define USE_ZBB_ORCB 0).

Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
---
 sysdeps/riscv/string-fza.h | 22 ++++++++++++++++++++--
 sysdeps/riscv/string-fzi.h | 20 +++++++++++++++++++-
 2 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/sysdeps/riscv/string-fza.h b/sysdeps/riscv/string-fza.h
index ee5c31317f..34d6972aea 100644
--- a/sysdeps/riscv/string-fza.h
+++ b/sysdeps/riscv/string-fza.h
@@ -19,7 +19,25 @@
 #ifndef _RISCV_STRING_FZA_H
 #define _RISCV_STRING_FZA_H 1
 
-#if defined __riscv_zbb || defined __riscv_xtheadbb
+/* Enable use of orc.b if Zbb is available.  */
+#ifndef USE_ZBB_ORCB
+# ifdef __riscv_zbb
+#  define USE_ZBB_ORCB 1
+# else
+#  define USE_ZBB_ORCB 0
+# endif
+#endif
+
+/* Enable use of th.tstnbz if XTheadBb is available.  */
+#ifndef USE_XTHEADBB_TSTNBZ
+# ifdef __riscv_xtheadbb
+#  define USE_XTHEADBB_TSTNBZ 1
+# else
+#  define USE_XTHEADBB_TSTNBZ 0
+# endif
+#endif
+
+#if USE_ZBB_ORCB || USE_XTHEADBB_TSTNBZ
 /* With bitmap extension we can use orc.b to find all zero bytes.  */
 # include <string-misc.h>
 # include <string-optype.h>
@@ -32,7 +50,7 @@ static __always_inline find_t
 find_zero_all (op_t x)
 {
   find_t r;
-#ifdef __riscv_xtheadbb
+#if USE_XTHEADBB_TSTNBZ
   asm ("th.tstnbz %0, %1" : "=r" (r) : "r" (x));
   return r;
 #else
diff --git a/sysdeps/riscv/string-fzi.h b/sysdeps/riscv/string-fzi.h
index 66237c2f03..e3c3a96d62 100644
--- a/sysdeps/riscv/string-fzi.h
+++ b/sysdeps/riscv/string-fzi.h
@@ -19,7 +19,25 @@
 #ifndef _STRING_RISCV_FZI_H
 #define _STRING_RISCV_FZI_H 1
 
-#if defined __riscv_zbb || defined __riscv_xtheadbb
+/* Enable use of orc.b if Zbb is available.  */
+#ifndef USE_ZBB_ORCB
+# ifdef __riscv_zbb
+#  define USE_ZBB_ORCB 1
+# else
+#  define USE_ZBB_ORCB 0
+# endif
+#endif
+
+/* Enable use of th.tstnbz if XTheadBb is available.  */
+#ifndef USE_XTHEADBB_TSTNBZ
+# ifdef __riscv_xtheadbb
+#  define USE_XTHEADBB_TSTNBZ 1
+# else
+#  define USE_XTHEADBB_TSTNBZ 0
+# endif
+#endif
+
+#if USE_ZBB_ORCB || USE_XTHEADBB_TSTNBZ
 # include <sysdeps/generic/string-fzi.h>
 #else
 /* Without bitmap clz/ctz extensions, it is faster to direct test the bits
-- 
2.45.1


  parent reply	other threads:[~2024-05-27 11:19 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-27 11:18 [PATCH v2 00/15] RISC-V: Add Zbb-optimized string routines as ifuncs Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 01/15] cdefs: Add mechanism to add attributes to __always_inline functions Christoph Müllner
2024-08-13 17:58   ` Adhemerval Zanella Netto
2024-08-14  9:29   ` Florian Weimer
2024-05-27 11:18 ` [PATCH v2 02/15] string/memchr: Add mechanism to set function attributes Christoph Müllner
2024-08-13 18:16   ` Adhemerval Zanella Netto
2024-05-27 11:18 ` [PATCH v2 03/15] string/memrchr: " Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 04/15] string/strchrnul: " Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 05/15] string/strcmp: " Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 06/15] string/strlen: " Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 07/15] string/strncmp: " Christoph Müllner
2024-05-27 11:18 ` Christoph Müllner [this message]
2024-05-27 11:18 ` [PATCH v2 09/15] RISC-V: Add compiler test for Zbb function attribute support Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 10/15] RISC-V: Add Zbb optimized memchr as ifunc Christoph Müllner
2024-08-13 18:23   ` Adhemerval Zanella Netto
2024-05-27 11:18 ` [PATCH v2 11/15] RISC-V: Add Zbb optimized memrchr " Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 12/15] RISC-V: Add Zbb optimized strchrnul " Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 13/15] RISC-V: Add Zbb optimized strcmp " Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 14/15] RISC-V: Add Zbb optimized strlen " Christoph Müllner
2024-05-27 11:19 ` [PATCH v2 15/15] RISC-V: Add Zbb optimized strncmp " Christoph Müllner
2024-06-03 21:08 ` [PATCH v2 00/15] RISC-V: Add Zbb-optimized string routines as ifuncs Christoph Müllner
2024-06-11 10:00   ` Christoph Müllner
2024-06-19 14:26 ` Adhemerval Zanella Netto
2024-06-20 15:52   ` Christoph Müllner
2024-07-17  7:34     ` Christoph Müllner
2024-08-13 14:05       ` Christoph Müllner
2024-08-13 17:39       ` Adhemerval Zanella Netto

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=20240527111900.1060546-9-christoph.muellner@vrull.eu \
    --to=christoph.muellner@vrull.eu \
    --cc=adhemerval.zanella@linaro.org \
    --cc=andrew@sifive.com \
    --cc=darius@bluespec.com \
    --cc=dj@redhat.com \
    --cc=evan@rivosinc.com \
    --cc=jeffreyalaw@gmail.com \
    --cc=kito.cheng@sifive.com \
    --cc=libc-alpha@sourceware.org \
    --cc=palmer@dabbelt.com \
    --cc=philipp.tomsich@vrull.eu \
    --cc=vineetg@rivosinc.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).