3 ms·
I dunno what you mean by CMOV vs “no” branches. However, CMOV is single cycle latency in Kaby Lake. Also, I don’t know if those data dependencies wouldn’t also
by CalChris 9y ago
I dunno what you mean by CMOV vs “no” branches.
However, CMOV is single cycle latency in Kaby Lake. Also, I don’t know if those data dependencies wouldn’t also cause similar problems for resolving a conditional branch.
It may be possible to construct a scenario where CMOV is marginally slower but I think we can put Linus Torvalds’ CMOV rant in the bit bucket. Intel recommends CMOV with a proviso. Assembly/Compiler Coding Rule 2:
Use the SETCC and CMOV instructions to eliminate
unpredictable conditional branches where possible.
Do not do this for predictable branches.
The Intel C Compiler uses it.
- TwoBit 9y agoDid Intel disprove Linus?
- CalChris 9y agoObviate would be a better choice of word.
- tedunangst 9y agoSomething like X = flag ? X : 0; X = test ? X : 0; Vs X |= flag; X |= test; The latter is more obviously branch less. How exactly the two perform probably requires some testing. And somewhat more general point, since we're writing C and not asm, depends how much you want to depend on the compiler to use the right instructions. To backtrack on my point a bit, whether CMOV gets used is an important consideration. > There's a chance that when inlined into the benchmark Clang uses a CMOV And a chance it won't. :)