Store interp_filter_stats into local variables

interp_filter_stats is used in interp filter search, which can be stored
in local variables. This change moved it out of macroblock struct.

Change-Id: I691df514fffe86bf581ebcecb84742dc47b00f33
diff --git a/av1/encoder/block.h b/av1/encoder/block.h
index f86fcc6..461bdec 100644
--- a/av1/encoder/block.h
+++ b/av1/encoder/block.h
@@ -182,16 +182,6 @@
 // 4: NEAREST, NEW, NEAR, GLOBAL
 #define SINGLE_REF_MODES ((REF_FRAMES - 1) * 4)
 
-#define MAX_INTERP_FILTER_STATS 64
-typedef struct {
-  int_interpfilters filters;
-  int_mv mv[2];
-  int8_t ref_frames[2];
-  COMPOUND_TYPE comp_type;
-  int64_t rd;
-  unsigned int pred_sse;
-} INTERPOLATION_FILTER_STATS;
-
 #define MAX_COMP_RD_STATS 64
 typedef struct {
   int32_t rate[COMPOUND_TYPES];
@@ -226,10 +216,6 @@
   // to select transform kernel.
   int rd_model;
 
-  // [comp_idx][saved stat_idx]
-  INTERPOLATION_FILTER_STATS interp_filter_stats[2][MAX_INTERP_FILTER_STATS];
-  int interp_filter_stats_idx[2];
-
   // prune_comp_search_by_single_result (3:MAX_REF_MV_SEARCH)
   SimpleRDState simple_rd_state[SINGLE_REF_MODES][3];
 
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index f2f76a0..dec84c5 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -8275,6 +8275,16 @@
   return rd;
 }
 
