[x264-devel] commit: VLC table optimizations (Jason Garrett-Glaser )

git version control git at videolan.org
Sat Dec 27 05:02:24 CET 2008


x264 | branch: master | Jason Garrett-Glaser <darkshikari at gmail.com> | Fri Dec 26 07:35:49 2008 -0500| [40ad1b6d411d1e7d0788d29627804a19977bb6ee] | committer: Jason Garrett-Glaser 

VLC table optimizations
Slightly reorganize VLC tables for ~2% faster block_residual_write_cavlc.
Also a small optimization in p8x8 CAVLC.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=40ad1b6d411d1e7d0788d29627804a19977bb6ee
---

 common/bs.h     |    5 +++--
 common/vlc.c    |   38 +++++++++++---------------------------
 encoder/cavlc.c |   12 ++++++------
 3 files changed, 20 insertions(+), 35 deletions(-)

diff --git a/common/bs.h b/common/bs.h
index 7ec1e10..463b418 100644
--- a/common/bs.h
+++ b/common/bs.h
@@ -50,10 +50,11 @@ typedef struct bs_s
     int     i_bits_encoded; /* RD only */
 } bs_t;
 
-extern const vlc_t x264_coeff_token[5][17*4];
+extern const vlc_t x264_coeff0_token[5];
+extern const vlc_t x264_coeff_token[5][16*4];
 extern const vlc_t x264_total_zeros[15][16];
 extern const vlc_t x264_total_zeros_dc[3][4];
