Grow MODE_INFO array to use an 8x8 basis.
authorRonald S. Bultje <rbultje@google.com>
Fri, 26 Apr 2013 18:57:17 +0000 (11:57 -0700)
committerRonald S. Bultje <rbultje@google.com>
Fri, 26 Apr 2013 18:57:17 +0000 (11:57 -0700)
Change-Id: I087e08e7909a406b71715b8525c104208daa6889

26 files changed:
vp9/common/vp9_alloccommon.c
vp9/common/vp9_blockd.h
vp9/common/vp9_entropy.h
vp9/common/vp9_entropymode.c
vp9/common/vp9_enums.h
vp9/common/vp9_loopfilter.c
vp9/common/vp9_mvref_common.c
vp9/common/vp9_onyxc_int.h
vp9/common/vp9_pred_common.c
vp9/common/vp9_pred_common.h
vp9/common/vp9_reconinter.c
vp9/common/vp9_reconinter.h
vp9/common/vp9_reconintra.c
vp9/common/vp9_tile_common.c
vp9/decoder/vp9_decodemv.c
vp9/decoder/vp9_decodframe.c
vp9/encoder/vp9_bitstream.c
vp9/encoder/vp9_encodeframe.c
vp9/encoder/vp9_encodemb.c
vp9/encoder/vp9_firstpass.c
vp9/encoder/vp9_mbgraph.c
vp9/encoder/vp9_onyx_if.c
vp9/encoder/vp9_ratectrl.c
vp9/encoder/vp9_rdopt.c
vp9/encoder/vp9_rdopt.h
vp9/encoder/vp9_segmentation.c

index b88a5d4..a7dc079 100644 (file)
@@ -27,7 +27,7 @@ void vp9_update_mode_info_border(VP9_COMMON *cpi, MODE_INFO *mi) {
   vpx_memset(mi, 0, sizeof(MODE_INFO) * stride);
 
   // Clear left border column
-  for (i = 1; i < cpi->mb_rows + 1; i++)
+  for (i = 1; i < cpi->mi_rows + 1; i++)
     vpx_memset(&mi[i * stride], 0, sizeof(MODE_INFO));
 }
 
