Open Quuxplusone opened 6 years ago
That documentation is incoherent. Is the last parameter of type float or long? Is it a percentage or a value from 0 to 1?
(In reply to Richard Smith from comment #1)
> That documentation is incoherent. Is the last parameter of type float or
> long? Is it a percentage or a value from 0 to 1?
Admittedly they did a poor job with the documentation there. The last parameter
is of type float (single) and is a value in the inclusive range 0.0f to 1.0,
where 0.0f represents a 0% (never) probability of the branch being taken and
1.0f represents as 100% (always) probability of the branch being taken.
Is there a link to the discussion that led to that addition in GCC? I'm curious what optimizer/code-generation expectation customers will have for this.
The chance of us doing anything useful with that percentage parameter seem slim to me. Ie, we have very little hope of statically modeling any reasonably complex dynamic branch predictor. A 50/50 branch may be entirely predictable dynamically.
The next GCC includes support for a new builtin
` [1] that is similar to
__builtin_expect()`, except with support for real probabilities:This builtin is useful in that it allows better specification of branch probabilities, which in theory should be able to be used to make more informed decisions regarding code block generation and organization.