[x264-devel] [PATCH 13/29] common: Move shared tables to a common file

Vittorio Giovara vittorio.giovara at gmail.com
Fri Feb 10 22:18:48 CET 2017


---
 Makefile                   |   2 +-
 common/bitstream.h         |  12 +-
 common/cabac.c             |  85 ------
 common/common.h            |   1 +
 common/dct.c               |  64 ----
 common/dct.h               |   5 -
 common/mc.c                |   3 -
 common/mc.h                |   2 -
 common/quant.c             |  12 -
 common/{vlc.c => tables.c} | 422 ++++++++++++++++++---------
 common/tables.h            |  69 +++++
 common/vlc.c               | 710 ---------------------------------------------
 common/vlc.h               |  37 +++
 encoder/analyse.c          |  33 ---
 encoder/cabac.c            |  47 ---
 encoder/macroblock.h       |   3 -
 encoder/set.c              |  22 --
 17 files changed, 396 insertions(+), 1133 deletions(-)
 copy common/{vlc.c => tables.c} (63%)
 create mode 100644 common/tables.h
 create mode 100644 common/vlc.h

diff --git a/Makefile b/Makefile
index 6d578cb..f039fcc 100644
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,7 @@ SRCS = common/mc.c common/predict.c common/pixel.c common/macroblock.c \
        common/set.c common/quant.c common/deblock.c common/vlc.c \
        common/mvpred.c common/bitstream.c \
        common/log.c common/mem.c common/picture.c common/mathematics.c \
-       common/param.c \
+       common/param.c common/tables.c \
        encoder/analyse.c encoder/me.c encoder/ratecontrol.c \
        encoder/set.c encoder/macroblock.c encoder/cabac.c \
        encoder/cavlc.c encoder/encoder.c encoder/lookahead.c
diff --git a/common/bitstream.h b/common/bitstream.h
index 2816ef3..9cbb9c8 100644
--- a/common/bitstream.h
+++ b/common/bitstream.h
@@ -28,11 +28,7 @@
 #ifndef X264_BS_H
 #define X264_BS_H
 
-typedef struct
-{
-    uint8_t i_bits;
-    uint8_t i_size;
-} vlc_t;
+#include "common/vlc.h"
 
 typedef struct
 {
@@ -60,12 +56,6 @@ typedef struct
     ALIGNED_16( dctcoef level[18] );
 } x264_run_level_t;
 
-extern const vlc_t x264_coeff0_token[6];
-extern const vlc_t x264_coeff_token[6][16][4];
-extern const vlc_t x264_total_zeros[15][16];
-extern const vlc_t x264_total_zeros_2x2_dc[3][4];
-extern const vlc_t x264_total_zeros_2x4_dc[7][8];
-
 typedef struct
 {
     uint8_t *(*nal_escape)( uint8_t *dst, uint8_t *src, uint8_t *end );
diff --git a/common/cabac.c b/common/cabac.c
index ae6586f..76f37f8 100644
--- a/common/cabac.c
+++ b/common/cabac.c
@@ -1240,91 +1240,6 @@ static const int8_t x264_cabac_context_init_PB[3][1024][2] =
     }
 };
 
-const uint8_t x264_cabac_range_lps[64][4] =
-{
-    {  2,   2,   2,   2}, {  6,   7,   8,   9}, {  6,   7,   9,  10}, {  6,   8,   9,  11},
-    {  7,   8,  10,  11}, {  7,   9,  10,  12}, {  7,   9,  11,  12}, {  8,   9,  11,  13},
-    {  8,  10,  12,  14}, {  9,  11,  12,  14}, {  9,  11,  13,  15}, { 10,  12,  14,  16},
-    { 10,  12,  15,  17}, { 11,  13,  15,  18}, { 11,  14,  16,  19}, { 12,  14,  17,  20},
-    { 12,  15,  18,  21}, { 13,  16,  19,  22}, { 14,  17,  20,  23}, { 14,  18,  21,  24},
-    { 15,  19,  22,  25}, { 16,  20,  23,  27}, { 17,  21,  25,  28}, { 18,  22,  26,  30},
-    { 19,  23,  27,  31}, { 20,  24,  29,  33}, { 21,  26,  30,  35}, { 22,  27,  32,  37},
-    { 23,  28,  33,  39}, { 24,  30,  35,  41}, { 26,  31,  37,  43}, { 27,  33,  39,  45},
-    { 29,  35,  41,  48}, { 30,  37,  43,  50}, { 32,  39,  46,  53}, { 33,  41,  48,  56},
-    { 35,  43,  51,  59}, { 37,  45,  54,  62}, { 39,  48,  56,  65}, { 41,  50,  59,  69},
-    { 43,  53,  63,  72}, { 46,  56,  66,  76}, { 48,  59,  69,  80}, { 51,  62,  73,  85},
-    { 53,  65,  77,  89}, { 56,  69,  81,  94}, { 59,  72,  86,  99}, { 62,  76,  90, 104},
-    { 66,  80,  95, 110}, { 69,  85, 100, 116}, { 73,  89, 105, 122}, { 77,  94, 111, 128},
-    { 81,  99, 117, 135}, { 85, 104, 123, 142}, { 90, 110, 130, 150}, { 95, 116, 137, 158},
-    {100, 122, 144, 166}, {105, 128, 152, 175}, {111, 135, 160, 185}, {116, 142, 169, 195},
-    {123, 150, 178, 205}, {128, 158, 187, 216}, {128, 167, 197, 227}, {128, 176, 208, 240}
-};
-
-const uint8_t x264_cabac_transition[128][2] =
-{
-    {  0,   0}, {  1,   1}, {  2,  50}, { 51,   3}, {  2,  50}, { 51,   3}, {  4,  52}, { 53,   5},
-    {  6,  52}, { 53,   7}, {  8,  52}, { 53,   9}, { 10,  54}, { 55,  11}, { 12,  54}, { 55,  13},
-    { 14,  54}, { 55,  15}, { 16,  56}, { 57,  17}, { 18,  56}, { 57,  19}, { 20,  56}, { 57,  21},
-    { 22,  58}, { 59,  23}, { 24,  58}, { 59,  25}, { 26,  60}, { 61,  27}, { 28,  60}, { 61,  29},
-    { 30,  60}, { 61,  31}, { 32,  62}, { 63,  33}, { 34,  62}, { 63,  35}, { 36,  64}, { 65,  37},
-    { 38,  66}, { 67,  39}, { 40,  66}, { 67,  41}, { 42,  66}, { 67,  43}, { 44,  68}, { 69,  45},
-    { 46,  68}, { 69,  47}, { 48,  70}, { 71,  49}, { 50,  72}, { 73,  51}, { 52,  72}, { 73,  53},
-    { 54,  74}, { 75,  55}, { 56,  74}, { 75,  57}, { 58,  76}, { 77,  59}, { 60,  78}, { 79,  61},
-    { 62,  78}, { 79,  63}, { 64,  80}, { 81,  65}, { 66,  82}, { 83,  67}, { 68,  82}, { 83,  69},
-    { 70,  84}, { 85,  71}, { 72,  84}, { 85,  73}, { 74,  88}, { 89,  75}, { 76,  88}, { 89,  77},
-    { 78,  90}, { 91,  79}, { 80,  90}, { 91,  81}, { 82,  94}, { 95,  83}, { 84,  94}, { 95,  85},
-    { 86,  96}, { 97,  87}, { 88,  96}, { 97,  89}, { 90, 100}, {101,  91}, { 92, 100}, {101,  93},
-    { 94, 102}, {103,  95}, { 96, 104}, {105,  97}, { 98, 104}, {105,  99}, {100, 108}, {109, 101},
-    {102, 108}, {109, 103}, {104, 110}, {111, 105}, {106, 112}, {113, 107}, {108, 114}, {115, 109},
-    {110, 116}, {117, 111}, {112, 118}, {119, 113}, {114, 118}, {119, 115}, {116, 122}, {123, 117},
-    {118, 122}, {123, 119}, {120, 124}, {125, 121}, {122, 126}, {127, 123}, {124, 127}, {126, 125}
-};
-
-const uint8_t x264_cabac_renorm_shift[64] =
-{
-    6,5,4,4,3,3,3,3,2,2,2,2,2,2,2,2,
-    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
-    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-};
-
-/* -ln2(probability) */
-const uint16_t x264_cabac_entropy[128] =
-{
-    FIX8(0.0273), FIX8(5.7370), FIX8(0.0288), FIX8(5.6618),
-    FIX8(0.0303), FIX8(5.5866), FIX8(0.0320), FIX8(5.5114),
-    FIX8(0.0337), FIX8(5.4362), FIX8(0.0355), FIX8(5.3610),
-    FIX8(0.0375), FIX8(5.2859), FIX8(0.0395), FIX8(5.2106),
-    FIX8(0.0416), FIX8(5.1354), FIX8(0.0439), FIX8(5.0602),
-    FIX8(0.0463), FIX8(4.9851), FIX8(0.0488), FIX8(4.9099),
-    FIX8(0.0515), FIX8(4.8347), FIX8(0.0543), FIX8(4.7595),
-    FIX8(0.0572), FIX8(4.6843), FIX8(0.0604), FIX8(4.6091),
-    FIX8(0.0637), FIX8(4.5339), FIX8(0.0671), FIX8(4.4588),
-    FIX8(0.0708), FIX8(4.3836), FIX8(0.0747), FIX8(4.3083),
-    FIX8(0.0788), FIX8(4.2332), FIX8(0.0832), FIX8(4.1580),
-    FIX8(0.0878), FIX8(4.0828), FIX8(0.0926), FIX8(4.0076),
-    FIX8(0.0977), FIX8(3.9324), FIX8(0.1032), FIX8(3.8572),
-    FIX8(0.1089), FIX8(3.7820), FIX8(0.1149), FIX8(3.7068),
-    FIX8(0.1214), FIX8(3.6316), FIX8(0.1282), FIX8(3.5565),
-    FIX8(0.1353), FIX8(3.4813), FIX8(0.1429), FIX8(3.4061),
-    FIX8(0.1510), FIX8(3.3309), FIX8(0.1596), FIX8(3.2557),
-    FIX8(0.1686), FIX8(3.1805), FIX8(0.1782), FIX8(3.1053),
-    FIX8(0.1884), FIX8(3.0301), FIX8(0.1992), FIX8(2.9549),
-    FIX8(0.2107), FIX8(2.8797), FIX8(0.2229), FIX8(2.8046),
-    FIX8(0.2358), FIX8(2.7294), FIX8(0.2496), FIX8(2.6542),
-    FIX8(0.2642), FIX8(2.5790), FIX8(0.2798), FIX8(2.5038),
-    FIX8(0.2964), FIX8(2.4286), FIX8(0.3142), FIX8(2.3534),
-    FIX8(0.3331), FIX8(2.2782), FIX8(0.3532), FIX8(2.2030),
-    FIX8(0.3748), FIX8(2.1278), FIX8(0.3979), FIX8(2.0527),
-    FIX8(0.4226), FIX8(1.9775), FIX8(0.4491), FIX8(1.9023),
-    FIX8(0.4776), FIX8(1.8271), FIX8(0.5082), FIX8(1.7519),
-    FIX8(0.5412), FIX8(1.6767), FIX8(0.5768), FIX8(1.6015),
-    FIX8(0.6152), FIX8(1.5263), FIX8(0.6568), FIX8(1.4511),
-    FIX8(0.7020), FIX8(1.3759), FIX8(0.7513), FIX8(1.3008),
-    FIX8(0.8050), FIX8(1.2256), FIX8(0.8638), FIX8(1.1504),
-    FIX8(0.9285), FIX8(1.0752), FIX8(1.0000), FIX8(1.0000)
-};
-
 uint8_t x264_cabac_contexts[4][QP_MAX_SPEC+1][1024];
 
 void x264_cabac_init( x264_t *h )
