| version 1.3, 2002/07/15 18:56:41 |
version 1.4, 2002/07/16 03:25:43 |
|
|
| extern "C" { |
extern "C" { |
| #endif |
#endif |
| |
|
| #define rdtsc_first(code, count, result) rdtsc_core(RDTSC_FIRST, code, count, result) |
#define rdtsc_first(code, count, result) \ |
| #define rdtsc_min(code, count, result) rdtsc_core(RDTSC_MIN, code, count, result) |
rdtsc_core(RDTSC_FIRST, code, count, result) |
| #define rdtsc_max(code, count, result) rdtsc_core(RDTSC_MAX, code, count, result) |
|
| #define rdtsc_avg(code, count, result) rdtsc_core(RDTSC_AVG, code, count, result) |
#define rdtsc_min(code, count, result) \ |
| |
rdtsc_core(RDTSC_MIN, code, count, result) |
| |
|
| |
#define rdtsc_max(code, count, result) \ |
| |
rdtsc_core(RDTSC_MAX, code, count, result) |
| |
|
| |
#define rdtsc_avg(code, count, result) \ |
| |
rdtsc_core(RDTSC_AVG, code, count, result) |
| |
|
| #define rdtsc_core(type, code, count, result) \ |
#define rdtsc_core(type, code, count, result) \ |
| do { \ |
do { \ |
| unsigned long __start, __end, __result, __i; \ |
unsigned long __start, __end, __i; \ |
| for (__i = 0; __i < count; __i++) { \ |
float __result; \ |
| |
for (__i = 0; __i < (count); __i++) { \ |
| __asm__ __volatile__("rdtsc" : "=a" (__start) : : "edx"); \ |
__asm__ __volatile__("rdtsc" : "=a" (__start) : : "edx"); \ |
| (code); \ |
(code); \ |
| __asm__ __volatile__("rdtsc" : "=a" (__end) : : "edx"); \ |
__asm__ __volatile__("rdtsc" : "=a" (__end) : : "edx"); \ |
| __end -= __start; \ |
__end -= __start; \ |
| if (type == RDTSC_AVG) { \ |
if ((type) == RDTSC_AVG) { \ |
| __result = (__result * i + __end) / (i + 1); \ |
/* compute average value on the fly */ \ |
| |
/* can't be optimized due overflow */ \ |
| |
__result = (__result * ((float)__i / ((float)__i+1)) \ |
| |
+ (float)__end / ((float)__i+1)); \ |
| } \ |
} \ |
| else { \ |
else { \ |
| if (! __i \ |
if (! __i \ |
| || (type == RDTSC_MIN && __end < __result) \ |
|| ((type) == RDTSC_MIN && __end < __result) \ |
| || (type == RDTSC_MAX && __end > __result)) \ |
|| ((type) == RDTSC_MAX && __end > __result)) \ |
| __result = __end; \ |
__result = __end; \ |
| } \ |
} \ |
| } \ |
} \ |
| result = __result; \ |
(result) = __result; \ |
| } while(0) |
} while(0) |
| |
|
| #ifdef __cplusplus |
#ifdef __cplusplus |