Conditional moves vs. branching in unrolled loops
Paul Sandoz
paul.sandoz at oracle.com
Wed Jan 6 15:01:52 UTC 2016
> On 6 Jan 2016, at 15:45, Vitaly Davidovich <vitalyd at gmail.com> wrote:
>
> Ok. The generated code for an unrolled loop firsts load array elements into registers before performing the cmovs.
>
> Yes, but the cmov cannot proceed until that load retires. If you had a normal branch, speculation can continue past the branch and put more instructions into the pipeline barring other hazards/dependencies. By "available in registers" I meant a cmov executed against 2 values in registers that are already available (i.e. the loads which put the values into registers have already completed, or the registers were set with immediates, etc).
>
> Basically, if the cost of branch misprediction is higher than waiting for both inputs to cmov to be available, then cmov is better. For very predictable branches, cmov is a loss (as we've already established in this thread) and I think always will be (i.e. cpu vendors seem to be putting more and more smarts into branch prediction instead).
>
Thanks for the explanations. It’s helpful.
> Yes, that was me not understanding the underlying branch profiling mechanisms.
>
> Actually, that question of mine was more aimed at John who said we should do something special for loops with max/min accumulators :).
>
Oh, ok :-)
Paul.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20160106/05726465/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 841 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20160106/05726465/signature.asc>
More information about the hotspot-compiler-dev
mailing list