diff --git a/common/common.h b/common/common.h
index 254ba4a..db5c47b 100644
--- a/common/common.h
+++ b/common/common.h
@@ -109,6 +109,7 @@ do {\
 #include "log.h"
 #include "mem.h"
 #include "mathematics.h"
+#include "tables.h"
 #include <stdarg.h>
 #include <stddef.h>
 #include <stdlib.h>
diff --git a/common/dct.c b/common/dct.c
index a270c4c..347dade 100644
--- a/common/dct.c
+++ b/common/dct.c
@@ -42,70 +42,6 @@
 #   include "mips/dct.h"
 #endif
 
-/* the inverse of the scaling factors introduced by 8x8 fdct */
-/* uint32 is for the asm implementation of trellis. the actual values fit in uint16. */
-#define W(i) (i==0 ? FIX8(1.0000) :\
-              i==1 ? FIX8(0.8859) :\
-              i==2 ? FIX8(1.6000) :\
-              i==3 ? FIX8(0.9415) :\
-              i==4 ? FIX8(1.2651) :\
-              i==5 ? FIX8(1.1910) :0)
-const uint32_t x264_dct8_weight_tab[64] = {
-    W(0), W(3), W(4), W(3),  W(0), W(3), W(4), W(3),
-    W(3), W(1), W(5), W(1),  W(3), W(1), W(5), W(1),
-    W(4), W(5), W(2), W(5),  W(4), W(5), W(2), W(5),
-    W(3), W(1), W(5), W(1),  W(3), W(1), W(5), W(1),
-
-    W(0), W(3), W(4), W(3),  W(0), W(3), W(4), W(3),
-    W(3), W(1), W(5), W(1),  W(3), W(1), W(5), W(1),
-    W(4), W(5), W(2), W(5),  W(4), W(5), W(2), W(5),
-    W(3), W(1), W(5), W(1),  W(3), W(1), W(5), W(1)
-};
-#undef W
-
-#define W(i) (i==0 ? FIX8(1.76777) :\
-              i==1 ? FIX8(1.11803) :\
-              i==2 ? FIX8(0.70711) :0)
-const uint32_t x264_dct4_weight_tab[16] = {
-    W(0), W(1), W(0), W(1),
-    W(1), W(2), W(1), W(2),
-    W(0), W(1), W(0), W(1),
-    W(1), W(2), W(1), W(2)
-};
-#undef W
-
-/* inverse squared */
-#define W(i) (i==0 ? FIX8(3.125) :\
-              i==1 ? FIX8(1.25) :\
-              i==2 ? FIX8(0.5) :0)
-const uint32_t x264_dct4_weight2_tab[16] = {
-    W(0), W(1), W(0), W(1),
-    W(1), W(2), W(1), W(2),
-    W(0), W(1), W(0), W(1),
-    W(1), W(2), W(1), W(2)
-};
-#undef W
-
-#define W(i) (i==0 ? FIX8(1.00000) :\
-              i==1 ? FIX8(0.78487) :\
-              i==2 ? FIX8(2.56132) :\
-              i==3 ? FIX8(0.88637) :\
-              i==4 ? FIX8(1.60040) :\
-              i==5 ? FIX8(1.41850) :0)
-const uint32_t x264_dct8_weight2_tab[64] = {
-    W(0), W(3), W(4), W(3),  W(0), W(3), W(4), W(3),
-    W(3), W(1), W(5), W(1),  W(3), W(1), W(5), W(1),
-    W(4), W(5), W(2), W(5),  W(4), W(5), W(2), W(5),
-    W(3), W(1), W(5), W(1),  W(3), W(1), W(5), W(1),
-
-    W(0), W(3), W(4), W(3),  W(0), W(3), W(4), W(3),
-    W(3), W(1), W(5), W(1),  W(3), W(1), W(5), W(1),
-    W(4), W(5), W(2), W(5),  W(4), W(5), W(2), W(5),
-    W(3), W(1), W(5), W(1),  W(3), W(1), W(5), W(1)
-};
-#undef W
-
-
 static void dct4x4dc( dctcoef d[16] )
 {
     dctcoef tmp[16];
diff --git a/common/dct.h b/common/dct.h
index d443e22..3008a40 100644
--- a/common/dct.h
+++ b/common/dct.h
@@ -26,11 +26,6 @@
 #ifndef X264_DCT_H
 #define X264_DCT_H
 
-extern const uint32_t x264_dct4_weight_tab[16];
-extern const uint32_t x264_dct8_weight_tab[64];
-extern const uint32_t x264_dct4_weight2_tab[16];
-extern const uint32_t x264_dct8_weight2_tab[64];
-
 typedef struct
 {
     // pix1  stride = FENC_STRIDE
diff --git a/common/mc.c b/common/mc.c
index 1934222..b6968d9 100644
--- a/common/mc.c
+++ b/common/mc.c
@@ -192,9 +192,6 @@ static void hpel_filter( pixel *dsth, pixel *dstv, pixel *dstc, pixel *src,
     }
 }
 
-const uint8_t x264_hpel_ref0[16] = {0,1,1,1,0,1,1,1,2,3,3,3,0,1,1,1};
-const uint8_t x264_hpel_ref1[16] = {0,0,1,0,2,2,3,2,2,2,3,2,2,2,3,2};
-
 static void mc_luma( pixel *dst,    intptr_t i_dst_stride,
                      pixel *src[4], intptr_t i_src_stride,
                      int mvx, int mvy,
diff --git a/common/mc.h b/common/mc.h
index f3e7079..f543fa9 100644
--- a/common/mc.h
+++ b/common/mc.h
@@ -240,8 +240,6 @@ typedef struct x264_weight_t
 } ALIGNED_16( x264_weight_t );
 
 extern const x264_weight_t x264_weight_none[3];
-extern const uint8_t x264_hpel_ref0[16];
-extern const uint8_t x264_hpel_ref1[16];
 
 #define SET_WEIGHT( w, b, s, d, o )\
 {\
diff --git a/common/quant.c b/common/quant.c
index 6cb3ad1..bfda5e2 100644
--- a/common/quant.c
+++ b/common/quant.c
@@ -320,18 +320,6 @@ static void denoise_dct( dctcoef *dct, uint32_t *sum, udctcoef *offset, int size
  *  chroma: for the complete mb: if score < 7 -> null
  */
 
-const uint8_t x264_decimate_table4[16] =
-{
-    3,2,2,1,1,1,0,0,0,0,0,0,0,0,0,0
-};
-const uint8_t x264_decimate_table8[64] =
-{
-    3,3,3,3,2,2,2,2,2,2,2,2,1,1,1,1,
-    1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,
-    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
-};
-
 static int ALWAYS_INLINE decimate_score_internal( dctcoef *dct, int i_max )
 {
     const uint8_t *ds_table = (i_max == 64) ? x264_decimate_table8 : x264_decimate_table4;
diff --git a/common/vlc.c b/common/tables.c
similarity index 63%
copy from common/vlc.c
copy to common/tables.c
index a55d4b9..2d5c58a 100644
--- a/common/vlc.c
+++ b/common/tables.c
@@ -1,11 +1,10 @@
 /*****************************************************************************
- * vlc.c : vlc tables
+ * tables.c: const tables
  *****************************************************************************
  * Copyright (C) 2003-2017 x264 project
  *
  * Authors: Laurent Aimar <fenrir at via.ecp.fr>
- *          Fiona Glaser <fiona at x264.com>
- *          Henrik Gramner <henrik at gramner.com>
+ *          Loren Merritt <lorenm at u.washington.edu>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -25,7 +24,291 @@
  * For more information, contact us at licensing at x264.com.
  *****************************************************************************/
 
-#include "common.h"
+#include "tables.h"
+#include "mathematics.h"
+
+const x264_level_t x264_levels[] =
+{
+    { 10,    1485,    99,    396,     64,    175,  64, 64,  0, 2, 0, 0, 1 },
+    {  9,    1485,    99,    396,    128,    350,  64, 64,  0, 2, 0, 0, 1 }, /* "1b" */
+    { 11,    3000,   396,    900,    192,    500, 128, 64,  0, 2, 0, 0, 1 },
+    { 12,    6000,   396,   2376,    384,   1000, 128, 64,  0, 2, 0, 0, 1 },
+    { 13,   11880,   396,   2376,    768,   2000, 128, 64,  0, 2, 0, 0, 1 },
+    { 20,   11880,   396,   2376,   2000,   2000, 128, 64,  0, 2, 0, 0, 1 },
+    { 21,   19800,   792,   4752,   4000,   4000, 256, 64,  0, 2, 0, 0, 0 },
+    { 22,   20250,  1620,   8100,   4000,   4000, 256, 64,  0, 2, 0, 0, 0 },
+    { 30,   40500,  1620,   8100,  10000,  10000, 256, 32, 22, 2, 0, 1, 0 },
+    { 31,  108000,  3600,  18000,  14000,  14000, 512, 16, 60, 4, 1, 1, 0 },
+    { 32,  216000,  5120,  20480,  20000,  20000, 512, 16, 60, 4, 1, 1, 0 },
+    { 40,  245760,  8192,  32768,  20000,  25000, 512, 16, 60, 4, 1, 1, 0 },
+    { 41,  245760,  8192,  32768,  50000,  62500, 512, 16, 24, 2, 1, 1, 0 },
+    { 42,  522240,  8704,  34816,  50000,  62500, 512, 16, 24, 2, 1, 1, 1 },
+    { 50,  589824, 22080, 110400, 135000, 135000, 512, 16, 24, 2, 1, 1, 1 },
+    { 51,  983040, 36864, 184320, 240000, 240000, 512, 16, 24, 2, 1, 1, 1 },
+    { 52, 2073600, 36864, 184320, 240000, 240000, 512, 16, 24, 2, 1, 1, 1 },
+    { 0 }
+};
+
+/*****************************************************************************
+ * DCT
+ *****************************************************************************/
+
+/* the inverse of the scaling factors introduced by 8x8 fdct */
+/* uint32 is for the asm implementation of trellis. the actual values fit in uint16. */
+#define W(i) (i==0 ? FIX8(1.0000) :\
+              i==1 ? FIX8(0.8859) :\
+              i==2 ? FIX8(1.6000) :\
+              i==3 ? FIX8(0.9415) :\
+              i==4 ? FIX8(1.2651) :\
+              i==5 ? FIX8(1.1910) :0)
+const uint32_t x264_dct8_weight_tab[64] = {
+    W(0), W(3), W(4), W(3),  W(0), W(3), W(4), W(3),
+    W(3), W(1), W(5), W(1),  W(3), W(1), W(5), W(1),
+    W(4), W(5), W(2), W(5),  W(4), W(5), W(2), W(5),
+    W(3), W(1), W(5), W(1),  W(3), W(1), W(5), W(1),
+
+    W(0), W(3), W(4), W(3),  W(0), W(3), W(4), W(3),
+    W(3), W(1), W(5), W(1),  W(3), W(1), W(5), W(1),
+    W(4), W(5), W(2), W(5),  W(4), W(5), W(2), W(5),
+    W(3), W(1), W(5), W(1),  W(3), W(1), W(5), W(1)
+};
+#undef W
+
+#define W(i) (i==0 ? FIX8(1.76777) :\
+              i==1 ? FIX8(1.11803) :\
+              i==2 ? FIX8(0.70711) :0)
+const uint32_t x264_dct4_weight_tab[16] = {
+    W(0), W(1), W(0), W(1),
+    W(1), W(2), W(1), W(2),
+    W(0), W(1), W(0), W(1),
+    W(1), W(2), W(1), W(2)
+};
+#undef W
+
+/* inverse squared */
+#define W(i) (i==0 ? FIX8(3.125) :\
+              i==1 ? FIX8(1.25) :\
+              i==2 ? FIX8(0.5) :0)
+const uint32_t x264_dct4_weight2_tab[16] = {
+    W(0), W(1), W(0), W(1),
+    W(1), W(2), W(1), W(2),
+    W(0), W(1), W(0), W(1),
+    W(1), W(2), W(1), W(2)
+};
+#undef W
+
+#define W(i) (i==0 ? FIX8(1.00000) :\
+              i==1 ? FIX8(0.78487) :\
+              i==2 ? FIX8(2.56132) :\
+              i==3 ? FIX8(0.88637) :\
+              i==4 ? FIX8(1.60040) :\
+              i==5 ? FIX8(1.41850) :0)
+const uint32_t x264_dct8_weight2_tab[64] = {
+    W(0), W(3), W(4), W(3),  W(0), W(3), W(4), W(3),
+    W(3), W(1), W(5), W(1),  W(3), W(1), W(5), W(1),
+    W(4), W(5), W(2), W(5),  W(4), W(5), W(2), W(5),
+    W(3), W(1), W(5), W(1),  W(3), W(1), W(5), W(1),
+
+    W(0), W(3), W(4), W(3),  W(0), W(3), W(4), W(3),
+    W(3), W(1), W(5), W(1),  W(3), W(1), W(5), W(1),
+    W(4), W(5), W(2), W(5),  W(4), W(5), W(2), W(5),
+    W(3), W(1), W(5), W(1),  W(3), W(1), W(5), W(1)
+};
+#undef W
+
+/*****************************************************************************
+ * CABAC
+ *****************************************************************************/
+
+/* -ln2(probability) */
+const uint16_t x264_cabac_entropy[128] =
+{
+    FIX8(0.0273), FIX8(5.7370), FIX8(0.0288), FIX8(5.6618),
+    FIX8(0.0303), FIX8(5.5866), FIX8(0.0320), FIX8(5.5114),
+    FIX8(0.0337), FIX8(5.4362), FIX8(0.0355), FIX8(5.3610),
+    FIX8(0.0375), FIX8(5.2859), FIX8(0.0395), FIX8(5.2106),
+    FIX8(0.0416), FIX8(5.1354), FIX8(0.0439), FIX8(5.0602),
+    FIX8(0.0463), FIX8(4.9851), FIX8(0.0488), FIX8(4.9099),
+    FIX8(0.0515), FIX8(4.8347), FIX8(0.0543), FIX8(4.7595),
+    FIX8(0.0572), FIX8(4.6843), FIX8(0.0604), FIX8(4.6091),
+    FIX8(0.0637), FIX8(4.5339), FIX8(0.0671), FIX8(4.4588),
+    FIX8(0.0708), FIX8(4.3836), FIX8(0.0747), FIX8(4.3083),
+    FIX8(0.0788), FIX8(4.2332), FIX8(0.0832), FIX8(4.1580),
+    FIX8(0.0878), FIX8(4.0828), FIX8(0.0926), FIX8(4.0076),
+    FIX8(0.0977), FIX8(3.9324), FIX8(0.1032), FIX8(3.8572),
+    FIX8(0.1089), FIX8(3.7820), FIX8(0.1149), FIX8(3.7068),
+    FIX8(0.1214), FIX8(3.6316), FIX8(0.1282), FIX8(3.5565),
+    FIX8(0.1353), FIX8(3.4813), FIX8(0.1429), FIX8(3.4061),
+    FIX8(0.1510), FIX8(3.3309), FIX8(0.1596), FIX8(3.2557),
+    FIX8(0.1686), FIX8(3.1805), FIX8(0.1782), FIX8(3.1053),
+    FIX8(0.1884), FIX8(3.0301), FIX8(0.1992), FIX8(2.9549),
+    FIX8(0.2107), FIX8(2.8797), FIX8(0.2229), FIX8(2.8046),
+    FIX8(0.2358), FIX8(2.7294), FIX8(0.2496), FIX8(2.6542),
+    FIX8(0.2642), FIX8(2.5790), FIX8(0.2798), FIX8(2.5038),
+    FIX8(0.2964), FIX8(2.4286), FIX8(0.3142), FIX8(2.3534),
+    FIX8(0.3331), FIX8(2.2782), FIX8(0.3532), FIX8(2.2030),
+    FIX8(0.3748), FIX8(2.1278), FIX8(0.3979), FIX8(2.0527),
+    FIX8(0.4226), FIX8(1.9775), FIX8(0.4491), FIX8(1.9023),
+    FIX8(0.4776), FIX8(1.8271), FIX8(0.5082), FIX8(1.7519),
+    FIX8(0.5412), FIX8(1.6767), FIX8(0.5768), FIX8(1.6015),
+    FIX8(0.6152), FIX8(1.5263), FIX8(0.6568), FIX8(1.4511),
+    FIX8(0.7020), FIX8(1.3759), FIX8(0.7513), FIX8(1.3008),
+    FIX8(0.8050), FIX8(1.2256), FIX8(0.8638), FIX8(1.1504),
+    FIX8(0.9285), FIX8(1.0752), FIX8(1.0000), FIX8(1.0000)
+};
+
+const uint8_t x264_cabac_range_lps[64][4] =
+{
+    {  2,   2,   2,   2}, {  6,   7,   8,   9}, {  6,   7,   9,  10}, {  6,   8,   9,  11},
+    {  7,   8,  10,  11}, {  7,   9,  10,  12}, {  7,   9,  11,  12}, {  8,   9,  11,  13},
+    {  8,  10,  12,  14}, {  9,  11,  12,  14}, {  9,  11,  13,  15}, { 10,  12,  14,  16},
+    { 10,  12,  15,  17}, { 11,  13,  15,  18}, { 11,  14,  16,  19}, { 12,  14,  17,  20},
+    { 12,  15,  18,  21}, { 13,  16,  19,  22}, { 14,  17,  20,  23}, { 14,  18,  21,  24},
+    { 15,  19,  22,  25}, { 16,  20,  23,  27}, { 17,  21,  25,  28}, { 18,  22,  26,  30},
+    { 19,  23,  27,  31}, { 20,  24,  29,  33}, { 21,  26,  30,  35}, { 22,  27,  32,  37},
+    { 23,  28,  33,  39}, { 24,  30,  35,  41}, { 26,  31,  37,  43}, { 27,  33,  39,  45},
+    { 29,  35,  41,  48}, { 30,  37,  43,  50}, { 32,  39,  46,  53}, { 33,  41,  48,  56},
+    { 35,  43,  51,  59}, { 37,  45,  54,  62}, { 39,  48,  56,  65}, { 41,  50,  59,  69},
+    { 43,  53,  63,  72}, { 46,  56,  66,  76}, { 48,  59,  69,  80}, { 51,  62,  73,  85},
+    { 53,  65,  77,  89}, { 56,  69,  81,  94}, { 59,  72,  86,  99}, { 62,  76,  90, 104},
+    { 66,  80,  95, 110}, { 69,  85, 100, 116}, { 73,  89, 105, 122}, { 77,  94, 111, 128},
+    { 81,  99, 117, 135}, { 85, 104, 123, 142}, { 90, 110, 130, 150}, { 95, 116, 137, 158},
+    {100, 122, 144, 166}, {105, 128, 152, 175}, {111, 135, 160, 185}, {116, 142, 169, 195},
+    {123, 150, 178, 205}, {128, 158, 187, 216}, {128, 167, 197, 227}, {128, 176, 208, 240}
+};
+
+const uint8_t x264_cabac_renorm_shift[64] =
+{
+    6,5,4,4,3,3,3,3,2,2,2,2,2,2,2,2,
+    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+};
+
+const uint8_t x264_cabac_transition[128][2] =
+{
+    {  0,   0}, {  1,   1}, {  2,  50}, { 51,   3}, {  2,  50}, { 51,   3}, {  4,  52}, { 53,   5},
+    {  6,  52}, { 53,   7}, {  8,  52}, { 53,   9}, { 10,  54}, { 55,  11}, { 12,  54}, { 55,  13},
+    { 14,  54}, { 55,  15}, { 16,  56}, { 57,  17}, { 18,  56}, { 57,  19}, { 20,  56}, { 57,  21},
+    { 22,  58}, { 59,  23}, { 24,  58}, { 59,  25}, { 26,  60}, { 61,  27}, { 28,  60}, { 61,  29},
+    { 30,  60}, { 61,  31}, { 32,  62}, { 63,  33}, { 34,  62}, { 63,  35}, { 36,  64}, { 65,  37},
+    { 38,  66}, { 67,  39}, { 40,  66}, { 67,  41}, { 42,  66}, { 67,  43}, { 44,  68}, { 69,  45},
+    { 46,  68}, { 69,  47}, { 48,  70}, { 71,  49}, { 50,  72}, { 73,  51}, { 52,  72}, { 73,  53},
+    { 54,  74}, { 75,  55}, { 56,  74}, { 75,  57}, { 58,  76}, { 77,  59}, { 60,  78}, { 79,  61},
+    { 62,  78}, { 79,  63}, { 64,  80}, { 81,  65}, { 66,  82}, { 83,  67}, { 68,  82}, { 83,  69},
+    { 70,  84}, { 85,  71}, { 72,  84}, { 85,  73}, { 74,  88}, { 89,  75}, { 76,  88}, { 89,  77},
+    { 78,  90}, { 91,  79}, { 80,  90}, { 91,  81}, { 82,  94}, { 95,  83}, { 84,  94}, { 95,  85},
+    { 86,  96}, { 97,  87}, { 88,  96}, { 97,  89}, { 90, 100}, {101,  91}, { 92, 100}, {101,  93},
+    { 94, 102}, {103,  95}, { 96, 104}, {105,  97}, { 98, 104}, {105,  99}, {100, 108}, {109, 101},
+    {102, 108}, {109, 103}, {104, 110}, {111, 105}, {106, 112}, {113, 107}, {108, 114}, {115, 109},
+    {110, 116}, {117, 111}, {112, 118}, {119, 113}, {114, 118}, {119, 115}, {116, 122}, {123, 117},
+    {118, 122}, {123, 119}, {120, 124}, {125, 121}, {122, 126}, {127, 123}, {124, 127}, {126, 125}
+};
+
+/*****************************************************************************
+ * HPEL
+ *****************************************************************************/
+
+const uint8_t x264_hpel_ref0[16] = {0,1,1,1,0,1,1,1,2,3,3,3,0,1,1,1};
+const uint8_t x264_hpel_ref1[16] = {0,0,1,0,2,2,3,2,2,2,3,2,2,2,3,2};
+
+/*****************************************************************************
+ * RDO
+ *****************************************************************************/
+
+/* Padded to [64] for easier addressing */
+const uint8_t x264_significant_coeff_flag_offset_8x8[2][64] =
+{{
+    0, 1, 2, 3, 4, 5, 5, 4, 4, 3, 3, 4, 4, 4, 5, 5,
+    4, 4, 4, 4, 3, 3, 6, 7, 7, 7, 8, 9,10, 9, 8, 7,
+    7, 6,11,12,13,11, 6, 7, 8, 9,14,10, 9, 8, 6,11,
+   12,13,11, 6, 9,14,10, 9,11,12,13,11,14,10,12
+},{
+    0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 7, 7, 8, 4, 5,
+    6, 9,10,10, 8,11,12,11, 9, 9,10,10, 8,11,12,11,
+    9, 9,10,10, 8,11,12,11, 9, 9,10,10, 8,13,13, 9,
+    9,10,10, 8,13,13, 9, 9,10,10,14,14,14,14,14
+}};
+const uint8_t x264_last_coeff_flag_offset_8x8[63] =
+{
+    0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+    3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
+    5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8
+};
+const uint8_t x264_coeff_flag_offset_chroma_422_dc[7] = { 0, 0, 1, 1, 2, 2, 2 }; /* MIN( i/2, 2 ) */
+const uint16_t x264_significant_coeff_flag_offset[2][16] =
+{
+    { 105+0, 105+15, 105+29, 105+44, 105+47, 402, 484+0, 484+15, 484+29, 660, 528+0, 528+15, 528+29, 718, 0, 0 },
+    { 277+0, 277+15, 277+29, 277+44, 277+47, 436, 776+0, 776+15, 776+29, 675, 820+0, 820+15, 820+29, 733, 0, 0 }
+};
+const uint16_t x264_last_coeff_flag_offset[2][16] =
+{
+    { 166+0, 166+15, 166+29, 166+44, 166+47, 417, 572+0, 572+15, 572+29, 690, 616+0, 616+15, 616+29, 748, 0, 0 },
+    { 338+0, 338+15, 338+29, 338+44, 338+47, 451, 864+0, 864+15, 864+29, 699, 908+0, 908+15, 908+29, 757, 0, 0 }
+};
+const uint16_t x264_coeff_abs_level_m1_offset[16] =
+{
+    227+0, 227+10, 227+20, 227+30, 227+39, 426, 952+0, 952+10, 952+20, 708, 982+0, 982+10, 982+20, 766
+};
+const uint8_t x264_count_cat_m1[14] = {15, 14, 15, 3, 14, 63, 15, 14, 15, 63, 15, 14, 15, 63};
+
+/*****************************************************************************
+ * lambda
+ *****************************************************************************/
+
+/* lambda = pow(2,qp/6-2) */
+const uint16_t x264_lambda_tab[] =
+{
+   1,   1,   1,   1,   1,   1,   1,   1, /*  0- 7 */
+   1,   1,   1,   1,   1,   1,   1,   1, /*  8-15 */
+   2,   2,   2,   2,   3,   3,   3,   4, /* 16-23 */
+   4,   4,   5,   6,   6,   7,   8,   9, /* 24-31 */
+  10,  11,  13,  14,  16,  18,  20,  23, /* 32-39 */
+  25,  29,  32,  36,  40,  45,  51,  57, /* 40-47 */
+  64,  72,  81,  91, 102, 114, 128, 144, /* 48-55 */
+ 161, 181, 203, 228, 256, 287, 323, 362, /* 56-63 */
+ 406, 456, 512, 575, 645, 724, 813, 912, /* 64-71 */
+1024,1149,1290,1448,1625,1825,2048,2299, /* 72-79 */
+2580,2896,                               /* 80-81 */
+};
+
+/* lambda2 = pow(lambda,2) * .9 * 256 */
+/* Capped to avoid overflow */
+const int x264_lambda2_tab[] =
+{
+       14,       18,       22,       28,       36,       45,      57,      72, /*  0- 7 */
+       91,      115,      145,      182,      230,      290,     365,     460, /*  8-15 */
+      580,      731,      921,     1161,     1462,     1843,    2322,    2925, /* 16-23 */
+     3686,     4644,     5851,     7372,     9289,    11703,   14745,   18578, /* 24-31 */
+    23407,    29491,    37156,    46814,    58982,    74313,   93628,  117964, /* 32-39 */
+   148626,   187257,   235929,   297252,   374514,   471859,  594505,  749029, /* 40-47 */
+   943718,  1189010,  1498059,  1887436,  2378021,  2996119, 3774873, 4756042, /* 48-55 */
+  5992238,  7549747,  9512085, 11984476, 15099494, 19024170,23968953,30198988, /* 56-63 */
+ 38048341, 47937906, 60397977, 76096683, 95875813,120795955,                   /* 64-69 */
+134217727,134217727,134217727,134217727,134217727,134217727,                   /* 70-75 */
+134217727,134217727,134217727,134217727,134217727,134217727,                   /* 76-81 */
+};
+
+/*****************************************************************************
+ * decimate
+ *****************************************************************************/
+
+const uint8_t x264_decimate_table4[16] =
+{
+    3,2,2,1,1,1,0,0,0,0,0,0,0,0,0,0
+};
+const uint8_t x264_decimate_table8[64] =
+{
+    3,3,3,3,2,2,2,2,2,2,2,2,1,1,1,1,
+    1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
+};
+
+/*****************************************************************************
+ * VLC
+ *****************************************************************************/
 
 /* [nC] */
 const vlc_t x264_coeff0_token[6] =
