3 ms·
Branchy code where the branches are statically known to be very unlikely ought to be practically as fast as the branch-free equivalent. You're probably forgoing
by zozbot234 7y ago
Branchy code where the branches are statically known to be very unlikely ought to be practically as fast as the branch-free equivalent. You're probably forgoing a few optimization opportunities since you do have to build a proper exception record (and perhaps a stack trace) if the code errors out but other than that, it just doesn't matter that much.
- mhh__ 7y agoStatic branch prediction isn't found on any major architectures, right? You can optimize the code generation around that knowledge but not passing it directly to the CPU
- chrisseaton 7y ago> Static branch prediction isn't found on any major architectures, right? All major AMD and Intel processors do static branch prediction.
- hrydgard 7y agoIt is absolutely done, it's just implicit rather than explicit. The simplest heuristic is to predict backwards branches as taken (loops) and forward branches as not taken, and it works quite well (though I think it might be more sophisticated than that).
- ncmncm 7y agoOf course the error-code checking branches will most usually be forward branches, thus not predicted correctly the first time through, or after spilling.
- ncmncm 7y agoBranchy checks for error codes -- the alternative to using exceptions -- are not statically predictable. Each such branch is dynamically predictable, but burns one of a strictly limited number of available branch prediction slots. So, while the successfully predicted branches are pretty cheap, many fewer can be predicted. Synthetic benchmarks generally have many fewer branches to predict than live code has.