Remix.run Logo
gpderetta 2 days ago

A few ISAs have used branch prediction hints but they have gone out of fashion (those on x86 are now ignored for example).

imtringued 2 days ago | parent [-]

They are useless because the compiler can simply lay out the code so that the most likely path doesn't trigger the branch and executes the code sequentially.

The pipeline has already loaded these instructions anyway, so continuing execution costs nothing. You then only need to predict the exceptional cases that do trigger the branch.

This means the only use case for branch prediction hints is for use cases where the most likely branch is changing at runtime. That is such a niche use case that it is never worth it. If you do need this, then you are better off investing into JIT instead of changing the ISA.

eigenform 2 days ago | parent [-]

Yep, you typically don't see it because we learned that it's easier to just assume that the default prediction is "not-taken."

AFAICT if you're hinting that a branch is biased-taken, really the only thing you might be doing is avoiding potential latency/incorrect speculation that comes with an initial misprediction (when you discover a branch that isn't currently being tracked). I think it's basically just an injunction to "don't wait for a misprediction, just install this branch in your BTB immediately" (or something along those lines).