Remove av1_cost_bit() It's more efficient to use av1_cost_literal() instead. Change-Id: I50727d4a4ee06492b373c2e7831c224c5eae8735
diff --git a/av1/encoder/cost.h b/av1/encoder/cost.h index 55a4af2..669f842 100644 --- a/av1/encoder/cost.h +++ b/av1/encoder/cost.h
@@ -24,12 +24,6 @@ // The factor to scale from cost in bits to cost in av1_prob_cost units. #define AV1_PROB_COST_SHIFT 9 -#define av1_cost_zero(prob) (av1_prob_cost[prob]) - -#define av1_cost_one(prob) av1_cost_zero(256 - (prob)) - -#define av1_cost_bit(prob, bit) av1_cost_zero((bit) ? 256 - (prob) : (prob)) - // Cost of coding an n bit literal, using 128 (i.e. 50%) probability // for each bit. #define av1_cost_literal(n) ((n) * (1 << AV1_PROB_COST_SHIFT)) @@ -38,7 +32,7 @@ static INLINE int av1_cost_symbol(aom_cdf_prob p15) { assert(0 < p15 && p15 < CDF_PROB_TOP); const int shift = CDF_PROB_BITS - 1 - get_msb(p15); - return av1_cost_zero(get_prob(p15 << shift, CDF_PROB_TOP)) + + return av1_prob_cost[get_prob(p15 << shift, CDF_PROB_TOP)] + av1_cost_literal(shift); }
diff --git a/av1/encoder/encodetxb.c b/av1/encoder/encodetxb.c index 614d180..946275b 100644 --- a/av1/encoder/encodetxb.c +++ b/av1/encoder/encodetxb.c
@@ -253,14 +253,11 @@ eob_cost = txb_eob_costs->eob_cost[eob_multi_ctx][eob_pt - 1]; if (k_eob_offset_bits[eob_pt] > 0) { - int eob_shift = k_eob_offset_bits[eob_pt] - 1; - int bit = (eob_extra & (1 << eob_shift)) ? 1 : 0; + const int eob_shift = k_eob_offset_bits[eob_pt] - 1; + const int bit = (eob_extra & (1 << eob_shift)) ? 1 : 0; eob_cost += txb_costs->eob_extra_cost[eob_pt][bit]; - for (int i = 1; i < k_eob_offset_bits[eob_pt]; i++) { - eob_shift = k_eob_offset_bits[eob_pt] - 1 - i; - bit = (eob_extra & (1 << eob_shift)) ? 1 : 0; - eob_cost += av1_cost_bit(128, bit); - } + const int offset_bits = k_eob_offset_bits[eob_pt]; + if (offset_bits > 1) eob_cost += av1_cost_literal(offset_bits - 1); } return eob_cost; } @@ -747,14 +744,14 @@ } if (is_nz) { - int sign = (v < 0) ? 1 : 0; + const int sign = (v < 0) ? 1 : 0; // sign bit cost if (c == 0) { int dc_sign_ctx = txb_ctx->dc_sign_ctx; cost += coeff_costs->dc_sign_cost[dc_sign_ctx][sign]; } else { - cost += av1_cost_bit(128, sign); + cost += av1_cost_literal(1); } if (level > NUM_BASE_LEVELS) { int ctx; @@ -772,19 +769,9 @@ if (level >= 1 + NUM_BASE_LEVELS + COEFF_BASE_RANGE) { // residual cost - int r = level - COEFF_BASE_RANGE - NUM_BASE_LEVELS; - int ri = r; - int length = 0; - - while (ri) { - ri >>= 1; - ++length; - } - - for (ri = 0; ri < length - 1; ++ri) cost += av1_cost_bit(128, 0); - - for (ri = length - 1; ri >= 0; --ri) - cost += av1_cost_bit(128, (r >> ri) & 0x01); + const int ri = level - COEFF_BASE_RANGE - NUM_BASE_LEVELS; + const int length = get_msb(ri) + 1; + cost += av1_cost_literal(2 * length); } } } @@ -809,7 +796,7 @@ if (coeff_idx == 0) { return dc_sign_cost[dc_sign_ctx][sign]; } else { - return av1_cost_bit(128, sign); + return av1_cost_literal(1); } } static INLINE int get_golomb_cost(int abs_qc) {
diff --git a/av1/encoder/palette.c b/av1/encoder/palette.c index 5fcbf9a..e61cd02 100644 --- a/av1/encoder/palette.c +++ b/av1/encoder/palette.c
@@ -125,7 +125,7 @@ cache_color_found, out_cache_colors); const int total_bits = n_cache + delta_encode_cost(out_cache_colors, n_out_cache, bit_depth, 1); - return total_bits * av1_cost_bit(128, 0); + return av1_cost_literal(total_bits); } int av1_palette_color_cost_uv(const PALETTE_MODE_INFO *const pmi, @@ -150,5 +150,5 @@ 2 + bit_depth + (bits_v + 1) * (n - 1) - zero_count; const int bits_using_raw = bit_depth * n; total_bits += 1 + AOMMIN(bits_using_delta, bits_using_raw); - return total_bits * av1_cost_bit(128, 0); + return av1_cost_literal(total_bits); }
diff --git a/av1/encoder/rd.h b/av1/encoder/rd.h index 31057cd..44f2f1b 100644 --- a/av1/encoder/rd.h +++ b/av1/encoder/rd.h
@@ -382,7 +382,7 @@ int is_first, const int *head_cost_table, const int *tail_cost_table) { - if (eob_val == LAST_EOB) return av1_cost_zero(128); + if (eob_val == LAST_EOB) return av1_cost_literal(1); const int comb_symb = 2 * AOMMIN(token, TWO_TOKEN) - eob_val + is_first; int cost = head_cost_table[comb_symb]; if (token > ONE_TOKEN) cost += tail_cost_table[token - TWO_TOKEN];
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c index 62911d0..d6edcf5 100644 --- a/av1/encoder/rdopt.c +++ b/av1/encoder/rdopt.c
@@ -363,9 +363,9 @@ const int m = (1 << l) - n; if (l == 0) return 0; if (v < m) - return (l - 1) * av1_cost_bit(128, 0); + return av1_cost_literal(l - 1); else - return l * av1_cost_bit(128, 0); + return av1_cost_literal(l); } // constants for prune 1 and prune 2 decision boundaries