Add high-precision sub-pixel search as a speed feature

Using the up-sampled reference frames in sub-pixel motion search is
enabled as a speed feature for good-quality mode speed 0 and speed 1.

Change-Id: Ieb454bf8c646ddb99e87bd64c8e74dbd78d84a50
diff --git a/vp10/encoder/rdopt.c b/vp10/encoder/rdopt.c
index bb62e32..665ba7d 100644
--- a/vp10/encoder/rdopt.c
+++ b/vp10/encoder/rdopt.c
@@ -4664,52 +4664,52 @@
     if (bestsme < INT_MAX) {
       int dis; /* TODO: use dis in distortion calculation later. */
       unsigned int sse;
-#if CONFIG_AFFINE_MOTION
-      // Use up-sampled reference frames.
-      struct macroblockd_plane *const pd = &xd->plane[0];
-      struct buf_2d backup_pred = pd->pre[0];
-      const YV12_BUFFER_CONFIG *upsampled_ref =
-          get_upsampled_ref(cpi, refs[id]);
+      if (cpi->sf.use_upsampled_references) {
+        // Use up-sampled reference frames.
+        struct macroblockd_plane *const pd = &xd->plane[0];
+        struct buf_2d backup_pred = pd->pre[0];
+        const YV12_BUFFER_CONFIG *upsampled_ref =
+            get_upsampled_ref(cpi, refs[id]);
 
-      // Set pred for Y plane
-      setup_pred_plane(&pd->pre[0], upsampled_ref->y_buffer,
-                       upsampled_ref->y_stride, (mi_row << 3), (mi_col << 3),
-                       NULL, pd->subsampling_x, pd->subsampling_y);
+        // Set pred for Y plane
+        setup_pred_plane(&pd->pre[0], upsampled_ref->y_buffer,
+                         upsampled_ref->y_stride, (mi_row << 3), (mi_col << 3),
+                         NULL, pd->subsampling_x, pd->subsampling_y);
 
-      // If bsize < BLOCK_8X8, adjust pred pointer for this block
-      if (bsize < BLOCK_8X8)
-        pd->pre[0].buf =
-            &pd->pre[0].buf[(vp10_raster_block_offset(BLOCK_8X8, block,
-            pd->pre[0].stride)) << 3];
+        // If bsize < BLOCK_8X8, adjust pred pointer for this block
+        if (bsize < BLOCK_8X8)
+          pd->pre[0].buf =
+              &pd->pre[0].buf[(vp10_raster_block_offset(BLOCK_8X8, block,
+              pd->pre[0].stride)) << 3];
 
-      bestsme = cpi->find_fractional_mv_step(
-          x, &tmp_mv,
-          &ref_mv[id].as_mv,
-          cpi->common.allow_high_precision_mv,
-          x->errorperbit,
-          &cpi->fn_ptr[bsize],
-          0, cpi->sf.mv.subpel_iters_per_step,
-          NULL,
-          x->nmvjointcost, x->mvcost,
-          &dis, &sse, second_pred,
-          pw, ph, 1);
+        bestsme = cpi->find_fractional_mv_step(
+            x, &tmp_mv,
+            &ref_mv[id].as_mv,
+            cpi->common.allow_high_precision_mv,
+            x->errorperbit,
+            &cpi->fn_ptr[bsize],
+            0, cpi->sf.mv.subpel_iters_per_step,
+            NULL,
+            x->nmvjointcost, x->mvcost,
+            &dis, &sse, second_pred,
+            pw, ph, 1);
 
-      // Restore the reference frames.
-      pd->pre[0] = backup_pred;
-#else
-      (void) block;
-      bestsme = cpi->find_fractional_mv_step(
-          x, &tmp_mv,
-          &ref_mv[id].as_mv,
-          cpi->common.allow_high_precision_mv,
-          x->errorperbit,
-          &cpi->fn_ptr[bsize],
-          0, cpi->sf.mv.subpel_iters_per_step,
-          NULL,
-          x->nmvjointcost, x->mvcost,
-          &dis, &sse, second_pred,
-          pw, ph);
-#endif
+        // Restore the reference frames.
+        pd->pre[0] = backup_pred;
+      } else {
+        (void) block;
+        bestsme = cpi->find_fractional_mv_step(
+            x, &tmp_mv,
+            &ref_mv[id].as_mv,
+            cpi->common.allow_high_precision_mv,
+            x->errorperbit,
+            &cpi->fn_ptr[bsize],
+            0, cpi->sf.mv.subpel_iters_per_step,
+            NULL,
+            x->nmvjointcost, x->mvcost,
+            &dis, &sse, second_pred,
+            pw, ph, 0);
+        }
     }
 
     // Restore the pointer to the first (possibly scaled) prediction buffer.
