aboutsummaryrefslogtreecommitdiffstats
path: root/include/cycles.h
blob: 01f36a9fa3fe08c911d7a3dcc623fd1906d1ab45 (plain) (blame)
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
#ifndef CYCLES_H
#define CYCLES_H

#ifdef __i386__

typedef unsigned long long cycles_t;

#define CYCLES_FMT "llu"

static inline cycles_t get_cycles(void) 
{
        unsigned long long ret;
        __asm__ __volatile__("rdtsc" : "=A" (ret));
        return ret;
}

#endif


#ifdef __sparc__

#define NPT_BIT 63

typedef unsigned long cycles_t;

#define CYCLES_FMT "lu"

static inline cycles_t get_cycles(void) {
	unsigned long cycles = 0;
	__asm__ __volatile__("rd %%asr24, %0" : "=r" (cycles));
	return cycles & ~(1UL << NPT_BIT);
}

#endif

#endif