]> git.sesse.net Git - x264/commitdiff
Backport various speed tweak ideas from ffmpeg
authorFiona Glaser <fiona@x264.com>
Sat, 13 Feb 2010 05:15:12 +0000 (21:15 -0800)
committerFiona Glaser <fiona@x264.com>
Mon, 15 Feb 2010 08:59:56 +0000 (00:59 -0800)
Add mv0 early termination to spatial direct calculation
Up to twice as fast direct mv calculation on near-motionless video.

Branchless CAVLC level code adjustment based on trailing ones.
A few clocks faster.

Check tc value before clipping in C version of deblock functions.
Much faster, but nobody uses those anyways.

Thanks to Michael Niedermayer for the ideas.

common/frame.c
common/macroblock.c
encoder/cavlc.c

index e7003fdf07c4359f73f5b24488b608fc95e4dcdb..79376d8bb64c38bf20bbd693aba61450411da416 100644 (file)
@@ -472,12 +472,14 @@ static inline void deblock_luma_c( uint8_t *pix, int xstride, int ystride, int a
                 int delta;
                 if( abs( p2 - p0 ) < beta )
                 {
-                    pix[-2*xstride] = p1 + x264_clip3( (( p2 + ((p0 + q0 + 1) >> 1)) >> 1) - p1, -tc0[i], tc0[i] );
+                    if( tc0[i] )
+                        pix[-2*xstride] = p1 + x264_clip3( (( p2 + ((p0 + q0 + 1) >> 1)) >> 1) - p1, -tc0[i], tc0[i] );
                     tc++;
                 }
                 if( abs( q2 - q0 ) < beta )
                 {
-                    pix[ 1*xstride] = q1 + x264_clip3( (( q2 + ((p0 + q0 + 1) >> 1)) >> 1) - q1, -tc0[i], tc0[i] );
+                    if( tc0[i] )
+                        pix[ 1*xstride] = q1 + x264_clip3( (( q2 + ((p0 + q0 + 1) >> 1)) >> 1) - q1, -tc0[i], tc0[i] );
                     tc++;
                 }
 
index 4608dcd99da0bb574f5f7bc917c310676be55b3d..88c51609732bd02b4c0a55116b9dcc54ded0d44d 100644 (file)
@@ -272,6 +272,9 @@ static int x264_mb_predict_mv_direct16x16_spatial( x264_t *h )
     x264_macroblock_cache_mv_ptr( h, 0, 0, 4, 4, 0, mv[0] );
     x264_macroblock_cache_mv_ptr( h, 0, 0, 4, 4, 1, mv[1] );
 
+    if( !M64( mv ) )
+        return 1;
+
     if( h->param.i_threads > 1
         && ( mv[0][1] > h->mb.mv_max_spel[1]
           || mv[1][1] > h->mb.mv_max_spel[1] ) )
index cee6f4e4b65e2127e9bf12c5c4d32a5879c779d6..e9243b370e84f9fd3be3c23a408f620ae78ebfa9 100644 (file)
@@ -147,10 +147,9 @@ static int block_residual_write_cavlc( x264_t *h, int i_ctxBlockCat, int16_t *l,
 
     if( i_trailing < i_total )
     {
-        int16_t val = runlevel.level[i_trailing];
-        int16_t val_original = runlevel.level[i_trailing]+LEVEL_TABLE_SIZE/2;
-        if( i_trailing < 3 )
-            val -= (val>>15)|1; /* as runlevel.level[i] can't be 1 for the first one if i_trailing < 3 */
+        int val = runlevel.level[i_trailing];
+        int val_original = runlevel.level[i_trailing]+LEVEL_TABLE_SIZE/2;
+        val -= ((val>>31)|1) & -(i_trailing < 3); /* as runlevel.level[i] can't be 1 for the first one if i_trailing < 3 */
         val += LEVEL_TABLE_SIZE/2;
 
         if( (unsigned)val_original < LEVEL_TABLE_SIZE )