@@ -736,134 +1019,3 @@ const vlc_t x264_total_zeros_2x4_dc[7][8] =
         { 0x1, 1 }, /* str=1 */
     }
 };
-
-/* [MIN( i_zero_left-1, 6 )][run_before] */
-static const vlc_t run_before[7][16] =
-{
-    { /* i_zero_left 1 */
-        { 0x1, 1 }, /* str=1 */
-        { 0x0, 1 }, /* str=0 */
-    },
-    { /* i_zero_left 2 */
-        { 0x1, 1 }, /* str=1 */
-        { 0x1, 2 }, /* str=01 */
-        { 0x0, 2 }, /* str=00 */
-    },
-    { /* i_zero_left 3 */
-        { 0x3, 2 }, /* str=11 */
-        { 0x2, 2 }, /* str=10 */
-        { 0x1, 2 }, /* str=01 */
-        { 0x0, 2 }, /* str=00 */
-    },
-    { /* i_zero_left 4 */
-        { 0x3, 2 }, /* str=11 */
-        { 0x2, 2 }, /* str=10 */
-        { 0x1, 2 }, /* str=01 */
-        { 0x1, 3 }, /* str=001 */
-        { 0x0, 3 }, /* str=000 */
-    },
-    { /* i_zero_left 5 */
-        { 0x3, 2 }, /* str=11 */
-        { 0x2, 2 }, /* str=10 */
-        { 0x3, 3 }, /* str=011 */
-        { 0x2, 3 }, /* str=010 */
-        { 0x1, 3 }, /* str=001 */
-        { 0x0, 3 }, /* str=000 */
-    },
-    { /* i_zero_left 6 */
-        { 0x3, 2 }, /* str=11 */
-        { 0x0, 3 }, /* str=000 */
-        { 0x1, 3 }, /* str=001 */
-        { 0x3, 3 }, /* str=011 */
-        { 0x2, 3 }, /* str=010 */
-        { 0x5, 3 }, /* str=101 */
-        { 0x4, 3 }, /* str=100 */
-    },
-    { /* i_zero_left >6 */
-        { 0x7, 3 }, /* str=111 */
-        { 0x6, 3 }, /* str=110 */
-        { 0x5, 3 }, /* str=101 */
-        { 0x4, 3 }, /* str=100 */
-        { 0x3, 3 }, /* str=011 */
-        { 0x2, 3 }, /* str=010 */
-        { 0x1, 3 }, /* str=001 */
-        { 0x1, 4 }, /* str=0001 */
-        { 0x1, 5 }, /* str=00001 */
-        { 0x1, 6 }, /* str=000001 */
-        { 0x1, 7 }, /* str=0000001 */
-        { 0x1, 8 }, /* str=00000001 */
-        { 0x1, 9 }, /* str=000000001 */
-        { 0x1, 10 }, /* str=0000000001 */
-        { 0x1, 11 }, /* str=00000000001 */
-    },
-};
-
-vlc_large_t x264_level_token[7][LEVEL_TABLE_SIZE];
-uint32_t x264_run_before[1<<16];
-
-void x264_cavlc_init( x264_t *h )
-{
-    for( int i_suffix = 0; i_suffix < 7; i_suffix++ )
-        for( int16_t level = -LEVEL_TABLE_SIZE/2; level < LEVEL_TABLE_SIZE/2; level++ )
-        {
-            int mask = level >> 15;
-            int abs_level = (level^mask)-mask;
-            int i_level_code = abs_level*2-mask-2;
-            int i_next = i_suffix;
-            vlc_large_t *vlc = &x264_level_token[i_suffix][level+LEVEL_TABLE_SIZE/2];
-
-            if( ( i_level_code >> i_suffix ) < 14 )
-            {
-                vlc->i_size = (i_level_code >> i_suffix) + 1 + i_suffix;
-                vlc->i_bits = (1<<i_suffix) + (i_level_code & ((1<<i_suffix)-1));
-            }
-            else if( i_suffix == 0 && i_level_code < 30 )
-            {
-                vlc->i_size = 19;
-                vlc->i_bits = (1<<4) + (i_level_code - 14);
-            }
-            else if( i_suffix > 0 && ( i_level_code >> i_suffix ) == 14 )
-            {
-                vlc->i_size = 15 + i_suffix;
-                vlc->i_bits = (1<<i_suffix) + (i_level_code & ((1<<i_suffix)-1));
-            }
-            else
-            {
-                i_level_code -= 15 << i_suffix;
-                if( i_suffix == 0 )
-                    i_level_code -= 15;
-                vlc->i_size = 28;
-                vlc->i_bits = (1<<12) + i_level_code;
-            }
-            if( i_next == 0 )
-                i_next++;
-            if( abs_level > (3 << (i_next-1)) && i_next < 6 )
-                i_next++;
-            vlc->i_next = i_next;
-        }
-
-    for( int i = 1; i < (1<<16); i++ )
-    {
-        x264_run_level_t runlevel;
-        ALIGNED_ARRAY_16( dctcoef, dct, [16] );
-        int size = 0;
-        int bits = 0;
-        for( int j = 0; j < 16; j++ )
-            dct[j] = i&(1<<j);
-        int total = h->quantf.coeff_level_run[DCT_LUMA_4x4]( dct, &runlevel );
-        int zeros = runlevel.last + 1 - total;
-        uint32_t mask = i << (x264_clz( i ) + 1);
-        for( int j = 0; j < total-1 && zeros > 0; j++ )
-        {
-            int idx = X264_MIN(zeros, 7) - 1;
-            int run = x264_clz( mask );
-            int len = run_before[idx][run].i_size;
-            size += len;
-            bits <<= len;
-            bits |= run_before[idx][run].i_bits;
-            zeros -= run;
-            mask <<= run + 1;
-        }
-        x264_run_before[i] = (bits << 5) + size;
-    }
-}
diff --git a/common/tables.h b/common/tables.h
new file mode 100644
index 0000000..4b026a1
--- /dev/null
+++ b/common/tables.h
@@ -0,0 +1,69 @@
+/*****************************************************************************
+ * tables.h: const tables
+ *****************************************************************************
+ * Copyright (C) 2003-2017 x264 project
+ *
+ * Authors: Laurent Aimar <fenrir at via.ecp.fr>
+ *          Loren Merritt <lorenm at u.washington.edu>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at licensing at x264.com.
+ *****************************************************************************/
+
+#ifndef COMMON_TABLES_H
+#define COMMON_TABLES_H
+
+#include <stdint.h>
+#include "x264.h"
+#include "common/vlc.h"
+
+extern const x264_level_t x264_levels[];
+
+extern const uint32_t x264_dct4_weight_tab[16];
+extern const uint32_t x264_dct8_weight_tab[64];
+extern const uint32_t x264_dct4_weight2_tab[16];
+extern const uint32_t x264_dct8_weight2_tab[64];
+
+extern const uint16_t x264_cabac_entropy[128];
+extern const uint8_t x264_cabac_range_lps[64][4];
+extern const uint8_t x264_cabac_renorm_shift[64];
+extern const uint8_t x264_cabac_transition[128][2];
+
+extern const uint8_t x264_hpel_ref0[16];
+extern const uint8_t x264_hpel_ref1[16];
+
+extern const uint8_t x264_significant_coeff_flag_offset_8x8[2][64];
+extern const uint8_t x264_last_coeff_flag_offset_8x8[63];
+extern const uint8_t x264_coeff_flag_offset_chroma_422_dc[7];
+extern const uint16_t x264_significant_coeff_flag_offset[2][16];
+extern const uint16_t x264_last_coeff_flag_offset[2][16];
+extern const uint16_t x264_coeff_abs_level_m1_offset[16];
+extern const uint8_t x264_count_cat_m1[14];
+
+extern const int x264_lambda2_tab[];
+extern const uint16_t x264_lambda_tab[];
+
+extern const uint8_t x264_decimate_table4[16];
+extern const uint8_t x264_decimate_table8[64];
+
+extern const vlc_t x264_coeff0_token[6];
+extern const vlc_t x264_coeff_token[6][16][4];
+extern const vlc_t x264_total_zeros[15][16];
+extern const vlc_t x264_total_zeros_2x2_dc[3][4];
+extern const vlc_t x264_total_zeros_2x4_dc[7][8];
+
+#endif
diff --git a/common/vlc.c b/common/vlc.c
index a55d4b9..8545099 100644
--- a/common/vlc.c
+++ b/common/vlc.c
@@ -27,716 +27,6 @@
 
 #include "common.h"
 
