在 2025/1/17 9:21, H. Peter Anvin 写道:
On 1/16/25 16:37, Ethan Zhao wrote:
hpa suggested to introduce "switch_likely" for this kind of
optimization
on a switch statement, which is also easier to read. I measured it
with
a user space focus test, it does improve performance a lot. But
obviously there are still a lot of work to do.
Find a way to instruct compiler to pick the right hot branch
meanwhile make folks
reading happy... yup, a lot of work.
It's not that complicated, believe it or not.
/*
* switch(v) biased for speed in the case v == l
*
* Note: gcc is quite sensitive to the exact form of this
* expression.
*/
#define switch_likely(v,l) \
switch((__typeof__(v))__builtin_expect((v),(l)))
I know we could play such trick for one branch, never think of there are
2-3 branches
are expected among 7 branches. :) , --- external interrupts, syscall,
page fault.
Thanks,
Ethan
-hpa
--
"firm, enduring, strong, and long-lived"