Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Thursday, October 15, 2026

Diff for libplaton/platon/misc/rdtsc.h between version 1.5 and 1.6

version 1.5, 2002/07/16 22:26:16 version 1.6, 2002/07/19 09:29:30
Line 1 
Line 1 
 #ifndef _PLATON_UTILS_RDTSC_H  #ifndef _PLATON_UTILS_RDTSC_H
 #define _PLATON_UTILS_RDTSC_H  #define _PLATON_UTILS_RDTSC_H
   
 #define RDTSC_FIRST     0 /* set the first results; default behaviour */  
 #define RDTSC_MIN       1 /* set the shortest result */  
 #define RDTSC_MAX       2 /* set the longest result */  
 #define RDTSC_AVG       3 /* set the average result */  
   
 #ifdef __cplusplus  #ifdef __cplusplus
 extern "C" {  extern "C" {
 #endif  #endif
   
 #define rdtsc_first(code, count, result) \  #define rdtsc(code, count) { \
                 rdtsc_core(RDTSC_FIRST, 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) \  
         do { \  
                 unsigned long __start, __end, __i; \                  unsigned long __start, __end, __i; \
                 float __result; \                  unsigned long __min,__avg = 0,__max,__tmp[(count)]; \
                 for (__i = 0; __i < (count); __i++) { \          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; \                          __tmp[__i] = __end - __start; \
                         if ((type) == RDTSC_AVG) { \                          __avg += __tmp[__i]; \
                                 /* compute average value on the fly */ \          }\
                                 /* can't be optimized due overflow  */ \          __min = __max = __tmp[0];\
                                 __result = (__result * ((float) __i / ((float) __i + 1)) \          for(__i = 1; __i < (count);__i++) { \
                                                 + (float) __end / ((float) __i + 1)); \                  if(__tmp[__i] < __min)\
                         } \                          __min = __tmp[__i];\
                         else { \                  if(__tmp[__i] > __max)\
                                 if (! __i \                          __max = __tmp[__i];\
                                                 || ((type) == RDTSC_MIN && __end < __result) \          }\
                                                 || ((type) == RDTSC_MAX && __end > __result)) \          printf("min: %lu avg: %lu max: %lu count: %d\n",\
                                         __result = __end; \                                  __min,__avg / (count),__max,(count));\
                         } \  }\
                 } \  
                 (result) = __result; \  
         } while(0)  
   
 #ifdef __cplusplus  #ifdef __cplusplus
 }  }
 #endif  #endif
   
 #endif                          /* #ifndef _PLATON_UTILS_RDTSC_H */  #endif                          /* #ifndef _PLATON_UTILS_RDTSC_H */
   

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top