On 12/2/25 04:57, Yao Zi wrote:
On Mon, Dec 01, 2025 at 06:49:03PM +0100, Heinrich Schuchardt wrote:
The following functions are provided:
Count leading zero bits
* int __clzsi2 (unsigned int a)
* int __clzdi2 (unsigned long a)
* int __clzti2 (unsigned long long a)
Count trailing zero bits
* int __ctzsi2 (unsigned int a)
* int __ctzdi2 (unsigned long a)
* int __ctzti2 (unsigned long long a)
Signed-off-by: Heinrich Schuchardt <[email protected]>
---
I noted there's another series with the same subject[1] sent almost at
the same time, and I couldn't tell the difference at the first glance.
Is this an incident?
Thank you for reviewing.
That was my mistake. I have set the first mail series [1] to superseded
in Patchwork.
arch/Kconfig | 1 +
arch/riscv/lib/Makefile | 2 +
arch/riscv/lib/clz.c | 105 ++++++++++++++++++++++++++++++++++++++++
arch/riscv/lib/ctz.c | 95 ++++++++++++++++++++++++++++++++++++
lib/Kconfig | 2 +-
5 files changed, 204 insertions(+), 1 deletion(-)
create mode 100644 arch/riscv/lib/clz.c
create mode 100644 arch/riscv/lib/ctz.c
diff --git a/arch/Kconfig b/arch/Kconfig
index 3133f892f94..4af0da2485f 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -159,6 +159,7 @@ config PPC
config RISCV
bool "RISC-V architecture"
select CREATE_ARCH_SYMLINK
+ select HAVE_PRIVATE_LIBGCC if 64BIT
Are 32-bit platforms excluded for lacking of enough library functions?
Should we exclude !RISCV_ISA_F || !RISCV_ISA_D platforms as well? Though
there's no in-tree 64-bit port without F/D extension.
As I am not aware of any RVA23 distro for 32bit RISC-V, I see no current
need.
32-bit support will require additionally implementing __ashldi3,
__lshldi3, __udivdi3.
If you want to implement these extra functions, you cannot trust the
documentation. The functions don't take the arguments described in
https://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html. E.g
__ashldi3 expects a 64 bit value passed in registers a0 (low bits), a1
(high bits) while the shift is passed in a2. 32-bit __udivdi3 expects
two 64-bit values.
See
https://github.com/gcc-mirror/gcc/blob/addda4a7e8593c37c90eb4c1d7edda29fa4bde31/libgcc/libgcc2.c#L412
libgcc is published under GPL-3 and therefore we cannot simply copy that
code into our GPL-2 project.
Best regards
Heinrich
select HAVE_SETJMP
select HAVE_INITJMP
select SUPPORT_ACPI
Regards,
Yao Zi
[1]: https://lore.kernel.org/u-boot/[email protected]/