4 ms·
it's arguably more of a cpu bug than a computer bug. The problem is that predictable data determined whether a cmov or a branch is faster. cmov is only faster t
by adgjlsfhk1 3mo ago
it's arguably more of a cpu bug than a computer bug. The problem is that predictable data determined whether a cmov or a branch is faster. cmov is only faster than if when the branch is unpredictable. Summer the compiler doesn't know what values your program will be called with, it can only pick and hope. To fix this, cpus could have an instruction like cmov but that learns whether speculation would be profitable and converts to treat it like a branch if better.
- delamon 3mo agoYou can, in fact, give compiler a hint wether the branch will be predictable or not. E.g. clang has __builtin_unpredictable().
- astrobe_ 3mo agotbh, I'm not sure if we need "more clever" CPUs since they cause more and more unpredictable performance outcome -- and more pressing issues like Spectre. Besides, looking at the evolution of technology tells us that performance increases mainly comes from parallelism, like multicore and GPUs. Which doesn't apply to "annoyingly not parallel" problems of course. But besides "gambling" approaches like branch prediction, there's not much you can do about them in the general case.
- IshKebab 3mo agoThere's no reason CPUs can't do prediction and speculative execution on conditional moves just like they do with conditional branches. But with conditional moves the cost of a misprediction is going to be much lower because you don't have to wait for an instruction fetch.