[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 09/11] RISC-V: Add libgcc helpers for clz
From: |
Alexander Graf |
Subject: |
[PATCH v5 09/11] RISC-V: Add libgcc helpers for clz |
Date: |
Mon, 28 Jan 2019 13:44:45 +0100 |
Gcc may decide it wants to call helper functions to execute clz. Provide
them in our own copy of libgcc.
Signed-off-by: Alexander Graf <address@hidden>
---
grub-core/kern/compiler-rt.c | 42 ++++++++++++++++++++++++++++++++++++++++++
include/grub/compiler-rt.h | 7 +++++++
2 files changed, 49 insertions(+)
diff --git a/grub-core/kern/compiler-rt.c b/grub-core/kern/compiler-rt.c
index 5cfcb3907..404902119 100644
--- a/grub-core/kern/compiler-rt.c
+++ b/grub-core/kern/compiler-rt.c
@@ -417,3 +417,45 @@ __aeabi_llsl (grub_uint64_t u, int b)
__attribute__ ((alias ("__ashldi3")));
#endif
+
+#ifdef __riscv
+
+/* Based on libgcc from gcc suite. */
+int
+__clzsi2 (grub_uint32_t val)
+{
+ int i = 32;
+ int j = 16;
+ int temp;
+
+ for (; j; j >>= 1)
+ {
+ if ((temp = val) >> j)
+ {
+ if (j == 1)
+ {
+ return (i - 2);
+ }
+ else
+ {
+ i -= j;
+ val = temp;
+ }
+ }
+ }
+ return (i - val);
+}
+
+int
+__clzdi2 (grub_uint64_t val)
+{
+ if (val >> 32)
+ {
+ return __clzsi2 (val >> 32);
+ }
+ else
+ {
+ return __clzsi2 (val) + 32;
+ }
+}
+#endif
diff --git a/include/grub/compiler-rt.h b/include/grub/compiler-rt.h
index dc73649a5..2cc69e239 100644
--- a/include/grub/compiler-rt.h
+++ b/include/grub/compiler-rt.h
@@ -108,6 +108,13 @@ EXPORT_FUNC (__aeabi_llsr) (grub_uint64_t u, int b);
#endif
+#ifdef __riscv
+int
+EXPORT_FUNC (__clzsi2) (grub_uint32_t val);
+
+int
+EXPORT_FUNC (__clzdi2) (grub_uint64_t val);
+#endif
#if defined (__powerpc__)
--
2.12.3
- [PATCH v5 00/11] Add RISC-V support, Alexander Graf, 2019/01/28
- [PATCH v5 02/11] PE: Add RISC-V definitions, Alexander Graf, 2019/01/28
- [PATCH v5 03/11] elf.h: Add RISC-V definitions, Alexander Graf, 2019/01/28
- [PATCH v5 01/11] efi: Rename armxx to arch, Alexander Graf, 2019/01/28
- [PATCH v5 05/11] RISC-V: Add early startup code, Alexander Graf, 2019/01/28
- [PATCH v5 09/11] RISC-V: Add libgcc helpers for clz,
Alexander Graf <=
- [PATCH v5 11/11] fdt: Treat device tree file type like ACPI, Alexander Graf, 2019/01/28
- [PATCH v5 07/11] RISC-V: Add awareness for RISC-V reloations, Alexander Graf, 2019/01/28
- [PATCH v5 10/11] RISC-V: Add to build system, Alexander Graf, 2019/01/28
- [PATCH v5 04/11] RISC-V: Add setjmp implementation, Alexander Graf, 2019/01/28
- [PATCH v5 06/11] RISC-V: Add Linux load logic, Alexander Graf, 2019/01/28
- [PATCH v5 08/11] RISC-V: Add auxiliary files, Alexander Graf, 2019/01/28