Merge ref-mv into codebase

Change-Id: I96e386678f6227f3ca735c9be2725cb9795b3296
diff --git a/av1/decoder/decodemv.c b/av1/decoder/decodemv.c
index ec0f877..3adc235 100644
--- a/av1/decoder/decodemv.c
+++ b/av1/decoder/decodemv.c
@@ -221,7 +221,6 @@
 
 static PREDICTION_MODE read_inter_mode(FRAME_CONTEXT *ec_ctx, MACROBLOCKD *xd,
                                        aom_reader *r, int16_t ctx) {
-#if CONFIG_REF_MV
   FRAME_COUNTS *counts = xd->counts;
   int16_t mode_ctx = ctx & NEWMV_CTX_MASK;
   aom_prob mode_prob = ec_ctx->newmv_prob[mode_ctx];
@@ -262,22 +261,8 @@
 
   // Invalid prediction mode.
   assert(0);
-#else
-#if CONFIG_EC_MULTISYMBOL
-  const int mode = av1_inter_mode_inv[aom_read_symbol(
-      r, ec_ctx->inter_mode_cdf[ctx], INTER_MODES, ACCT_STR)];
-#else
-  const int mode = aom_read_tree(r, av1_inter_mode_tree,
-                                 ec_ctx->inter_mode_probs[ctx], ACCT_STR);
-#endif
-  FRAME_COUNTS *counts = xd->counts;
-  if (counts) ++counts->inter_mode[ctx][mode];
-
-  return NEARESTMV + mode;
-#endif
 }
 
-#if CONFIG_REF_MV
 static void read_drl_idx(const AV1_COMMON *cm, MACROBLOCKD *xd,
                          MB_MODE_INFO *mbmi, aom_reader *r) {
   uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
@@ -324,7 +309,6 @@
     }
   }
 }
-#endif
 
 #if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
 static MOTION_MODE read_motion_mode(AV1_COMMON *cm, MACROBLOCKD *xd,
@@ -1477,7 +1461,6 @@
   FRAME_CONTEXT *ec_ctx = cm->fc;
 #endif
   BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
-#if CONFIG_REF_MV
   MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
 #if CONFIG_CB4X4
   int_mv *pred_mv = mbmi->pred_mv;
@@ -1486,9 +1469,6 @@
   int_mv *pred_mv =
       (bsize >= BLOCK_8X8) ? mbmi->pred_mv : xd->mi[0]->bmi[block].pred_mv;
 #endif  // CONFIG_CB4X4
-#else
-  (void)block;
-#endif  // CONFIG_REF_MV
   (void)ref_frame;
   (void)cm;
   (void)mi_row;
@@ -1498,12 +1478,7 @@
   switch (mode) {
     case NEWMV: {
       FRAME_COUNTS *counts = xd->counts;
-#if !CONFIG_REF_MV
-      nmv_context *const nmvc = &ec_ctx->nmvc;
-      nmv_context_counts *const mv_counts = counts ? &counts->mv : NULL;
-#endif
       for (i = 0; i < 1 + is_compound; ++i) {
-#if CONFIG_REF_MV
         int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
         int nmv_ctx =
             av1_nmv_ctx(xd->ref_mv_count[rf_type], xd->ref_mv_stack[rf_type], i,
@@ -1511,13 +1486,10 @@
         nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
         nmv_context_counts *const mv_counts =
             counts ? &counts->mv[nmv_ctx] : NULL;
-#endif
         read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, nmvc, mv_counts, allow_hp);
         ret = ret && is_mv_valid(&mv[i].as_mv);
 
-#if CONFIG_REF_MV
         pred_mv[i].as_int = ref_mv[i].as_int;
-#endif
       }
       break;
     }
@@ -1525,20 +1497,16 @@
       mv[0].as_int = nearest_mv[0].as_int;
       if (is_compound) mv[1].as_int = nearest_mv[1].as_int;
 
-#if CONFIG_REF_MV
       pred_mv[0].as_int = nearest_mv[0].as_int;
       if (is_compound) pred_mv[1].as_int = nearest_mv[1].as_int;
-#endif
       break;
     }
     case NEARMV: {
       mv[0].as_int = near_mv[0].as_int;
       if (is_compound) mv[1].as_int = near_mv[1].as_int;
 
-#if CONFIG_REF_MV
       pred_mv[0].as_int = near_mv[0].as_int;
       if (is_compound) pred_mv[1].as_int = near_mv[1].as_int;
-#endif
       break;
     }
     case ZEROMV: {
@@ -1557,22 +1525,15 @@
       if (is_compound) mv[1].as_int = 0;
 #endif  // CONFIG_GLOBAL_MOTION
 
-#if CONFIG_REF_MV
       pred_mv[0].as_int = mv[0].as_int;
       if (is_compound) pred_mv[1].as_int = mv[1].as_int;
-#endif
       break;
     }
 #if CONFIG_EXT_INTER
     case NEW_NEWMV: {
       FRAME_COUNTS *counts = xd->counts;
-#if !CONFIG_REF_MV
-      nmv_context *const nmvc = &ec_ctx->nmvc;
-      nmv_context_counts *const mv_counts = counts ? &counts->mv : NULL;
-#endif
       assert(is_compound);
       for (i = 0; i < 2; ++i) {
-#if CONFIG_REF_MV
         int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
         int nmv_ctx =
             av1_nmv_ctx(xd->ref_mv_count[rf_type], xd->ref_mv_stack[rf_type], i,
@@ -1580,7 +1541,6 @@
         nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
         nmv_context_counts *const mv_counts =
             counts ? &counts->mv[nmv_ctx] : NULL;
-#endif
         read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, nmvc, mv_counts, allow_hp);
         ret = ret && is_mv_valid(&mv[i].as_mv);
       }
@@ -1612,17 +1572,12 @@
     }
     case NEW_NEARESTMV: {
       FRAME_COUNTS *counts = xd->counts;
-#if CONFIG_REF_MV
       int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
       int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type],
                                 xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx);
       nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
       nmv_context_counts *const mv_counts =
           counts ? &counts->mv[nmv_ctx] : NULL;
