Remove adaptive motion search speed feature

Adaptive motion search speed feature was previously disabled due to
multi-thread mismatch. Currently, the encoder achieves a similar
functionality with the use of mvs from tpl models, so the speed feature
is no longer needed.

BUG=aomedia:2694

Change-Id: Ie719c630ca8ec30a52b96a123adc72844f171316
diff --git a/av1/encoder/block.h b/av1/encoder/block.h
index 8e5fb6f..fe29513 100644
--- a/av1/encoder/block.h
+++ b/av1/encoder/block.h
@@ -747,9 +747,6 @@
   // Some of these are not currently used by the codec so they should probably
   // be removed.
   unsigned int simple_motion_pred_sse;
-
-  // Used to store sub partition's choices.
-  MV pred_mv[REF_FRAMES];
 };
 
 // Only consider full SB, MC_FLOW_BSIZE_1D = 16.
diff --git a/av1/encoder/context_tree.c b/av1/encoder/context_tree.c
index 4cf58c1..6d07ef2 100644
--- a/av1/encoder/context_tree.c
+++ b/av1/encoder/context_tree.c
@@ -38,8 +38,6 @@
 
   dst_ctx->rd_stats = src_ctx->rd_stats;
   dst_ctx->rd_mode_is_ready = src_ctx->rd_mode_is_ready;
-
-  memcpy(dst_ctx->pred_mv, src_ctx->pred_mv, sizeof(MV) * REF_FRAMES);
 }
 
 void av1_setup_shared_coeff_buffer(AV1_COMMON *cm,
diff --git a/av1/encoder/context_tree.h b/av1/encoder/context_tree.h
index cb9bdfc..bef99ca 100644
--- a/av1/encoder/context_tree.h
+++ b/av1/encoder/context_tree.h
@@ -60,10 +60,6 @@
 
   int rd_mode_is_ready;  // Flag to indicate whether rd pick mode decision has
                          // been made.
-
-  // motion vector cache for adaptive motion search control in partition
-  // search loop
-  MV pred_mv[REF_FRAMES];
 } PICK_MODE_CONTEXT;
 
 typedef struct PC_TREE {
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 27297ce..439e4b7 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -2687,15 +2687,6 @@
 }
 #endif  // !CONFIG_REALTIME_ONLY
 
-static INLINE void store_pred_mv(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx) {
-  memcpy(ctx->pred_mv, x->pred_mv, sizeof(x->pred_mv));
-}
-
-static INLINE void load_pred_mv(MACROBLOCK *x,
-                                const PICK_MODE_CONTEXT *const ctx) {
-  memcpy(x->pred_mv, ctx->pred_mv, sizeof(x->pred_mv));
-}
-
 #if !CONFIG_REALTIME_ONLY
 // Try searching for an encoding for the given subblock. Returns zero if the
 // rdcost is already too high (to tell the caller not to bother searching for
@@ -2705,14 +2696,12 @@
                            int mi_row, int mi_col, BLOCK_SIZE subsize,
                            RD_STATS best_rdcost, RD_STATS *sum_rdc,
                            PARTITION_TYPE partition,
