public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] riscv: Add support for XTheadBb in string-fz[a,i].h
@ 2023-08-23  5:46 Christoph Muellner
  2023-08-24 17:21 ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 6+ messages in thread
From: Christoph Muellner @ 2023-08-23  5:46 UTC (permalink / raw)
  To: libc-alpha, Palmer Dabbelt, Darius Rad, Andrew Waterman, Philipp Tomsich
  Cc: Christoph Müllner

From: Christoph Müllner <christoph.muellner@vrull.eu>

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>
---
 sysdeps/riscv/string-fza.h | 7 ++++++-
 sysdeps/riscv/string-fzi.h | 2 +-
 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
-- 
2.41.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] riscv: Add support for XTheadBb in string-fz[a,i].h
  2023-08-23  5:46 [PATCH] riscv: Add support for XTheadBb in string-fz[a,i].h Christoph Muellner
@ 2023-08-24 17:21 ` Adhemerval Zanella Netto
  2023-08-24 17:36   ` Christoph Müllner
  2023-09-06 10:34   ` Christoph Müllner
  0 siblings, 2 replies; 6+ messages in thread
From: Adhemerval Zanella Netto @ 2023-08-24 17:21 UTC (permalink / raw)
  To: Christoph Muellner, libc-alpha, Palmer Dabbelt, Darius Rad,
	Andrew Waterman, Philipp Tomsich



On 23/08/23 02:46, Christoph Muellner wrote:
> From: Christoph Müllner <christoph.muellner@vrull.eu>
> 
> 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>


LGTM, thanks.  Is th.tstnbz available as builtin by chance?

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>


> ---
>  sysdeps/riscv/string-fza.h | 7 ++++++-
>  sysdeps/riscv/string-fzi.h | 2 +-
>  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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] riscv: Add support for XTheadBb in string-fz[a,i].h
  2023-08-24 17:21 ` Adhemerval Zanella Netto
@ 2023-08-24 17:36   ` Christoph Müllner
  2023-09-06 10:34   ` Christoph Müllner
  1 sibling, 0 replies; 6+ messages in thread
From: Christoph Müllner @ 2023-08-24 17:36 UTC (permalink / raw)
  To: Adhemerval Zanella Netto
  Cc: libc-alpha, Palmer Dabbelt, Darius Rad, Andrew Waterman, Philipp Tomsich

[-- Attachment #1: Type: text/plain, Size: 2552 bytes --]

On Thu, Aug 24, 2023 at 7:21 PM Adhemerval Zanella Netto <
adhemerval.zanella@linaro.org> wrote:

>
>
> On 23/08/23 02:46, Christoph Muellner wrote:
> > From: Christoph Müllner <christoph.muellner@vrull.eu>
> >
> > 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>
>
>
> LGTM, thanks.  Is th.tstnbz available as builtin by chance?
>

No, same situation like orc.b.

Thanks,
Christoph


>
> Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
>
>
> > ---
> >  sysdeps/riscv/string-fza.h | 7 ++++++-
> >  sysdeps/riscv/string-fzi.h | 2 +-
> >  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
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] riscv: Add support for XTheadBb in string-fz[a,i].h
  2023-08-24 17:21 ` Adhemerval Zanella Netto
  2023-08-24 17:36   ` Christoph Müllner
@ 2023-09-06 10:34   ` Christoph Müllner
  2023-09-06 11:39     ` Adhemerval Zanella Netto
  1 sibling, 1 reply; 6+ messages in thread
From: Christoph Müllner @ 2023-09-06 10:34 UTC (permalink / raw)
  To: Adhemerval Zanella Netto
  Cc: libc-alpha, Palmer Dabbelt, Darius Rad, Andrew Waterman, Philipp Tomsich