-#else
-      nmv_context *const nmvc = &ec_ctx->nmvc;
-      nmv_context_counts *const mv_counts = counts ? &counts->mv : NULL;
-#endif
       read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp);
       assert(is_compound);
       ret = ret && is_mv_valid(&mv[0].as_mv);
@@ -1631,17 +1586,12 @@
     }
     case NEAREST_NEWMV: {
       FRAME_COUNTS *counts = xd->counts;
-#if CONFIG_REF_MV
       int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
       int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type],
                                 xd->ref_mv_stack[rf_type], 1, mbmi->ref_mv_idx);
       nmv_context_counts *const mv_counts =
           counts ? &counts->mv[nmv_ctx] : NULL;
       nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
-#else
-      nmv_context *const nmvc = &ec_ctx->nmvc;
-      nmv_context_counts *const mv_counts = counts ? &counts->mv : NULL;
-#endif
       mv[0].as_int = nearest_mv[0].as_int;
       read_mv(r, &mv[1].as_mv, &ref_mv[1].as_mv, nmvc, mv_counts, allow_hp);
       assert(is_compound);
@@ -1650,17 +1600,12 @@
     }
     case NEAR_NEWMV: {
       FRAME_COUNTS *counts = xd->counts;
-#if CONFIG_REF_MV
       int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
       int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type],
                                 xd->ref_mv_stack[rf_type], 1, mbmi->ref_mv_idx);
       nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
       nmv_context_counts *const mv_counts =
           counts ? &counts->mv[nmv_ctx] : NULL;
-#else
-      nmv_context *const nmvc = &ec_ctx->nmvc;
-      nmv_context_counts *const mv_counts = counts ? &counts->mv : NULL;
-#endif
       mv[0].as_int = near_mv[0].as_int;
       read_mv(r, &mv[1].as_mv, &ref_mv[1].as_mv, nmvc, mv_counts, allow_hp);
       assert(is_compound);
@@ -1670,17 +1615,12 @@
     }
     case NEW_NEARMV: {
       FRAME_COUNTS *counts = xd->counts;
-#if CONFIG_REF_MV
       int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
       int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type],
                                 xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx);
       nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
       nmv_context_counts *const mv_counts =
           counts ? &counts->mv[nmv_ctx] : NULL;
-#else
-      nmv_context *const nmvc = &ec_ctx->nmvc;
-      nmv_context_counts *const mv_counts = counts ? &counts->mv : NULL;
-#endif
       read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp);
       assert(is_compound);
       ret = ret && is_mv_valid(&mv[0].as_mv);
@@ -1748,9 +1688,9 @@
   int_mv ref_mvs[MODE_CTX_REF_FRAMES][MAX_MV_REF_CANDIDATES];
   int ref, is_compound;
   int16_t inter_mode_ctx[MODE_CTX_REF_FRAMES];
-#if CONFIG_REF_MV && CONFIG_EXT_INTER
+#if CONFIG_EXT_INTER
   int16_t compound_inter_mode_ctx[MODE_CTX_REF_FRAMES];
