From 1a363a8cae8539e82f44028548bb8c1a4ae6bd60 Mon Sep 17 00:00:00 2001 From: Angie Chiang Date: Tue, 25 Jun 2019 15:21:17 -0700 Subject: [PATCH] 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 --- vp9/encoder/vp9_mcomp.c | 46 ++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/vp9/encoder/vp9_mcomp.c b/vp9/encoder/vp9_mcomp.c index 388f87040..52bcea55f 100644 --- a/vp9/encoder/vp9_mcomp.c +++ b/vp9/encoder/vp9_mcomp.c @@ -2149,18 +2149,20 @@ static double diamond_search_sad_new(const MACROBLOCK *x, 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 @@ static double diamond_search_sad_new(const MACROBLOCK *x, 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++; -- 2.40.0