3 ms·
> branches are usually superior to conditional moves for predictable conditions as they break dependency chains. Interesting, not heard that before. Do you kno
by abainbridge 7y ago
> branches are usually superior to conditional moves for predictable conditions as they break dependency chains.
Interesting, not heard that before. Do you know of somewhere I can read about this?
- gpderetta 7y agoAgner Fog is the usual go-to reference. For this specific case, you can also google any of Linus rants on conditional moves (they used to be very high latency, although today they are not so much of an issue). This one for example: https://yarchive.net/comp/linux/cmov.html https://yarchive.net/comp/linux/cmov.html
- abainbridge 7y agoNice. Like every other topic, there's more complexity if you keep looking harder.
- ncmncm 7y agoIt is complicated to describe when cmov is slow and when it is fast. As a rule of thumb, if the next loop iteration data operations depend on a cmov in this one, and around, cmov will be slow. If not, it is very, very fast. Use of cmov can make quicksort 2x as fast. Gcc absolutely won't generate two cmov instructions in a basic block. Clang, for its part, abandons practically all optimization of loops that could conceivably generate a throw.