[FFmpeg-cvslog] av_compare_ts: Improve speed when calculations fit in 64bit.

Michael Niedermayer git at videolan.org
Wed May 11 22:17:39 CEST 2011


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Wed May 11 20:41:19 2011 +0200| [a18eff49c03622c628913d0199dfa61e5c29f0d6] | committer: Michael Niedermayer

av_compare_ts: Improve speed when calculations fit in 64bit.

about 110 cpu cycles before 60 cpu cycles afterwards.
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a18eff49c03622c628913d0199dfa61e5c29f0d6
---

 libavutil/mathematics.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/libavutil/mathematics.c b/libavutil/mathematics.c
index c6851cb..cfe8fbc 100644
--- a/libavutil/mathematics.c
+++ b/libavutil/mathematics.c
@@ -27,6 +27,7 @@
 #include <stdint.h>
 #include <limits.h>
 #include "mathematics.h"
+#include "libavutil/common.h"
 
 const uint8_t ff_sqrt_tab[256]={
   0, 16, 23, 28, 32, 36, 40, 43, 46, 48, 51, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 77, 79, 80, 82, 84, 85, 87, 88, 90,
@@ -139,6 +140,8 @@ int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){
 int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b){
     int64_t a= tb_a.num * (int64_t)tb_b.den;
     int64_t b= tb_b.num * (int64_t)tb_a.den;
+    if((FFABS(ts_a)|a|FFABS(ts_b)|b)<=INT_MAX)
+        return (ts_a*a > ts_b*b) - (ts_a*a < ts_b*b);
     if (av_rescale_rnd(ts_a, a, b, AV_ROUND_DOWN) < ts_b) return -1;
     if (av_rescale_rnd(ts_b, b, a, AV_ROUND_DOWN) < ts_a) return  1;
     return 0;



More information about the ffmpeg-cvslog mailing list