Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


Something 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. :)


Did Intel disprove Linus?


Obviate would be a better choice of word.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: