I want to write a function to get the current timestamp. Because the __retscp(&addr) function is used directly, one parameter must be input every time. I want to write a function cutTime() in a .h file that returns the current timestamp each time. Since I don't want to lose time because of the function call process, I define it as an inline function. One uses rdtsc and the other uses rdtscp. Are my two implementations the same as using __retscp(&addr) directly?
1.static inline uint64_t curTime() {
uint64_t a, d;
asm volatile ("mfence");
asm volatile("rdtsc" : "=a"(a), "=d"(d) :: "rcx");
a = (d<<32) | a;
asm volatile ("mfence");
return a;
}
2.static inline uint64_t curTime() {
uint64_t a;
asm volatile ("rdtscp" : "=a" (a));
return a;
}
3.__rdtscp( & junk)