-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtiming.h
More file actions
40 lines (31 loc) · 939 Bytes
/
Copy pathtiming.h
File metadata and controls
40 lines (31 loc) · 939 Bytes
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
#ifndef TIMING_H
#define TIMING_H
#define NUM_TIMINGS 100000
int compareDouble(const void *x, const void *y)
{
double xx = *(double*)x, yy = *(double*)y;
if (xx < yy) return -1;
if (xx > yy) return 1;
return 0;
}
unsigned long long int startTimer(void)
{
unsigned a, d;
__asm__ volatile("CPUID\n\t"
"RDTSC\n\t"
"mov %%edx, %0\n\t"
"mov %%eax, %1\n\t": "=r" (d),
"=r" (a):: "%rax", "%rbx", "%rcx", "%rdx");
return ((unsigned long long)a) | (((unsigned long long)d) << 32);;
}
unsigned long long int endTimer(void)
{
unsigned a, d;
__asm__ volatile("RDTSCP\n\t"
"mov %%edx, %0\n\t"
"mov %%eax,%1\n\t"
"CPUID\n\t": "=r" (d), "=r" (a)::
"%rax", "%rbx", "%rcx", "%rdx");
return ((unsigned long long)a) | (((unsigned long long)d) << 32);;
}
#endif