Correct some usages of subpel/fullpel conversion

Change-Id: I8b2af6047f96e2578b78a73e8df855f810e26a1e
diff --git a/av1/common/mv.h b/av1/common/mv.h
index d7c48da..d6823a0 100644
--- a/av1/common/mv.h
+++ b/av1/common/mv.h
@@ -62,6 +62,10 @@
   return subpel_mv;
 }
 
+static AOM_INLINE void convert_fullmv_to_mv(int_mv *mv) {
+  mv->as_mv = get_mv_from_fullmv(&mv->as_fullmv);
+}
+
 // Bits of precision used for the model
 #define WARPEDMODEL_PREC_BITS 16
 #define WARPEDMODEL_ROW3HOMO_PREC_BITS 16
diff --git a/av1/common/mvref_common.c b/av1/common/mvref_common.c
index 9ae0fe6..7479ec7 100644
--- a/av1/common/mvref_common.c
+++ b/av1/common/mvref_common.c
@@ -1058,10 +1058,10 @@
   int x = col_offset * MI_SIZE + sign_c * AOMMAX(bw, MI_SIZE) / 2 - 1;
   int y = row_offset * MI_SIZE + sign_r * AOMMAX(bh, MI_SIZE) / 2 - 1;
 
-  pts[0] = (x * 8);
-  pts[1] = (y * 8);
-  pts_inref[0] = (x * 8) + mbmi->mv[0].as_mv.col;
-  pts_inref[1] = (y * 8) + mbmi->mv[0].as_mv.row;
+  pts[0] = GET_MV_SUBPEL(x);
+  pts[1] = GET_MV_SUBPEL(y);
+  pts_inref[0] = GET_MV_SUBPEL(x) + mbmi->mv[0].as_mv.col;
+  pts_inref[1] = GET_MV_SUBPEL(y) + mbmi->mv[0].as_mv.row;
 }
 
 // Select samples according to the motion vector difference.
diff --git a/av1/common/mvref_common.h b/av1/common/mvref_common.h
index d12e5c5..9f441e2 100644
--- a/av1/common/mvref_common.h
+++ b/av1/common/mvref_common.h
@@ -50,10 +50,10 @@
 }
 
 static INLINE void clamp_mv_ref(MV *mv, int bw, int bh, const MACROBLOCKD *xd) {
-  clamp_mv(mv, xd->mb_to_left_edge - bw * 8 - MV_BORDER,
-           xd->mb_to_right_edge + bw * 8 + MV_BORDER,
-           xd->mb_to_top_edge - bh * 8 - MV_BORDER,
-           xd->mb_to_bottom_edge + bh * 8 + MV_BORDER);
+  clamp_mv(mv, xd->mb_to_left_edge - GET_MV_SUBPEL(bw) - MV_BORDER,
+           xd->mb_to_right_edge + GET_MV_SUBPEL(bw) + MV_BORDER,
+           xd->mb_to_top_edge - GET_MV_SUBPEL(bh) - MV_BORDER,
+           xd->mb_to_bottom_edge + GET_MV_SUBPEL(bh) + MV_BORDER);
 }
 
 // This function returns either the appropriate sub block or block's mv
