-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdtsc.h
61 lines (49 loc) · 1.19 KB
/
rdtsc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef __RDTSC_H_DEFINE__
#define __RDTSC_H_DEFINE__
#include <stdint.h>
#if defined(__i386__)
static __inline__ uint64_t rdtsc(void)
{
uint64_t x;
__asm__ volatile ("rdtsc" : "=A" (x));
return x;
}
#elif defined(__x86_64__)
static __inline__ uint64_t rdtsc(void)
{
unsigned hi, lo;
__asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
return ( (uint64_t)lo)|( ((uint64_t)hi)<<32 );
}
#elif defined(__powerpc__)
#if defined(__powerpc64__)
static __inline__ uint64_t rdtsc(void)
{
uint64_t x;
asm volatile ("mfspr %0,%1" :
"=&r" (x)
: "i" (0x10C) ); /* read 64-bit timebase */
return x;
}
#else
static __inline__ uint64_t rdtsc(void)
{
uint64_t 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);
}
#endif
#endif // __powerpc__
#endif