To add to what was already said, many architectures support branch prediction, i.e. ways of marking which of the branches is most likely to happen so that the resulting code and execution is better suited to the most common situation - that is if "b" is likely to be true, the processor can start loading code from the positive branch before the value of expression "b" is even evaluated.
For example for gcc:
#define likely(x) __builtin_expect((x),1)
#define unlikely(x) __builtin_expect((x),0)
if(likely(b)) {
a = c;
} else {
a = d;
}
#define likely(x) __builtin_expect((x),1)
#define unlikely(x) __builtin_expect((x),0)
if(likely(b)) {
a = c;
} else {
a = d;
}
To copy to clipboard, switch view to plain text mode
Bookmarks