@@ -4990,57 +4990,57 @@
 
           if (bestsme < INT_MAX) {
             int distortion;
-#if CONFIG_AFFINE_MOTION
-            const int pw = 4 * num_4x4_blocks_wide_lookup[bsize];
-            const int ph = 4 * num_4x4_blocks_high_lookup[bsize];
-            // Use up-sampled reference frames.
-            struct macroblockd_plane *const pd = &xd->plane[0];
-            struct buf_2d backup_pred = pd->pre[0];
-            const YV12_BUFFER_CONFIG *upsampled_ref =
-                get_upsampled_ref(cpi, mbmi->ref_frame[0]);
+            if (cpi->sf.use_upsampled_references) {
+              const int pw = 4 * num_4x4_blocks_wide_lookup[bsize];
+              const int ph = 4 * num_4x4_blocks_high_lookup[bsize];
+              // Use up-sampled reference frames.
+              struct macroblockd_plane *const pd = &xd->plane[0];
+              struct buf_2d backup_pred = pd->pre[0];
+              const YV12_BUFFER_CONFIG *upsampled_ref =
+                  get_upsampled_ref(cpi, mbmi->ref_frame[0]);
 
-            // Set pred for Y plane
-            setup_pred_plane(&pd->pre[0], upsampled_ref->y_buffer,
-                             upsampled_ref->y_stride,
-                             (mi_row << 3), (mi_col << 3),
-                             NULL, pd->subsampling_x, pd->subsampling_y);
+              // Set pred for Y plane
+              setup_pred_plane(&pd->pre[0], upsampled_ref->y_buffer,
+                               upsampled_ref->y_stride,
+                               (mi_row << 3), (mi_col << 3),
+                               NULL, pd->subsampling_x, pd->subsampling_y);
 
-            // adjust pred pointer for this block
-            pd->pre[0].buf =
-                &pd->pre[0].buf[(vp10_raster_block_offset(BLOCK_8X8, i,
-                pd->pre[0].stride)) << 3];
+              // adjust pred pointer for this block
+              pd->pre[0].buf =
+                  &pd->pre[0].buf[(vp10_raster_block_offset(BLOCK_8X8, i,
+                  pd->pre[0].stride)) << 3];
 
-            cpi->find_fractional_mv_step(
-                x,
-                new_mv,
-                &bsi->ref_mv[0]->as_mv,
-                cm->allow_high_precision_mv,
-                x->errorperbit, &cpi->fn_ptr[bsize],
-                cpi->sf.mv.subpel_force_stop,
-                cpi->sf.mv.subpel_iters_per_step,
-                cond_cost_list(cpi, cost_list),
-                x->nmvjointcost, x->mvcost,
-                &distortion,
-                &x->pred_sse[mbmi->ref_frame[0]],
-                NULL, pw, ph, 1);
+              cpi->find_fractional_mv_step(
+                  x,
+                  new_mv,
+                  &bsi->ref_mv[0]->as_mv,
+                  cm->allow_high_precision_mv,
+                  x->errorperbit, &cpi->fn_ptr[bsize],
+                  cpi->sf.mv.subpel_force_stop,
+                  cpi->sf.mv.subpel_iters_per_step,
+                  cond_cost_list(cpi, cost_list),
+                  x->nmvjointcost, x->mvcost,
+                  &distortion,
+                  &x->pred_sse[mbmi->ref_frame[0]],
+                  NULL, pw, ph, 1);
 
-            // Restore the reference frames.
-            pd->pre[0] = backup_pred;
-#else
-            cpi->find_fractional_mv_step(
-                x,
-                new_mv,
-                &bsi->ref_mv[0]->as_mv,
-                cm->allow_high_precision_mv,
-                x->errorperbit, &cpi->fn_ptr[bsize],
-                cpi->sf.mv.subpel_force_stop,
-                cpi->sf.mv.subpel_iters_per_step,
-                cond_cost_list(cpi, cost_list),
-                x->nmvjointcost, x->mvcost,
-                &distortion,
-                &x->pred_sse[mbmi->ref_frame[0]],
-                NULL, 0, 0);
-#endif
+              // Restore the reference frames.
+              pd->pre[0] = backup_pred;
+            } else {
+              cpi->find_fractional_mv_step(
+                  x,
+                  new_mv,
+                  &bsi->ref_mv[0]->as_mv,
+                  cm->allow_high_precision_mv,
+                  x->errorperbit, &cpi->fn_ptr[bsize],
+                  cpi->sf.mv.subpel_force_stop,
+                  cpi->sf.mv.subpel_iters_per_step,
+                  cond_cost_list(cpi, cost_list),
+                  x->nmvjointcost, x->mvcost,
+                  &distortion,
+                  &x->pred_sse[mbmi->ref_frame[0]],
+                  NULL, 0, 0, 0);
+            }
 
             // save motion search result for use in compound prediction
 #if CONFIG_EXT_INTER
@@ -5637,43 +5637,43 @@
 
   if (bestsme < INT_MAX) {
     int dis;  /* TODO: use dis in distortion calculation later. */
-#if CONFIG_AFFINE_MOTION
-    const int pw = 4 * num_4x4_blocks_wide_lookup[bsize];
-    const int ph = 4 * num_4x4_blocks_high_lookup[bsize];
-    // Use up-sampled reference frames.
-    struct macroblockd_plane *const pd = &xd->plane[0];
-    struct buf_2d backup_pred = pd->pre[ref_idx];
-    const YV12_BUFFER_CONFIG *upsampled_ref = get_upsampled_ref(cpi, ref);
+    if (cpi->sf.use_upsampled_references) {
+      const int pw = 4 * num_4x4_blocks_wide_lookup[bsize];
+      const int ph = 4 * num_4x4_blocks_high_lookup[bsize];
+      // Use up-sampled reference frames.
+      struct macroblockd_plane *const pd = &xd->plane[0];
+      struct buf_2d backup_pred = pd->pre[ref_idx];
+      const YV12_BUFFER_CONFIG *upsampled_ref = get_upsampled_ref(cpi, ref);
 
-    // Set pred for Y plane
-    setup_pred_plane(&pd->pre[ref_idx], upsampled_ref->y_buffer,
-                     upsampled_ref->y_stride, (mi_row << 3), (mi_col << 3),
-                     NULL, pd->subsampling_x, pd->subsampling_y);
+      // Set pred for Y plane
+      setup_pred_plane(&pd->pre[ref_idx], upsampled_ref->y_buffer,
+                       upsampled_ref->y_stride, (mi_row << 3), (mi_col << 3),
+                       NULL, pd->subsampling_x, pd->subsampling_y);
 
-    bestsme = cpi->find_fractional_mv_step(x, &tmp_mv->as_mv, &ref_mv,
-                                           cm->allow_high_precision_mv,
-                                           x->errorperbit,
-                                           &cpi->fn_ptr[bsize],
-                                           cpi->sf.mv.subpel_force_stop,
-                                           cpi->sf.mv.subpel_iters_per_step,
-                                           cond_cost_list(cpi, cost_list),
-                                           x->nmvjointcost, x->mvcost,
-                                           &dis, &x->pred_sse[ref], NULL,
-                                           pw, ph, 1);
+      bestsme = cpi->find_fractional_mv_step(x, &tmp_mv->as_mv, &ref_mv,
+                                             cm->allow_high_precision_mv,
+                                             x->errorperbit,
+                                             &cpi->fn_ptr[bsize],
+                                             cpi->sf.mv.subpel_force_stop,
+                                             cpi->sf.mv.subpel_iters_per_step,
+                                             cond_cost_list(cpi, cost_list),
+                                             x->nmvjointcost, x->mvcost,
+                                             &dis, &x->pred_sse[ref], NULL,
+                                             pw, ph, 1);
 
-    // Restore the reference frames.
-    pd->pre[ref_idx] = backup_pred;
-#else
-    cpi->find_fractional_mv_step(x, &tmp_mv->as_mv, &ref_mv,
-                                 cm->allow_high_precision_mv,
-                                 x->errorperbit,
-                                 &cpi->fn_ptr[bsize],
-                                 cpi->sf.mv.subpel_force_stop,
-                                 cpi->sf.mv.subpel_iters_per_step,
-                                 cond_cost_list(cpi, cost_list),
-                                 x->nmvjointcost, x->mvcost,
-                                 &dis, &x->pred_sse[ref], NULL, 0, 0);
-#endif
+      // Restore the reference frames.
+      pd->pre[ref_idx] = backup_pred;
+    } else {
+      cpi->find_fractional_mv_step(x, &tmp_mv->as_mv, &ref_mv,
+                                   cm->allow_high_precision_mv,
+                                   x->errorperbit,
+                                   &cpi->fn_ptr[bsize],
+                                   cpi->sf.mv.subpel_force_stop,
+                                   cpi->sf.mv.subpel_iters_per_step,
+                                   cond_cost_list(cpi, cost_list),
+                                   x->nmvjointcost, x->mvcost,
+                                   &dis, &x->pred_sse[ref], NULL, 0, 0, 0);
+    }
   }
   *rate_mv = vp10_mv_bit_cost(&tmp_mv->as_mv, &ref_mv,
                              x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);