Rummeris

cpucycles.c

Nov 17th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. #if defined(__i386__)
  2.  
  3. static __inline__ unsigned long long cpucycles(void)
  4. {
  5.     //printf("32 bit machine");
  6.     unsigned long long int x;
  7.     __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
  8.     return x;
  9. }
  10.  
  11. #elif defined(__x86_64__)
  12.  
  13. static __inline__ unsigned long long cpucycles(void)
  14. {
  15.     //printf("64 bit machine");
  16.     unsigned hi, lo;
  17.     __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
  18.     return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
  19. }
  20.  
  21. #endif
Advertisement
Add Comment
Please, Sign In to add comment