@@ -272,14 +272,13 @@
                                    int mib_size, int mi_row, int mi_col) {
   (void)mi_col;
   if (mi_row - mib_size < tile->mi_row_start) {
-    ref_dv->as_mv.row = 0;
-    ref_dv->as_mv.col = -MI_SIZE * mib_size - INTRABC_DELAY_PIXELS;
+    ref_dv->as_fullmv.row = 0;
+    ref_dv->as_fullmv.col = -MI_SIZE * mib_size - INTRABC_DELAY_PIXELS;
   } else {
-    ref_dv->as_mv.row = -MI_SIZE * mib_size;
-    ref_dv->as_mv.col = 0;
+    ref_dv->as_fullmv.row = -MI_SIZE * mib_size;
+    ref_dv->as_fullmv.col = 0;
   }
-  ref_dv->as_mv.row *= 8;
-  ref_dv->as_mv.col *= 8;
+  convert_fullmv_to_mv(ref_dv);
 }
 
 static INLINE int av1_is_dv_valid(const MV dv, const AV1_COMMON *cm,
diff --git a/av1/common/onyxc_int.h b/av1/common/onyxc_int.h
index 52b1052..c567add6 100644
--- a/av1/common/onyxc_int.h
+++ b/av1/common/onyxc_int.h
@@ -839,10 +839,10 @@
 static INLINE void set_mi_row_col(MACROBLOCKD *xd, const TileInfo *const tile,
                                   int mi_row, int bh, int mi_col, int bw,
                                   int mi_rows, int mi_cols) {
-  xd->mb_to_top_edge = -((mi_row * MI_SIZE) * 8);
-  xd->mb_to_bottom_edge = ((mi_rows - bh - mi_row) * MI_SIZE) * 8;
-  xd->mb_to_left_edge = -((mi_col * MI_SIZE) * 8);
-  xd->mb_to_right_edge = ((mi_cols - bw - mi_col) * MI_SIZE) * 8;
+  xd->mb_to_top_edge = -GET_MV_SUBPEL(mi_row * MI_SIZE);
+  xd->mb_to_bottom_edge = GET_MV_SUBPEL((mi_rows - bh - mi_row) * MI_SIZE);
+  xd->mb_to_left_edge = -GET_MV_SUBPEL((mi_col * MI_SIZE));
+  xd->mb_to_right_edge = GET_MV_SUBPEL((mi_cols - bw - mi_col) * MI_SIZE);
 
   xd->mi_row = mi_row;
   xd->mi_col = mi_col;
diff --git a/av1/common/reconinter.c b/av1/common/reconinter.c
index fb6b344..ffa5e2f 100644
--- a/av1/common/reconinter.c
+++ b/av1/common/reconinter.c
@@ -1013,10 +1013,10 @@
                          ref_scale_factors, num_planes);
   }
 
-  xd->mb_to_top_edge = 8 * MI_SIZE * (-left_mi_row);
+  xd->mb_to_top_edge = GET_MV_SUBPEL(MI_SIZE * (-left_mi_row));
   xd->mb_to_bottom_edge =
       ctxt->mb_to_far_edge +
-      (xd->n4_h - rel_mi_row - left_mi_height) * MI_SIZE * 8;
+      GET_MV_SUBPEL((xd->n4_h - rel_mi_row - left_mi_height) * MI_SIZE);
 }
 
 /* clang-format off */
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 5783b85..0fd451f 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -958,7 +958,7 @@
   // except for 128-wide blocks, where we only use a height of 32.
   int this_height = xd->n4_h * MI_SIZE;
   int pred_height = AOMMIN(this_height / 2, 32);
-  xd->mb_to_bottom_edge += (this_height - pred_height) * 8;
+  xd->mb_to_bottom_edge += GET_MV_SUBPEL(this_height - pred_height);
   struct build_prediction_ctxt ctxt = { cm,         tmp_buf,
                                         tmp_width,  tmp_height,
                                         tmp_stride, xd->mb_to_right_edge };
@@ -967,9 +967,9 @@
                                 max_neighbor_obmc[mi_size_wide_log2[bsize]],
                                 dec_build_prediction_by_above_pred, &ctxt);
 
-  xd->mb_to_left_edge = -((xd->mi_col * MI_SIZE) * 8);
+  xd->mb_to_left_edge = -GET_MV_SUBPEL(xd->mi_col * MI_SIZE);
   xd->mb_to_right_edge = ctxt.mb_to_far_edge;