[-- Attachment #1: Type: text/plain, Size: 2568 bytes --]

On Thu, Aug 24, 2023 at 7:21 PM Adhemerval Zanella Netto <
adhemerval.zanella@linaro.org> wrote:

>
>
> On 23/08/23 02:46, Christoph Muellner wrote:
> > From: Christoph Müllner <christoph.muellner@vrull.eu>
> >
> > 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>
>
>
> LGTM, thanks.  Is th.tstnbz available as builtin by chance?
>
> Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
>

Is anything blocking this from getting merged?

Thanks,
Christoph


>
>
> > ---
> >  sysdeps/riscv/string-fza.h | 7 ++++++-
> >  sysdeps/riscv/string-fzi.h | 2 +-
> >  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
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] riscv: Add support for XTheadBb in string-fz[a,i].h
  2023-09-06 10:34   ` Christoph Müllner
@ 2023-09-06 11:39     ` Adhemerval Zanella Netto
  2023-09-06 13:52       ` Christoph Müllner
  0 siblings, 1 reply; 6+ messages in thread
From: Adhemerval Zanella Netto @ 2023-09-06 11:39 UTC (permalink / raw)
  To: Christoph Müllner
  Cc: libc-alpha, Palmer Dabbelt, Darius Rad, Andrew Waterman, Philipp Tomsich



On 06/09/23 07:34, Christoph Müllner wrote:
> 
> 
> On Thu, Aug 24, 2023 at 7:21 PM Adhemerval Zanella Netto <adhemerval.zanella@linaro.org <mailto:adhemerval.zanella@linaro.org>> wrote:
> 
> 
> 
>     On 23/08/23 02:46, Christoph Muellner wrote:
>     > From: Christoph Müllner <christoph.muellner@vrull.eu <mailto:christoph.muellner@vrull.eu>>
>     >
>     > 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 <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 <mailto:christoph.muellner@vrull.eu>>
> 
> 
>     LGTM, thanks.  Is th.tstnbz available as builtin by chance?
> 
>     Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org <mailto:adhemerval.zanella@linaro.org>>
> 
> 

Someone to actually push it, since it is already reviewed. I will install it.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] riscv: Add support for XTheadBb in string-fz[a,i].h
  2023-09-06 11:39     ` Adhemerval Zanella Netto
@ 2023-09-06 13:52       ` Christoph Müllner
  0 siblings, 0 replies; 6+ messages in thread
From: Christoph Müllner @ 2023-09-06 13:52 UTC (permalink / raw)
  To: Adhemerval Zanella Netto
  Cc: libc-alpha, Palmer Dabbelt, Darius Rad, Andrew Waterman, Philipp Tomsich

[-- Attachment #1: Type: text/plain, Size: 1546 bytes --]

On Wed, Sep 6, 2023 at 1:39 PM Adhemerval Zanella Netto <
adhemerval.zanella@linaro.org> wrote:

>
>
> On 06/09/23 07:34, Christoph Müllner wrote:
> >
> >
> > On Thu, Aug 24, 2023 at 7:21 PM Adhemerval Zanella Netto <
> adhemerval.zanella@linaro.org <mailto:adhemerval.zanella@linaro.org>>
> wrote:
> >
> >
> >
> >     On 23/08/23 02:46, Christoph Muellner wrote:
> >     > From: Christoph Müllner <christoph.muellner@vrull.eu <mailto:
> christoph.muellner@vrull.eu>>
> >     >
> >     > 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 <
> 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
> <mailto:christoph.muellner@vrull.eu>>
> >
> >
> >     LGTM, thanks.  Is th.tstnbz available as builtin by chance?
> >
> >     Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org
> <mailto:adhemerval.zanella@linaro.org>>
> >
> >
>
> Someone to actually push it, since it is already reviewed. I will install
> it.
>

Thanks!

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-09-06 13:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-23  5:46 [PATCH] riscv: Add support for XTheadBb in string-fz[a,i].h Christoph Muellner
2023-08-24 17:21 ` Adhemerval Zanella Netto
2023-08-24 17:36   ` Christoph Müllner
2023-09-06 10:34   ` Christoph Müllner
2023-09-06 11:39     ` Adhemerval Zanella Netto
2023-09-06 13:52       ` Christoph Müllner

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).