Diff for libplaton/platon/misc/rdtsc.h between version 1.1 and 1.2
| version 1.1, 2002/07/15 17:34:11 |
version 1.2, 2002/07/15 18:46:09 |
|
|
| #include <stdio.h> |
|
| #ifndef _PLATON_UTILS_RDTSC_H |
#ifndef _PLATON_UTILS_RDTSC_H |
| #define _PLATON_UTILS_RDTSC_H |
#define _PLATON_UTILS_RDTSC_H |
| |
|
| |
#define RDTSC_MIN 0 |
| |
#define RDTSC_MAX 1 |
| |
#define RDTSC_AVG 2 |
| |
|
| #ifdef __cplusplus |
#ifdef __cplusplus |
| extern "C" { |
extern "C" { |
| #endif |
#endif |
| |
|
| #define rdtsc(x,i) { \ |
#define rdtsc_min(code, count, result) rdtsc_core(RDTSC_MIN, code, count, result) |
| unsigned long start,end;\ |
#define rdtsc_max(code, count, result) rdtsc_core(RDTSC_MAX, code, count, result) |
| int min = 100000\; \ |
#define rdtsc_avg(code, count, result) rdtsc_core(RDTSC_AVG, code, count, result) |
| while(i != 0) {\ |
|
| __asm__ __volatile__("rdtsc" : "=a" (start) : : "edx");\ |
#define rdtsc_core(type, code, count, result) \ |
| (x);\ |
do { \ |
| __asm__ __volatile__("rdtsc" : "=a" (end) : : "edx");\ |
unsigned long __start, __end, __result, __i; \ |
| end -= start;\ |
for (__i = 0; __i < count; __i++) { \ |
| if(end < min) \ |
__asm__ __volatile__("rdtsc" : "=a" (__start) : : "edx"); \ |
| min = end;\ |
(code); \ |
| i--;\ |
__asm__ __volatile__("rdtsc" : "=a" (__end) : : "edx"); \ |
| }\ |
__end -= __start; \ |
| printf("Code runs %d cpu clocks\n",min);\ |
if (type == RDTSC_AVG) { \ |
| }\ |
__result = (__result * i + __end) / (i + 1); \ |
| |
} \ |
| |
else { \ |
| |
if (! __i \ |
| |
|| (type == RDTSC_MIN && __end < __result) \ |
| |
|| (type == RDTSC_MAX && __end > __result)) \ |
| |
__result = __end; \ |
| |
} \ |
| |
} \ |
| |
result = __result; \ |
| |
} while(0) |
| |
|
| #ifdef __cplusplus |
#ifdef __cplusplus |
| } |
} |
| #endif |
#endif |
| #endif |
|
| #endif /* #ifndef _PLATON_UTILS_RDTSC_H */ |
#endif /* #ifndef _PLATON_UTILS_RDTSC_H */ |
| |
|
Platon Group <platon@platon.org> http://platon.org/
|
|