You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
740 B

  1. // read the processor time stamp register
  2. #if defined __i386__
  3. #define USE_RDTSC 1
  4. static inline unsigned long long rdtsc() {
  5. unsigned long hi, lo;
  6. __asm__ __volatile__ ("rdtsc\n"
  7. "movl %%edx,%0\n"
  8. "movl %%eax,%1" : "=r"(hi), "=r"(lo) : : "edx", "eax");
  9. return ((unsigned long long) hi << 32ULL) + (unsigned long long) lo;
  10. }
  11. #else
  12. #if defined __x86_64__
  13. #define USE_RDTSC 1
  14. static inline unsigned long long rdtsc() {
  15. unsigned long long r;
  16. __asm__ __volatile__ ("rdtsc\n"
  17. "shl $32,%%rdx\n"
  18. "or %%rdx,%%rax\n"
  19. "movq %%rax,%0" : "=r"(r) : : "edx", "eax", "rdx", "rax");
  20. return r;
  21. }
  22. #else
  23. #define USE_RDTSC 0
  24. #endif
  25. #endif