-/* [nC] */
-const vlc_t x264_coeff0_token[6] =
-{
-    { 0x1, 1 }, /* str=1 */
-    { 0x3, 2 }, /* str=11 */
-    { 0xf, 4 }, /* str=1111 */
-    { 0x3, 6 }, /* str=000011 */
-    { 0x1, 2 }, /* str=01 */
-    { 0x1, 1 }, /* str=1 */
-};
-
-/* [nC][i_total_coeff-1][i_trailing] */
-const vlc_t x264_coeff_token[6][16][4] =
-{
-    { /* table 0 */
-        { /* i_total 1 */
-            { 0x5, 6 }, /* str=000101 */
-            { 0x1, 2 }, /* str=01 */
-        },
-        { /* i_total 2 */
-            { 0x7, 8 }, /* str=00000111 */
-            { 0x4, 6 }, /* str=000100 */
-            { 0x1, 3 }, /* str=001 */
-        },
-        { /* i_total 3 */
-            { 0x7, 9 }, /* str=000000111 */
-            { 0x6, 8 }, /* str=00000110 */
-            { 0x5, 7 }, /* str=0000101 */
-            { 0x3, 5 }, /* str=00011 */
-        },
-        { /* i_total 4 */
-            { 0x7, 10 }, /* str=0000000111 */
-            { 0x6, 9 },  /* str=000000110 */
-            { 0x5, 8 },  /* str=00000101 */
-            { 0x3, 6 },  /* str=000011 */
-        },
-        { /* i_total 5 */
-            { 0x7, 11 }, /* str=00000000111 */
-            { 0x6, 10 }, /* str=0000000110 */
-            { 0x5, 9 },  /* str=000000101 */
-            { 0x4, 7 },  /* str=0000100 */
-        },
-        { /* i_total 6 */
-            { 0xf, 13 }, /* str=0000000001111 */
-            { 0x6, 11 }, /* str=00000000110 */
-            { 0x5, 10 }, /* str=0000000101 */
-            { 0x4, 8 },  /* str=00000100 */
-        },
-        { /* i_total 7 */
-            { 0xb, 13 }, /* str=0000000001011 */
-            { 0xe, 13 }, /* str=0000000001110 */
-            { 0x5, 11 }, /* str=00000000101 */
-            { 0x4, 9 },  /* str=000000100 */
-        },
-        { /* i_total 8 */
-            { 0x8, 13 }, /* str=0000000001000 */
-            { 0xa, 13 }, /* str=0000000001010 */
-            { 0xd, 13 }, /* str=0000000001101 */
-            { 0x4, 10 }, /* str=0000000100 */
-        },
-        { /* i_total 9 */
-            { 0xf, 14 }, /* str=00000000001111 */
-            { 0xe, 14 }, /* str=00000000001110 */
-            { 0x9, 13 }, /* str=0000000001001 */
-            { 0x4, 11 }, /* str=00000000100 */
-        },
-        { /* i_total 10 */
-            { 0xb, 14 }, /* str=00000000001011 */
-            { 0xa, 14 }, /* str=00000000001010 */
-            { 0xd, 14 }, /* str=00000000001101 */
-            { 0xc, 13 }, /* str=0000000001100 */
-        },
-        { /* i_total 14 */
-            { 0xf, 15 }, /* str=000000000001111 */
-            { 0xe, 15 }, /* str=000000000001110 */
-            { 0x9, 14 }, /* str=00000000001001 */
-            { 0xc, 14 }, /* str=00000000001100 */
-        },
-        { /* i_total 12 */
-            { 0xb, 15 }, /* str=000000000001011 */
-            { 0xa, 15 }, /* str=000000000001010 */
-            { 0xd, 15 }, /* str=000000000001101 */
-            { 0x8, 14 }, /* str=00000000001000 */
-        },
-        { /* i_total 13 */
-            { 0xf, 16 }, /* str=0000000000001111 */
-            { 0x1, 15 }, /* str=000000000000001 */
-            { 0x9, 15 }, /* str=000000000001001 */
-            { 0xc, 15 }, /* str=000000000001100 */
-        },
-        { /* i_total 14 */
-            { 0xb, 16 }, /* str=0000000000001011 */
-            { 0xe, 16 }, /* str=0000000000001110 */
-            { 0xd, 16 }, /* str=0000000000001101 */
-            { 0x8, 15 }, /* str=000000000001000 */
-        },
-        { /* i_total 15 */
-            { 0x7, 16 }, /* str=0000000000000111 */
-            { 0xa, 16 }, /* str=0000000000001010 */
-            { 0x9, 16 }, /* str=0000000000001001 */
-            { 0xc, 16 }, /* str=0000000000001100 */
-        },
-        { /* i_total 16 */
-            { 0x4, 16 }, /* str=0000000000000100 */
-            { 0x6, 16 }, /* str=0000000000000110 */
-            { 0x5, 16 }, /* str=0000000000000101 */
-            { 0x8, 16 }, /* str=0000000000001000 */
-        },
-    },
-    { /* table 1 */
-        { /* i_total 1 */
-            { 0xb, 6 }, /* str=001011 */
-            { 0x2, 2 }, /* str=10 */
-        },
-        { /* i_total 2 */
-            { 0x7, 6 }, /* str=000111 */
-            { 0x7, 5 }, /* str=00111 */
-            { 0x3, 3 }, /* str=011 */
-        },
-        { /* i_total 3 */
-            { 0x7, 7 }, /* str=0000111 */
-            { 0xa, 6 }, /* str=001010 */
-            { 0x9, 6 }, /* str=001001 */
-            { 0x5, 4 }, /* str=0101 */
-        },
-        { /* i_total 4 */
-            { 0x7, 8 }, /* str=00000111 */
-            { 0x6, 6 }, /* str=000110 */
-            { 0x5, 6 }, /* str=000101 */
-            { 0x4, 4 }, /* str=0100 */
-        },
-        { /* i_total 5 */
-            { 0x4, 8 }, /* str=00000100 */
-            { 0x6, 7 }, /* str=0000110 */
-            { 0x5, 7 }, /* str=0000101 */
-            { 0x6, 5 }, /* str=00110 */
-        },
-        { /* i_total 6 */
-            { 0x7, 9 }, /* str=000000111 */
-            { 0x6, 8 }, /* str=00000110 */
-            { 0x5, 8 }, /* str=00000101 */
-            { 0x8, 6 }, /* str=001000 */
-        },
-        { /* i_total 7 */
-            { 0xf, 11 }, /* str=00000001111 */
-            { 0x6, 9 },  /* str=000000110 */
-            { 0x5, 9 },  /* str=000000101 */
-            { 0x4, 6 },  /* str=000100 */
-        },
-        { /* i_total 8 */
-            { 0xb, 11 }, /* str=00000001011 */
-            { 0xe, 11 }, /* str=00000001110 */
-            { 0xd, 11 }, /* str=00000001101 */
-            { 0x4, 7 },  /* str=0000100 */
-        },
-        { /* i_total 9 */
-            { 0xf, 12 }, /* str=000000001111 */
-            { 0xa, 11 }, /* str=00000001010 */
-            { 0x9, 11 }, /* str=00000001001 */
-            { 0x4, 9 },  /* str=000000100 */
-        },
-        { /* i_total 10 */
-            { 0xb, 12 }, /* str=000000001011 */
-            { 0xe, 12 }, /* str=000000001110 */
-            { 0xd, 12 }, /* str=000000001101 */
-            { 0xc, 11 }, /* str=00000001100 */
-        },
-        { /* i_total 11 */
-            { 0x8, 12 }, /* str=000000001000 */
-            { 0xa, 12 }, /* str=000000001010 */
-            { 0x9, 12 }, /* str=000000001001 */
-            { 0x8, 11 }, /* str=00000001000 */
-        },
-        { /* i_total 12 */
-            { 0xf, 13 }, /* str=0000000001111 */
-            { 0xe, 13 }, /* str=0000000001110 */
-            { 0xd, 13 }, /* str=0000000001101 */
-            { 0xc, 12 }, /* str=000000001100 */
-        },
-        { /* i_total 13 */
-            { 0xb, 13 }, /* str=0000000001011 */
-            { 0xa, 13 }, /* str=0000000001010 */
-            { 0x9, 13 }, /* str=0000000001001 */
-            { 0xc, 13 }, /* str=0000000001100 */
-        },
-        { /* i_total 14 */
-            { 0x7, 13 }, /* str=0000000000111 */
-            { 0xb, 14 }, /* str=00000000001011 */
-            { 0x6, 13 }, /* str=0000000000110 */
-            { 0x8, 13 }, /* str=0000000001000 */
-        },
-        { /* i_total 15 */
-            { 0x9, 14 }, /* str=00000000001001 */
-            { 0x8, 14 }, /* str=00000000001000 */
-            { 0xa, 14 }, /* str=00000000001010 */
-            { 0x1, 13 }, /* str=0000000000001 */
-        },
-        { /* i_total 16 */
-            { 0x7, 14 }, /* str=00000000000111 */
-            { 0x6, 14 }, /* str=00000000000110 */
-            { 0x5, 14 }, /* str=00000000000101 */
-            { 0x4, 14 }, /* str=00000000000100 */
-        },
-    },
-    { /* table 2 */
-        { /* i_total 1 */
-            { 0xf, 6 }, /* str=001111 */
-            { 0xe, 4 }, /* str=1110 */
-        },
-        { /* i_total 2 */
-            { 0xb, 6 }, /* str=001011 */
-            { 0xf, 5 }, /* str=01111 */
-            { 0xd, 4 }, /* str=1101 */
-        },
-        { /* i_total 3 */
-            { 0x8, 6 }, /* str=001000 */
-            { 0xc, 5 }, /* str=01100 */
-            { 0xe, 5 }, /* str=01110 */
-            { 0xc, 4 }, /* str=1100 */
-        },
-        { /* i_total 4 */
-            { 0xf, 7 }, /* str=0001111 */
-            { 0xa, 5 }, /* str=01010 */
-            { 0xb, 5 }, /* str=01011 */
-            { 0xb, 4 }, /* str=1011 */
-        },
-        { /* i_total 5 */
-            { 0xb, 7 }, /* str=0001011 */
-            { 0x8, 5 }, /* str=01000 */
-            { 0x9, 5 }, /* str=01001 */
-            { 0xa, 4 }, /* str=1010 */
-        },
-        { /* i_total 6 */
-            { 0x9, 7 }, /* str=0001001 */
-            { 0xe, 6 }, /* str=001110 */
-            { 0xd, 6 }, /* str=001101 */
-            { 0x9, 4 }, /* str=1001 */
-        },
-        { /* i_total 7 */
-            { 0x8, 7 }, /* str=0001000 */
-            { 0xa, 6 }, /* str=001010 */
-            { 0x9, 6 }, /* str=001001 */
-            { 0x8, 4 }, /* str=1000 */
-        },
-        { /* i_total 8 */
-            { 0xf, 8 }, /* str=00001111 */
-            { 0xe, 7 }, /* str=0001110 */
-            { 0xd, 7 }, /* str=0001101 */
-            { 0xd, 5 }, /* str=01101 */
-        },
-        { /* i_total 9 */
-            { 0xb, 8 }, /* str=00001011 */
-            { 0xe, 8 }, /* str=00001110 */
-            { 0xa, 7 }, /* str=0001010 */
-            { 0xc, 6 }, /* str=001100 */
-        },
-        { /* i_total 10 */
-            { 0xf, 9 }, /* str=000001111 */
-            { 0xa, 8 }, /* str=00001010 */
-            { 0xd, 8 }, /* str=00001101 */
-            { 0xc, 7 }, /* str=0001100 */
-        },
-        { /* i_total 11 */
-            { 0xb, 9 }, /* str=000001011 */
-            { 0xe, 9 }, /* str=000001110 */
-            { 0x9, 8 }, /* str=00001001 */
-            { 0xc, 8 }, /* str=00001100 */
-        },
-        { /* i_total 12 */
-            { 0x8, 9 }, /* str=000001000 */
-            { 0xa, 9 }, /* str=000001010 */
-            { 0xd, 9 }, /* str=000001101 */
-            { 0x8, 8 }, /* str=00001000 */
-        },
-        { /* i_total 13 */
-            { 0xd, 10 }, /* str=0000001101 */
-            { 0x7, 9 },  /* str=000000111 */
-            { 0x9, 9 },  /* str=000001001 */
-            { 0xc, 9 },  /* str=000001100 */
-        },
-        { /* i_total 14 */
-            { 0x9, 10 }, /* str=0000001001 */
-            { 0xc, 10 }, /* str=0000001100 */
-            { 0xb, 10 }, /* str=0000001011 */
-            { 0xa, 10 }, /* str=0000001010 */
-        },
-        { /* i_total 15 */
-            { 0x5, 10 }, /* str=0000000101 */
-            { 0x8, 10 }, /* str=0000001000 */
-            { 0x7, 10 }, /* str=0000000111 */
-            { 0x6, 10 }, /* str=0000000110 */
-        },
-        { /* i_total 16 */
-            { 0x1, 10 }, /* str=0000000001 */
-            { 0x4, 10 }, /* str=0000000100 */
-            { 0x3, 10 }, /* str=0000000011 */
-            { 0x2, 10 }, /* str=0000000010 */
-        },
-    },
-    { /* table 3 */
-        { /* i_total 1 */
-            { 0x0, 6 }, /* str=000000 */
-            { 0x1, 6 }, /* str=000001 */
-        },
-        { /* i_total 2 */
-            { 0x4, 6 }, /* str=000100 */
-            { 0x5, 6 }, /* str=000101 */
-            { 0x6, 6 }, /* str=000110 */
-        },
-        { /* i_total 3 */
-            { 0x8, 6 }, /* str=001000 */
-            { 0x9, 6 }, /* str=001001 */
-            { 0xa, 6 }, /* str=001010 */
-            { 0xb, 6 }, /* str=001011 */
-        },
-        { /* i_total 4 */
-            { 0xc, 6 }, /* str=001100 */
-            { 0xd, 6 }, /* str=001101 */
-            { 0xe, 6 }, /* str=001110 */
-            { 0xf, 6 }, /* str=001111 */
-        },
-        { /* i_total 5 */
-            { 0x10, 6 }, /* str=010000 */
-            { 0x11, 6 }, /* str=010001 */
-            { 0x12, 6 }, /* str=010010 */
-            { 0x13, 6 }, /* str=010011 */
-        },
-        { /* i_total 6 */
-            { 0x14, 6 }, /* str=010100 */
-            { 0x15, 6 }, /* str=010101 */
-            { 0x16, 6 }, /* str=010110 */
-            { 0x17, 6 }, /* str=010111 */
-        },
-        { /* i_total 7 */
-            { 0x18, 6 }, /* str=011000 */
-            { 0x19, 6 }, /* str=011001 */
-            { 0x1a, 6 }, /* str=011010 */
-            { 0x1b, 6 }, /* str=011011 */
-        },
-        { /* i_total 8 */
-            { 0x1c, 6 }, /* str=011100 */
-            { 0x1d, 6 }, /* str=011101 */
-            { 0x1e, 6 }, /* str=011110 */
-            { 0x1f, 6 }, /* str=011111 */
-        },
-        { /* i_total 9 */
-            { 0x20, 6 }, /* str=100000 */
-            { 0x21, 6 }, /* str=100001 */
-            { 0x22, 6 }, /* str=100010 */
-            { 0x23, 6 }, /* str=100011 */
-        },
-        { /* i_total 10 */
-            { 0x24, 6 }, /* str=100100 */
-            { 0x25, 6 }, /* str=100101 */
-            { 0x26, 6 }, /* str=100110 */
-            { 0x27, 6 }, /* str=100111 */
-        },
-        { /* i_total 11 */
-            { 0x28, 6 }, /* str=101000 */
-            { 0x29, 6 }, /* str=101001 */
-            { 0x2a, 6 }, /* str=101010 */
-            { 0x2b, 6 }, /* str=101011 */
-        },
-        { /* i_total 12 */
-            { 0x2c, 6 }, /* str=101100 */
-            { 0x2d, 6 }, /* str=101101 */
-            { 0x2e, 6 }, /* str=101110 */
-            { 0x2f, 6 }, /* str=101111 */
-        },
-        { /* i_total 13 */
-            { 0x30, 6 }, /* str=110000 */
-            { 0x31, 6 }, /* str=110001 */
-            { 0x32, 6 }, /* str=110010 */
-            { 0x33, 6 }, /* str=110011 */
-        },
-        { /* i_total 14 */
-            { 0x34, 6 }, /* str=110100 */
-            { 0x35, 6 }, /* str=110101 */
-            { 0x36, 6 }, /* str=110110 */
-            { 0x37, 6 }, /* str=110111 */
-        },
-        { /* i_total 15 */
-            { 0x38, 6 }, /* str=111000 */
-            { 0x39, 6 }, /* str=111001 */
-            { 0x3a, 6 }, /* str=111010 */
-            { 0x3b, 6 }, /* str=111011 */
-        },
-        { /* i_total 16 */
-            { 0x3c, 6 }, /* str=111100 */
-            { 0x3d, 6 }, /* str=111101 */
-            { 0x3e, 6 }, /* str=111110 */
-            { 0x3f, 6 }, /* str=111111 */
-        },
-    },
-    { /* table 4 */
-        { /* i_total 1 */
-            { 0x7, 6 }, /* str=000111 */
-            { 0x1, 1 }, /* str=1 */
-        },
-        { /* i_total 2 */
-            { 0x4, 6 }, /* str=000100 */
-            { 0x6, 6 }, /* str=000110 */
-            { 0x1, 3 }, /* str=001 */
-        },
-        { /* i_total 3 */
-            { 0x3, 6 }, /* str=000011 */
-            { 0x3, 7 }, /* str=0000011 */
-            { 0x2, 7 }, /* str=0000010 */
-            { 0x5, 6 }, /* str=000101 */
-        },
-        { /* i_total 4 */
-            { 0x2, 6 }, /* str=000010 */
-            { 0x3, 8 }, /* str=00000011 */
-            { 0x2, 8 }, /* str=00000010 */
-            { 0x0, 7 }, /* str=0000000 */
-        },
-    },
-    { /* table 5 */
-        { /* i_total 1 */
-            { 0xf, 7 }, /* str=0001111 */
-            { 0x1, 2 }, /* str=01 */
-        },
-        { /* i_total 2 */
-            { 0xe, 7 }, /* str=0001110 */
-            { 0xd, 7 }, /* str=0001101 */
-            { 0x1, 3 }, /* str=001 */
-        },
-        { /* i_total 3 */
-            { 0x7, 9 }, /* str=000000111 */
-            { 0xc, 7 }, /* str=0001100 */
-            { 0xb, 7 }, /* str=0001011 */
-            { 0x1, 5 }, /* str=00001 */
-        },
-        { /* i_total 4 */
-            { 0x6, 9 }, /* str=000000110 */
-            { 0x5, 9 }, /* str=000000101 */
-            { 0xa, 7 }, /* str=0001010 */
-            { 0x1, 6 }, /* str=000001 */
-        },
-        { /* i_total 5 */
-            { 0x7, 10 }, /* str=0000000111 */
-            { 0x6, 10 }, /* str=0000000110 */
-            { 0x4, 9 },  /* str=000000100 */
-            { 0x9, 7 },  /* str=0001001 */
-        },
-        { /* i_total 6 */
-            { 0x7, 11 }, /* str=00000000111 */
-            { 0x6, 11 }, /* str=00000000110 */
-            { 0x5, 10 }, /* str=0000000101 */
-            { 0x8, 7 },  /* str=0001000 */
-        },
-        { /* i_total 7 */
-            { 0x7, 12 }, /* str=000000000111 */
-            { 0x6, 12 }, /* str=000000000110 */
-            { 0x5, 11 }, /* str=00000000101 */
-            { 0x4, 10 }, /* str=0000000100 */
-        },
-        { /* i_total 8 */
-            { 0x7, 13 }, /* str=0000000000111 */
-            { 0x5, 12 }, /* str=000000000101 */
-            { 0x4, 12 }, /* str=000000000100 */
-            { 0x4, 11 }, /* str=00000000100 */
-        },
-    },
-};
-
-/* [i_total_coeff-1][i_total_zeros] */
-const vlc_t x264_total_zeros[15][16] =
-{
-    { /* i_total 1 */
-        { 0x1, 1 }, /* str=1 */
-        { 0x3, 3 }, /* str=011 */
-        { 0x2, 3 }, /* str=010 */
-        { 0x3, 4 }, /* str=0011 */
-        { 0x2, 4 }, /* str=0010 */
-        { 0x3, 5 }, /* str=00011 */
-        { 0x2, 5 }, /* str=00010 */
-        { 0x3, 6 }, /* str=000011 */
-        { 0x2, 6 }, /* str=000010 */
-        { 0x3, 7 }, /* str=0000011 */
-        { 0x2, 7 }, /* str=0000010 */
-        { 0x3, 8 }, /* str=00000011 */
-        { 0x2, 8 }, /* str=00000010 */
-        { 0x3, 9 }, /* str=000000011 */
-        { 0x2, 9 }, /* str=000000010 */
-        { 0x1, 9 }, /* str=000000001 */
-    },
-    { /* i_total 2 */
-        { 0x7, 3 }, /* str=111 */
-        { 0x6, 3 }, /* str=110 */
-        { 0x5, 3 }, /* str=101 */
-        { 0x4, 3 }, /* str=100 */
-        { 0x3, 3 }, /* str=011 */
-        { 0x5, 4 }, /* str=0101 */
-        { 0x4, 4 }, /* str=0100 */
-        { 0x3, 4 }, /* str=0011 */
-        { 0x2, 4 }, /* str=0010 */
-        { 0x3, 5 }, /* str=00011 */
-        { 0x2, 5 }, /* str=00010 */
-        { 0x3, 6 }, /* str=000011 */
-        { 0x2, 6 }, /* str=000010 */
-        { 0x1, 6 }, /* str=000001 */
-        { 0x0, 6 }, /* str=000000 */
-    },
-    { /* i_total 3 */
-        { 0x5, 4 }, /* str=0101 */
-        { 0x7, 3 }, /* str=111 */
-        { 0x6, 3 }, /* str=110 */
-        { 0x5, 3 }, /* str=101 */
-        { 0x4, 4 }, /* str=0100 */
-        { 0x3, 4 }, /* str=0011 */
-        { 0x4, 3 }, /* str=100 */
-        { 0x3, 3 }, /* str=011 */
-        { 0x2, 4 }, /* str=0010 */
-        { 0x3, 5 }, /* str=00011 */
-        { 0x2, 5 }, /* str=00010 */
-        { 0x1, 6 }, /* str=000001 */
-        { 0x1, 5 }, /* str=00001 */
-        { 0x0, 6 }, /* str=000000 */
-    },
-    { /* i_total 4 */
-        { 0x3, 5 }, /* str=00011 */
-        { 0x7, 3 }, /* str=111 */
-        { 0x5, 4 }, /* str=0101 */
-        { 0x4, 4 }, /* str=0100 */
-        { 0x6, 3 }, /* str=110 */
-        { 0x5, 3 }, /* str=101 */
-        { 0x4, 3 }, /* str=100 */
-        { 0x3, 4 }, /* str=0011 */
-        { 0x3, 3 }, /* str=011 */
-        { 0x2, 4 }, /* str=0010 */
-        { 0x2, 5 }, /* str=00010 */
-        { 0x1, 5 }, /* str=00001 */
-        { 0x0, 5 }, /* str=00000 */
-    },
-    { /* i_total 5 */
-        { 0x5, 4 }, /* str=0101 */
-        { 0x4, 4 }, /* str=0100 */
-        { 0x3, 4 }, /* str=0011 */
-        { 0x7, 3 }, /* str=111 */
-        { 0x6, 3 }, /* str=110 */
-        { 0x5, 3 }, /* str=101 */
-        { 0x4, 3 }, /* str=100 */
-        { 0x3, 3 }, /* str=011 */
-        { 0x2, 4 }, /* str=0010 */
-        { 0x1, 5 }, /* str=00001 */
-        { 0x1, 4 }, /* str=0001 */
-        { 0x0, 5 }, /* str=00000 */
-    },
-    { /* i_total 6 */
-        { 0x1, 6 }, /* str=000001 */
-        { 0x1, 5 }, /* str=00001 */
-        { 0x7, 3 }, /* str=111 */
-        { 0x6, 3 }, /* str=110 */
-        { 0x5, 3 }, /* str=101 */
-        { 0x4, 3 }, /* str=100 */
-        { 0x3, 3 }, /* str=011 */
-        { 0x2, 3 }, /* str=010 */
-        { 0x1, 4 }, /* str=0001 */
-        { 0x1, 3 }, /* str=001 */
-        { 0x0, 6 }, /* str=000000 */
-    },
-    { /* i_total 7 */
-        { 0x1, 6 }, /* str=000001 */
-        { 0x1, 5 }, /* str=00001 */
-        { 0x5, 3 }, /* str=101 */
-        { 0x4, 3 }, /* str=100 */
-        { 0x3, 3 }, /* str=011 */
-        { 0x3, 2 }, /* str=11 */
-        { 0x2, 3 }, /* str=010 */
-        { 0x1, 4 }, /* str=0001 */
-        { 0x1, 3 }, /* str=001 */
-        { 0x0, 6 }, /* str=000000 */
-    },
-    { /* i_total 8 */
-        { 0x1, 6 }, /* str=000001 */
-        { 0x1, 4 }, /* str=0001 */
-        { 0x1, 5 }, /* str=00001 */
-        { 0x3, 3 }, /* str=011 */
-        { 0x3, 2 }, /* str=11 */
-        { 0x2, 2 }, /* str=10 */
-        { 0x2, 3 }, /* str=010 */
-        { 0x1, 3 }, /* str=001 */
-        { 0x0, 6 }, /* str=000000 */
-    },
-    { /* i_total 9 */
-        { 0x1, 6 }, /* str=000001 */
-        { 0x0, 6 }, /* str=000000 */
-        { 0x1, 4 }, /* str=0001 */
-        { 0x3, 2 }, /* str=11 */
-        { 0x2, 2 }, /* str=10 */
-        { 0x1, 3 }, /* str=001 */
-        { 0x1, 2 }, /* str=01 */
-        { 0x1, 5 }, /* str=00001 */
-    },
-    { /* i_total 10 */
-        { 0x1, 5 }, /* str=00001 */
-        { 0x0, 5 }, /* str=00000 */
-        { 0x1, 3 }, /* str=001 */
-        { 0x3, 2 }, /* str=11 */
-        { 0x2, 2 }, /* str=10 */
-        { 0x1, 2 }, /* str=01 */
-        { 0x1, 4 }, /* str=0001 */
-    },
-    { /* i_total 11 */
-        { 0x0, 4 }, /* str=0000 */
-        { 0x1, 4 }, /* str=0001 */
-        { 0x1, 3 }, /* str=001 */
-        { 0x2, 3 }, /* str=010 */
-        { 0x1, 1 }, /* str=1 */
-        { 0x3, 3 }, /* str=011 */
-    },
-    { /* i_total 12 */
-        { 0x0, 4 }, /* str=0000 */
-        { 0x1, 4 }, /* str=0001 */
-        { 0x1, 2 }, /* str=01 */
-        { 0x1, 1 }, /* str=1 */
-        { 0x1, 3 }, /* str=001 */
-    },
-    { /* i_total 13 */
-        { 0x0, 3 }, /* str=000 */
-        { 0x1, 3 }, /* str=001 */
-        { 0x1, 1 }, /* str=1 */
-        { 0x1, 2 }, /* str=01 */
-    },
-    { /* i_total 14 */
-        { 0x0, 2 }, /* str=00 */
-        { 0x1, 2 }, /* str=01 */
-        { 0x1, 1 }, /* str=1 */
-    },
-    { /* i_total 15 */
-        { 0x0, 1 }, /* str=0 */
-        { 0x1, 1 }, /* str=1 */
-    },
-};
-
-/* [i_total_coeff-1][i_total_zeros] */
-const vlc_t x264_total_zeros_2x2_dc[3][4] =
-{
-    { /* i_total 1 */
-        { 0x1, 1 }, /* str=1 */
-        { 0x1, 2 }, /* str=01 */
-        { 0x1, 3 }, /* str=001 */
-        { 0x0, 3 }  /* str=000 */
-    },
-    { /* i_total 2 */
-        { 0x1, 1 }, /* str=1 */
-        { 0x1, 2 }, /* str=01 */
-        { 0x0, 2 }, /* str=00 */
-    },
-    { /* i_total 3 */
-        { 0x1, 1 }, /* str=1 */
-        { 0x0, 1 }, /* str=0 */
-    },
-};
-
-/* [i_total_coeff-1][i_total_zeros] */
-const vlc_t x264_total_zeros_2x4_dc[7][8] =
-{
-    { /* i_total 1 */
-        { 0x1, 1 }, /* str=1 */
-        { 0x2, 3 }, /* str=010 */
-        { 0x3, 3 }, /* str=011 */
-        { 0x2, 4 }, /* str=0010 */
-        { 0x3, 4 }, /* str=0011 */
-        { 0x1, 4 }, /* str=0001 */
-        { 0x1, 5 }, /* str=00001 */
-        { 0x0, 5 }, /* str=00000 */
-    },
-    { /* i_total 2 */
-        { 0x0, 3 }, /* str=000 */
-        { 0x1, 2 }, /* str=01 */
-        { 0x1, 3 }, /* str=001 */
-        { 0x4, 3 }, /* str=100 */
-        { 0x5, 3 }, /* str=101 */
-        { 0x6, 3 }, /* str=110 */
-        { 0x7, 3 }, /* str=111 */
-    },
-    { /* i_total 3 */
-        { 0x0, 3 }, /* str=000 */
-        { 0x1, 3 }, /* str=001 */
-        { 0x1, 2 }, /* str=01 */
-        { 0x2, 2 }, /* str=10 */
-        { 0x6, 3 }, /* str=110 */
-        { 0x7, 3 }, /* str=111 */
-    },
-    { /* i_total 4 */
-        { 0x6, 3 }, /* str=110 */
-        { 0x0, 2 }, /* str=00 */
-        { 0x1, 2 }, /* str=01 */
-        { 0x2, 2 }, /* str=10 */
-        { 0x7, 3 }, /* str=111 */
-    },
-    { /* i_total 5 */
-        { 0x0, 2 }, /* str=00 */
-        { 0x1, 2 }, /* str=01 */
-        { 0x2, 2 }, /* str=10 */
-        { 0x3, 2 }, /* str=11 */
-    },
-    { /* i_total 6 */
-        { 0x0, 2 }, /* str=00 */
-        { 0x1, 2 }, /* str=01 */
-        { 0x1, 1 }, /* str=1 */
-    },
-    { /* i_total 7 */
-        { 0x0, 1 }, /* str=0 */
-        { 0x1, 1 }, /* str=1 */
-    }
-};
-
 /* [MIN( i_zero_left-1, 6 )][run_before] */
 static const vlc_t run_before[7][16] =
 {
diff --git a/common/vlc.h b/common/vlc.h
new file mode 100644
index 0000000..9f1dc12
--- /dev/null
+++ b/common/vlc.h
@@ -0,0 +1,37 @@
+/*****************************************************************************
+ * vlc.h: vlc type
+ *****************************************************************************
+ * Copyright (C) 2003-2017 x264 project
+ *
+ * Authors: Loren Merritt <lorenm at u.washington.edu>
+ *          Fiona Glaser <fiona at x264.com>
+ *          Laurent Aimar <fenrir at via.ecp.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at licensing at x264.com.
+ *****************************************************************************/
+
+#ifndef X264_VLC_H
+#define X264_VLC_H
+
+typedef struct
+{
+    uint8_t i_bits;
+    uint8_t i_size;
+} vlc_t;
+
+#endif
diff --git a/encoder/analyse.c b/encoder/analyse.c
index fdb9ccd..d40a6c0 100644
--- a/encoder/analyse.c
+++ b/encoder/analyse.c
@@ -134,39 +134,6 @@ typedef struct
 
 } x264_mb_analysis_t;
 
