Revision 2f5421d5

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
libavutil/internal.h
34 34
#include <stddef.h>
35 35
#include <assert.h>
36 36
#include "common.h"
37
#include "timer.h"
37 38

  
38 39
#ifndef attribute_align_arg
39 40
#if (!defined(__ICC) || __ICC > 1100) && AV_GCC_VERSION_AT_LEAST(4,2)
libavutil/timer.h
1
/**
2
 * @file timer.h
3
 * high precision timer, useful to profile code
4
 *
5
 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
6
 *
7
 * This file is part of FFmpeg.
8
 *
9
 * FFmpeg is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU Lesser General Public
11
 * License as published by the Free Software Foundation; either
12
 * version 2.1 of the License, or (at your option) any later version.
13
 *
14
 * FFmpeg is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 * Lesser General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public
20
 * License along with FFmpeg; if not, write to the Free Software
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
 */
23

  
24
#ifndef AVUTIL_TIMER_H
25
#define AVUTIL_TIMER_H
26

  
27
#include <stdlib.h>
28
#include <stdint.h>
29
#include "config.h"
30

  
31
#if ARCH_X86 || ARCH_PPC || ARCH_BFIN
32
#define AV_READ_TIME read_time
33
#if ARCH_X86
34
static inline uint64_t read_time(void)
35
{
36
    uint32_t a, d;
37
    __asm__ volatile("rdtsc\n\t"
38
                 : "=a" (a), "=d" (d));
39
    return ((uint64_t)d << 32) + a;
40
}
41
#elif ARCH_BFIN
42
static inline uint64_t read_time(void)
43
{
44
    union {
45
        struct {
46
            unsigned lo;
47
            unsigned hi;
48
        } p;
49
        unsigned long long c;
50
    } t;
51
    __asm__ volatile ("%0=cycles; %1=cycles2;" : "=d" (t.p.lo), "=d" (t.p.hi));
52
    return t.c;
53
}
54
#else //FIXME check ppc64
55
static inline uint64_t read_time(void)
56
{
57
    uint32_t tbu, tbl, temp;
58

  
59
     /* from section 2.2.1 of the 32-bit PowerPC PEM */
60
     __asm__ volatile(
61
         "1:\n"
62
         "mftbu  %2\n"
63
         "mftb   %0\n"
64
         "mftbu  %1\n"
65
         "cmpw   %2,%1\n"
66
         "bne    1b\n"
67
     : "=r"(tbl), "=r"(tbu), "=r"(temp)
68
     :
69
     : "cc");
70

  
71
     return (((uint64_t)tbu)<<32) | (uint64_t)tbl;
72
}
73
#endif
74
#elif HAVE_GETHRTIME
75
#define AV_READ_TIME gethrtime
76
#endif
77

  
78
#ifdef AV_READ_TIME
79
#define START_TIMER \
80
uint64_t tend;\
81
uint64_t tstart= AV_READ_TIME();\
82

  
83
#define STOP_TIMER(id) \
84
tend= AV_READ_TIME();\
85
{\
86
    static uint64_t tsum=0;\
87
    static int tcount=0;\
88
    static int tskip_count=0;\
89
    if(tcount<2 || tend - tstart < 8*tsum/tcount || tend - tstart < 2000){\
90
        tsum+= tend - tstart;\
91
        tcount++;\
92
    }else\
93
        tskip_count++;\
94
    if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
95
        av_log(NULL, AV_LOG_ERROR, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n",\
96
               tsum*10/tcount, id, tcount, tskip_count);\
97
    }\
98
}
99
#else
100
#define START_TIMER
101
#define STOP_TIMER(id) {}
102
#endif
103

  
104
#endif /* AVUTIL_TIMER_H */

Also available in: Unified diff