@@ -36,9 +36,9 @@ void vp9_update_mode_info_in_image(VP9_COMMON *cpi, MODE_INFO *mi) {
   MODE_INFO *ptr;
 
   // For each in image mode_info element set the in image flag to 1
-  for (i = 0; i < cpi->mb_rows; i++) {
+  for (i = 0; i < cpi->mi_rows; i++) {
     ptr = mi;
-    for (j = 0; j < cpi->mb_cols; j++) {
+    for (j = 0; j < cpi->mi_cols; j++) {
       ptr->mbmi.mb_in_image = 1;
       ptr++;  // Next element in the row
     }
@@ -110,10 +110,13 @@ int vp9_alloc_frame_buffers(VP9_COMMON *oci, int width, int height) {
   }
 
   oci->mb_rows = aligned_height >> 4;
+  oci->mi_rows = aligned_height >> LOG2_MI_SIZE;
   oci->mb_cols = aligned_width >> 4;
+  oci->mi_cols = aligned_width >> LOG2_MI_SIZE;
   oci->MBs = oci->mb_rows * oci->mb_cols;
-  oci->mode_info_stride = oci->mb_cols + 1;
-  oci->mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO));
+  oci->mode_info_stride = oci->mi_cols + 1;
+  oci->mip = vpx_calloc(oci->mode_info_stride * (oci->mi_rows + 1),
+                        sizeof(MODE_INFO));
 
   if (!oci->mip) {
     vp9_free_frame_buffers(oci);
@@ -124,7 +127,8 @@ int vp9_alloc_frame_buffers(VP9_COMMON *oci, int width, int height) {
 
   /* allocate memory for last frame MODE_INFO array */
 
-  oci->prev_mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO));
+  oci->prev_mip = vpx_calloc(oci->mode_info_stride * (oci->mi_rows + 1),
+                             sizeof(MODE_INFO));
 
   if (!oci->prev_mip) {
     vp9_free_frame_buffers(oci);
index 3d15624..246aae1 100644 (file)
@@ -205,39 +205,49 @@ typedef enum {
   MAX_REF_FRAMES = 4
 } MV_REFERENCE_FRAME;
 
-static INLINE int mb_width_log2(BLOCK_SIZE_TYPE sb_type) {
+static INLINE int mi_width_log2(BLOCK_SIZE_TYPE sb_type) {
   switch (sb_type) {
+#if CONFIG_SB8X8
+    case BLOCK_SIZE_SB8X16:
+    case BLOCK_SIZE_SB8X8: return 0;
+    case BLOCK_SIZE_SB16X8:
+#endif
     case BLOCK_SIZE_MB16X16:
-    case BLOCK_SIZE_SB16X32: return 0;
+    case BLOCK_SIZE_SB16X32: return 0 + CONFIG_SB8X8;
     case BLOCK_SIZE_SB32X16:
     case BLOCK_SIZE_SB32X64:
-    case BLOCK_SIZE_SB32X32: return 1;
+    case BLOCK_SIZE_SB32X32: return 1 + CONFIG_SB8X8;
     case BLOCK_SIZE_SB64X32:
-    case BLOCK_SIZE_SB64X64: return 2;
+    case BLOCK_SIZE_SB64X64: return 2 + CONFIG_SB8X8;
     default: assert(0);
   }
 }
 
-static INLINE int mb_height_log2(BLOCK_SIZE_TYPE sb_type) {
+static INLINE int mi_height_log2(BLOCK_SIZE_TYPE sb_type) {
   switch (sb_type) {
+#if CONFIG_SB8X8
+    case BLOCK_SIZE_SB16X8:
+    case BLOCK_SIZE_SB8X8: return 0;
+    case BLOCK_SIZE_SB8X16:
+#endif
     case BLOCK_SIZE_MB16X16:
-    case BLOCK_SIZE_SB32X16: return 0;
+    case BLOCK_SIZE_SB32X16: return 0 + CONFIG_SB8X8;
     case BLOCK_SIZE_SB16X32:
     case BLOCK_SIZE_SB64X32:
-    case BLOCK_SIZE_SB32X32: return 1;
+    case BLOCK_SIZE_SB32X32: return 1 + CONFIG_SB8X8;
     case BLOCK_SIZE_SB32X64:
-    case BLOCK_SIZE_SB64X64: return 2;
+    case BLOCK_SIZE_SB64X64: return 2 + CONFIG_SB8X8;
     default: assert(0);
   }
 }
 
 // parse block dimension in the unit of 4x4 blocks
 static INLINE int b_width_log2(BLOCK_SIZE_TYPE sb_type) {
-  return mb_width_log2(sb_type) + 2;
+  return mi_width_log2(sb_type) + 2 - CONFIG_SB8X8;
 }
 
 static INLINE int b_height_log2(BLOCK_SIZE_TYPE sb_type) {
-  return mb_height_log2(sb_type) + 2;
+  return mi_height_log2(sb_type) + 2 - CONFIG_SB8X8;
 }
 
 typedef struct {
@@ -426,10 +436,10 @@ typedef struct macroblockd {
 static INLINE void update_partition_context(MACROBLOCKD *xd,
                                             BLOCK_SIZE_TYPE sb_type,
                                             BLOCK_SIZE_TYPE sb_size) {
-  int bsl = mb_width_log2(sb_size), bs = 1 << bsl;
-  int bwl = mb_width_log2(sb_type);
-  int bhl = mb_height_log2(sb_type);
-  int boffset = mb_width_log2(BLOCK_SIZE_SB64X64) - bsl;
+  int bsl = mi_width_log2(sb_size) - CONFIG_SB8X8, bs = 1 << bsl;
+  int bwl = mi_width_log2(sb_type) - CONFIG_SB8X8;
+  int bhl = mi_height_log2(sb_type) - CONFIG_SB8X8;
+  int boffset = mi_width_log2(BLOCK_SIZE_SB64X64) - CONFIG_SB8X8 - bsl;
   int i;
   // skip macroblock partition
   if (bsl == 0)
@@ -465,11 +475,11 @@ static INLINE void update_partition_context(MACROBLOCKD *xd,
 
 static INLINE int partition_plane_context(MACROBLOCKD *xd,
                                           BLOCK_SIZE_TYPE sb_type) {
-  int bsl = mb_width_log2(sb_type), bs = 1 << bsl;
+  int bsl = mi_width_log2(sb_type) - CONFIG_SB8X8, bs = 1 << bsl;
   int above = 0, left = 0, i;
-  int boffset = mb_width_log2(BLOCK_SIZE_SB64X64) - bsl;
+  int boffset = mi_width_log2(BLOCK_SIZE_SB64X64) - bsl - CONFIG_SB8X8;
 
-  assert(mb_width_log2(sb_type) == mb_height_log2(sb_type));
+  assert(mi_width_log2(sb_type) == mi_height_log2(sb_type));
   assert(bsl >= 0);
   assert(boffset >= 0);
 
index 07b07a7..06641dc 100644 (file)
@@ -119,7 +119,8 @@ void vp9_adapt_coef_probs(struct VP9Common *);
 static INLINE void vp9_reset_sb_tokens_context(MACROBLOCKD* const xd,
                                                BLOCK_SIZE_TYPE bsize) {
   /* Clear entropy contexts */
-  const int bw = 1 << mb_width_log2(bsize), bh = 1 << mb_height_log2(bsize);
+  const int bw = 1 << (b_width_log2(bsize) - 2);
+  const int bh = 1 << (b_height_log2(bsize) - 2);
   vpx_memset(xd->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES) * bw);
   vpx_memset(xd->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES) * bh);
 }
index fbf4bdf..8d5577f 100644 (file)
@@ -683,7 +683,7 @@ void vp9_setup_past_independence(VP9_COMMON *cm, MACROBLOCKD *xd) {
   vp9_clearall_segfeatures(xd);
   xd->mb_segment_abs_delta = SEGMENT_DELTADATA;
   if (cm->last_frame_seg_map)
-    vpx_memset(cm->last_frame_seg_map, 0, (cm->mb_rows * cm->mb_cols));
+    vpx_memset(cm->last_frame_seg_map, 0, (cm->mi_rows * cm->mi_cols));
 
   // Reset the mode ref deltas for loop filter
   vpx_memset(xd->last_ref_lf_deltas, 0, sizeof(xd->last_ref_lf_deltas));
@@ -705,9 +705,9 @@ void vp9_setup_past_independence(VP9_COMMON *cm, MACROBLOCKD *xd) {
     vpx_memcpy(&cm->frame_contexts[i], &cm->fc, sizeof(cm->fc));
 
   vpx_memset(cm->prev_mip, 0,
-             cm->mode_info_stride * (cm->mb_rows + 1)* sizeof(MODE_INFO));
+             cm->mode_info_stride * (cm->mi_rows + 1) * sizeof(MODE_INFO));
   vpx_memset(cm->mip, 0,
-             cm->mode_info_stride * (cm->mb_rows + 1)* sizeof(MODE_INFO));
+             cm->mode_info_stride * (cm->mi_rows + 1) * sizeof(MODE_INFO));
 
   vp9_update_mode_info_border(cm, cm->mip);
   vp9_update_mode_info_in_image(cm, cm->mi);
index 23ed3e1..fddbb55 100644 (file)
 
 #include "./vpx_config.h"
 
+#if CONFIG_SB8X8
+#define LOG2_MI_SIZE 3
+#else
+#define LOG2_MI_SIZE 4
+#endif
+
+#define MI_SIZE (1 << LOG2_MI_SIZE)
+#define MI_UV_SIZE (1 << (LOG2_MI_SIZE - 1))
+
 typedef enum BLOCK_SIZE_TYPE {
 #if CONFIG_SB8X8
   BLOCK_SIZE_SB8X8,
index 0bb7968..ed0c354 100644 (file)
@@ -304,7 +304,7 @@ static void lpf_sb32(VP9_COMMON *cm, const MODE_INFO *mode_info_context,
       y_only? 0 : v_ptr,
       y_stride, uv_stride, dering);
   // process 2nd MB top-right
-  mi = mode_info_context + 1;
+  mi = mode_info_context + (1 << CONFIG_SB8X8);
   do_left_v = !(wbl >= 3 /* 32x16 or >=32x32 */ && (tx_size >= TX_32X32 ||
       sb_mb_lf_skip(mode_info_context, mi)));
   do_above_h = (mb_row > 0);
@@ -320,7 +320,7 @@ static void lpf_sb32(VP9_COMMON *cm, const MODE_INFO *mode_info_context,
       y_stride, uv_stride, dering);
 
   // process 3rd MB bottom-left
-  mi = mode_info_context + mis;
+  mi = mode_info_context + (mis << CONFIG_SB8X8);
   do_left_v = (mb_col > 0);
   do_above_h = !(hbl >= 3 /* 16x32 or >=32x32 */ && (tx_size >= TX_32X32 ||
       sb_mb_lf_skip(mode_info_context, mi)));
@@ -336,15 +336,15 @@ static void lpf_sb32(VP9_COMMON *cm, const MODE_INFO *mode_info_context,
       y_stride, uv_stride, dering);
 
   // process 4th MB bottom right
-  mi = mode_info_context + mis + 1;
+  mi = mode_info_context + ((mis + 1) << CONFIG_SB8X8);
   do_left_v = !(wbl >= 3 /* 32x16 or >=32x32 */ && (tx_size >= TX_32X32 ||
-      sb_mb_lf_skip(mi - 1, mi)));
+      sb_mb_lf_skip(mi - (1 << CONFIG_SB8X8), mi)));
   do_above_h = !(hbl >= 3 /* 16x32 or >=32x32 */ && (tx_size >= TX_32X32 ||
-      sb_mb_lf_skip(mode_info_context + 1, mi)));
+      sb_mb_lf_skip(mode_info_context + (1 << CONFIG_SB8X8), mi)));
   do_left_v_mbuv = (wbl >= 3 /* 32x16 or >=32x32 */ && (tx_size >= TX_16X16 ||
-      sb_mb_lf_skip(mi - 1, mi)));
+      sb_mb_lf_skip(mi - (1 << CONFIG_SB8X8), mi)));
   do_above_h_mbuv = !(hbl >= 3 /* 16x32 or >=32x32 */ && (tx_size >= TX_16X16 ||
-      sb_mb_lf_skip(mode_info_context + 1, mi)));
+      sb_mb_lf_skip(mode_info_context + (1 << CONFIG_SB8X8), mi)));
   lpf_mb(cm, mi, do_left_v, do_above_h,
       do_left_v_mbuv, do_above_h_mbuv,
       y_ptr + 16 * y_stride + 16,
@@ -361,16 +361,17 @@ static void lpf_sb64(VP9_COMMON *cm, const MODE_INFO *mode_info_context,
   lpf_sb32(cm, mode_info_context, mb_row, mb_col,
       y_ptr, u_ptr, v_ptr,
       y_stride, uv_stride, y_only, dering);
-  lpf_sb32(cm, mode_info_context + 2, mb_row, mb_col + 2,
+  lpf_sb32(cm, mode_info_context + (2 << CONFIG_SB8X8), mb_row, mb_col + 2,
       y_ptr + 32, u_ptr + 16, v_ptr + 16,
       y_stride, uv_stride, y_only, dering);
-  lpf_sb32(cm, mode_info_context + cm->mode_info_stride * 2,
+  lpf_sb32(cm, mode_info_context + cm->mode_info_stride * (2 << CONFIG_SB8X8),
       mb_row + 2, mb_col,
       y_ptr + 32 * y_stride,
       u_ptr + 16 * uv_stride,
       v_ptr + 16 * uv_stride,
       y_stride, uv_stride, y_only, dering);
-  lpf_sb32(cm, mode_info_context + cm->mode_info_stride * 2 + 2,
+  lpf_sb32(cm, mode_info_context + cm->mode_info_stride *
+      (2 << CONFIG_SB8X8) + (2 << CONFIG_SB8X8),
       mb_row + 2, mb_col + 2,
       y_ptr + 32 * y_stride + 32,
       u_ptr + 16 * uv_stride + 16,
@@ -440,14 +441,14 @@ void vp9_loop_filter_frame(VP9_COMMON *cm,
       y_ptr += 64;
       u_ptr = y_only? 0 : u_ptr + 32;
       v_ptr = y_only? 0 : v_ptr + 32;
-      mode_info_context += 4;       // step to next SB64
+      mode_info_context += 4 << CONFIG_SB8X8;       // step to next SB64
     }
     if (extra_sb32_col) {
       // process 2 SB32s in the extra SB32 col
       lpf_sb32(cm, mode_info_context, mb_row, mb_col,
                y_ptr, u_ptr, v_ptr,
                y_stride, uv_stride, y_only, dering);
-      lpf_sb32(cm, mode_info_context + mis * 2,
+      lpf_sb32(cm, mode_info_context + mis * (2 << CONFIG_SB8X8),
                mb_row + 2, mb_col,
                y_ptr + 32 * y_stride,
                u_ptr + 16 * uv_stride,
@@ -456,7 +457,7 @@ void vp9_loop_filter_frame(VP9_COMMON *cm,
       y_ptr += 32;
       u_ptr = y_only? 0 : u_ptr + 16;
       v_ptr = y_only? 0 : v_ptr + 16;
-      mode_info_context += 2;       // step to next SB32
+      mode_info_context += 2 << CONFIG_SB8X8;       // step to next SB32
       mb_col += 2;
     }
     if (extra_mb_col) {
@@ -474,7 +475,7 @@ void vp9_loop_filter_frame(VP9_COMMON *cm,
              y_only? 0 : v_ptr,
              y_stride, uv_stride, dering);
       // process 2nd MB
-      mi = mode_info_context + mis;
+      mi = mode_info_context + (mis << CONFIG_SB8X8);
       do_left_v = (mb_col > 0);
       do_above_h = 1;
       do_left_v_mbuv =  1;
@@ -486,7 +487,7 @@ void vp9_loop_filter_frame(VP9_COMMON *cm,
              y_only ? 0 : (v_ptr + 8 * uv_stride),
              y_stride, uv_stride, dering);
       // process 3nd MB
-      mi = mode_info_context + mis * 2;
+      mi = mode_info_context + (mis << CONFIG_SB8X8) * 2;
       do_left_v = (mb_col > 0);
       do_above_h = 1;
       do_left_v_mbuv =  1;
@@ -498,7 +499,7 @@ void vp9_loop_filter_frame(VP9_COMMON *cm,
              y_only ? 0 : (v_ptr + 16 * uv_stride),
              y_stride, uv_stride, dering);
       // process 4th MB
-      mi = mode_info_context + mis * 3;
+      mi = mode_info_context + (mis << CONFIG_SB8X8) * 3;
       do_left_v = (mb_col > 0);
       do_above_h = 1;
       do_left_v_mbuv =  1;
@@ -512,7 +513,7 @@ void vp9_loop_filter_frame(VP9_COMMON *cm,
       y_ptr += 16;
       u_ptr = y_only? 0 : u_ptr + 8;
       v_ptr = y_only? 0 : v_ptr + 8;
-      mode_info_context++;       // step to next MB
+      mode_info_context += 1 << CONFIG_SB8X8;       // step to next MB
     }
     // move pointers to the begining of next sb64 row
     y_ptr += y_stride  * 64 - post->y_width;
@@ -521,7 +522,7 @@ void vp9_loop_filter_frame(VP9_COMMON *cm,
       v_ptr += uv_stride *  32 - post->uv_width;
     }
     /* skip to next SB64 row */
-    mode_info_context += mis * 4 - cm->mb_cols;
+    mode_info_context += mis * (4 << CONFIG_SB8X8) - cm->mi_cols;
   }
   if (extra_sb32_row) {
     const int sb32_cols = sb64_cols * 2 + extra_sb32_col;
@@ -532,7 +533,7 @@ void vp9_loop_filter_frame(VP9_COMMON *cm,
       y_ptr += 32;
       u_ptr = y_only? 0 : u_ptr + 16;
       v_ptr = y_only? 0 : v_ptr + 16;
-      mode_info_context += 2;       // step to next SB32
+      mode_info_context += 2 << CONFIG_SB8X8;       // step to next SB32
     }
     if (extra_mb_col) {
       // process 1st MB
@@ -548,7 +549,7 @@ void vp9_loop_filter_frame(VP9_COMMON *cm,
              y_only? NULL : v_ptr,
              y_stride, uv_stride, dering);
       // process 2nd MB
-      mi = mode_info_context + mis;
+      mi = mode_info_context + (mis << CONFIG_SB8X8);
       do_left_v = (mb_col > 0);
       do_above_h = 1;
       do_left_v_mbuv =  1;
@@ -562,14 +563,14 @@ void vp9_loop_filter_frame(VP9_COMMON *cm,
       y_ptr += 16;
       u_ptr = y_only? 0 : u_ptr + 8;
       v_ptr = y_only? 0 : v_ptr + 8;
-      mode_info_context++;       /* step to next MB */
+      mode_info_context += 1 << CONFIG_SB8X8;       /* step to next MB */
     }
     // move pointers to the beginning of next sb64 row
     y_ptr += y_stride * 32 - post->y_width;
     u_ptr += y_only? 0 : uv_stride *  16 - post->uv_width;
     v_ptr += y_only? 0 : uv_stride *  16 - post->uv_width;
     // skip to next MB row if exist
-    mode_info_context += mis * 2 - cm->mb_cols;
+    mode_info_context += mis * (2 << CONFIG_SB8X8) - cm->mi_cols;
     mb_row += 2;
   }
   if (extra_mb_row) {
@@ -588,7 +589,7 @@ void vp9_loop_filter_frame(VP9_COMMON *cm,
       y_ptr += 16;
       u_ptr = y_only? 0 : u_ptr + 8;
       v_ptr = y_only? 0 : v_ptr + 8;
-      mode_info_context++;     // step to next MB
+      mode_info_context += 1 << CONFIG_SB8X8;     // step to next MB
     }
   }
 }
index fa4158f..b6ccb8b 100644 (file)
 
 #define MVREF_NEIGHBOURS 8
 
+#if CONFIG_SB8X8
 static int mb_mv_ref_search[MVREF_NEIGHBOURS][2] = {
-    {0, -1}, {-1, 0}, {-1, -1}, {0, -2},
-    {-2, 0}, {-1, -2}, {-2, -1}, {-2, -2}
+    {0, -1}, {-1, 0}, {-1, -1}, {0, -3},
+    {-3, 0}, {-1, -3}, {-3, -1}, {-3, -3}
 };
 
 static int sb_mv_ref_search[MVREF_NEIGHBOURS][2] = {
-    {0, -1}, {-1, 0}, {1, -1}, {-1, 1},
-    {-1, -1}, {0, -2}, {-2, 0}, {-1, -2}
+    {0, -1}, {-1, 0}, {2, -1}, {-1, 2},
+    {-1, -1}, {0, -3}, {-3, 0}, {-1, -3}
 };
 
 static int sb64_mv_ref_search[MVREF_NEIGHBOURS][2] = {
-    {0, -1}, {-1, 0}, {1, -1}, {-1, 1},
-    {2, -1}, {-1, 2}, {3, -1}, {-1,-1}
+    {0, -1}, {-1, 0}, {2, -1}, {-1,  2},
+    {4, -1}, {-1, 4}, {6, -1}, {-1, -1}
+};
+#else
+static int mb_mv_ref_search[MVREF_NEIGHBOURS][2] = {
+  {0, -1}, {-1, 0}, {-1, -1}, {0, -2},
+  {-2, 0}, {-1, -2}, {-2, -1}, {-2, -2}
 };
 
+static int sb_mv_ref_search[MVREF_NEIGHBOURS][2] = {
+  {0, -1}, {-1, 0}, {1, -1}, {-1, 1},
+  {-1, -1}, {0, -2}, {-2, 0}, {-1, -2}
+};
+
+static int sb64_mv_ref_search[MVREF_NEIGHBOURS][2] = {
+  {0, -1}, {-1, 0}, {1, -1}, {-1,  1},
+  {2, -1}, {-1, 2}, {3, -1}, {-1, -1}
+};
+#endif
 
 // clamp_mv_ref
 #define MV_BORDER (16 << 3) // Allow 16 pels in 1/8th pel units
@@ -160,7 +176,7 @@ void vp9_find_mv_refs(VP9_COMMON *cm, MACROBLOCKD *xd, MODE_INFO *here,
   int refmv_count = 0;
   int split_count = 0;
   int (*mv_ref_search)[2];
-  const int mb_col = (-xd->mb_to_left_edge) >> 7;
+  const int mi_col = get_mi_col(xd);
   // Blank the reference vector lists and other local structures.
   vpx_memset(mv_ref_list, 0, sizeof(int_mv) * MAX_MV_REF_CANDIDATES);
   vpx_memset(candidate_scores, 0, sizeof(candidate_scores));
@@ -176,11 +192,11 @@ void vp9_find_mv_refs(VP9_COMMON *cm, MACROBLOCKD *xd, MODE_INFO *here,
   // We first scan for candidate vectors that match the current reference frame
   // Look at nearest neigbours
   for (i = 0; i < 2; ++i) {
-    const int mb_search_col = mb_col + mv_ref_search[i][0];
+    const int mi_search_col = mi_col + mv_ref_search[i][0];
 
-    if ((mb_search_col >= cm->cur_tile_mb_col_start) &&
-        (mb_search_col < cm->cur_tile_mb_col_end) &&
-        ((mv_ref_search[i][1] << 7) >= xd->mb_to_top_edge)) {
+    if ((mi_search_col >= cm->cur_tile_mi_col_start) &&
+        (mi_search_col < cm->cur_tile_mi_col_end) &&
+        ((mv_ref_search[i][1] << (7 - CONFIG_SB8X8)) >= xd->mb_to_top_edge)) {
 
       candidate_mi = here + mv_ref_search[i][0] +
                      (mv_ref_search[i][1] * xd->mode_info_stride);
@@ -196,11 +212,11 @@ void vp9_find_mv_refs(VP9_COMMON *cm, MACROBLOCKD *xd, MODE_INFO *here,
   // More distant neigbours
   for (i = 2; (i < MVREF_NEIGHBOURS) &&
               (refmv_count < MAX_MV_REF_CANDIDATES); ++i) {
-    const int mb_search_col = mb_col + mv_ref_search[i][0];
+    const int mi_search_col = mi_col + mv_ref_search[i][0];
 
-    if ((mb_search_col >= cm->cur_tile_mb_col_start) &&
-        (mb_search_col < cm->cur_tile_mb_col_end) &&
-        ((mv_ref_search[i][1] << 7) >= xd->mb_to_top_edge)) {
+    if ((mi_search_col >= cm->cur_tile_mi_col_start) &&
+        (mi_search_col < cm->cur_tile_mi_col_end) &&
+        ((mv_ref_search[i][1] << (7 - CONFIG_SB8X8)) >= xd->mb_to_top_edge)) {
       candidate_mi = here + mv_ref_search[i][0] +
                      (mv_ref_search[i][1] * xd->mode_info_stride);
 
@@ -226,11 +242,11 @@ void vp9_find_mv_refs(VP9_COMMON *cm, MACROBLOCKD *xd, MODE_INFO *here,
   // Look first at spatial neighbours
   for (i = 0; (i < MVREF_NEIGHBOURS) &&
               (refmv_count < MAX_MV_REF_CANDIDATES); ++i) {
-    const int mb_search_col = mb_col + mv_ref_search[i][0];
+    const int mi_search_col = mi_col + mv_ref_search[i][0];
 
-    if ((mb_search_col >= cm->cur_tile_mb_col_start) &&
-        (mb_search_col < cm->cur_tile_mb_col_end) &&
-        ((mv_ref_search[i][1] << 7) >= xd->mb_to_top_edge)) {
+    if ((mi_search_col >= cm->cur_tile_mi_col_start) &&
+        (mi_search_col < cm->cur_tile_mi_col_end) &&
+        ((mv_ref_search[i][1] << (7 - CONFIG_SB8X8)) >= xd->mb_to_top_edge)) {
       candidate_mi = here + mv_ref_search[i][0] +
                      (mv_ref_search[i][1] * xd->mode_info_stride);
 
index 839d5a8..aa59053 100644 (file)
@@ -201,9 +201,12 @@ typedef struct VP9Common {
   int last_show_frame;
 
   int frame_flags;
+  // MBs, mb_rows/cols is in 16-pixel units; mi_rows/cols is in
+  // MODE_INFO units (depending on CONFIG_SB8X8, that is either
+  // 16-pixel or 8-pixel)
   int MBs;
-  int mb_rows;
-  int mb_cols;
+  int mb_rows, mi_rows;
+  int mb_cols, mi_cols;
   int mode_info_stride;
 
   /* profile settings */
@@ -314,9 +317,9 @@ typedef struct VP9Common {
   int frame_parallel_decoding_mode;
 
   int tile_columns, log2_tile_columns;
-  int cur_tile_mb_col_start, cur_tile_mb_col_end, cur_tile_col_idx;
+  int cur_tile_mi_col_start, cur_tile_mi_col_end, cur_tile_col_idx;
   int tile_rows, log2_tile_rows;
-  int cur_tile_mb_row_start, cur_tile_mb_row_end, cur_tile_row_idx;
+  int cur_tile_mi_row_start, cur_tile_mi_row_end, cur_tile_row_idx;
 } VP9_COMMON;
 
 static int get_free_fb(VP9_COMMON *cm) {
@@ -343,26 +346,26 @@ static int mb_cols_aligned_to_sb(VP9_COMMON *cm) {
   return (cm->mb_cols + 3) & ~3;
 }
 
-static void set_mb_row_col(VP9_COMMON *cm, MACROBLOCKD *xd,
-                       int mb_row, int bh,
-                       int mb_col, int bw) {
-  xd->mb_to_top_edge    = -((mb_row * 16) << 3);
-  xd->mb_to_bottom_edge = ((cm->mb_rows - bh - mb_row) * 16) << 3;
-  xd->mb_to_left_edge   = -((mb_col * 16) << 3);
-  xd->mb_to_right_edge  = ((cm->mb_cols - bw - mb_col) * 16) << 3;
+static void set_mi_row_col(VP9_COMMON *cm, MACROBLOCKD *xd,
+                       int mi_row, int bh,
+                       int mi_col, int bw) {
+  xd->mb_to_top_edge    = -((mi_row * MI_SIZE) << 3);
+  xd->mb_to_bottom_edge = ((cm->mi_rows - bh - mi_row) * MI_SIZE) << 3;
+  xd->mb_to_left_edge   = -((mi_col * MI_SIZE) << 3);
+  xd->mb_to_right_edge  = ((cm->mi_cols - bw - mi_col) * MI_SIZE) << 3;
 
   // Are edges available for intra prediction?
-  xd->up_available    = (mb_row != 0);
-  xd->left_available  = (mb_col > cm->cur_tile_mb_col_start);
-  xd->right_available = (mb_col + bw < cm->cur_tile_mb_col_end);
+  xd->up_available    = (mi_row != 0);
+  xd->left_available  = (mi_col > cm->cur_tile_mi_col_start);
+  xd->right_available = (mi_col + bw < cm->cur_tile_mi_col_end);
 }
 
-static int get_mb_row(const MACROBLOCKD *xd) {
-  return ((-xd->mb_to_top_edge) >> 7);
+static int get_mi_row(const MACROBLOCKD *xd) {
+  return ((-xd->mb_to_top_edge) >> (3 + LOG2_MI_SIZE));
 }
 
-static int get_mb_col(const MACROBLOCKD *xd) {
-  return ((-xd->mb_to_left_edge) >> 7);
+static int get_mi_col(const MACROBLOCKD *xd) {
+  return ((-xd->mb_to_left_edge) >> (3 + LOG2_MI_SIZE));
 }
 
 static int get_token_alloc(int mb_rows, int mb_cols) {
index 882b56f..459e9d5 100644 (file)
@@ -169,35 +169,34 @@ void vp9_set_pred_flag(MACROBLOCKD *const xd,
                        unsigned char pred_flag) {
   const int mis = xd->mode_info_stride;
   BLOCK_SIZE_TYPE bsize = xd->mode_info_context->mbmi.sb_type;
-  const int bh = 1 << mb_height_log2(bsize);
-  const int bw = 1 << mb_width_log2(bsize);
+  const int bh = 1 << mi_height_log2(bsize);
+  const int bw = 1 << mi_width_log2(bsize);
 #define sub(a, b) (b) < 0 ? (a) + (b) : (a)
-  const int x_mbs = sub(bw, xd->mb_to_right_edge >> 7);
-  const int y_mbs = sub(bh, xd->mb_to_bottom_edge >> 7);
+  const int x_mis = sub(bw, xd->mb_to_right_edge >> (3 + LOG2_MI_SIZE));
+  const int y_mis = sub(bh, xd->mb_to_bottom_edge >> (3 + LOG2_MI_SIZE));
 #undef sub
   int x, y;
 
   switch (pred_id) {
     case PRED_SEG_ID:
-      for (y = 0; y < y_mbs; y++) {
-        for (x = 0; x < x_mbs; x++) {
-          xd->mode_info_context[y * mis + x].mbmi.seg_id_predicted =
-              pred_flag;
+      for (y = 0; y < y_mis; y++) {
+        for (x = 0; x < x_mis; x++) {
+          xd->mode_info_context[y * mis + x].mbmi.seg_id_predicted = pred_flag;
         }
       }
       break;
 
     case PRED_REF:
-      for (y = 0; y < y_mbs; y++) {
-        for (x = 0; x < x_mbs; x++) {
+      for (y = 0; y < y_mis; y++) {
+        for (x = 0; x < x_mis; x++) {
           xd->mode_info_context[y * mis + x].mbmi.ref_predicted = pred_flag;
         }
       }
       break;
 
     case PRED_MBSKIP:
-      for (y = 0; y < y_mbs; y++) {
-        for (x = 0; x < x_mbs; x++) {
+      for (y = 0; y < y_mis; y++) {
+        for (x = 0; x < x_mis; x++) {
           xd->mode_info_context[y * mis + x].mbmi.mb_skip_coeff = pred_flag;
         }
       }
@@ -214,27 +213,23 @@ void vp9_set_pred_flag(MACROBLOCKD *const xd,
 // peredict various bitstream signals.
 
 // Macroblock segment id prediction function
-int vp9_get_pred_mb_segid(VP9_COMMON *cm, BLOCK_SIZE_TYPE sb_type,
-                          int mb_row, int mb_col) {
-  const int mb_index = mb_row * cm->mb_cols + mb_col;
-  if (sb_type > BLOCK_SIZE_MB16X16) {
-    const int bw = 1 << mb_width_log2(sb_type);
-    const int bh = 1 << mb_height_log2(sb_type);
-    const int ymbs = MIN(cm->mb_rows - mb_row, bh);
-    const int xmbs = MIN(cm->mb_cols - mb_col, bw);
-    int segment_id = INT_MAX;
-    int x, y;
-
-    for (y = 0; y < ymbs; y++) {
-      for (x = 0; x < xmbs; x++) {
-        const int index = mb_index + (y * cm->mb_cols + x);
-        segment_id = MIN(segment_id, cm->last_frame_seg_map[index]);
-      }
+int vp9_get_pred_mi_segid(VP9_COMMON *cm, BLOCK_SIZE_TYPE sb_type,
+                          int mi_row, int mi_col) {
+  const int mi_index = mi_row * cm->mi_cols + mi_col;
+  const int bw = 1 << mi_width_log2(sb_type);
+  const int bh = 1 << mi_height_log2(sb_type);
+  const int ymis = MIN(cm->mi_rows - mi_row, bh);
+  const int xmis = MIN(cm->mi_cols - mi_col, bw);
+  int segment_id = INT_MAX;
+  int x, y;
+
+  for (y = 0; y < ymis; y++) {
+    for (x = 0; x < xmis; x++) {
+      const int index = mi_index + (y * cm->mi_cols + x);
+      segment_id = MIN(segment_id, cm->last_frame_seg_map[index]);
     }
-    return segment_id;
-  } else {
-    return cm->last_frame_seg_map[mb_index];
   }
+  return segment_id;
 }
 
 MV_REFERENCE_FRAME vp9_get_pred_ref(const VP9_COMMON *const cm,
index 222d5f3..afb0bfe 100644 (file)
@@ -43,8 +43,8 @@ void vp9_set_pred_flag(MACROBLOCKD *const xd,
                        unsigned char pred_flag);
 
 
-int vp9_get_pred_mb_segid(VP9_COMMON *cm, BLOCK_SIZE_TYPE sb_type,
-                          int mb_row, int mb_col);
+int vp9_get_pred_mi_segid(VP9_COMMON *cm, BLOCK_SIZE_TYPE sb_type,
+                          int mi_row, int mi_col);
 
 MV_REFERENCE_FRAME vp9_get_pred_ref(const VP9_COMMON *const cm,
                                     const MACROBLOCKD *const xd);
index 483db07..6efe246 100644 (file)
@@ -387,11 +387,11 @@ static void build_inter_predictors(int plane, int block,
   }
 }
 void vp9_build_inter_predictors_sby(MACROBLOCKD *xd,
-                                    int mb_row,
-                                    int mb_col,
+                                    int mi_row,
+                                    int mi_col,
                                     BLOCK_SIZE_TYPE bsize) {
   struct build_inter_predictors_args args = {
-    xd, mb_col * 16, mb_row * 16,
+    xd, mi_col * MI_SIZE, mi_row * MI_SIZE,
     {xd->plane[0].dst.buf, NULL, NULL}, {xd->plane[0].dst.stride, 0, 0},
     {{xd->plane[0].pre[0].buf, NULL, NULL},
      {xd->plane[0].pre[1].buf, NULL, NULL}},
@@ -401,11 +401,11 @@ void vp9_build_inter_predictors_sby(MACROBLOCKD *xd,
   foreach_predicted_block_in_plane(xd, bsize, 0, build_inter_predictors, &args);
 }
 void vp9_build_inter_predictors_sbuv(MACROBLOCKD *xd,
-                                     int mb_row,
-                                     int mb_col,
+                                     int mi_row,
+                                     int mi_col,
                                      BLOCK_SIZE_TYPE bsize) {
   struct build_inter_predictors_args args = {
-    xd, mb_col * 16, mb_row * 16,
+    xd, mi_col * MI_SIZE, mi_row * MI_SIZE,
     {NULL, xd->plane[1].dst.buf, xd->plane[2].dst.buf},
     {0, xd->plane[1].dst.stride, xd->plane[1].dst.stride},
     {{NULL, xd->plane[1].pre[0].buf, xd->plane[2].pre[0].buf},
@@ -416,7 +416,7 @@ void vp9_build_inter_predictors_sbuv(MACROBLOCKD *xd,
   foreach_predicted_block_uv(xd, bsize, build_inter_predictors, &args);
 }
 void vp9_build_inter_predictors_sb(MACROBLOCKD *xd,
-                                   int mb_row, int mb_col,
+                                   int mi_row, int mi_col,
                                    BLOCK_SIZE_TYPE bsize) {
 #if CONFIG_COMP_INTERINTRA_PRED
   uint8_t *const y = xd->plane[0].dst.buf;
@@ -426,8 +426,8 @@ void vp9_build_inter_predictors_sb(MACROBLOCKD *xd,
   const int uv_stride = xd->plane[1].dst.stride;
 #endif
 
-  vp9_build_inter_predictors_sby(xd, mb_row, mb_col, bsize);
-  vp9_build_inter_predictors_sbuv(xd, mb_row, mb_col, bsize);
+  vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize);
+  vp9_build_inter_predictors_sbuv(xd, mi_row, mi_col, bsize);
 
 #if CONFIG_COMP_INTERINTRA_PRED
   if (xd->mode_info_context->mbmi.second_ref_frame == INTRA_FRAME)
index 51b705f..d2e7455 100644 (file)
@@ -79,11 +79,11 @@ static int scaled_buffer_offset(int x_offset,
 
 static void setup_pred_plane(struct buf_2d *dst,
                              uint8_t *src, int stride,
-                             int mb_row, int mb_col,
+                             int mi_row, int mi_col,
                              const struct scale_factors *scale,
                              int subsampling_x, int subsampling_y) {
-  const int x = (16 * mb_col) >> subsampling_x;
-  const int y = (16 * mb_row) >> subsampling_y;
+  const int x = (MI_SIZE * mi_col) >> subsampling_x;
+  const int y = (MI_SIZE * mi_row) >> subsampling_y;
   dst->buf = src + scaled_buffer_offset(x, y, stride, scale);
   dst->stride = stride;
 }
@@ -91,25 +91,25 @@ static void setup_pred_plane(struct buf_2d *dst,
 // TODO(jkoleszar): audit all uses of this that don't set mb_row, mb_col
 static void setup_dst_planes(MACROBLOCKD *xd,
                              const YV12_BUFFER_CONFIG *src,
-                             int mb_row, int mb_col) {
+                             int mi_row, int mi_col) {
   setup_pred_plane(&xd->plane[0].dst,
                    src->y_buffer, src->y_stride,
-                   mb_row, mb_col, NULL,
+                   mi_row, mi_col, NULL,
                    xd->plane[0].subsampling_x, xd->plane[0].subsampling_y);
   setup_pred_plane(&xd->plane[1].dst,
                    src->u_buffer, src->uv_stride,
-                   mb_row, mb_col, NULL,
+                   mi_row, mi_col, NULL,
                    xd->plane[1].subsampling_x, xd->plane[1].subsampling_y);
   setup_pred_plane(&xd->plane[2].dst,
                    src->v_buffer, src->uv_stride,
-                   mb_row, mb_col, NULL,
+                   mi_row, mi_col, NULL,
                    xd->plane[2].subsampling_x, xd->plane[2].subsampling_y);
 }
 
 static void setup_pre_planes(MACROBLOCKD *xd,
                              const YV12_BUFFER_CONFIG *src0,
                              const YV12_BUFFER_CONFIG *src1,
-                             int mb_row, int mb_col,
+                             int mi_row, int mi_col,
                              const struct scale_factors *scale,
                              const struct scale_factors *scale_uv) {
   int i;
@@ -122,22 +122,22 @@ static void setup_pre_planes(MACROBLOCKD *xd,
 
     setup_pred_plane(&xd->plane[0].pre[i],
                      src->y_buffer, src->y_stride,
-                     mb_row, mb_col, scale ? scale + i : NULL,
+                     mi_row, mi_col, scale ? scale + i : NULL,
                      xd->plane[0].subsampling_x, xd->plane[0].subsampling_y);
     setup_pred_plane(&xd->plane[1].pre[i],
                      src->u_buffer, src->uv_stride,
-                     mb_row, mb_col, scale_uv ? scale_uv + i : NULL,
+                     mi_row, mi_col, scale_uv ? scale_uv + i : NULL,
                      xd->plane[1].subsampling_x, xd->plane[1].subsampling_y);
     setup_pred_plane(&xd->plane[2].pre[i],
                      src->v_buffer, src->uv_stride,
-                     mb_row, mb_col, scale_uv ? scale_uv + i : NULL,
+                     mi_row, mi_col, scale_uv ? scale_uv + i : NULL,
                      xd->plane[2].subsampling_x, xd->plane[2].subsampling_y);
   }
 }
 
 static void setup_pred_block(YV12_BUFFER_CONFIG *dst,
                              const YV12_BUFFER_CONFIG *src,
-                             int mb_row, int mb_col,
+                             int mi_row, int mi_col,
                              const struct scale_factors *scale,
                              const struct scale_factors *scale_uv) {
   const int recon_y_stride = src->y_stride;
@@ -146,13 +146,15 @@ static void setup_pred_block(YV12_BUFFER_CONFIG *dst,
   int recon_uvoffset;
 
   if (scale) {
-    recon_yoffset = scaled_buffer_offset(16 * mb_col, 16 * mb_row,
+    recon_yoffset = scaled_buffer_offset(MI_SIZE * mi_col, MI_SIZE * mi_row,
                                          recon_y_stride, scale);
-    recon_uvoffset = scaled_buffer_offset(8 * mb_col, 8 * mb_row,
+    recon_uvoffset = scaled_buffer_offset(MI_UV_SIZE * mi_col,
+                                          MI_UV_SIZE * mi_row,
                                           recon_uv_stride, scale_uv);
   } else {
-    recon_yoffset = 16 * mb_row * recon_y_stride + 16 * mb_col;
-    recon_uvoffset = 8 * mb_row * recon_uv_stride + 8 * mb_col;
+    recon_yoffset = MI_SIZE * mi_row * recon_y_stride + MI_SIZE * mi_col;
+    recon_uvoffset = MI_UV_SIZE * mi_row * recon_uv_stride +
+                     MI_UV_SIZE * mi_col;
   }
 
   *dst = *src;
index a66e782..a603c7e 100644 (file)
@@ -542,8 +542,8 @@ void vp9_build_interintra_predictors_sby(MACROBLOCKD *xd,
                                                uint8_t *ypred,
                                                int ystride,
                                                BLOCK_SIZE_TYPE bsize) {
-  int bwl = mb_width_log2(bsize),  bw = 16 << bwl;
-  int bhl = mb_height_log2(bsize), bh = 16 << bhl;
+  int bwl = mi_width_log2(bsize),  bw = MI_SIZE << bwl;
+  int bhl = mi_height_log2(bsize), bh = MI_SIZE << bhl;
   uint8_t intrapredictor[4096];
   vp9_build_intra_predictors(
       xd->plane[0].dst.buf, xd->plane[0].dst.stride,
@@ -559,8 +559,8 @@ void vp9_build_interintra_predictors_sbuv(MACROBLOCKD *xd,
                                                 uint8_t *vpred,
                                                 int uvstride,
                                                 BLOCK_SIZE_TYPE bsize) {
-  int bwl = mb_width_log2(bsize),  bw = 8 << bwl;
-  int bhl = mb_height_log2(bsize), bh = 8 << bhl;
+  int bwl = mi_width_log2(bsize),  bw = MI_UV_SIZE << bwl;
+  int bhl = mi_height_log2(bsize), bh = MI_UV_SIZE << bhl;
   uint8_t uintrapredictor[1024];
   uint8_t vintrapredictor[1024];
   vp9_build_intra_predictors(
@@ -582,8 +582,8 @@ void vp9_build_interintra_predictors_sbuv(MACROBLOCKD *xd,
 
 void vp9_build_intra_predictors_sby_s(MACROBLOCKD *xd,
                                       BLOCK_SIZE_TYPE bsize) {
-  const int bwl = b_width_log2(bsize),  bw = 4 << bwl;
-  const int bhl = b_height_log2(bsize), bh = 4 << bhl;
+  const int bwl = mi_width_log2(bsize),  bw = MI_SIZE << bwl;
+  const int bhl = mi_height_log2(bsize), bh = MI_SIZE << bhl;
 
   vp9_build_intra_predictors(xd->plane[0].dst.buf, xd->plane[0].dst.stride,
                              xd->plane[0].dst.buf, xd->plane[0].dst.stride,
@@ -595,8 +595,8 @@ void vp9_build_intra_predictors_sby_s(MACROBLOCKD *xd,
 
 void vp9_build_intra_predictors_sbuv_s(MACROBLOCKD *xd,
                                        BLOCK_SIZE_TYPE bsize) {
-  const int bwl = b_width_log2(bsize)  - 1, bw = 4 << bwl;
-  const int bhl = b_height_log2(bsize) - 1, bh = 4 << bhl;
+  const int bwl = mi_width_log2(bsize), bw = MI_UV_SIZE << bwl;
+  const int bhl = mi_height_log2(bsize), bh = MI_UV_SIZE << bhl;
 
   vp9_build_intra_predictors(xd->plane[1].dst.buf, xd->plane[1].dst.stride,
                              xd->plane[1].dst.buf, xd->plane[1].dst.stride,
index b6178f2..a9d8cf0 100644 (file)
 
 static void vp9_get_tile_offsets(VP9_COMMON *cm, int *min_tile_off,
                                  int *max_tile_off, int tile_idx,
-                                 int log2_n_tiles, int n_mbs) {
-  const int n_sbs = (n_mbs + 3) >> 2;
+                                 int log2_n_tiles, int n_mis) {
+#if CONFIG_SB8X8
+  const int n_sbs = (n_mis + 7) >> 3;
+#else
+  const int n_sbs = (n_mis + 3) >> 2;
+#endif
   const int sb_off1 =  (tile_idx      * n_sbs) >> log2_n_tiles;
   const int sb_off2 = ((tile_idx + 1) * n_sbs) >> log2_n_tiles;
 
-  *min_tile_off = MIN(sb_off1 << 2, n_mbs);
-  *max_tile_off = MIN(sb_off2 << 2, n_mbs);
+  *min_tile_off = MIN(sb_off1 << (2 + CONFIG_SB8X8), n_mis);
+  *max_tile_off = MIN(sb_off2 << (2 + CONFIG_SB8X8), n_mis);
 }
 
 void vp9_get_tile_col_offsets(VP9_COMMON *cm, int tile_col_idx) {
   cm->cur_tile_col_idx = tile_col_idx;
-  vp9_get_tile_offsets(cm, &cm->cur_tile_mb_col_start,
-                       &cm->cur_tile_mb_col_end, tile_col_idx,
-                       cm->log2_tile_columns, cm->mb_cols);
+  vp9_get_tile_offsets(cm, &cm->cur_tile_mi_col_start,
+                       &cm->cur_tile_mi_col_end, tile_col_idx,
+                       cm->log2_tile_columns, cm->mi_cols);
 }
 
 void vp9_get_tile_row_offsets(VP9_COMMON *cm, int tile_row_idx) {
   cm->cur_tile_row_idx = tile_row_idx;
-  vp9_get_tile_offsets(cm, &cm->cur_tile_mb_row_start,
-                       &cm->cur_tile_mb_row_end, tile_row_idx,
-                       cm->log2_tile_rows, cm->mb_rows);
+  vp9_get_tile_offsets(cm, &cm->cur_tile_mi_row_start,
+                       &cm->cur_tile_mi_row_end, tile_row_idx,
+                       cm->log2_tile_rows, cm->mi_rows);
 }
 
 
index 246484c..fbb7dbd 100644 (file)
@@ -94,24 +94,20 @@ static int read_mb_segid(vp9_reader *r, MACROBLOCKD *xd) {
 }
 
 static void set_segment_id(VP9_COMMON *cm, MB_MODE_INFO *mbmi,
-                           int mb_row, int mb_col, int segment_id) {
-  const int mb_index = mb_row * cm->mb_cols + mb_col;
+                           int mi_row, int mi_col, int segment_id) {
+  const int mi_index = mi_row * cm->mi_cols + mi_col;
   const BLOCK_SIZE_TYPE sb_type = mbmi->sb_type;
-  if (sb_type > BLOCK_SIZE_MB16X16) {
-    const int bw = 1 << mb_width_log2(sb_type);
-    const int bh = 1 << mb_height_log2(sb_type);
-    const int ymbs = MIN(cm->mb_rows - mb_row, bh);
-    const int xmbs = MIN(cm->mb_cols - mb_col, bw);
-    int x, y;
-
-    for (y = 0; y < ymbs; y++) {
-      for (x = 0; x < xmbs; x++) {
-        const int index = mb_index + (y * cm->mb_cols + x);
-        cm->last_frame_seg_map[index] = segment_id;
-      }
+  const int bw = 1 << mi_width_log2(sb_type);
+  const int bh = 1 << mi_height_log2(sb_type);
+  const int ymis = MIN(cm->mi_rows - mi_row, bh);
+  const int xmis = MIN(cm->mi_cols - mi_col, bw);
+  int x, y;
+
+  for (y = 0; y < ymis; y++) {
+    for (x = 0; x < xmis; x++) {
+      const int index = mi_index + (y * cm->mi_cols + x);
+      cm->last_frame_seg_map[index] = segment_id;
     }
-  } else {
-    cm->last_frame_seg_map[mb_index] = segment_id;
   }
 }
 
@@ -128,7 +124,7 @@ static TX_SIZE select_txfm_size(VP9_COMMON *cm, vp9_reader *r,
 
 extern const int vp9_i8x8_block[4];
 static void kfread_modes(VP9D_COMP *pbi, MODE_INFO *m,
-                         int mb_row, int mb_col,
+                         int mi_row, int mi_col,
                          vp9_reader *r) {
   VP9_COMMON *const cm = &pbi->common;
   MACROBLOCKD *const xd = &pbi->mb;
@@ -139,7 +135,7 @@ static void kfread_modes(VP9D_COMP *pbi, MODE_INFO *m,
   m->mbmi.segment_id = 0;
   if (xd->segmentation_enabled && xd->update_mb_segmentation_map) {
     m->mbmi.segment_id = read_mb_segid(r, xd);
-    set_segment_id(cm, &m->mbmi, mb_row, mb_col, m->mbmi.segment_id);
+    set_segment_id(cm, &m->mbmi, mi_row, mi_col, m->mbmi.segment_id);
   }
 
   m->mbmi.mb_skip_coeff = vp9_segfeature_active(xd, m->mbmi.segment_id,
@@ -520,7 +516,7 @@ static void mb_mode_mv_init(VP9D_COMP *pbi, vp9_reader *r) {
 // This function either reads the segment id for the current macroblock from
 // the bitstream or if the value is temporally predicted asserts the predicted
 // value
-static int read_mb_segment_id(VP9D_COMP *pbi, int mb_row, int mb_col,
+static int read_mb_segment_id(VP9D_COMP *pbi, int mi_row, int mi_col,
                               vp9_reader *r) {
   VP9_COMMON *const cm = &pbi->common;
   MACROBLOCKD *const xd = &pbi->mb;
@@ -543,17 +539,17 @@ static int read_mb_segment_id(VP9D_COMP *pbi, int mb_row, int mb_col,
 
       // If the value is flagged as correctly predicted
       // then use the predicted value, otherwise decode it explicitly
-      segment_id = pred_flag ? vp9_get_pred_mb_segid(cm, mbmi->sb_type,
-                                                     mb_row, mb_col)
+      segment_id = pred_flag ? vp9_get_pred_mi_segid(cm, mbmi->sb_type,
+                                                     mi_row, mi_col)
                              : read_mb_segid(r, xd);
     } else {
       segment_id = read_mb_segid(r, xd);  // Normal unpredicted coding mode
     }
 
-    set_segment_id(cm, mbmi, mb_row, mb_col, segment_id);  // Side effect
+    set_segment_id(cm, mbmi, mi_row, mi_col, segment_id);  // Side effect
     return segment_id;
   } else {
-    return vp9_get_pred_mb_segid(cm, mbmi->sb_type, mb_row, mb_col);
+    return vp9_get_pred_mi_segid(cm, mbmi->sb_type, mi_row, mi_col);
   }
 }
 
@@ -589,7 +585,7 @@ static INLINE INTERPOLATIONFILTERTYPE read_switchable_filter_type(
 
 static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
                              MODE_INFO *prev_mi,
-                             int mb_row, int mb_col,
+                             int mi_row, int mi_col,
                              vp9_reader *r) {
   VP9_COMMON *const cm = &pbi->common;
   nmv_context *const nmvc = &cm->fc.nmvc;
@@ -598,8 +594,8 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
 
   int_mv *const mv0 = &mbmi->mv[0];
   int_mv *const mv1 = &mbmi->mv[1];
-  const int bw = 1 << mb_width_log2(mi->mbmi.sb_type);
-  const int bh = 1 << mb_height_log2(mi->mbmi.sb_type);
+  const int bw = 1 << mi_width_log2(mi->mbmi.sb_type);
+  const int bh = 1 << mi_height_log2(mi->mbmi.sb_type);
 
   const int use_prev_in_find_mv_refs = cm->width == cm->last_width &&
                                        cm->height == cm->last_height &&
@@ -620,7 +616,7 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
   // Distance of Mb to the various image edges.
   // These specified to 8th pel as they are always compared to MV values
   // that are in 1/8th pel units
-  set_mb_row_col(cm, xd, mb_row, bh, mb_col, bw);
+  set_mi_row_col(cm, xd, mi_row, bh, mi_col, bw);
 
   mb_to_top_edge = xd->mb_to_top_edge - LEFT_TOP_MARGIN;
   mb_to_bottom_edge = xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN;
@@ -628,7 +624,7 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
   mb_to_right_edge = xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN;
 
   // Read the macroblock segment id.
-  mbmi->segment_id = read_mb_segment_id(pbi, mb_row, mb_col, r);
+  mbmi->segment_id = read_mb_segment_id(pbi, mi_row, mi_col, r);
 
   mbmi->mb_skip_coeff = vp9_segfeature_active(xd, mbmi->segment_id,
                                               SEG_LVL_SKIP);
@@ -653,7 +649,7 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
       const int ref_fb_idx = cm->active_ref_idx[ref_frame - 1];
 
       setup_pre_planes(xd, &cm->yv12_fb[ref_fb_idx], NULL,
-                       mb_row, mb_col, xd->scale_factor, xd->scale_factor_uv);
+                       mi_row, mi_col, xd->scale_factor, xd->scale_factor_uv);
 
 #ifdef DEC_DEBUG
       if (dec_debug)
@@ -718,7 +714,7 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
         *sf1 = cm->active_ref_scale[second_ref_frame - 1];
 
         setup_pre_planes(xd, NULL, &cm->yv12_fb[second_ref_fb_idx],
-                         mb_row, mb_col, xd->scale_factor, xd->scale_factor_uv);
+                         mi_row, mi_col, xd->scale_factor, xd->scale_factor_uv);
 
         vp9_find_mv_refs(cm, xd, mi,
                          use_prev_in_find_mv_refs ? prev_mi : NULL,
@@ -1016,8 +1012,8 @@ void vp9_decode_mode_mvs_init(VP9D_COMP* const pbi, vp9_reader *r) {
 
 void vp9_decode_mb_mode_mv(VP9D_COMP* const pbi,
                            MACROBLOCKD* const xd,
-                           int mb_row,
-                           int mb_col,
+                           int mi_row,
+                           int mi_col,
                            vp9_reader *r) {
   VP9_COMMON *const cm = &pbi->common;
   MODE_INFO *mi = xd->mode_info_context;
@@ -1025,24 +1021,24 @@ void vp9_decode_mb_mode_mv(VP9D_COMP* const pbi,
   MB_MODE_INFO *const mbmi = &mi->mbmi;
 
   if (cm->frame_type == KEY_FRAME) {
-    kfread_modes(pbi, mi, mb_row, mb_col, r);
+    kfread_modes(pbi, mi, mi_row, mi_col, r);
   } else {
-    read_mb_modes_mv(pbi, mi, &mi->mbmi, prev_mi, mb_row, mb_col, r);
+    read_mb_modes_mv(pbi, mi, &mi->mbmi, prev_mi, mi_row, mi_col, r);
     set_scale_factors(xd,
                       mi->mbmi.ref_frame - 1, mi->mbmi.second_ref_frame - 1,
                       cm->active_ref_scale);
   }
 
-  if (mbmi->sb_type > BLOCK_SIZE_MB16X16) {
-    const int bw = 1 << mb_width_log2(mbmi->sb_type);
-    const int bh = 1 << mb_height_log2(mbmi->sb_type);
-    const int y_mbs = MIN(bh, cm->mb_rows - mb_row);
-    const int x_mbs = MIN(bw, cm->mb_cols - mb_col);
+  if (1) {
+    const int bw = 1 << mi_width_log2(mbmi->sb_type);
+    const int bh = 1 << mi_height_log2(mbmi->sb_type);
+    const int y_mis = MIN(bh, cm->mi_rows - mi_row);
+    const int x_mis = MIN(bw, cm->mi_cols - mi_col);
     const int mis = cm->mode_info_stride;
     int x, y;
 
-    for (y = 0; y < y_mbs; y++)
-      for (x = !y; x < x_mbs; x++)
+    for (y = 0; y < y_mis; y++)
+      for (x = !y; x < x_mis; x++)
         mi[y * mis + x] = *mi;
   }
 }
index ad3a489..f09340d 100644 (file)
@@ -560,9 +560,9 @@ static void decode_sb_16x16(MACROBLOCKD *mb, BLOCK_SIZE_TYPE bsize) {
     decode_sbuv_8x8(mb, bsize);
 }
 
-static void decode_sb(VP9D_COMP *pbi, MACROBLOCKD *xd, int mb_row, int mb_col,
+static void decode_sb(VP9D_COMP *pbi, MACROBLOCKD *xd, int mi_row, int mi_col,
                       vp9_reader *r, BLOCK_SIZE_TYPE bsize) {
-  const int bwl = mb_width_log2(bsize), bhl = mb_height_log2(bsize);
+  const int bwl = mi_width_log2(bsize), bhl = mi_height_log2(bsize);
   const int bw = 1 << bwl, bh = 1 << bhl;
   int n, eobtotal;
   VP9_COMMON *const pc = &pbi->common;
@@ -580,7 +580,7 @@ static void decode_sb(VP9D_COMP *pbi, MACROBLOCKD *xd, int mb_row, int mb_col,
     vp9_build_intra_predictors_sby_s(xd, bsize);
     vp9_build_intra_predictors_sbuv_s(xd, bsize);
   } else {
-    vp9_build_inter_predictors_sb(xd, mb_row, mb_col, bsize);
+    vp9_build_inter_predictors_sb(xd, mi_row, mi_col, bsize);
   }
 
   if (mbmi->mb_skip_coeff) {
@@ -596,7 +596,7 @@ static void decode_sb(VP9D_COMP *pbi, MACROBLOCKD *xd, int mb_row, int mb_col,
       for (n = 0; n < bw * bh; n++) {
         const int x_idx = n & (bw - 1), y_idx = n >> bwl;
 
-        if (mb_col + x_idx < pc->mb_cols && mb_row + y_idx < pc->mb_rows)
+        if (mi_col + x_idx < pc->mi_cols && mi_row + y_idx < pc->mi_rows)
           mi[y_idx * mis + x_idx].mbmi.mb_skip_coeff = 1;
       }
     } else {
@@ -624,7 +624,7 @@ static void decode_sb(VP9D_COMP *pbi, MACROBLOCKD *xd, int mb_row, int mb_col,
 // TODO(jingning): Need to merge SB and MB decoding. The MB decoding currently
 // couples special handles on I8x8, B_PRED, and splitmv modes.
 static void decode_mb(VP9D_COMP *pbi, MACROBLOCKD *xd,
-                     int mb_row, int mb_col,
+                     int mi_row, int mi_col,
                      vp9_reader *r) {
   int eobtotal = 0;
   MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi;
@@ -651,7 +651,7 @@ static void decode_mb(VP9D_COMP *pbi, MACROBLOCKD *xd,
            xd->mode_info_context->mbmi.mode, tx_size,
            xd->mode_info_context->mbmi.interp_filter);
 #endif
-    vp9_build_inter_predictors_sb(xd, mb_row, mb_col, BLOCK_SIZE_MB16X16);
+    vp9_build_inter_predictors_sb(xd, mi_row, mi_col, BLOCK_SIZE_MB16X16);
   }
 
   if (mbmi->mb_skip_coeff) {
@@ -737,35 +737,38 @@ static int get_delta_q(vp9_reader *r, int *dq) {
 }
 
 static void set_offsets(VP9D_COMP *pbi, BLOCK_SIZE_TYPE bsize,
-                        int mb_row, int mb_col) {
-  const int bh = 1 << mb_height_log2(bsize);
-  const int bw = 1 << mb_width_log2(bsize);
+                        int mi_row, int mi_col) {
+  const int bh = 1 << mi_height_log2(bsize);
+  const int bw = 1 << mi_width_log2(bsize);
   VP9_COMMON *const cm = &pbi->common;
   MACROBLOCKD *const xd = &pbi->mb;
 
-  const int mb_idx = mb_row * cm->mode_info_stride + mb_col;
+  const int mi_idx = mi_row * cm->mode_info_stride + mi_col;
   const YV12_BUFFER_CONFIG *dst_fb = &cm->yv12_fb[cm->new_fb_idx];
-  const int recon_yoffset = (16 * mb_row) * dst_fb->y_stride + (16 * mb_col);
-  const int recon_uvoffset = (8 * mb_row) * dst_fb->uv_stride + (8 * mb_col);
+  const int recon_yoffset =
+      (MI_SIZE * mi_row) * dst_fb->y_stride + (MI_SIZE * mi_col);
+  const int recon_uvoffset =
+      (MI_UV_SIZE * mi_row) * dst_fb->uv_stride + (MI_UV_SIZE * mi_col);
 
-  xd->mode_info_context = cm->mi + mb_idx;
+  xd->mode_info_context = cm->mi + mi_idx;
   xd->mode_info_context->mbmi.sb_type = bsize;
-  xd->prev_mode_info_context = cm->prev_mi + mb_idx;
-  xd->above_context = cm->above_context + mb_col;
-  xd->left_context = cm->left_context + mb_row % 4;
-  xd->above_seg_context = cm->above_seg_context + mb_col;
-  xd->left_seg_context  = cm->left_seg_context + (mb_row & 3);
+  xd->prev_mode_info_context = cm->prev_mi + mi_idx;
+
+  xd->above_context = cm->above_context + (mi_col >> CONFIG_SB8X8);
+  xd->left_context = cm->left_context + ((mi_row >> CONFIG_SB8X8) & 3);
+  xd->above_seg_context = cm->above_seg_context + (mi_col >> CONFIG_SB8X8);
+  xd->left_seg_context  = cm->left_seg_context + ((mi_row >> CONFIG_SB8X8) & 3);
 
   // Distance of Mb to the various image edges. These are specified to 8th pel
   // as they are always compared to values that are in 1/8th pel units
-  set_mb_row_col(cm, xd, mb_row, bh, mb_col, bw);
+  set_mi_row_col(cm, xd, mi_row, bh, mi_col, bw);
 
   xd->plane[0].dst.buf = dst_fb->y_buffer + recon_yoffset;
   xd->plane[1].dst.buf = dst_fb->u_buffer + recon_uvoffset;
   xd->plane[2].dst.buf = dst_fb->v_buffer + recon_uvoffset;
 }
 
-static void set_refs(VP9D_COMP *pbi, int mb_row, int mb_col) {
+static void set_refs(VP9D_COMP *pbi, int mi_row, int mi_col) {
   VP9_COMMON *const cm = &pbi->common;
   MACROBLOCKD *const xd = &pbi->mb;
   MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi;
@@ -776,7 +779,7 @@ static void set_refs(VP9D_COMP *pbi, int mb_row, int mb_col) {
     const YV12_BUFFER_CONFIG *cfg = &cm->yv12_fb[fb_idx];
     xd->scale_factor[0]    = cm->active_ref_scale[mbmi->ref_frame - 1];
     xd->scale_factor_uv[0] = cm->active_ref_scale[mbmi->ref_frame - 1];
-    setup_pre_planes(xd, cfg, NULL, mb_row, mb_col,
+    setup_pre_planes(xd, cfg, NULL, mi_row, mi_col,
                      xd->scale_factor, xd->scale_factor_uv);
     xd->corrupted |= cfg->corrupted;
 
@@ -786,47 +789,48 @@ static void set_refs(VP9D_COMP *pbi, int mb_row, int mb_col) {
       const YV12_BUFFER_CONFIG *second_cfg = &cm->yv12_fb[second_fb_idx];
       xd->scale_factor[1]    = cm->active_ref_scale[mbmi->second_ref_frame - 1];
       xd->scale_factor_uv[1] = cm->active_ref_scale[mbmi->second_ref_frame - 1];
-      setup_pre_planes(xd, NULL, second_cfg, mb_row, mb_col,
+      setup_pre_planes(xd, NULL, second_cfg, mi_row, mi_col,
                        xd->scale_factor, xd->scale_factor_uv);
       xd->corrupted |= second_cfg->corrupted;
     }
   }
 }
 
-static void decode_modes_b(VP9D_COMP *pbi, int mb_row, int mb_col,
+static void decode_modes_b(VP9D_COMP *pbi, int mi_row, int mi_col,
                            vp9_reader *r, BLOCK_SIZE_TYPE bsize) {
   MACROBLOCKD *const xd = &pbi->mb;
 
-  set_offsets(pbi, bsize, mb_row, mb_col);
-  vp9_decode_mb_mode_mv(pbi, xd, mb_row, mb_col, r);
-  set_refs(pbi, mb_row, mb_col);
+  set_offsets(pbi, bsize, mi_row, mi_col);
+  vp9_decode_mb_mode_mv(pbi, xd, mi_row, mi_col, r);
+  set_refs(pbi, mi_row, mi_col);
 
   // TODO(jingning): merge decode_sb_ and decode_mb_
   if (bsize > BLOCK_SIZE_MB16X16)
-    decode_sb(pbi, xd, mb_row, mb_col, r, bsize);
+    decode_sb(pbi, xd, mi_row, mi_col, r, bsize);
   else
-    decode_mb(pbi, xd, mb_row, mb_col, r);
+    decode_mb(pbi, xd, mi_row, mi_col, r);
 
   xd->corrupted |= vp9_reader_has_error(r);
 }
 
-static void decode_modes_sb(VP9D_COMP *pbi, int mb_row, int mb_col,
+static void decode_modes_sb(VP9D_COMP *pbi, int mi_row, int mi_col,
                             vp9_reader* r, BLOCK_SIZE_TYPE bsize) {
   VP9_COMMON *const pc = &pbi->common;
   MACROBLOCKD *const xd = &pbi->mb;
-  int bsl = mb_width_log2(bsize), bs = (1 << bsl) / 2;
+  int bsl = mi_width_log2(bsize), bs = (1 << bsl) / 2;
   int n;
   PARTITION_TYPE partition = PARTITION_NONE;
   BLOCK_SIZE_TYPE subsize;
 
-  if (mb_row >= pc->mb_rows || mb_col >= pc->mb_cols)
+  if (mi_row >= pc->mi_rows || mi_col >= pc->mi_cols)
     return;
 
   if (bsize > BLOCK_SIZE_MB16X16) {
     int pl;
     // read the partition information
-    xd->left_seg_context = pc->left_seg_context + (mb_row & 3);
-    xd->above_seg_context = pc->above_seg_context + mb_col;
+    xd->left_seg_context =
+        pc->left_seg_context + ((mi_row >> CONFIG_SB8X8) & 3);
+    xd->above_seg_context = pc->above_seg_context + (mi_col >> CONFIG_SB8X8);
     pl = partition_plane_context(xd, bsize);
     partition = treed_read(r, vp9_partition_tree,
                            pc->fc.partition_prob[pl]);
@@ -836,21 +840,21 @@ static void decode_modes_sb(VP9D_COMP *pbi, int mb_row, int mb_col,
   switch (partition) {
     case PARTITION_NONE:
       subsize = bsize;
-      decode_modes_b(pbi, mb_row, mb_col, r, subsize);
+      decode_modes_b(pbi, mi_row, mi_col, r, subsize);
       break;
     case PARTITION_HORZ:
       subsize = (bsize == BLOCK_SIZE_SB64X64) ? BLOCK_SIZE_SB64X32 :
                                                 BLOCK_SIZE_SB32X16;
-      decode_modes_b(pbi, mb_row, mb_col, r, subsize);
-      if ((mb_row + bs) < pc->mb_rows)
-        decode_modes_b(pbi, mb_row + bs, mb_col, r, subsize);
+      decode_modes_b(pbi, mi_row, mi_col, r, subsize);
+      if ((mi_row + bs) < pc->mi_rows)
+        decode_modes_b(pbi, mi_row + bs, mi_col, r, subsize);
       break;
     case PARTITION_VERT:
       subsize = (bsize == BLOCK_SIZE_SB64X64) ? BLOCK_SIZE_SB32X64 :
                                                 BLOCK_SIZE_SB16X32;
-      decode_modes_b(pbi, mb_row, mb_col, r, subsize);
-      if ((mb_col + bs) < pc->mb_cols)
-        decode_modes_b(pbi, mb_row, mb_col + bs, r, subsize);
+      decode_modes_b(pbi, mi_row, mi_col, r, subsize);
+      if ((mi_col + bs) < pc->mi_cols)
+        decode_modes_b(pbi, mi_row, mi_col + bs, r, subsize);
       break;
     case PARTITION_SPLIT:
       subsize = (bsize == BLOCK_SIZE_SB64X64) ? BLOCK_SIZE_SB32X32 :
@@ -861,7 +865,7 @@ static void decode_modes_sb(VP9D_COMP *pbi, int mb_row, int mb_col,
           xd->sb_index = n;
         else
           xd->mb_index = n;
-        decode_modes_sb(pbi, mb_row + j * bs, mb_col + i * bs, r, subsize);
+        decode_modes_sb(pbi, mi_row + j * bs, mi_col + i * bs, r, subsize);
       }
       break;
     default:
@@ -871,8 +875,8 @@ static void decode_modes_sb(VP9D_COMP *pbi, int mb_row, int mb_col,
   if ((partition == PARTITION_SPLIT) && (bsize > BLOCK_SIZE_SB32X32))
     return;
 
-  xd->left_seg_context = pc->left_seg_context + (mb_row & 3);
-  xd->above_seg_context = pc->above_seg_context + mb_col;
+  xd->left_seg_context = pc->left_seg_context + ((mi_row >> CONFIG_SB8X8) & 3);
+  xd->above_seg_context = pc->above_seg_context + (mi_col >> CONFIG_SB8X8);
   update_partition_context(xd, subsize, bsize);
 }
 
@@ -1024,11 +1028,13 @@ static void update_frame_size(VP9D_COMP *pbi) {
   const int height = multiple16(cm->height);
 
   cm->mb_rows = height / 16;
+  cm->mi_rows = height >> LOG2_MI_SIZE;
   cm->mb_cols = width / 16;
+  cm->mi_cols = width >> LOG2_MI_SIZE;
   cm->MBs = cm->mb_rows * cm->mb_cols;
-  cm->mode_info_stride = cm->mb_cols + 1;
+  cm->mode_info_stride = cm->mi_cols + 1;
   memset(cm->mip, 0,
-         cm->mode_info_stride * (cm->mb_rows + 1) * sizeof(MODE_INFO));
+         cm->mode_info_stride * (cm->mi_rows + 1) * sizeof(MODE_INFO));
   vp9_update_mode_info_border(cm, cm->mip);
   vp9_update_mode_info_border(cm, cm->prev_mip);
 
@@ -1286,16 +1292,16 @@ static void update_frame_context(FRAME_CONTEXT *fc) {
 
 static void decode_tile(VP9D_COMP *pbi, vp9_reader *r) {
   VP9_COMMON *const pc = &pbi->common;
-  int mb_row, mb_col;
+  int mi_row, mi_col;
 
-  for (mb_row = pc->cur_tile_mb_row_start;
-       mb_row < pc->cur_tile_mb_row_end; mb_row += 4) {
+  for (mi_row = pc->cur_tile_mi_row_start;
+       mi_row < pc->cur_tile_mi_row_end; mi_row += (4 << CONFIG_SB8X8)) {
     // For a SB there are 2 left contexts, each pertaining to a MB row within
     vpx_memset(pc->left_context, 0, sizeof(pc->left_context));
     vpx_memset(pc->left_seg_context, 0, sizeof(pc->left_seg_context));
-    for (mb_col = pc->cur_tile_mb_col_start;
-         mb_col < pc->cur_tile_mb_col_end; mb_col += 4) {
-      decode_modes_sb(pbi, mb_row, mb_col, r, BLOCK_SIZE_SB64X64);
+    for (mi_col = pc->cur_tile_mi_col_start;
+         mi_col < pc->cur_tile_mi_col_end; mi_col += (4 << CONFIG_SB8X8)) {
+      decode_modes_sb(pbi, mi_row, mi_col, r, BLOCK_SIZE_SB64X64);
     }
   }
 }
@@ -1552,7 +1558,7 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) {
   // Create the segmentation map structure and set to 0
   if (!pc->last_frame_seg_map)
     CHECK_MEM_ERROR(pc->last_frame_seg_map,
-                    vpx_calloc((pc->mb_rows * pc->mb_cols), 1));
+                    vpx_calloc((pc->mi_rows * pc->mi_cols), 1));
 
   // set up frame new frame for intra coded blocks
   vp9_setup_intra_recon(new_fb);
index 870d9d4..d099960 100644 (file)
@@ -686,8 +686,7 @@ static void update_ref_probs(VP9_COMP *const cpi) {
 }
 
 static void pack_inter_mode_mvs(VP9_COMP *cpi, MODE_INFO *m,
-                                vp9_writer *bc,
-                                int mb_rows_left, int mb_cols_left) {
+                                vp9_writer *bc, int mi_row, int mi_col) {
   VP9_COMMON *const pc = &cpi->common;
   const nmv_context *nmvc = &pc->fc.nmvc;
   MACROBLOCK *const x = &cpi->mb;
@@ -697,21 +696,11 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, MODE_INFO *m,
   const MV_REFERENCE_FRAME rf = mi->ref_frame;
   const MB_PREDICTION_MODE mode = mi->mode;
   const int segment_id = mi->segment_id;
-  const int bw = 1 << mb_width_log2(mi->sb_type);
-  const int bh = 1 << mb_height_log2(mi->sb_type);
   int skip_coeff;
 
-  int mb_row = pc->mb_rows - mb_rows_left;
-  int mb_col = pc->mb_cols - mb_cols_left;
   xd->prev_mode_info_context = pc->prev_mi + (m - pc->mi);
   x->partition_info = x->pi + (m - pc->mi);
 
-  // Distance of Mb to the various image edges.
-  // These specified to 8th pel as they are always compared to MV
-  // values that are in 1/8th pel units
-
-  set_mb_row_col(pc, xd, mb_row, bh, mb_col, bw);
-
 #ifdef ENTROPY_STATS
   active_section = 9;
 #endif
@@ -926,8 +915,7 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, MODE_INFO *m,
 
 static void write_mb_modes_kf(const VP9_COMP *cpi,
                               MODE_INFO *m,
-                              vp9_writer *bc,
-                              int mb_rows_left, int mb_cols_left) {
+                              vp9_writer *bc, int mi_row, int mi_col) {
   const VP9_COMMON *const c = &cpi->common;
   const MACROBLOCKD *const xd = &cpi->mb.e_mbd;
   const int mis = c->mode_info_stride;
@@ -1145,23 +1133,21 @@ void print_zpcstats() {
 
 static void write_modes_b(VP9_COMP *cpi, MODE_INFO *m, vp9_writer *bc,
                           TOKENEXTRA **tok, TOKENEXTRA *tok_end,
-                          int mb_row, int mb_col) {
+                          int mi_row, int mi_col) {
   VP9_COMMON *const cm = &cpi->common;
   MACROBLOCKD *const xd = &cpi->mb.e_mbd;
 
   xd->mode_info_context = m;
-  set_mb_row_col(&cpi->common, xd, mb_row,
-                 1 << mb_height_log2(m->mbmi.sb_type),
-                 mb_col, 1 << mb_width_log2(m->mbmi.sb_type));
+  set_mi_row_col(&cpi->common, xd, mi_row,
+                 1 << mi_height_log2(m->mbmi.sb_type),
+                 mi_col, 1 << mi_width_log2(m->mbmi.sb_type));
   if (cm->frame_type == KEY_FRAME) {
-    write_mb_modes_kf(cpi, m, bc,
-                      cm->mb_rows - mb_row, cm->mb_cols - mb_col);
+    write_mb_modes_kf(cpi, m, bc, mi_row, mi_col);
 #ifdef ENTROPY_STATS
     active_section = 8;
 #endif
   } else {
-    pack_inter_mode_mvs(cpi, m, bc,
-                        cm->mb_rows - mb_row, cm->mb_cols - mb_col);
+    pack_inter_mode_mvs(cpi, m, bc, mi_row, mi_col);
 #ifdef ENTROPY_STATS
     active_section = 1;
 #endif
@@ -1173,23 +1159,23 @@ static void write_modes_b(VP9_COMP *cpi, MODE_INFO *m, vp9_writer *bc,
 
 static void write_modes_sb(VP9_COMP *cpi, MODE_INFO *m, vp9_writer *bc,
                            TOKENEXTRA **tok, TOKENEXTRA *tok_end,
-                           int mb_row, int mb_col,
+                           int mi_row, int mi_col,
                            BLOCK_SIZE_TYPE bsize) {
   VP9_COMMON *const cm = &cpi->common;
   MACROBLOCKD *xd = &cpi->mb.e_mbd;
   const int mis = cm->mode_info_stride;
   int bwl, bhl;
   int bw, bh;
-  int bsl = mb_width_log2(bsize), bs = (1 << bsl) / 2;
+  int bsl = mi_width_log2(bsize), bs = (1 << bsl) / 2;
   int n;
   PARTITION_TYPE partition;
   BLOCK_SIZE_TYPE subsize;
 
-  if (mb_row >= cm->mb_rows || mb_col >= cm->mb_cols)
+  if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
     return;
 
-  bwl = mb_width_log2(m->mbmi.sb_type);
-  bhl = mb_height_log2(m->mbmi.sb_type);
+  bwl = mi_width_log2(m->mbmi.sb_type);
+  bhl = mi_height_log2(m->mbmi.sb_type);
   bw = 1 << bwl;
   bh = 1 << bhl;
 
@@ -1207,8 +1193,9 @@ static void write_modes_sb(VP9_COMP *cpi, MODE_INFO *m, vp9_writer *bc,
 
   if (bsize > BLOCK_SIZE_MB16X16) {
     int pl;
-    xd->left_seg_context = cm->left_seg_context + (mb_row & 3);
-    xd->above_seg_context = cm->above_seg_context + mb_col;
+    xd->left_seg_context =
+        cm->left_seg_context + ((mi_row >> CONFIG_SB8X8) & 3);
+    xd->above_seg_context = cm->above_seg_context + (mi_col >> CONFIG_SB8X8);
     pl = partition_plane_context(xd, bsize);
     // encode the partition information
     write_token(bc, vp9_partition_tree, cm->fc.partition_prob[pl],
@@ -1218,21 +1205,21 @@ static void write_modes_sb(VP9_COMP *cpi, MODE_INFO *m, vp9_writer *bc,
   switch (partition) {
     case PARTITION_NONE:
       subsize = bsize;
-      write_modes_b(cpi, m, bc, tok, tok_end, mb_row, mb_col);
+      write_modes_b(cpi, m, bc, tok, tok_end, mi_row, mi_col);
       break;
     case PARTITION_HORZ:
       subsize = (bsize == BLOCK_SIZE_SB64X64) ? BLOCK_SIZE_SB64X32 :
                                                 BLOCK_SIZE_SB32X16;
-      write_modes_b(cpi, m, bc, tok, tok_end, mb_row, mb_col);
-      if ((mb_row + bh) < cm->mb_rows)
-        write_modes_b(cpi, m + bh * mis, bc, tok, tok_end, mb_row + bh, mb_col);
+      write_modes_b(cpi, m, bc, tok, tok_end, mi_row, mi_col);
+      if ((mi_row + bh) < cm->mi_rows)
+        write_modes_b(cpi, m + bh * mis, bc, tok, tok_end, mi_row + bh, mi_col);
       break;
     case PARTITION_VERT:
       subsize = (bsize == BLOCK_SIZE_SB64X64) ? BLOCK_SIZE_SB32X64 :
                                                 BLOCK_SIZE_SB16X32;
-      write_modes_b(cpi, m, bc, tok, tok_end, mb_row, mb_col);
-      if ((mb_col + bw) < cm->mb_cols)
-        write_modes_b(cpi, m + bw, bc, tok, tok_end, mb_row, mb_col + bw);
+      write_modes_b(cpi, m, bc, tok, tok_end, mi_row, mi_col);
+      if ((mi_col + bw) < cm->mi_cols)
+        write_modes_b(cpi, m + bw, bc, tok, tok_end, mi_row, mi_col + bw);
       break;
     case PARTITION_SPLIT:
       // TODO(jingning): support recursive partitioning down to 16x16 as for
@@ -1246,7 +1233,7 @@ static void write_modes_sb(VP9_COMP *cpi, MODE_INFO *m, vp9_writer *bc,
       for (n = 0; n < 4; n++) {
         int j = n >> 1, i = n & 0x01;
         write_modes_sb(cpi, m + j * bs * mis + i * bs, bc, tok, tok_end,
-                       mb_row + j * bs, mb_col + i * bs, subsize);
+                       mi_row + j * bs, mi_col + i * bs, subsize);
       }
       break;
     default:
@@ -1257,8 +1244,8 @@ static void write_modes_sb(VP9_COMP *cpi, MODE_INFO *m, vp9_writer *bc,
   if ((partition == PARTITION_SPLIT) && (bsize > BLOCK_SIZE_SB32X32))
     return;
 
-  xd->left_seg_context = cm->left_seg_context + (mb_row & 3);
-  xd->above_seg_context = cm->above_seg_context + mb_col;
+  xd->left_seg_context = cm->left_seg_context + ((mi_row >> CONFIG_SB8X8) & 3);
+  xd->above_seg_context = cm->above_seg_context + (mi_col >> CONFIG_SB8X8);
   update_partition_context(xd, subsize, bsize);
 }
 
@@ -1267,19 +1254,21 @@ static void write_modes(VP9_COMP *cpi, vp9_writer* const bc,
   VP9_COMMON *const c = &cpi->common;
   const int mis = c->mode_info_stride;
   MODE_INFO *m, *m_ptr = c->mi;
-  int mb_row, mb_col;
+  int mi_row, mi_col;
 
-  m_ptr += c->cur_tile_mb_col_start + c->cur_tile_mb_row_start * mis;
+  m_ptr += c->cur_tile_mi_col_start + c->cur_tile_mi_row_start * mis;
   vpx_memset(c->above_seg_context, 0, sizeof(PARTITION_CONTEXT) *
-                                       mb_cols_aligned_to_sb(c));
+             mb_cols_aligned_to_sb(c));
 
-  for (mb_row = c->cur_tile_mb_row_start;
-       mb_row < c->cur_tile_mb_row_end; mb_row += 4, m_ptr += 4 * mis) {
+  for (mi_row = c->cur_tile_mi_row_start;
+       mi_row < c->cur_tile_mi_row_end;
+       mi_row += (4 << CONFIG_SB8X8), m_ptr += (4 << CONFIG_SB8X8) * mis) {
     m = m_ptr;
     vpx_memset(c->left_seg_context, 0, sizeof(c->left_seg_context));
-    for (mb_col = c->cur_tile_mb_col_start;
-         mb_col < c->cur_tile_mb_col_end; mb_col += 4, m += 4)
-      write_modes_sb(cpi, m, bc, tok, tok_end, mb_row, mb_col,
+    for (mi_col = c->cur_tile_mi_col_start;
+         mi_col < c->cur_tile_mi_col_end;
+         mi_col += (4 << CONFIG_SB8X8), m += (4 << CONFIG_SB8X8))
+      write_modes_sb(cpi, m, bc, tok, tok_end, mi_row, mi_col,
                      BLOCK_SIZE_SB64X64);
   }
 }
index 1436566..8e524f4 100644 (file)
@@ -48,10 +48,10 @@ int enc_debug = 0;
 void vp9_select_interp_filter_type(VP9_COMP *cpi);
 
 static void encode_macroblock(VP9_COMP *cpi, TOKENEXTRA **t,
-                              int output_enabled, int mb_row, int mb_col);
+                              int output_enabled, int mi_row, int mi_col);
 
 static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t,
-                              int output_enabled, int mb_row, int mb_col,
+                              int output_enabled, int mi_row, int mi_col,
                               BLOCK_SIZE_TYPE bsize);
 
 static void adjust_act_zbin(VP9_COMP *cpi, MACROBLOCK *x);
@@ -358,7 +358,7 @@ static void update_state(VP9_COMP *cpi,
   int mb_mode = mi->mbmi.mode;
   int mb_mode_index = ctx->best_mode_index;
   const int mis = cpi->common.mode_info_stride;
-  const int bh = 1 << mb_height_log2(bsize), bw = 1 << mb_width_log2(bsize);
+  const int bh = 1 << mi_height_log2(bsize), bw = 1 << mi_width_log2(bsize);
 
 #if CONFIG_DEBUG
   assert(mb_mode < MB_MODE_COUNT);
@@ -371,8 +371,8 @@ static void update_state(VP9_COMP *cpi,
   // when the mode was picked for it
   for (y = 0; y < bh; y++) {
     for (x_idx = 0; x_idx < bw; x_idx++) {
-      if ((xd->mb_to_right_edge >> 7) + bw > x_idx &&
-          (xd->mb_to_bottom_edge >> 7) + bh > y) {
+      if ((xd->mb_to_right_edge >> (3 + LOG2_MI_SIZE)) + bw > x_idx &&
+          (xd->mb_to_bottom_edge >> (3 + LOG2_MI_SIZE)) + bh > y) {
         MODE_INFO *mi_addr = xd->mode_info_context + x_idx + y * mis;
 
         vpx_memcpy(mi_addr, mi, sizeof(MODE_INFO));
@@ -389,6 +389,17 @@ static void update_state(VP9_COMP *cpi,
 
     mbmi->mv[0].as_int = x->partition_info->bmi[15].mv.as_int;
     mbmi->mv[1].as_int = x->partition_info->bmi[15].second_mv.as_int;
+#if CONFIG_SB8X8
+    vpx_memcpy(x->partition_info + mis, &ctx->partition_info,
+               sizeof(PARTITION_INFO));
+    vpx_memcpy(x->partition_info + 1, &ctx->partition_info,
+               sizeof(PARTITION_INFO));
+    vpx_memcpy(x->partition_info + mis + 1, &ctx->partition_info,
+               sizeof(PARTITION_INFO));
+    xd->mode_info_context[1].mbmi =
+    xd->mode_info_context[mis].mbmi =
+    xd->mode_info_context[1 + mis].mbmi = *mbmi;
+#endif
   }
 
   x->skip = ctx->skip;
@@ -480,6 +491,11 @@ static void update_state(VP9_COMP *cpi,
       mbmi->best_mv.as_int = best_mv.as_int;
       mbmi->best_second_mv.as_int = best_second_mv.as_int;
       vp9_update_nmv_count(cpi, x, &best_mv, &best_second_mv);
+#if CONFIG_SB8X8
+      xd->mode_info_context[1].mbmi =
+      xd->mode_info_context[mis].mbmi =
+      xd->mode_info_context[1 + mis].mbmi = *mbmi;
+#endif
     }
 #if CONFIG_COMP_INTERINTRA_PRED
     if (mbmi->mode >= NEARESTMV && mbmi->mode < SPLITMV &&
@@ -510,7 +526,7 @@ static void update_state(VP9_COMP *cpi,
 
 static unsigned find_seg_id(uint8_t *buf, BLOCK_SIZE_TYPE bsize,
                             int start_y, int height, int start_x, int width) {
-  const int bw = 1 << mb_width_log2(bsize), bh = 1 << mb_height_log2(bsize);
+  const int bw = 1 << mi_width_log2(bsize), bh = 1 << mi_height_log2(bsize);
   const int end_x = MIN(start_x + bw, width);
   const int end_y = MIN(start_y + bh, height);
   int x, y;
@@ -547,15 +563,17 @@ void vp9_setup_src_planes(MACROBLOCK *x,
 }
 
 static void set_offsets(VP9_COMP *cpi,
-                        int mb_row, int mb_col, BLOCK_SIZE_TYPE bsize) {
+                        int mi_row, int mi_col, BLOCK_SIZE_TYPE bsize) {
   MACROBLOCK *const x = &cpi->mb;
   VP9_COMMON *const cm = &cpi->common;
   MACROBLOCKD *const xd = &x->e_mbd;
   MB_MODE_INFO *mbmi;
   const int dst_fb_idx = cm->new_fb_idx;
+  const int idx_str = xd->mode_info_stride * mi_row + mi_col;
+  const int bw = 1 << mi_width_log2(bsize), bh = 1 << mi_height_log2(bsize);
+  const int mb_row = mi_row >> CONFIG_SB8X8;
+  const int mb_col = mi_col >> CONFIG_SB8X8;
   const int idx_map = mb_row * cm->mb_cols + mb_col;
-  const int idx_str = xd->mode_info_stride * mb_row + mb_col;
-  const int bw = 1 << mb_width_log2(bsize), bh = 1 << mb_height_log2(bsize);
 
   // entropy context structures
   xd->above_context = cm->above_context + mb_col;
@@ -576,23 +594,23 @@ static void set_offsets(VP9_COMP *cpi,
   xd->prev_mode_info_context = cm->prev_mi + idx_str;
 
   // Set up destination pointers
-  setup_dst_planes(xd, &cm->yv12_fb[dst_fb_idx], mb_row, mb_col);
+  setup_dst_planes(xd, &cm->yv12_fb[dst_fb_idx], mi_row, mi_col);
 
   /* Set up limit values for MV components to prevent them from
    * extending beyond the UMV borders assuming 16x16 block size */
-  x->mv_row_min = -((mb_row * 16) + VP9BORDERINPIXELS - VP9_INTERP_EXTEND);
-  x->mv_col_min = -((mb_col * 16) + VP9BORDERINPIXELS - VP9_INTERP_EXTEND);
-  x->mv_row_max = ((cm->mb_rows - mb_row) * 16 +
-                   (VP9BORDERINPIXELS - 16 * bh - VP9_INTERP_EXTEND));
-  x->mv_col_max = ((cm->mb_cols - mb_col) * 16 +
-                   (VP9BORDERINPIXELS - 16 * bw - VP9_INTERP_EXTEND));
+  x->mv_row_min = -((mi_row * MI_SIZE) + VP9BORDERINPIXELS - VP9_INTERP_EXTEND);
+  x->mv_col_min = -((mi_col * MI_SIZE) + VP9BORDERINPIXELS - VP9_INTERP_EXTEND);
+  x->mv_row_max = ((cm->mi_rows - mi_row) * MI_SIZE +
+                   (VP9BORDERINPIXELS - MI_SIZE * bh - VP9_INTERP_EXTEND));
+  x->mv_col_max = ((cm->mi_cols - mi_col) * MI_SIZE +
+                   (VP9BORDERINPIXELS - MI_SIZE * bw - VP9_INTERP_EXTEND));
 
   // Set up distance of MB to edge of frame in 1/8th pel units
-  assert(!(mb_col & (bw - 1)) && !(mb_row & (bh - 1)));
-  set_mb_row_col(cm, xd, mb_row, bh, mb_col, bw);
+  assert(!(mi_col & (bw - 1)) && !(mi_row & (bh - 1)));
+  set_mi_row_col(cm, xd, mi_row, bh, mi_col, bw);
 
   /* set up source buffers */
-  vp9_setup_src_planes(x, cpi->Source, mb_row, mb_col);
+  vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col);
 
   /* R/D setup */
   x->rddiv = cpi->RDDIV;
@@ -602,10 +620,10 @@ static void set_offsets(VP9_COMP *cpi,
   if (xd->segmentation_enabled) {
     if (xd->update_mb_segmentation_map) {
       mbmi->segment_id = find_seg_id(cpi->segmentation_map, bsize,
-                                     mb_row, cm->mb_rows, mb_col, cm->mb_cols);
+                                     mi_row, cm->mi_rows, mi_col, cm->mi_cols);
     } else {
       mbmi->segment_id = find_seg_id(cm->last_frame_seg_map, bsize,
-                                     mb_row, cm->mb_rows, mb_col, cm->mb_cols);
+                                     mi_row, cm->mi_rows, mi_col, cm->mi_cols);
     }
     assert(mbmi->segment_id <= (MAX_MB_SEGMENTS-1));
     vp9_mb_init_quantizer(cpi, x);
@@ -623,8 +641,10 @@ static void set_offsets(VP9_COMP *cpi,
       const int x = mb_col & ~3;
       const int p16 = ((mb_row & 1) << 1) +  (mb_col & 1);
       const int p32 = ((mb_row & 2) << 2) + ((mb_col & 2) << 1);
-      const int tile_progress = cm->cur_tile_mb_col_start * cm->mb_rows;
-      const int mb_cols = cm->cur_tile_mb_col_end - cm->cur_tile_mb_col_start;
+      const int tile_progress =
+          cm->cur_tile_mi_col_start * cm->mb_rows >> CONFIG_SB8X8;
+      const int mb_cols =
+          (cm->cur_tile_mi_col_end - cm->cur_tile_mi_col_start) >> CONFIG_SB8X8;
 
       cpi->seg0_progress =
           ((y * mb_cols + x * 4 + p32 + p16 + tile_progress) << 16) / cm->MBs;
@@ -635,8 +655,8 @@ static void set_offsets(VP9_COMP *cpi,
 }
 
 static int pick_mb_mode(VP9_COMP *cpi,
-                        int mb_row,
-                        int mb_col,
+                        int mi_row,
+                        int mi_col,
                         TOKENEXTRA **tp,
                         int *totalrate,
                         int *totaldist) {
@@ -646,7 +666,7 @@ static int pick_mb_mode(VP9_COMP *cpi,
   int splitmodes_used = 0;
   MB_MODE_INFO *mbmi;
 
-  set_offsets(cpi, mb_row, mb_col, BLOCK_SIZE_MB16X16);
+  set_offsets(cpi, mi_row, mi_col, BLOCK_SIZE_MB16X16);
 
   if (cpi->oxcf.tuning == VP8_TUNE_SSIM)
     vp9_activity_masking(cpi, x);
@@ -663,7 +683,7 @@ static int pick_mb_mode(VP9_COMP *cpi,
     vpx_memcpy(&x->mb_context[xd->sb_index][xd->mb_index].mic,
                xd->mode_info_context, sizeof(MODE_INFO));
   } else {
-    vp9_pick_mode_inter_macroblock(cpi, x, mb_row, mb_col,
+    vp9_pick_mode_inter_macroblock(cpi, x, mi_row, mi_col,
                                    totalrate, totaldist);
     splitmodes_used += (mbmi->mode == SPLITMV);
 
@@ -675,14 +695,14 @@ static int pick_mb_mode(VP9_COMP *cpi,
   return splitmodes_used;
 }
 
-static void pick_sb_modes(VP9_COMP *cpi, int mb_row, int mb_col,
+static void pick_sb_modes(VP9_COMP *cpi, int mi_row, int mi_col,
                           TOKENEXTRA **tp, int *totalrate, int *totaldist,
                           BLOCK_SIZE_TYPE bsize, PICK_MODE_CONTEXT *ctx) {
   VP9_COMMON *const cm = &cpi->common;
   MACROBLOCK *const x = &cpi->mb;
   MACROBLOCKD *const xd = &x->e_mbd;
 
-  set_offsets(cpi, mb_row, mb_col, bsize);
+  set_offsets(cpi, mi_row, mi_col, bsize);
   xd->mode_info_context->mbmi.sb_type = bsize;
   if (cpi->oxcf.tuning == VP8_TUNE_SSIM)
     vp9_activity_masking(cpi, x);
@@ -692,12 +712,12 @@ static void pick_sb_modes(VP9_COMP *cpi, int mb_row, int mb_col,
   if (cm->frame_type == KEY_FRAME) {
     vp9_rd_pick_intra_mode_sb(cpi, x, totalrate, totaldist, bsize, ctx);
   } else {
-    vp9_rd_pick_inter_mode_sb(cpi, x, mb_row, mb_col, totalrate, totaldist,
+    vp9_rd_pick_inter_mode_sb(cpi, x, mi_row, mi_col, totalrate, totaldist,
                               bsize, ctx);
   }
 }
 
-static void update_stats(VP9_COMP *cpi, int mb_row, int mb_col) {
+static void update_stats(VP9_COMP *cpi, int mi_row, int mi_col) {
   VP9_COMMON *const cm = &cpi->common;
   MACROBLOCK *const x = &cpi->mb;
   MACROBLOCKD *const xd = &x->e_mbd;
@@ -754,8 +774,8 @@ static void update_stats(VP9_COMP *cpi, int mb_row, int mb_col) {
 }
 
 static void encode_sb(VP9_COMP *cpi,
-                      int mb_row,
-                      int mb_col,
+                      int mi_row,
+                      int mi_col,
                       int output_enabled,
                       TOKENEXTRA **tp, BLOCK_SIZE_TYPE is_sb) {
   VP9_COMMON *const cm = &cpi->common;
@@ -764,19 +784,21 @@ static void encode_sb(VP9_COMP *cpi,
   BLOCK_SIZE_TYPE bsize = BLOCK_SIZE_SB32X32;
   int pl;
 
-  xd->left_seg_context  = cm->left_seg_context + (mb_row & 0x03);
-  xd->above_seg_context = cm->above_seg_context + mb_col;
+  xd->left_seg_context  =
+      cm->left_seg_context + ((mi_row >> CONFIG_SB8X8) & 0x03);
+  xd->above_seg_context =
+      cm->above_seg_context + (mi_col >> CONFIG_SB8X8);
   pl = partition_plane_context(xd, bsize);
 
   if (is_sb == BLOCK_SIZE_SB32X32) {
-    set_offsets(cpi, mb_row, mb_col, bsize);
+    set_offsets(cpi, mi_row, mi_col, bsize);
     update_state(cpi, &x->sb32_context[xd->sb_index],
                  bsize, output_enabled);
 
     encode_superblock(cpi, tp,
-                      output_enabled, mb_row, mb_col, bsize);
+                      output_enabled, mi_row, mi_col, bsize);
     if (output_enabled) {
-      update_stats(cpi, mb_row, mb_col);
+      update_stats(cpi, mi_row, mi_col);
       cpi->partition_count[pl][PARTITION_NONE]++;
 
       (*tp)->token = EOSB_TOKEN;
@@ -787,14 +809,16 @@ static void encode_sb(VP9_COMP *cpi,
 
     if (output_enabled)
       cpi->partition_count[pl][PARTITION_VERT]++;
-    for (i = 0; i < 2 && mb_col + i != cm->mb_cols; i++) {
-      set_offsets(cpi, mb_row, mb_col + i, BLOCK_SIZE_SB16X32);
+    for (i = 0; i < 2 && mi_col + (i << CONFIG_SB8X8) != cm->mi_cols; i++) {
+      set_offsets(cpi, mi_row, mi_col + (i << CONFIG_SB8X8),
+                  BLOCK_SIZE_SB16X32);
       update_state(cpi, &x->sb16x32_context[xd->sb_index][i],
                    BLOCK_SIZE_SB16X32, output_enabled);
       encode_superblock(cpi, tp,
-                        output_enabled, mb_row, mb_col + i, BLOCK_SIZE_SB16X32);
+                        output_enabled, mi_row, mi_col + (i << CONFIG_SB8X8),
+                        BLOCK_SIZE_SB16X32);
       if (output_enabled) {
-        update_stats(cpi, mb_row, mb_col + i);
+        update_stats(cpi, mi_row, mi_col + i);
 
         (*tp)->token = EOSB_TOKEN;
         (*tp)++;
@@ -805,14 +829,16 @@ static void encode_sb(VP9_COMP *cpi,
 
     if (output_enabled)
       cpi->partition_count[pl][PARTITION_HORZ]++;
-    for (i = 0; i < 2 && mb_row + i != cm->mb_rows; i++) {
-      set_offsets(cpi, mb_row + i, mb_col, BLOCK_SIZE_SB32X16);
+    for (i = 0; i < 2 && mi_row + (i << CONFIG_SB8X8) != cm->mi_rows; i++) {
+      set_offsets(cpi, mi_row + (i << CONFIG_SB8X8), mi_col,
+                  BLOCK_SIZE_SB32X16);
       update_state(cpi, &x->sb32x16_context[xd->sb_index][i],
                    BLOCK_SIZE_SB32X16, output_enabled);
       encode_superblock(cpi, tp,
-                        output_enabled, mb_row + i, mb_col, BLOCK_SIZE_SB32X16);
+                        output_enabled, mi_row + (i << CONFIG_SB8X8), mi_col,
+                        BLOCK_SIZE_SB32X16);
       if (output_enabled) {
-        update_stats(cpi, mb_row + i, mb_col);
+        update_stats(cpi, mi_row + (i << CONFIG_SB8X8), mi_col);
 
         (*tp)->token = EOSB_TOKEN;
         (*tp)++;
@@ -824,14 +850,15 @@ static void encode_sb(VP9_COMP *cpi,
       cpi->partition_count[pl][PARTITION_SPLIT]++;
 
     for (i = 0; i < 4; i++) {
-      const int x_idx = i & 1, y_idx = i >> 1;
+      const int x_idx = (i & 1) << CONFIG_SB8X8;
+      const int y_idx = (i >> 1) << CONFIG_SB8X8;
 
-      if ((mb_row + y_idx >= cm->mb_rows) || (mb_col + x_idx >= cm->mb_cols)) {
+      if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols)) {
         // MB lies outside frame, move on
         continue;
       }
 
-      set_offsets(cpi, mb_row + y_idx, mb_col + x_idx, BLOCK_SIZE_MB16X16);
+      set_offsets(cpi, mi_row + y_idx, mi_col + x_idx, BLOCK_SIZE_MB16X16);
       xd->mb_index = i;
       update_state(cpi, &x->mb_context[xd->sb_index][i],
                    BLOCK_SIZE_MB16X16, output_enabled);
@@ -840,9 +867,9 @@ static void encode_sb(VP9_COMP *cpi,
         vp9_activity_masking(cpi, x);
 
       encode_macroblock(cpi, tp,
-                        output_enabled, mb_row + y_idx, mb_col + x_idx);
+                        output_enabled, mi_row + y_idx, mi_col + x_idx);
       if (output_enabled) {
-        update_stats(cpi, mb_row + y_idx, mb_col + x_idx);
+        update_stats(cpi, mi_row + y_idx, mi_col + x_idx);
 
         (*tp)->token = EOSB_TOKEN;
         (*tp)++;
@@ -850,8 +877,8 @@ static void encode_sb(VP9_COMP *cpi,
     }
   }
 
-  xd->above_seg_context = cm->above_seg_context + mb_col;
-  xd->left_seg_context  = cm->left_seg_context + (mb_row & 3);
+  xd->above_seg_context = cm->above_seg_context + (mi_col >> CONFIG_SB8X8);
+  xd->left_seg_context  = cm->left_seg_context + ((mi_row >> CONFIG_SB8X8) & 3);
   update_partition_context(xd, is_sb, BLOCK_SIZE_SB32X32);
 
   // debug output
@@ -866,8 +893,8 @@ static void encode_sb(VP9_COMP *cpi,
 }
 
 static void encode_sb64(VP9_COMP *cpi,
-                        int mb_row,
-                        int mb_col,
+                        int mi_row,
+                        int mi_col,
                         TOKENEXTRA **tp, BLOCK_SIZE_TYPE is_sb[4]) {
   VP9_COMMON *const cm = &cpi->common;
   MACROBLOCK *const x = &cpi->mb;
@@ -875,16 +902,16 @@ static void encode_sb64(VP9_COMP *cpi,
   BLOCK_SIZE_TYPE bsize = BLOCK_SIZE_SB64X64;
   int pl;
 
-  xd->left_seg_context  = cm->left_seg_context + (mb_row & 3);
-  xd->above_seg_context = cm->above_seg_context + mb_col;
+  xd->left_seg_context  = cm->left_seg_context + ((mi_row >> CONFIG_SB8X8) & 3);
+  xd->above_seg_context = cm->above_seg_context + (mi_col >> CONFIG_SB8X8);
   pl = partition_plane_context(xd, bsize);
 
   if (is_sb[0] == BLOCK_SIZE_SB64X64) {
-    set_offsets(cpi, mb_row, mb_col, bsize);
+    set_offsets(cpi, mi_row, mi_col, bsize);
     update_state(cpi, &x->sb64_context, bsize, 1);
     encode_superblock(cpi, tp,
-                      1, mb_row, mb_col, bsize);
-    update_stats(cpi, mb_row, mb_col);
+                      1, mi_row, mi_col, bsize);
+    update_stats(cpi, mi_row, mi_col);
 
     (*tp)->token = EOSB_TOKEN;
     (*tp)++;
@@ -893,12 +920,14 @@ static void encode_sb64(VP9_COMP *cpi,
     int i;
 
     cpi->partition_count[pl][PARTITION_VERT]++;
-    for (i = 0; i < 2 && mb_col + i * 2 != cm->mb_cols; i++) {
-      set_offsets(cpi, mb_row, mb_col + i * 2, BLOCK_SIZE_SB32X64);
+    for (i = 0; i < 2 && mi_col + (i * 2 << CONFIG_SB8X8) != cm->mi_cols; i++) {
+      set_offsets(cpi, mi_row, mi_col + (i * 2 << CONFIG_SB8X8),
+                  BLOCK_SIZE_SB32X64);
       update_state(cpi, &x->sb32x64_context[i], BLOCK_SIZE_SB32X64, 1);
       encode_superblock(cpi, tp,
-                        1, mb_row, mb_col + i * 2, BLOCK_SIZE_SB32X64);
-      update_stats(cpi, mb_row, mb_col + i * 2);
+                        1, mi_row, mi_col + (i * 2 << CONFIG_SB8X8),
+                        BLOCK_SIZE_SB32X64);
+      update_stats(cpi, mi_row, mi_col + (i * 2 << CONFIG_SB8X8));
 
       (*tp)->token = EOSB_TOKEN;
       (*tp)++;
@@ -907,12 +936,14 @@ static void encode_sb64(VP9_COMP *cpi,
     int i;
 
     cpi->partition_count[pl][PARTITION_HORZ]++;
-    for (i = 0; i < 2 && mb_row + i * 2 != cm->mb_rows; i++) {
-      set_offsets(cpi, mb_row + i * 2, mb_col, BLOCK_SIZE_SB64X32);
+    for (i = 0; i < 2 && mi_row + (i * 2 << CONFIG_SB8X8) != cm->mi_rows; i++) {
+      set_offsets(cpi, mi_row + (i * 2 << CONFIG_SB8X8), mi_col,
+                  BLOCK_SIZE_SB64X32);
       update_state(cpi, &x->sb64x32_context[i], BLOCK_SIZE_SB64X32, 1);
       encode_superblock(cpi, tp,
-                        1, mb_row + i * 2, mb_col, BLOCK_SIZE_SB64X32);
-      update_stats(cpi, mb_row + i * 2, mb_col);
+                        1, mi_row + (i * 2 << CONFIG_SB8X8), mi_col,
+                        BLOCK_SIZE_SB64X32);
+      update_stats(cpi, mi_row + (i * 2 << CONFIG_SB8X8), mi_col);
 
       (*tp)->token = EOSB_TOKEN;
       (*tp)++;
@@ -921,42 +952,43 @@ static void encode_sb64(VP9_COMP *cpi,
     int i;
     cpi->partition_count[pl][PARTITION_SPLIT]++;
     for (i = 0; i < 4; i++) {
-      const int x_idx = i & 1, y_idx = i >> 1;
+      const int x_idx = (i & 1) << (1 + CONFIG_SB8X8);
+      const int y_idx = (i & 2) << CONFIG_SB8X8;
 
-      if (mb_row + y_idx * 2 >= cm->mb_rows ||
-          mb_col + x_idx * 2 >= cm->mb_cols) {
+      if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols) {
         // MB lies outside frame, move on
         continue;
       }
       xd->sb_index = i;
-      encode_sb(cpi, mb_row + 2 * y_idx, mb_col + 2 * x_idx, 1, tp,
+      encode_sb(cpi, mi_row + y_idx, mi_col + x_idx, 1, tp,
                 is_sb[i]);
     }
   }
 
   if (is_sb[0] > BLOCK_SIZE_SB32X32) {
-    xd->above_seg_context = cm->above_seg_context + mb_col;
-    xd->left_seg_context  = cm->left_seg_context + (mb_row & 3);
+    xd->above_seg_context = cm->above_seg_context + (mi_col >> CONFIG_SB8X8);
+    xd->left_seg_context  =
+        cm->left_seg_context + ((mi_row >> CONFIG_SB8X8) & 3);
     update_partition_context(xd, is_sb[0], BLOCK_SIZE_SB64X64);
   }
 }
 
 static void encode_sb_row(VP9_COMP *cpi,
-                          int mb_row,
+                          int mi_row,
                           TOKENEXTRA **tp,
                           int *totalrate) {
   VP9_COMMON *const cm = &cpi->common;
   MACROBLOCK *const x = &cpi->mb;
   MACROBLOCKD *const xd = &x->e_mbd;
-  int mb_col, pl;
+  int mi_col, pl;
 
   // Initialize the left context for the new SB row
   vpx_memset(cm->left_context, 0, sizeof(cm->left_context));
   vpx_memset(cm->left_seg_context, 0, sizeof(cm->left_seg_context));
 
   // Code each SB in the row
-  for (mb_col = cm->cur_tile_mb_col_start;
-       mb_col < cm->cur_tile_mb_col_end; mb_col += 4) {
+  for (mi_col = cm->cur_tile_mi_col_start;
+       mi_col < cm->cur_tile_mi_col_end; mi_col += (4 << CONFIG_SB8X8)) {
     int i;
     BLOCK_SIZE_TYPE sb_partitioning[4];
     int sb64_rate = 0, sb64_dist = 0;
@@ -965,35 +997,39 @@ static void encode_sb_row(VP9_COMP *cpi,
     PARTITION_CONTEXT seg_l[4], seg_a[4];
     TOKENEXTRA *tp_orig = *tp;
 
-    memcpy(&a, cm->above_context + mb_col, sizeof(a));
+    memcpy(&a, cm->above_context + (mi_col >> CONFIG_SB8X8), sizeof(a));
     memcpy(&l, cm->left_context, sizeof(l));
-    memcpy(&seg_a, cm->above_seg_context + mb_col, sizeof(seg_a));
+    memcpy(&seg_a, cm->above_seg_context + (mi_col >> CONFIG_SB8X8),
+           sizeof(seg_a));
     memcpy(&seg_l, cm->left_seg_context, sizeof(seg_l));
     for (i = 0; i < 4; i++) {
-      const int x_idx = (i & 1) << 1, y_idx = i & 2;
+      const int x_idx = (i & 1) << (1 + CONFIG_SB8X8);
+      const int y_idx = (i & 2) << CONFIG_SB8X8;
       int sb32_rate = 0, sb32_dist = 0;
       int splitmodes_used = 0;
       int sb32_skip = 0;
       int j;
       ENTROPY_CONTEXT_PLANES l2[2], a2[2];
 
-      if (mb_row + y_idx >= cm->mb_rows || mb_col + x_idx >= cm->mb_cols)
+      if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols)
         continue;
 
       xd->sb_index = i;
 
       /* Function should not modify L & A contexts; save and restore on exit */
-      vpx_memcpy(l2, cm->left_context + y_idx, sizeof(l2));
-      vpx_memcpy(a2, cm->above_context + mb_col + x_idx, sizeof(a2));
+      vpx_memcpy(l2, cm->left_context + (y_idx >> CONFIG_SB8X8), sizeof(l2));
+      vpx_memcpy(a2, cm->above_context + ((mi_col + x_idx) >> CONFIG_SB8X8),
+                 sizeof(a2));
 
       /* Encode MBs in raster order within the SB */
       sb_partitioning[i] = BLOCK_SIZE_MB16X16;
       for (j = 0; j < 4; j++) {
-        const int x_idx_m = x_idx + (j & 1), y_idx_m = y_idx + (j >> 1);
+        const int x_idx_m = x_idx + ((j & 1) << CONFIG_SB8X8);
+        const int y_idx_m = y_idx + ((j >> 1) << CONFIG_SB8X8);
         int r, d;
 
-        if (mb_row + y_idx_m >= cm->mb_rows ||
-            mb_col + x_idx_m >= cm->mb_cols) {
+        if (mi_row + y_idx_m >= cm->mi_rows ||
+            mi_col + x_idx_m >= cm->mi_cols) {
           // MB lies outside frame, move on
           continue;
         }
@@ -1001,22 +1037,28 @@ static void encode_sb_row(VP9_COMP *cpi,
         // Index of the MB in the SB 0..3
         xd->mb_index = j;
 
-        splitmodes_used += pick_mb_mode(cpi, mb_row + y_idx_m,
-                                        mb_col + x_idx_m, tp, &r, &d);
+        splitmodes_used += pick_mb_mode(cpi, mi_row + y_idx_m,
+                                        mi_col + x_idx_m, tp, &r, &d);
         sb32_rate += r;
         sb32_dist += d;
 
         // Dummy encode, do not do the tokenization
-        encode_macroblock(cpi, tp, 0, mb_row + y_idx_m,
-                          mb_col + x_idx_m);
+#if CONFIG_SB8X8
+        update_state(cpi, &x->mb_context[xd->sb_index][xd->mb_index],
+                     BLOCK_SIZE_MB16X16, 0);
+#endif
+        encode_macroblock(cpi, tp, 0, mi_row + y_idx_m,
+                          mi_col + x_idx_m);
       }
 
       /* Restore L & A coding context to those in place on entry */
-      vpx_memcpy(cm->left_context + y_idx, l2, sizeof(l2));
-      vpx_memcpy(cm->above_context + mb_col + x_idx, a2, sizeof(a2));
+      vpx_memcpy(cm->left_context + (y_idx >> CONFIG_SB8X8), l2, sizeof(l2));
+      vpx_memcpy(cm->above_context + ((mi_col + x_idx) >> CONFIG_SB8X8), a2,
+                 sizeof(a2));
 
-      xd->left_seg_context  = cm->left_seg_context + (y_idx & 3);
-      xd->above_seg_context = cm->above_seg_context + mb_col + x_idx;
+      xd->left_seg_context  = cm->left_seg_context + (y_idx >> CONFIG_SB8X8);
+      xd->above_seg_context =
+          cm->above_seg_context + ((mi_col + x_idx) >> CONFIG_SB8X8);
       pl = partition_plane_context(xd, BLOCK_SIZE_SB32X32);
       sb32_rate += x->partition_cost[pl][PARTITION_SPLIT];
 
@@ -1026,31 +1068,32 @@ static void encode_sb_row(VP9_COMP *cpi,
       }
 
       // check 32x16
-      if (mb_col + x_idx + 1 < cm->mb_cols) {
+      if (mi_col + x_idx + (2 << CONFIG_SB8X8) <= cm->mi_cols) {
         int r, d;
 
         xd->mb_index = 0;
-        pick_sb_modes(cpi, mb_row + y_idx, mb_col + x_idx,
+        pick_sb_modes(cpi, mi_row + y_idx, mi_col + x_idx,
                       tp, &r, &d, BLOCK_SIZE_SB32X16,
                       &x->sb32x16_context[xd->sb_index][xd->mb_index]);
-        if (mb_row + y_idx + 1 < cm->mb_rows) {
+        if (mi_row + y_idx + (1 << CONFIG_SB8X8) < cm->mi_rows) {
           int r2, d2;
 
           update_state(cpi, &x->sb32x16_context[xd->sb_index][xd->mb_index],
                        BLOCK_SIZE_SB32X16, 0);
           encode_superblock(cpi, tp,
-                            0, mb_row + y_idx, mb_col + x_idx,
+                            0, mi_row + y_idx, mi_col + x_idx,
                             BLOCK_SIZE_SB32X16);
           xd->mb_index = 1;
-          pick_sb_modes(cpi, mb_row + y_idx + 1, mb_col + x_idx,
-                        tp, &r2, &d2, BLOCK_SIZE_SB32X16,
+          pick_sb_modes(cpi, mi_row + y_idx + (1 << CONFIG_SB8X8),
+                        mi_col + x_idx, tp, &r2, &d2, BLOCK_SIZE_SB32X16,
                         &x->sb32x16_context[xd->sb_index][xd->mb_index]);
           r += r2;
           d += d2;
         }
 
-        xd->left_seg_context  = cm->left_seg_context + (y_idx & 3);
-        xd->above_seg_context = cm->above_seg_context + mb_col + x_idx;
+        xd->left_seg_context  = cm->left_seg_context + (y_idx >> CONFIG_SB8X8);
+        xd->above_seg_context =
+            cm->above_seg_context + ((mi_col + x_idx) >> CONFIG_SB8X8);
         pl = partition_plane_context(xd, BLOCK_SIZE_SB32X32);
         r += x->partition_cost[pl][PARTITION_HORZ];
 
@@ -1062,36 +1105,40 @@ static void encode_sb_row(VP9_COMP *cpi,
           sb_partitioning[i] = BLOCK_SIZE_SB32X16;
         }
 
-        vpx_memcpy(cm->left_context + y_idx, l2, sizeof(l2));
-        vpx_memcpy(cm->above_context + mb_col + x_idx, a2, sizeof(a2));
+        vpx_memcpy(cm->left_context + (y_idx >> CONFIG_SB8X8), l2, sizeof(l2));
+        vpx_memcpy(cm->above_context + ((mi_col + x_idx) >> CONFIG_SB8X8), a2,
+                   sizeof(a2));
       }
 
       // check 16x32
-      if (mb_row + y_idx + 1 < cm->mb_rows) {
+      if (mi_row + y_idx + (2 << CONFIG_SB8X8) <= cm->mi_rows) {
         int r, d;
 
         xd->mb_index = 0;
-        pick_sb_modes(cpi, mb_row + y_idx, mb_col + x_idx,
+        pick_sb_modes(cpi, mi_row + y_idx, mi_col + x_idx,
                       tp, &r, &d, BLOCK_SIZE_SB16X32,
                       &x->sb16x32_context[xd->sb_index][xd->mb_index]);
-        if (mb_col + x_idx + 1 < cm->mb_cols) {
+        if (mi_col + x_idx + (1 << CONFIG_SB8X8) < cm->mi_cols) {
           int r2, d2;
 
           update_state(cpi, &x->sb16x32_context[xd->sb_index][xd->mb_index],
                        BLOCK_SIZE_SB16X32, 0);
           encode_superblock(cpi, tp,
-                            0, mb_row + y_idx, mb_col + x_idx,
+                            0, mi_row + y_idx, mi_col + x_idx,
                             BLOCK_SIZE_SB16X32);
           xd->mb_index = 1;
-          pick_sb_modes(cpi, mb_row + y_idx, mb_col + x_idx + 1,
+          pick_sb_modes(cpi, mi_row + y_idx,
+                        mi_col + x_idx + (1 << CONFIG_SB8X8),
                         tp, &r2, &d2, BLOCK_SIZE_SB16X32,
                         &x->sb16x32_context[xd->sb_index][xd->mb_index]);
           r += r2;
           d += d2;
         }
 
-        xd->left_seg_context  = cm->left_seg_context + (y_idx & 3);
-        xd->above_seg_context = cm->above_seg_context + mb_col + x_idx;
+        xd->left_seg_context  =
+            cm->left_seg_context + (y_idx >> CONFIG_SB8X8);
+        xd->above_seg_context =
+            cm->above_seg_context + ((mi_col + x_idx) >> CONFIG_SB8X8);
         pl = partition_plane_context(xd, BLOCK_SIZE_SB32X32);
         r += x->partition_cost[pl][PARTITION_VERT];
 
@@ -1103,21 +1150,24 @@ static void encode_sb_row(VP9_COMP *cpi,
           sb_partitioning[i] = BLOCK_SIZE_SB16X32;
         }
 
-        vpx_memcpy(cm->left_context + y_idx, l2, sizeof(l2));
-        vpx_memcpy(cm->above_context + mb_col + x_idx, a2, sizeof(a2));
+        vpx_memcpy(cm->left_context + (y_idx >> CONFIG_SB8X8), l2, sizeof(l2));
+        vpx_memcpy(cm->above_context + ((mi_col + x_idx) >> CONFIG_SB8X8), a2,
+                   sizeof(a2));
       }
 
-      if (!sb32_skip && !(mb_col + x_idx + 1 >= cm->mb_cols ||
-                          mb_row + y_idx + 1 >= cm->mb_rows)) {
+      if (!sb32_skip &&
+          mi_col + x_idx + (2 << CONFIG_SB8X8) <= cm->mi_cols &&
+          mi_row + y_idx + (2 << CONFIG_SB8X8) <= cm->mi_rows) {
         int r, d;
 
         /* Pick a mode assuming that it applies to all 4 of the MBs in the SB */
-        pick_sb_modes(cpi, mb_row + y_idx, mb_col + x_idx,
+        pick_sb_modes(cpi, mi_row + y_idx, mi_col + x_idx,
                       tp, &r, &d, BLOCK_SIZE_SB32X32,
                       &x->sb32_context[xd->sb_index]);
 
-        xd->left_seg_context  = cm->left_seg_context + (y_idx & 3);
-        xd->above_seg_context = cm->above_seg_context + mb_col + x_idx;
+        xd->left_seg_context  = cm->left_seg_context + (y_idx >> CONFIG_SB8X8);
+        xd->above_seg_context =
+            cm->above_seg_context + ((mi_col + x_idx) >> CONFIG_SB8X8);
         pl = partition_plane_context(xd, BLOCK_SIZE_SB32X32);
         r += x->partition_cost[pl][PARTITION_NONE];
 
@@ -1143,37 +1193,38 @@ static void encode_sb_row(VP9_COMP *cpi,
       // pixels of the lower level; also, inverting SB/MB order (big->small
       // instead of small->big) means we can use as threshold for small, which
       // may enable breakouts if RD is not good enough (i.e. faster)
-      encode_sb(cpi, mb_row + y_idx, mb_col + x_idx, 0, tp,
+      encode_sb(cpi, mi_row + y_idx, mi_col + x_idx, 0, tp,
                 sb_partitioning[i]);
     }
 
-    memcpy(cm->above_context + mb_col, &a, sizeof(a));
+    memcpy(cm->above_context + (mi_col >> CONFIG_SB8X8), &a, sizeof(a));
     memcpy(cm->left_context, &l, sizeof(l));
-    memcpy(cm->above_seg_context + mb_col, &seg_a, sizeof(seg_a));
+    memcpy(cm->above_seg_context + (mi_col >> CONFIG_SB8X8), &seg_a,
+           sizeof(seg_a));
     memcpy(cm->left_seg_context, &seg_l, sizeof(seg_l));
 
     xd->left_seg_context  = cm->left_seg_context;
-    xd->above_seg_context = cm->above_seg_context + mb_col;
+    xd->above_seg_context = cm->above_seg_context + (mi_col >> CONFIG_SB8X8);
     pl = partition_plane_context(xd, BLOCK_SIZE_SB64X64);
     sb64_rate += x->partition_cost[pl][PARTITION_SPLIT];
 
     // check 64x32
-    if (mb_col + 3 < cm->mb_cols && !(cm->mb_rows & 1)) {
+    if (mi_col + (4 << CONFIG_SB8X8) <= cm->mi_cols && !(cm->mb_rows & 1)) {
       int r, d;
 
       xd->sb_index = 0;
-      pick_sb_modes(cpi, mb_row, mb_col,
+      pick_sb_modes(cpi, mi_row, mi_col,
                     tp, &r, &d, BLOCK_SIZE_SB64X32,
                     &x->sb64x32_context[xd->sb_index]);
-      if (mb_row + 2 != cm->mb_rows) {
+      if (mi_row + (2 << CONFIG_SB8X8) != cm->mi_rows) {
         int r2, d2;
 
         update_state(cpi, &x->sb64x32_context[xd->sb_index],
                      BLOCK_SIZE_SB64X32, 0);
         encode_superblock(cpi, tp,
-                          0, mb_row, mb_col, BLOCK_SIZE_SB64X32);
+                          0, mi_row, mi_col, BLOCK_SIZE_SB64X32);
         xd->sb_index = 1;
-        pick_sb_modes(cpi, mb_row + 2, mb_col,
+        pick_sb_modes(cpi, mi_row + (2 << CONFIG_SB8X8), mi_col,
                       tp, &r2, &d2, BLOCK_SIZE_SB64X32,
                       &x->sb64x32_context[xd->sb_index]);
         r += r2;
@@ -1181,7 +1232,7 @@ static void encode_sb_row(VP9_COMP *cpi,
       }
 
       xd->left_seg_context  = cm->left_seg_context;
-      xd->above_seg_context = cm->above_seg_context + mb_col;
+      xd->above_seg_context = cm->above_seg_context + (mi_col >> CONFIG_SB8X8);
       pl = partition_plane_context(xd, BLOCK_SIZE_SB64X64);
       r += x->partition_cost[pl][PARTITION_HORZ];
 
@@ -1194,26 +1245,26 @@ static void encode_sb_row(VP9_COMP *cpi,
       }
 
       vpx_memcpy(cm->left_context, l, sizeof(l));
-      vpx_memcpy(cm->above_context + mb_col, a, sizeof(a));
+      vpx_memcpy(cm->above_context + (mi_col >> CONFIG_SB8X8), a, sizeof(a));
     }
 
     // check 32x64
-    if (mb_row + 3 < cm->mb_rows && !(cm->mb_cols & 1)) {
+    if (mi_row + (4 << CONFIG_SB8X8) <= cm->mi_rows && !(cm->mb_cols & 1)) {
       int r, d;
 
       xd->sb_index = 0;
-      pick_sb_modes(cpi, mb_row, mb_col,
+      pick_sb_modes(cpi, mi_row, mi_col,
                     tp, &r, &d, BLOCK_SIZE_SB32X64,
                     &x->sb32x64_context[xd->sb_index]);
-      if (mb_col + 2 != cm->mb_cols) {
+      if (mi_col + (2 << CONFIG_SB8X8) != cm->mi_cols) {
         int r2, d2;
 
         update_state(cpi, &x->sb32x64_context[xd->sb_index],
                      BLOCK_SIZE_SB32X64, 0);
         encode_superblock(cpi, tp,
-                          0, mb_row, mb_col, BLOCK_SIZE_SB32X64);
+                          0, mi_row, mi_col, BLOCK_SIZE_SB32X64);
         xd->sb_index = 1;
-        pick_sb_modes(cpi, mb_row, mb_col + 2,
+        pick_sb_modes(cpi, mi_row, mi_col + (2 << CONFIG_SB8X8),
                       tp, &r2, &d2, BLOCK_SIZE_SB32X64,
                       &x->sb32x64_context[xd->sb_index]);
         r += r2;
@@ -1221,7 +1272,7 @@ static void encode_sb_row(VP9_COMP *cpi,
       }
 
       xd->left_seg_context  = cm->left_seg_context;
-      xd->above_seg_context = cm->above_seg_context + mb_col;
+      xd->above_seg_context = cm->above_seg_context + (mi_col >> CONFIG_SB8X8);
       pl = partition_plane_context(xd, BLOCK_SIZE_SB64X64);
       r += x->partition_cost[pl][PARTITION_VERT];
 
@@ -1234,18 +1285,19 @@ static void encode_sb_row(VP9_COMP *cpi,
       }
 
       vpx_memcpy(cm->left_context, l, sizeof(l));
-      vpx_memcpy(cm->above_context + mb_col, a, sizeof(a));
+      vpx_memcpy(cm->above_context + (mi_col >> CONFIG_SB8X8), a, sizeof(a));
     }
 
-    if (!sb64_skip && !(mb_col + 3 >= cm->mb_cols ||
-                        mb_row + 3 >= cm->mb_rows)) {
+    if (!sb64_skip &&
+        mi_col + (4 << CONFIG_SB8X8) <= cm->mi_cols &&
+        mi_row + (4 << CONFIG_SB8X8) <= cm->mi_rows) {
       int r, d;
 
-      pick_sb_modes(cpi, mb_row, mb_col, tp, &r, &d,
+      pick_sb_modes(cpi, mi_row, mi_col, tp, &r, &d,
                     BLOCK_SIZE_SB64X64, &x->sb64_context);
 
       xd->left_seg_context  = cm->left_seg_context;
-      xd->above_seg_context = cm->above_seg_context + mb_col;
+      xd->above_seg_context = cm->above_seg_context + (mi_col >> CONFIG_SB8X8);
       pl = partition_plane_context(xd, BLOCK_SIZE_SB64X64);
       r += x->partition_cost[pl][PARTITION_NONE];
 
@@ -1258,7 +1310,7 @@ static void encode_sb_row(VP9_COMP *cpi,
     }
 
     assert(tp_orig == *tp);
-    encode_sb64(cpi, mb_row, mb_col, tp, sb_partitioning);
+    encode_sb64(cpi, mi_row, mi_col, tp, sb_partitioning);
     assert(tp_orig < *tp);
   }
 }
@@ -1342,7 +1394,7 @@ static void switch_lossless_mode(VP9_COMP *cpi, int lossless) {
 
 
 static void encode_frame_internal(VP9_COMP *cpi) {
-  int mb_row;
+  int mi_row;
   MACROBLOCK *const x = &cpi->mb;
   VP9_COMMON *const cm = &cpi->common;
   MACROBLOCKD *const xd = &x->e_mbd;
@@ -1440,9 +1492,10 @@ static void encode_frame_internal(VP9_COMP *cpi) {
 
           // For each row of SBs in the frame
           vp9_get_tile_col_offsets(cm, tile_col);
-          for (mb_row = cm->cur_tile_mb_row_start;
-               mb_row < cm->cur_tile_mb_row_end; mb_row += 4) {
-            encode_sb_row(cpi, mb_row, &tp, &totalrate);
+          for (mi_row = cm->cur_tile_mi_row_start;
+               mi_row < cm->cur_tile_mi_row_end;
+               mi_row += (4 << CONFIG_SB8X8)) {
+            encode_sb_row(cpi, mi_row, &tp, &totalrate);
           }
           cpi->tok_count[tile_col] = (unsigned int)(tp - tp_old);
           assert(tp - cpi->tok <=
@@ -1513,7 +1566,7 @@ static void set_txfm_flag(MODE_INFO *mi, int mis, int ymbs, int xmbs,
 
 static void reset_skip_txfm_size_sb(VP9_COMP *cpi, MODE_INFO *mi,
                                     int mis, TX_SIZE txfm_max,
-                                    int mb_rows_left, int mb_cols_left,
+                                    int mi_rows_left, int mi_cols_left,
                                     BLOCK_SIZE_TYPE bsize) {
   MB_MODE_INFO *const mbmi = &mi->mbmi;
 
@@ -1521,9 +1574,9 @@ static void reset_skip_txfm_size_sb(VP9_COMP *cpi, MODE_INFO *mi,
     MACROBLOCK *const x = &cpi->mb;
     MACROBLOCKD *const xd = &x->e_mbd;
     const int segment_id = mbmi->segment_id;
-    const int bh = 1 << mb_height_log2(bsize), bw = 1 << mb_width_log2(bsize);
-    const int ymbs = MIN(bh, mb_rows_left);
-    const int xmbs = MIN(bw, mb_cols_left);
+    const int bh = 1 << mi_height_log2(bsize), bw = 1 << mi_width_log2(bsize);
+    const int ymbs = MIN(bh, mi_rows_left);
+    const int xmbs = MIN(bw, mi_cols_left);
 
     xd->mode_info_context = mi;
     assert(vp9_segfeature_active(xd, segment_id, SEG_LVL_SKIP) ||
@@ -1534,87 +1587,96 @@ static void reset_skip_txfm_size_sb(VP9_COMP *cpi, MODE_INFO *mi,
 
 static void reset_skip_txfm_size(VP9_COMP *cpi, TX_SIZE txfm_max) {
   VP9_COMMON *const cm = &cpi->common;
-  int mb_row, mb_col;
+  int mi_row, mi_col;
   const int mis = cm->mode_info_stride;
   MODE_INFO *mi, *mi_ptr = cm->mi;
 
-  for (mb_row = 0; mb_row < cm->mb_rows; mb_row += 4, mi_ptr += 4 * mis) {
+  for (mi_row = 0; mi_row < cm->mi_rows;
+       mi_row += (4 << CONFIG_SB8X8), mi_ptr += (4 << CONFIG_SB8X8) * mis) {
     mi = mi_ptr;
-    for (mb_col = 0; mb_col < cm->mb_cols; mb_col += 4, mi += 4) {
+    for (mi_col = 0; mi_col < cm->mi_cols;
+         mi_col += (4 << CONFIG_SB8X8), mi += (4 << CONFIG_SB8X8)) {
       if (mi->mbmi.sb_type == BLOCK_SIZE_SB64X64) {
         reset_skip_txfm_size_sb(cpi, mi, mis, txfm_max,
-                                cm->mb_rows - mb_row, cm->mb_cols - mb_col,
+                                cm->mi_rows - mi_row, cm->mi_cols - mi_col,
                                 BLOCK_SIZE_SB64X64);
       } else if (mi->mbmi.sb_type == BLOCK_SIZE_SB64X32) {
         reset_skip_txfm_size_sb(cpi, mi, mis, txfm_max,
-                                cm->mb_rows - mb_row, cm->mb_cols - mb_col,
+                                cm->mi_rows - mi_row, cm->mi_cols - mi_col,
                                 BLOCK_SIZE_SB64X32);
-        if (mb_row + 2 != cm->mb_rows)
-          reset_skip_txfm_size_sb(cpi, mi + 2 * mis, mis, txfm_max,
-                                  cm->mb_rows - mb_row - 2,
-                                  cm->mb_cols - mb_col,
+        if (mi_row + (2 << CONFIG_SB8X8) != cm->mi_rows)
+          reset_skip_txfm_size_sb(cpi, mi + (2 << CONFIG_SB8X8) * mis, mis,
+                                  txfm_max,
+                                  cm->mi_rows - mi_row - (2 << CONFIG_SB8X8),
+                                  cm->mi_cols - mi_col,
                                   BLOCK_SIZE_SB64X32);
       } else if (mi->mbmi.sb_type == BLOCK_SIZE_SB32X64) {
         reset_skip_txfm_size_sb(cpi, mi, mis, txfm_max,
-                                cm->mb_rows - mb_row, cm->mb_cols - mb_col,
+                                cm->mi_rows - mi_row, cm->mi_cols - mi_col,
                                 BLOCK_SIZE_SB32X64);
-        if (mb_col + 2 != cm->mb_cols)
-          reset_skip_txfm_size_sb(cpi, mi + 2, mis, txfm_max,
-                                  cm->mb_rows - mb_row,
-                                  cm->mb_cols - mb_col - 2,
+        if (mi_col + (2 << CONFIG_SB8X8) != cm->mi_cols)
+          reset_skip_txfm_size_sb(cpi, mi + (2 << CONFIG_SB8X8), mis, txfm_max,
+                                  cm->mi_rows - mi_row,
+                                  cm->mi_cols - mi_col - (2 << CONFIG_SB8X8),
                                   BLOCK_SIZE_SB32X64);
       } else {
         int i;
 
         for (i = 0; i < 4; i++) {
-          const int x_idx_sb = (i & 1) << 1, y_idx_sb = i & 2;
+          const int x_idx_sb = (i & 1) << (1 + CONFIG_SB8X8);
+          const int y_idx_sb = (i & 2) << CONFIG_SB8X8;
           MODE_INFO *sb_mi = mi + y_idx_sb * mis + x_idx_sb;
 
-          if (mb_row + y_idx_sb >= cm->mb_rows ||
-              mb_col + x_idx_sb >= cm->mb_cols)
+          if (mi_row + y_idx_sb >= cm->mi_rows ||
+              mi_col + x_idx_sb >= cm->mi_cols)
             continue;
 
           if (sb_mi->mbmi.sb_type == BLOCK_SIZE_SB32X32) {
             reset_skip_txfm_size_sb(cpi, sb_mi, mis, txfm_max,
-                                    cm->mb_rows - mb_row - y_idx_sb,
-                                    cm->mb_cols - mb_col - x_idx_sb,
+                                    cm->mi_rows - mi_row - y_idx_sb,
+                                    cm->mi_cols - mi_col - x_idx_sb,
                                     BLOCK_SIZE_SB32X32);
           } else if (sb_mi->mbmi.sb_type == BLOCK_SIZE_SB32X16) {
             reset_skip_txfm_size_sb(cpi, sb_mi, mis, txfm_max,
-                                    cm->mb_rows - mb_row - y_idx_sb,
-                                    cm->mb_cols - mb_col - x_idx_sb,
+                                    cm->mi_rows - mi_row - y_idx_sb,
+                                    cm->mi_cols - mi_col - x_idx_sb,
                                     BLOCK_SIZE_SB32X16);
-            if (mb_row + y_idx_sb + 1 != cm->mb_rows)
-              reset_skip_txfm_size_sb(cpi, sb_mi + mis, mis, txfm_max,
-                                      cm->mb_rows - mb_row - y_idx_sb - 1,
-                                      cm->mb_cols - mb_col - x_idx_sb,
+            if (mi_row + y_idx_sb + (1 << CONFIG_SB8X8) != cm->mi_rows)
+              reset_skip_txfm_size_sb(cpi, sb_mi + (mis << CONFIG_SB8X8), mis,
+                                      txfm_max,
+                                      cm->mi_rows - mi_row - y_idx_sb -
+                                          (1 << CONFIG_SB8X8),
+                                      cm->mi_cols - mi_col - x_idx_sb,
                                       BLOCK_SIZE_SB32X16);
           } else if (sb_mi->mbmi.sb_type == BLOCK_SIZE_SB16X32) {
             reset_skip_txfm_size_sb(cpi, sb_mi, mis, txfm_max,
-                                    cm->mb_rows - mb_row - y_idx_sb,
-                                    cm->mb_cols - mb_col - x_idx_sb,
+                                    cm->mi_rows - mi_row - y_idx_sb,
+                                    cm->mi_cols - mi_col - x_idx_sb,
                                     BLOCK_SIZE_SB16X32);
-            if (mb_col + x_idx_sb + 1 != cm->mb_cols)
-              reset_skip_txfm_size_sb(cpi, sb_mi + 1, mis, txfm_max,
-                                      cm->mb_rows - mb_row - y_idx_sb,
-                                      cm->mb_cols - mb_col - x_idx_sb - 1,
+            if (mi_col + x_idx_sb + (1 << CONFIG_SB8X8) != cm->mi_cols)
+              reset_skip_txfm_size_sb(cpi, sb_mi + (1 << CONFIG_SB8X8), mis,
+                                      txfm_max,
+                                      cm->mi_rows - mi_row - y_idx_sb,
+                                      cm->mi_cols - mi_col - x_idx_sb -
+                                          (1 << CONFIG_SB8X8),
                                       BLOCK_SIZE_SB16X32);
           } else {
             int m;
 
             for (m = 0; m < 4; m++) {
-              const int x_idx = x_idx_sb + (m & 1), y_idx = y_idx_sb + (m >> 1);
+              const int x_idx = x_idx_sb + ((m & 1) << CONFIG_SB8X8);
+              const int y_idx = y_idx_sb + ((m >> 1) << CONFIG_SB8X8);
               MODE_INFO *mb_mi;
 
-              if (mb_col + x_idx >= cm->mb_cols ||
-                  mb_row + y_idx >= cm->mb_rows)
+              if (mi_col + x_idx >= cm->mi_cols ||
+                  mi_row + y_idx >= cm->mi_rows)
                 continue;
 
               mb_mi = mi + y_idx * mis + x_idx;
               assert(mb_mi->mbmi.sb_type == BLOCK_SIZE_MB16X16);
               reset_skip_txfm_size_sb(cpi, mb_mi, mis, txfm_max,
-                                      cm->mb_rows - mb_row - y_idx,
-                                      cm->mb_cols - mb_col - x_idx,
+                                      cm->mi_rows - mi_row - y_idx,
+                                      cm->mi_cols - mi_col - x_idx,
                                       BLOCK_SIZE_MB16X16);
             }
           }
@@ -1858,13 +1920,16 @@ static void adjust_act_zbin(VP9_COMP *cpi, MACROBLOCK *x) {
 
 static void encode_macroblock(VP9_COMP *cpi, TOKENEXTRA **t,
                               int output_enabled,
-                              int mb_row, int mb_col) {
+                              int mi_row, int mi_col) {
   VP9_COMMON *const cm = &cpi->common;
   MACROBLOCK *const x = &cpi->mb;
   MACROBLOCKD *const xd = &x->e_mbd;
   MODE_INFO *mi = xd->mode_info_context;
   MB_MODE_INFO *const mbmi = &mi->mbmi;
   const int mis = cm->mode_info_stride;
+#if CONFIG_SB8X8
+  int n;
+#endif
 
   assert(xd->mode_info_context->mbmi.sb_type == BLOCK_SIZE_MB16X16);
 
@@ -1963,12 +2028,12 @@ static void encode_macroblock(VP9_COMP *cpi, TOKENEXTRA **t,
         &cpi->common.yv12_fb[ref_fb_idx],
         mbmi->second_ref_frame > 0 ? &cpi->common.yv12_fb[second_ref_fb_idx]
                                    : NULL,
-        mb_row, mb_col, xd->scale_factor, xd->scale_factor_uv);
+        mi_row, mi_col, xd->scale_factor, xd->scale_factor_uv);
 
     if (!x->skip) {
-      vp9_encode_inter16x16(cm, x, mb_row, mb_col);
+      vp9_encode_inter16x16(cm, x, mi_row, mi_col);
     } else {
-      vp9_build_inter_predictors_sb(xd, mb_row, mb_col, BLOCK_SIZE_MB16X16);
+      vp9_build_inter_predictors_sb(xd, mi_row, mi_col, BLOCK_SIZE_MB16X16);
 #if CONFIG_COMP_INTERINTRA_PRED
       if (xd->mode_info_context->mbmi.second_ref_frame == INTRA_FRAME) {
         vp9_build_interintra_predictors(xd,
@@ -2049,6 +2114,16 @@ static void encode_macroblock(VP9_COMP *cpi, TOKENEXTRA **t,
     vp9_reset_sb_tokens_context(xd, BLOCK_SIZE_MB16X16);
   }
 
+#if CONFIG_SB8X8
+  // copy skip flag on all mb_mode_info contexts in this SB
+  // if this was a skip at this txfm size
+  for (n = 1; n < 4; n++) {
+    const int x_idx = n & 1, y_idx = n >> 1;
+    if (mi_col + x_idx < cm->mi_cols && mi_row + y_idx < cm->mi_rows)
+      mi[x_idx + y_idx * mis].mbmi.mb_skip_coeff = mi->mbmi.mb_skip_coeff;
+  }
+#endif
+
   if (output_enabled) {
     int segment_id = mbmi->segment_id;
     if (cpi->common.txfm_mode == TX_MODE_SELECT &&
@@ -2063,22 +2138,38 @@ static void encode_macroblock(VP9_COMP *cpi, TOKENEXTRA **t,
                   mbmi->partitioning != PARTITIONING_4X4)) {
         cpi->txfm_count_8x8p[mbmi->txfm_size]++;
       }
-    } else if (mbmi->mode != I4X4_PRED && mbmi->mode != I8X8_PRED &&
-        mbmi->mode != SPLITMV && cpi->common.txfm_mode >= ALLOW_16X16) {
-      mbmi->txfm_size = TX_16X16;
-    } else if (mbmi->mode != I4X4_PRED &&
-               !(mbmi->mode == SPLITMV &&
-                 mbmi->partitioning == PARTITIONING_4X4) &&
-               cpi->common.txfm_mode >= ALLOW_8X8) {
-      mbmi->txfm_size = TX_8X8;
     } else {
-      mbmi->txfm_size = TX_4X4;
+#if CONFIG_SB8X8
+      int y, x;
+#endif
+
+      if (mbmi->mode != I4X4_PRED && mbmi->mode != I8X8_PRED &&
+          mbmi->mode != SPLITMV && cpi->common.txfm_mode >= ALLOW_16X16) {
+        mbmi->txfm_size = TX_16X16;
+      } else if (mbmi->mode != I4X4_PRED &&
+                 !(mbmi->mode == SPLITMV &&
+                   mbmi->partitioning == PARTITIONING_4X4) &&
+                 cpi->common.txfm_mode >= ALLOW_8X8) {
+        mbmi->txfm_size = TX_8X8;
+      } else {
+        mbmi->txfm_size = TX_4X4;
+      }
+
+#if CONFIG_SB8X8
+      for (y = 0; y < 2; y++) {
+        for (x = !y; x < 2; x++) {
+          if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) {
+            mi[mis * y + x].mbmi.txfm_size = mbmi->txfm_size;
+          }
+        }
+      }
+#endif
     }
   }
 }
 
 static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t,
-                              int output_enabled, int mb_row, int mb_col,
+                              int output_enabled, int mi_row, int mi_col,
                               BLOCK_SIZE_TYPE bsize) {
   VP9_COMMON *const cm = &cpi->common;
   MACROBLOCK *const x = &cpi->mb;
@@ -2087,8 +2178,8 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t,
   MODE_INFO *mi = x->e_mbd.mode_info_context;
   unsigned int segment_id = mi->mbmi.segment_id;
   const int mis = cm->mode_info_stride;
-  const int bwl = mb_width_log2(bsize);
-  const int bw = 1 << bwl, bh = 1 << mb_height_log2(bsize);
+  const int bwl = mi_width_log2(bsize);
+  const int bw = 1 << bwl, bh = 1 << mi_height_log2(bsize);
 
   if (cm->frame_type == KEY_FRAME) {
     if (cpi->oxcf.tuning == VP8_TUNE_SSIM) {
@@ -2156,9 +2247,9 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t,
         &cpi->common.yv12_fb[ref_fb_idx],
         xd->mode_info_context->mbmi.second_ref_frame > 0
             ? &cpi->common.yv12_fb[second_ref_fb_idx] : NULL,
-        mb_row, mb_col, xd->scale_factor, xd->scale_factor_uv);
+        mi_row, mi_col, xd->scale_factor, xd->scale_factor_uv);
 
-    vp9_build_inter_predictors_sb(xd, mb_row, mb_col, bsize);
+    vp9_build_inter_predictors_sb(xd, mi_row, mi_col, bsize);
   }
 
   if (!x->skip) {
@@ -2254,7 +2345,7 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t,
   // if this was a skip at this txfm size
   for (n = 1; n < bw * bh; n++) {
     const int x_idx = n & (bw - 1), y_idx = n >> bwl;
-    if (mb_col + x_idx < cm->mb_cols && mb_row + y_idx < cm->mb_rows)
+    if (mi_col + x_idx < cm->mi_cols && mi_row + y_idx < cm->mi_rows)
       mi[x_idx + y_idx * mis].mbmi.mb_skip_coeff = mi->mbmi.mb_skip_coeff;
   }
 
@@ -2276,7 +2367,7 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t,
 
       for (y = 0; y < bh; y++) {
         for (x = 0; x < bw; x++) {
-          if (mb_col + x < cm->mb_cols && mb_row + y < cm->mb_rows) {
+          if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) {
             mi[mis * y + x].mbmi.txfm_size = sz;
           }
         }
index a11bb3e..0823316 100644 (file)
@@ -764,20 +764,20 @@ void vp9_fidct_mb(VP9_COMMON *const cm, MACROBLOCK *x) {
 }
 
 void vp9_encode_inter16x16(VP9_COMMON *const cm, MACROBLOCK *x,
-                           int mb_row, int mb_col) {
+                           int mi_row, int mi_col) {
   MACROBLOCKD *const xd = &x->e_mbd;
 
-  vp9_build_inter_predictors_sb(xd, mb_row, mb_col, BLOCK_SIZE_MB16X16);
+  vp9_build_inter_predictors_sb(xd, mi_row, mi_col, BLOCK_SIZE_MB16X16);
   vp9_subtract_sb(x, BLOCK_SIZE_MB16X16);
   vp9_fidct_mb(cm, x);
   vp9_recon_sb(xd, BLOCK_SIZE_MB16X16);
 }
 
 /* this function is used by first pass only */
-void vp9_encode_inter16x16y(MACROBLOCK *x, int mb_row, int mb_col) {
+void vp9_encode_inter16x16y(MACROBLOCK *x, int mi_row, int mi_col) {
   MACROBLOCKD *xd = &x->e_mbd;
 
-  vp9_build_inter_predictors_sby(xd, mb_row, mb_col, BLOCK_SIZE_MB16X16);
+  vp9_build_inter_predictors_sby(xd, mi_row, mi_col, BLOCK_SIZE_MB16X16);
   vp9_subtract_sby(x, BLOCK_SIZE_MB16X16);
 
   vp9_transform_sby_4x4(x, BLOCK_SIZE_MB16X16);
index 607cd99..e4d6863 100644 (file)
@@ -520,9 +520,12 @@ void vp9_first_pass(VP9_COMP *cpi) {
       int gf_motion_error = INT_MAX;
       int use_dc_pred = (mb_col || mb_row) && (!mb_col || !mb_row);
 
-      set_mb_row_col(cm, xd,
-                     mb_row, 1 << mb_height_log2(BLOCK_SIZE_MB16X16),
-                     mb_col, 1 << mb_height_log2(BLOCK_SIZE_MB16X16));
+      set_mi_row_col(cm, xd,
+                     mb_row << CONFIG_SB8X8,
+                     1 << mi_height_log2(BLOCK_SIZE_MB16X16),
+                     mb_col << CONFIG_SB8X8,
+                     1 << mi_height_log2(BLOCK_SIZE_MB16X16));
+
       xd->plane[0].dst.buf = new_yv12->y_buffer + recon_yoffset;
       xd->plane[1].dst.buf = new_yv12->u_buffer + recon_uvoffset;
       xd->plane[2].dst.buf = new_yv12->v_buffer + recon_uvoffset;
index 27e9ece..fe5d114 100644 (file)
@@ -386,10 +386,22 @@ static void separate_arf_mbs(VP9_COMP *cpi) {
       // goes in segment 0
       if (arf_not_zz[offset + mb_col]) {
         ncnt[0]++;
+#if CONFIG_SB8X8
+        cpi->segmentation_map[offset * 4 + 2 * mb_col] = 0;
+        cpi->segmentation_map[offset * 4 + 2 * mb_col + 1] = 0;
+        cpi->segmentation_map[offset * 4 + 2 * mb_col + cm->mi_cols] = 0;
+        cpi->segmentation_map[offset * 4 + 2 * mb_col + cm->mi_cols + 1] = 0;
+      } else {
+        cpi->segmentation_map[offset * 4 + 2 * mb_col] = 1;
+        cpi->segmentation_map[offset * 4 + 2 * mb_col + 1] = 1;
+        cpi->segmentation_map[offset * 4 + 2 * mb_col + cm->mi_cols] = 1;
+        cpi->segmentation_map[offset * 4 + 2 * mb_col + cm->mi_cols + 1] = 1;
+#else
         cpi->segmentation_map[offset + mb_col] = 0;
       } else {
-        ncnt[1]++;
         cpi->segmentation_map[offset + mb_col] = 1;
+#endif
+        ncnt[1]++;
       }
     }
   }
index 0b64fe1..d557c6e 100644 (file)
@@ -379,7 +379,7 @@ static void configure_static_seg_features(VP9_COMP *cpi) {
   // Disable and clear down for KF
   if (cm->frame_type == KEY_FRAME) {
     // Clear down the global segmentation map
-    vpx_memset(cpi->segmentation_map, 0, (cm->mb_rows * cm->mb_cols));
+    vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
     xd->update_mb_segmentation_map = 0;
     xd->update_mb_segmentation_data = 0;
 #if CONFIG_IMPLICIT_SEGMENTATION
@@ -395,7 +395,7 @@ static void configure_static_seg_features(VP9_COMP *cpi) {
   } else if (cpi->refresh_alt_ref_frame) {
     // If this is an alt ref frame
     // Clear down the global segmentation map
-    vpx_memset(cpi->segmentation_map, 0, (cm->mb_rows * cm->mb_cols));
+    vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
     xd->update_mb_segmentation_map = 0;
     xd->update_mb_segmentation_data = 0;
 #if CONFIG_IMPLICIT_SEGMENTATION
@@ -460,8 +460,7 @@ static void configure_static_seg_features(VP9_COMP *cpi) {
       else {
         vp9_disable_segmentation((VP9_PTR)cpi);
 
-        vpx_memset(cpi->segmentation_map, 0,
-                   (cm->mb_rows * cm->mb_cols));
+        vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
 
         xd->update_mb_segmentation_map = 0;
         xd->update_mb_segmentation_data = 0;
@@ -549,8 +548,8 @@ static void print_seg_map(VP9_COMP *cpi) {
 
   fprintf(statsfile, "%10d\n", cm->current_video_frame);
 
-  for (row = 0; row < cpi->common.mb_rows; row++) {
-    for (col = 0; col < cpi->common.mb_cols; col++) {
+  for (row = 0; row < cpi->common.mi_rows; row++) {
+    for (col = 0; col < cpi->common.mi_cols; col++) {
       fprintf(statsfile, "%10d", cpi->segmentation_map[map_index]);
       map_index++;
     }
@@ -567,13 +566,13 @@ static void update_reference_segmentation_map(VP9_COMP *cpi) {
   MODE_INFO *mi, *mi_ptr = cm->mi;
   uint8_t *cache_ptr = cm->last_frame_seg_map, *cache;
 
-  for (row = 0; row < cm->mb_rows; row++) {
+  for (row = 0; row < cm->mi_rows; row++) {
     mi = mi_ptr;
     cache = cache_ptr;
-    for (col = 0; col < cm->mb_cols; col++, mi++, cache++)
+    for (col = 0; col < cm->mi_cols; col++, mi++, cache++)
       cache[0] = mi->mbmi.segment_id;
     mi_ptr += cm->mode_info_stride;
-    cache_ptr += cm->mb_cols;
+    cache_ptr += cm->mi_cols;
   }
 }
 
@@ -907,7 +906,7 @@ static int alloc_partition_data(VP9_COMP *cpi) {
   vpx_free(cpi->mb.pip);
 
   cpi->mb.pip = vpx_calloc((cpi->common.mode_info_stride) *
-                           (cpi->common.mb_rows + 1),
+                           (cpi->common.mi_rows + 1),
                            sizeof(PARTITION_INFO));
   if (!cpi->mb.pip)
     return 1;
@@ -987,11 +986,13 @@ static void update_frame_size(VP9_COMP *cpi) {
   const int aligned_height = multiple16(cm->height);
 
   cm->mb_rows = aligned_height >> 4;
+  cm->mi_rows = aligned_height >> LOG2_MI_SIZE;
   cm->mb_cols = aligned_width >> 4;
+  cm->mi_cols = aligned_width >> LOG2_MI_SIZE;
   cm->MBs = cm->mb_rows * cm->mb_cols;
-  cm->mode_info_stride = cm->mb_cols + 1;
+  cm->mode_info_stride = cm->mi_cols + 1;
   memset(cm->mip, 0,
-        cm->mode_info_stride * (cm->mb_rows + 1) * sizeof(MODE_INFO));
+        cm->mode_info_stride * (cm->mi_rows + 1) * sizeof(MODE_INFO));
   vp9_update_mode_info_border(cm, cm->mip);
 
   cm->mi = cm->mip + cm->mode_info_stride + 1;
@@ -1434,16 +1435,17 @@ VP9_PTR vp9_create_compressor(VP9_CONFIG *oxcf) {
   cpi->gold_is_alt  = 0;
 
   // Create the encoder segmentation map and set all entries to 0
-  CHECK_MEM_ERROR(cpi->segmentation_map, vpx_calloc((cpi->common.mb_rows * cpi->common.mb_cols), 1));
+  CHECK_MEM_ERROR(cpi->segmentation_map,
+                  vpx_calloc(cpi->common.mi_rows * cpi->common.mi_cols, 1));
 
   // And a copy in common for temporal coding
   CHECK_MEM_ERROR(cm->last_frame_seg_map,
-                  vpx_calloc((cpi->common.mb_rows * cpi->common.mb_cols), 1));
+                  vpx_calloc(cpi->common.mi_rows * cpi->common.mi_cols, 1));
 
   // And a place holder structure is the coding context
   // for use if we want to save and restore it
   CHECK_MEM_ERROR(cpi->coding_context.last_frame_seg_map_copy,
-                  vpx_calloc((cpi->common.mb_rows * cpi->common.mb_cols), 1));
+                  vpx_calloc(cpi->common.mi_rows * cpi->common.mi_cols, 1));
 
   CHECK_MEM_ERROR(cpi->active_map, vpx_calloc(cpi->common.mb_rows * cpi->common.mb_cols, 1));
   vpx_memset(cpi->active_map, 1, (cpi->common.mb_rows * cpi->common.mb_cols));
@@ -3336,6 +3338,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
     vp9_adapt_zpc_probs(&cpi->common);
 #endif
   }
+
   if (cpi->common.frame_type != KEY_FRAME) {
     vp9_copy(cpi->common.fc.sb_ymode_counts, cpi->sb_ymode_count);
     vp9_copy(cpi->common.fc.ymode_counts, cpi->ymode_count);
@@ -3668,10 +3671,12 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
 
   if (cm->show_frame) {
     vpx_memcpy(cm->prev_mip, cm->mip,
-               cm->mode_info_stride * (cm->mb_rows + 1) * sizeof(MODE_INFO));
+               cm->mode_info_stride * (cm->mi_rows + 1) *
+               sizeof(MODE_INFO));
   } else {
     vpx_memset(cm->prev_mip, 0,
-               cm->mode_info_stride * (cm->mb_rows + 1) * sizeof(MODE_INFO));
+               cm->mode_info_stride * (cm->mi_rows + 1) *
+               sizeof(MODE_INFO));
   }
 }
 
index 7a419fb..f593852 100644 (file)
@@ -159,7 +159,7 @@ void vp9_save_coding_context(VP9_COMP *cpi) {
   vp9_copy(cc->prob_comppred, cm->prob_comppred);
 
   vpx_memcpy(cpi->coding_context.last_frame_seg_map_copy,
-             cm->last_frame_seg_map, (cm->mb_rows * cm->mb_cols));
+             cm->last_frame_seg_map, (cm->mi_rows * cm->mi_cols));
 
   vp9_copy(cc->last_ref_lf_deltas, xd->last_ref_lf_deltas);
   vp9_copy(cc->last_mode_lf_deltas, xd->last_mode_lf_deltas);
@@ -221,7 +221,7 @@ void vp9_restore_coding_context(VP9_COMP *cpi) {
 
   vpx_memcpy(cm->last_frame_seg_map,
              cpi->coding_context.last_frame_seg_map_copy,
-             (cm->mb_rows * cm->mb_cols));
+             (cm->mi_rows * cm->mi_cols));
 
   vp9_copy(xd->last_ref_lf_deltas, cc->last_ref_lf_deltas);
   vp9_copy(xd->last_mode_lf_deltas, cc->last_mode_lf_deltas);
index 7de5bf7..058a2da 100644 (file)
@@ -1606,7 +1606,7 @@ static int labels2mode(
   int_mv seg_mvs[MAX_REF_FRAMES - 1],
   int_mv *best_ref_mv,
   int_mv *second_best_ref_mv,
-  int *mvjcost, int *mvcost[2]) {
+  int *mvjcost, int *mvcost[2], VP9_COMP *cpi) {
   MACROBLOCKD *const xd = &x->e_mbd;
   MODE_INFO *const mic = xd->mode_info_context;
   MB_MODE_INFO * mbmi = &mic->mbmi;
@@ -2167,7 +2167,7 @@ static void rd_check_segment_txsize(VP9_COMP *cpi, MACROBLOCK *x,
       rate = labels2mode(x, labels, i, this_mode, &mode_mv[this_mode],
                          &second_mode_mv[this_mode], seg_mvs[i],
                          bsi->ref_mv, bsi->second_ref_mv, x->nmvjointcost,
-                         x->mvcost);
+                         x->mvcost, cpi);
 
       // Trap vectors that reach beyond the UMV borders
       if (((mode_mv[this_mode].as_mv.row >> 3) < x->mv_row_min) ||
@@ -2226,7 +2226,8 @@ static void rd_check_segment_txsize(VP9_COMP *cpi, MACROBLOCK *x,
 
     labels2mode(x, labels, i, mode_selected, &mode_mv[mode_selected],
                 &second_mode_mv[mode_selected], seg_mvs[i],
-                bsi->ref_mv, bsi->second_ref_mv, x->nmvjointcost, x->mvcost);
+                bsi->ref_mv, bsi->second_ref_mv, x->nmvjointcost,
+                x->mvcost, cpi);
 
     br += sbr;
     bd += sbd;
@@ -2735,7 +2736,7 @@ static void store_coding_context(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx,
 static void setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x,
                                int idx, MV_REFERENCE_FRAME frame_type,
                                enum BlockSize block_size,
-                               int mb_row, int mb_col,
+                               int mi_row, int mi_col,
                                int_mv frame_nearest_mv[MAX_REF_FRAMES],
                                int_mv frame_near_mv[MAX_REF_FRAMES],
                                int frame_mdcounts[4][4],
@@ -2750,13 +2751,15 @@ static void setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x,
   // set up scaling factors
   scale[frame_type] = cpi->common.active_ref_scale[frame_type - 1];
   scale[frame_type].x_offset_q4 =
-      (mb_col * 16 * scale[frame_type].x_num / scale[frame_type].x_den) & 0xf;
+      (mi_col * MI_SIZE * scale[frame_type].x_num /
+       scale[frame_type].x_den) & 0xf;
   scale[frame_type].y_offset_q4 =
-      (mb_row * 16 * scale[frame_type].y_num / scale[frame_type].y_den) & 0xf;
+      (mi_row * MI_SIZE * scale[frame_type].y_num /
+       scale[frame_type].y_den) & 0xf;
 
   // TODO(jkoleszar): Is the UV buffer ever used here? If so, need to make this
   // use the UV scaling factors.
-  setup_pred_block(&yv12_mb[frame_type], yv12, mb_row, mb_col,
+  setup_pred_block(&yv12_mb[frame_type], yv12, mi_row, mi_col,
                    &scale[frame_type], &scale[frame_type]);
 
   // Gets an initial list of candidate vectors from neighbours and orders them
@@ -2873,8 +2876,8 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
                                  int_mv frame_mv[MB_MODE_COUNT]
                                                 [MAX_REF_FRAMES],
                                  YV12_BUFFER_CONFIG *scaled_ref_frame,
-                                 int mb_row, int mb_col) {
-  const int bw = 1 << mb_width_log2(bsize), bh = 1 << mb_height_log2(bsize);
+                                 int mi_row, int mi_col) {
+  const int bw = 1 << mi_width_log2(bsize), bh = 1 << mi_height_log2(bsize);
   const enum BlockSize block_size = y_bsizet_to_block_size(bsize);
   const enum BlockSize uv_block_size = y_to_uv_block_size(block_size);
   VP9_COMMON *cm = &cpi->common;
@@ -2939,7 +2942,7 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
           for (i = 0; i < MAX_MB_PLANE; i++)
             backup_yv12[i] = xd->plane[i].pre[0];
 
-          setup_pre_planes(xd, scaled_ref_frame, NULL, mb_row, mb_col,
+          setup_pre_planes(xd, scaled_ref_frame, NULL, mi_row, mi_col,
                            NULL, NULL);
         }
 
@@ -3075,7 +3078,7 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
         unsigned int sse, var;
         int tmp_rate_y, tmp_rate_u, tmp_rate_v;
         int tmp_dist_y, tmp_dist_u, tmp_dist_v;
-        vp9_build_inter_predictors_sb(xd, mb_row, mb_col, bsize);
+        vp9_build_inter_predictors_sb(xd, mi_row, mi_col, bsize);
         var = cpi->fn_ptr[block_size].vf(x->plane[0].src.buf,
                                          x->plane[0].src.stride,
                                          xd->plane[0].dst.buf,
@@ -3084,7 +3087,7 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
         // Note our transform coeffs are 8 times an orthogonal transform.
         // Hence quantizer step is also 8 times. To get effective quantizer
         // we need to divide by 8 before sending to modeling function.
-        model_rd_from_var_lapndz(var, 16 * bw * 16 * bh,
+        model_rd_from_var_lapndz(var, MI_SIZE * bw * MI_SIZE * bh,
                                  xd->plane[0].dequant[1] >> 3,
                                  &tmp_rate_y, &tmp_dist_y);
         var = cpi->fn_ptr[uv_block_size].vf(x->plane[1].src.buf,
@@ -3092,7 +3095,7 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
                                             xd->plane[1].dst.buf,
                                             xd->plane[1].dst.stride,
                                             &sse);
-        model_rd_from_var_lapndz(var, 8 * bw * 8 * bh,
+        model_rd_from_var_lapndz(var, MI_UV_SIZE * bw * MI_UV_SIZE * bh,
                                  xd->plane[1].dequant[1] >> 3,
                                  &tmp_rate_u, &tmp_dist_u);
         var = cpi->fn_ptr[uv_block_size].vf(x->plane[2].src.buf,
@@ -3100,7 +3103,7 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
                                             xd->plane[2].dst.buf,
                                             xd->plane[1].dst.stride,
                                             &sse);
-        model_rd_from_var_lapndz(var, 8 * bw * 8 * bh,
+        model_rd_from_var_lapndz(var, MI_UV_SIZE * bw * MI_UV_SIZE * bh,
                                  xd->plane[2].dequant[1] >> 3,
                                  &tmp_rate_v, &tmp_dist_v);
         rd = RDCOST(x->rdmult, x->rddiv,
@@ -3125,18 +3128,18 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
           (cm->mcomp_filter_type != SWITCHABLE &&
            cm->mcomp_filter_type == mbmi->interp_filter)) {
         int i;
-        for (i = 0; i < 16 * bh; ++i)
-          vpx_memcpy(tmp_ybuf + i * 16 * bw,
+        for (i = 0; i < MI_SIZE * bh; ++i)
+          vpx_memcpy(tmp_ybuf + i * MI_SIZE * bw,
                      xd->plane[0].dst.buf + i * xd->plane[0].dst.stride,
-                     sizeof(unsigned char) * 16 * bw);
-        for (i = 0; i < 8 * bh; ++i)
-          vpx_memcpy(tmp_ubuf + i * 8 * bw,
+                     sizeof(unsigned char) * MI_SIZE * bw);
+        for (i = 0; i < MI_UV_SIZE * bh; ++i)
+          vpx_memcpy(tmp_ubuf + i * MI_UV_SIZE * bw,
                      xd->plane[1].dst.buf + i * xd->plane[1].dst.stride,
-                     sizeof(unsigned char) * 8 * bw);
-        for (i = 0; i < 8 * bh; ++i)
-          vpx_memcpy(tmp_vbuf + i * 8 * bw,
+                     sizeof(unsigned char) * MI_UV_SIZE * bw);
+        for (i = 0; i < MI_UV_SIZE * bh; ++i)
+          vpx_memcpy(tmp_vbuf + i * MI_UV_SIZE * bw,
                      xd->plane[2].dst.buf + i * xd->plane[1].dst.stride,
-                     sizeof(unsigned char) * 8 * bw);
+                     sizeof(unsigned char) * MI_UV_SIZE * bw);
         pred_exists = 1;
       }
       interpolating_intpel_seen |=
@@ -3153,19 +3156,22 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
 
   if (pred_exists) {
     // FIXME(rbultje): mb code still predicts into xd->predictor
-    for (i = 0; i < bh * 16; ++i)
+    for (i = 0; i < bh * MI_SIZE; ++i)
       vpx_memcpy(xd->plane[0].dst.buf + i * xd->plane[0].dst.stride,
-                 tmp_ybuf + i * bw * 16, sizeof(unsigned char) * bw * 16);
-    for (i = 0; i < bh * 8; ++i)
+                 tmp_ybuf + i * bw * MI_SIZE,
+                 sizeof(unsigned char) * bw * MI_SIZE);
+    for (i = 0; i < bh * MI_UV_SIZE; ++i)
       vpx_memcpy(xd->plane[1].dst.buf + i * xd->plane[1].dst.stride,
-                 tmp_ubuf + i * bw * 8, sizeof(unsigned char) * bw * 8);
-    for (i = 0; i < bh * 8; ++i)
+                 tmp_ubuf + i * bw * MI_UV_SIZE,
+                 sizeof(unsigned char) * bw * MI_UV_SIZE);
+    for (i = 0; i < bh * MI_UV_SIZE; ++i)
       vpx_memcpy(xd->plane[2].dst.buf + i * xd->plane[1].dst.stride,
-                 tmp_vbuf + i * bw * 8, sizeof(unsigned char) * bw * 8);
+                 tmp_vbuf + i * bw * MI_UV_SIZE,
+                 sizeof(unsigned char) * bw * MI_UV_SIZE);
   } else {
     // Handles the special case when a filter that is not in the
     // switchable list (ex. bilinear, 6-tap) is indicated at the frame level
-    vp9_build_inter_predictors_sb(xd, mb_row, mb_col, bsize);
+    vp9_build_inter_predictors_sb(xd, mi_row, mi_col, bsize);
   }
 
   if (cpi->common.mcomp_filter_type == SWITCHABLE) {
@@ -3276,7 +3282,7 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
 }
 
 static void rd_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
-                               int mb_row, int mb_col,
+                               int mi_row, int mi_col,
                                int *returnrate, int *returndistortion,
                                int64_t *returnintra) {
   static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG,
@@ -3363,21 +3369,21 @@ static void rd_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
 
   if (cpi->ref_frame_flags & VP9_LAST_FLAG) {
     setup_buffer_inter(cpi, x, cpi->lst_fb_idx,
-                       LAST_FRAME, BLOCK_16X16, mb_row, mb_col,
+                       LAST_FRAME, BLOCK_16X16, mi_row, mi_col,
                        frame_mv[NEARESTMV], frame_mv[NEARMV],
                        frame_mdcounts, yv12_mb, scale_factor);
   }
 
   if (cpi->ref_frame_flags & VP9_GOLD_FLAG) {
     setup_buffer_inter(cpi, x, cpi->gld_fb_idx,
-                       GOLDEN_FRAME, BLOCK_16X16, mb_row, mb_col,
+                       GOLDEN_FRAME, BLOCK_16X16, mi_row, mi_col,
                        frame_mv[NEARESTMV], frame_mv[NEARMV],
                        frame_mdcounts, yv12_mb, scale_factor);
   }
 
   if (cpi->ref_frame_flags & VP9_ALT_FLAG) {
     setup_buffer_inter(cpi, x, cpi->alt_fb_idx,
-                       ALTREF_FRAME, BLOCK_16X16, mb_row, mb_col,
+                       ALTREF_FRAME, BLOCK_16X16, mi_row, mi_col,
                        frame_mv[NEARESTMV], frame_mv[NEARMV],
                        frame_mdcounts, yv12_mb, scale_factor);
   }
@@ -3742,7 +3748,7 @@ static void rd_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
       if (tmp_rd < best_yrd) {
         int uv_skippable;
 
-        vp9_build_inter_predictors_sbuv(&x->e_mbd, mb_row, mb_col,
+        vp9_build_inter_predictors_sbuv(&x->e_mbd, mi_row, mi_col,
                                         BLOCK_SIZE_MB16X16);
 
         vp9_subtract_sbuv(x, BLOCK_SIZE_MB16X16);
@@ -3791,7 +3797,7 @@ static void rd_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
                                   &rate_uv, &distortion_uv,
                                   &mode_excluded, &disable_skip,
                                   mode_index, &tmp_best_filter, frame_mv,
-                                  scaled_ref_frame, mb_row, mb_col);
+                                  scaled_ref_frame, mi_row, mi_col);
       if (this_rd == INT64_MAX)
         continue;
     }
@@ -4302,7 +4308,7 @@ void vp9_rd_pick_intra_mode(VP9_COMP *cpi, MACROBLOCK *x,
 }
 
 int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
-                                  int mb_row, int mb_col,
+                                  int mi_row, int mi_col,
                                   int *returnrate,
                                   int *returndistortion,
                                   BLOCK_SIZE_TYPE bsize,
@@ -4403,7 +4409,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
   for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) {
     if (cpi->ref_frame_flags & flag_list[ref_frame]) {
       setup_buffer_inter(cpi, x, idx_list[ref_frame], ref_frame, block_size,
-                         mb_row, mb_col, frame_mv[NEARESTMV], frame_mv[NEARMV],
+                         mi_row, mi_col, frame_mv[NEARESTMV], frame_mv[NEARMV],
                          frame_mdcounts, yv12_mb, scale_factor);
     }
     frame_mv[NEWMV][ref_frame].as_int = INVALID_MV;
@@ -4603,7 +4609,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
                                   &rate_uv, &distortion_uv,
                                   &mode_excluded, &disable_skip,
                                   mode_index, &tmp_best_filter, frame_mv,
-                                  scaled_ref_frame, mb_row, mb_col);
+                                  scaled_ref_frame, mi_row, mi_col);
       if (this_rd == INT64_MAX)
         continue;
     }
@@ -4898,7 +4904,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
 }
 
 void vp9_pick_mode_inter_macroblock(VP9_COMP *cpi, MACROBLOCK *x,
-                                    int mb_row, int mb_col,
+                                    int mi_row, int mi_col,
                                     int *totalrate, int *totaldist) {
   MACROBLOCKD *const xd = &x->e_mbd;
   MB_MODE_INFO * mbmi = &x->e_mbd.mode_info_context->mbmi;
@@ -4916,7 +4922,7 @@ void vp9_pick_mode_inter_macroblock(VP9_COMP *cpi, MACROBLOCK *x,
   {
     int zbin_mode_boost_enabled = cpi->zbin_mode_boost_enabled;
 
-    rd_pick_inter_mode(cpi, x, mb_row, mb_col, &rate,
+    rd_pick_inter_mode(cpi, x, mi_row, mi_col, &rate,
                        &distortion, &intra_error);
 
     /* restore cpi->zbin_mode_boost_enabled */
index 6fce507..eef2a4f 100644 (file)
@@ -27,11 +27,11 @@ void vp9_rd_pick_intra_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
                                PICK_MODE_CONTEXT *ctx);
 
 void vp9_pick_mode_inter_macroblock(VP9_COMP *cpi, MACROBLOCK *x,
-                                    int mb_row, int mb_col,
+                                    int mi_row, int mi_col,
                                     int *r, int *d);
 
 int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
-                                  int mb_row, int mb_col,
+                                  int mi_row, int mi_col,
                                   int *r, int *d, BLOCK_SIZE_TYPE bsize,
                                   PICK_MODE_CONTEXT *ctx);
 
index c243458..bee39cd 100644 (file)
@@ -37,7 +37,7 @@ void vp9_set_segmentation_map(VP9_PTR ptr,
 
   // Copy in the new segmentation map
   vpx_memcpy(cpi->segmentation_map, segmentation_map,
-             (cpi->common.mb_rows * cpi->common.mb_cols));
+             (cpi->common.mi_rows * cpi->common.mi_cols));
 
   // Signal that the map should be updated.
   cpi->mb.e_mbd.update_mb_segmentation_map = 1;
@@ -127,13 +127,13 @@ static void count_segs(VP9_COMP *cpi,
                        int *no_pred_segcounts,
                        int (*temporal_predictor_count)[2],
                        int *t_unpred_seg_counts,
-                       int bw, int bh, int mb_row, int mb_col) {
+                       int bw, int bh, int mi_row, int mi_col) {
   VP9_COMMON *const cm = &cpi->common;
   MACROBLOCKD *const xd = &cpi->mb.e_mbd;
   const int segment_id = mi->mbmi.segment_id;
 
   xd->mode_info_context = mi;
-  set_mb_row_col(cm, xd, mb_row, bh, mb_col, bw);
+  set_mi_row_col(cm, xd, mi_row, bh, mi_col, bw);
 
   // Count the number of hits on each segment with no prediction
   no_pred_segcounts[segment_id]++;
@@ -141,8 +141,8 @@ static void count_segs(VP9_COMP *cpi,
   // Temporal prediction not allowed on key frames
   if (cm->frame_type != KEY_FRAME) {
     // Test to see if the segment id matches the predicted value.
-    const int pred_seg_id = vp9_get_pred_mb_segid(cm, mi->mbmi.sb_type,
-                                                  mb_row, mb_col);
+    const int pred_seg_id = vp9_get_pred_mi_segid(cm, mi->mbmi.sb_type,
+                                                  mi_row, mi_col);
     const int seg_predicted = (segment_id == pred_seg_id);
 
     // Get the segment id prediction context
@@ -167,7 +167,7 @@ void vp9_choose_segmap_coding_method(VP9_COMP *cpi) {
   int t_pred_cost = INT_MAX;
 
   int i;
-  int tile_col, mb_row, mb_col;
+  int tile_col, mi_row, mi_col;
 
   int temporal_predictor_count[PREDICTION_PROBS][2];
   int no_pred_segcounts[MAX_MB_SEGMENTS];
@@ -196,78 +196,95 @@ void vp9_choose_segmap_coding_method(VP9_COMP *cpi) {
 
   for (tile_col = 0; tile_col < cm->tile_columns; tile_col++) {
     vp9_get_tile_col_offsets(cm, tile_col);
-    mi_ptr = cm->mi + cm->cur_tile_mb_col_start;
-    for (mb_row = 0; mb_row < cm->mb_rows; mb_row += 4, mi_ptr += 4 * mis) {
+    mi_ptr = cm->mi + cm->cur_tile_mi_col_start;
+    for (mi_row = 0; mi_row < cm->mi_rows;
+         mi_row += (4 << CONFIG_SB8X8), mi_ptr += (4 << CONFIG_SB8X8) * mis) {
       mi = mi_ptr;
-      for (mb_col = cm->cur_tile_mb_col_start;
-           mb_col < cm->cur_tile_mb_col_end; mb_col += 4, mi += 4) {
+      for (mi_col = cm->cur_tile_mi_col_start;
+           mi_col < cm->cur_tile_mi_col_end;
+           mi_col += (4 << CONFIG_SB8X8), mi += (4 << CONFIG_SB8X8)) {
         if (mi->mbmi.sb_type == BLOCK_SIZE_SB64X64) {
           count_segs(cpi, mi, no_pred_segcounts, temporal_predictor_count,
-                     t_unpred_seg_counts, 4, 4, mb_row, mb_col);
+                     t_unpred_seg_counts, 4 << CONFIG_SB8X8,
+                     4 << CONFIG_SB8X8, mi_row, mi_col);
         } else if (mi->mbmi.sb_type == BLOCK_SIZE_SB64X32) {
           count_segs(cpi, mi, no_pred_segcounts, temporal_predictor_count,
-                     t_unpred_seg_counts, 4, 2, mb_row, mb_col);
-          if (mb_row + 2 != cm->mb_rows)
-            count_segs(cpi, mi + 2 * mis, no_pred_segcounts,
+                     t_unpred_seg_counts, 4 << CONFIG_SB8X8,
+                     2 << CONFIG_SB8X8, mi_row, mi_col);
+          if (mi_row + (2 << CONFIG_SB8X8) != cm->mi_rows)
+            count_segs(cpi, mi + (2 << CONFIG_SB8X8) * mis, no_pred_segcounts,
                        temporal_predictor_count,
-                       t_unpred_seg_counts, 4, 2, mb_row + 2, mb_col);
+                       t_unpred_seg_counts, 4 << CONFIG_SB8X8,
+                       2 << CONFIG_SB8X8, mi_row + (2 << CONFIG_SB8X8), mi_col);
         } else if (mi->mbmi.sb_type == BLOCK_SIZE_SB32X64) {
           count_segs(cpi, mi, no_pred_segcounts, temporal_predictor_count,
-                     t_unpred_seg_counts, 2, 4, mb_row, mb_col);
-          if (mb_col + 2 != cm->mb_cols)
-            count_segs(cpi, mi + 2, no_pred_segcounts, temporal_predictor_count,
-                       t_unpred_seg_counts, 2, 4, mb_row, mb_col + 2);
+                     t_unpred_seg_counts, 2 << CONFIG_SB8X8,
+                     4 << CONFIG_SB8X8, mi_row, mi_col);
+          if (mi_col + (2 << CONFIG_SB8X8) != cm->mi_cols)
+            count_segs(cpi, mi + (2 << CONFIG_SB8X8), no_pred_segcounts,
+                       temporal_predictor_count,
+                       t_unpred_seg_counts, 2 << CONFIG_SB8X8,
+                       4 << CONFIG_SB8X8, mi_row, mi_col + (2 << CONFIG_SB8X8));
         } else {
           for (i = 0; i < 4; i++) {
-            int x_idx = (i & 1) << 1, y_idx = i & 2;
+            const int x_idx = (i & 1) << (1 + CONFIG_SB8X8);
+            const int y_idx = (i & 2) << CONFIG_SB8X8;
             MODE_INFO *sb_mi = mi + y_idx * mis + x_idx;
 
-            if (mb_col + x_idx >= cm->mb_cols ||
-                mb_row + y_idx >= cm->mb_rows) {
+            if (mi_col + x_idx >= cm->mi_cols ||
+                mi_row + y_idx >= cm->mi_rows) {
               continue;
             }
 
             if (sb_mi->mbmi.sb_type == BLOCK_SIZE_SB32X32) {
               count_segs(cpi, sb_mi, no_pred_segcounts,
-                         temporal_predictor_count, t_unpred_seg_counts, 2, 2,
-                         mb_row + y_idx, mb_col + x_idx);
+                         temporal_predictor_count, t_unpred_seg_counts,
+                         2 << CONFIG_SB8X8, 2 << CONFIG_SB8X8,
+                         mi_row + y_idx, mi_col + x_idx);
             } else if (sb_mi->mbmi.sb_type == BLOCK_SIZE_SB32X16) {
               count_segs(cpi, sb_mi, no_pred_segcounts,
                          temporal_predictor_count,
-                         t_unpred_seg_counts, 2, 1,
-                         mb_row + y_idx, mb_col + x_idx);
-              if (mb_row + y_idx + 1 != cm->mb_rows)
-                count_segs(cpi, sb_mi + mis, no_pred_segcounts,
-                           temporal_predictor_count,
-                           t_unpred_seg_counts, 2, 1,
-                           mb_row + y_idx + 1, mb_col + x_idx);
+                         t_unpred_seg_counts, 2 << CONFIG_SB8X8,
+                         1 << CONFIG_SB8X8,
+                         mi_row + y_idx, mi_col + x_idx);
+              if (mi_row + y_idx + (1 << CONFIG_SB8X8) != cm->mi_rows)
+                count_segs(cpi, sb_mi + (mis << CONFIG_SB8X8),
+                           no_pred_segcounts, temporal_predictor_count,
+                           t_unpred_seg_counts, 2 << CONFIG_SB8X8,
+                           1 << CONFIG_SB8X8,
+                           mi_row + y_idx + (1 << CONFIG_SB8X8),
+                           mi_col + x_idx);
             } else if (sb_mi->mbmi.sb_type == BLOCK_SIZE_SB16X32) {
               count_segs(cpi, sb_mi, no_pred_segcounts,
                          temporal_predictor_count,
-                         t_unpred_seg_counts, 1, 2,
-                         mb_row + y_idx, mb_col + x_idx);
-              if (mb_col + x_idx + 1 != cm->mb_cols)
-                count_segs(cpi, sb_mi + 1, no_pred_segcounts,
+                         t_unpred_seg_counts, 1 << CONFIG_SB8X8,
+                         2 << CONFIG_SB8X8,
+                         mi_row + y_idx, mi_col + x_idx);
+              if (mi_col + x_idx + (1 << CONFIG_SB8X8) != cm->mi_cols)
+                count_segs(cpi, sb_mi + (1 << CONFIG_SB8X8), no_pred_segcounts,
                            temporal_predictor_count,
-                           t_unpred_seg_counts, 1, 2,
-                           mb_row + y_idx, mb_col + x_idx + 1);
+                           t_unpred_seg_counts, 1 << CONFIG_SB8X8,
+                           2 << CONFIG_SB8X8,
+                           mi_row + y_idx,
+                           mi_col + x_idx + (1 << CONFIG_SB8X8));
             } else {
               int j;
 
               for (j = 0; j < 4; j++) {
-                const int x_idx_mb = x_idx + (j & 1);
-                const int y_idx_mb = y_idx + (j >> 1);
+                const int x_idx_mb = x_idx + ((j & 1) << CONFIG_SB8X8);
+                const int y_idx_mb = y_idx + ((j >> 1) << CONFIG_SB8X8);
                 MODE_INFO *mb_mi = mi + x_idx_mb + y_idx_mb * mis;
 
-                if (mb_col + x_idx_mb >= cm->mb_cols ||
-                    mb_row + y_idx_mb >= cm->mb_rows) {
+                if (mi_col + x_idx_mb >= cm->mi_cols ||
+                    mi_row + y_idx_mb >= cm->mi_rows) {
                   continue;
                 }
 
                 assert(mb_mi->mbmi.sb_type == BLOCK_SIZE_MB16X16);
                 count_segs(cpi, mb_mi, no_pred_segcounts,
                            temporal_predictor_count, t_unpred_seg_counts,
-                           1, 1, mb_row + y_idx_mb, mb_col + x_idx_mb);
+                           1 << CONFIG_SB8X8, 1 << CONFIG_SB8X8,
+                           mi_row + y_idx_mb, mi_col + x_idx_mb);
               }
             }
           }