]> www.infradead.org Git - nvme.git/commit
riscv: Optimize bitops with Zbb extension
authorXiao Wang <xiao.w.wang@intel.com>
Tue, 31 Oct 2023 06:45:53 +0000 (14:45 +0800)
committerPalmer Dabbelt <palmer@rivosinc.com>
Thu, 9 Nov 2023 18:15:52 +0000 (10:15 -0800)
commit457926b253200bd9bdfae9a016a3b1d1dc661d55
tree28d569b7577836d8163a8ebc37f67bbf5524749e
parente72c4333d2f2e7f2200f71a88c0480fd2a769a64
riscv: Optimize bitops with Zbb extension

This patch leverages the alternative mechanism to dynamically optimize
bitops (including __ffs, __fls, ffs, fls) with Zbb instructions. When
Zbb ext is not supported by the runtime CPU, legacy implementation is
used. If Zbb is supported, then the optimized variants will be selected
via alternative patching.

The legacy bitops support is taken from the generic C implementation as
fallback.

If the parameter is a build-time constant, we leverage compiler builtin to
calculate the result directly, this approach is inspired by x86 bitops
implementation.

EFI stub runs before the kernel, so alternative mechanism should not be
used there, this patch introduces a macro NO_ALTERNATIVE for this purpose.

Signed-off-by: Xiao Wang <xiao.w.wang@intel.com>
Reviewed-by: Charlie Jenkins <charlie@rivosinc.com>
Link: https://lore.kernel.org/r/20231031064553.2319688-3-xiao.w.wang@intel.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/include/asm/bitops.h
drivers/firmware/efi/libstub/Makefile