Branch Predictor and Instruction Pipelining, how can I prove the existence of it?
Posted: 2023-02-10, 20:01:26
I was reading the source code of gstreamer and saw some "g_likely()" macros.
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.
But I tested many times on a Intel I5-8250U and saw no difference between the two statements.
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.
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
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