gcc - __builtin_expect 来自 GCC 的概率

程序员可以使用来自 GCC 的

__builtin_expect 来显示哪些变体预计会经常出现,哪些变体很少见。但是 __builtin_expect 只有“真”和“假”(0% 或 100% 概率)

对于一些大型项目,很难获得配置文件反馈(-fprofile-arcs),有时程序员确实知道,他在程序的某个点有多大的分支概率。

可以提示编译器一个分支的概率 >0% 和

最佳答案

来自 here :

long __builtin_expect_with_probability

(long exp, long c, double probability) The function has the same semantics as __builtin_expect, but caller provides the expected probability that exp == c. Last argument, probability, is a floating-value in the inclusive range 0.0f and 1.0f. The probability argument must be constant floating-point expression.

Jesin 在评论中指出,Clang 11 has it too .

https://stackoverflow.com/questions/4195143/

相关文章:

google-chrome - chrome.tabs 问题与 chrome.tabs.update

ruby-on-rails - Ruby on Rails 究竟是什么?

iphone - 滚动时 UITableView 未正确更新

variables - Lua:为什么改变一个变量的值也会改变另一个变量的值?

sql-server - SQL 服务器 2008 : how does NOLOCK works

opengl - 如何让鼠标光标在 opengl/glut 中消失?

c++11 - 无法创建 Direct2D DXGI 表面

image - 人体的宽度和高度

ajax - setInterval 不适用于 ajax 调用

r - 为什么 nlogn 很难反转?