Add get_br_count_mag() This will speed up lv_map encoder time by 1.5% Change-Id: Ia9f7634bae221d2fb8fb7dc6f3202c6bacdd5b32
diff --git a/av1/common/txb_common.h b/av1/common/txb_common.h index 562b9fb..6dde2a0 100644 --- a/av1/common/txb_common.h +++ b/av1/common/txb_common.h
@@ -179,6 +179,33 @@ #define BR_MAG_OFFSET 1 // TODO(angiebird): optimize this function by using a table to map from // count/mag to ctx + +static INLINE int get_br_count_mag(int *mag, const tran_low_t *tcoeffs, int bwl, + int height, int row, int col, int level) { + mag[0] = 0; + mag[1] = 0; + int count = 0; + for (int idx = 0; idx < BR_CONTEXT_POSITION_NUM; ++idx) { + const int ref_row = row + br_ref_offset[idx][0]; + const int ref_col = col + br_ref_offset[idx][1]; + if (ref_row < 0 || ref_col < 0 || ref_row >= height || + ref_col >= (1 << bwl)) + continue; + const int pos = (ref_row << bwl) + ref_col; + tran_low_t abs_coeff = abs(tcoeffs[pos]); + count += abs_coeff > level; + if (br_ref_offset[idx][0] >= 0 && br_ref_offset[idx][1] >= 0) { + if (abs_coeff > mag[0]) { + mag[0] = abs_coeff; + mag[1] = 1; + } else if (abs_coeff == mag[0]) { + ++mag[1]; + } + } + } + return count; +} + static INLINE int get_br_ctx_from_count_mag(int row, int col, int count, int mag) { int offset = 0;
diff --git a/av1/encoder/encodetxb.c b/av1/encoder/encodetxb.c index f152b43..35edbec 100644 --- a/av1/encoder/encodetxb.c +++ b/av1/encoder/encodetxb.c
@@ -476,10 +476,8 @@ if (!has_br(qcoeff[coeff_idx])) continue; int *br_count = txb_cache->br_count_arr + coeff_idx; int *br_mag = txb_cache->br_mag_arr[coeff_idx]; - *br_count = get_level_count(qcoeff, bwl, height, row, col, NUM_BASE_LEVELS, - br_ref_offset, BR_CONTEXT_POSITION_NUM); - get_mag(br_mag, qcoeff, bwl, height, row, col, br_ref_offset, - BR_CONTEXT_POSITION_NUM); + *br_count = get_br_count_mag(br_mag, qcoeff, bwl, height, row, col, + NUM_BASE_LEVELS); txb_cache->br_ctx_arr[coeff_idx] = get_br_ctx_from_count_mag(row, col, *br_count, br_mag[0]); }