We have a macro for error-checking that goes like this:
#define CheckCondition( x ) \
if( x ) { \
//okay, do nothing \
} else { \
CallFunctionThatThrowsException(); \
}
and normally the condition has to be true and we'd like the CPU branch prediction to always select this path, and if it happens to be false we don't really care of a misprediction - throwing an exception and massive stack unwinding will cost a fortune anyway.
According to CPU hardcore descriptions branch prediction will treat forward jumps and backward jumps slightly differently (something like a backward jump is always performed and a forward jump is never performed) and the compiler could improve branch prediction by generating code that will give right hints to the CPU branch predictor.
gcc seems to have likely and unlikely hints for that. Is there anything like that in Visual C++? Can __assume keyword be used for that?