Rework inter prediction process in cb4x4 mode

Use 2x2 inter prediction for chroma component. This improves the
compression performance by 0.6% for lowres.

Change-Id: If9d98e49cee63f40085b179652bfacc31ff462ea
diff --git a/av1/common/reconinter.c b/av1/common/reconinter.c
index 8975b17..83f347e 100644
--- a/av1/common/reconinter.c
+++ b/av1/common/reconinter.c
@@ -880,7 +880,7 @@
   int subpel_y;
 } SubpelParams;
 
-void build_inter_predictors(MACROBLOCKD *xd, int plane,
+void build_inter_predictors(const AV1_COMMON *cm, MACROBLOCKD *xd, int plane,
 #if CONFIG_MOTION_VAR
                             int mi_col_offset, int mi_row_offset,
 #endif  // CONFIG_MOTION_VAR
@@ -893,13 +893,10 @@
   struct macroblockd_plane *const pd = &xd->plane[plane];
 #if CONFIG_MOTION_VAR
   const MODE_INFO *mi = xd->mi[mi_col_offset + xd->mi_stride * mi_row_offset];
-#if !CONFIG_CB4X4 || CONFIG_SUB8X8_MC
-  const int build_for_obmc = !(mi_col_offset == 0 && mi_row_offset == 0);
-#endif  // !CONFIG_CB4X4 || CONFIG_SUB8X8_MC
 #else
   const MODE_INFO *mi = xd->mi[0];
 #endif  // CONFIG_MOTION_VAR
-  const int is_compound = has_second_ref(&mi->mbmi);
+  int is_compound = has_second_ref(&mi->mbmi);
   int ref;
 #if CONFIG_INTRABC
   const int is_intrabc = is_intrabc_block(&mi->mbmi);
@@ -915,37 +912,66 @@
 
 #if CONFIG_CB4X4
   (void)block;
+  (void)cm;
 #endif
 
-#if CONFIG_SUB8X8_MC
-#if CONFIG_MOTION_VAR
-  if (mi->mbmi.sb_type < BLOCK_8X8 && plane > 0 && !build_for_obmc) {
-#else
-  if (mi->mbmi.sb_type < BLOCK_8X8 && plane > 0) {
-#endif  // CONFIG_MOTION_VAR
-    // block size in log2
-    const int b4_wl = b_width_log2_lookup[mi->mbmi.sb_type];
-    const int b4_hl = b_height_log2_lookup[mi->mbmi.sb_type];
-    const int b8_sl = b_width_log2_lookup[BLOCK_8X8];
+#if CONFIG_CHROMA_SUB8X8
+  const BLOCK_SIZE bsize = mi->mbmi.sb_type;
+  int sub8x8_inter = bsize < BLOCK_8X8 && plane > 0;
+  const int row_start = (block_size_high[bsize] == 4) ? -1 : 0;
+  const int col_start = (block_size_wide[bsize] == 4) ? -1 : 0;
 
+  for (int row = row_start; row <= 0 && sub8x8_inter; ++row)
+    for (int col = col_start; col <= 0; ++col)
+      if (!is_inter_block(&xd->mi[row * xd->mi_stride + col]->mbmi))
+        sub8x8_inter = 0;
+
+#if CONFIG_MOTION_VAR
+  const int build_for_obmc = !(mi_col_offset == 0 && mi_row_offset == 0);
+  if (!build_for_obmc && sub8x8_inter) {
+#else
+  if (sub8x8_inter) {
+#endif  // CONFIG_MOTION_VAR
     // block size
-    const int b4_w = 1 << b4_wl;
-    const int b4_h = 1 << b4_hl;
-    const int b8_s = 1 << b8_sl;
+    const int b4_w = block_size_wide[bsize] >> pd->subsampling_x;
+    const int b4_h = block_size_high[bsize] >> pd->subsampling_y;
+    const int b8_w = block_size_wide[BLOCK_8X8] >> pd->subsampling_x;
+    const int b8_h = block_size_high[BLOCK_8X8] >> pd->subsampling_y;
     int idx, idy;
 
     const int x_base = x;
     const int y_base = y;
 
-    // processing unit size
-    const int x_step = w >> (b8_sl - b4_wl);
-    const int y_step = h >> (b8_sl - b4_hl);
+    const struct buf_2d orig_pred_buf[2] = { pd->pre[0], pd->pre[1] };
 
-    for (idy = 0; idy < b8_s; idy += b4_h) {
-      for (idx = 0; idx < b8_s; idx += b4_w) {
-        const int chr_idx = (idy * 2) + idx;
+    int row = row_start;
+    for (idy = 0; idy < b8_h; idy += b4_h) {
+      int col = col_start;
+      for (idx = 0; idx < b8_w; idx += b4_w) {
+        MB_MODE_INFO *this_mbmi = &xd->mi[row * xd->mi_stride + col]->mbmi;
+        is_compound = has_second_ref(this_mbmi);
+
         for (ref = 0; ref < 1 + is_compound; ++ref) {
           struct buf_2d *const dst_buf = &pd->dst;
+
+          const RefBuffer *ref_buf =
+              &cm->frame_refs[this_mbmi->ref_frame[ref] - LAST_FRAME];
+
+          const int c_offset =
+              (mi_x + MI_SIZE * col_start) >> pd->subsampling_x;
+          const int r_offset =
+              (mi_y + MI_SIZE * row_start) >> pd->subsampling_y;
+          pd->pre[ref].buf0 =
+              (plane == 1) ? ref_buf->buf->u_buffer : ref_buf->buf->v_buffer;
+          pd->pre[ref].buf =
+              pd->pre[ref].buf0 + scaled_buffer_offset(c_offset, r_offset,
+                                                       ref_buf->buf->uv_stride,
+                                                       &ref_buf->sf);
+
+          pd->pre[ref].width = ref_buf->buf->uv_crop_width;
+          pd->pre[ref].height = ref_buf->buf->uv_crop_height;
+          pd->pre[ref].stride = ref_buf->buf->uv_stride;
+
 #if CONFIG_INTRABC
           const struct scale_factors *const sf =
               is_intrabc ? &xd->sf_identity : &xd->block_refs[ref]->sf;
@@ -955,7 +981,9 @@
           struct buf_2d *const pre_buf = &pd->pre[ref];
 #endif  // CONFIG_INTRABC
           uint8_t *dst = dst_buf->buf;
-          const MV mv = mi->bmi[chr_idx].as_mv[ref].as_mv;
+
+          const MV mv = this_mbmi->mv[ref].as_mv;
+
           const MV mv_q4 = clamp_mv_to_umv_border_sb(
               xd, &mv, bw, bh, pd->subsampling_x, pd->subsampling_y);
           uint8_t *pre;
@@ -973,8 +1001,8 @@
 #endif  // CONFIG_WARPED_MOTION
 #endif  // CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
 
-          x = x_base + idx * x_step;
-          y = y_base + idy * y_step;
+          x = x_base + idx;
+          y = y_base + idy;
 
           dst += dst_buf->stride * y + x;
 
@@ -1014,21 +1042,25 @@
 #endif  // CONFIG_EXT_INTER
             av1_make_inter_predictor(
                 pre, pre_buf->stride, dst, dst_buf->stride, subpel_x, subpel_y,
-                sf, x_step, y_step, &conv_params, mi->mbmi.interp_filter,
+                sf, b4_w, b4_h, &conv_params, this_mbmi->interp_filter,
 #if CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
-                &warp_types, (mi_x >> pd->subsampling_x) + x,
-                (mi_y >> pd->subsampling_y) + y, plane, ref,
+                &warp_types, ((mi_x + MI_SIZE * col) >> pd->subsampling_x) + x,
+                ((mi_y + MI_SIZE * row) >> pd->subsampling_y) + y, plane, ref,
 #endif  // CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
 #if CONFIG_MOTION_VAR
                 mi_col_offset, mi_row_offset,
 #endif
                 xs, ys, xd);
         }
+        ++col;
       }
+      ++row;
     }
+
+    for (ref = 0; ref < 2; ++ref) pd->pre[ref] = orig_pred_buf[ref];
     return;
   }
-#endif
+#endif  // CONFIG_CHROMA_SUB8X8
 
   {
     struct buf_2d *const dst_buf = &pd->dst;
@@ -1170,8 +1202,9 @@
   }
 }
 
-void av1_build_inter_predictor_sub8x8(MACROBLOCKD *xd, int plane, int i, int ir,
-                                      int ic, int mi_row, int mi_col) {
+void av1_build_inter_predictor_sub8x8(const AV1_COMMON *cm, MACROBLOCKD *xd,
+                                      int plane, int i, int ir, int ic,
+                                      int mi_row, int mi_col) {
   struct macroblockd_plane *const pd = &xd->plane[plane];
   MODE_INFO *const mi = xd->mi[0];
   const BLOCK_SIZE plane_bsize = get_plane_block_size(mi->mbmi.sb_type, pd);
@@ -1180,6 +1213,8 @@
   uint8_t *const dst = &pd->dst.buf[(ir * pd->dst.stride + ic) << 2];
   int ref;
   const int is_compound = has_second_ref(&mi->mbmi);
+  (void)cm;
+
 #if CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
   WarpTypesAllowed warp_types;
   const int p_col = ((mi_col * MI_SIZE) >> pd->subsampling_x) + 4 * ic;
@@ -1229,7 +1264,8 @@
   }
 }
 
-static void build_inter_predictors_for_planes(MACROBLOCKD *xd, BLOCK_SIZE bsize,
+static void build_inter_predictors_for_planes(const AV1_COMMON *cm,
+                                              MACROBLOCKD *xd, BLOCK_SIZE bsize,
                                               int mi_row, int mi_col,
                                               int plane_from, int plane_to) {
   int plane;
@@ -1265,7 +1301,7 @@
       assert(pw * num_4x4_w == bw && ph * num_4x4_h == bh);
       for (y = 0; y < num_4x4_h; ++y)
         for (x = 0; x < num_4x4_w; ++x)
-          build_inter_predictors(xd, plane,
+          build_inter_predictors(cm, xd, plane,
 #if CONFIG_MOTION_VAR
                                  0, 0,
 #endif  // CONFIG_MOTION_VAR
@@ -1275,7 +1311,7 @@
 #endif  // CONFIG_SUPERTX && CONFIG_EXT_INTER
                                  mi_x, mi_y);
     } else {
-      build_inter_predictors(xd, plane,
+      build_inter_predictors(cm, xd, plane,
 #if CONFIG_MOTION_VAR
                              0, 0,
 #endif  // CONFIG_MOTION_VAR
@@ -1288,9 +1324,10 @@
   }
 }
 
-void av1_build_inter_predictors_sby(MACROBLOCKD *xd, int mi_row, int mi_col,
-                                    BUFFER_SET *ctx, BLOCK_SIZE bsize) {
-  build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 0, 0);
+void av1_build_inter_predictors_sby(const AV1_COMMON *cm, MACROBLOCKD *xd,
+                                    int mi_row, int mi_col, BUFFER_SET *ctx,
+                                    BLOCK_SIZE bsize) {
+  build_inter_predictors_for_planes(cm, xd, bsize, mi_row, mi_col, 0, 0);
 #if CONFIG_EXT_INTER
   if (is_interintra_pred(&xd->mi[0]->mbmi)) {
     BUFFER_SET default_ctx = { { xd->plane[0].dst.buf, NULL, NULL },
@@ -1304,9 +1341,10 @@
 #endif  // CONFIG_EXT_INTER
 }
 
-void av1_build_inter_predictors_sbuv(MACROBLOCKD *xd, int mi_row, int mi_col,
-                                     BUFFER_SET *ctx, BLOCK_SIZE bsize) {
-  build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 1,
+void av1_build_inter_predictors_sbuv(const AV1_COMMON *cm, MACROBLOCKD *xd,
+                                     int mi_row, int mi_col, BUFFER_SET *ctx,
+                                     BLOCK_SIZE bsize) {
+  build_inter_predictors_for_planes(cm, xd, bsize, mi_row, mi_col, 1,
                                     MAX_MB_PLANE - 1);
 #if CONFIG_EXT_INTER
   if (is_interintra_pred(&xd->mi[0]->mbmi)) {
@@ -1325,9 +1363,10 @@
 }
 
 // TODO(afergs): Check if ctx can be made constant
-void av1_build_inter_predictors_sb(MACROBLOCKD *xd, int mi_row, int mi_col,
-                                   BUFFER_SET *ctx, BLOCK_SIZE bsize) {
-  build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 0,
+void av1_build_inter_predictors_sb(const AV1_COMMON *cm, MACROBLOCKD *xd,
+                                   int mi_row, int mi_col, BUFFER_SET *ctx,
+                                   BLOCK_SIZE bsize) {
+  build_inter_predictors_for_planes(cm, xd, bsize, mi_row, mi_col, 0,
                                     MAX_MB_PLANE - 1);
 #if CONFIG_EXT_INTER
   if (is_interintra_pred(&xd->mi[0]->mbmi)) {
@@ -1522,7 +1561,8 @@
   } while (--h_remain);
 }
 
-void av1_build_inter_predictors_sb_sub8x8_extend(MACROBLOCKD *xd,
+void av1_build_inter_predictors_sb_sub8x8_extend(const AV1_COMMON *cm,
+                                                 MACROBLOCKD *xd,
 #if CONFIG_EXT_INTER
                                                  int mi_row_ori, int mi_col_ori,
 #endif  // CONFIG_EXT_INTER
@@ -1553,7 +1593,7 @@
     const int bw = 4 * num_4x4_w;
     const int bh = 4 * num_4x4_h;
 
-    build_inter_predictors(xd, plane,
+    build_inter_predictors(cm, xd, plane,
 #if CONFIG_MOTION_VAR
                            0, 0,
 #endif  // CONFIG_MOTION_VAR
@@ -1577,7 +1617,7 @@
 #endif  // CONFIG_EXT_INTER
 }
 
-void av1_build_inter_predictors_sb_extend(MACROBLOCKD *xd,
+void av1_build_inter_predictors_sb_extend(const AV1_COMMON *cm, MACROBLOCKD *xd,
 #if CONFIG_EXT_INTER
                                           int mi_row_ori, int mi_col_ori,
 #endif  // CONFIG_EXT_INTER
@@ -1596,7 +1636,7 @@
     const int bw = block_size_wide[plane_bsize];
     const int bh = block_size_high[plane_bsize];
 
-    build_inter_predictors(xd, plane,
+    build_inter_predictors(cm, xd, plane,
 #if CONFIG_MOTION_VAR
                            0, 0,
 #endif  // CONFIG_MOTION_VAR
@@ -1960,8 +2000,8 @@
                   4);
 
       if (skip_u4x4_pred_in_obmc(bsize, pd, 0)) continue;
-      build_inter_predictors(xd, j, mi_col_offset, mi_row_offset, 0, bw, bh, 0,
-                             0, bw, bh,
+      build_inter_predictors(cm, xd, j, mi_col_offset, mi_row_offset, 0, bw, bh,
+                             0, 0, bw, bh,
 #if CONFIG_SUPERTX && CONFIG_EXT_INTER
                              0, 0,
 #endif  // CONFIG_SUPERTX && CONFIG_EXT_INTER
@@ -2041,8 +2081,8 @@
       bh = (mi_step << MI_SIZE_LOG2) >> pd->subsampling_y;
 
       if (skip_u4x4_pred_in_obmc(bsize, pd, 1)) continue;
-      build_inter_predictors(xd, j, mi_col_offset, mi_row_offset, 0, bw, bh, 0,
-                             0, bw, bh,
+      build_inter_predictors(cm, xd, j, mi_col_offset, mi_row_offset, 0, bw, bh,
+                             0, 0, bw, bh,
 #if CONFIG_SUPERTX && CONFIG_EXT_INTER
                              0, 0,
 #endif  // CONFIG_SUPERTX && CONFIG_EXT_INTER
@@ -2185,7 +2225,7 @@
               continue;
 
             build_inter_predictors(
-                xd, j, mi_col_offset, mi_row_offset, y * 2 + x, bw, bh,
+                cm, xd, j, mi_col_offset, mi_row_offset, y * 2 + x, bw, bh,
                 (4 * x) >> pd->subsampling_x,
                 xd->n8_h == 1 ? (4 >> pd->subsampling_y) : 0, pw, bh,
 #if CONFIG_SUPERTX && CONFIG_EXT_INTER
@@ -2194,13 +2234,13 @@
                 mi_x, mi_y);
           }
       } else {
-        build_inter_predictors(xd, j, mi_col_offset, mi_row_offset, 0, bw, bh,
-                               0, xd->n8_h == 1 ? (4 >> pd->subsampling_y) : 0,
-                               bw, bh,
+        build_inter_predictors(
+            cm, xd, j, mi_col_offset, mi_row_offset, 0, bw, bh, 0,
+            xd->n8_h == 1 ? (4 >> pd->subsampling_y) : 0, bw, bh,
 #if CONFIG_SUPERTX && CONFIG_EXT_INTER
-                               0, 0,
+            0, 0,
 #endif  // CONFIG_SUPERTX && CONFIG_EXT_INTER
-                               mi_x, mi_y);
+            mi_x, mi_y);
       }
     }
 #if CONFIG_EXT_INTER
@@ -2292,7 +2332,7 @@
             if ((bp == PARTITION_VERT || bp == PARTITION_SPLIT) && x != 0)
               continue;
 
-            build_inter_predictors(xd, j, mi_col_offset, mi_row_offset,
+            build_inter_predictors(cm, xd, j, mi_col_offset, mi_row_offset,
                                    y * 2 + x, bw, bh,
                                    xd->n8_w == 1 ? 4 >> pd->subsampling_x : 0,
                                    (4 * y) >> pd->subsampling_y, bw, ph,
@@ -2302,9 +2342,9 @@
                                    mi_x, mi_y);
           }
       } else {
-        build_inter_predictors(xd, j, mi_col_offset, mi_row_offset, 0, bw, bh,
-                               xd->n8_w == 1 ? 4 >> pd->subsampling_x : 0, 0,
-                               bw, bh,
+        build_inter_predictors(cm, xd, j, mi_col_offset, mi_row_offset, 0, bw,
+                               bh, xd->n8_w == 1 ? 4 >> pd->subsampling_x : 0,
+                               0, bw, bh,
 #if CONFIG_SUPERTX && CONFIG_EXT_INTER
                                0, 0,
 #endif  // CONFIG_SUPERTX && CONFIG_EXT_INTER
diff --git a/av1/common/reconinter.h b/av1/common/reconinter.h
index 8dcea88..7485264 100644
--- a/av1/common/reconinter.h
+++ b/av1/common/reconinter.h
@@ -258,7 +258,7 @@
 #endif  // CONFIG_COMPOUND_SEGMENT
 #endif  // CONFIG_EXT_INTER
 
-void build_inter_predictors(MACROBLOCKD *xd, int plane,
+void build_inter_predictors(const AV1_COMMON *cm, MACROBLOCKD *xd, int plane,
 #if CONFIG_MOTION_VAR
                             int mi_col_offset, int mi_row_offset,
 #endif  // CONFIG_MOTION_VAR
@@ -536,27 +536,32 @@
   return res;
 }
 
-void av1_build_inter_predictor_sub8x8(MACROBLOCKD *xd, int plane, int i, int ir,
-                                      int ic, int mi_row, int mi_col);
+void av1_build_inter_predictor_sub8x8(const AV1_COMMON *cm, MACROBLOCKD *xd,
+                                      int plane, int i, int ir, int ic,
+                                      int mi_row, int mi_col);
 
-void av1_build_inter_predictors_sby(MACROBLOCKD *xd, int mi_row, int mi_col,
-                                    BUFFER_SET *ctx, BLOCK_SIZE bsize);
+void av1_build_inter_predictors_sby(const AV1_COMMON *cm, MACROBLOCKD *xd,
+                                    int mi_row, int mi_col, BUFFER_SET *ctx,
+                                    BLOCK_SIZE bsize);
 
-void av1_build_inter_predictors_sbuv(MACROBLOCKD *xd, int mi_row, int mi_col,
-                                     BUFFER_SET *ctx, BLOCK_SIZE bsize);
+void av1_build_inter_predictors_sbuv(const AV1_COMMON *cm, MACROBLOCKD *xd,
+                                     int mi_row, int mi_col, BUFFER_SET *ctx,
+                                     BLOCK_SIZE bsize);
 
-void av1_build_inter_predictors_sb(MACROBLOCKD *xd, int mi_row, int mi_col,
-                                   BUFFER_SET *ctx, BLOCK_SIZE bsize);
+void av1_build_inter_predictors_sb(const AV1_COMMON *cm, MACROBLOCKD *xd,
+                                   int mi_row, int mi_col, BUFFER_SET *ctx,
+                                   BLOCK_SIZE bsize);
 
 #if CONFIG_SUPERTX
-void av1_build_inter_predictors_sb_sub8x8_extend(MACROBLOCKD *xd,
+void av1_build_inter_predictors_sb_sub8x8_extend(const AV1_COMMON *cm,
+                                                 MACROBLOCKD *xd,
 #if CONFIG_EXT_INTER
                                                  int mi_row_ori, int mi_col_ori,
 #endif  // CONFIG_EXT_INTER
                                                  int mi_row, int mi_col,
                                                  BLOCK_SIZE bsize, int block);
 
-void av1_build_inter_predictors_sb_extend(MACROBLOCKD *xd,
+void av1_build_inter_predictors_sb_extend(const AV1_COMMON *cm, MACROBLOCKD *xd,
 #if CONFIG_EXT_INTER
                                           int mi_row_ori, int mi_col_ori,
 #endif  // CONFIG_EXT_INTER
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 47bc183..ec383a7 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -875,13 +875,13 @@
                          (c >> xd->plane[2].subsampling_x);
 
   if (!b_sub8x8)
-    av1_build_inter_predictors_sb_extend(xd,
+    av1_build_inter_predictors_sb_extend(&pbi->common, xd,
 #if CONFIG_EXT_INTER
                                          mi_row_ori, mi_col_ori,
 #endif  // CONFIG_EXT_INTER
                                          mi_row_pred, mi_col_pred, bsize_pred);
   else
-    av1_build_inter_predictors_sb_sub8x8_extend(xd,
+    av1_build_inter_predictors_sb_sub8x8_extend(&pbi->common, xd,
 #if CONFIG_EXT_INTER
                                                 mi_row_ori, mi_col_ori,
 #endif  // CONFIG_EXT_INTER
@@ -1645,7 +1645,7 @@
       }
     } else {
       // Prediction
-      av1_build_inter_predictors_sb(xd, mi_row, mi_col, NULL,
+      av1_build_inter_predictors_sb(cm, xd, mi_row, mi_col, NULL,
                                     AOMMAX(bsize, BLOCK_8X8));
 
       // Reconstruction
@@ -1755,9 +1755,9 @@
     }
 
 #if CONFIG_CB4X4
-    av1_build_inter_predictors_sb(xd, mi_row, mi_col, NULL, bsize);
+    av1_build_inter_predictors_sb(cm, xd, mi_row, mi_col, NULL, bsize);
 #else
-    av1_build_inter_predictors_sb(xd, mi_row, mi_col, NULL,
+    av1_build_inter_predictors_sb(cm, xd, mi_row, mi_col, NULL,
                                   AOMMAX(bsize, BLOCK_8X8));
 #endif
 
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index ec242dc..f26cf02 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -952,7 +952,7 @@
       x->pred_mv[LAST_FRAME] = mbmi->mv[0].as_mv;
     }
 
-    av1_build_inter_predictors_sb(xd, mi_row, mi_col, NULL, cm->sb_size);
+    av1_build_inter_predictors_sb(cm, xd, mi_row, mi_col, NULL, cm->sb_size);
 
     ref = xd->plane[0].dst.buf;
     ref_stride = xd->plane[0].dst.stride;
@@ -5994,9 +5994,9 @@
       av1_setup_pre_planes(xd, ref, cfg, mi_row, mi_col,
                            &xd->block_refs[ref]->sf);
     }
-    av1_build_inter_predictors_sby(xd, mi_row, mi_col, NULL, block_size);
+    av1_build_inter_predictors_sby(cm, xd, mi_row, mi_col, NULL, block_size);
 
-    av1_build_inter_predictors_sbuv(xd, mi_row, mi_col, NULL, block_size);
+    av1_build_inter_predictors_sbuv(cm, xd, mi_row, mi_col, NULL, block_size);
 #if CONFIG_MOTION_VAR
     if (mbmi->motion_mode == OBMC_CAUSAL) {
 #if CONFIG_NCOBMC
@@ -6281,13 +6281,13 @@
   }
 
   if (!b_sub8x8)
-    av1_build_inter_predictors_sb_extend(xd,
+    av1_build_inter_predictors_sb_extend(cm, xd,
 #if CONFIG_EXT_INTER
                                          mi_row_ori, mi_col_ori,
 #endif  // CONFIG_EXT_INTER
                                          mi_row_pred, mi_col_pred, bsize_pred);
   else
-    av1_build_inter_predictors_sb_sub8x8_extend(xd,
+    av1_build_inter_predictors_sb_sub8x8_extend(cm, xd,
 #if CONFIG_EXT_INTER
                                                 mi_row_ori, mi_col_ori,
 #endif  // CONFIG_EXT_INTER
diff --git a/av1/encoder/firstpass.c b/av1/encoder/firstpass.c
index ac4210b..7797420 100644
--- a/av1/encoder/firstpass.c
+++ b/av1/encoder/firstpass.c
@@ -884,7 +884,7 @@
           xd->mi[0]->mbmi.tx_size = TX_4X4;
           xd->mi[0]->mbmi.ref_frame[0] = LAST_FRAME;
           xd->mi[0]->mbmi.ref_frame[1] = NONE_FRAME;
-          av1_build_inter_predictors_sby(xd, mb_row * mb_scale,
+          av1_build_inter_predictors_sby(cm, xd, mb_row * mb_scale,
                                          mb_col * mb_scale, NULL, bsize);
           av1_encode_sby_pass1(cm, x, bsize);
           sum_mvr += mv.row;
diff --git a/av1/encoder/mbgraph.c b/av1/encoder/mbgraph.c
index 1296027..8578611 100644
--- a/av1/encoder/mbgraph.c
+++ b/av1/encoder/mbgraph.c
@@ -71,7 +71,8 @@
   xd->mi[0]->mbmi.ref_frame[1] = NONE_FRAME;
 #endif  // CONFIG_EXT_INTER
 
-  av1_build_inter_predictors_sby(xd, mb_row, mb_col, NULL, BLOCK_16X16);
+  av1_build_inter_predictors_sby(&cpi->common, xd, mb_row, mb_col, NULL,
+                                 BLOCK_16X16);
 
   /* restore UMV window */
   x->mv_limits = tmp_mv_limits;
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index abe1b01..d66ebe5 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -5181,7 +5181,7 @@
 
   assert(tx_type == DCT_DCT);
 
-  av1_build_inter_predictor_sub8x8(xd, 0, i, ir, ic, mi_row, mi_col);
+  av1_build_inter_predictor_sub8x8(cm, xd, 0, i, ir, ic, mi_row, mi_col);
 
 #if CONFIG_HIGHBITDEPTH
   if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
@@ -6466,7 +6466,8 @@
         const int txb_height = max_block_high(xd, plane_bsize, 0);
         int idx_, idy_;
 
-        av1_build_inter_predictor_sub8x8(xd, 0, i, idy, idx, mi_row, mi_col);
+        av1_build_inter_predictor_sub8x8(cm, xd, 0, i, idy, idx, mi_row,
+                                         mi_col);
 #if CONFIG_HIGHBITDEPTH
         if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
           aom_highbd_subtract_block(
@@ -7916,7 +7917,7 @@
   set_default_interp_filters(mbmi, assign_filter);
 
   *switchable_rate = av1_get_switchable_rate(cpi, xd);
-  av1_build_inter_predictors_sb(xd, mi_row, mi_col, orig_dst, bsize);
+  av1_build_inter_predictors_sb(cm, xd, mi_row, mi_col, orig_dst, bsize);
   model_rd_for_sb(cpi, bsize, x, xd, 0, MAX_MB_PLANE - 1, &tmp_rate, &tmp_dist,
                   skip_txfm_sb, skip_sse_sb);
   *rd = RDCOST(x->rdmult, x->rddiv, *switchable_rate + tmp_rate, tmp_dist);
@@ -7952,7 +7953,7 @@
         mbmi->interp_filter = (InterpFilter)i;
 #endif  // CONFIG_DUAL_FILTER
         tmp_rs = av1_get_switchable_rate(cpi, xd);
-        av1_build_inter_predictors_sb(xd, mi_row, mi_col, orig_dst, bsize);
+        av1_build_inter_predictors_sb(cm, xd, mi_row, mi_col, orig_dst, bsize);
         model_rd_for_sb(cpi, bsize, x, xd, 0, MAX_MB_PLANE - 1, &tmp_rate,
                         &tmp_dist, &tmp_skip_sb, &tmp_skip_sse);
         tmp_rd = RDCOST(x->rdmult, x->rddiv, tmp_rs + tmp_rate, tmp_dist);
@@ -8113,10 +8114,10 @@
         if (!has_subpel_mv_component(xd->mi[0], xd, 1))
           mbmi->interp_filter[1] = EIGHTTAP_REGULAR;
 #endif  // CONFIG_DUAL_FILTER
-        av1_build_inter_predictors_sb(xd, mi_row, mi_col, orig_dst, bsize);
+        av1_build_inter_predictors_sb(cm, xd, mi_row, mi_col, orig_dst, bsize);
 #if CONFIG_EXT_INTER
       } else {
-        av1_build_inter_predictors_sb(xd, mi_row, mi_col, orig_dst, bsize);
+        av1_build_inter_predictors_sb(cm, xd, mi_row, mi_col, orig_dst, bsize);
 #endif  // CONFIG_EXT_INTER
       }
       av1_build_obmc_inter_prediction(
@@ -8147,7 +8148,7 @@
       if (find_projection(mbmi->num_proj_ref[0], pts, pts_inref, bsize,
                           mbmi->mv[0].as_mv.row, mbmi->mv[0].as_mv.col,
                           &mbmi->wm_params[0], mi_row, mi_col) == 0) {
-        av1_build_inter_predictors_sb(xd, mi_row, mi_col, NULL, bsize);
+        av1_build_inter_predictors_sb(cm, xd, mi_row, mi_col, NULL, bsize);
         model_rd_for_sb(cpi, bsize, x, xd, 0, MAX_MB_PLANE - 1, &tmp_rate,
                         &tmp_dist, skip_txfm_sb, skip_sse_sb);
       } else {
@@ -8660,7 +8661,8 @@
 
       switch (cur_type) {
         case COMPOUND_AVERAGE:
-          av1_build_inter_predictors_sby(xd, mi_row, mi_col, &orig_dst, bsize);
+          av1_build_inter_predictors_sby(cm, xd, mi_row, mi_col, &orig_dst,
+                                         bsize);
           av1_subtract_plane(x, bsize, 0);
           rd = estimate_yrd_for_sb(cpi, bsize, x, &rate_sum, &dist_sum,
                                    &tmp_skip_txfm_sb, &tmp_skip_sse_sb,
@@ -8914,7 +8916,7 @@
   if (pred_exists == 0) {
     int tmp_rate;
     int64_t tmp_dist;
-    av1_build_inter_predictors_sb(xd, mi_row, mi_col, &orig_dst, bsize);
+    av1_build_inter_predictors_sb(cm, xd, mi_row, mi_col, &orig_dst, bsize);
     model_rd_for_sb(cpi, bsize, x, xd, 0, MAX_MB_PLANE - 1, &tmp_rate,
                     &tmp_dist, &skip_txfm_sb, &skip_sse_sb);
     rd = RDCOST(x->rdmult, x->rddiv, rs + tmp_rate, tmp_dist);
@@ -9049,7 +9051,7 @@
 #endif
   mbmi->skip = 0;
   x->skip = 0;
-  av1_build_inter_predictors_sb(xd, mi_row, mi_col, NULL, bsize);
+  av1_build_inter_predictors_sb(cm, xd, mi_row, mi_col, NULL, bsize);
 
   int rate_mv = av1_mv_bit_cost(&dv, &dv_ref.as_mv, x->nmvjointcost, x->mvcost,
                                 MV_COST_WEIGHT);
@@ -10794,7 +10796,7 @@
     }
 
     if (is_inter_mode(mbmi->mode)) {
-      av1_build_inter_predictors_sb(xd, mi_row, mi_col, NULL, bsize);
+      av1_build_inter_predictors_sb(cm, xd, mi_row, mi_col, NULL, bsize);
 #if CONFIG_MOTION_VAR
       if (mbmi->motion_mode == OBMC_CAUSAL) {
         av1_build_obmc_inter_prediction(
@@ -11973,7 +11975,7 @@
         // then dont bother looking at UV
         int is_cost_valid_uv;
         RD_STATS rd_stats_uv;
-        av1_build_inter_predictors_sbuv(&x->e_mbd, mi_row, mi_col, NULL,
+        av1_build_inter_predictors_sbuv(cm, &x->e_mbd, mi_row, mi_col, NULL,
                                         BLOCK_8X8);
 #if CONFIG_VAR_TX
         is_cost_valid_uv =
@@ -12454,7 +12456,7 @@
   av1_setup_dst_planes(x->e_mbd.plane, bsize,
                        get_frame_new_buffer(&cpi->common), mi_row, mi_col);
 
-  av1_build_inter_predictors_sb(xd, mi_row, mi_col, NULL, bsize);
+  av1_build_inter_predictors_sb(cm, xd, mi_row, mi_col, NULL, bsize);
 
   av1_subtract_plane(x, bsize, 0);
   super_block_yrd(cpi, x, &rd_stats_y, bsize, INT64_MAX);