-#endif  // CONFIG_REF_MV && CONFIG_EXT_INTER
+#endif  // CONFIG_EXT_INTER
   int16_t mode_ctx = 0;
 #if CONFIG_WARPED_MOTION
   int pts[SAMPLES_ARRAY_SIZE], pts_inref[SAMPLES_ARRAY_SIZE];
@@ -1774,18 +1714,14 @@
   for (ref = 0; ref < 1 + is_compound; ++ref) {
     MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref];
 
-    av1_find_mv_refs(cm, xd, mi, frame,
-#if CONFIG_REF_MV
-                     &xd->ref_mv_count[frame], xd->ref_mv_stack[frame],
+    av1_find_mv_refs(
+        cm, xd, mi, frame, &xd->ref_mv_count[frame], xd->ref_mv_stack[frame],
 #if CONFIG_EXT_INTER
-                     compound_inter_mode_ctx,
+        compound_inter_mode_ctx,
 #endif  // CONFIG_EXT_INTER
-#endif
-                     ref_mvs[frame], mi_row, mi_col, fpm_sync, (void *)pbi,
-                     inter_mode_ctx);
+        ref_mvs[frame], mi_row, mi_col, fpm_sync, (void *)pbi, inter_mode_ctx);
   }
 
-#if CONFIG_REF_MV
   if (is_compound) {
     MV_REFERENCE_FRAME ref_frame = av1_ref_frame_type(mbmi->ref_frame);
     av1_find_mv_refs(cm, xd, mi, ref_frame, &xd->ref_mv_count[ref_frame],
@@ -1833,9 +1769,6 @@
     mode_ctx =
         av1_mode_context_analyzer(inter_mode_ctx, mbmi->ref_frame, bsize, -1);
   mbmi->ref_mv_idx = 0;
-#else
-  mode_ctx = inter_mode_ctx[mbmi->ref_frame[0]];
-#endif
 
   if (segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) {
     mbmi->mode = ZEROMV;
@@ -1852,7 +1785,6 @@
       else
 #endif  // CONFIG_EXT_INTER
         mbmi->mode = read_inter_mode(ec_ctx, xd, r, mode_ctx);
-#if CONFIG_REF_MV
 #if CONFIG_EXT_INTER
       if (mbmi->mode == NEWMV || mbmi->mode == NEW_NEWMV ||
           have_nearmv_in_inter_mode(mbmi->mode))
@@ -1860,7 +1792,6 @@
       if (mbmi->mode == NEARMV || mbmi->mode == NEWMV)
 #endif
         read_drl_idx(cm, xd, mbmi, r);
-#endif
     }
   }
 
@@ -1876,7 +1807,6 @@
     }
   }
 
-#if CONFIG_REF_MV
   if (mbmi->ref_mv_idx > 0) {
     int_mv cur_mv =
         xd->ref_mv_stack[mbmi->ref_frame[0]][1 + mbmi->ref_mv_idx].this_mv;
@@ -1938,7 +1868,6 @@
     }
 #endif  // CONFIG_EXT_INTER
   }
-#endif
 
 #if !CONFIG_DUAL_FILTER && !CONFIG_WARPED_MOTION && !CONFIG_GLOBAL_MOTION
   read_mb_interp_filter(cm, xd, mbmi, r);
@@ -1958,13 +1887,11 @@
         int_mv block[2];
         const int j = idy * 2 + idx;
         int_mv ref_mv_s8[2];
-#if CONFIG_REF_MV
 #if CONFIG_EXT_INTER
         if (!is_compound)
 #endif  // CONFIG_EXT_INTER
           mode_ctx = av1_mode_context_analyzer(inter_mode_ctx, mbmi->ref_frame,
                                                bsize, j);
-#endif
 #if CONFIG_EXT_INTER
         if (is_compound)
           b_mode = read_inter_compound_mode(cm, xd, r, mode_ctx);
