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/not_a_novel_account Aug 23 '26
None of this has anything to do with branch prediction. It impacts instruction layout which affects pipelining and icache performance.
You absolutely should use hints to tell the compiler which branch is hot and which is cold, unless you're already using PGO to feed it the same information. LLVM and GCC do not have good heuristics for figuring this out unguided.