[PATCH] RISC-V: Use __builtin_ffs when zbb is enabled

Xi Ruoyao xry111@xry111.site
Mon Jan 27 01:42:11 GMT 2025


On Mon, 2025-01-27 at 01:23 +0000, Anton Blanchard wrote:
> Using __builtin_ffs when zbb is enabled takes __ffs from 26
> instructions to 5.
> ---

The change will generate a infinite recursion with GCC 11:
https://godbolt.org/z/cKzG5Tb35

Please check the GCC version with __GNUC_PREREQ.

>  sysdeps/riscv/math-use-builtins-ffs.h | 7 +++++++
>  1 file changed, 7 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..a172f63d36
> --- /dev/null
> +++ b/sysdeps/riscv/math-use-builtins-ffs.h
> @@ -0,0 +1,7 @@
> +#ifdef __riscv_zbb
> +#define USE_FFS_BUILTIN   1
> +#define USE_FFSLL_BUILTIN 1
> +#else
> +#define USE_FFS_BUILTIN   0
> +#define USE_FFSLL_BUILTIN 0
> +#endif

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University


More information about the Libc-alpha mailing list