diff options
| author | Andrea Bastoni <bastoni@cs.unc.edu> | 2009-12-17 16:06:15 -0500 |
|---|---|---|
| committer | Andrea Bastoni <bastoni@cs.unc.edu> | 2009-12-17 16:06:15 -0500 |
| commit | 1872bfbc1f4a5b3c4980fae889787ab15ddcc83b (patch) | |
| tree | ee980ec191b585f16ddee75c7537250aa1e054b6 /include | |
| parent | aaf499a6cab77b827d427f234e5c1f1e21c410ef (diff) | |
Porting on x86_64
Diffstat (limited to 'include')
| -rw-r--r-- | include/cycles.h | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/include/cycles.h b/include/cycles.h index 01f36a9..e9b0e11 100644 --- a/include/cycles.h +++ b/include/cycles.h | |||
| @@ -1,23 +1,50 @@ | |||
| 1 | #ifndef CYCLES_H | 1 | #ifndef CYCLES_H |
| 2 | #define CYCLES_H | 2 | #define CYCLES_H |
| 3 | 3 | ||
| 4 | #ifdef __i386__ | 4 | #ifdef __x86_64__ |
| 5 | |||
| 6 | #define rdtscll(val) do { \ | ||
| 7 | unsigned int __a,__d; \ | ||
| 8 | __asm__ __volatile__("rdtsc" : "=a" (__a), "=d" (__d)); \ | ||
| 9 | (val) = ((unsigned long)__a) | (((unsigned long)__d)<<32); \ | ||
| 10 | } while(0) | ||
| 11 | |||
| 12 | static __inline__ unsigned long long native_read_tsc(void) | ||
| 13 | { | ||
| 14 | unsigned long long val; | ||
| 15 | |||
| 16 | __asm__ __volatile__("mfence":::"memory"); | ||
| 17 | rdtscll(val); | ||
| 18 | __asm__ __volatile__("mfence":::"memory"); | ||
| 19 | |||
| 20 | return val; | ||
| 21 | } | ||
| 5 | 22 | ||
| 6 | typedef unsigned long long cycles_t; | ||
| 7 | 23 | ||
| 8 | #define CYCLES_FMT "llu" | 24 | #define CYCLES_FMT "llu" |
| 9 | 25 | ||
| 10 | static inline cycles_t get_cycles(void) | 26 | typedef unsigned long long cycles_t; |
| 27 | |||
| 28 | static inline cycles_t get_cycles(void) | ||
| 11 | { | 29 | { |
| 12 | unsigned long long ret; | 30 | return native_read_tsc(); |
| 13 | __asm__ __volatile__("rdtsc" : "=A" (ret)); | 31 | } |
| 14 | return ret; | 32 | #elif defined __i386__ |
| 33 | static inline unsigned long long native_read_tsc(void) { | ||
| 34 | unsigned long long val; | ||
| 35 | __asm__ __volatile__("rdtsc" : "=A" (val)); | ||
| 36 | return val; | ||
| 15 | } | 37 | } |
| 16 | 38 | ||
| 17 | #endif | 39 | typedef unsigned long long cycles_t; |
| 18 | 40 | ||
| 41 | #define CYCLES_FMT "llu" | ||
| 19 | 42 | ||
| 20 | #ifdef __sparc__ | 43 | static inline cycles_t get_cycles(void) |
| 44 | { | ||
| 45 | return native_read_tsc(); | ||
| 46 | } | ||
| 47 | #elif defined __sparc__ | ||
| 21 | 48 | ||
| 22 | #define NPT_BIT 63 | 49 | #define NPT_BIT 63 |
| 23 | 50 | ||
