4 ms·
The use of previous branch history and branch address as a "context" for prediction reminds me of the very similar technique used for prediction in arithmetic c
by userbinator 9y ago
The use of previous branch history and branch address as a "context" for prediction reminds me of the very similar technique used for prediction in arithmetic compression as used in e.g. JBIG2, JPEG2000, etc. --- the goal being that, if an event X happens several times in context C, then whenever context C occurs, the probability of X is more likely.
Also, since modern CPUs internally have many functional units to which operations can be dispatched, I wonder if, in the case that the "confidence" of a branch prediction is not high, "splitting" the execution stream and executing both branches in parallel until the result is known (or one of the branches encounters another branch...), would yield much benefit over predicting and then having to re-execute the other path if the prediction is wrong. I.e. does it take longer to flush the pipeline and restart on the other path at full rate, or to run both paths in parallel at effectively 1/2 the rate until the prediction is known?
- cwzwarich 9y agoThis wouldn't really buy you much, because after N branches you'd be pursuing 2^N possible execution paths, each of which requires its own resources throughout the CPU, to fetch, decode, rename, schedule, execute, and retire the instructions. Going any deeper than a few branches would be impractical, and you'd be spending most of your resources on computation that doesn't affect the final result. It also doesn't work for indirect branches, unless your predictor can produce a ranked list of possibilities, and you only execute the top few.
- marcosdumay 9y agoSo, if you have low confidence in a short time in too many branches you would lose some performance. But that would happen anyway, you can't optimize low confidence stuff. The GP's question is still a good one. Is doing both branches in parallel better than going superscalar into the slightly more favored one? Is the low confidence situation common enough that it's worth adding the extra circuitry into the CPU.
- buildbot 9y agoPeople has tried this but as other have pointed out, it doesn’t get you very far. Along the same lines is runahead execution which is not directly related to branch prediction, but follows the similar idea you had that if you have all these functional units , you might as well try to figure out what you should start prefetching by speculatly executing the most likely sequence of instructions- even if you are waiting on data for those instructions!
- deepnotderp 9y agoRunahead is a totally different concept though, it attempts to extract MLP and throws away all the work even if it was valid.
- buildbot 9y agoTrue, I was just reminded of it by the original poster’s idea.
- deepnotderp 9y agoFair enough, runahead is a cool idea after all :)
- mjevans 9y agoYou could do it, but 'work' produces heat. From that point of view a branch predictor /saves/ you from spending the heat of the cases you /don't/ need to have processed. The performance per watt of such a design would probably leave it on the back of a napkin as an educated guess of how costly that would be.
- Simon_says 9y agoPie-in-the-sky idea here, but only irreversible computations produce heat. Maybe in the distant future we can make chips that do many parallel computations of all branches reversibly, and only make the results irreversible once the correct branch is known?
- dfox 9y agoIn theory, irreversible computations have to produce heat, while reversible do not. In practice this is mostly irrelevant, because the heat involved is so minuscule that there will always be other significantly larger sources of inefficiency involved. Also it is somewhat questionable whether one could actually construct physical realization of useful logic primitive that is truly reversible.
- deepnotderp 9y agoYes, but functional units are only around ~6% of the power consumption of a modern superscalar processor. And with Moore's law squeaking out its last few iterations, that number will get even smaller. If you can remove a good part of that by using predication, then you actually win out on power and heat as well.
- terryf 9y agoThey do. Video here from 7 years ago that talks about it: https://www.infoq.com/presentations/click-crash-course-modern-hardware https://www.infoq.com/presentations/click-crash-course-moder... Basically, they do speculative execution with register renaming to get quick turn-around if the memory is available in cache. It really is quite crazy how much faster the cpu is than memory and what tricks it pulls to get around that problem.
- deepnotderp 9y agoYou're thinking of predication, also sometimes called "if- conversion" or more loosely, speculation It's very useful for getting rid of small control flow that doesn't really change the path of execution much, but doing it for too long is impossible due to the exponential complexity.
- jasonwatkinspdx 9y ago> Also, since modern CPUs internally have many functional units to which operations can be dispatched, I wonder if, in the case that the "confidence" of a branch prediction is not high, "splitting" the execution stream and executing both branches in parallel until the result is known... This is called disjoint eager execution: http://dl.acm.org/citation.cfm?id=225208 http://dl.acm.org/citation.cfm?id=225208 What killed the idea is that branch predictors are simply too good. You'd end up almost never speculating off the main spine the predictor gives you, and so all the other machinery needed doesn't provide nearly enough value for its cost.