shithub: libvpx

Download patch

ref: e9d68a5e36d82d99918918438840f2b6f9735a05
parent: 5da753bef9522fa042b8491240358a80e521a76d
author: Ronald S. Bultje <rbultje@google.com>
date: Fri May 31 05:18:59 EDT 2013

Merge all various transform size data trackers into single variables.

Change-Id: I2dfc569106b29fbe4da20585a0e85e5e9ea6a4db

--- a/vp9/common/vp9_entropy.c
+++ b/vp9/common/vp9_entropy.c
@@ -483,14 +483,14 @@
 };
 
 void vp9_default_coef_probs(VP9_COMMON *pc) {
-  vpx_memcpy(pc->fc.coef_probs_4x4, default_coef_probs_4x4,
-             sizeof(pc->fc.coef_probs_4x4));
-  vpx_memcpy(pc->fc.coef_probs_8x8, default_coef_probs_8x8,
-             sizeof(pc->fc.coef_probs_8x8));
-  vpx_memcpy(pc->fc.coef_probs_16x16, default_coef_probs_16x16,
-             sizeof(pc->fc.coef_probs_16x16));
-  vpx_memcpy(pc->fc.coef_probs_32x32, default_coef_probs_32x32,
-             sizeof(pc->fc.coef_probs_32x32));
+  vpx_memcpy(pc->fc.coef_probs[TX_4X4], default_coef_probs_4x4,
+             sizeof(pc->fc.coef_probs[TX_4X4]));
+  vpx_memcpy(pc->fc.coef_probs[TX_8X8], default_coef_probs_8x8,
+             sizeof(pc->fc.coef_probs[TX_8X8]));
+  vpx_memcpy(pc->fc.coef_probs[TX_16X16], default_coef_probs_16x16,
+             sizeof(pc->fc.coef_probs[TX_16X16]));
+  vpx_memcpy(pc->fc.coef_probs[TX_32X32], default_coef_probs_32x32,
+             sizeof(pc->fc.coef_probs[TX_32X32]));
 }
 
 // Neighborhood 5-tuples for various scans and blocksizes,
@@ -677,13 +677,13 @@
         }
 }
 
-static void adapt_coef_probs(
-    vp9_coeff_probs_model *dst_coef_probs,
-    vp9_coeff_probs_model *pre_coef_probs,
-    vp9_coeff_count_model *coef_counts,
-    unsigned int (*eob_branch_count)[REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS],
-    int count_sat,
-    int update_factor) {
+static void adapt_coef_probs(VP9_COMMON *cm, TX_SIZE txfm_size,
+                             int count_sat, int update_factor) {
+  vp9_coeff_probs_model *dst_coef_probs = cm->fc.coef_probs[txfm_size];
+  vp9_coeff_probs_model *pre_coef_probs = cm->fc.pre_coef_probs[txfm_size];
+  vp9_coeff_count_model *coef_counts = cm->fc.coef_counts[txfm_size];
+  unsigned int (*eob_branch_count)[REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS] =
+      cm->fc.eob_branch_counts[txfm_size];
   int t, i, j, k, l, count;
   int factor;
   unsigned int branch_ct[UNCONSTRAINED_NODES][2];
@@ -719,6 +719,7 @@
 }
 
 void vp9_adapt_coef_probs(VP9_COMMON *cm) {
+  TX_SIZE t;
   int count_sat;
   int update_factor; /* denominator 256 */
 
@@ -732,20 +733,6 @@
     update_factor = COEF_MAX_UPDATE_FACTOR;
     count_sat = COEF_COUNT_SAT;
   }
-  adapt_coef_probs(cm->fc.coef_probs_4x4, cm->fc.pre_coef_probs_4x4,
-                   cm->fc.coef_counts_4x4,
-                   cm->fc.eob_branch_counts[TX_4X4],
-                   count_sat, update_factor);
-  adapt_coef_probs(cm->fc.coef_probs_8x8, cm->fc.pre_coef_probs_8x8,
-                   cm->fc.coef_counts_8x8,
-                   cm->fc.eob_branch_counts[TX_8X8],
-                   count_sat, update_factor);
-  adapt_coef_probs(cm->fc.coef_probs_16x16, cm->fc.pre_coef_probs_16x16,
-                   cm->fc.coef_counts_16x16,
-                   cm->fc.eob_branch_counts[TX_16X16],
-                   count_sat, update_factor);
-  adapt_coef_probs(cm->fc.coef_probs_32x32, cm->fc.pre_coef_probs_32x32,
-                   cm->fc.coef_counts_32x32,
-                   cm->fc.eob_branch_counts[TX_32X32],
-                   count_sat, update_factor);
+  for (t = TX_4X4; t <= TX_32X32; t++)
+    adapt_coef_probs(cm, t, count_sat, update_factor);
 }
--- a/vp9/common/vp9_onyxc_int.h
+++ b/vp9/common/vp9_onyxc_int.h
@@ -62,18 +62,9 @@
   unsigned int uv_mode_counts[VP9_INTRA_MODES][VP9_INTRA_MODES];
   unsigned int partition_counts[NUM_PARTITION_CONTEXTS][PARTITION_TYPES];
 