-extern const vlc_t x264_run_before[7][15];
+extern const vlc_t x264_run_before[7][16];
 
 /* A larger level table size theoretically could help a bit at extremely
  * high bitrates, but the cost in cache is usually too high for it to be
diff --git a/common/vlc.c b/common/vlc.c
index 6c15963..e575dfb 100644
--- a/common/vlc.c
+++ b/common/vlc.c
@@ -21,15 +21,19 @@
 #include "common.h"
 
 #define MKVLC( a, b ) { a, b }
-const vlc_t x264_coeff_token[5][17*4] =
+const vlc_t x264_coeff0_token[5] =
+{
+    MKVLC( 0x1, 1 ), /* str=1 */
+    MKVLC( 0x3, 2 ), /* str=11 */
+    MKVLC( 0xf, 4 ), /* str=1111 */
+    MKVLC( 0x3, 6 ), /* str=000011 */
+    MKVLC( 0x1, 2 )  /* str=01 */
+};
+
+const vlc_t x264_coeff_token[5][16*4] =
 {
     /* table 0 */
     {
-        MKVLC( 0x1, 1 ), /* str=1 */
-        MKVLC( 0x0, 0 ), /* str= */
-        MKVLC( 0x0, 0 ), /* str= */
-        MKVLC( 0x0, 0 ), /* str= */
-
         MKVLC( 0x5, 6 ), /* str=000101 */
         MKVLC( 0x1, 2 ), /* str=01 */
         MKVLC( 0x0, 0 ), /* str= */
@@ -113,11 +117,6 @@ const vlc_t x264_coeff_token[5][17*4] =
 
     /* table 1 */
     {
-        MKVLC( 0x3, 2 ), /* str=11 */
-        MKVLC( 0x0, 0 ), /* str= */
-        MKVLC( 0x0, 0 ), /* str= */
-        MKVLC( 0x0, 0 ), /* str= */
-
         MKVLC( 0xb, 6 ), /* str=001011 */
         MKVLC( 0x2, 2 ), /* str=10 */
         MKVLC( 0x0, 0 ), /* str= */
@@ -200,11 +199,6 @@ const vlc_t x264_coeff_token[5][17*4] =
     },
     /* table 2 */
     {
-        MKVLC( 0xf, 4 ), /* str=1111 */
-        MKVLC( 0x0, 0 ), /* str= */
-        MKVLC( 0x0, 0 ), /* str= */
-        MKVLC( 0x0, 0 ), /* str= */
-
         MKVLC( 0xf, 6 ), /* str=001111 */
         MKVLC( 0xe, 4 ), /* str=1110 */
         MKVLC( 0x0, 0 ), /* str= */
@@ -288,11 +282,6 @@ const vlc_t x264_coeff_token[5][17*4] =
 
     /* table 3 */
     {
-        MKVLC( 0x3, 6 ), /* str=000011 */
-        MKVLC( 0x0, 0 ), /* str= */
-        MKVLC( 0x0, 0 ), /* str= */
-        MKVLC( 0x0, 0 ), /* str= */
-
         MKVLC( 0x0, 6 ), /* str=000000 */
         MKVLC( 0x1, 6 ), /* str=000001 */
         MKVLC( 0x0, 0 ), /* str= */
@@ -376,11 +365,6 @@ const vlc_t x264_coeff_token[5][17*4] =
 
     /* table 4 */
     {
-        MKVLC( 0x1, 2 ), /* str=01 */
-        MKVLC( 0x0, 0 ), /* str= */
-        MKVLC( 0x0, 0 ), /* str= */
-        MKVLC( 0x0, 0 ), /* str= */
-
         MKVLC( 0x7, 6 ), /* str=000111 */
         MKVLC( 0x1, 1 ), /* str=1 */
         MKVLC( 0x0, 0 ), /* str= */
@@ -762,7 +746,7 @@ const vlc_t x264_total_zeros_dc[3][4] =
 };
 
 /* x264_run_before[__MIN( i_zero_left -1, 6 )][run_before] */
-const vlc_t x264_run_before[7][15] =
+const vlc_t x264_run_before[7][16] =
 {
     { /* i_zero_left 1 */
         MKVLC( 0x1, 1 ), /* str=1 */
diff --git a/encoder/cavlc.c b/encoder/cavlc.c
index 053d222..1a338ac 100644
--- a/encoder/cavlc.c
+++ b/encoder/cavlc.c
@@ -125,7 +125,7 @@ static void block_residual_write_cavlc( x264_t *h, bs_t *s, int i_ctxBlockCat, i
 
     if( !h->mb.cache.non_zero_count[x264_scan8[i_idx]] )
     {
-        bs_write_vlc( s, x264_coeff_token[nC][0] );
+        bs_write_vlc( s, x264_coeff0_token[nC] );
         return;
     }
 
@@ -158,7 +158,7 @@ static void block_residual_write_cavlc( x264_t *h, bs_t *s, int i_ctxBlockCat, i
     i_sign >>= 3-i_trailing;
 
     /* total/trailing */
-    bs_write_vlc( s, x264_coeff_token[nC][i_total*4+i_trailing] );
+    bs_write_vlc( s, x264_coeff_token[nC][i_total*4+i_trailing-4] );
 
     i_suffix_length = i_total > 10 && i_trailing < 3;
     if( i_trailing > 0 || RDO_SKIP_BS )
@@ -441,17 +441,17 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
     }
     else if( i_mb_type == P_8x8 )
     {
-        int b_sub_ref0;
+        int b_sub_ref;
         if( (h->mb.cache.ref[0][x264_scan8[0]] | h->mb.cache.ref[0][x264_scan8[ 4]] |
              h->mb.cache.ref[0][x264_scan8[8]] | h->mb.cache.ref[0][x264_scan8[12]]) == 0 )
         {
             bs_write_ue( s, 4 );
-            b_sub_ref0 = 0;
+            b_sub_ref = 0;
         }
         else
         {
             bs_write_ue( s, 3 );
-            b_sub_ref0 = 1;
+            b_sub_ref = h->mb.pic.i_fref[0] > 1;
         }
 
         /* sub mb type */
@@ -462,7 +462,7 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
             bs_write( s, 4, 0xf );
 
         /* ref0 */
-        if( h->mb.pic.i_fref[0] > 1 && b_sub_ref0 )
+        if( b_sub_ref )
         {
             bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[0]] );
             bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[4]] );



More information about the x264-devel mailing list