-
Notifications
You must be signed in to change notification settings - Fork 1
/
RealTime.h
73 lines (59 loc) · 1.72 KB
/
RealTime.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
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef PerfTools_RealTime_H
#define PerfTools_RealTime_H
//
// defines "rdtsc"
//
#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__) || defined(__ppc__)
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 The file PerfTools/Measure/interface/RealTime.h needs to be set up for your CPU type.
#endif
/*
#if defined(__powerpc__) || defined(__ppc__)
#include "PPCRealTime.h"
#elif defined(__i386__) || defined(__ia64) || defined(__ia64__) || defined(__x86_64__) || defined(__x86_64)
#include "PentiumRealTime.h"
#else
#error The file PerfTools/Measure/interface/RealTime.h needs to be set up for your CPU type.
#endif
*/
namespace perftools {
typedef long long int TimeDiffType;
typedef unsigned long long int TimeType;
// High Precision real time in clock-units
inline TimeType realTime() {
return rdtsc();
}
}
#endif // PerfTools_RealTime_H