+#define MAX_INTERP_FILTER_STATS 64
+typedef struct {
+  int_interpfilters filters;
+  int_mv mv[2];
+  int8_t ref_frames[2];
+  COMPOUND_TYPE comp_type;
+  int64_t rd;
+  unsigned int pred_sse;
+} INTERPOLATION_FILTER_STATS;
+
 typedef struct {
   // OBMC secondary prediction buffers and respective strides
   uint8_t *above_pred_buf[MAX_MB_PLANE];
@@ -8296,6 +8306,9 @@
   INTERINTRA_MODE *inter_intra_mode;
   int single_ref_first_pass;
   SimpleRDState *simple_rd_state;
+  // [comp_idx][saved stat_idx]
+  INTERPOLATION_FILTER_STATS interp_filter_stats[2][MAX_INTERP_FILTER_STATS];
+  int interp_filter_stats_idx[2];
 } HandleInterModeArgs;
 
 /* If the current mode shares the same mv with other modes with higher cost,
@@ -8938,12 +8951,14 @@
   return 1;
 }
 
-static INLINE int find_interp_filter_in_stats(MACROBLOCK *x,
-                                              MB_MODE_INFO *const mbmi) {
+static INLINE int find_interp_filter_in_stats(
+    MB_MODE_INFO *const mbmi,
+    INTERPOLATION_FILTER_STATS (*interp_filter_stats)[MAX_INTERP_FILTER_STATS],
+    int *interp_filter_stats_idx) {
   const int comp_idx = mbmi->compound_idx;
-  const int offset = x->interp_filter_stats_idx[comp_idx];
+  const int offset = interp_filter_stats_idx[comp_idx];
   for (int j = 0; j < offset; ++j) {
-    const INTERPOLATION_FILTER_STATS *st = &x->interp_filter_stats[comp_idx][j];
+    const INTERPOLATION_FILTER_STATS *st = &interp_filter_stats[comp_idx][j];
     if (is_interp_filter_match(st, mbmi)) {
       mbmi->interp_filters = st->filters;
       return j;
@@ -8967,12 +8982,12 @@
   return 0;  // no match result found
 }
 
-static INLINE void save_interp_filter_search_stat(MACROBLOCK *x,
-                                                  MB_MODE_INFO *const mbmi,
-                                                  int64_t rd,
-                                                  unsigned int pred_sse) {
+static INLINE void save_interp_filter_search_stat(
+    MB_MODE_INFO *const mbmi, int64_t rd, unsigned int pred_sse,
+    INTERPOLATION_FILTER_STATS (*interp_filter_stats)[MAX_INTERP_FILTER_STATS],
+    int *interp_filter_stats_idx) {
   const int comp_idx = mbmi->compound_idx;
-  const int offset = x->interp_filter_stats_idx[comp_idx];
+  const int offset = interp_filter_stats_idx[comp_idx];
   if (offset < MAX_INTERP_FILTER_STATS) {
     INTERPOLATION_FILTER_STATS stat = { mbmi->interp_filters,
                                         { mbmi->mv[0], mbmi->mv[1] },
@@ -8981,8 +8996,8 @@
                                         mbmi->interinter_comp.type,
                                         rd,
                                         pred_sse };
-    x->interp_filter_stats[comp_idx][offset] = stat;
-    x->interp_filter_stats_idx[comp_idx]++;
+    interp_filter_stats[comp_idx][offset] = stat;
+    interp_filter_stats_idx[comp_idx]++;
   }
 }
 
@@ -9014,15 +9029,15 @@
   }
 }
 
-static INLINE int find_interp_filter_match(MACROBLOCK *const x,
-                                           const AV1_COMP *const cpi,
-                                           const InterpFilter assign_filter,
-                                           const int need_search) {
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MB_MODE_INFO *const mbmi = xd->mi[0];
+static INLINE int find_interp_filter_match(
+    MB_MODE_INFO *const mbmi, const AV1_COMP *const cpi,
+    const InterpFilter assign_filter, const int need_search,
+    INTERPOLATION_FILTER_STATS (*interp_filter_stats)[MAX_INTERP_FILTER_STATS],
+    int *interp_filter_stats_idx) {
   int match_found_idx = -1;
   if (cpi->sf.skip_repeat_interpolation_filter_search && need_search)
-    match_found_idx = find_interp_filter_in_stats(x, mbmi);
+    match_found_idx = find_interp_filter_in_stats(mbmi, interp_filter_stats,
+                                                  interp_filter_stats_idx);
 
   if (!need_search || match_found_idx == -1)
     set_default_interp_filters(mbmi, assign_filter);
@@ -9103,14 +9118,15 @@
   int match_found_idx = -1;
   const InterpFilter assign_filter = cm->interp_filter;
 
-  match_found_idx =
-      find_interp_filter_match(x, cpi, assign_filter, need_search);
+  match_found_idx = find_interp_filter_match(
+      mbmi, cpi, assign_filter, need_search, args->interp_filter_stats,
+      args->interp_filter_stats_idx);
 
   if (match_found_idx != -1) {
     const int comp_idx = mbmi->compound_idx;
-    *rd = x->interp_filter_stats[comp_idx][match_found_idx].rd;
+    *rd = args->interp_filter_stats[comp_idx][match_found_idx].rd;
     x->pred_sse[ref_frame] =
-        x->interp_filter_stats[comp_idx][match_found_idx].pred_sse;
+        args->interp_filter_stats[comp_idx][match_found_idx].pred_sse;
     return 0;
   }
 
@@ -9220,7 +9236,9 @@
   // save search results
   if (cpi->sf.skip_repeat_interpolation_filter_search) {
     assert(match_found_idx == -1);
-    save_interp_filter_search_stat(x, mbmi, *rd, x->pred_sse[ref_frame]);
+    save_interp_filter_search_stat(mbmi, *rd, x->pred_sse[ref_frame],
+                                   args->interp_filter_stats,
+                                   args->interp_filter_stats_idx);
   }
   return 0;
 }
@@ -10927,7 +10945,9 @@
       const int need_search = av1_is_interp_needed(xd);
       const InterpFilter assign_filter = cm->interp_filter;
       int is_luma_interp_done = 0;
-      find_interp_filter_match(x, cpi, assign_filter, need_search);
+      find_interp_filter_match(mbmi, cpi, assign_filter, need_search,
+                               args->interp_filter_stats,
+                               args->interp_filter_stats_idx);
 
       int64_t best_rd_compound;
       int64_t rd_thresh;
@@ -11931,10 +11951,6 @@
   // Set params for mode evaluation
   set_mode_eval_params(cpi, x, MODE_EVAL);
 
-  if (cpi->sf.skip_repeat_interpolation_filter_search) {
-    x->interp_filter_stats_idx[0] = 0;
-    x->interp_filter_stats_idx[1] = 0;
-  }
   x->comp_rd_stats_idx = 0;
 }
 
@@ -12927,7 +12943,9 @@
                                0,
                                interintra_modes,
                                1,
-                               NULL };
+                               NULL,
+                               { { { { 0 }, { { 0 } }, { 0 }, 0, 0, 0 } } },
+                               { 0 } };
   for (i = 0; i < REF_FRAMES; ++i) x->pred_sse[i] = INT_MAX;
 
   av1_invalid_rd_stats(rd_cost);
@@ -13539,10 +13557,6 @@
     x->use_default_inter_tx_type = 1;
   else
     x->use_default_inter_tx_type = 0;
-  if (cpi->sf.skip_repeat_interpolation_filter_search) {
-    x->interp_filter_stats_idx[0] = 0;
-    x->interp_filter_stats_idx[1] = 0;
-  }
 }
 
 // TODO(kyslov): now this is very similar to av1_rd_pick_inter_mode_sb except:
@@ -13588,7 +13602,9 @@
                                0,
                                NULL,
                                1,
-                               NULL };
+                               NULL,
+                               { { { { 0 }, { { 0 } }, { 0 }, 0, 0, 0 } } },
+                               { 0 } };
   for (i = 0; i < REF_FRAMES; ++i) x->pred_sse[i] = INT_MAX;
 
   av1_invalid_rd_stats(rd_cost);