Example:
if (almost_always_false_condition) {
// do something
}
Is there a way to suggest compiler that in 99% condition will be false.
The condition calculation takes ~60 cycles to be checked, and it cannot be calculated at compile time by compiler itself.
(gcc 4.3)
If you want to suggest to GCC that a condition is likely to have a given value as a hint for arranging code flow, you should use
__builtin_expect( ):However, it sounds like you want to find a way to avoid evaluating the condition, which
__builtin_expect( )won’t do. Is there a way that you can quickly approximate the condition, and only do the full check when the approximation is true:Can you tell us more about what the condition is?