Revision 2f5421d5 libavutil/common.h

View differences:

libavutil/common.h
323 323
        }\
324 324
    }
325 325

  
326
#if ARCH_X86 || ARCH_PPC || ARCH_BFIN
327
#define AV_READ_TIME read_time
328
#if ARCH_X86
329
static inline uint64_t read_time(void)
330
{
331
    uint32_t a, d;
332
    __asm__ volatile("rdtsc\n\t"
333
                 : "=a" (a), "=d" (d));
334
    return ((uint64_t)d << 32) + a;
335
}
336
#elif ARCH_BFIN
337
static inline uint64_t read_time(void)
338
{
339
    union {
340
        struct {
341
            unsigned lo;
342
            unsigned hi;
343
        } p;
344
        unsigned long long c;
345
    } t;
346
    __asm__ volatile ("%0=cycles; %1=cycles2;" : "=d" (t.p.lo), "=d" (t.p.hi));
347
    return t.c;
348
}
349
#else //FIXME check ppc64
350
static inline uint64_t read_time(void)
351
{
352
    uint32_t tbu, tbl, temp;
353

  
354
     /* from section 2.2.1 of the 32-bit PowerPC PEM */
355
     __asm__ volatile(
356
         "1:\n"
357
         "mftbu  %2\n"
358
         "mftb   %0\n"
359
         "mftbu  %1\n"
360
         "cmpw   %2,%1\n"
361
         "bne    1b\n"
362
     : "=r"(tbl), "=r"(tbu), "=r"(temp)
363
     :
364
     : "cc");
365

  
366
     return (((uint64_t)tbu)<<32) | (uint64_t)tbl;
367
}
368
#endif
369
#elif HAVE_GETHRTIME
370
#define AV_READ_TIME gethrtime
371
#endif
372

  
373
#ifdef AV_READ_TIME
374
#define START_TIMER \
375
uint64_t tend;\
376
uint64_t tstart= AV_READ_TIME();\
377

  
378
#define STOP_TIMER(id) \
379
tend= AV_READ_TIME();\
380
{\
381
    static uint64_t tsum=0;\
382
    static int tcount=0;\
383
    static int tskip_count=0;\
384
    if(tcount<2 || tend - tstart < FFMAX(8*tsum/tcount, 2000)){\
385
        tsum+= tend - tstart;\
386
        tcount++;\
387
    }else\
388
        tskip_count++;\
389
    if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
390
        av_log(NULL, AV_LOG_ERROR, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n",\
391
               tsum*10/tcount, id, tcount, tskip_count);\
392
    }\
393
}
394
#else
395
#define START_TIMER
396
#define STOP_TIMER(id) {}
397
#endif
398

  
399 326
/**
400 327
 * Returns NULL if CONFIG_SMALL is true otherwise the argument
401 328
 * without modifications, used to disable the definition of strings

Also available in: Unified diff