Propgate constants through subexp routines.

This avoids calls to get_unsigned_bits() with constants and
replaces hard to trace loops with simpler structures.

Change-Id: Ic1afc5a17d7df5bcfc85b76efda316b0bf118467
This commit is contained in:
Alex Converse 2014-02-03 11:14:46 -08:00
parent f7c17b89f0
commit 41d3c989fd
2 changed files with 42 additions and 90 deletions

View File

@ -19,14 +19,10 @@ static int inv_recenter_nonneg(int v, int m) {
return v % 2 ? m - (v + 1) / 2 : m + v / 2; return v % 2 ? m - (v + 1) / 2 : m + v / 2;
} }
static int decode_uniform(vp9_reader *r, int n) { static int decode_uniform(vp9_reader *r) {
int v; const int l = 8;
const int l = get_unsigned_bits(n); const int m = (1 << l) - 191;
const int m = (1 << l) - n; const int v = vp9_read_literal(r, l - 1);
if (!l)
return 0;
v = vp9_read_literal(r, l - 1);
return v < m ? v : (v << 1) - m + vp9_read_bit(r); return v < m ? v : (v << 1) - m + vp9_read_bit(r);
} }
@ -78,30 +74,19 @@ static int inv_remap_prob(int v, int m) {
} }
} }
static int decode_term_subexp(vp9_reader *r, int k, int num_syms) { static int decode_term_subexp(vp9_reader *r) {
int i = 0, mk = 0, word; if (!vp9_read_bit(r))
while (1) { return vp9_read_literal(r, 4);
const int b = i ? k + i - 1 : k; if (!vp9_read_bit(r))
const int a = 1 << b; return vp9_read_literal(r, 4) + 16;
if (num_syms <= mk + 3 * a) { if (!vp9_read_bit(r))
word = decode_uniform(r, num_syms - mk) + mk; return vp9_read_literal(r, 5) + 32;
break; return decode_uniform(r) + 64;
} else {
if (vp9_read_bit(r)) {
i++;
mk += a;
} else {
word = vp9_read_literal(r, b) + mk;
break;
}
}
}
return word;
} }
void vp9_diff_update_prob(vp9_reader *r, vp9_prob* p) { void vp9_diff_update_prob(vp9_reader *r, vp9_prob* p) {
if (vp9_read(r, DIFF_UPDATE_PROB)) { if (vp9_read(r, DIFF_UPDATE_PROB)) {
const int delp = decode_term_subexp(r, SUBEXP_PARAM, 255); const int delp = decode_term_subexp(r);
*p = (vp9_prob)inv_remap_prob(delp, *p); *p = (vp9_prob)inv_remap_prob(delp, *p);
} }
} }

View File

@ -18,17 +18,6 @@
static int update_bits[255]; static int update_bits[255];
static int count_uniform(int v, int n) {
int l = get_unsigned_bits(n);
int m;
if (l == 0) return 0;
m = (1 << l) - n;
if (v < m)
return l - 1;
else
return l;
}
static int split_index(int i, int n, int modulus) { static int split_index(int i, int n, int modulus) {
int max1 = (n - 1 - modulus / 2) / modulus + 1; int max1 = (n - 1 - modulus / 2) / modulus + 1;
if (i % modulus == modulus / 2) if (i % modulus == modulus / 2)
@ -81,29 +70,16 @@ static int remap_prob(int v, int m) {
return i; return i;
} }
static int count_term_subexp(int word, int k, int num_syms) { static int count_term_subexp(int word) {
int count = 0; if (word < 16)
int i = 0; return 5;
int mk = 0; if (word < 32)
while (1) { return 6;
int b = (i ? k + i - 1 : k); if (word < 64)
int a = (1 << b); return 8;
if (num_syms <= mk + 3 * a) { if (word < 129)
count += count_uniform(word - mk, num_syms - mk); return 10;
break; return 11;
} else {
int t = (word >= mk + a);
count++;
if (t) {
i = i + 1;
mk += a;
} else {
count += b;
break;
}
}
}
return count;
} }
static int prob_diff_update_cost(vp9_prob newp, vp9_prob oldp) { static int prob_diff_update_cost(vp9_prob newp, vp9_prob oldp) {
@ -111,12 +87,9 @@ static int prob_diff_update_cost(vp9_prob newp, vp9_prob oldp) {
return update_bits[delp] * 256; return update_bits[delp] * 256;
} }
static void encode_uniform(vp9_writer *w, int v, int n) { static void encode_uniform(vp9_writer *w, int v) {
int l = get_unsigned_bits(n); const int l = 8;
int m; const int m = (1 << l) - 191;
if (l == 0)
return;
m = (1 << l) - n;
if (v < m) { if (v < m) {
vp9_write_literal(w, v, l - 1); vp9_write_literal(w, v, l - 1);
} else { } else {
@ -125,38 +98,32 @@ static void encode_uniform(vp9_writer *w, int v, int n) {
} }
} }
static void encode_term_subexp(vp9_writer *w, int word, int k, int num_syms) { static INLINE int write_bit_gte(vp9_writer *w, int word, int test) {
int i = 0; vp9_write_literal(w, word >= test, 1);
int mk = 0; return word >= test;
while (1) {
int b = (i ? k + i - 1 : k);
int a = (1 << b);
if (num_syms <= mk + 3 * a) {
encode_uniform(w, word - mk, num_syms - mk);
break;
} else {
int t = (word >= mk + a);
vp9_write_literal(w, t, 1);
if (t) {
i = i + 1;
mk += a;
} else {
vp9_write_literal(w, word - mk, b);
break;
}
} }
static void encode_term_subexp(vp9_writer *w, int word) {
if (!write_bit_gte(w, word, 16)) {
vp9_write_literal(w, word, 4);
} else if (!write_bit_gte(w, word, 32)) {
vp9_write_literal(w, word - 16, 4);
} else if (!write_bit_gte(w, word, 64)) {
vp9_write_literal(w, word - 32, 5);
} else {
encode_uniform(w, word - 64);
} }
} }
void vp9_write_prob_diff_update(vp9_writer *w, vp9_prob newp, vp9_prob oldp) { void vp9_write_prob_diff_update(vp9_writer *w, vp9_prob newp, vp9_prob oldp) {
const int delp = remap_prob(newp, oldp); const int delp = remap_prob(newp, oldp);
encode_term_subexp(w, delp, SUBEXP_PARAM, 255); encode_term_subexp(w, delp);
} }
void vp9_compute_update_table() { void vp9_compute_update_table() {
int i; int i;
for (i = 0; i < 254; i++) for (i = 0; i < 254; i++)
update_bits[i] = count_term_subexp(i, SUBEXP_PARAM, 255); update_bits[i] = count_term_subexp(i);
} }
int vp9_prob_diff_update_savings_search(const unsigned int *ct, int vp9_prob_diff_update_savings_search(const unsigned int *ct,