cpuid
is used as a serializing instruction to prevent ooo execution when benchmarking, since the execution of benchmarked instructions might be reordered before rdtsc
if it's used alone. My question is whether it is still possible for the instructions below rdtsc
to be reordered in between cpuid
and rdtsc
? Since rdtsc
is not a serializing instruction, instructions can be freely reordered around it?
Since RDTSC does not depend on any input (it takes no arguments) in principle the OOO pipeline will run it as soon as it can. The reason you add a serializing instruction before it is not to let the RDTSC execute earlier.
There is an answer from John McCalpin here, you might find it useful. He explains the OOO reordering for the RDTSCP instruction (which behaves differently from RDTSC) which you may prefer to use instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With