rdtsc 备忘
from: http://stackoverflow.com/questions/6814792/why-is-clock-gettime-so-erratic
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
static uint64_t rdtsc() { #if defined(__GNUC__) # if defined(__i386__) uint64_t x; __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); return x; # elif defined(__x86_64__) uint32_t hi, lo; __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); return ((uint64_t)lo) | ((uint64_t)hi << 32); # else # error Unsupported architecture. # endif #elif defined(_MSC_VER) return __rdtsc(); #else # error Other compilers not supported... #endif } |