Are there any perfomance test results for usage of likely/unlikely hints?

gcc features likely/unlikely hints that help the compiler to generate machine code with better branch prediction.

Is there any data on how proper usage or failure to use those hints affects performance of real code on some real systems?


The question differs, but Peter Cordes's answer on this question gives a clear hint ;) . Modern CPU's ignore static hints and use dynamic branch prediction.


I don't know of any thorough analysis of such particular hints. In any case, it would be extremely CPU-specific. In general, if you are sure about the likelyhood (eg, > 90%) then it is probably worthwhile to add such annotations, although improvements will vary a lot with the specific use case.

Modern Desktop CPUs tend to have very good branch prediction. If your code is on a hot path anyway, the dynamic branch predictor will quickly figure out that the branch is biased on its own. Such hints are mainly useful to help the static predictor which kicks in if no dynamic branch information is available.

On x86, the static predictor predicts forward branches not to be taken and backward branches to be taken (since they usually indicate loops). The compiler will therefore adjust static code layout to match the predictions. (This may also help putting the hot path on adjacent cache lines, which may help further.)

On PPC, some jump instructions have a bit to predict their likelyhood. I don't know if the compiler will rearrange code, too.

I don't know how ARM CPUs predict branches. As a low-power device it may have less sophisticated branch prediction and static prediction could have more impact.

链接地址: http://www.djcxy.com/p/9340.html

上一篇: 是否可以将调试器附加到正在运行的PHP进程?

下一篇: 有没有使用可能/不可能提示的性能测试结果?