From: Yury Norov <yury.norov@gmail.com>
To: Vivian Wang <wangruikang@iscas.ac.cn>
Cc: Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Vivian Wang <uwu@dram.page>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 5/6] riscv: bitops: Convert to use_alternative_likely
Date: Wed, 20 Aug 2025 11:04:31 -0400 [thread overview]
Message-ID: <aKXj_zTwvk0SwUpV@yury> (raw)
In-Reply-To: <20250820-riscv-altn-helper-wip-v1-5-c3c626c1f7e6@iscas.ac.cn>
On Wed, Aug 20, 2025 at 09:44:49PM +0800, Vivian Wang wrote:
> 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@iscas.ac.cn>
> ---
> arch/riscv/include/asm/bitops.h | 112 ++++++++++++++++++----------------------
> 1 file changed, 50 insertions(+), 62 deletions(-)
>
> diff --git a/arch/riscv/include/asm/bitops.h b/arch/riscv/include/asm/bitops.h
> index d59310f74c2ba70caeb7b9b0e9221882117583f5..0257d547a96293909d90b017c8a48b508d0fd642 100644
> --- a/arch/riscv/include/asm/bitops.h
> +++ b/arch/riscv/include/asm/bitops.h
> @@ -47,20 +47,17 @@
>
> static __always_inline unsigned long variable__ffs(unsigned long word)
> {
> - asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
> - RISCV_ISA_EXT_ZBB, 1)
> - : : : : legacy);
> -
> - asm volatile (".option push\n"
> - ".option arch,+zbb\n"
> - "ctz %0, %1\n"
> - ".option pop\n"
> - : "=r" (word) : "r" (word) :);
> -
> - return word;
> -
> -legacy:
> - return generic___ffs(word);
> + if (use_alternative_likely(0, RISCV_ISA_EXT_ZBB)) {
I don't think that 'likely' is used properly here. The likely/unlikely
wording has a meaning of a hint to the compiler:
if (unlikely(WARN_ON(cond))
goto err;
In your case, it's just meaningless, because whatever is 'likely' for
one CPU, will be always 'unlikely' for another.
> + asm volatile (".option push\n"
> + ".option arch,+zbb\n"
> + "ctz %0, %1\n"
> + ".option pop\n"
> + : "=r" (word) : "r" (word) :);
> +
> + return word;
> + } else {
> + return generic___ffs(word);
> + }
> }
This tabs wipe most of the history. Can you reorganize your patch
such that it preserves as much history as you can?
if (use_alternative_unlikely(...))
return generic___ffs();
asm volatile (".option push\n"
".option arch,+zbb\n"
"ctz %0, %1\n"
".option pop\n"
: "=r" (word) : "r" (word) :);
return word;
And so on.
Thanks,
Yury
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2025-08-20 18:26 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-20 13:44 [PATCH 0/6] riscv: Add helpers use_alternative_{likely,unlikely} Vivian Wang
2025-08-20 13:44 ` [PATCH 1/6] riscv: Introduce use_alternative_{likely,unlikely} Vivian Wang
2025-08-20 14:56 ` Yury Norov
2025-08-20 15:25 ` Vivian Wang
2025-08-20 15:43 ` Yury Norov
2025-08-20 16:41 ` Vivian Wang
2025-08-20 13:44 ` [PATCH 2/6] riscv: pgtable: Convert to use_alternative_unlikely Vivian Wang
2025-08-20 13:44 ` [PATCH 3/6] riscv: checksum: Convert to use_alternative_likely Vivian Wang
2025-08-20 13:44 ` [PATCH 4/6] riscv: hweight: " Vivian Wang
2025-08-20 13:44 ` [PATCH 5/6] riscv: bitops: " Vivian Wang
2025-08-20 15:04 ` Yury Norov [this message]
2025-08-20 15:36 ` Vivian Wang
2025-08-20 13:44 ` [PATCH 6/6] riscv: cmpxchg: " Vivian Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aKXj_zTwvk0SwUpV@yury \
--to=yury.norov@gmail.com \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux@rasmusvillemoes.dk \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=uwu@dram.page \
--cc=wangruikang@iscas.ac.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).