Commit 751a2335 authored by Hui Su's avatar Hui Su

Remove av1_cost_bit()

It's more efficient to use av1_cost_literal() instead.

Change-Id: I50727d4a4ee06492b373c2e7831c224c5eae8735
parent 41d61528
......@@ -60,30 +60,10 @@ static INLINE void aom_write(aom_writer *br, int bit, int probability) {
aom_daala_write(br, bit, probability);
}
static INLINE void aom_write_record(aom_writer *br, int bit, int probability,
TOKEN_STATS *token_stats) {
aom_write(br, bit, probability);
#if CONFIG_RD_DEBUG
token_stats->cost += av1_cost_bit(probability, bit);
#else
(void)token_stats;
#endif
}
static INLINE void aom_write_bit(aom_writer *w, int bit) {
aom_write(w, bit, 128); // aom_prob_half
}
static INLINE void aom_write_bit_record(aom_writer *w, int bit,
TOKEN_STATS *token_stats) {
aom_write_bit(w, bit);
#if CONFIG_RD_DEBUG
token_stats->cost += av1_cost_bit(128, bit); // aom_prob_half
#else
(void)token_stats;
#endif
}
static INLINE void aom_write_literal(aom_writer *w, int data, int bits) {
int bit;
......
......@@ -24,12 +24,6 @@ extern const uint16_t av1_prob_cost[256];
// 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 @@ extern const uint16_t av1_prob_cost[256];
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);
}
......
......@@ -253,14 +253,11 @@ static int get_eob_cost(int eob, int seg_eob,
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 @@ int av1_cost_coeffs_txb(const AV1_COMMON *const cm, const MACROBLOCK *x,
}
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 @@ int av1_cost_coeffs_txb(const AV1_COMMON *const cm, const MACROBLOCK *x,
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 @@ static INLINE int get_sign_bit_cost(tran_low_t qc, int coeff_idx,
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) {
......
......@@ -125,7 +125,7 @@ int av1_palette_color_cost_y(const PALETTE_MODE_INFO *const pmi,
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 @@ int av1_palette_color_cost_uv(const PALETTE_MODE_INFO *const pmi,
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);
}
......@@ -382,7 +382,7 @@ static INLINE int av1_get_coeff_token_cost(int token, int8_t eob_val,
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];
......
......@@ -363,9 +363,9 @@ static INLINE int write_uniform_cost(int n, int v) {
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment