00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef __MMX_TIMER_HPP
00014 #define __MMX_TIMER_HPP
00015 #ifdef BASIX_TIME_WITH_SYS_TIME
00016 # include <sys/time.h>
00017 # include <time.h>
00018 #else
00019 # ifdef BASIX_HAVE_SYS_TIME_H
00020 # include <sys/time.h>
00021 # else
00022 # include <time.h>
00023 # endif
00024 #endif
00025 #include <basix/string.hpp>
00026
00028
00029 namespace mmx {
00030
00032 nat mmx_time ();
00033 double mmx_var_time ();
00034 inline string mmx_time_unit () { return("ms"); };
00035
00037 nat mmx_user_time();
00038 inline string mmx_user_time_unit () { return("ms"); };
00039
00041 #if defined(__GNUC__) && defined(__i386__)
00042 extern __inline__ xnat mmx_cpu_time () {
00043 unsigned long long x;
00044 __asm__ volatile ("rdtsc" : "=A" (x));
00045 return (xnat) x;
00046 }
00047 inline string mmx_cpu_time_unit () { return("tk"); };
00048
00049 #elif defined(__GNUC__) && (defined(__amd64__) || defined(__x86_64__))
00050 inline xnat mmx_cpu_time () {
00051 unsigned int a, d;
00052 __asm__ volatile ("rdtsc" : "=a" (a), "=d" (d));
00053 return (((xnat) d)<<32) | ((xnat) a);
00054 }
00055 inline string mmx_cpu_time_unit () { return("tk"); };
00056 #else
00057
00058 inline xnat mmx_cpu_time () {
00059 return (xnat) clock ();
00060 }
00061 inline string mmx_cpu_time_unit () { return("mus"); };
00062 #endif
00063
00064 }
00065 #endif // __MMX_TIMER_HPP