“rdtsc”: “=a” (a0), “=d” (d0) what does this do? [duplicate]

℡╲_俬逩灬. 提交于 2020-01-04 02:03:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!