Hacker News new | ask | show | jobs
by Sesse__ 25 days ago
I'm not sure if you mean to imply so, but the __builtin_expect() hint is not embedded in the instruction stream in any way. It mostly affects basic block layout (and not always in a good way).
1 comments

Newer Intel CPUs (Raptor Lake?) are "adding back" the "branch hint" prefixes. On the Pentium P4, the segment prefixes were repurposed on conditional branches to be branch hints, but then ditched because branch prediction got good. I guess as cores have gotten deeper and deeper it makes sense to bring them back?
Do you have a source? And is there any current compiler that will emit these hints?
Redwood Cove*. It's in the optimization manual (vol 1)[0], section 2.1.1.1. It explicitly references the "SSE2" branch hints (2E and 3E).

[0]: https://cdrdv2.intel.com/v1/dl/getContent/671488

So, it basically says:

  - Do not use them in hot code
  - Use them only if you have PGO (which ignores static hints like __builtin_expect)
  - Use them only if you cannot do it by basic block layout
So it seems very narrow. On top of that, it's only for the P-cores, whose design seems to be on their way out. But thanks, it's good to know nevertheless :-)