]> git.sesse.net Git - x264/commitdiff
Optimizations in predict_mv_direct
authorFiona Glaser <fiona@x264.com>
Mon, 15 Dec 2008 02:30:51 +0000 (18:30 -0800)
committerFiona Glaser <fiona@x264.com>
Mon, 15 Dec 2008 02:33:11 +0000 (18:33 -0800)
Add some early terminations and minor optimizations
This change may also fix the extremely rare direct+threading MV bug.

common/macroblock.c

index 0ee4880b683fdaf958ebcbf4938967f76e514882..bf2fe4960a389288a4ba21860062bd113837a107 100644 (file)
@@ -273,29 +273,27 @@ static int x264_mb_predict_mv_direct16x16_spatial( x264_t *h )
 
     if( ref[0] < 0 && ref[1] < 0 )
     {
-        ref[0] =
-        ref[1] = 0;
-        *(uint64_t*)mv[0] = 0;
+        x264_macroblock_cache_ref( h, 0, 0, 4, 4, 0, 0 );
+        x264_macroblock_cache_ref( h, 0, 0, 4, 4, 1, 0 );
+        x264_macroblock_cache_mv( h, 0, 0, 4, 4, 0, 0 );
+        x264_macroblock_cache_mv( h, 0, 0, 4, 4, 1, 0 );
+        return 1;
     }
+
+    if( ref[0] >= 0 )
+        x264_mb_predict_mv_16x16( h, 0, ref[0], mv[0] );
     else
-    {
-        for( i_list=0; i_list<2; i_list++ )
-        {
-            if( ref[i_list] >= 0 )
-                x264_mb_predict_mv_16x16( h, i_list, ref[i_list], mv[i_list] );
-            else
-                *(uint32_t*)mv[i_list] = 0;
-        }
-    }
+        *(uint32_t*)mv[0] = 0;
+    if( ref[1] >= 0 )
+        x264_mb_predict_mv_16x16( h, 1, ref[1], mv[1] );
+    else
+        *(uint32_t*)mv[1] = 0;
 
     x264_macroblock_cache_ref( h, 0, 0, 4, 4, 0, ref[0] );
     x264_macroblock_cache_ref( h, 0, 0, 4, 4, 1, ref[1] );
     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( IS_INTRA( type_col ) )
-        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] ) )
@@ -308,6 +306,9 @@ static int x264_mb_predict_mv_direct16x16_spatial( x264_t *h )
         return 0;
     }
 
+    if( IS_INTRA( type_col ) || (ref[0]&&ref[1]) )
+        return 1;
+
     b8x8 = h->sps->b_direct8x8_inference ||
            (type_col != P_8x8 && type_col != B_SKIP && type_col != B_DIRECT && type_col != B_8x8);