-                           const PICK_MODE_CONTEXT *const prev_ctx,
                            PICK_MODE_CONTEXT *this_ctx) {
   MACROBLOCK *const x = &td->mb;
   const int orig_mult = x->rdmult;
   setup_block_rdmult(cpi, x, mi_row, mi_col, subsize, NO_AQ, NULL);
 
   av1_rd_cost_update(x->rdmult, &best_rdcost);
-  if (cpi->sf.mv_sf.adaptive_motion_search) load_pred_mv(x, prev_ctx);
 
   RD_STATS rdcost_remaining;
   av1_rd_stats_subtraction(x->rdmult, &best_rdcost, sum_rdc, &rdcost_remaining);
@@ -2744,13 +2733,15 @@
 
 // Tests an AB partition, and updates the encoder status, the pick mode
 // contexts, the best rdcost, and the best partition.
-static bool rd_test_partition3(
-    AV1_COMP *const cpi, ThreadData *td, TileDataEnc *tile_data,
-    TokenExtra **tp, PC_TREE *pc_tree, RD_STATS *best_rdc,
-    PICK_MODE_CONTEXT *ctxs[3], const PICK_MODE_CONTEXT *const ctx, int mi_row,
-    int mi_col, BLOCK_SIZE bsize, PARTITION_TYPE partition, int mi_row0,
-    int mi_col0, BLOCK_SIZE subsize0, int mi_row1, int mi_col1,
-    BLOCK_SIZE subsize1, int mi_row2, int mi_col2, BLOCK_SIZE subsize2) {
+static bool rd_test_partition3(AV1_COMP *const cpi, ThreadData *td,
+                               TileDataEnc *tile_data, TokenExtra **tp,
+                               PC_TREE *pc_tree, RD_STATS *best_rdc,
+                               PICK_MODE_CONTEXT *ctxs[3], int mi_row,
+                               int mi_col, BLOCK_SIZE bsize,
+                               PARTITION_TYPE partition, int mi_row0,
+                               int mi_col0, BLOCK_SIZE subsize0, int mi_row1,
+                               int mi_col1, BLOCK_SIZE subsize1, int mi_row2,
+                               int mi_col2, BLOCK_SIZE subsize2) {
   const MACROBLOCK *const x = &td->mb;
   const MACROBLOCKD *const xd = &x->e_mbd;
   const int pl = partition_plane_context(xd, mi_row, mi_col, bsize);
@@ -2759,15 +2750,15 @@
   sum_rdc.rate = x->mode_costs.partition_cost[pl][partition];
   sum_rdc.rdcost = RDCOST(x->rdmult, sum_rdc.rate, 0);
   if (!rd_try_subblock(cpi, td, tile_data, tp, 0, mi_row0, mi_col0, subsize0,
-                       *best_rdc, &sum_rdc, partition, ctx, ctxs[0]))
+                       *best_rdc, &sum_rdc, partition, ctxs[0]))
     return false;
 
   if (!rd_try_subblock(cpi, td, tile_data, tp, 0, mi_row1, mi_col1, subsize1,
-                       *best_rdc, &sum_rdc, partition, ctxs[0], ctxs[1]))
+                       *best_rdc, &sum_rdc, partition, ctxs[1]))
     return false;
 
   if (!rd_try_subblock(cpi, td, tile_data, tp, 1, mi_row2, mi_col2, subsize2,
-                       *best_rdc, &sum_rdc, partition, ctxs[1], ctxs[2]))
+                       *best_rdc, &sum_rdc, partition, ctxs[2]))
     return false;
 
   av1_rd_cost_update(x->rdmult, &sum_rdc);
@@ -3343,9 +3334,6 @@
     restore_context(x, &x_ctx, mi_row, mi_col, bsize, num_planes);
   }
 
-  // Store estimated motion vector.
-  if (cpi->sf.mv_sf.adaptive_motion_search) store_pred_mv(x, ctx_none);
-
   // PARTITION_SPLIT
   int64_t part_split_rd = INT64_MAX;
   BLOCK_SIZE subsize = get_partition_subsize(bsize, PARTITION_SPLIT);
@@ -3380,8 +3368,6 @@
           mi_col + x_idx >= mi_params->mi_cols)
         continue;
 
-      if (cpi->sf.mv_sf.adaptive_motion_search) load_pred_mv(x, ctx_none);
-
       pc_tree->split[idx]->index = idx;
       int64_t *p_split_rd = &part_search_state.split_rd[idx];
 
@@ -3503,7 +3489,6 @@
             av1_alloc_pmc(cm, subsize, &td->shared_coeff_buf);
       }
     }
-    if (cpi->sf.mv_sf.adaptive_motion_search) load_pred_mv(x, ctx_none);
     part_search_state.sum_rdc.rate =
         part_search_state.partition_cost[PARTITION_HORZ];
     part_search_state.sum_rdc.rdcost =
@@ -3545,8 +3530,6 @@
       update_state(cpi, td, ctx_h, mi_row, mi_col, subsize, 1);
       encode_superblock(cpi, tile_data, td, tp, DRY_RUN_NORMAL, subsize, NULL);
 
-      if (cpi->sf.mv_sf.adaptive_motion_search) load_pred_mv(x, ctx_h);
-
       av1_rd_stats_subtraction(x->rdmult, &best_rdc, &part_search_state.sum_rdc,
                                &best_remain_rdcost);
 
@@ -3610,8 +3593,6 @@
       }
     }
 
