3 ms·
I'm vaguely aware of this, but also honestly surprised the CPU isn't speculating on the move anyway.
by Filligree 5y ago
I'm vaguely aware of this, but also honestly surprised the CPU isn't speculating on the move anyway.
- gpderetta 5y agoIn principle it could. But A) it would be a bit pointless because cmov is used to avoid badly predictable branches and B) IIRC after the whole spectre affair Intel gave the guarantee that cmov is never speculated. Regarding A, you could have a meta predictor that decides whether you should speculate or not, trained on the misprediciton rate. But then you do not need the cmov in the first place and you can just dynamically convert non-diverging jumps to predication. This is, I think, called Dynamic Hammock Predication and was implemented, in some restricted cases (IIRC jumping over a single instruction) in some recent POWER cpus from IBM. I think that RISC-V also doesn't have predication and an implementation is supposed to use this optimization instead.