I know it's something related to branch predicting and I wanted to write a demo to test how much speed can benefit from this.
Then I wrote some c++ codes like following, expecting one is faster than another.
Code: Select all
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
val=1;
// loop 1, expected to be fast
if(likely(val))
...
// loop 2, predict fail, pipeline flush
if(unlikely(val))
...
After googling I reached this website. I guess it's because "static predicting" is not working, but some other predicting techniq on the processor is doing the right prediction.
https://www.agner.org/optimize/microarchitecture.pdfBranch hint prefixes have no useful effect on PM and Core2 processors.
So, to make it short:
Is there a way I can "fool" the branch predictor and see the same code is slowed down by some well-designed dataset?
Apologize for my poor English