3 ms·
Linus made that rant in 2007 [1]. He was right back then for circa 2007 hardware but Intel has improved CMOV quite a bit over the 13 years since. Intel now reco
by CalChris 6y ago
Linus made that rant in 2007 [1]. He was right back then for circa 2007 hardware but Intel has improved CMOV quite a bit over the 13 years since. Intel now recommends CMOV for unpredictable branches in their Intel® 64 and IA-32 Architectures Optimization Reference Manual as 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. Do not use these instructions to eliminate all unpredictable conditional branches (because using these instructions will incur execution overhead due to the requirement for executing both paths of a conditional branch). In addition, converting a conditional branch to SETCC or CMOV trades off control flow dependence for data dependence and restricts the capability of the out-of-order engine. When tuning, note that all Intel 64 and IA-32 processors usually have very high branch prediction rates. Consistently mispredicted branches are generally rare. Use these instructions only if the increase in computation time is less than the expected cost of a mispredicted branch."
NB: Intel is recommending CMOV for unpredictable branches. For well predictable branches, they're recommending ... branches.
[1] https://yarchive.net/comp/linux/cmov.html https://yarchive.net/comp/linux/cmov.html
- throwaway_pdp09 6y agoThat was a dumb oversight on my part not to think to mention this vital point. Thanks. (also thanks for SETcc, I didn't know of this instruction)