You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.2 KiB
C
55 lines
1.2 KiB
C
#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 long rdtsc(void)
|
|
{
|
|
unsigned hi, lo;
|
|
__asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
|
|
return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
|
|
}
|
|
|
|
#elif defined(__powerpc__)
|
|
|
|
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: $ $Author: kazutomo $
|
|
* $Revision: 1.6 $ $Date: 2005/04/13 18:49:58 $
|
|
*/
|
|
|
|
#endif |