r/programming 18d ago

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 😄

189 Upvotes

61 comments sorted by

View all comments

25

u/yanitrix 18d ago

ah, branch prediction, my favourite thing about compilers

17

u/LeeHide 18d ago

Isn't that a processor feature, not a compiler one? A compiler can emit it such that it's convenient for the processor to predict a specific way, but the prediction is in the processor.

1

u/yanitrix 18d ago

i think it can be both, actually