3 ms·
What's the “corresponding thing” to branch prediction for conditional moves? Is it just speculative execution?
by kzrdude 4y ago
What's the “corresponding thing” to branch prediction for conditional moves? Is it just speculative execution?
- nikic 4y agoAs far as I know there isn't anything like that for cmovs. The cmov depends on the condition, so it will only be executed once the condition is available. Of course, execution can still continue with instructions that don't need the cmov result. And because there is no branch, which instructions get executed does not depend on the cmov condition.
- gpderetta 4y agowell, the point of conditional moves is to avoid speculation. In theory a sophisticated CPU could convert predictable CMOVs to branches (and some non-diverging unpredictable branches to CMOVs), but IIRC Intel has, since Spectre, guaranteed that CMOV itself never triggers speculation.
- masklinn 4y agoThere isn’t one. Branch prediction allows speculative execution, but cmov just blocks. Reordering may allow executing independent instructions which follow the cmov, but anything depending on the cmov will have to wait. It’s one of the reasons compilers avoid cmov relatively aggressively, they can cause pipeline stalls which don’t affect branches.