I saw a sentence in a paper “Transforming branches into data dependencies to avoid mispredicted branches.” (Page 6)
I wonder how to change the code from branches into data dependencies.
This is the paper: http://www.adms-conf.org/p1-SCHLEGEL.pdf
Update: How to transform branches in the binary search?
The basic idea (I would presume) would be to change something like:
into:
For branches in a binary search, let’s consider the basic idea of the "normal" binary search, which typically looks (at least vaguely) like this:
We could get rid of most of the branching here in pretty much the same way:
[For general purpose code use
left + (right-left)/2instead of(left+right)/2.]We do still have the branching for the loop itself, of course, but we’re generally a lot less concerned about that–that branch is extremely amenable to prediction, so even if we did eliminate it, doing so would gain little as a rule.