[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250820-riscv-altn-helper-wip-v1-4-c3c626c1f7e6@iscas.ac.cn>
Date: Wed, 20 Aug 2025 21:44:48 +0800
From: Vivian Wang <wangruikang@...as.ac.cn>
To: Paul Walmsley <paul.walmsley@...ive.com>,
Palmer Dabbelt <palmer@...belt.com>, Albert Ou <aou@...s.berkeley.edu>,
Alexandre Ghiti <alex@...ti.fr>, Yury Norov <yury.norov@...il.com>,
Rasmus Villemoes <linux@...musvillemoes.dk>
Cc: Vivian Wang <wangruikang@...as.ac.cn>, Vivian Wang <uwu@...m.page>,
linux-riscv@...ts.infradead.org, linux-kernel@...r.kernel.org
Subject: [PATCH 4/6] riscv: hweight: Convert to use_alternative_likely
Use use_alternative_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@...as.ac.cn>
---
arch/riscv/include/asm/arch_hweight.h | 42 +++++++++++++++--------------------
1 file changed, 18 insertions(+), 24 deletions(-)
diff --git a/arch/riscv/include/asm/arch_hweight.h b/arch/riscv/include/asm/arch_hweight.h
index 0e7cdbbec8efd3c293da2fa96a8c6d0a93faf56f..58ed7a3b2d7882f6a7913c4bfdb9bce4a4394956 100644
--- a/arch/riscv/include/asm/arch_hweight.h
+++ b/arch/riscv/include/asm/arch_hweight.h
@@ -20,20 +20,17 @@
static __always_inline unsigned int __arch_hweight32(unsigned int w)
{
#if defined(CONFIG_RISCV_ISA_ZBB) && defined(CONFIG_TOOLCHAIN_HAS_ZBB)
- asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
- RISCV_ISA_EXT_ZBB, 1)
- : : : : legacy);
+ if (use_alternative_likely(0, RISCV_ISA_EXT_ZBB)) {
+ asm (".option push\n"
+ ".option arch,+zbb\n"
+ CPOPW "%0, %1\n"
+ ".option pop\n"
+ : "=r" (w) : "r" (w) :);
- asm (".option push\n"
- ".option arch,+zbb\n"
- CPOPW "%0, %1\n"
- ".option pop\n"
- : "=r" (w) : "r" (w) :);
-
- return w;
-
-legacy:
+ return w;
+ }
#endif
+
return __sw_hweight32(w);
}
@@ -51,20 +48,17 @@ static inline unsigned int __arch_hweight8(unsigned int w)
static __always_inline unsigned long __arch_hweight64(__u64 w)
{
#if defined(CONFIG_RISCV_ISA_ZBB) && defined(CONFIG_TOOLCHAIN_HAS_ZBB)
- asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
- RISCV_ISA_EXT_ZBB, 1)
- : : : : legacy);
+ if (use_alternative_likely(0, RISCV_ISA_EXT_ZBB)) {
+ asm (".option push\n"
+ ".option arch,+zbb\n"
+ "cpop %0, %1\n"
+ ".option pop\n"
+ : "=r" (w) : "r" (w) :);
- asm (".option push\n"
- ".option arch,+zbb\n"
- "cpop %0, %1\n"
- ".option pop\n"
- : "=r" (w) : "r" (w) :);
-
- return w;
-
-legacy:
+ return w;
+ }
#endif
+
return __sw_hweight64(w);
}
#else /* BITS_PER_LONG == 64 */
--
2.50.1
Powered by blists - more mailing lists