osg*_*sgx 0 gcc built-in prediction optimizer-hints
__builtin_expect来自GCC的程序员可以使用它来显示哪些变体经常出现且很少见.但 __builtin_expect只有"真实"和"假"(0%或100%概率)
对于一些大型项目来说,获取个人资料反馈很难变化(-fprofile-arcs),有时程序员确实知道,他在程序的某些方面有多大的分支概率.
可以给编译器一个提示,即分支的概率> 0%且<100%?
从这里:
长__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 thatexp == 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 pointed out in the comments, Clang 11 has it too.
真与假的确意味着"第一种变体更有可能","第二种变体更有可能".除了这些之外,没有实际需要任何其他值.编译器将无法使用该信息.