Refactor supertx implementation

Replace hard coded numbers with table access. Avoid comparing
values from different enums.

Change-Id: I43216db4a9b13ee317e8e517683946f526e5ca0e
diff --git a/av1/common/blockd.h b/av1/common/blockd.h
index cf646bf..b71c997 100644
--- a/av1/common/blockd.h
+++ b/av1/common/blockd.h
@@ -555,9 +555,9 @@
 
 #if CONFIG_SUPERTX
 static INLINE int supertx_enabled(const MB_MODE_INFO *mbmi) {
-  return (int)txsize_sqr_map[mbmi->tx_size] >
-         AOMMIN(b_width_log2_lookup[mbmi->sb_type],
-                b_height_log2_lookup[mbmi->sb_type]);
+  TX_SIZE max_tx_size = txsize_sqr_map[mbmi->tx_size];
+  return tx_size_wide[max_tx_size] >
+         AOMMIN(block_size_wide[mbmi->sb_type], block_size_high[mbmi->sb_type]);
 }
 #endif  // CONFIG_SUPERTX
 
@@ -869,16 +869,16 @@
 static INLINE TX_SIZE get_uv_tx_size(const MB_MODE_INFO *mbmi,
                                      const struct macroblockd_plane *pd) {
   TX_SIZE uv_txsize;
+#if CONFIG_CB4X4
+  assert(mbmi->tx_size > TX_2X2);
+#endif
+
 #if CONFIG_SUPERTX
   if (supertx_enabled(mbmi))
     return uvsupertx_size_lookup[txsize_sqr_map[mbmi->tx_size]]
                                 [pd->subsampling_x][pd->subsampling_y];
 #endif  // CONFIG_SUPERTX
 
-#if CONFIG_CB4X4
-  assert(mbmi->tx_size > TX_2X2);
-#endif
-
   uv_txsize = uv_txsize_lookup[mbmi->sb_type][mbmi->tx_size][pd->subsampling_x]
                               [pd->subsampling_y];
   assert(uv_txsize != TX_INVALID);
diff --git a/av1/common/entropymode.c b/av1/common/entropymode.c
index f7dbf7e..7949d2a 100644
--- a/av1/common/entropymode.c
+++ b/av1/common/entropymode.c
@@ -1910,7 +1910,7 @@
 
 #if CONFIG_SUPERTX
   for (i = 0; i < PARTITION_SUPERTX_CONTEXTS; ++i) {
-    for (j = 1; j < TX_SIZES; ++j) {
+    for (j = TX_8X8; j < TX_SIZES; ++j) {
       fc->supertx_prob[i][j] = av1_mode_mv_merge_probs(
           pre_fc->supertx_prob[i][j], counts->supertx[i][j]);
     }
diff --git a/av1/common/reconinter.c b/av1/common/reconinter.c
index 7881f90..f7d4c65 100644
--- a/av1/common/reconinter.c
+++ b/av1/common/reconinter.c
@@ -1043,10 +1043,10 @@
   const struct macroblockd_plane *pd = &xd->plane[plane];
   const int ssx = pd->subsampling_x;
   const int ssy = pd->subsampling_y;
-  const int top_w = (4 << b_width_log2_lookup[top_bsize]) >> ssx;
-  const int top_h = (4 << b_height_log2_lookup[top_bsize]) >> ssy;
-  const int w = (4 << b_width_log2_lookup[bsize]) >> ssx;
-  const int h = (4 << b_height_log2_lookup[bsize]) >> ssy;
+  const int top_w = block_size_wide[top_bsize] >> ssx;
+  const int top_h = block_size_high[top_bsize] >> ssy;
+  const int w = block_size_wide[bsize] >> ssx;
+  const int h = block_size_high[bsize] >> ssy;
   const int w_offset = ((mi_col - mi_col_ori) * MI_SIZE) >> ssx;
   const int h_offset = ((mi_row - mi_row_ori) * MI_SIZE) >> ssy;
 
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 3800fec..3f1c147 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -646,8 +646,8 @@
   // Used in supertx
   // (mi_row_ori, mi_col_ori): location for mv
   // (mi_row_pred, mi_col_pred, bsize_pred): region to predict
-  const int bw = num_8x8_blocks_wide_lookup[bsize_pred];
-  const int bh = num_8x8_blocks_high_lookup[bsize_pred];
+  const int bw = mi_size_wide[bsize_pred];
+  const int bh = mi_size_high[bsize_pred];
   const int offset = mi_row_ori * cm->mi_stride + mi_col_ori;
   xd->mi = cm->mi_grid_visible + offset;
   xd->mi[0] = cm->mi + offset;
@@ -682,8 +682,8 @@
 static void set_offsets_topblock(AV1_COMMON *const cm, MACROBLOCKD *const xd,
                                  const TileInfo *const tile, BLOCK_SIZE bsize,
                                  int mi_row, int mi_col) {
-  const int bw = num_8x8_blocks_wide_lookup[bsize];
-  const int bh = num_8x8_blocks_high_lookup[bsize];
+  const int bw = mi_size_wide[bsize];
+  const int bh = mi_size_high[bsize];
   const int offset = mi_row * cm->mi_stride + mi_col;
 
   xd->mi = cm->mi_grid_visible + offset;
@@ -699,8 +699,8 @@
 static void set_param_topblock(AV1_COMMON *const cm, MACROBLOCKD *const xd,
                                BLOCK_SIZE bsize, int mi_row, int mi_col,
                                int txfm, int skip) {
-  const int bw = num_8x8_blocks_wide_lookup[bsize];
-  const int bh = num_8x8_blocks_high_lookup[bsize];
+  const int bw = mi_size_wide[bsize];
+  const int bh = mi_size_high[bsize];
   const int x_mis = AOMMIN(bw, cm->mi_cols - mi_col);
   const int y_mis = AOMMIN(bh, cm->mi_rows - mi_row);
   const int offset = mi_row * cm->mi_stride + mi_col;
@@ -749,8 +749,8 @@
   // bextend: 1: region to predict is an extension of ori; 0: not
   int r = (mi_row_pred - mi_row_top) * MI_SIZE;
   int c = (mi_col_pred - mi_col_top) * MI_SIZE;
-  const int mi_width_top = num_8x8_blocks_wide_lookup[bsize_top];
-  const int mi_height_top = num_8x8_blocks_high_lookup[bsize_top];
+  const int mi_width_top = mi_size_wide[bsize_top];
+  const int mi_height_top = mi_size_high[bsize_top];
   MB_MODE_INFO *mbmi;
   AV1_COMMON *const cm = &pbi->common;
 
@@ -768,6 +768,9 @@
 
   if (!bextend) {
     mbmi->tx_size = b_width_log2_lookup[bsize_top];
+#if CONFIG_CB4X4
+    ++mbmi->tx_size;
+#endif
   }
 
   xd->plane[0].dst.stride = dst_stride[0];
@@ -805,8 +808,8 @@
                            uint8_t *dst_buf[3], int dst_stride[3], int dir) {
   // dir: 0-lower, 1-upper, 2-left, 3-right
   //      4-lowerleft, 5-upperleft, 6-lowerright, 7-upperright
-  const int mi_width = num_8x8_blocks_wide_lookup[bsize];
-  const int mi_height = num_8x8_blocks_high_lookup[bsize];
+  const int mi_width = mi_size_wide[bsize];
+  const int mi_height = mi_size_high[bsize];
   int xss = xd->plane[1].subsampling_x;
   int yss = xd->plane[1].subsampling_y;
   int b_sub8x8 = (bsize < BLOCK_8X8) ? 1 : 0;
@@ -814,11 +817,12 @@
   int unit, mi_row_pred, mi_col_pred;
 
   if (dir == 0 || dir == 1) {
-    extend_bsize = (mi_width == 1 || bsize < BLOCK_8X8 || xss < yss)
-                       ? BLOCK_8X8
-                       : BLOCK_16X8;
-    unit = num_8x8_blocks_wide_lookup[extend_bsize];
-    mi_row_pred = mi_row + ((dir == 0) ? mi_height : -1);
+    extend_bsize =
+        (mi_width == mi_size_wide[BLOCK_8X8] || bsize < BLOCK_8X8 || xss < yss)
+            ? BLOCK_8X8
+            : BLOCK_16X8;
+    unit = mi_size_wide[extend_bsize];
+    mi_row_pred = mi_row + ((dir == 0) ? mi_height : -mi_size_high[BLOCK_8X8]);
     mi_col_pred = mi_col;
 
     dec_predict_b_extend(pbi, xd, tile, block, mi_row, mi_col, mi_row_pred,