shithub: libvpx

Download patch

ref: 72fd127f8c03333e0b6d1cc5f1e579a7b8af38fb
parent: 85fd8bdb01674e5eebe91cef2a944e71b3738031
author: Dmitry Kovalev <dkovalev@google.com>
date: Wed Sep 18 09:11:38 EDT 2013

Removing redundant code from vp9_mcomp.c.

Replacing ((1 << MV_MAX_BITS) - 1) with MV_MAX, adding const
qualifiers, reusing computed values.

Change-Id: I7b46d47f6c644b079d9c3478116a9de465a9baec

--- a/vp9/encoder/vp9_mcomp.c
+++ b/vp9/encoder/vp9_mcomp.c
@@ -333,11 +333,9 @@
   unsigned int eighthiters = iters_per_step;
   int thismse;
 
-  uint8_t *y = xd->plane[0].pre[0].buf +
-               (bestmv->as_mv.row) * xd->plane[0].pre[0].stride +
-               bestmv->as_mv.col;
-
   const int y_stride = xd->plane[0].pre[0].stride;
+  const int offset = (bestmv->as_mv.row) * y_stride + bestmv->as_mv.col;
+  uint8_t *y = xd->plane[0].pre[0].buf + offset;
 
   int rr = ref_mv->as_mv.row;
   int rc = ref_mv->as_mv.col;
@@ -352,8 +350,6 @@
   int tr = br;
   int tc = bc;
 
-  const int offset = (bestmv->as_mv.row) * y_stride + bestmv->as_mv.col;
-
   // central mv
   bestmv->as_mv.row <<= 3;
   bestmv->as_mv.col <<= 3;
