Hacker News new | ask | show | jobs
by kevin_thibedeau 21 days ago
You should prefer using the standardized likely/unlikely attributes instead.
1 comments

Branchless programming is a thing because those don't work, and branch prediction hurts performance on many cases
I think -- I know -- that you have misunderstood what branch prediction is.

Maybe you are asking for way to do static branch prediction for selected conditional branches instead of dynamic branch prediction (or as a supplement)? That's the most charitable way I can interpret your comments.

That is already part of the x86 architecture. Intel introduced it back in the Pentium 4 days. It takes the form of an extra prefix byte that hints the branch as "taken" or "not taken". The trick to doing it in a backwards compatible way is that they reuse the segment override prefixes (CS and DS). These hints are ignored on modern CPUs -- except maybe on some very new Intel CPUs? They are ignored because the dynamic branch predictor works better.