Constrain hash table access within tile boundary

Limit the prediction residual hash table access within the same
tile. This resolves a data race issue across tiles in multi-threading
encoding that triggers instable encoding results.

BUG=aomedia:1088

Change-Id: Ia4a415a0750bd60ee8ac4e56aa1cd39ec99e19c7
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index fcba03c..5f51fc7 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -4884,8 +4884,10 @@
   TX_SIZE min_tx_size = sub_tx_size_map[max_txsize_rect_lookup[bsize]];
   const TxSetType tx_set_type = get_ext_tx_set_type(
       min_tx_size, bsize, is_inter, cm->reduced_tx_set_used);
-  int within_border = (mi_row + mi_size_high[bsize] <= cm->mi_rows) &&
-                      (mi_col + mi_size_wide[bsize] <= cm->mi_cols);
+  int within_border = mi_row >= xd->tile.mi_row_start &&
+                      (mi_row + mi_size_high[bsize] < xd->tile.mi_row_end) &&
+                      mi_col >= xd->tile.mi_col_start &&
+                      (mi_col + mi_size_wide[bsize] < xd->tile.mi_col_end);
 
   av1_invalid_rd_stats(rd_stats);