Originally posted by: MartinCracauer
Originally posted by: LithographWoker
The work of the Branch Prediction unit in Intel processors with NetBurst architecture is based on the work with Branch target Buffer (BTB). It is a 4KB buffer storing the statistics about the already complete branching. In other words, Intel?s branch prediction is based on a probabilistic model: the CPU evaluates a given branch as preferable or not in each particular case according to the collected statistical data. This algorithm proved very efficient, however, it turns out absolutely useless if there is no statistics about a certain branch. The Northwood based CPUs selected a ?backward? branch in this case, considering that quitting cycles is the most widely spread branch
You can also tell the CPU which one is more likely, but I am not aware of a compiler doing that (because the compiler likely doesn't know either, except maybe for exception where it can assume the exception won't be thrown).
However, Intel documents what will be assumed by default so that you can put the more probable code into the branch that it assumes is more probable. This of course will be useless once this decision ends up in the cache.
That is all fine but really, for Pentium-3s, Pentium-Ms and AMDs I don't have to do any of this nonsense to get good performance. Why would I invest time into doing this optimization if the result is only required for the biggest power hog on the market which will never end up in our datacenter racks?