@@ -424,46 +420,33 @@
                                  int *distortion,
                                  unsigned int *sse1) {
   uint8_t *z = x->plane[0].src.buf;
-  int src_stride = x->plane[0].src.stride;
+  const int src_stride = x->plane[0].src.stride;
   MACROBLOCKD *xd = &x->e_mbd;
-  int rr, rc, br, bc, hstep;
-  int tr, tc;
   unsigned int besterr = INT_MAX;
   unsigned int sse;
   unsigned int whichdir;
   int thismse;
-  int maxc, minc, maxr, minr;
-  int y_stride;
-  int offset;
   unsigned int halfiters = iters_per_step;
   unsigned int quarteriters = iters_per_step;
   unsigned int eighthiters = iters_per_step;
 
-  uint8_t *y = xd->plane[0].pre[0].buf +
-               (bestmv->as_mv.row) * xd->plane[0].pre[0].stride +
-               bestmv->as_mv.col;
+  const int y_stride = xd->plane[0].pre[0].stride;
+  const int offset = bestmv->as_mv.row * y_stride + bestmv->as_mv.col;
+  uint8_t *y = xd->plane[0].pre[0].buf + offset;
 
-  y_stride = xd->plane[0].pre[0].stride;
+  int rr = ref_mv->as_mv.row;
+  int rc = ref_mv->as_mv.col;
+  int br = bestmv->as_mv.row << 3;
+  int bc = bestmv->as_mv.col << 3;
+  int hstep = 4;
+  const int minc = MAX(x->mv_col_min << 3, ref_mv->as_mv.col - MV_MAX);
+  const int maxc = MIN(x->mv_col_max << 3, ref_mv->as_mv.col + MV_MAX);
+  const int minr = MAX(x->mv_row_min << 3, ref_mv->as_mv.row - MV_MAX);
+  const int maxr = MIN(x->mv_row_max << 3, ref_mv->as_mv.row + MV_MAX);
 
-  rr = ref_mv->as_mv.row;
-  rc = ref_mv->as_mv.col;
-  br = bestmv->as_mv.row << 3;
-  bc = bestmv->as_mv.col << 3;
-  hstep = 4;
-  minc = MAX(x->mv_col_min << 3,
-             (ref_mv->as_mv.col) - ((1 << MV_MAX_BITS) - 1));
-  maxc = MIN(x->mv_col_max << 3,
-             (ref_mv->as_mv.col) + ((1 << MV_MAX_BITS) - 1));
-  minr = MAX(x->mv_row_min << 3,
-             (ref_mv->as_mv.row) - ((1 << MV_MAX_BITS) - 1));
-  maxr = MIN(x->mv_row_max << 3,
-             (ref_mv->as_mv.row) + ((1 << MV_MAX_BITS) - 1));
+  int tr = br;
+  int tc = bc;
 
-  tr = br;
-  tc = bc;
-
-  offset = (bestmv->as_mv.row) * y_stride + bestmv->as_mv.col;
-
   // central mv
   bestmv->as_mv.row <<= 3;
   bestmv->as_mv.col <<= 3;
@@ -543,11 +526,9 @@
   int thismse;
 
   DECLARE_ALIGNED_ARRAY(16, uint8_t, comp_pred, 64 * 64);
-  uint8_t *const y = xd->plane[0].pre[0].buf +
-               (bestmv->as_mv.row) * xd->plane[0].pre[0].stride +
-               bestmv->as_mv.col;
-
   const int y_stride = xd->plane[0].pre[0].stride;
+  const int offset = bestmv->as_mv.row * y_stride + bestmv->as_mv.col;
+  uint8_t *const y = xd->plane[0].pre[0].buf + offset;
 
   int rr = ref_mv->as_mv.row;
   int rc = ref_mv->as_mv.col;
@@ -562,8 +543,6 @@
   int tr = br;
   int tc = bc;
 
-  const int offset = (bestmv->as_mv.row) * y_stride + bestmv->as_mv.col;
-
   // central mv
   bestmv->as_mv.row <<= 3;
   bestmv->as_mv.col <<= 3;
@@ -638,47 +617,33 @@
                                       const uint8_t *second_pred,
                                       int w, int h) {
   uint8_t *z = x->plane[0].src.buf;
-  int src_stride = x->plane[0].src.stride;
+  const int src_stride = x->plane[0].src.stride;
   MACROBLOCKD *xd = &x->e_mbd;
-  int rr, rc, br, bc, hstep;
-  int tr, tc;
   unsigned int besterr = INT_MAX;
   unsigned int sse;
   unsigned int whichdir;
   int thismse;
-  int maxc, minc, maxr, minr;
-  int y_stride;
-  int offset;
   unsigned int halfiters = iters_per_step;
   unsigned int quarteriters = iters_per_step;
   unsigned int eighthiters = iters_per_step;
 
   DECLARE_ALIGNED_ARRAY(16, uint8_t, comp_pred, 64 * 64);
-  uint8_t *y = xd->plane[0].pre[0].buf +
-               (bestmv->as_mv.row) * xd->plane[0].pre[0].stride +
-               bestmv->as_mv.col;
+  const int y_stride = xd->plane[0].pre[0].stride;
+  const int offset = (bestmv->as_mv.row) * y_stride + bestmv->as_mv.col;
+  uint8_t *y = xd->plane[0].pre[0].buf + offset;
 
-  y_stride = xd->plane[0].pre[0].stride;
+  int rr = ref_mv->as_mv.row;
+  int rc = ref_mv->as_mv.col;
+  int br = bestmv->as_mv.row << 3;
+  int bc = bestmv->as_mv.col << 3;
+  int hstep = 4;
+  const int minc = MAX(x->mv_col_min << 3, ref_mv->as_mv.col - MV_MAX);
+  const int maxc = MIN(x->mv_col_max << 3, ref_mv->as_mv.col + MV_MAX);
+  const int minr = MAX(x->mv_row_min << 3, ref_mv->as_mv.row - MV_MAX);
+  const int maxr = MIN(x->mv_row_max << 3, ref_mv->as_mv.row + MV_MAX);
 
-  rr = ref_mv->as_mv.row;
-  rc = ref_mv->as_mv.col;
-  br = bestmv->as_mv.row << 3;
-  bc = bestmv->as_mv.col << 3;
-  hstep = 4;
-  minc = MAX(x->mv_col_min << 3, (ref_mv->as_mv.col) -
-             ((1 << MV_MAX_BITS) - 1));
-  maxc = MIN(x->mv_col_max << 3, (ref_mv->as_mv.col) +
-             ((1 << MV_MAX_BITS) - 1));
-  minr = MAX(x->mv_row_min << 3, (ref_mv->as_mv.row) -
-             ((1 << MV_MAX_BITS) - 1));
-  maxr = MIN(x->mv_row_max << 3, (ref_mv->as_mv.row) +
-             ((1 << MV_MAX_BITS) - 1));
-
-  tr = br;
-  tc = bc;
-
-
-  offset = (bestmv->as_mv.row) * y_stride + bestmv->as_mv.col;
+  int tr = br;
+  int tc = bc;
 
   // central mv
   bestmv->as_mv.row <<= 3;