about summary refs log tree commit diff
path: root/sysdeps/riscv
diff options
context:
space:
mode:
authorChristoph Müllner <christoph.muellner@vrull.eu>2023-08-23 07:46:28 +0200
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2023-09-06 09:27:43 -0300
commit3d6fcf1bd7f462d333c36a14efc0e03f2fdd3f9e (patch)
tree773c257487ce30d630043e9a30f1894c15f1f65b /sysdeps/riscv
parent3bf7bab88b0da01d4f5ef20afbbb45203185501e (diff)
downloadglibc-3d6fcf1bd7f462d333c36a14efc0e03f2fdd3f9e.tar.gz
glibc-3d6fcf1bd7f462d333c36a14efc0e03f2fdd3f9e.tar.xz
glibc-3d6fcf1bd7f462d333c36a14efc0e03f2fdd3f9e.zip
riscv: Add support for XTheadBb in string-fz[a,i].h
XTheadBb has similar instructions like Zbb, which allow optimized
string processing:
* th.ff0: find-first zero is a CLZ instruction.
* th.tstnbz: Similar like orc.b, but with a bit-inverted result.

The instructions are documented here:
  https://github.com/T-head-Semi/thead-extension-spec/tree/master/xtheadbb

These instructions can be found in the T-Head C906 and the C910.

Tested with the string tests.

Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Diffstat (limited to 'sysdeps/riscv')
-rw-r--r--sysdeps/riscv/string-fza.h7
-rw-r--r--sysdeps/riscv/string-fzi.h2
2 files changed, 7 insertions, 2 deletions
diff --git a/sysdeps/riscv/string-fza.h b/sysdeps/riscv/string-fza.h
index 4429653a00..4958d5d151 100644
--- a/sysdeps/riscv/string-fza.h
+++ b/sysdeps/riscv/string-fza.h
@@ -19,7 +19,7 @@
 #ifndef _RISCV_STRING_FZA_H
 #define _RISCV_STRING_FZA_H 1
 
-#ifdef __riscv_zbb
+#if defined __riscv_zbb || defined __riscv_xtheadbb
 /* With bitmap extension we can use orc.b to find all zero bytes.  */
 # include <string-misc.h>
 # include <string-optype.h>
@@ -32,8 +32,13 @@ static __always_inline find_t
 find_zero_all (op_t x)
 {
   find_t r;
+#ifdef __riscv_xtheadbb
+  asm ("th.tstnbz %0, %1" : "=r" (r) : "r" (x));
+  return r;
+#else
   asm ("orc.b %0, %1" : "=r" (r) : "r" (x));
   return ~r;
+#endif
 }
 
 /* This function returns 0xff for each byte that is equal between X1 and
diff --git a/sysdeps/riscv/string-fzi.h b/sysdeps/riscv/string-fzi.h
index 8f56c378ff..45d6367a10 100644
--- a/sysdeps/riscv/string-fzi.h
+++ b/sysdeps/riscv/string-fzi.h
@@ -19,7 +19,7 @@
 #ifndef _STRING_RISCV_FZI_H
 #define _STRING_RISCV_FZI_H 1
 
-#ifdef __riscv_zbb
+#if defined __riscv_zbb || defined __riscv_xtheadbb
 # include <sysdeps/generic/string-fzi.h>
 #else
 /* Without bitmap clz/ctz extensions, it is faster to direct test the bits