Add faster mv0 special case for macroblock-tree
authorFiona Glaser <fiona@x264.com>
Sat, 10 Apr 2010 01:13:22 +0000 (18:13 -0700)
committerFiona Glaser <fiona@x264.com>
Sun, 11 Apr 2010 03:44:55 +0000 (20:44 -0700)
Improves performance on low-motion video.

encoder/slicetype.c

index dac02298c0fc29d4d1db1426852bfdb58e4ab3a1..d1c31e79c21f6ce7ce797442e77ca46794334417 100644 (file)
@@ -686,12 +686,24 @@ static void x264_macroblock_tree_propagate( x264_t *h, x264_frame_t **frames, in
                 for( int list = 0; list < 2; list++ )
                     if( (lists_used >> list)&1 )
                     {
+#define CLIP_ADD(s,x) (s) = X264_MIN((s)+(x),(1<<16)-1)
+                        int listamount = propagate_amount;
+                        /* Apply bipred weighting. */
+                        if( lists_used == 3 )
+                            listamount = (listamount * bipred_weights[list] + 32) >> 6;
+
+                        /* Early termination for simple case of mv0. */
+                        if( !M32( mvs[list][mb_index] ) )
+                        {
+                            CLIP_ADD( ref_costs[list][mb_index], listamount );
+                            continue;
+                        }
+
                         int x = mvs[list][mb_index][0];
                         int y = mvs[list][mb_index][1];
-                        int listamount = propagate_amount;
                         int mbx = (x>>5)+h->mb.i_mb_x;
                         int mby = (y>>5)+h->mb.i_mb_y;
-                        int idx0 = mbx + mby*h->mb.i_mb_stride;
+                        int idx0 = mbx + mby * h->mb.i_mb_stride;
                         int idx1 = idx0 + 1;
                         int idx2 = idx0 + h->mb.i_mb_stride;
                         int idx3 = idx0 + h->mb.i_mb_stride + 1;
@@ -702,12 +714,6 @@ static void x264_macroblock_tree_propagate( x264_t *h, x264_frame_t **frames, in
                         int idx2weight = y*(32-x);
                         int idx3weight = y*x;
 
-                        /* Apply bipred weighting. */
-                        if( lists_used == 3 )
-                            listamount = (listamount * bipred_weights[list] + 32) >> 6;
-
-#define CLIP_ADD(s,x) (s) = X264_MIN((s)+(x),(1<<16)-1)
-
                         /* We could just clip the MVs, but pixels that lie outside the frame probably shouldn't
                          * be counted. */
                         if( mbx < h->sps->i_mb_width-1 && mby < h->sps->i_mb_height-1 && mbx >= 0 && mby >= 0 )