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

riscv: cmpxchg: Use riscv_has_extension_likely

Use riscv_has_extension_likely() to check for RISCV_ISA_EXT_ZAWRS,
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[no_zawrs]", "nop", ...).

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

authored by

Vivian Wang and committed by
Paul Walmsley
724c6944 6b85e9ac

+4 -8
+4 -8
arch/riscv/include/asm/cmpxchg.h
··· 373 373 u32 *__ptr32b; 374 374 ulong __s, __val, __mask; 375 375 376 - asm goto(ALTERNATIVE("j %l[no_zawrs]", "nop", 377 - 0, RISCV_ISA_EXT_ZAWRS, 1) 378 - : : : : no_zawrs); 376 + if (!riscv_has_extension_likely(RISCV_ISA_EXT_ZAWRS)) { 377 + ALT_RISCV_PAUSE(); 378 + return; 379 + } 379 380 380 381 switch (size) { 381 382 case 1: ··· 438 437 default: 439 438 BUILD_BUG(); 440 439 } 441 - 442 - return; 443 - 444 - no_zawrs: 445 - ALT_RISCV_PAUSE(); 446 440 } 447 441 448 442 #define __cmpwait_relaxed(ptr, val) \