-/* lambda = pow(2,qp/6-2) */
-const uint16_t x264_lambda_tab[QP_MAX_MAX+1] =
-{
-   1,   1,   1,   1,   1,   1,   1,   1, /*  0- 7 */
-   1,   1,   1,   1,   1,   1,   1,   1, /*  8-15 */
-   2,   2,   2,   2,   3,   3,   3,   4, /* 16-23 */
-   4,   4,   5,   6,   6,   7,   8,   9, /* 24-31 */
-  10,  11,  13,  14,  16,  18,  20,  23, /* 32-39 */
-  25,  29,  32,  36,  40,  45,  51,  57, /* 40-47 */
-  64,  72,  81,  91, 102, 114, 128, 144, /* 48-55 */
- 161, 181, 203, 228, 256, 287, 323, 362, /* 56-63 */
- 406, 456, 512, 575, 645, 724, 813, 912, /* 64-71 */
-1024,1149,1290,1448,1625,1825,2048,2299, /* 72-79 */
-2580,2896,                               /* 80-81 */
-};
-
-/* lambda2 = pow(lambda,2) * .9 * 256 */
-/* Capped to avoid overflow */
-const int x264_lambda2_tab[QP_MAX_MAX+1] =
-{
-       14,       18,       22,       28,       36,       45,      57,      72, /*  0- 7 */
-       91,      115,      145,      182,      230,      290,     365,     460, /*  8-15 */
-      580,      731,      921,     1161,     1462,     1843,    2322,    2925, /* 16-23 */
-     3686,     4644,     5851,     7372,     9289,    11703,   14745,   18578, /* 24-31 */
-    23407,    29491,    37156,    46814,    58982,    74313,   93628,  117964, /* 32-39 */
-   148626,   187257,   235929,   297252,   374514,   471859,  594505,  749029, /* 40-47 */
-   943718,  1189010,  1498059,  1887436,  2378021,  2996119, 3774873, 4756042, /* 48-55 */
-  5992238,  7549747,  9512085, 11984476, 15099494, 19024170,23968953,30198988, /* 56-63 */
- 38048341, 47937906, 60397977, 76096683, 95875813,120795955,                   /* 64-69 */
-134217727,134217727,134217727,134217727,134217727,134217727,                   /* 70-75 */
-134217727,134217727,134217727,134217727,134217727,134217727,                   /* 76-81 */
-};
-
 // should the intra and inter lambdas be different?
 // I'm just matching the behaviour of deadzone quant.
 static const int x264_trellis_lambda2_tab[2][QP_MAX_MAX+1] =
