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,
"Aydın Mercan" <aydin@mercan.dev>
Subject: Re: [PATCH 1/6] riscv: Introduce use_alternative_{likely,unlikely}
Date: Wed, 20 Aug 2025 11:43:00 -0400 [thread overview]
Message-ID: <aKXtBJ5Aqqmvdc1B@yury> (raw)
In-Reply-To: <544577b2-6810-4bef-b588-e1c662d5be13@iscas.ac.cn>
> > This 'unlikely' version is just an negation of 'likely' one, and it
> > looks like an attempt to save on one negation. On the other hand, the
> > function is __always_inline, which means that compiler should normally
> > take care of it. Can you prove with objdump that it really works as
> > intended? I mean that
> >
> > if (use_alternative_unlikely())
> > do_something();
> >
> > generates a better code than
> >
> > if (!use_alternative_likely())
> > do_something();
>
> use_alternative_likely() and use_alternative_unlikely() are not
> negations of each other and in fact should be functionally equivalent. I
> also briefly explained the difference in the comment, but the difference
> is which case is nop i.e. fallthrough, and which case requires a jump
> instruction. The likely case should get a "nop", and the unlikely case
> should get a "j %l[...]". This choice does work as intended [1].
>
> I don't think it is possible to give both options to the compiler, so at
> least for now AIUI users have to pick one.
>
> The same applies to __riscv_has_extension_{likely,unlikely}.
>
> Vivian "dramforever" Wang
>
> [1]: https://godbolt.org/z/v8zTEhzTx
I realize that likely and unlikely versions generate different code,
I'm just not convinced that
1. it works in real kernel as intended, not only in the godbold; and
2. has any measurable impact.
That's why I asked you to share objdump and possibly perf tests.
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
WARNING: multiple messages have this Message-ID (diff)
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,
"Aydın Mercan" <aydin@mercan.dev>
Subject: Re: [PATCH 1/6] riscv: Introduce use_alternative_{likely,unlikely}
Date: Wed, 20 Aug 2025 11:43:00 -0400 [thread overview]
Message-ID: <aKXtBJ5Aqqmvdc1B@yury> (raw)
In-Reply-To: <544577b2-6810-4bef-b588-e1c662d5be13@iscas.ac.cn>
> > This 'unlikely' version is just an negation of 'likely' one, and it
> > looks like an attempt to save on one negation. On the other hand, the
> > function is __always_inline, which means that compiler should normally
> > take care of it. Can you prove with objdump that it really works as
> > intended? I mean that
> >
> > if (use_alternative_unlikely())
> > do_something();
> >
> > generates a better code than
> >
> > if (!use_alternative_likely())
> > do_something();
>
> use_alternative_likely() and use_alternative_unlikely() are not
> negations of each other and in fact should be functionally equivalent. I
> also briefly explained the difference in the comment, but the difference
> is which case is nop i.e. fallthrough, and which case requires a jump
> instruction. The likely case should get a "nop", and the unlikely case
> should get a "j %l[...]". This choice does work as intended [1].
>
> I don't think it is possible to give both options to the compiler, so at
> least for now AIUI users have to pick one.
>
> The same applies to __riscv_has_extension_{likely,unlikely}.
>
> Vivian "dramforever" Wang
>
> [1]: https://godbolt.org/z/v8zTEhzTx
I realize that likely and unlikely versions generate different code,
I'm just not convinced that
1. it works in real kernel as intended, not only in the godbold; and
2. has any measurable impact.
That's why I asked you to share objdump and possibly perf tests.
next prev parent reply other threads:[~2025-08-20 18:58 UTC|newest]
Thread overview: 28+ 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 ` Vivian Wang
2025-08-20 13:44 ` [PATCH 1/6] riscv: Introduce use_alternative_{likely,unlikely} Vivian Wang
2025-08-20 13:44 ` Vivian Wang
2025-08-20 14:56 ` Yury Norov
2025-08-20 14:56 ` Yury Norov
2025-08-20 15:25 ` Vivian Wang
2025-08-20 15:25 ` Vivian Wang
2025-08-20 15:43 ` Yury Norov [this message]
2025-08-20 15:43 ` Yury Norov
2025-08-20 16:41 ` Vivian Wang
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 ` Vivian Wang
2025-10-02 16:29 ` ChaosEsque Team
2025-10-02 16:29 ` ChaosEsque Team
2025-08-20 13:44 ` [PATCH 3/6] riscv: checksum: Convert to use_alternative_likely Vivian Wang
2025-08-20 13:44 ` Vivian Wang
2025-08-20 13:44 ` [PATCH 4/6] riscv: hweight: " Vivian Wang
2025-08-20 13:44 ` Vivian Wang
2025-08-20 13:44 ` [PATCH 5/6] riscv: bitops: " Vivian Wang
2025-08-20 13:44 ` Vivian Wang
2025-08-20 15:04 ` Yury Norov
2025-08-20 15:04 ` Yury Norov
2025-08-20 15:36 ` Vivian Wang
2025-08-20 15:36 ` Vivian Wang
2025-08-20 13:44 ` [PATCH 6/6] riscv: cmpxchg: " Vivian Wang
2025-08-20 13:44 ` 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=aKXtBJ5Aqqmvdc1B@yury \
--to=yury.norov@gmail.com \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=aydin@mercan.dev \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.