See two macro functions when looking at the code: likely () unlikely ()
#define LIKELY (x) __builtin_expect (!! (x), 1) #define unlikely (x) __builtin_expect (!! (x), 0)
__builtin_expect () is about processing branch predictions, allowing the compiler to do some optimizations to optimize the possibility of branching programs
if (likely (x))---> indicates that there is a high likelihood of true in if
if (unlikely (x))---Indicates a high likelihood of false in if
Instance:
#include <iostream> #include <string> #include <vector> #include <stdio.h> #define LIKELY (x) __ Builtin_expect (!! (x), 1) #define unlikely (x) __builtin_expect (!! (x), 0) #define BUG_ON (condition) do { if (unlikely (condition)! = 0) printf ("Bug:faile at%s:%d%s ()!\n", __f ile__, __line__, __function__); } while (0) using namespace std;int main (int argc, const char *argv[]) { int i = 7; BUG_ON (i! =); return 0; return 0;}
More information:
http://kernelnewbies.org/FAQ/LikelyUnlikely
Http://linux.chinaunix.net/techdoc/develop/2007/08/31/966838.shtml
I'll see you later when you http://hi.baidu.com/uu_dou/item/e9f6f41d570d817b7a5f25c7http://my.oschina.net/moooofly/blog/175019.
__builtin_except () function in Linux