riscv: more efficient clz and ctz

For RISC-V platforms that do not provide machine instructions to count
leading and trailing zeros, this commit includes more efficient library
functions. For verification, we expose the bodies of the functions to
the proofs.

Kernel config options `CLZ_BUILTIN` and `CTZ_BUILTIN` allow selection of
whether compiler builtin functions should be used. These are only
supported on platforms where the builtin compiles to inline assembly. By
default, the options are on for all platforms except RISC-V.

Signed-off-by: Matthew Brecknell <Matthew.Brecknell@data61.csiro.au>
This commit is contained in:
Matthew Brecknell
2020-08-03 23:22:02 +10:00
parent 2a0e5a2a1f
commit 9ec5df5fa8
6 changed files with 462 additions and 59 deletions

View File

@@ -462,4 +462,46 @@ config_string(
DEPENDS "KernelIsMCS" UNDEF_DISABLED
)
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."
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."
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."
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."
DEFAULT OFF
)
config_option(
KernelClzNoBuiltin CLZ_NO_BUILTIN
"Expose implementations of clzl and clzll to verification by avoiding the use \
of __builtin_clzl and __builtin_clzll."
DEFAULT OFF
)
config_option(
KernelCtzNoBuiltin CTZ_NO_BUILTIN
"Expose implementations of ctzl and ctzll to verification by avoiding the use \
of __builtin_ctzl and __builtin_ctzll."
DEFAULT OFF
)
add_config_library(kernel "${configure_string}")