Originally committed as revision 16618 to svn://svn.ffmpeg.org/ffmpeg/trunk
| ... | ... |
@@ -323,79 +323,6 @@ static inline av_pure int ff_get_fourcc(const char *s){
|
| 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 |
| 40 | 41 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,104 @@ |
| 0 |
+/** |
|
| 1 |
+ * @file timer.h |
|
| 2 |
+ * high precision timer, useful to profile code |
|
| 3 |
+ * |
|
| 4 |
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> |
|
| 5 |
+ * |
|
| 6 |
+ * This file is part of FFmpeg. |
|
| 7 |
+ * |
|
| 8 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
| 9 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 10 |
+ * License as published by the Free Software Foundation; either |
|
| 11 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
| 12 |
+ * |
|
| 13 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
| 14 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 15 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 16 |
+ * Lesser General Public License for more details. |
|
| 17 |
+ * |
|
| 18 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 19 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
| 20 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
| 21 |
+ */ |
|
| 22 |
+ |
|
| 23 |
+#ifndef AVUTIL_TIMER_H |
|
| 24 |
+#define AVUTIL_TIMER_H |
|
| 25 |
+ |
|
| 26 |
+#include <stdlib.h> |
|
| 27 |
+#include <stdint.h> |
|
| 28 |
+#include "config.h" |
|
| 29 |
+ |
|
| 30 |
+#if ARCH_X86 || ARCH_PPC || ARCH_BFIN |
|
| 31 |
+#define AV_READ_TIME read_time |
|
| 32 |
+#if ARCH_X86 |
|
| 33 |
+static inline uint64_t read_time(void) |
|
| 34 |
+{
|
|
| 35 |
+ uint32_t a, d; |
|
| 36 |
+ __asm__ volatile("rdtsc\n\t"
|
|
| 37 |
+ : "=a" (a), "=d" (d)); |
|
| 38 |
+ return ((uint64_t)d << 32) + a; |
|
| 39 |
+} |
|
| 40 |
+#elif ARCH_BFIN |
|
| 41 |
+static inline uint64_t read_time(void) |
|
| 42 |
+{
|
|
| 43 |
+ union {
|
|
| 44 |
+ struct {
|
|
| 45 |
+ unsigned lo; |
|
| 46 |
+ unsigned hi; |
|
| 47 |
+ } p; |
|
| 48 |
+ unsigned long long c; |
|
| 49 |
+ } t; |
|
| 50 |
+ __asm__ volatile ("%0=cycles; %1=cycles2;" : "=d" (t.p.lo), "=d" (t.p.hi));
|
|
| 51 |
+ return t.c; |
|
| 52 |
+} |
|
| 53 |
+#else //FIXME check ppc64 |
|
| 54 |
+static inline uint64_t read_time(void) |
|
| 55 |
+{
|
|
| 56 |
+ uint32_t tbu, tbl, temp; |
|
| 57 |
+ |
|
| 58 |
+ /* from section 2.2.1 of the 32-bit PowerPC PEM */ |
|
| 59 |
+ __asm__ volatile( |
|
| 60 |
+ "1:\n" |
|
| 61 |
+ "mftbu %2\n" |
|
| 62 |
+ "mftb %0\n" |
|
| 63 |
+ "mftbu %1\n" |
|
| 64 |
+ "cmpw %2,%1\n" |
|
| 65 |
+ "bne 1b\n" |
|
| 66 |
+ : "=r"(tbl), "=r"(tbu), "=r"(temp) |
|
| 67 |
+ : |
|
| 68 |
+ : "cc"); |
|
| 69 |
+ |
|
| 70 |
+ return (((uint64_t)tbu)<<32) | (uint64_t)tbl; |
|
| 71 |
+} |
|
| 72 |
+#endif |
|
| 73 |
+#elif HAVE_GETHRTIME |
|
| 74 |
+#define AV_READ_TIME gethrtime |
|
| 75 |
+#endif |
|
| 76 |
+ |
|
| 77 |
+#ifdef AV_READ_TIME |
|
| 78 |
+#define START_TIMER \ |
|
| 79 |
+uint64_t tend;\ |
|
| 80 |
+uint64_t tstart= AV_READ_TIME();\ |
|
| 81 |
+ |
|
| 82 |
+#define STOP_TIMER(id) \ |
|
| 83 |
+tend= AV_READ_TIME();\ |
|
| 84 |
+{\
|
|
| 85 |
+ static uint64_t tsum=0;\ |
|
| 86 |
+ static int tcount=0;\ |
|
| 87 |
+ static int tskip_count=0;\ |
|
| 88 |
+ if(tcount<2 || tend - tstart < 8*tsum/tcount || tend - tstart < 2000){\
|
|
| 89 |
+ tsum+= tend - tstart;\ |
|
| 90 |
+ tcount++;\ |
|
| 91 |
+ }else\ |
|
| 92 |
+ tskip_count++;\ |
|
| 93 |
+ if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
|
|
| 94 |
+ av_log(NULL, AV_LOG_ERROR, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n",\ |
|
| 95 |
+ tsum*10/tcount, id, tcount, tskip_count);\ |
|
| 96 |
+ }\ |
|
| 97 |
+} |
|
| 98 |
+#else |
|
| 99 |
+#define START_TIMER |
|
| 100 |
+#define STOP_TIMER(id) {}
|
|
| 101 |
+#endif |
|
| 102 |
+ |
|
| 103 |
+#endif /* AVUTIL_TIMER_H */ |