赞
踩
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
gcc(version 4.4.0)
long __builtin_expect (long exp, long c)
long __builtin_expect (long exp, long c)
You may use __builtin_expect to provide the compiler with branch prediction information. In general, you should prefer to use actual profile feedback for this(‘-fprofile-arcs’), as programmers are notoriously bad at predicting how their programs actually perform. However, there are applications in which this data is hard to collect.
The return value is the value of exp, which should be an integral expression. The value of c must be a compile-time constant. The semantics of the built-in are that it is expected that exp == c
if (likely(...)){
}
if (unlikely(...)){
}
if (xxx){
A;
} else {
B;
}
c;
if (xxx){
A;
goto c; //如果没有c,就直接return了,如果有后续代码c,则跳转回c处运行。
}
B;
c;
* value 值大于0的概率更大,则如下代码
if (value > 0){
A;
} else {
B;
}
或者:
if (value <= 0){
B;
} else {
A;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。