On 08/14/2018 03:36 PM, 2016 quekong wrote:
And Intel seems don't want to talk about it any more, because the latest material I found within Intel Document was written about ten years ago.
Since branch prediction is nowadays a security feature, I doubt you will see detailed public documentation from any processor manufacturer.
I know static branch prediction is (far?) less important than dynamic, but in quite a few situations, CPU will be completely lost and programmers(with compiler) are usually the best guide. Of course these situations are usually not performance bottleneck, because once a branch is frequently executed, the dynamic predictor will capture it.
There is a movement to replace table-driven stack unwinding with a conditional branch after most function calls, and those branches should predict really well statically. (And so would return value checks for almost all POSIX functions.) Statically predicting those branches as not taken may free up branch prediction resources for other uses.
On the other hand, programmers tend to misuse __builtin_expect to say that something is unlikely to happen, while it can happen quite regularly during certain executions of the program. So if __builtin_expect results in static hints from the compiler, the CPU will be better off ignoring those hints in most cases.
Thanks, Florian