]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
riscv: Add support for XTheadBb in string-fz[a,i].h
authorChristoph Müllner <christoph.muellner@vrull.eu>
Wed, 23 Aug 2023 05:46:28 +0000 (07:46 +0200)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 6 Sep 2023 12:27:43 +0000 (09:27 -0300)
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>
sysdeps/riscv/string-fza.h
sysdeps/riscv/string-fzi.h

index 4429653a001de09730cfa83325b29556a8afb5ed..4958d5d1519737ee01b1b03985899a2695bad109 100644 (file)
@@ -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
index 8f56c378ff96e1a411bba11646b0c43238b79499..45d6367a10619d416f77480b511e8973b28a4a96 100644 (file)
@@ -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