Code cleanup: mainly rd_pick_partition and methods called from there.

- Const correctness
- Refactoring
- Make variables local when possible etc
- Remove -Wcast-qual to allow explicitly casting away const.

Cherry-picked from aomedia/master: c27fcccc
And then a number of more const correctness changes to make sure other
experiments build OK.

Change-Id: I77c18d99d21218fbdc9b186d7ed3792dc401a0a0
diff --git a/av1/common/mvref_common.c b/av1/common/mvref_common.c
index 4fdeefe..2344bc1 100644
--- a/av1/common/mvref_common.c
+++ b/av1/common/mvref_common.c
@@ -763,8 +763,8 @@
   *near_mv = mvlist[1];
 }
 
-void av1_append_sub8x8_mvs_for_idx(AV1_COMMON *cm, MACROBLOCKD *xd, int block,
-                                   int ref, int mi_row, int mi_col,
+void av1_append_sub8x8_mvs_for_idx(const AV1_COMMON *cm, MACROBLOCKD *xd,
+                                   int block, int ref, int mi_row, int mi_col,
 #if CONFIG_REF_MV
                                    CANDIDATE_MV *ref_mv_stack,
                                    uint8_t *ref_mv_count,