diff --git a/encoder/cabac.c b/encoder/cabac.c
index 954fa9c..780177b 100644
--- a/encoder/cabac.c
+++ b/encoder/cabac.c
@@ -644,53 +644,6 @@ static int ALWAYS_INLINE cabac_cbf_ctxidxinc( x264_t *h, int i_cat, int i_idx, i
     }
 }
 
-#if !RDO_SKIP_BS
-extern const uint8_t x264_significant_coeff_flag_offset_8x8[2][64];
-extern const uint8_t x264_last_coeff_flag_offset_8x8[63];
-extern const uint8_t x264_coeff_flag_offset_chroma_422_dc[7];
-extern const uint16_t x264_significant_coeff_flag_offset[2][16];
-extern const uint16_t x264_last_coeff_flag_offset[2][16];
-extern const uint16_t x264_coeff_abs_level_m1_offset[16];
-extern const uint8_t x264_count_cat_m1[14];
-#else
-/* Padded to [64] for easier addressing */
-const uint8_t x264_significant_coeff_flag_offset_8x8[2][64] =
-{{
-    0, 1, 2, 3, 4, 5, 5, 4, 4, 3, 3, 4, 4, 4, 5, 5,
-    4, 4, 4, 4, 3, 3, 6, 7, 7, 7, 8, 9,10, 9, 8, 7,
-    7, 6,11,12,13,11, 6, 7, 8, 9,14,10, 9, 8, 6,11,
-   12,13,11, 6, 9,14,10, 9,11,12,13,11,14,10,12
-},{
-    0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 7, 7, 8, 4, 5,
-    6, 9,10,10, 8,11,12,11, 9, 9,10,10, 8,11,12,11,
-    9, 9,10,10, 8,11,12,11, 9, 9,10,10, 8,13,13, 9,
-    9,10,10, 8,13,13, 9, 9,10,10,14,14,14,14,14
-}};
-const uint8_t x264_last_coeff_flag_offset_8x8[63] =
-{
-    0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-    3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
-    5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8
-};
-const uint8_t x264_coeff_flag_offset_chroma_422_dc[7] = { 0, 0, 1, 1, 2, 2, 2 }; /* MIN( i/2, 2 ) */
-const uint16_t x264_significant_coeff_flag_offset[2][16] =
-{
-    { 105+0, 105+15, 105+29, 105+44, 105+47, 402, 484+0, 484+15, 484+29, 660, 528+0, 528+15, 528+29, 718, 0, 0 },
-    { 277+0, 277+15, 277+29, 277+44, 277+47, 436, 776+0, 776+15, 776+29, 675, 820+0, 820+15, 820+29, 733, 0, 0 }
-};
-const uint16_t x264_last_coeff_flag_offset[2][16] =
-{
-    { 166+0, 166+15, 166+29, 166+44, 166+47, 417, 572+0, 572+15, 572+29, 690, 616+0, 616+15, 616+29, 748, 0, 0 },
-    { 338+0, 338+15, 338+29, 338+44, 338+47, 451, 864+0, 864+15, 864+29, 699, 908+0, 908+15, 908+29, 757, 0, 0 }
-};
-const uint16_t x264_coeff_abs_level_m1_offset[16] =
-{
-    227+0, 227+10, 227+20, 227+30, 227+39, 426, 952+0, 952+10, 952+20, 708, 982+0, 982+10, 982+20, 766
-};
-const uint8_t x264_count_cat_m1[14] = {15, 14, 15, 3, 14, 63, 15, 14, 15, 63, 15, 14, 15, 63};
-#endif
-
 // node ctx: 0..3: abslevel1 (with abslevelgt1 == 0).
 //           4..7: abslevelgt1 + 3 (and abslevel1 doesn't matter).
 /* map node ctx => cabac ctx for level=1 */
