1 #ifndef __RDTSC_H_DEFINED__ 2 #define __RDTSC_H_DEFINED__ 3 4 5 #if defined(__i386__) 6 rdtsc(void)7static __inline__ unsigned long long rdtsc(void) 8 { 9 unsigned long long int x; 10 __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); 11 return x; 12 } 13 #elif defined(__x86_64__) 14 15 // typedef unsigned long long int unsigned long long; 16 rdtsc(void)17static __inline__ unsigned long long rdtsc(void) 18 { 19 unsigned hi, lo; 20 __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); 21 return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 ); 22 } 23 24 #elif defined(__powerpc__) 25 26 // typedef unsigned long long int unsigned long long; 27 rdtsc(void)28static __inline__ unsigned long long rdtsc(void) 29 { 30 unsigned long long int result=0; 31 unsigned long int upper, lower,tmp; 32 __asm__ volatile( 33 "0: \n" 34 "\tmftbu %0 \n" 35 "\tmftb %1 \n" 36 "\tmftbu %2 \n" 37 "\tcmpw %2,%0 \n" 38 "\tbne 0b \n" 39 : "=r"(upper),"=r"(lower),"=r"(tmp) 40 ); 41 result = upper; 42 result = result<<32; 43 result = result|lower; 44 45 return(result); 46 } 47 48 #else 49 50 #error "No tick counter is available!" 51 52 #endif 53 54 #endif 55