-  xd->mb_to_bottom_edge -= (this_height - pred_height) * 8;
+  xd->mb_to_bottom_edge -= GET_MV_SUBPEL(this_height - pred_height);
 }
 
 static INLINE void dec_build_prediction_by_left_pred(
@@ -1012,7 +1012,7 @@
   // except for 128-wide blocks, where we only use a width of 32.
   int this_width = xd->n4_w * MI_SIZE;
   int pred_width = AOMMIN(this_width / 2, 32);
-  xd->mb_to_right_edge += (this_width - pred_width) * 8;
+  xd->mb_to_right_edge += GET_MV_SUBPEL(this_width - pred_width);
 
   struct build_prediction_ctxt ctxt = { cm,         tmp_buf,
                                         tmp_width,  tmp_height,
@@ -1022,8 +1022,8 @@
                                max_neighbor_obmc[mi_size_high_log2[bsize]],
                                dec_build_prediction_by_left_pred, &ctxt);
 
-  xd->mb_to_top_edge = -((xd->mi_row * MI_SIZE) * 8);
-  xd->mb_to_right_edge -= (this_width - pred_width) * 8;
+  xd->mb_to_top_edge = -GET_MV_SUBPEL(xd->mi_row * MI_SIZE);
+  xd->mb_to_right_edge -= GET_MV_SUBPEL(this_width - pred_width);
   xd->mb_to_bottom_edge = ctxt.mb_to_far_edge;
 }
 
diff --git a/av1/encoder/firstpass.c b/av1/encoder/firstpass.c
index 26c9f9c..d8b6a3c 100644
--- a/av1/encoder/firstpass.c
+++ b/av1/encoder/firstpass.c
@@ -219,7 +219,8 @@
 }
 
 static AOM_INLINE void first_pass_motion_search(AV1_COMP *cpi, MACROBLOCK *x,
-                                                const MV *ref_mv, MV *best_mv,
+                                                const MV *ref_mv,
+                                                FULLPEL_MV *best_mv,
                                                 int *best_motion_err) {
   MACROBLOCKD *const xd = &x->e_mbd;
   FULLPEL_MV start_mv = get_fullmv_from_mv(ref_mv);
@@ -244,7 +245,7 @@
 
   if (tmp_err < *best_motion_err) {
     *best_motion_err = tmp_err;
-    *best_mv = x->best_mv.as_mv;
+    *best_mv = x->best_mv.as_fullmv;
   }
 }
 
@@ -532,7 +533,7 @@
       if (!frame_is_intra_only(cm)) {  // Do a motion search
         int tmp_err, motion_error, raw_motion_error;
         // Assume 0,0 motion with no mv overhead.
-        MV mv = kZeroMv, tmp_mv = kZeroMv;
+        FULLPEL_MV mv = kZeroFullMv, tmp_mv = kZeroFullMv;
         struct buf_2d unscaled_last_source_buf_2d;
 
         xd->plane[0].pre[0].buf = lst_yv12->y_buffer + recon_yoffset;
@@ -692,11 +693,10 @@
                              DOUBLE_DIVIDE_CHECK((double)this_intra_error);
           }
 
-          mv.row *= 8;
-          mv.col *= 8;
+          MV best_mv = get_mv_from_fullmv(&mv);
           this_intra_error = motion_error;
           xd->mi[0]->mode = NEWMV;
-          xd->mi[0]->mv[0].as_mv = mv;
+          xd->mi[0]->mv[0].as_mv = best_mv;
           xd->mi[0]->tx_size = TX_4X4;
           xd->mi[0]->ref_frame[0] = LAST_FRAME;
           xd->mi[0]->ref_frame[1] = NONE_FRAME;
@@ -704,22 +704,22 @@
                                         mb_col * mb_scale, NULL, bsize,
                                         AOM_PLANE_Y, AOM_PLANE_Y);
           av1_encode_sby_pass1(cm, x, bsize);
-          sum_mvr += mv.row;
-          sum_mvr_abs += abs(mv.row);
-          sum_mvc += mv.col;
-          sum_mvc_abs += abs(mv.col);
-          sum_mvrs += mv.row * mv.row;
-          sum_mvcs += mv.col * mv.col;
+          sum_mvr += best_mv.row;
+          sum_mvr_abs += abs(best_mv.row);
+          sum_mvc += best_mv.col;
+          sum_mvc_abs += abs(best_mv.col);
+          sum_mvrs += best_mv.row * best_mv.row;
+          sum_mvcs += best_mv.col * best_mv.col;
           ++intercount;
 