-    if (cpi->sf.mv_sf.adaptive_motion_search) load_pred_mv(x, ctx_none);
-
     part_search_state.sum_rdc.rate =
         part_search_state.partition_cost[PARTITION_VERT];
     part_search_state.sum_rdc.rdcost =
@@ -3651,8 +3632,6 @@
       update_state(cpi, td, pc_tree->vertical[0], mi_row, mi_col, subsize, 1);
       encode_superblock(cpi, tile_data, td, tp, DRY_RUN_NORMAL, subsize, NULL);
 
-      if (cpi->sf.mv_sf.adaptive_motion_search) load_pred_mv(x, ctx_none);
-
       av1_rd_stats_subtraction(x->rdmult, &best_rdc, &part_search_state.sum_rdc,
                                &best_remain_rdcost);
       pick_sb_modes(cpi, tile_data, x, mi_row, blk_params.mi_col_edge,
@@ -3781,7 +3760,7 @@
     // Test this partition and update the best partition.
     part_search_state.found_best_partition |= rd_test_partition3(
         cpi, td, tile_data, tp, pc_tree, &best_rdc, pc_tree->horizontala,
-        ctx_none, mi_row, mi_col, bsize, PARTITION_HORZ_A, mi_row, mi_col,
+        mi_row, mi_col, bsize, PARTITION_HORZ_A, mi_row, mi_col,
         blk_params.split_bsize2, mi_row, blk_params.mi_col_edge,
         blk_params.split_bsize2, blk_params.mi_row_edge, mi_col, subsize);
 #if CONFIG_COLLECT_PARTITION_STATS
@@ -3832,8 +3811,8 @@
     // Test this partition and update the best partition.
     part_search_state.found_best_partition |= rd_test_partition3(
         cpi, td, tile_data, tp, pc_tree, &best_rdc, pc_tree->horizontalb,
-        ctx_none, mi_row, mi_col, bsize, PARTITION_HORZ_B, mi_row, mi_col,
-        subsize, blk_params.mi_row_edge, mi_col, blk_params.split_bsize2,
+        mi_row, mi_col, bsize, PARTITION_HORZ_B, mi_row, mi_col, subsize,
+        blk_params.mi_row_edge, mi_col, blk_params.split_bsize2,
         blk_params.mi_row_edge, blk_params.mi_col_edge,
         blk_params.split_bsize2);
 
@@ -3885,8 +3864,8 @@
 #endif
     // Test this partition and update the best partition.
     part_search_state.found_best_partition |= rd_test_partition3(
-        cpi, td, tile_data, tp, pc_tree, &best_rdc, pc_tree->verticala,
-        ctx_none, mi_row, mi_col, bsize, PARTITION_VERT_A, mi_row, mi_col,
+        cpi, td, tile_data, tp, pc_tree, &best_rdc, pc_tree->verticala, mi_row,
+        mi_col, bsize, PARTITION_VERT_A, mi_row, mi_col,
         blk_params.split_bsize2, blk_params.mi_row_edge, mi_col,
         blk_params.split_bsize2, mi_row, blk_params.mi_col_edge, subsize);
 #if CONFIG_COLLECT_PARTITION_STATS
@@ -3937,11 +3916,10 @@
 #endif
     // Test this partition and update the best partition.
     part_search_state.found_best_partition |= rd_test_partition3(
-        cpi, td, tile_data, tp, pc_tree, &best_rdc, pc_tree->verticalb,
-        ctx_none, mi_row, mi_col, bsize, PARTITION_VERT_B, mi_row, mi_col,
-        subsize, mi_row, blk_params.mi_col_edge, blk_params.split_bsize2,
-        blk_params.mi_row_edge, blk_params.mi_col_edge,
-        blk_params.split_bsize2);
+        cpi, td, tile_data, tp, pc_tree, &best_rdc, pc_tree->verticalb, mi_row,
+        mi_col, bsize, PARTITION_VERT_B, mi_row, mi_col, subsize, mi_row,
+        blk_params.mi_col_edge, blk_params.split_bsize2, blk_params.mi_row_edge,
+        blk_params.mi_col_edge, blk_params.split_bsize2);
 #if CONFIG_COLLECT_PARTITION_STATS
     if (partition_timer_on) {
       aom_usec_timer_mark(&partition_timer);
@@ -4036,7 +4014,6 @@
        active_h_edge(cpi, mi_row, blk_params.mi_step))) {
     av1_init_rd_stats(&part_search_state.sum_rdc);
     const int quarter_step = mi_size_high[bsize] / 4;
-    PICK_MODE_CONTEXT *ctx_prev = ctx_none;
 
     subsize = get_partition_subsize(bsize, PARTITION_HORZ_4);
     part_search_state.sum_rdc.rate =
@@ -4067,12 +4044,10 @@
       if (!rd_try_subblock(cpi, td, tile_data, tp, (i == 3), this_mi_row,
                            mi_col, subsize, best_rdc,
                            &part_search_state.sum_rdc, PARTITION_HORZ_4,
-                           ctx_prev, ctx_this)) {
+                           ctx_this)) {
         av1_invalid_rd_stats(&part_search_state.sum_rdc);
         break;
       }
