r/programming • u/chaobang • Aug 22 '26
The unlikely Linux macro
https://rushed-reflections.bearblog.dev/an-unlikely-experiment/Wrote a bit about the `unlikely` and `likely` macros in the Linux codebase. Great little exploration into tiny optimizations that everyone should know more about 😄
188
Upvotes
View all comments
Show parent comment
2
u/cdb_11 Aug 24 '26
Both are fine in a high-level language. It's about the actual asm. The compiler should ideally arrange the branches in such way so the more likely branch is a fall through the conditional branch.
And it's the opposite for backward jumps, like in loops. When the label appears before the conditional jump.