]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
riscv: bitops: Use riscv_has_extension_likely
authorVivian Wang <wangruikang@iscas.ac.cn>
Tue, 18 Nov 2025 04:19:22 +0000 (21:19 -0700)
committerPaul Walmsley <pjw@kernel.org>
Wed, 19 Nov 2025 16:19:28 +0000 (09:19 -0700)
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-4-ef941c87669a@iscas.ac.cn
Signed-off-by: Paul Walmsley <pjw@kernel.org>
arch/riscv/include/asm/bitops.h

index 77880677b06e03875721f33515a6d2ac9166c373..238092125c1188ba27f8397200c52b33c499c5ee 100644 (file)
@@ -47,9 +47,8 @@
 
 static __always_inline __attribute_const__ unsigned long variable__ffs(unsigned long word)
 {
-       asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
-                                     RISCV_ISA_EXT_ZBB, 1)
-                         : : : : legacy);
+       if (!riscv_has_extension_likely(RISCV_ISA_EXT_ZBB))
+               return generic___ffs(word);
 
        asm volatile (".option push\n"
                      ".option arch,+zbb\n"
@@ -58,9 +57,6 @@ static __always_inline __attribute_const__ unsigned long variable__ffs(unsigned
                      : "=r" (word) : "r" (word) :);
 
        return word;
-
-legacy:
-       return generic___ffs(word);
 }
 
 /**
@@ -76,9 +72,8 @@ legacy:
 
 static __always_inline __attribute_const__ unsigned long variable__fls(unsigned long word)
 {
-       asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
-                                     RISCV_ISA_EXT_ZBB, 1)
-                         : : : : legacy);
+       if (!riscv_has_extension_likely(RISCV_ISA_EXT_ZBB))
+               return generic___fls(word);
 
        asm volatile (".option push\n"
                      ".option arch,+zbb\n"
@@ -87,9 +82,6 @@ static __always_inline __attribute_const__ unsigned long variable__fls(unsigned
                      : "=r" (word) : "r" (word) :);
 
        return BITS_PER_LONG - 1 - word;
-
-legacy:
-       return generic___fls(word);
 }
 
 /**
@@ -105,9 +97,8 @@ legacy:
 
 static __always_inline __attribute_const__ int variable_ffs(int x)
 {
-       asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
-                                     RISCV_ISA_EXT_ZBB, 1)
-                         : : : : legacy);
+       if (!riscv_has_extension_likely(RISCV_ISA_EXT_ZBB))
+               return generic_ffs(x);
 
        if (!x)
                return 0;
@@ -119,9 +110,6 @@ static __always_inline __attribute_const__ int variable_ffs(int x)
                      : "=r" (x) : "r" (x) :);
 
        return x + 1;
-
-legacy:
-       return generic_ffs(x);
 }
 
 /**
@@ -137,9 +125,8 @@ legacy:
 
 static __always_inline int variable_fls(unsigned int x)
 {
-       asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
-                                     RISCV_ISA_EXT_ZBB, 1)
-                         : : : : legacy);
+       if (!riscv_has_extension_likely(RISCV_ISA_EXT_ZBB))
+               return generic_fls(x);
 
        if (!x)
                return 0;
@@ -151,9 +138,6 @@ static __always_inline int variable_fls(unsigned int x)
                      : "=r" (x) : "r" (x) :);
 
        return 32 - x;
-
-legacy:
-       return generic_fls(x);
 }
 
 /**