Clean up hash me code

As hash me is enabled for intra frames only,
the code related to non-intra frames is removed

Change-Id: I280f058fc830bd082c7299ec7998bf5236b8eb7f
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 1dd68a6..66ac461 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -5592,19 +5592,11 @@
     av1_hash_table_create(&cm->cur_frame->hash_table);
     av1_generate_block_2x2_hash_value(cpi->source, block_hash_values[0],
                                       is_block_same[0], &cpi->td.mb);
-    // Hash data generated for screen contents is used for the following:
-    // 1. intraBC ME
-    // 2. Calculation of cm->cur_frame_force_integer_mv
-    // As the calculation of cm->cur_frame_force_integer_mv is limited to 8x8
-    // block size, for non-intra frames, max_size for hash calculation can be
-    // limited to 8x8
+    // Hash data generated for screen contents is used for intraBC ME
     // TODO(any): Adjust max_size based on superblock size for intra frames
-    const int max_size =
-        frame_is_intra_only(cm) ? 128 : FORCE_INT_MV_DECISION_BLOCK_SIZE;
-    const int min_size = 4;
     const int min_alloc_size = block_size_wide[cm->mi_alloc_bsize];
     int src_idx = 0;
-    for (int size = min_size; size <= max_size; size *= 2, src_idx = !src_idx) {
+    for (int size = 4; size <= 128; size *= 2, src_idx = !src_idx) {
       const int dst_idx = !src_idx;
       av1_generate_block_hash_value(
           cpi->source, size, block_hash_values[src_idx],
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index c47a6c2..8012dd6 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -5957,8 +5957,7 @@
 #endif  // DUMP_RECON_FRAMES
 
 static int is_integer_mv(AV1_COMP *cpi, const YV12_BUFFER_CONFIG *cur_picture,
-                         const YV12_BUFFER_CONFIG *last_picture,
-                         hash_table *last_hash_table) {
+                         const YV12_BUFFER_CONFIG *last_picture) {
   aom_clear_system_state();
   // check use hash ME
   int k;
@@ -5970,7 +5969,6 @@
   int T = 0;  // total block
   int C = 0;  // match with collocated block
   int S = 0;  // smooth region but not match with collocated block
-  int M = 0;  // match with other block
 
   const int pic_width = cur_picture->y_width;
   const int pic_height = cur_picture->y_height;
@@ -6024,34 +6022,19 @@
         S++;
         continue;
       }
-      if (av1_use_hash_me(cpi)) {
-        uint32_t hash_value_1;
-        uint32_t hash_value_2;
-        av1_get_block_hash_value(
-            cur_picture->y_buffer + y_pos * stride_cur + x_pos, stride_cur,
-            block_size, &hash_value_1, &hash_value_2,
-            (cur_picture->flags & YV12_FLAG_HIGHBITDEPTH), &cpi->td.mb);
-        // Hashing does not work for highbitdepth currently.
-        // TODO(Roger): Make it work for highbitdepth.
-        if (av1_has_exact_match(last_hash_table, hash_value_1, hash_value_2)) {
-          M++;
-        }
-      }
     }
   }
 
   assert(T > 0);
-  double csm_rate = ((double)(C + S + M)) / ((double)(T));
-  double m_rate = ((double)(M)) / ((double)(T));
+  double cs_rate = ((double)(C + S)) / ((double)(T));
 
-  cpi->csm_rate_array[cpi->rate_index] = csm_rate;
-  cpi->m_rate_array[cpi->rate_index] = m_rate;
+  cpi->cs_rate_array[cpi->rate_index] = cs_rate;
 
   cpi->rate_index = (cpi->rate_index + 1) % max_history_size;
   cpi->rate_size++;
   cpi->rate_size = AOMMIN(cpi->rate_size, max_history_size);
 
-  if (csm_rate < threshold_current) {
+  if (cs_rate < threshold_current) {
     return 0;
   }
 
@@ -6059,29 +6042,22 @@
     return 1;
   }
 
-  double csm_average = 0.0;
-  double m_average = 0.0;
+  double cs_average = 0.0;
 
   for (k = 0; k < cpi->rate_size; k++) {
-    csm_average += cpi->csm_rate_array[k];
-    m_average += cpi->m_rate_array[k];
+    cs_average += cpi->cs_rate_array[k];
   }
-  csm_average /= cpi->rate_size;
-  m_average /= cpi->rate_size;
+  cs_average /= cpi->rate_size;
 
-  if (csm_average < threshold_average) {
+  if (cs_average < threshold_average) {
     return 0;
   }
 
-  if (M > (T - C - S) / 3) {
+  if ((T - C - S) < 0) {
     return 1;
   }
 
-  if (csm_rate > 0.99 && m_rate > 0.01) {
-    return 1;
-  }
-
-  if (csm_average + m_average > 1.01) {
+  if (cs_average > 1.01) {
     return 1;
   }
 
@@ -6261,8 +6237,7 @@
       // Adaptive mode: see what previous frame encoded did
       if (cpi->unscaled_last_source != NULL) {
         cm->cur_frame_force_integer_mv =
-            is_integer_mv(cpi, cpi->source, cpi->unscaled_last_source,
-                          cpi->previous_hash_table);
+            is_integer_mv(cpi, cpi->source, cpi->unscaled_last_source);
       } else {
         cpi->common.cur_frame_force_integer_mv = 0;
       }
@@ -6279,11 +6254,6 @@
          "Hash-me is leaking memory!");
 #endif
 
-  if (!is_stat_generation_stage(cpi) && cpi->need_to_clear_prev_hash_table) {
-    av1_hash_table_clear_all(cpi->previous_hash_table);
-    cpi->need_to_clear_prev_hash_table = 0;
-  }
-
   // Set default state for segment based loop filter update flags.
   cm->lf.mode_ref_delta_update = 0;
 
@@ -6481,14 +6451,6 @@
 
   av1_rc_postencode_update(cpi, *size);
 
-  // Store encoded frame's hash table for in_integer_mv() next time.
-  // Beware! If we don't update previous_hash_table here we will leak the
-  // items stored in cur_frame's hash_table!
-  if (!is_stat_generation_stage(cpi) && av1_use_hash_me(cpi)) {
-    cpi->previous_hash_table = &cm->cur_frame->hash_table;
-    cpi->need_to_clear_prev_hash_table = 1;
-  }
-
   // Clear the one shot update flags for segmentation map and mode/ref loop
   // filter deltas.
   cm->seg.update_map = 0;
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index 6248e86..ff45616 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -808,12 +808,9 @@
   // For a still frame, this flag is set to 1 to skip partition search.
   int partition_search_skippable_frame;
 
-  double csm_rate_array[32];
-  double m_rate_array[32];
+  double cs_rate_array[32];
   int rate_size;
   int rate_index;
-  hash_table *previous_hash_table;
-  int need_to_clear_prev_hash_table;
   int previous_index;
 
   unsigned int row_mt;
@@ -1323,7 +1320,7 @@
 // TODO(huisu@google.com, youzhou@microsoft.com): enable hash-me for HBD.
 static INLINE int av1_use_hash_me(const AV1_COMP *const cpi) {
   return (cpi->common.allow_screen_content_tools &&
-          !cpi->sf.mv_sf.disable_hash_me);
+          frame_is_intra_only(&cpi->common));
 }
 
 static INLINE hash_table *av1_get_ref_frame_hash_map(
diff --git a/av1/encoder/speed_features.c b/av1/encoder/speed_features.c
index 960071f..b1707fa 100644
--- a/av1/encoder/speed_features.c
+++ b/av1/encoder/speed_features.c
@@ -293,9 +293,6 @@
   sf->part_sf.prune_ext_partition_types_search_level = 1;
   sf->part_sf.simple_motion_search_prune_rect = 1;
 
-  // TODO(any): Clean-up code related to hash_me in inter frames
-  sf->mv_sf.disable_hash_me = frame_is_intra_only(cm) ? 0 : 1;
-
   sf->inter_sf.disable_wedge_search_edge_thresh = 0;
   sf->inter_sf.disable_wedge_search_var_thresh = 0;
   // TODO(debargha): Test, tweak and turn on either 1 or 2
@@ -953,7 +950,6 @@
   mv_sf->auto_mv_step_size = 0;
   mv_sf->adaptive_motion_search = 0;
   mv_sf->use_accurate_subpel_search = USE_8_TAPS;
-  mv_sf->disable_hash_me = 0;
   mv_sf->reduce_search_range = 0;
   mv_sf->prune_mesh_search = 0;
   mv_sf->exhaustive_searches_thresh = 0;
diff --git a/av1/encoder/speed_features.h b/av1/encoder/speed_features.h
index cc8e8e6..0f7b89b 100644
--- a/av1/encoder/speed_features.h
+++ b/av1/encoder/speed_features.h
@@ -474,10 +474,6 @@
   // Pattern to be used for exhaustive mesh searches of intraBC ME.
   MESH_PATTERN intrabc_mesh_patterns[MAX_MESH_STEP];
 
-  // Use to control hash generation and use of the same
-  // Applicable only for screen contents
-  int disable_hash_me;
-
   // Reduce single motion search range based on MV result of prior ref_mv_idx.
   int reduce_search_range;