6 ms·
Cmov is, and was, efficient whenever branch prediction is unreliable. Clang will turn eligible ?: expressions into cmov. Gcc will do no more than one of those
by ncmncm 5y ago
Cmov is, and was, efficient whenever branch prediction is unreliable.
Clang will turn eligible ?: expressions into cmov. Gcc will do no more than one of those per basic block, subject to fragile conditions. Gcc got its fingers badly burned by overuse of cmov. [Edit: I am wrong! Gcc would not do it when I was trying. More research needed.]
Generally, branches break dependency chains, enabling more implicit speculative parallelism. Older cores stuck cmov ops onto dependency chains, where more recently they are treated more like branches. That gives you less speculative evaluation, but consumes less state that would be discarded on a mis-predicted branch.