00001
00024 #ifndef AVUTIL_TIMER_H
00025 #define AVUTIL_TIMER_H
00026
00027 #include <stdlib.h>
00028 #include <stdint.h>
00029 #include "config.h"
00030
00031 #if ARCH_X86 || ARCH_PPC || ARCH_BFIN
00032 #define AV_READ_TIME read_time
00033 #if ARCH_X86
00034 static inline uint64_t read_time(void)
00035 {
00036 uint32_t a, d;
00037 __asm__ volatile("rdtsc\n\t"
00038 : "=a" (a), "=d" (d));
00039 return ((uint64_t)d << 32) + a;
00040 }
00041 #elif ARCH_BFIN
00042 static inline uint64_t read_time(void)
00043 {
00044 union {
00045 struct {
00046 unsigned lo;
00047 unsigned hi;
00048 } p;
00049 unsigned long long c;
00050 } t;
00051 __asm__ volatile ("%0=cycles; %1=cycles2;" : "=d" (t.p.lo), "=d" (t.p.hi));
00052 return t.c;
00053 }
00054 #else //FIXME check ppc64
00055 static inline uint64_t read_time(void)
00056 {
00057 uint32_t tbu, tbl, temp;
00058
00059
00060 __asm__ volatile(
00061 "1:\n"
00062 "mftbu %2\n"
00063 "mftb %0\n"
00064 "mftbu %1\n"
00065 "cmpw %2,%1\n"
00066 "bne 1b\n"
00067 : "=r"(tbl), "=r"(tbu), "=r"(temp)
00068 :
00069 : "cc");
00070
00071 return (((uint64_t)tbu)<<32) | (uint64_t)tbl;
00072 }
00073 #endif
00074 #elif HAVE_GETHRTIME
00075 #define AV_READ_TIME gethrtime
00076 #endif
00077
00078 #ifdef AV_READ_TIME
00079 #define START_TIMER \
00080 uint64_t tend;\
00081 uint64_t tstart= AV_READ_TIME();\
00082
00083 #define STOP_TIMER(id) \
00084 tend= AV_READ_TIME();\
00085 {\
00086 static uint64_t tsum=0;\
00087 static int tcount=0;\
00088 static int tskip_count=0;\
00089 if(tcount<2 || tend - tstart < 8*tsum/tcount || tend - tstart < 2000){\
00090 tsum+= tend - tstart;\
00091 tcount++;\
00092 }else\
00093 tskip_count++;\
00094 if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
00095 av_log(NULL, AV_LOG_ERROR, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n",\
00096 tsum*10/tcount, id, tcount, tskip_count);\
00097 }\
00098 }
00099 #else
00100 #define START_TIMER
00101 #define STOP_TIMER(id) {}
00102 #endif
00103
00104 #endif