@@ -1977,10 +1904,8 @@
 #else
         if (b_mode != ZEROMV) {
 #endif  // CONFIG_EXT_INTER
-#if CONFIG_REF_MV
           CANDIDATE_MV ref_mv_stack[2][MAX_REF_MV_STACK_SIZE];
           uint8_t ref_mv_count[2];
-#endif
           for (ref = 0; ref < 1 + is_compound; ++ref)
 #if CONFIG_EXT_INTER
           {
@@ -1989,9 +1914,7 @@
                                   j, mi_row, mi_col, NULL);
 #endif  // CONFIG_EXT_INTER
             av1_append_sub8x8_mvs_for_idx(cm, xd, j, ref, mi_row, mi_col,
-#if CONFIG_REF_MV
                                           ref_mv_stack[ref], &ref_mv_count[ref],
-#endif
 #if CONFIG_EXT_INTER
                                           mv_ref_list,
 #endif  // CONFIG_EXT_INTER
@@ -2009,12 +1932,8 @@
         }
 
         for (ref = 0; ref < 1 + is_compound && b_mode != ZEROMV; ++ref) {
-#if CONFIG_REF_MV
           ref_mv_s8[ref] = nearest_sub8x8[ref];
           lower_mv_precision(&ref_mv_s8[ref].as_mv, allow_hp);
-#else
-          ref_mv_s8[ref] = nearestmv[ref];
-#endif
         }
 #if CONFIG_EXT_INTER
         (void)ref_mv_s8;
@@ -2041,10 +1960,8 @@
       }
     }
 
-#if CONFIG_REF_MV
     mbmi->pred_mv[0].as_int = mi->bmi[3].pred_mv[0].as_int;
     mbmi->pred_mv[1].as_int = mi->bmi[3].pred_mv[1].as_int;
-#endif
     mi->mbmi.mode = b_mode;
 
     mbmi->mv[0].as_int = mi->bmi[3].as_mv[0].as_int;
@@ -2056,42 +1973,35 @@
 
 #if CONFIG_EXT_INTER
     if (is_compound) {
-#if CONFIG_REF_MV
       int ref_mv_idx = mbmi->ref_mv_idx;
       // Special case: NEAR_NEWMV and NEW_NEARMV modes use
       // 1 + mbmi->ref_mv_idx (like NEARMV) instead of
       // mbmi->ref_mv_idx (like NEWMV)
       if (mbmi->mode == NEAR_NEWMV || mbmi->mode == NEW_NEARMV)
         ref_mv_idx = 1 + mbmi->ref_mv_idx;
-#endif
 
       if (compound_ref0_mode(mbmi->mode) == NEWMV) {
-#if CONFIG_REF_MV
         uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
         if (xd->ref_mv_count[ref_frame_type] > 1) {
           ref_mv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv;
           clamp_mv_ref(&ref_mv[0].as_mv, xd->n8_w << MI_SIZE_LOG2,
                        xd->n8_h << MI_SIZE_LOG2, xd);
         }
-#endif
         nearestmv[0] = ref_mv[0];
       }
       if (compound_ref1_mode(mbmi->mode) == NEWMV) {
-#if CONFIG_REF_MV
         uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
         if (xd->ref_mv_count[ref_frame_type] > 1) {
           ref_mv[1] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].comp_mv;
           clamp_mv_ref(&ref_mv[1].as_mv, xd->n8_w << MI_SIZE_LOG2,
                        xd->n8_h << MI_SIZE_LOG2, xd);
         }
-#endif
         nearestmv[1] = ref_mv[1];
       }
     } else {
 #endif  // CONFIG_EXT_INTER
       if (mbmi->mode == NEWMV) {
         for (ref = 0; ref < 1 + is_compound; ++ref) {
-#if CONFIG_REF_MV
           uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
           if (xd->ref_mv_count[ref_frame_type] > 1) {
             ref_mv[ref] =
@@ -2102,7 +2012,6 @@
             clamp_mv_ref(&ref_mv[ref].as_mv, xd->n8_w << MI_SIZE_LOG2,
                          xd->n8_h << MI_SIZE_LOG2, xd);
           }
-#endif
           nearestmv[ref] = ref_mv[ref];
         }
       }
@@ -2371,7 +2280,6 @@
 
   if (frame_is_intra_only(cm)) {
     read_intra_frame_mode_info(cm, xd, mi_row, mi_col, r);
-#if CONFIG_REF_MV
     for (h = 0; h < y_mis; ++h) {
       MV_REF *const frame_mv = frame_mvs + h * cm->mi_cols;
       for (w = 0; w < x_mis; ++w) {
@@ -2380,7 +2288,6 @@
         mv->ref_frame[1] = NONE_FRAME;
       }
     }
-#endif
   } else {
     read_inter_frame_mode_info(pbi, xd,
 #if CONFIG_SUPERTX
@@ -2395,10 +2302,8 @@
         mv->ref_frame[1] = mi->mbmi.ref_frame[1];
         mv->mv[0].as_int = mi->mbmi.mv[0].as_int;
         mv->mv[1].as_int = mi->mbmi.mv[1].as_int;
-#if CONFIG_REF_MV
         mv->pred_mv[0].as_int = mi->mbmi.pred_mv[0].as_int;
         mv->pred_mv[1].as_int = mi->mbmi.pred_mv[1].as_int;
-#endif
       }
     }
   }