I tried to use the rdtsc command of Intel CPU to count the program. I checked the relevant information and found that the rdtsc command under GCC could not obtain the correct result, so I want to see how C's code is compiled into an assembly:
In GCC, G ++-O main. s main. cpp-S
Microsoft's Cl compiler is like this: cl.exe/Fas main. cpp
The compilation produced by GCC is in at&t format, while Microsoft is in Intel format. From the annotation point of view, the compilation generated by Microsoft Cl is much more intimate, and the source code and line number information are all in it, which is clear at a glance.
Of course, the compilation cannot be understood. For example, if rdtsc is used in cl, why does the result returned by the command be stored in edX: eax and finally can be used as the return value of the function? It seems that I am a pure idiot in the compilation field !!! This is my future direction.
OK. Finally, paste the code called by rdtsc that can be used in both Cl and GCC:/*** // call the Intel CPU command rdtsc to obtain the time count, easy to obtain performance metrics of code segments
/// @ Return 64 indicates the CPU clock value of the unsigned integer
Unsigned long rdtsc ()
...{
# Ifdef _ msc_ver/** // * msvc compiler */
_ ASM _ emit 0x0f
_ ASM _ emit 0x31
# Else/* GCC compiler */
Unsigned long temp;
Unsigned int low, high;
_ ASM _ volatile _ ("rdtsc": "= A" (low), "= D" (high ));
Temp = high;
Temp <= 32;
Temp + = low;
Return temp;
# Endif
}