LoongArch: Use builtins for ffs and ffsll

Message ID 20240204002750.402652-1-xry111@xry111.site
State Committed
Commit 2e80f139376450acdb7d879d799439578a41810e
Headers
Series LoongArch: Use builtins for ffs and ffsll |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
redhat-pt-bot/TryBot-32bit success Build for i686
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Testing passed

Commit Message

Xi Ruoyao Feb. 4, 2024, 12:27 a.m. UTC
  On LoongArch GCC compiles __builtin_ffs{,ll} to basically
`(x ? __builtin_ctz (x) : -1) + 1`.  Since a hardware ctz instruction is
available, this is much better than the table-driven generic
implementation.

Tested on loongarch64.

Signed-off-by: Xi Ruoyao <xry111@xry111.site>
---
 sysdeps/loongarch/math-use-builtins-ffs.h | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 sysdeps/loongarch/math-use-builtins-ffs.h
  

Comments

Adhemerval Zanella Netto Feb. 5, 2024, 1:57 p.m. UTC | #1
On 03/02/24 21:27, Xi Ruoyao wrote:
> On LoongArch GCC compiles __builtin_ffs{,ll} to basically
> `(x ? __builtin_ctz (x) : -1) + 1`.  Since a hardware ctz instruction is
> available, this is much better than the table-driven generic
> implementation.
> 
> Tested on loongarch64.
> 
> Signed-off-by: Xi Ruoyao <xry111@xry111.site>

LGTM, thanks.

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

> ---
>  sysdeps/loongarch/math-use-builtins-ffs.h | 2 ++
>  1 file changed, 2 insertions(+)
>  create mode 100644 sysdeps/loongarch/math-use-builtins-ffs.h
> 
> diff --git a/sysdeps/loongarch/math-use-builtins-ffs.h b/sysdeps/loongarch/math-use-builtins-ffs.h
> new file mode 100644
> index 0000000000..a83bb15414
> --- /dev/null
> +++ b/sysdeps/loongarch/math-use-builtins-ffs.h
> @@ -0,0 +1,2 @@
> +#define USE_FFS_BUILTIN   1
> +#define USE_FFSLL_BUILTIN 1
  

Patch

diff --git a/sysdeps/loongarch/math-use-builtins-ffs.h b/sysdeps/loongarch/math-use-builtins-ffs.h
new file mode 100644
index 0000000000..a83bb15414
--- /dev/null
+++ b/sysdeps/loongarch/math-use-builtins-ffs.h
@@ -0,0 +1,2 @@ 
+#define USE_FFS_BUILTIN   1
+#define USE_FFSLL_BUILTIN 1