Simplify search_method selection

This CL simplify how search_method selection is done in temporal filter.

Performance on hdres:
 SPDSET | AVG_PSNR | OVR_PSNR |   SSIM  |  SPD
    6   |  -0.071% |  -0.072% | -0.162% |  -0.5%
    5   |  -0.076% |  -0.078% | -0.096% |  -0.7%
    4   |  -0.014% |  -0.015% | -0.020% |  -0.3%

STATS_CHANGED

Change-Id: I15ad944d7155a82f900ddfdc53d75e37b95acf81
diff --git a/av1/encoder/firstpass.c b/av1/encoder/firstpass.c
index dd9ae88..a5e91f3 100644
--- a/av1/encoder/firstpass.c
+++ b/av1/encoder/firstpass.c
@@ -234,8 +234,8 @@
   FULLPEL_MOTION_SEARCH_PARAMS ms_params;
   av1_make_default_fullpel_ms_params(&ms_params, cpi, x, bsize, ref_mv,
                                      first_pass_search_sites,
-                                     fine_search_interval, NSTEP);
-  ms_params.search_method = NSTEP;
+                                     fine_search_interval);
+  av1_set_mv_search_method(&ms_params, first_pass_search_sites, NSTEP);
 
   FULLPEL_MV this_best_mv;
   tmp_err = av1_full_pixel_search(start_mv, &ms_params, step_param, NULL,
diff --git a/av1/encoder/mcomp.c b/av1/encoder/mcomp.c
index 8dff9e7..4225b00 100644
--- a/av1/encoder/mcomp.c
+++ b/av1/encoder/mcomp.c
@@ -55,19 +55,6 @@
   ms_buffers->obmc_mask = x->obmc_buffer.mask;
 }
 
-// Array to inform which all search methods are having
-// same candidates and different in number of search steps.
-const SEARCH_METHODS search_method_lookup[NUM_SEARCH_METHODS] = {
-  DIAMOND,  // DIAMOND
-  NSTEP,    // NSTEP
-  HEX,      // HEX
-  BIGDIA,   // BIGDIA
-  SQUARE,   // SQUARE
-  HEX,      // FAST_HEX
-  BIGDIA,   // FAST_DIAMOND
-  BIGDIA    // FAST_BIGDIA
-};
-
 static AOM_INLINE SEARCH_METHODS
 get_faster_search_method(SEARCH_METHODS search_method) {
   // Note on search method's accuracy:
@@ -93,7 +80,7 @@
     FULLPEL_MOTION_SEARCH_PARAMS *ms_params, const struct AV1_COMP *cpi,
     const MACROBLOCK *x, BLOCK_SIZE bsize, const MV *ref_mv,
     const search_site_config search_sites[NUM_SEARCH_METHODS],
-    int fine_search_interval, SEARCH_METHODS search_method) {
+    int fine_search_interval) {
   const MV_SPEED_FEATURES *mv_sf = &cpi->sf.mv_sf;
 
   // High level params
@@ -102,16 +89,15 @@
 
   init_ms_buffers(&ms_params->ms_buffers, x);
 
-  ms_params->search_method = search_method;
+  SEARCH_METHODS search_method = mv_sf->search_method;
   if (mv_sf->use_bsize_dependent_search_method) {
     const int min_dim = AOMMIN(block_size_wide[bsize], block_size_high[bsize]);
     if (min_dim >= 32) {
-      ms_params->search_method =
-          get_faster_search_method(ms_params->search_method);
+      search_method = get_faster_search_method(search_method);
     }
   }
-  ms_params->search_sites =
-      &search_sites[search_method_lookup[ms_params->search_method]];
+
+  av1_set_mv_search_method(ms_params, search_sites, search_method);
 
   ms_params->mesh_patterns[0] = mv_sf->mesh_patterns;
   ms_params->mesh_patterns[1] = mv_sf->intrabc_mesh_patterns;
diff --git a/av1/encoder/mcomp.h b/av1/encoder/mcomp.h
index 366650e..05ae381 100644
--- a/av1/encoder/mcomp.h
+++ b/av1/encoder/mcomp.h
@@ -166,6 +166,9 @@
 
   MSBuffers ms_buffers;
 
+  // WARNING: search_method should be regarded as a private variable and should
+  // not be modified directly so it is in sync with search_sites. To modify it,
+  // use av1_set_mv_search_method.
   SEARCH_METHODS search_method;
   const search_site_config *search_sites;
   FullMvLimits mv_limits;
@@ -194,7 +197,7 @@
     FULLPEL_MOTION_SEARCH_PARAMS *ms_params, const struct AV1_COMP *cpi,
     const MACROBLOCK *x, BLOCK_SIZE bsize, const MV *ref_mv,
     const search_site_config search_sites[NUM_SEARCH_METHODS],
-    int fine_search_interval, SEARCH_METHODS search_method);
+    int fine_search_interval);
 
 // Sets up configs for fullpixel diamond search method.
 void av1_init_dsmotion_compensation(search_site_config *cfg, int stride);
