LIKELY&UNLIKELY 宏提示编译器做分支预测
Link Share :https://zhiqiang.org/coding/folly-likely-macro.html
- via RSS
folly
的Likely.h
文件提供了 LIKELY 和 UNLIKELY
宏,提示编译器在分支预测时选择分支。其实现很简单:
#define LIKELY(x) (__builtin_expect((x), 1))
#define UNLIKELY(x) (__builtin_expect((x), 0))
用法如下:
#include <folly/likely.h>
int a = 1;
if (LIKELY(a == 1)) {
a = 2;
}
if (UNLIKELY(a == 3)) {
a = 3;
}
只在gcc
下适用。
Tips: Until now, everytime you want to store your article, we will help you store it in Filecoin network. In the future, you can store it in Filecoin network using your own filecoin.
Support author:
Author's Filecoin address:
Or you can use Likecoin to support author: