RISC-V: Use builtins for ffs and ffsll while supported extension available

Message ID 20240619064342.10423-2-jz531210@gmail.com (mailing list archive)
State Superseded
Headers
Series RISC-V: Use builtins for ffs and ffsll while supported extension available |

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 Build passed
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Test passed

Commit Message

Julian Zhu June 19, 2024, 6:43 a.m. UTC
  Hardware `ctz`/`ctzw` instructions are available in the RISC-V Zbb extension, and the `ctz` instruction `th.ff1` is available in the RISC-V XTheadBb extension. We can  get more simplified code compared to the generic implement of `ffs`/`ffsll`.

Signed-off-by: Julian Zhu <jz531210@gmail.com>
---
 sysdeps/riscv/math-use-builtins-ffs.h | 7 +++++++
 1 file changed, 7 insertions(+)
 create mode 100644 sysdeps/riscv/math-use-builtins-ffs.h
  

Comments

Andreas Schwab June 19, 2024, 7:30 a.m. UTC | #1
On Jun 19 2024, Julian Zhu wrote:

> \ No newline at end of file

Please fix that.
  

Patch

diff --git a/sysdeps/riscv/math-use-builtins-ffs.h b/sysdeps/riscv/math-use-builtins-ffs.h
new file mode 100644
index 0000000000..62408e23e0
--- /dev/null
+++ b/sysdeps/riscv/math-use-builtins-ffs.h
@@ -0,0 +1,7 @@ 
+#if defined __riscv_zbb
+#define USE_FFS_BUILTIN   1
+#define USE_FFSLL_BUILTIN 1
+#elif __riscv_xtheadbb
+#define USE_FFS_BUILTIN   0
+#define USE_FFSLL_BUILTIN 1
+#endif
\ No newline at end of file