问题
I'm new to C++ and benchmarking
I don't understand what the this part of the code does? So I found something about the edx, eax registers, but I don't fully understand how that plays into the code. So I understand this code essentially returns the current tick of the cpu cycle. So, does it store the current tick into the registers, one part in the hi and the other part in the lo. And, does the "=a", and "=d" specify which register to store it in.
And what is the significance of breaking it into two parts.
"rdtsc" : "=a" (lo), "=d" (hi)
Code in context:
int64_t rdtsc(){
unsigned int lo,hi;
__asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
return ((uint64_t)hi << 32) | lo;
}
回答1:
It uses inline assembly to call the rdtsc opcode which returns an 64 bit integer. The high part is stored to hi
and the low to lo
.
In Windows and Visual Studio where inline assembly is not available in x64, you would use the __rdtsc.
来源:https://stackoverflow.com/questions/56940066/rdtsc-a-a0-d-d0-what-does-this-do