3 ms·
I don't speak x86. Do you mean that these compilers are evaluating both conditions, all the time? At what optimization level?
by geophile 6y ago
I don't speak x86. Do you mean that these compilers are evaluating both conditions, all the time? At what optimization level?
- edflsafoiewq 6y agoYes, you can check on godbolt. At -O{1,2,3}. At -Os, clang still generates cmovs, but gcc generates a jump.
- benchaney 6y agox86 has instructions that execute conditionally. Most conditionals in higher level languages get compiled to conditional jumps, but using conditional operations this isn't necessary. The same code path is taken in all cases, and the instructions effect is what is conditional. In the case of cmov, it is either a nop or a mov dependent on the state of the conditional flags. Using this construct instead of a regular mov guarded by conditional jumps has better performance in some cases. On my machine gcc is outputting a combination of conditional jumps and conditional movs at all optimization levels