… | |
… | |
25 | |
25 | |
26 | #ifndef DEVEL_H |
26 | #ifndef DEVEL_H |
27 | #define DEVEL_H |
27 | #define DEVEL_H |
28 | |
28 | |
29 | // used for benchmarking (x86/amd64-specific) |
29 | // used for benchmarking (x86/amd64-specific) |
|
|
30 | #ifdef DEVEL64 |
30 | typedef unsigned int cstamp; |
31 | typedef uint64_t cstamp; |
|
|
32 | #else |
|
|
33 | typedef uint32_t cstamp; |
|
|
34 | #endif |
|
|
35 | |
|
|
36 | #if defined(__i386__) || defined(__x86_64__) |
31 | |
37 | |
32 | static inline cstamp |
38 | static inline cstamp |
33 | stamp (void) |
39 | stamp (void) |
34 | { |
40 | { |
35 | cstamp tsc; |
41 | uint32_t l, h; |
|
|
42 | |
36 | asm volatile ("rdtsc" : "=a" (tsc) : : "edx"); |
43 | asm volatile ("rdtsc" : "=a" (l), "=d" (h)); |
|
|
44 | |
|
|
45 | #ifdef DEVEL64 |
|
|
46 | return ((cstamp)h << 32) | l; |
|
|
47 | #else |
37 | return tsc; |
48 | return l; |
|
|
49 | #endif |
38 | } |
50 | } |
|
|
51 | |
|
|
52 | #elif defined(__powerpc__) |
|
|
53 | static inline cstamp |
|
|
54 | stamp (void) |
|
|
55 | { |
|
|
56 | unsigned uint32_t u, l, tmp; |
|
|
57 | |
|
|
58 | asm volatile ( |
|
|
59 | "0: \n" |
|
|
60 | "\tmftbu %0 \n" |
|
|
61 | "\tmftb %1 \n" |
|
|
62 | "\tmftbu %2 \n" |
|
|
63 | "\tcmpw %2,%0\n" |
|
|
64 | "\tbne 0b \n" |
|
|
65 | : "=r" (h), "=r" (l), "=r" (tmp) |
|
|
66 | ); |
|
|
67 | |
|
|
68 | #ifdef DEVEL64 |
|
|
69 | return ((cstamp)h << 32) | l; |
|
|
70 | #else |
|
|
71 | return l; |
|
|
72 | #endif |
|
|
73 | } |
|
|
74 | |
|
|
75 | #endif |
39 | |
76 | |
40 | static inline cstamp |
77 | static inline cstamp |
41 | measure (cstamp t) |
78 | measure (cstamp t) |
42 | { |
79 | { |
43 | return stamp () - t; |
80 | return stamp () - t; |