-          best_ref_mv = mv;
+          best_ref_mv = best_mv;
 
-          if (!is_zero_mv(&mv)) {
+          if (!is_zero_mv(&best_mv)) {
             ++mvcount;
 
             // Non-zero vector, was it different from the last non zero vector?
-            if (!is_equal_mv(&mv, &lastmv)) ++new_mv_count;
-            lastmv = mv;
+            if (!is_equal_mv(&best_mv, &lastmv)) ++new_mv_count;
+            lastmv = best_mv;
 
             // Does the row vector point inwards or outwards?
             if (mb_row < cm->mb_rows / 2) {
diff --git a/av1/encoder/mcomp.c b/av1/encoder/mcomp.c
index 055c95a..b4d70ba 100644
--- a/av1/encoder/mcomp.c
+++ b/av1/encoder/mcomp.c
@@ -50,9 +50,13 @@
 #define SSE_LAMBDA_HDRES 1  // Used by mv_cost_err_fn
 #define SAD_LAMBDA_HDRES 8  // Used by mvsad_err_cost during full pixel search
 
+static INLINE int get_offset_from_mv(const FULLPEL_MV *mv, int stride) {
+  return mv->row * stride + mv->col;
+}
+
 static INLINE const uint8_t *get_buf_from_mv(const struct buf_2d *buf,
                                              const FULLPEL_MV *mv) {
-  return &buf->buf[mv->row * buf->stride + mv->col];
+  return &buf->buf[get_offset_from_mv(mv, buf->stride)];
 }
 
 void av1_set_mv_search_range(MvLimits *mv_limits, const MV *mv) {
@@ -182,7 +186,7 @@
     for (i = 0; i <= num_search_pts; ++i) {
       search_site *const ss = &cfg->ss[stage_index][i];
       ss->mv = ss_mvs[i];
-      ss->offset = ss->mv.row * stride + ss->mv.col;
+      ss->offset = get_offset_from_mv(&ss->mv, stride);
     }
     cfg->searches_per_step[stage_index] = num_search_pts;
     cfg->radius[stage_index] = radius;
@@ -226,7 +230,7 @@
     for (i = 0; i <= num_search_pts; ++i) {
       search_site *const ss = &cfg->ss[stage_index][i];
       ss->mv = ss_mvs[i];
-      ss->offset = ss->mv.row * stride + ss->mv.col;
+      ss->offset = get_offset_from_mv(&ss->mv, stride);
     }
     cfg->searches_per_step[stage_index] = num_search_pts;
     cfg->radius[stage_index] = radius;
@@ -267,7 +271,7 @@
     for (int i = 0; i <= num_search_pts; ++i) {
       search_site *const ss = &cfg->ss[stage_index][i];
       ss->mv = ss_mvs[i];
-      ss->offset = ss->mv.row * stride + ss->mv.col;
+      ss->offset = get_offset_from_mv(&ss->mv, stride);
     }
     cfg->searches_per_step[stage_index] = num_search_pts;
     cfg->radius[stage_index] = radius;
@@ -418,35 +422,33 @@
     }                                              \
   }
 
-#define SETUP_SUBPEL_SEARCH                                             \
-  const uint8_t *const src_address = x->plane[0].src.buf;               \
-  const int src_stride = x->plane[0].src.stride;                        \
-  const MACROBLOCKD *xd = &x->e_mbd;                                    \
-  unsigned int besterr = INT_MAX;                                       \
-  unsigned int sse;                                                     \
-  unsigned int whichdir;                                                \
-  int thismse;                                                          \
-  MV *bestmv = &x->best_mv.as_mv;                                       \
-  const unsigned int halfiters = iters_per_step;                        \
-  const unsigned int quarteriters = iters_per_step;                     \
-  const unsigned int eighthiters = iters_per_step;                      \
-  const int y_stride = xd->plane[0].pre[0].stride;                      \
-  const int offset = bestmv->row * y_stride + bestmv->col;              \
-  const uint8_t *const y = xd->plane[0].pre[0].buf;                     \
-  const MV_COST_TYPE mv_cost_type = x->mv_cost_type;                    \
-                                                                        \
-  int br = bestmv->row * 8;                                             \
-  int bc = bestmv->col * 8;                                             \
-  int hstep = 4;                                                        \
-  int minc, maxc, minr, maxr;                                           \
-  int tr = br;                                                          \
-  int tc = bc;                                                          \
-                                                                        \
-  set_subpel_mv_search_range(&x->mv_limits, &minc, &maxc, &minr, &maxr, \
-                             ref_mv);                                   \
-                                                                        \
-  bestmv->row *= 8;                                                     \
-  bestmv->col *= 8;
+#define SETUP_SUBPEL_SEARCH                                               \
+  const uint8_t *const src_address = x->plane[0].src.buf;                 \
+  const int src_stride = x->plane[0].src.stride;                          \
+  const MACROBLOCKD *xd = &x->e_mbd;                                      \
+  unsigned int besterr = INT_MAX;                                         \
+  unsigned int sse;                                                       \
+  unsigned int whichdir;                                                  \
+  int thismse;                                                            \
+  const unsigned int halfiters = iters_per_step;                          \
+  const unsigned int quarteriters = iters_per_step;                       \
+  const unsigned int eighthiters = iters_per_step;                        \
+  const int y_stride = xd->plane[0].pre[0].stride;                        \
+  const int offset = get_offset_from_mv(&x->best_mv.as_fullmv, y_stride); \
+  const uint8_t *const y = xd->plane[0].pre[0].buf;                       \
+  const MV_COST_TYPE mv_cost_type = x->mv_cost_type;                      \
+                                                                          \
+  convert_fullmv_to_mv(&x->best_mv);                                      \
+  MV *bestmv = &x->best_mv.as_mv;                                         \
+                                                                          \
+  int br = bestmv->row;                                                   \
+  int bc = bestmv->col;                                                   \
+  int hstep = 4;                                                          \
+  int minc, maxc, minr, maxr;                                             \
+  int tr = br;                                                            \
+  int tc = bc;                                                            \
+                                                                          \
+  set_subpel_mv_search_range(&x->mv_limits, &minc, &maxc, &minr, &maxr, ref_mv);
 
 static unsigned int setup_center_error(
     const MACROBLOCKD *xd, const MV *bestmv, const MV *ref_mv,
@@ -893,13 +895,14 @@
   unsigned int sse;
   unsigned int thismse;
   const int y_stride = xd->plane[0].pre[0].stride;
-  MV *bestmv = &x->best_mv.as_mv;
-  const int offset = bestmv->row * y_stride + bestmv->col;
+  const int offset = get_offset_from_mv(&x->best_mv.as_fullmv, y_stride);
   const uint8_t *const y = xd->plane[0].pre[0].buf;
   const MV_COST_TYPE mv_cost_type = x->mv_cost_type;
+  convert_fullmv_to_mv(&x->best_mv);
+  MV *bestmv = &x->best_mv.as_mv;
 
-  int br = bestmv->row * 8;
-  int bc = bestmv->col * 8;
+  int br = bestmv->row;
+  int bc = bestmv->col;
   int hstep = 4;
   int iter, round = 3 - forced_stop;
   int tr = br;
@@ -915,9 +918,6 @@
   if (!allow_hp)
     if (round == 3) round = 2;
 
-  bestmv->row *= 8;
-  bestmv->col *= 8;
-
   if (use_accurate_subpel_search)
     besterr = upsampled_setup_center_error(
         xd, cm, mi_row, mi_col, bestmv, ref_mv, error_per_bit, vfp, src_address,
@@ -2394,7 +2394,7 @@
     best_sad = tmp_sad;
   }
 
-  best_int_mv->as_mv = get_mv_from_fullmv(&best_int_mv->as_fullmv);
+  convert_fullmv_to_mv(best_int_mv);
 
   set_subpel_mv_search_range(
       &x->mv_limits, &subpel_mv_limits.col_min, &subpel_mv_limits.col_max,
@@ -2697,11 +2697,10 @@
   unsigned int sse;
   unsigned int thismse;
   const int y_stride = pd->pre[0].stride;
-  const int offset =
-      x->best_mv.as_fullmv.row * y_stride + x->best_mv.as_fullmv.col;
+  const int offset = get_offset_from_mv(&x->best_mv.as_fullmv, y_stride);
   const uint8_t *y = pd->pre[0].buf;
   const MV_COST_TYPE mv_cost_type = x->mv_cost_type;
-  x->best_mv.as_mv = get_mv_from_fullmv(&x->best_mv.as_fullmv);
+  convert_fullmv_to_mv(&x->best_mv);
   MV *bestmv = &x->best_mv.as_mv;
 
   int br = bestmv->row;
diff --git a/av1/encoder/mcomp.h b/av1/encoder/mcomp.h
index 1621a34..1d84370 100644
--- a/av1/encoder/mcomp.h
+++ b/av1/encoder/mcomp.h
@@ -190,11 +190,15 @@
                                               int *col_min, int *col_max,
                                               int *row_min, int *row_max,
                                               const MV *ref_mv) {
-  const int max_mv = MAX_FULL_PEL_VAL * 8;
-  const int minc = AOMMAX(mv_limits->col_min * 8, ref_mv->col - max_mv);
-  const int maxc = AOMMIN(mv_limits->col_max * 8, ref_mv->col + max_mv);
-  const int minr = AOMMAX(mv_limits->row_min * 8, ref_mv->row - max_mv);
-  const int maxr = AOMMIN(mv_limits->row_max * 8, ref_mv->row + max_mv);
+  const int max_mv = GET_MV_SUBPEL(MAX_FULL_PEL_VAL);
+  const int minc =
+      AOMMAX(GET_MV_SUBPEL(mv_limits->col_min), ref_mv->col - max_mv);
+  const int maxc =
+      AOMMIN(GET_MV_SUBPEL(mv_limits->col_max), ref_mv->col + max_mv);
+  const int minr =
+      AOMMAX(GET_MV_SUBPEL(mv_limits->row_min), ref_mv->row - max_mv);
+  const int maxr =
+      AOMMIN(GET_MV_SUBPEL(mv_limits->row_max), ref_mv->row + max_mv);
 
   *col_min = AOMMAX(MV_LOW + 1, minc);
   *col_max = AOMMIN(MV_UPP - 1, maxc);
diff --git a/av1/encoder/motion_search_facade.c b/av1/encoder/motion_search_facade.c
index 80c003e..c8bff71 100644
--- a/av1/encoder/motion_search_facade.c
+++ b/av1/encoder/motion_search_facade.c
@@ -149,8 +149,7 @@
   x->mv_limits = tmp_mv_limits;
 
   if (cpi->common.cur_frame_force_integer_mv) {
-    x->best_mv.as_mv.row *= 8;
-    x->best_mv.as_mv.col *= 8;
+    convert_fullmv_to_mv(&x->best_mv);
   }
   const int use_fractional_mv =
       bestsme < INT_MAX && cpi->common.cur_frame_force_integer_mv == 0;
@@ -173,21 +172,21 @@
               cpi->sf.mv_sf.use_accurate_subpel_search, 1);
 
           if (try_second) {
-            const int minc =
-                AOMMAX(x->mv_limits.col_min * 8, ref_mv.col - MV_MAX);
-            const int maxc =
-                AOMMIN(x->mv_limits.col_max * 8, ref_mv.col + MV_MAX);
-            const int minr =
-                AOMMAX(x->mv_limits.row_min * 8, ref_mv.row - MV_MAX);
-            const int maxr =
-                AOMMIN(x->mv_limits.row_max * 8, ref_mv.row + MV_MAX);
+            const int minc = AOMMAX(GET_MV_SUBPEL(x->mv_limits.col_min),
+                                    ref_mv.col - MV_MAX);
+            const int maxc = AOMMIN(GET_MV_SUBPEL(x->mv_limits.col_max),
+                                    ref_mv.col + MV_MAX);
+            const int minr = AOMMAX(GET_MV_SUBPEL(x->mv_limits.row_min),
+                                    ref_mv.row - MV_MAX);
+            const int maxr = AOMMIN(GET_MV_SUBPEL(x->mv_limits.row_max),
+                                    ref_mv.row + MV_MAX);
             MV best_mv = x->best_mv.as_mv;
 
             x->best_mv = x->second_best_mv;
-            if (x->best_mv.as_mv.row * 8 <= maxr &&
-                x->best_mv.as_mv.row * 8 >= minr &&
-                x->best_mv.as_mv.col * 8 <= maxc &&
-                x->best_mv.as_mv.col * 8 >= minc) {
+            if (GET_MV_SUBPEL(x->best_mv.as_mv.row) <= maxr &&
+                GET_MV_SUBPEL(x->best_mv.as_mv.row) >= minr &&
+                GET_MV_SUBPEL(x->best_mv.as_mv.col) <= maxc &&
+                GET_MV_SUBPEL(x->best_mv.as_mv.col) >= minc) {
               const int this_var = cpi->find_fractional_mv_step(
                   x, cm, mi_row, mi_col, &ref_mv, cm->allow_high_precision_mv,
                   x->errorperbit, &cpi->fn_ptr[bsize],
@@ -377,7 +376,7 @@
     if (id) xd->plane[plane].pre[0] = ref_yv12[id];
 
     if (cpi->common.cur_frame_force_integer_mv) {
-      best_int_mv->as_mv = get_mv_from_fullmv(&best_int_mv->as_fullmv);
+      convert_fullmv_to_mv(best_int_mv);
     }
     if (bestsme < INT_MAX && cpi->common.cur_frame_force_integer_mv == 0) {
       int dis; /* TODO: use dis in distortion calculation later. */
@@ -495,7 +494,7 @@
   }
 
   if (cpi->common.cur_frame_force_integer_mv) {
-    best_int_mv->as_mv = get_mv_from_fullmv(&best_int_mv->as_fullmv);
+    convert_fullmv_to_mv(best_int_mv);
   }
   const int use_fractional_mv =
       bestsme < INT_MAX && cpi->common.cur_frame_force_integer_mv == 0;
diff --git a/av1/encoder/nonrd_pickmode.c b/av1/encoder/nonrd_pickmode.c
index ecf00e2..71e457e 100644
--- a/av1/encoder/nonrd_pickmode.c
+++ b/av1/encoder/nonrd_pickmode.c
@@ -159,9 +159,7 @@
   x->mv_limits = tmp_mv_limits;
   *tmp_mv = x->best_mv;
   // calculate the bit cost on motion vector
-  MV mvp_full;
-  mvp_full.row = tmp_mv->as_mv.row * 8;
-  mvp_full.col = tmp_mv->as_mv.col * 8;
+  MV mvp_full = get_mv_from_fullmv(&tmp_mv->as_fullmv);
 
   *rate_mv = av1_mv_bit_cost(&mvp_full, &ref_mv, x->nmv_vec_cost,
                              x->mv_cost_stack, MV_COST_WEIGHT);
diff --git a/av1/encoder/partition_strategy.h b/av1/encoder/partition_strategy.h
index ee1d475..8295963 100644
--- a/av1/encoder/partition_strategy.h
+++ b/av1/encoder/partition_strategy.h
@@ -163,10 +163,12 @@
 
   // Set up distance of MB to edge of frame in 1/8th pel units.
   assert(!(mi_col & (mi_width - 1)) && !(mi_row & (mi_height - 1)));
-  xd->mb_to_top_edge = -((mi_row * MI_SIZE) * 8);
-  xd->mb_to_bottom_edge = ((cm->mi_rows - mi_height - mi_row) * MI_SIZE) * 8;
-  xd->mb_to_left_edge = -((mi_col * MI_SIZE) * 8);
-  xd->mb_to_right_edge = ((cm->mi_cols - mi_width - mi_col) * MI_SIZE) * 8;
+  xd->mb_to_top_edge = -GET_MV_SUBPEL(mi_row * MI_SIZE);
+  xd->mb_to_bottom_edge =
+      GET_MV_SUBPEL((cm->mi_rows - mi_height - mi_row) * MI_SIZE);
+  xd->mb_to_left_edge = -GET_MV_SUBPEL(mi_col * MI_SIZE);
+  xd->mb_to_right_edge =
+      GET_MV_SUBPEL((cm->mi_cols - mi_width - mi_col) * MI_SIZE);
 
   // Set up source buffers.
   av1_setup_src_planes(x, cpi->source, mi_row, mi_col, num_planes, bsize);
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index 0e92590..c6e5a2e 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -2503,8 +2503,7 @@
 
     x->mv_limits = tmp_mv_limits;
     if (bestsme == INT_MAX) continue;
-    const MV dv = { .row = x->best_mv.as_mv.row * 8,
-                    .col = x->best_mv.as_mv.col * 8 };
+    const MV dv = get_mv_from_fullmv(&x->best_mv.as_fullmv);
     if (mv_check_bounds(&x->mv_limits, &dv)) continue;
     if (!av1_is_dv_valid(dv, cm, xd, mi_row, mi_col, bsize,
                          cm->seq_params.mib_size_log2))
diff --git a/av1/encoder/tpl_model.c b/av1/encoder/tpl_model.c
index dcc3459..b6ba4bf 100644
--- a/av1/encoder/tpl_model.c
+++ b/av1/encoder/tpl_model.c
@@ -752,8 +752,9 @@
     x->mv_limits.row_min = -((mi_row * MI_SIZE) + (17 - 2 * AOM_INTERP_EXTEND));
     x->mv_limits.row_max = (cm->mi_rows - mi_height - mi_row) * MI_SIZE +
                            (17 - 2 * AOM_INTERP_EXTEND);
-    xd->mb_to_top_edge = -((mi_row * MI_SIZE) * 8);
-    xd->mb_to_bottom_edge = ((cm->mi_rows - mi_height - mi_row) * MI_SIZE) * 8;
+    xd->mb_to_top_edge = -GET_MV_SUBPEL(mi_row * MI_SIZE);
+    xd->mb_to_bottom_edge =
+        GET_MV_SUBPEL((cm->mi_rows - mi_height - mi_row) * MI_SIZE);
     for (mi_col = 0; mi_col < cm->mi_cols; mi_col += mi_width) {
       TplDepStats tpl_stats;
 
@@ -762,8 +763,8 @@
           -((mi_col * MI_SIZE) + (17 - 2 * AOM_INTERP_EXTEND));
       x->mv_limits.col_max = ((cm->mi_cols - mi_width - mi_col) * MI_SIZE) +
                              (17 - 2 * AOM_INTERP_EXTEND);
-      xd->mb_to_left_edge = -((mi_col * MI_SIZE) * 8);
-      xd->mb_to_right_edge = ((cm->mi_cols - mi_width - mi_col) * MI_SIZE) * 8;
+      xd->mb_to_left_edge = -GET_MV_SUBPEL(mi_col * MI_SIZE);
+      xd->mb_to_right_edge = GET_MV_SUBPEL(cm->mi_cols - mi_width - mi_col);
       mode_estimation(cpi, x, xd, &sf, frame_idx, mi_row, mi_col, bsize,
                       tx_size, ref_frame, src_frame, &tpl_stats);