-
-      ctx_prev = ctx_this;
     }
 
     // Calculate the total cost and update the best partition.
@@ -4102,7 +4077,6 @@
        active_v_edge(cpi, mi_row, blk_params.mi_step))) {
     av1_init_rd_stats(&part_search_state.sum_rdc);
     const int quarter_step = mi_size_wide[bsize] / 4;
-    PICK_MODE_CONTEXT *ctx_prev = ctx_none;
 
     subsize = get_partition_subsize(bsize, PARTITION_VERT_4);
     part_search_state.sum_rdc.rate =
@@ -4131,12 +4105,10 @@
       if (!rd_try_subblock(cpi, td, tile_data, tp, (i == 3), mi_row,
                            this_mi_col, subsize, best_rdc,
                            &part_search_state.sum_rdc, PARTITION_VERT_4,
-                           ctx_prev, ctx_this)) {
+                           ctx_this)) {
         av1_invalid_rd_stats(&part_search_state.sum_rdc);
         break;
       }
-
-      ctx_prev = ctx_this;
     }
 
     // Calculate the total cost and update the best partition
@@ -5097,7 +5069,6 @@
   // Reset hash state for transform/mode rd hash information
   reset_hash_records(&x->txfm_search_info, cpi->sf.tx_sf.use_inter_txb_hash);
   av1_zero(x->picked_ref_frames_mask);
-  av1_zero(x->pred_mv);
   av1_invalid_rd_stats(rd_cost);
 }
 
diff --git a/av1/encoder/motion_search_facade.c b/av1/encoder/motion_search_facade.c
index 12009de..4f2c2f2 100644
--- a/av1/encoder/motion_search_facade.c
+++ b/av1/encoder/motion_search_facade.c
@@ -88,43 +88,6 @@
     step_param = mv_search_params->mv_step_param;
   }
 
-  if (cpi->sf.mv_sf.adaptive_motion_search && bsize < cm->seq_params.sb_size) {
-    int boffset =
-        2 * (mi_size_wide_log2[cm->seq_params.sb_size] -
-             AOMMIN(mi_size_high_log2[bsize], mi_size_wide_log2[bsize]));
-    step_param = AOMMAX(step_param, boffset);
-  }
-
-  if (cpi->sf.mv_sf.adaptive_motion_search) {
-    int bwl = mi_size_wide_log2[bsize];
-    int bhl = mi_size_high_log2[bsize];
-    int tlevel = x->pred_mv_sad[ref] >> (bwl + bhl + 4);
-
-    if (tlevel < 5) {
-      step_param += 2;
-      step_param = AOMMIN(step_param, MAX_MVSEARCH_STEPS - 1);
-    }
-
-    // prev_mv_sad is not setup for dynamically scaled frames.
-    if (cpi->oxcf.resize_mode != RESIZE_RANDOM) {
-      int i;
-      for (i = LAST_FRAME; i <= ALTREF_FRAME && cm->show_frame; ++i) {
-        if ((x->pred_mv_sad[ref] >> 3) > x->pred_mv_sad[i]) {
-          x->pred_mv[ref].row = 0;
-          x->pred_mv[ref].col = 0;
-          best_mv->as_int = INVALID_MV;
-
-          if (scaled_ref_frame) {
-            // Swap back the original buffers before returning.
-            for (int j = 0; j < num_planes; ++j)
-              xd->plane[j].pre[ref_idx] = backup_yv12[j];
-          }
-          return;
-        }
-      }
-    }
-  }
-
   const MV ref_mv = av1_get_ref_mv(x, ref_idx).as_mv;
   FULLPEL_MV start_mv;
   if (mbmi->motion_mode != SIMPLE_TRANSLATION)
