blob: ba87181b76fd8d0123cb55a8679870d86b241adb [file] [log] [blame]
// Codes from: http://www.mcs.anl.gov/~kazutomo/rdtsc.h
#ifndef __RDTSC_H_DEFINED__
#define __RDTSC_H_DEFINED__
#if defined(__i386__)
static __inline__ unsigned long long rdtsc(void)
{
unsigned long long int x;
__asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
return x;
}
#elif defined(__x86_64__)
static __inline__ unsigned long rdtsc(void)
{
unsigned hi, lo;
__asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
return ( (unsigned long)lo)|( ((unsigned long)hi)<<32 );
}
#elif defined(__powerpc__)
typedef unsigned long long int unsigned long long;
static __inline__ unsigned long long rdtsc(void)
{
unsigned long long int result=0;
unsigned long int upper, lower,tmp;
__asm__ volatile(
"0: \n"
"\tmftbu %0 \n"
"\tmftb %1 \n"
"\tmftbu %2 \n"
"\tcmpw %2,%0 \n"
"\tbne 0b \n"
: "=r"(upper),"=r"(lower),"=r"(tmp)
);
result = upper;
result = result<<32;
result = result|lower;
return(result);
}
#else
#error "No tick counter is available!"
#endif
/* $RCSfile: rdtsc.h,v $ $Author: alenhar2 $
* $Revision: 1.3 $ $Date: 2008-10-13 22:04:20 $
*/
#endif