diff --git a/encoder/macroblock.h b/encoder/macroblock.h
index 9ab4700..56e9520 100644
--- a/encoder/macroblock.h
+++ b/encoder/macroblock.h
@@ -29,9 +29,6 @@
 
 #include "common/macroblock.h"
 
-extern const int x264_lambda2_tab[QP_MAX_MAX+1];
-extern const uint16_t x264_lambda_tab[QP_MAX_MAX+1];
-
 void x264_rdo_init( void );
 
 int x264_macroblock_probe_skip( x264_t *h, int b_bidir );
diff --git a/encoder/set.c b/encoder/set.c
index f86189f..07cb4c4 100644
--- a/encoder/set.c
+++ b/encoder/set.c
@@ -781,28 +781,6 @@ int x264_sei_avcintra_vanc_write( x264_t *h, bs_t *s, int len )
     return 0;
 }
 
-const x264_level_t x264_levels[] =
-{
-    { 10,    1485,    99,    396,     64,    175,  64, 64,  0, 2, 0, 0, 1 },
-    {  9,    1485,    99,    396,    128,    350,  64, 64,  0, 2, 0, 0, 1 }, /* "1b" */
-    { 11,    3000,   396,    900,    192,    500, 128, 64,  0, 2, 0, 0, 1 },
-    { 12,    6000,   396,   2376,    384,   1000, 128, 64,  0, 2, 0, 0, 1 },
-    { 13,   11880,   396,   2376,    768,   2000, 128, 64,  0, 2, 0, 0, 1 },
-    { 20,   11880,   396,   2376,   2000,   2000, 128, 64,  0, 2, 0, 0, 1 },
-    { 21,   19800,   792,   4752,   4000,   4000, 256, 64,  0, 2, 0, 0, 0 },
-    { 22,   20250,  1620,   8100,   4000,   4000, 256, 64,  0, 2, 0, 0, 0 },
-    { 30,   40500,  1620,   8100,  10000,  10000, 256, 32, 22, 2, 0, 1, 0 },
-    { 31,  108000,  3600,  18000,  14000,  14000, 512, 16, 60, 4, 1, 1, 0 },
-    { 32,  216000,  5120,  20480,  20000,  20000, 512, 16, 60, 4, 1, 1, 0 },
-    { 40,  245760,  8192,  32768,  20000,  25000, 512, 16, 60, 4, 1, 1, 0 },
-    { 41,  245760,  8192,  32768,  50000,  62500, 512, 16, 24, 2, 1, 1, 0 },
-    { 42,  522240,  8704,  34816,  50000,  62500, 512, 16, 24, 2, 1, 1, 1 },
-    { 50,  589824, 22080, 110400, 135000, 135000, 512, 16, 24, 2, 1, 1, 1 },
-    { 51,  983040, 36864, 184320, 240000, 240000, 512, 16, 24, 2, 1, 1, 1 },
-    { 52, 2073600, 36864, 184320, 240000, 240000, 512, 16, 24, 2, 1, 1, 1 },
-    { 0 }
-};
-
 #define ERROR(...)\
 {\
     if( verbose )\
-- 
2.10.0



More information about the x264-devel mailing list