@@ -352,10 +315,6 @@
   }
   *rate_mv = av1_mv_bit_cost(&best_mv->as_mv, &ref_mv, mv_costs->nmv_joint_cost,
                              mv_costs->mv_cost_stack, MV_COST_WEIGHT);
-
-  if (cpi->sf.mv_sf.adaptive_motion_search &&
-      mbmi->motion_mode == SIMPLE_TRANSLATION)
-    x->pred_mv[ref] = best_mv->as_mv;
 }
 
 void av1_joint_motion_search(const AV1_COMP *cpi, MACROBLOCK *x,
diff --git a/av1/encoder/rd.c b/av1/encoder/rd.c
index cac9fb8..61e8b25 100644
--- a/av1/encoder/rd.c
+++ b/av1/encoder/rd.c
@@ -1009,10 +1009,6 @@
   if (ref_mv.as_int != ref_mv1.as_int) {
     pred_mv[num_mv_refs++] = ref_mv1.as_mv;
   }
-  if (cpi->sf.mv_sf.adaptive_motion_search &&
-      block_size < x->sb_enc.max_partition_size) {
-    pred_mv[num_mv_refs++] = x->pred_mv[ref_frame];
-  }
 
   assert(num_mv_refs <= (int)(sizeof(pred_mv) / sizeof(pred_mv[0])));
 
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index cbda563..ef1e222 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -1440,9 +1440,6 @@
             tmp_rate_mv = av1_mv_bit_cost(
                 &mbmi->mv[0].as_mv, &ref_mv.as_mv, x->mv_costs.nmv_joint_cost,
                 x->mv_costs.mv_cost_stack, MV_COST_WEIGHT);
-            if (cpi->sf.mv_sf.adaptive_motion_search) {
-              x->pred_mv[mbmi->ref_frame[0]] = mbmi->mv[0].as_mv;
-            }
             tmp_rate2 = rate2_nocoeff - rate_mv0 + tmp_rate_mv;
           } else {
             // Restore the old MV and WM parameters.
diff --git a/av1/encoder/speed_features.c b/av1/encoder/speed_features.c
index c758565..4d1b066 100644
--- a/av1/encoder/speed_features.c
+++ b/av1/encoder/speed_features.c
@@ -973,7 +973,6 @@
 
 static AOM_INLINE void init_mv_sf(MV_SPEED_FEATURES *mv_sf) {
   mv_sf->full_pixel_search_level = 0;
-  mv_sf->adaptive_motion_search = 0;
   mv_sf->auto_mv_step_size = 0;
   mv_sf->exhaustive_searches_thresh = 0;
   mv_sf->obmc_full_pixel_search_level = 0;
diff --git a/av1/encoder/speed_features.h b/av1/encoder/speed_features.h
index ad470cf..53aeed2 100644
--- a/av1/encoder/speed_features.h
+++ b/av1/encoder/speed_features.h
@@ -454,11 +454,6 @@
   // encoding and decoding; otherwise, it uses bilinear interpolation.
   SUBPEL_SEARCH_TYPE use_accurate_subpel_search;
 
-  // TODO(jingning): combine the related motion search speed features
-  // This allows us to use motion search at other sizes as a starting
-  // point for this motion search and limits the search range around it.
-  int adaptive_motion_search;
-
   // Threshold for allowing exhaustive motion search.
   int exhaustive_searches_thresh;
 
diff --git a/av1/encoder/var_based_part.c b/av1/encoder/var_based_part.c
index 995ee5e..d2efb39 100644
--- a/av1/encoder/var_based_part.c
+++ b/av1/encoder/var_based_part.c
@@ -776,7 +776,6 @@
     *ref_frame_partition = GOLDEN_FRAME;
     x->nonrd_prune_ref_frame_search = 0;
   } else {
-    x->pred_mv[LAST_FRAME] = mi->mv[0].as_mv;
     *ref_frame_partition = LAST_FRAME;
     x->nonrd_prune_ref_frame_search =
         cpi->sf.rt_sf.nonrd_prune_ref_frame_search;