-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdtsc.h
41 lines (35 loc) · 1.45 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
#ifndef __RDTSC_H__
#define __RDTSC_H__
// uso:
// unsigned long start, end;
// RDTSC_START(start);
// ... codigo ...
// RDTSC_STOP(end);
// unsigned long delta = end - start;
#define RDTSC(var) \
{ \
__asm__ __volatile__ ( \
"xor %%rdx, %%rdx\n\t" \
"xor %%rax, %%rax\n\t" \
"lfence\n\t" \
"rdtsc\n\t" \
"sal $32, %%rdx\n\t" \
"or %%rdx, %%rax\n\t" \
"movq %%rax, %0\n\t" \
: "=r" (var) \
: /* no input */ \
: "%rax", "%rdx" \
); \
}
#define RDTSC_START(start) \
{ \
/* warm up ... */ \
RDTSC(start); \
RDTSC(start); \
RDTSC(start); \
}
#define RDTSC_STOP(end) \
{ \
RDTSC(end); \
}
#endif /* !__RDTSC_H__ */