@@ -210,6 +213,29 @@
 // Sets up configs for SQUARE motion search method.
 void av1_init_motion_compensation_square(search_site_config *cfg, int stride);
 
+// Mv beyond the range do not produce new/different prediction block.
+static INLINE void av1_set_mv_search_method(
+    FULLPEL_MOTION_SEARCH_PARAMS *ms_params,
+    const search_site_config search_sites[NUM_SEARCH_METHODS],
+    SEARCH_METHODS search_method) {
+  // Array to inform which all search methods are having
+  // same candidates and different in number of search steps.
+  static const SEARCH_METHODS search_method_lookup[NUM_SEARCH_METHODS] = {
+    DIAMOND,  // DIAMOND
+    NSTEP,    // NSTEP
+    HEX,      // HEX
+    BIGDIA,   // BIGDIA
+    SQUARE,   // SQUARE
+    HEX,      // FAST_HEX
+    BIGDIA,   // FAST_DIAMOND
+    BIGDIA    // FAST_BIGDIA
+  };
+
+  ms_params->search_method = search_method;
+  ms_params->search_sites =
+      &search_sites[search_method_lookup[ms_params->search_method]];
+}
+
 // Set up limit values for MV components.
 // Mv beyond the range do not produce new/different prediction block.
 static INLINE void av1_set_mv_row_limits(
diff --git a/av1/encoder/motion_search_facade.c b/av1/encoder/motion_search_facade.c
index 4436543..9dbca7e 100644
--- a/av1/encoder/motion_search_facade.c
+++ b/av1/encoder/motion_search_facade.c
@@ -186,8 +186,7 @@
       mv_search_params->search_site_cfg[SS_CFG_SRC];
   FULLPEL_MOTION_SEARCH_PARAMS full_ms_params;
   av1_make_default_fullpel_ms_params(&full_ms_params, cpi, x, bsize, &ref_mv,
-                                     src_search_sites, fine_search_interval,
-                                     cpi->sf.mv_sf.search_method);
+                                     src_search_sites, fine_search_interval);
 
   switch (mbmi->motion_mode) {
     case SIMPLE_TRANSLATION: {
@@ -421,9 +420,9 @@
 
     // Make motion search params
     FULLPEL_MOTION_SEARCH_PARAMS full_ms_params;
-    av1_make_default_fullpel_ms_params(
-        &full_ms_params, cpi, x, bsize, &ref_mv[id].as_mv, NULL,
-        /*fine_search_interval=*/0, cpi->sf.mv_sf.search_method);
+    av1_make_default_fullpel_ms_params(&full_ms_params, cpi, x, bsize,
+                                       &ref_mv[id].as_mv, NULL,
+                                       /*fine_search_interval=*/0);
 
     av1_set_ms_compound_refs(&full_ms_params.ms_buffers, second_pred, mask,
                              mask_stride, id);
@@ -547,9 +546,9 @@
 
   // Make motion search params
   FULLPEL_MOTION_SEARCH_PARAMS full_ms_params;
-  av1_make_default_fullpel_ms_params(
-      &full_ms_params, cpi, x, bsize, &ref_mv.as_mv, NULL,
-      /*fine_search_interval=*/0, cpi->sf.mv_sf.search_method);
+  av1_make_default_fullpel_ms_params(&full_ms_params, cpi, x, bsize,
+                                     &ref_mv.as_mv, NULL,
+                                     /*fine_search_interval=*/0);
 
   av1_set_ms_compound_refs(&full_ms_params.ms_buffers, second_pred, mask,
                            mask_stride, ref_idx);
@@ -767,8 +766,7 @@
   const int fine_search_interval = use_fine_search_interval(cpi);
   FULLPEL_MOTION_SEARCH_PARAMS full_ms_params;
   av1_make_default_fullpel_ms_params(&full_ms_params, cpi, x, bsize, &ref_mv,
-                                     src_search_sites, fine_search_interval,
-                                     cpi->sf.mv_sf.search_method);
+                                     src_search_sites, fine_search_interval);
 
   var = av1_full_pixel_search(start_mv, &full_ms_params, step_param,
                               cond_cost_list(cpi, cost_list),
diff --git a/av1/encoder/nonrd_pickmode.c b/av1/encoder/nonrd_pickmode.c
index f541094..678658c 100644
--- a/av1/encoder/nonrd_pickmode.c
+++ b/av1/encoder/nonrd_pickmode.c
@@ -179,9 +179,9 @@
   const search_site_config *src_search_sites =
       cpi->mv_search_params.search_site_cfg[SS_CFG_SRC];
   FULLPEL_MOTION_SEARCH_PARAMS full_ms_params;
-  av1_make_default_fullpel_ms_params(
-      &full_ms_params, cpi, x, bsize, &center_mv, src_search_sites,
-      /*fine_search_interval=*/0, cpi->sf.mv_sf.search_method);
+  av1_make_default_fullpel_ms_params(&full_ms_params, cpi, x, bsize, &center_mv,
+                                     src_search_sites,
+                                     /*fine_search_interval=*/0);
 
   av1_full_pixel_search(start_mv, &full_ms_params, step_param,
                         cond_cost_list(cpi, cost_list), &tmp_mv->as_fullmv,
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index ac1b346..1cae85d 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -2961,9 +2961,9 @@
   FULLPEL_MOTION_SEARCH_PARAMS fullms_params;
   const search_site_config *lookahead_search_sites =
       cpi->mv_search_params.search_site_cfg[SS_CFG_LOOKAHEAD];
-  av1_make_default_fullpel_ms_params(
-      &fullms_params, cpi, x, bsize, &dv_ref.as_mv, lookahead_search_sites,
-      /*fine_search_interval=*/0, cpi->sf.mv_sf.search_method);
+  av1_make_default_fullpel_ms_params(&fullms_params, cpi, x, bsize,
+                                     &dv_ref.as_mv, lookahead_search_sites,
+                                     /*fine_search_interval=*/0);
   fullms_params.is_intra_mode = 1;
 
   for (enum IntrabcMotionDirection dir = IBC_MOTION_ABOVE;
diff --git a/av1/encoder/temporal_filter.c b/av1/encoder/temporal_filter.c
index 3252d08..112cd32 100644
--- a/av1/encoder/temporal_filter.c
+++ b/av1/encoder/temporal_filter.c
@@ -104,19 +104,7 @@
   // Parameters used for motion search.
   FULLPEL_MOTION_SEARCH_PARAMS full_ms_params;
   SUBPEL_MOTION_SEARCH_PARAMS ms_params;
-  SEARCH_METHODS search_method = NSTEP;
-  // The initialization of search method with mv_sf.search_method
-  // happens only for some cases to prevent bit mismatch with ref version.
-  // ToDo(anyone): As per previous implementation search method has been changed
-  // without taking care of search site config. Now as the initialization of
-  // search site config for all search methods happens at frame level,
-  // we can try to use that when changing the search method.
-  if (cpi->oxcf.mode == GOOD &&
-      (!cpi->sf.mv_sf.use_bsize_dependent_search_method ||
-       (cpi->sf.mv_sf.use_bsize_dependent_search_method &&
-        block_size < BLOCK_32X32))) {
-    search_method = cpi->sf.mv_sf.search_method;
-  }
+  const SEARCH_METHODS search_method = NSTEP;
   const search_site_config *search_site_cfg =
       cpi->mv_search_params.search_site_cfg[SS_CFG_LOOKAHEAD];
   const int step_param = av1_init_search_range(
@@ -150,7 +138,8 @@
 
   av1_make_default_fullpel_ms_params(&full_ms_params, cpi, mb, block_size,
                                      &baseline_mv, search_site_cfg,
-                                     /*fine_search_interval=*/0, search_method);
+                                     /*fine_search_interval=*/0);
+  av1_set_mv_search_method(&full_ms_params, search_site_cfg, search_method);
   full_ms_params.run_mesh_search = 1;
   full_ms_params.mv_cost_params.mv_cost_type = mv_cost_type;
 
@@ -193,29 +182,17 @@
     start_mv = get_fullmv_from_mv(ref_mv);
 
     int subblock_idx = 0;
-    search_method = NSTEP;
     for (int i = 0; i < mb_height; i += subblock_height) {
       for (int j = 0; j < mb_width; j += subblock_width) {
         const int offset = i * y_stride + j;
         mb->plane[0].src.buf = frame_to_filter->y_buffer + y_offset + offset;
         mbd->plane[0].pre[0].buf = ref_frame->y_buffer + y_offset + offset;
-        // The initialization of search method with mv_sf.search_method
-        // happens only for some cases to prevent bit mismatch with ref version.
-        // ToDo(anyone): As per previous implementation search method has been
-        // changed without taking care of search site config. Now as the
-        // initialization of search site config for all search methods happens
-        // at frame level, we can try to use that when changing the search
-        // method.
-        if (cpi->oxcf.mode == GOOD &&
-            (!cpi->sf.mv_sf.use_bsize_dependent_search_method ||
-             (cpi->sf.mv_sf.use_bsize_dependent_search_method &&
-              subblock_size < BLOCK_32X32))) {
-          search_method = cpi->sf.mv_sf.search_method;
-        }
-        av1_make_default_fullpel_ms_params(
-            &full_ms_params, cpi, mb, subblock_size, &baseline_mv,
-            search_site_cfg,
-            /*fine_search_interval=*/0, search_method);
+        av1_make_default_fullpel_ms_params(&full_ms_params, cpi, mb,
+                                           subblock_size, &baseline_mv,
+                                           search_site_cfg,
+                                           /*fine_search_interval=*/0);
+        av1_set_mv_search_method(&full_ms_params, search_site_cfg,
+                                 search_method);
         full_ms_params.run_mesh_search = 1;
         full_ms_params.mv_cost_params.mv_cost_type = mv_cost_type;
 
diff --git a/av1/encoder/tpl_model.c b/av1/encoder/tpl_model.c
index 443794e..d1cfb45 100644
--- a/av1/encoder/tpl_model.c
+++ b/av1/encoder/tpl_model.c
@@ -168,9 +168,11 @@
   assert(search_site_cfg->stride == stride_ref);
 
   FULLPEL_MOTION_SEARCH_PARAMS full_ms_params;
-  av1_make_default_fullpel_ms_params(
-      &full_ms_params, cpi, x, bsize, &center_mv, search_site_cfg,
-      /*fine_search_interval=*/0, tpl_sf->search_method);
+  av1_make_default_fullpel_ms_params(&full_ms_params, cpi, x, bsize, &center_mv,
+                                     search_site_cfg,
+                                     /*fine_search_interval=*/0);
+  av1_set_mv_search_method(&full_ms_params, search_site_cfg,
+                           tpl_sf->search_method);
 
   av1_full_pixel_search(start_mv, &full_ms_params, step_param,
                         cond_cost_list(cpi, cost_list), &best_mv->as_fullmv,