3 ms·
The Linux kernel exploits that by using two macros (likely() and unlikely()) that give hints to the compiler using GCC's __builtin_expect: if(likely(condition)
by codesink 16y ago
The Linux kernel exploits that by using two macros (likely() and unlikely()) that give hints to the compiler using GCC's __builtin_expect:
if(likely(condition))
dosomething();
- wendroid 16y ago:) That's what I came to say http://kerneltrap.org/node/4705 http://kerneltrap.org/node/4705 I also have some other links : These people saw 10% gain in their Scheme http://people.csail.mit.edu/jaffer/CNS/interpreter-branch http://people.csail.mit.edu/jaffer/CNS/interpreter-branch And this concerns reducing power consumption using Branch Prediction Prediction ! http://www.eecg.toronto.edu/~moshovos/research/iccd02.pdf http://www.eecg.toronto.edu/~moshovos/research/iccd02.pdf
- matthavener 16y agoeven without likely/unlikely, branch prediction still occurs in branch-prediction supporting processors. the kernel optimization just optimizes for the first case. once the branch prediction state machine as aligned itself towards the more likely branch, accurate branch prediction will occur for the resulting calls (typically iterations or something like that)