[PATCH v3] RISC-V: Use __builtin_ffs when zbb is enabled
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Tue Jan 28 13:26:38 GMT 2025
On 27/01/25 10:11, Anton Blanchard wrote:
> Using __builtin_ffs when zbb is enabled takes __ffs from 26
> instructions to 5.
We already have a similar patch [1] which also cover __riscv_xtheadbb.
[1] https://patchwork.sourceware.org/project/glibc/patch/20241108134143.327-1-julian.oerv@isrc.iscas.ac.cn/
> ---
> sysdeps/riscv/math-use-builtins-ffs.h | 9 +++++++++
> 1 file changed, 9 insertions(+)
> create mode 100644 sysdeps/riscv/math-use-builtins-ffs.h
>
> diff --git a/sysdeps/riscv/math-use-builtins-ffs.h b/sysdeps/riscv/math-use-builtins-ffs.h
> new file mode 100644
> index 0000000000..c2b50b0b62
> --- /dev/null
> +++ b/sysdeps/riscv/math-use-builtins-ffs.h
> @@ -0,0 +1,9 @@
> +/* Expansion of __builtin_ffs using zbb instructions was not implemented
> + until gcc 12, so we need to check the compiler version. */
> +#if __GNUC_PREREQ (12, 0) && defined __riscv_zbb
> +#define USE_FFS_BUILTIN 1
> +#define USE_FFSLL_BUILTIN 1
> +#else
> +#define USE_FFS_BUILTIN 0
> +#define USE_FFSLL_BUILTIN 0
> +#endif
More information about the Libc-alpha
mailing list