Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

riscv: hweight: Use riscv_has_extension_likely

Use riscv_has_extension_likely() to check for RISCV_ISA_EXT_ZBB,
replacing the use of asm goto with ALTERNATIVE.

The "likely" variant is used to match the behavior of the original
implementation using ALTERNATIVE("j %l[legacy]", "nop", ...).

Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
Link: https://patch.msgid.link/20251020-riscv-altn-helper-wip-v4-3-ef941c87669a@iscas.ac.cn
Signed-off-by: Paul Walmsley <pjw@kernel.org>

authored by

Vivian Wang and committed by
Paul Walmsley
8261a9d1 1c7d491d

+8 -16
+8 -16
arch/riscv/include/asm/arch_hweight.h
··· 19 19 20 20 static __always_inline unsigned int __arch_hweight32(unsigned int w) 21 21 { 22 - #if defined(CONFIG_RISCV_ISA_ZBB) && defined(CONFIG_TOOLCHAIN_HAS_ZBB) 23 - asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0, 24 - RISCV_ISA_EXT_ZBB, 1) 25 - : : : : legacy); 22 + if (!(IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && 23 + IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB) && 24 + riscv_has_extension_likely(RISCV_ISA_EXT_ZBB))) 25 + return __sw_hweight32(w); 26 26 27 27 asm (".option push\n" 28 28 ".option arch,+zbb\n" ··· 31 31 : "=r" (w) : "r" (w) :); 32 32 33 33 return w; 34 - 35 - legacy: 36 - #endif 37 - return __sw_hweight32(w); 38 34 } 39 35 40 36 static inline unsigned int __arch_hweight16(unsigned int w) ··· 46 50 #if BITS_PER_LONG == 64 47 51 static __always_inline unsigned long __arch_hweight64(__u64 w) 48 52 { 49 - #if defined(CONFIG_RISCV_ISA_ZBB) && defined(CONFIG_TOOLCHAIN_HAS_ZBB) 50 - asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0, 51 - RISCV_ISA_EXT_ZBB, 1) 52 - : : : : legacy); 53 + if (!(IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && 54 + IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB) && 55 + riscv_has_extension_likely(RISCV_ISA_EXT_ZBB))) 56 + return __sw_hweight64(w); 53 57 54 58 asm (".option push\n" 55 59 ".option arch,+zbb\n" ··· 58 62 : "=r" (w) : "r" (w) :); 59 63 60 64 return w; 61 - 62 - legacy: 63 - #endif 64 - return __sw_hweight64(w); 65 65 } 66 66 #else /* BITS_PER_LONG == 64 */ 67 67 static inline unsigned long __arch_hweight64(__u64 w)