-  vp9_coeff_probs_model coef_probs_4x4[BLOCK_TYPES];
-  vp9_coeff_probs_model coef_probs_8x8[BLOCK_TYPES];
-  vp9_coeff_probs_model coef_probs_16x16[BLOCK_TYPES];
-  vp9_coeff_probs_model coef_probs_32x32[BLOCK_TYPES];
-  vp9_coeff_probs_model pre_coef_probs_4x4[BLOCK_TYPES];
-  vp9_coeff_probs_model pre_coef_probs_8x8[BLOCK_TYPES];
-  vp9_coeff_probs_model pre_coef_probs_16x16[BLOCK_TYPES];
-  vp9_coeff_probs_model pre_coef_probs_32x32[BLOCK_TYPES];
-  vp9_coeff_count_model coef_counts_4x4[BLOCK_TYPES];
-  vp9_coeff_count_model coef_counts_8x8[BLOCK_TYPES];
-  vp9_coeff_count_model coef_counts_16x16[BLOCK_TYPES];
-  vp9_coeff_count_model coef_counts_32x32[BLOCK_TYPES];
+  vp9_coeff_probs_model coef_probs[TX_SIZE_MAX_SB][BLOCK_TYPES];
+  vp9_coeff_probs_model pre_coef_probs[TX_SIZE_MAX_SB][BLOCK_TYPES];
+  vp9_coeff_count_model coef_counts[TX_SIZE_MAX_SB][BLOCK_TYPES];
   unsigned int eob_branch_counts[TX_SIZE_MAX_SB][BLOCK_TYPES][REF_TYPES]
                                 [COEF_BANDS][PREV_COEF_CONTEXTS];
 
--- a/vp9/decoder/vp9_decodframe.c
+++ b/vp9/decoder/vp9_decodframe.c
@@ -577,11 +577,10 @@
   xd->mode_info_stride = pc->mode_info_stride;
 }
 
