3 ms·
Depends on how predictable the branches are. LLVM used to use CMOVs whenever possible but I believe this was changed a few years back to generally improve perfo
by enigmo 11y ago
Depends on how predictable the branches are. LLVM used to use CMOVs whenever possible but I believe this was changed a few years back to generally improve performance.
See a related bug in GCC: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56309 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56309
"conditional moves instead of compare and branch result in almost 2x slower code"
- lorenzhs 11y agoYeah, easy to predict branches are really cheap. Very non-deterministic, hard-to-predict ones on the other hand are still surprisingly expensive. In such a case, conditional moves might make sense, or sometimes you can also use the result of a comparison in arithmetic operations, something like: idx = 2*idx + (key > table[idx]) (to move a key down an implicitly-stored binary tree)
- a_e_k 11y agoI remember Linus making much the same point: http://yarchive.net/comp/linux/cmov.html http://yarchive.net/comp/linux/cmov.html It generally lines up with what I've observed. Surprisingly, I've found that even arithmetic comparisons like you mentioned ran a bit faster with branches instead of conditional moves. The one case where I have seen comparisons benefit is with SSE code where the comparison results go straight to a register instead of a flag.