riscv: fix CLZ and CTZ for riscv32 builds (#325)

A previous commit (9ec5df5f) to provide more efficient CLZ (count
leading zeros) and CTZ (count trailing zeros) removed the `__clzsi2` and
`__ctzsi2` symbols, due to a misunderstanding of the types of these and
other library functions expected by GCC's intrinsics. 9ec5df5f broke the
riscv32 build.

This commit corrects the misunderstanding:
- `__clzsi2` and `__ctzsi2` are reinstated with correct types.
- The types of `__clzdi2` and `__ctzdi2` are corrected.
- `__clzti2` and `__ctzti2` are removed, since seL4 contains no compiler
  intrinsics that would require them.
- `clzl` and `ctzl` dispatch to the appropriate library functions based
  on the size of `unsigned long`.
- Configuration options are updated to ensure that the library functions
  are included in the kernel binary only when needed.

Signed-off-by: Matthew Brecknell <Matthew.Brecknell@data61.csiro.au>
This commit is contained in:
Matthew Brecknell
2021-03-30 13:17:16 +11:00
committed by GitHub
parent 2ac4185381
commit 14f2ed7650
4 changed files with 70 additions and 53 deletions

View File

@@ -463,30 +463,26 @@ config_string(
)
config_option(
KernelClzlImpl CLZL_IMPL
"Define a __clzdi2 function to count leading zeros for unsigned long arguments. \
Only needed on platforms which lack a builtin instruction."
KernelClz32 CLZ_32 "Define a __clzsi2 function to count leading zeros for uint32_t arguments. \
Only needed on platforms which lack a builtin instruction."
DEFAULT OFF
)
config_option(
KernelClzllImpl CLZLL_IMPL
"Define a __clzti2 function to count leading zeros for unsigned long long arguments. \
Only needed on platforms which lack a builtin instruction."
KernelClz64 CLZ_64 "Define a __clzdi2 function to count leading zeros for uint64_t arguments. \
Only needed on platforms which lack a builtin instruction."
DEFAULT OFF
)
config_option(
KernelCtzlImpl CTZL_IMPL
"Define a __ctzdi2 function to count trailing zeros for unsigned long arguments. \
Only needed on platforms which lack a builtin instruction."
KernelCtz32 CTZ_32 "Define a __ctzsi2 function to count trailing zeros for uint32_t arguments. \
Only needed on platforms which lack a builtin instruction."
DEFAULT OFF
)
config_option(
KernelCtzllImpl CTZLL_IMPL
"Define a __ctzti2 function to count trailing zeros for unsigned long long arguments. \
Only needed on platforms which lack a builtin instruction."
KernelCtz64 CTZ_64 "Define a __ctzdi2 function to count trailing zeros for uint64_t arguments. \
Only needed on platforms which lack a builtin instruction."
DEFAULT OFF
)