-static void read_coef_probs_common(
-    vp9_coeff_probs_model *coef_probs,
-    TX_SIZE tx_size,
-    vp9_reader *r) {
+static void read_coef_probs_common(FRAME_CONTEXT *fc, TX_SIZE tx_size,
+                                   vp9_reader *r) {
   const int entropy_nodes_update = UNCONSTRAINED_NODES;
+  vp9_coeff_probs_model *coef_probs = fc->coef_probs[tx_size];
 
   int i, j, k, l, m;
 
@@ -612,16 +611,16 @@
   const TXFM_MODE mode = pbi->common.txfm_mode;
   FRAME_CONTEXT *const fc = &pbi->common.fc;
 
-  read_coef_probs_common(fc->coef_probs_4x4, TX_4X4, r);
+  read_coef_probs_common(fc, TX_4X4, r);
 
   if (mode > ONLY_4X4)
-    read_coef_probs_common(fc->coef_probs_8x8, TX_8X8, r);
+    read_coef_probs_common(fc, TX_8X8, r);
 
   if (mode > ALLOW_8X8)
-    read_coef_probs_common(fc->coef_probs_16x16, TX_16X16, r);
+    read_coef_probs_common(fc, TX_16X16, r);
 
   if (mode > ALLOW_16X16)
-    read_coef_probs_common(fc->coef_probs_32x32, TX_32X32, r);
+    read_coef_probs_common(fc, TX_32X32, r);
 }
 
 static void setup_segmentation(VP9_COMMON *pc, MACROBLOCKD *xd, vp9_reader *r) {
@@ -798,19 +797,13 @@
 }
 
 static void update_frame_context(FRAME_CONTEXT *fc) {
-  vp9_copy(fc->pre_coef_probs_4x4, fc->coef_probs_4x4);
-  vp9_copy(fc->pre_coef_probs_8x8, fc->coef_probs_8x8);
-  vp9_copy(fc->pre_coef_probs_16x16, fc->coef_probs_16x16);
-  vp9_copy(fc->pre_coef_probs_32x32, fc->coef_probs_32x32);
+  vp9_copy(fc->pre_coef_probs, fc->coef_probs);
   vp9_copy(fc->pre_y_mode_prob, fc->y_mode_prob);
   vp9_copy(fc->pre_uv_mode_prob, fc->uv_mode_prob);
   vp9_copy(fc->pre_partition_prob, fc->partition_prob);
   fc->pre_nmvc = fc->nmvc;
 
-  vp9_zero(fc->coef_counts_4x4);
-  vp9_zero(fc->coef_counts_8x8);
-  vp9_zero(fc->coef_counts_16x16);
-  vp9_zero(fc->coef_counts_32x32);
+  vp9_zero(fc->coef_counts);
   vp9_zero(fc->eob_branch_counts);
   vp9_zero(fc->y_mode_counts);
   vp9_zero(fc->uv_mode_counts);
--- a/vp9/decoder/vp9_detokenize.c
+++ b/vp9/decoder/vp9_detokenize.c
@@ -120,6 +120,8 @@
   int skip_eob_node = 0;
 #endif
 
+  coef_probs  = fc->coef_probs[txfm_size][type][ref];
+  coef_counts = fc->coef_counts[txfm_size];
   switch (txfm_size) {
     default:
     case TX_4X4: {
@@ -128,8 +130,6 @@
       scan = get_scan_4x4(tx_type);
       above_ec = A[0] != 0;
       left_ec = L[0] != 0;
-      coef_probs  = fc->coef_probs_4x4[type][ref];
-      coef_counts = fc->coef_counts_4x4;
       default_eob = 16;
       band_translate = vp9_coefband_trans_4x4;
       break;
@@ -142,8 +142,6 @@
       tx_type = (type == PLANE_TYPE_Y_WITH_DC) ?
           get_tx_type_8x8(xd, y + (x >> 1)) : DCT_DCT;
       scan = get_scan_8x8(tx_type);
-      coef_probs  = fc->coef_probs_8x8[type][ref];
-      coef_counts = fc->coef_counts_8x8;
       above_ec = (A[0] + A[1]) != 0;
       left_ec = (L[0] + L[1]) != 0;
       default_eob = 64;
@@ -158,8 +156,6 @@
       tx_type = (type == PLANE_TYPE_Y_WITH_DC) ?
           get_tx_type_16x16(xd, y + (x >> 2)) : DCT_DCT;
       scan = get_scan_16x16(tx_type);
-      coef_probs  = fc->coef_probs_16x16[type][ref];
-      coef_counts = fc->coef_counts_16x16;
       above_ec = (A[0] + A[1] + A[2] + A[3]) != 0;
       left_ec = (L[0] + L[1] + L[2] + L[3]) != 0;
       default_eob = 256;
@@ -168,8 +164,6 @@
     }
     case TX_32X32:
       scan = vp9_default_scan_32x32;
-      coef_probs = fc->coef_probs_32x32[type][ref];
-      coef_counts = fc->coef_counts_32x32;
       above_ec = (A[0] + A[1] + A[2] + A[3] + A[4] + A[5] + A[6] + A[7]) != 0;
       left_ec = (L[0] + L[1] + L[2] + L[3] + L[4] + L[5] + L[6] + L[7]) != 0;
       default_eob = 1024;
--- a/vp9/encoder/vp9_bitstream.c
+++ b/vp9/encoder/vp9_bitstream.c
@@ -43,10 +43,7 @@
 int intra_mode_stats[VP9_INTRA_MODES]
                     [VP9_INTRA_MODES]
                     [VP9_INTRA_MODES];
-vp9_coeff_stats tree_update_hist_4x4[BLOCK_TYPES];
-vp9_coeff_stats tree_update_hist_8x8[BLOCK_TYPES];
-vp9_coeff_stats tree_update_hist_16x16[BLOCK_TYPES];
-vp9_coeff_stats tree_update_hist_32x32[BLOCK_TYPES];
+vp9_coeff_stats tree_update_hist[TX_SIZE_MAX_SB][BLOCK_TYPES];
 
 extern unsigned int active_section;
 #endif
@@ -1014,24 +1011,20 @@
   fclose(f);
 }
 
-static void build_tree_distribution(vp9_coeff_probs_model *coef_probs,
-                                    vp9_coeff_count *coef_counts,
-                                    unsigned int (*eob_branch_ct)[REF_TYPES]
-                                                                 [COEF_BANDS]
-                                                          [PREV_COEF_CONTEXTS],
+static void build_tree_distribution(VP9_COMP *cpi, TX_SIZE txfm_size) {
+  vp9_coeff_probs_model *coef_probs = cpi->frame_coef_probs[txfm_size];
+  vp9_coeff_count *coef_counts = cpi->coef_counts[txfm_size];
+  unsigned int (*eob_branch_ct)[REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS] =
+      cpi->common.fc.eob_branch_counts[txfm_size];
+  vp9_coeff_stats *coef_branch_ct = cpi->frame_branch_ct[txfm_size];
 #ifdef ENTROPY_STATS
-                                    VP9_COMP *cpi,
-                                    vp9_coeff_accum *context_counters,
-#endif
-                                    vp9_coeff_stats *coef_branch_ct,
-                                    int block_types) {
-  int i, j, k, l;
-#ifdef ENTROPY_STATS
+  vp9_coeff_accum *context_counters = context_counters[txfm_size];
   int t = 0;
 #endif
   vp9_prob full_probs[ENTROPY_NODES];
+  int i, j, k, l;
 
-  for (i = 0; i < block_types; ++i) {
+  for (i = 0; i < BLOCK_TYPES; ++i) {
     for (j = 0; j < REF_TYPES; ++j) {
       for (k = 0; k < COEF_BANDS; ++k) {
         for (l = 0; l < PREV_COEF_CONTEXTS; ++l) {
@@ -1071,46 +1064,20 @@
 }
 
 static void build_coeff_contexts(VP9_COMP *cpi) {
-  build_tree_distribution(cpi->frame_coef_probs_4x4,
-                          cpi->coef_counts_4x4,
-                          cpi->common.fc.eob_branch_counts[TX_4X4],
-#ifdef ENTROPY_STATS
-                          cpi, context_counters_4x4,
-#endif
-                          cpi->frame_branch_ct_4x4, BLOCK_TYPES);
-  build_tree_distribution(cpi->frame_coef_probs_8x8,
-                          cpi->coef_counts_8x8,
-                          cpi->common.fc.eob_branch_counts[TX_8X8],
-#ifdef ENTROPY_STATS
-                          cpi, context_counters_8x8,
-#endif
-                          cpi->frame_branch_ct_8x8, BLOCK_TYPES);
-  build_tree_distribution(cpi->frame_coef_probs_16x16,
-                          cpi->coef_counts_16x16,
-                          cpi->common.fc.eob_branch_counts[TX_16X16],
-#ifdef ENTROPY_STATS
-                          cpi, context_counters_16x16,
-#endif
-                          cpi->frame_branch_ct_16x16, BLOCK_TYPES);
-  build_tree_distribution(cpi->frame_coef_probs_32x32,
-                          cpi->coef_counts_32x32,
-                          cpi->common.fc.eob_branch_counts[TX_32X32],
-#ifdef ENTROPY_STATS
-                          cpi, context_counters_32x32,
-#endif
-                          cpi->frame_branch_ct_32x32, BLOCK_TYPES);
+  TX_SIZE t;
+  for (t = TX_4X4; t <= TX_32X32; t++)
+    build_tree_distribution(cpi, t);
 }
 
-static void update_coef_probs_common(
-    vp9_writer* const bc,
-    VP9_COMP *cpi,
+static void update_coef_probs_common(vp9_writer* const bc, VP9_COMP *cpi,
+                                     TX_SIZE tx_size) {
 #ifdef ENTROPY_STATS
-    vp9_coeff_stats *tree_update_hist,
+  vp9_coeff_stats *tree_update_hist = tree_update_hist[tx_size];
 #endif
-    vp9_coeff_probs_model *new_frame_coef_probs,
-    vp9_coeff_probs_model *old_frame_coef_probs,
-    vp9_coeff_stats *frame_branch_ct,
-    TX_SIZE tx_size) {
+  vp9_coeff_probs_model *new_frame_coef_probs = cpi->frame_coef_probs[tx_size];
+  vp9_coeff_probs_model *old_frame_coef_probs =
+      cpi->common.fc.coef_probs[tx_size];
+  vp9_coeff_stats *frame_branch_ct = cpi->frame_branch_ct[tx_size];
   int i, j, k, l, t;
   int update[2] = {0, 0};
   int savings;
@@ -1208,51 +1175,19 @@
   // Build the cofficient contexts based on counts collected in encode loop
   build_coeff_contexts(cpi);
 
-  update_coef_probs_common(bc,
-                           cpi,
-#ifdef ENTROPY_STATS
-                           tree_update_hist_4x4,
-#endif
-                           cpi->frame_coef_probs_4x4,
-                           cpi->common.fc.coef_probs_4x4,
-                           cpi->frame_branch_ct_4x4,
-                           TX_4X4);
+  update_coef_probs_common(bc, cpi, TX_4X4);
 
   /* do not do this if not even allowed */
   if (cpi->common.txfm_mode != ONLY_4X4) {
-    update_coef_probs_common(bc,
-                             cpi,
-#ifdef ENTROPY_STATS
-                             tree_update_hist_8x8,
-#endif
-                             cpi->frame_coef_probs_8x8,
-                             cpi->common.fc.coef_probs_8x8,
-                             cpi->frame_branch_ct_8x8,
-                             TX_8X8);
+    update_coef_probs_common(bc, cpi, TX_8X8);
   }
 
   if (cpi->common.txfm_mode > ALLOW_8X8) {
-    update_coef_probs_common(bc,
-                             cpi,
-#ifdef ENTROPY_STATS
-                             tree_update_hist_16x16,
-#endif
-                             cpi->frame_coef_probs_16x16,
-                             cpi->common.fc.coef_probs_16x16,
-                             cpi->frame_branch_ct_16x16,
-                             TX_16X16);
+    update_coef_probs_common(bc, cpi, TX_16X16);
   }
 
   if (cpi->common.txfm_mode > ALLOW_16X16) {
-    update_coef_probs_common(bc,
-                             cpi,
-#ifdef ENTROPY_STATS
-                             tree_update_hist_32x32,
-#endif
-                             cpi->frame_coef_probs_32x32,
-                             cpi->common.fc.coef_probs_32x32,
-                             cpi->frame_branch_ct_32x32,
-                             TX_32X32);
+    update_coef_probs_common(bc, cpi, TX_32X32);
   }
 }
 
@@ -1665,15 +1600,7 @@
 
   vp9_clear_system_state();  // __asm emms;
 
-  vp9_copy(cpi->common.fc.pre_coef_probs_4x4,
-           cpi->common.fc.coef_probs_4x4);
-  vp9_copy(cpi->common.fc.pre_coef_probs_8x8,
-           cpi->common.fc.coef_probs_8x8);
-  vp9_copy(cpi->common.fc.pre_coef_probs_16x16,
-           cpi->common.fc.coef_probs_16x16);
-  vp9_copy(cpi->common.fc.pre_coef_probs_32x32,
-           cpi->common.fc.coef_probs_32x32);
-
+  vp9_copy(cpi->common.fc.pre_coef_probs, cpi->common.fc.coef_probs);
   vp9_copy(cpi->common.fc.pre_y_mode_prob, cpi->common.fc.y_mode_prob);
   vp9_copy(cpi->common.fc.pre_uv_mode_prob, cpi->common.fc.uv_mode_prob);
   vp9_copy(cpi->common.fc.pre_partition_prob, cpi->common.fc.partition_prob);
@@ -1839,21 +1766,18 @@
   FILE *f = fopen("coefupdprob.h", "w");
   fprintf(f, "\n/* Update probabilities for token entropy tree. */\n\n");
 
-  print_tree_update_for_type(f, tree_update_hist_4x4, BLOCK_TYPES,
+  print_tree_update_for_type(f, tree_update_hist[TX_4X4],   BLOCK_TYPES,
                              "vp9_coef_update_probs_4x4[BLOCK_TYPES]");
-  print_tree_update_for_type(f, tree_update_hist_8x8, BLOCK_TYPES,
+  print_tree_update_for_type(f, tree_update_hist[TX_8X8],   BLOCK_TYPES,
                              "vp9_coef_update_probs_8x8[BLOCK_TYPES]");
-  print_tree_update_for_type(f, tree_update_hist_16x16, BLOCK_TYPES,
+  print_tree_update_for_type(f, tree_update_hist[TX_16X16], BLOCK_TYPES,
                              "vp9_coef_update_probs_16x16[BLOCK_TYPES]");
-  print_tree_update_for_type(f, tree_update_hist_32x32, BLOCK_TYPES,
+  print_tree_update_for_type(f, tree_update_hist[TX_32X32], BLOCK_TYPES,
                              "vp9_coef_update_probs_32x32[BLOCK_TYPES]");
 
   fclose(f);
   f = fopen("treeupdate.bin", "wb");
-  fwrite(tree_update_hist_4x4, sizeof(tree_update_hist_4x4), 1, f);
-  fwrite(tree_update_hist_8x8, sizeof(tree_update_hist_8x8), 1, f);
-  fwrite(tree_update_hist_16x16, sizeof(tree_update_hist_16x16), 1, f);
-  fwrite(tree_update_hist_32x32, sizeof(tree_update_hist_32x32), 1, f);
+  fwrite(tree_update_hist, sizeof(tree_update_hist), 1, f);
   fclose(f);
 }
 #endif
--- a/vp9/encoder/vp9_encodeframe.c
+++ b/vp9/encoder/vp9_encodeframe.c
@@ -1534,10 +1534,7 @@
   xd->prev_mode_info_context = cm->prev_mi;
 
   vp9_zero(cpi->NMVcount);
-  vp9_zero(cpi->coef_counts_4x4);
-  vp9_zero(cpi->coef_counts_8x8);
-  vp9_zero(cpi->coef_counts_16x16);
-  vp9_zero(cpi->coef_counts_32x32);
+  vp9_zero(cpi->coef_counts);
   vp9_zero(cm->fc.eob_branch_counts);
 
   cpi->mb.e_mbd.lossless = cm->base_qindex == 0 &&
--- a/vp9/encoder/vp9_onyx_if.c
+++ b/vp9/encoder/vp9_onyx_if.c
@@ -466,8 +466,8 @@
 void vp9_update_mode_context_stats(VP9_COMP *cpi) {
   VP9_COMMON *cm = &cpi->common;
   int i, j;
-  unsigned int (*mv_ref_ct)[4][2] = cm->fc.mv_ref_ct;
-  int64_t (*mv_ref_stats)[4][2] = cpi->mv_ref_stats;
+  unsigned int (*mv_ref_ct)[VP9_MVREFS - 1][2] = cm->fc.mv_ref_ct;
+  int64_t (*mv_ref_stats)[VP9_MVREFS - 1][2] = cpi->mv_ref_stats;
   FILE *f;
 
   // Read the past stats counters
@@ -2422,7 +2422,7 @@
                                       unsigned int *frame_flags) {
   VP9_COMMON *cm = &cpi->common;
   MACROBLOCKD *xd = &cpi->mb.e_mbd;
-
+  TX_SIZE t;
   int q;
   int frame_over_shoot_limit;
   int frame_under_shoot_limit;
@@ -3100,14 +3100,9 @@
   release_scaled_references(cpi);
   update_reference_frames(cpi);
 
-  vp9_full_to_model_counts(cpi->common.fc.coef_counts_4x4,
-                           cpi->coef_counts_4x4);
-  vp9_full_to_model_counts(cpi->common.fc.coef_counts_8x8,
-                           cpi->coef_counts_8x8);
-  vp9_full_to_model_counts(cpi->common.fc.coef_counts_16x16,
-                           cpi->coef_counts_16x16);
-  vp9_full_to_model_counts(cpi->common.fc.coef_counts_32x32,
-                           cpi->coef_counts_32x32);
+  for (t = TX_4X4; t <= TX_32X32; t++)
+    vp9_full_to_model_counts(cpi->common.fc.coef_counts[t],
+                             cpi->coef_counts[t]);
   if (!cpi->common.error_resilient_mode &&
       !cpi->common.frame_parallel_decoding_mode) {
     vp9_adapt_coef_probs(&cpi->common);
--- a/vp9/encoder/vp9_onyx_int.h
+++ b/vp9/encoder/vp9_onyx_int.h
@@ -76,10 +76,7 @@
   // 0 = I4X4_PRED, ZERO_MV, MV, SPLIT
   signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS];
 
-  vp9_coeff_probs_model coef_probs_4x4[BLOCK_TYPES];
-  vp9_coeff_probs_model coef_probs_8x8[BLOCK_TYPES];
-  vp9_coeff_probs_model coef_probs_16x16[BLOCK_TYPES];
-  vp9_coeff_probs_model coef_probs_32x32[BLOCK_TYPES];
+  vp9_coeff_probs_model coef_probs[TX_SIZE_MAX_SB][BLOCK_TYPES];
 
   vp9_prob y_mode_prob[VP9_INTRA_MODES - 1]; /* interframe intra mode probs */
   vp9_prob uv_mode_prob[VP9_INTRA_MODES][VP9_INTRA_MODES - 1];
@@ -414,21 +411,9 @@
 
   nmv_context_counts NMVcount;
 
-  vp9_coeff_count coef_counts_4x4[BLOCK_TYPES];
-  vp9_coeff_probs_model frame_coef_probs_4x4[BLOCK_TYPES];
-  vp9_coeff_stats frame_branch_ct_4x4[BLOCK_TYPES];
-
-  vp9_coeff_count coef_counts_8x8[BLOCK_TYPES];
-  vp9_coeff_probs_model frame_coef_probs_8x8[BLOCK_TYPES];
-  vp9_coeff_stats frame_branch_ct_8x8[BLOCK_TYPES];
-
-  vp9_coeff_count coef_counts_16x16[BLOCK_TYPES];
-  vp9_coeff_probs_model frame_coef_probs_16x16[BLOCK_TYPES];
-  vp9_coeff_stats frame_branch_ct_16x16[BLOCK_TYPES];
-
-  vp9_coeff_count coef_counts_32x32[BLOCK_TYPES];
-  vp9_coeff_probs_model frame_coef_probs_32x32[BLOCK_TYPES];
-  vp9_coeff_stats frame_branch_ct_32x32[BLOCK_TYPES];
+  vp9_coeff_count coef_counts[TX_SIZE_MAX_SB][BLOCK_TYPES];
+  vp9_coeff_probs_model frame_coef_probs[TX_SIZE_MAX_SB][BLOCK_TYPES];
+  vp9_coeff_stats frame_branch_ct[TX_SIZE_MAX_SB][BLOCK_TYPES];
 
   int gfu_boost;
   int last_boost;
--- a/vp9/encoder/vp9_ratectrl.c
+++ b/vp9/encoder/vp9_ratectrl.c
@@ -139,10 +139,7 @@
   vp9_copy(cc->last_ref_lf_deltas, xd->last_ref_lf_deltas);
   vp9_copy(cc->last_mode_lf_deltas, xd->last_mode_lf_deltas);
 
-  vp9_copy(cc->coef_probs_4x4, cm->fc.coef_probs_4x4);
-  vp9_copy(cc->coef_probs_8x8, cm->fc.coef_probs_8x8);
-  vp9_copy(cc->coef_probs_16x16, cm->fc.coef_probs_16x16);
-  vp9_copy(cc->coef_probs_32x32, cm->fc.coef_probs_32x32);
+  vp9_copy(cc->coef_probs, cm->fc.coef_probs);
   vp9_copy(cc->switchable_interp_prob, cm->fc.switchable_interp_prob);
 }
 
@@ -177,10 +174,7 @@
   vp9_copy(xd->last_ref_lf_deltas, cc->last_ref_lf_deltas);
   vp9_copy(xd->last_mode_lf_deltas, cc->last_mode_lf_deltas);
 
-  vp9_copy(cm->fc.coef_probs_4x4, cc->coef_probs_4x4);
-  vp9_copy(cm->fc.coef_probs_8x8, cc->coef_probs_8x8);
-  vp9_copy(cm->fc.coef_probs_16x16, cc->coef_probs_16x16);
-  vp9_copy(cm->fc.coef_probs_32x32, cc->coef_probs_32x32);
+  vp9_copy(cm->fc.coef_probs, cc->coef_probs);
   vp9_copy(cm->fc.switchable_interp_prob, cc->switchable_interp_prob);
 }
 
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -112,39 +112,41 @@
 };
 
 #if CONFIG_BALANCED_COEFTREE
-static void fill_token_costs(vp9_coeff_count *c,
-                             vp9_coeff_count *cnoskip,
-                             vp9_coeff_probs_model *p,
-                             TX_SIZE tx_size) {
+static void fill_token_costs(vp9_coeff_count (*c)[BLOCK_TYPES],
+                             vp9_coeff_count (*cnoskip)[BLOCK_TYPES],
+                             vp9_coeff_probs_model (*p)[BLOCK_TYPES]) {
   int i, j, k, l;
-  for (i = 0; i < BLOCK_TYPES; i++)
-    for (j = 0; j < REF_TYPES; j++)
-      for (k = 0; k < COEF_BANDS; k++)
-        for (l = 0; l < PREV_COEF_CONTEXTS; l++) {
-          vp9_prob probs[ENTROPY_NODES];
-          vp9_model_to_full_probs(p[i][j][k][l], probs);
-          vp9_cost_tokens((int *)cnoskip[i][j][k][l], probs,
-                          vp9_coef_tree);
-          // Replace the eob node prob with a very small value so that the
-          // cost approximately equals the cost without the eob node
-          probs[1] = 1;
-          vp9_cost_tokens((int *)c[i][j][k][l], probs, vp9_coef_tree);
-        }
+  TX_SIZE t;
+  for (t = TX_4X4; t <= TX_32X32; t++)
+    for (i = 0; i < BLOCK_TYPES; i++)
+      for (j = 0; j < REF_TYPES; j++)
+        for (k = 0; k < COEF_BANDS; k++)
+          for (l = 0; l < PREV_COEF_CONTEXTS; l++) {
+            vp9_prob probs[ENTROPY_NODES];
+            vp9_model_to_full_probs(p[t][i][j][k][l], probs);
+            vp9_cost_tokens((int *)cnoskip[t][i][j][k][l], probs,
+                            vp9_coef_tree);
+            // Replace the eob node prob with a very small value so that the
+            // cost approximately equals the cost without the eob node
+            probs[1] = 1;
+            vp9_cost_tokens((int *)c[t][i][j][k][l], probs, vp9_coef_tree);
+          }
 }
 #else
-static void fill_token_costs(vp9_coeff_count *c,
-                             vp9_coeff_probs_model *p,
-                             TX_SIZE tx_size) {
+static void fill_token_costs(vp9_coeff_count (*c)[BLOCK_TYPES],
+                             vp9_coeff_probs_model (*p)[BLOCK_TYPES]) {
   int i, j, k, l;
-  for (i = 0; i < BLOCK_TYPES; i++)
-    for (j = 0; j < REF_TYPES; j++)
-      for (k = 0; k < COEF_BANDS; k++)
-        for (l = 0; l < PREV_COEF_CONTEXTS; l++) {
-          vp9_prob probs[ENTROPY_NODES];
-          vp9_model_to_full_probs(p[i][j][k][l], probs);
-          vp9_cost_tokens_skip((int *)c[i][j][k][l], probs,
-                               vp9_coef_tree);
-        }
+  TX_SIZE t;
+  for (t = TX_4X4; t <= TX_32X32; t++)
+    for (i = 0; i < BLOCK_TYPES; i++)
+      for (j = 0; j < REF_TYPES; j++)
+        for (k = 0; k < COEF_BANDS; k++)
+          for (l = 0; l < PREV_COEF_CONTEXTS; l++) {
+            vp9_prob probs[ENTROPY_NODES];
+            vp9_model_to_full_probs(p[t][i][j][k][l], probs);
+            vp9_cost_tokens_skip((int *)c[t][i][j][k][l], probs,
+                                 vp9_coef_tree);
+          }
 }
 #endif
 
@@ -238,27 +240,12 @@
   }
 
 #if CONFIG_BALANCED_COEFTREE
-  fill_token_costs(cpi->mb.token_costs[TX_4X4],
-                   cpi->mb.token_costs_noskip[TX_4X4],
-                   cpi->common.fc.coef_probs_4x4, TX_4X4);
-  fill_token_costs(cpi->mb.token_costs[TX_8X8],
-                   cpi->mb.token_costs_noskip[TX_8X8],
-                   cpi->common.fc.coef_probs_8x8, TX_8X8);
-  fill_token_costs(cpi->mb.token_costs[TX_16X16],
-                   cpi->mb.token_costs_noskip[TX_16X16],
-                   cpi->common.fc.coef_probs_16x16, TX_16X16);
-  fill_token_costs(cpi->mb.token_costs[TX_32X32],
-                   cpi->mb.token_costs_noskip[TX_32X32],
-                   cpi->common.fc.coef_probs_32x32, TX_32X32);
+  fill_token_costs(cpi->mb.token_costs,
+                   cpi->mb.token_costs_noskip,
+                   cpi->common.fc.coef_probs);
 #else
-  fill_token_costs(cpi->mb.token_costs[TX_4X4],
-                   cpi->common.fc.coef_probs_4x4, TX_4X4);
-  fill_token_costs(cpi->mb.token_costs[TX_8X8],
-                   cpi->common.fc.coef_probs_8x8, TX_8X8);
-  fill_token_costs(cpi->mb.token_costs[TX_16X16],
-                   cpi->common.fc.coef_probs_16x16, TX_16X16);
-  fill_token_costs(cpi->mb.token_costs[TX_32X32],
-                   cpi->common.fc.coef_probs_32x32, TX_32X32);
+  fill_token_costs(cpi->mb.token_costs,
+                   cpi->common.fc.coef_probs);
 #endif
 
   for (i = 0; i < NUM_PARTITION_CONTEXTS; i++)
@@ -332,6 +319,9 @@
     assert(tx_size == tx_size_uv);
   }
 
+#if !CONFIG_BALANCED_COEFTREE
+  vp9_model_to_full_probs_sb(cm->fc.coef_probs[tx_size][type][ref], coef_probs);
+#endif
   switch (tx_size) {
     case TX_4X4: {
       tx_type = (type == PLANE_TYPE_Y_WITH_DC) ?
@@ -338,10 +328,6 @@
           get_tx_type_4x4(xd, block) : DCT_DCT;
       above_ec = A[0] != 0;
       left_ec = L[0] != 0;
-#if !CONFIG_BALANCED_COEFTREE
-      vp9_model_to_full_probs_sb(cm->fc.coef_probs_4x4[type][ref],
-                                 coef_probs);
-#endif
       seg_eob = 16;
       scan = get_scan_4x4(tx_type);
       band_translate = vp9_coefband_trans_4x4;
@@ -356,10 +342,6 @@
       above_ec = (A[0] + A[1]) != 0;
       left_ec = (L[0] + L[1]) != 0;
       scan = get_scan_8x8(tx_type);
-#if !CONFIG_BALANCED_COEFTREE
-      vp9_model_to_full_probs_sb(cm->fc.coef_probs_8x8[type][ref],
-                                 coef_probs);
-#endif
       seg_eob = 64;
       band_translate = vp9_coefband_trans_8x8plus;
       break;
@@ -371,10 +353,6 @@
       TX_TYPE tx_type = (type == PLANE_TYPE_Y_WITH_DC) ?
           get_tx_type_16x16(xd, y + (x >> 2)) : DCT_DCT;
       scan = get_scan_16x16(tx_type);
-#if !CONFIG_BALANCED_COEFTREE
-      vp9_model_to_full_probs_sb(cm->fc.coef_probs_16x16[type][ref],
-                                 coef_probs);
-#endif
       seg_eob = 256;
       above_ec = (A[0] + A[1] + A[2] + A[3]) != 0;
       left_ec = (L[0] + L[1] + L[2] + L[3]) != 0;
@@ -383,10 +361,6 @@
     }
     case TX_32X32:
       scan = vp9_default_scan_32x32;
-#if !CONFIG_BALANCED_COEFTREE
-      vp9_model_to_full_probs_sb(cm->fc.coef_probs_32x32[type][ref],
-                                 coef_probs);
-#endif
       seg_eob = 1024;
       above_ec = (A[0] + A[1] + A[2] + A[3] + A[4] + A[5] + A[6] + A[7]) != 0;
       left_ec = (L[0] + L[1] + L[2] + L[3] + L[4] + L[5] + L[6] + L[7]) != 0;
--- a/vp9/encoder/vp9_tokenize.c
+++ b/vp9/encoder/vp9_tokenize.c
@@ -25,15 +25,8 @@
    compressions, then generating vp9_context.c = initial stats. */
 
 #ifdef ENTROPY_STATS
-vp9_coeff_accum context_counters_4x4[BLOCK_TYPES];
-vp9_coeff_accum context_counters_8x8[BLOCK_TYPES];
-vp9_coeff_accum context_counters_16x16[BLOCK_TYPES];
-vp9_coeff_accum context_counters_32x32[BLOCK_TYPES];
-
-extern vp9_coeff_stats tree_update_hist_4x4[BLOCK_TYPES];
-extern vp9_coeff_stats tree_update_hist_8x8[BLOCK_TYPES];
-extern vp9_coeff_stats tree_update_hist_16x16[BLOCK_TYPES];
-extern vp9_coeff_stats tree_update_hist_32x32[BLOCK_TYPES];
+vp9_coeff_accum context_counters[TX_SIZE_MAX_SB][BLOCK_TYPES];
+extern vp9_coeff_stats tree_update_hist[TX_SIZE_MAX_SB][BLOCK_TYPES];
 #endif  /* ENTROPY_STATS */
 
 DECLARE_ALIGNED(16, extern const uint8_t,
@@ -143,6 +136,8 @@
   const uint8_t * band_translate;
   assert((!type && !plane) || (type && plane));
 
+  counts = cpi->coef_counts[tx_size];
+  coef_probs = cpi->common.fc.coef_probs[tx_size];
   switch (tx_size) {
     default:
     case TX_4X4: {
@@ -152,8 +147,6 @@
       left_ec = L[0] != 0;
       seg_eob = 16;
       scan = get_scan_4x4(tx_type);
-      counts = cpi->coef_counts_4x4;
-      coef_probs = cpi->common.fc.coef_probs_4x4;
       band_translate = vp9_coefband_trans_4x4;
       break;
     }
@@ -166,8 +159,6 @@
       left_ec = (L[0] + L[1]) != 0;
       seg_eob = 64;
       scan = get_scan_8x8(tx_type);
-      counts = cpi->coef_counts_8x8;
-      coef_probs = cpi->common.fc.coef_probs_8x8;
       band_translate = vp9_coefband_trans_8x8plus;
       break;
     }
@@ -180,8 +171,6 @@
       left_ec = (L[0] + L[1] + L[2] + L[3]) != 0;
       seg_eob = 256;
       scan = get_scan_16x16(tx_type);
-      counts = cpi->coef_counts_16x16;
-      coef_probs = cpi->common.fc.coef_probs_16x16;
       band_translate = vp9_coefband_trans_8x8plus;
       break;
     }
@@ -190,8 +179,6 @@
       left_ec = (L[0] + L[1] + L[2] + L[3] + L[4] + L[5] + L[6] + L[7]) != 0;
       seg_eob = 1024;
       scan = vp9_default_scan_32x32;
-      counts = cpi->coef_counts_32x32;
-      coef_probs = cpi->common.fc.coef_probs_32x32;
       band_translate = vp9_coefband_trans_8x8plus;
       break;
   }
@@ -322,29 +309,17 @@
 void init_context_counters(void) {
   FILE *f = fopen("context.bin", "rb");
   if (!f) {
-    vpx_memset(context_counters_4x4, 0, sizeof(context_counters_4x4));
-    vpx_memset(context_counters_8x8, 0, sizeof(context_counters_8x8));
-    vpx_memset(context_counters_16x16, 0, sizeof(context_counters_16x16));
-    vpx_memset(context_counters_32x32, 0, sizeof(context_counters_32x32));
+    vp9_zero(context_counters);
   } else {
-    fread(context_counters_4x4, sizeof(context_counters_4x4), 1, f);
-    fread(context_counters_8x8, sizeof(context_counters_8x8), 1, f);
-    fread(context_counters_16x16, sizeof(context_counters_16x16), 1, f);
-    fread(context_counters_32x32, sizeof(context_counters_32x32), 1, f);
+    fread(context_counters, sizeof(context_counters), 1, f);
     fclose(f);
   }
 
   f = fopen("treeupdate.bin", "rb");
   if (!f) {
-    vpx_memset(tree_update_hist_4x4, 0, sizeof(tree_update_hist_4x4));
-    vpx_memset(tree_update_hist_8x8, 0, sizeof(tree_update_hist_8x8));
-    vpx_memset(tree_update_hist_16x16, 0, sizeof(tree_update_hist_16x16));
-    vpx_memset(tree_update_hist_32x32, 0, sizeof(tree_update_hist_32x32));
+    vpx_memset(tree_update_hist, 0, sizeof(tree_update_hist));
   } else {
-    fread(tree_update_hist_4x4, sizeof(tree_update_hist_4x4), 1, f);
-    fread(tree_update_hist_8x8, sizeof(tree_update_hist_8x8), 1, f);
-    fread(tree_update_hist_16x16, sizeof(tree_update_hist_16x16), 1, f);
-    fread(tree_update_hist_32x32, sizeof(tree_update_hist_32x32), 1, f);
+    fread(tree_update_hist, sizeof(tree_update_hist), 1, f);
     fclose(f);
   }
 }
@@ -446,32 +421,29 @@
   fprintf(f, "\n/* *** GENERATED FILE: DO NOT EDIT *** */\n\n");
 
   /* print counts */
-  print_counter(f, context_counters_4x4, BLOCK_TYPES,
+  print_counter(f, context_counters[TX_4X4], BLOCK_TYPES,
                 "vp9_default_coef_counts_4x4[BLOCK_TYPES]");
-  print_counter(f, context_counters_8x8, BLOCK_TYPES,
+  print_counter(f, context_counters[TX_8X8], BLOCK_TYPES,
                 "vp9_default_coef_counts_8x8[BLOCK_TYPES]");
-  print_counter(f, context_counters_16x16, BLOCK_TYPES,
+  print_counter(f, context_counters[TX_16X16], BLOCK_TYPES,
                 "vp9_default_coef_counts_16x16[BLOCK_TYPES]");
-  print_counter(f, context_counters_32x32, BLOCK_TYPES,
+  print_counter(f, context_counters[TX_32X32], BLOCK_TYPES,
                 "vp9_default_coef_counts_32x32[BLOCK_TYPES]");
 
   /* print coefficient probabilities */
-  print_probs(f, context_counters_4x4, BLOCK_TYPES,
+  print_probs(f, context_counters[TX_4X4], BLOCK_TYPES,
               "default_coef_probs_4x4[BLOCK_TYPES]");
-  print_probs(f, context_counters_8x8, BLOCK_TYPES,
+  print_probs(f, context_counters[TX_8X8], BLOCK_TYPES,
               "default_coef_probs_8x8[BLOCK_TYPES]");
-  print_probs(f, context_counters_16x16, BLOCK_TYPES,
+  print_probs(f, context_counters[TX_16X16], BLOCK_TYPES,
               "default_coef_probs_16x16[BLOCK_TYPES]");
-  print_probs(f, context_counters_32x32, BLOCK_TYPES,
+  print_probs(f, context_counters[TX_32X32], BLOCK_TYPES,
               "default_coef_probs_32x32[BLOCK_TYPES]");
 
   fclose(f);
 
   f = fopen("context.bin", "wb");
-  fwrite(context_counters_4x4, sizeof(context_counters_4x4), 1, f);
-  fwrite(context_counters_8x8, sizeof(context_counters_8x8), 1, f);
-  fwrite(context_counters_16x16, sizeof(context_counters_16x16), 1, f);
-  fwrite(context_counters_32x32, sizeof(context_counters_32x32), 1, f);
+  fwrite(context_counters, sizeof(context_counters), 1, f);
   fclose(f);
 }
 #endif
--- a/vp9/encoder/vp9_tokenize.h
+++ b/vp9/encoder/vp9_tokenize.h
@@ -43,10 +43,7 @@
 void init_context_counters();
 void print_context_counters();
 
-extern vp9_coeff_accum context_counters_4x4[BLOCK_TYPES];
-extern vp9_coeff_accum context_counters_8x8[BLOCK_TYPES];
-extern vp9_coeff_accum context_counters_16x16[BLOCK_TYPES];
-extern vp9_coeff_accum context_counters_32x32[BLOCK_TYPES];
+extern vp9_coeff_accum context_counters[TX_SIZE_MAX_SB][BLOCK_TYPES];
 #endif
 
 extern const int *vp9_dct_value_cost_ptr;