shithub: libvpx

Download patch

ref: 1a363a8cae8539e82f44028548bb8c1a4ae6bd60
parent: 5ab6039987847e60e621615fc135e198d5dc0ad8
author: Angie Chiang <angiebird@google.com>
date: Tue Jun 25 11:21:17 EDT 2019

Speed up diamond_search_sad_new

The percentage of encoding time spent on diamond_search_sad_new
reduces from 8% to 6%

Change-Id: I1be55b957475d780974cc2e721f8c2d4d266e916

--- a/vp9/encoder/vp9_mcomp.c
+++ b/vp9/encoder/vp9_mcomp.c
@@ -2149,18 +2149,20 @@
                        sad_array);
 
         for (t = 0; t < 4; t++, i++) {
-          const MV this_mv = { best_full_mv->row + ss_mv[i].row,
-                               best_full_mv->col + ss_mv[i].col };
-          const double mv_dist = sad_array[t];
-          const double mv_cost =
-              vp9_nb_mvs_inconsistency(&this_mv, nb_full_mvs, full_mv_num) /
-              (double)(1 << LOG2_PRECISION);
-          double thissad = mv_dist + lambda * mv_cost;
-          if (thissad < bestsad) {
-            bestsad = thissad;
-            *best_mv_dist = mv_dist;
-            *best_mv_cost = mv_cost;
-            best_site = i;
+          if (sad_array[t] < bestsad) {
+            const MV this_mv = { best_full_mv->row + ss_mv[i].row,
+                                 best_full_mv->col + ss_mv[i].col };
+            const double mv_dist = sad_array[t];
+            const double mv_cost =
+                vp9_nb_mvs_inconsistency(&this_mv, nb_full_mvs, full_mv_num) /
+                (double)(1 << LOG2_PRECISION);
+            double thissad = mv_dist + lambda * mv_cost;
+            if (thissad < bestsad) {
+              bestsad = thissad;
+              *best_mv_dist = mv_dist;
+              *best_mv_cost = mv_cost;
+              best_site = i;
+            }
           }
         }
       }
@@ -2174,15 +2176,17 @@
           const uint8_t *const check_here = ss_os[i] + best_address;
           const double mv_dist =
               fn_ptr->sdf(what, what_stride, check_here, in_what_stride);
-          const double mv_cost =
-              vp9_nb_mvs_inconsistency(&this_mv, nb_full_mvs, full_mv_num) /
-              (double)(1 << LOG2_PRECISION);
-          double thissad = mv_dist + lambda * mv_cost;
-          if (thissad < bestsad) {
-            bestsad = thissad;
-            *best_mv_dist = mv_dist;
-            *best_mv_cost = mv_cost;
-            best_site = i;
+          if (mv_dist < bestsad) {
+            const double mv_cost =
+                vp9_nb_mvs_inconsistency(&this_mv, nb_full_mvs, full_mv_num) /
+                (double)(1 << LOG2_PRECISION);
+            double thissad = mv_dist + lambda * mv_cost;
+            if (thissad < bestsad) {
+              bestsad = thissad;
+              *best_mv_dist = mv_dist;
+              *best_mv_cost = mv_cost;
+              best_site = i;
+            }
           }
         }
         i++;