Mercurial > libavutil.hg
annotate timer.h @ 682:79f4e9cc2e07 libavutil
Remove the Mersenne Twister from the public API/ABI.
We provide better PRNGs.
| author | michael |
|---|---|
| date | Sun, 08 Mar 2009 14:35:13 +0000 |
| parents | 70bdd5501662 |
| children | fa8c9944568f |
| rev | line source |
|---|---|
| 604 | 1 /** |
|
642
70bdd5501662
Use full internal pathname in doxygen @file directives.
diego
parents:
604
diff
changeset
|
2 * @file libavutil/timer.h |
| 604 | 3 * high precision timer, useful to profile code |
| 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 | 24 #ifndef AVUTIL_TIMER_H |
| 25 #define AVUTIL_TIMER_H | |
|
0
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
26 |
| 604 | 27 #include <stdlib.h> |
| 28 #include <stdint.h> | |
| 29 #include "config.h" | |
|
129
ccae53673692
Fix ASF format parser's broken UTF-16 string handling
gpoirier
parents:
127
diff
changeset
|
30 |
| 603 | 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 | 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 | 37 __asm__ volatile("rdtsc\n\t" |
| 452 | 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 | 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; | |
| 578 | 51 __asm__ volatile ("%0=cycles; %1=cycles2;" : "=d" (t.p.lo), "=d" (t.p.hi)); |
| 342 | 52 return t.c; |
| 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 | 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 | 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 | 86 static uint64_t tsum=0;\ |
| 87 static int tcount=0;\ | |
| 88 static int tskip_count=0;\ | |
| 604 | 89 if(tcount<2 || tend - tstart < 8*tsum/tcount || tend - tstart < 2000){\ |
| 452 | 90 tsum+= tend - tstart;\ |
| 91 tcount++;\ | |
| 92 }else\ | |
| 93 tskip_count++;\ | |
| 94 if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\ | |
| 516 | 95 av_log(NULL, AV_LOG_ERROR, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n",\ |
| 452 | 96 tsum*10/tcount, id, tcount, tskip_count);\ |
| 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 | 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 | 104 #endif /* AVUTIL_TIMER_H */ |
