annotate timer.h @ 607:819752f80c64 libavutil

export gcd function as av_gcd()
author aurel
date Sat, 17 Jan 2009 11:13:33 +0000
parents 3c748945c2ad
children 70bdd5501662
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
604
3c748945c2ad move timer related code in a new timer.h file
aurel
parents: 603
diff changeset
1 /**
3c748945c2ad move timer related code in a new timer.h file
aurel
parents: 603
diff changeset
2 * @file timer.h
3c748945c2ad move timer related code in a new timer.h file
aurel
parents: 603
diff changeset
3 * high precision timer, useful to profile code
3c748945c2ad move timer related code in a new timer.h file
aurel
parents: 603
diff changeset
4 *
108
11be8e0d1344 Add official LGPL license headers to the files that were missing them.
diego
parents: 104
diff changeset
5 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
11be8e0d1344 Add official LGPL license headers to the files that were missing them.
diego
parents: 104
diff changeset
6 *
116
d76a36742464 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 113
diff changeset
7 * This file is part of FFmpeg.
d76a36742464 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 113
diff changeset
8 *
d76a36742464 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 113
diff changeset
9 * FFmpeg is free software; you can redistribute it and/or
108
11be8e0d1344 Add official LGPL license headers to the files that were missing them.
diego
parents: 104
diff changeset
10 * modify it under the terms of the GNU Lesser General Public
11be8e0d1344 Add official LGPL license headers to the files that were missing them.
diego
parents: 104
diff changeset
11 * License as published by the Free Software Foundation; either
116
d76a36742464 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 113
diff changeset
12 * version 2.1 of the License, or (at your option) any later version.
108
11be8e0d1344 Add official LGPL license headers to the files that were missing them.
diego
parents: 104
diff changeset
13 *
116
d76a36742464 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 113
diff changeset
14 * FFmpeg is distributed in the hope that it will be useful,
108
11be8e0d1344 Add official LGPL license headers to the files that were missing them.
diego
parents: 104
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11be8e0d1344 Add official LGPL license headers to the files that were missing them.
diego
parents: 104
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11be8e0d1344 Add official LGPL license headers to the files that were missing them.
diego
parents: 104
diff changeset
17 * Lesser General Public License for more details.
11be8e0d1344 Add official LGPL license headers to the files that were missing them.
diego
parents: 104
diff changeset
18 *
11be8e0d1344 Add official LGPL license headers to the files that were missing them.
diego
parents: 104
diff changeset
19 * You should have received a copy of the GNU Lesser General Public
116
d76a36742464 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 113
diff changeset
20 * License along with FFmpeg; if not, write to the Free Software
108
11be8e0d1344 Add official LGPL license headers to the files that were missing them.
diego
parents: 104
diff changeset
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
11be8e0d1344 Add official LGPL license headers to the files that were missing them.
diego
parents: 104
diff changeset
22 */
11be8e0d1344 Add official LGPL license headers to the files that were missing them.
diego
parents: 104
diff changeset
23
604
3c748945c2ad move timer related code in a new timer.h file
aurel
parents: 603
diff changeset
24 #ifndef AVUTIL_TIMER_H
3c748945c2ad move timer related code in a new timer.h file
aurel
parents: 603
diff changeset
25 #define AVUTIL_TIMER_H
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
26
604
3c748945c2ad move timer related code in a new timer.h file
aurel
parents: 603
diff changeset
27 #include <stdlib.h>
3c748945c2ad move timer related code in a new timer.h file
aurel
parents: 603
diff changeset
28 #include <stdint.h>
3c748945c2ad move timer related code in a new timer.h file
aurel
parents: 603
diff changeset
29 #include "config.h"
129
ccae53673692 Fix ASF format parser's broken UTF-16 string handling
gpoirier
parents: 127
diff changeset
30
603
880c6441f56a Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 592
diff changeset
31 #if ARCH_X86 || ARCH_PPC || ARCH_BFIN
370
de3dc287f939 * Making [START|STOP]_TIMER work on architectures that support gethrtime()
romansh
parents: 342
diff changeset
32 #define AV_READ_TIME read_time
603
880c6441f56a Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 592
diff changeset
33 #if ARCH_X86
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
34 static inline uint64_t read_time(void)
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
35 {
580
fddfdadb477f Port read_time() that works on x86_32 and 64 from noe.
michael
parents: 578
diff changeset
36 uint32_t a, d;
578
b20a4eb68876 Convert asm keyword into __asm__.
flameeyes
parents: 576
diff changeset
37 __asm__ volatile("rdtsc\n\t"
452
4b2cd7e98d58 prettyprinting cosmetics
diego
parents: 443
diff changeset
38 : "=a" (a), "=d" (d));
580
fddfdadb477f Port read_time() that works on x86_32 and 64 from noe.
michael
parents: 578
diff changeset
39 return ((uint64_t)d << 32) + a;
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
40 }
342
02c938e7a087 Blackfin - read_time primitive
mhoffman
parents: 341
diff changeset
41 #elif ARCH_BFIN
02c938e7a087 Blackfin - read_time primitive
mhoffman
parents: 341
diff changeset
42 static inline uint64_t read_time(void)
02c938e7a087 Blackfin - read_time primitive
mhoffman
parents: 341
diff changeset
43 {
02c938e7a087 Blackfin - read_time primitive
mhoffman
parents: 341
diff changeset
44 union {
02c938e7a087 Blackfin - read_time primitive
mhoffman
parents: 341
diff changeset
45 struct {
02c938e7a087 Blackfin - read_time primitive
mhoffman
parents: 341
diff changeset
46 unsigned lo;
02c938e7a087 Blackfin - read_time primitive
mhoffman
parents: 341
diff changeset
47 unsigned hi;
02c938e7a087 Blackfin - read_time primitive
mhoffman
parents: 341
diff changeset
48 } p;
02c938e7a087 Blackfin - read_time primitive
mhoffman
parents: 341
diff changeset
49 unsigned long long c;
02c938e7a087 Blackfin - read_time primitive
mhoffman
parents: 341
diff changeset
50 } t;
578
b20a4eb68876 Convert asm keyword into __asm__.
flameeyes
parents: 576
diff changeset
51 __asm__ volatile ("%0=cycles; %1=cycles2;" : "=d" (t.p.lo), "=d" (t.p.hi));
342
02c938e7a087 Blackfin - read_time primitive
mhoffman
parents: 341
diff changeset
52 return t.c;
02c938e7a087 Blackfin - read_time primitive
mhoffman
parents: 341
diff changeset
53 }
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
54 #else //FIXME check ppc64
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
55 static inline uint64_t read_time(void)
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
56 {
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
57 uint32_t tbu, tbl, temp;
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
58
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
59 /* from section 2.2.1 of the 32-bit PowerPC PEM */
578
b20a4eb68876 Convert asm keyword into __asm__.
flameeyes
parents: 576
diff changeset
60 __asm__ volatile(
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
61 "1:\n"
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
62 "mftbu %2\n"
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
63 "mftb %0\n"
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
64 "mftbu %1\n"
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
65 "cmpw %2,%1\n"
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
66 "bne 1b\n"
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
67 : "=r"(tbl), "=r"(tbu), "=r"(temp)
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
68 :
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
69 : "cc");
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
70
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
71 return (((uint64_t)tbu)<<32) | (uint64_t)tbl;
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
72 }
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
73 #endif
603
880c6441f56a Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 592
diff changeset
74 #elif HAVE_GETHRTIME
370
de3dc287f939 * Making [START|STOP]_TIMER work on architectures that support gethrtime()
romansh
parents: 342
diff changeset
75 #define AV_READ_TIME gethrtime
de3dc287f939 * Making [START|STOP]_TIMER work on architectures that support gethrtime()
romansh
parents: 342
diff changeset
76 #endif
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
77
370
de3dc287f939 * Making [START|STOP]_TIMER work on architectures that support gethrtime()
romansh
parents: 342
diff changeset
78 #ifdef AV_READ_TIME
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
79 #define START_TIMER \
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
80 uint64_t tend;\
370
de3dc287f939 * Making [START|STOP]_TIMER work on architectures that support gethrtime()
romansh
parents: 342
diff changeset
81 uint64_t tstart= AV_READ_TIME();\
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
82
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
83 #define STOP_TIMER(id) \
370
de3dc287f939 * Making [START|STOP]_TIMER work on architectures that support gethrtime()
romansh
parents: 342
diff changeset
84 tend= AV_READ_TIME();\
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
85 {\
452
4b2cd7e98d58 prettyprinting cosmetics
diego
parents: 443
diff changeset
86 static uint64_t tsum=0;\
4b2cd7e98d58 prettyprinting cosmetics
diego
parents: 443
diff changeset
87 static int tcount=0;\
4b2cd7e98d58 prettyprinting cosmetics
diego
parents: 443
diff changeset
88 static int tskip_count=0;\
604
3c748945c2ad move timer related code in a new timer.h file
aurel
parents: 603
diff changeset
89 if(tcount<2 || tend - tstart < 8*tsum/tcount || tend - tstart < 2000){\
452
4b2cd7e98d58 prettyprinting cosmetics
diego
parents: 443
diff changeset
90 tsum+= tend - tstart;\
4b2cd7e98d58 prettyprinting cosmetics
diego
parents: 443
diff changeset
91 tcount++;\
4b2cd7e98d58 prettyprinting cosmetics
diego
parents: 443
diff changeset
92 }else\
4b2cd7e98d58 prettyprinting cosmetics
diego
parents: 443
diff changeset
93 tskip_count++;\
4b2cd7e98d58 prettyprinting cosmetics
diego
parents: 443
diff changeset
94 if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
516
80cd26ba5c7c Make START/STOP_TIMER not require -v 2.
michael
parents: 513
diff changeset
95 av_log(NULL, AV_LOG_ERROR, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n",\
452
4b2cd7e98d58 prettyprinting cosmetics
diego
parents: 443
diff changeset
96 tsum*10/tcount, id, tcount, tskip_count);\
4b2cd7e98d58 prettyprinting cosmetics
diego
parents: 443
diff changeset
97 }\
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
98 }
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
99 #else
12
ce8f9f4390c3 COSMETICS: Remove all trailing whitespace.
diego
parents: 11
diff changeset
100 #define START_TIMER
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
101 #define STOP_TIMER(id) {}
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
102 #endif
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
103
604
3c748945c2ad move timer related code in a new timer.h file
aurel
parents: 603
diff changeset
104 #endif /* AVUTIL_TIMER_H */