Commit 41d3c989 authored by Alex Converse's avatar Alex Converse
Browse files

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
parent f7c17b89
......@@ -19,14 +19,10 @@ static int inv_recenter_nonneg(int v, int m) {
return v % 2 ? m - (v + 1) / 2 : m + v / 2;
}
static int decode_uniform(vp9_reader *r, int n) {
int v;
const int l = get_unsigned_bits(n);
const int m = (1 << l) - n;
if (!l)
return 0;
v = vp9_read_literal(r, l - 1);
static int decode_uniform(vp9_reader *r) {
const int l = 8;
const int m = (1 << l) - 191;
const int v = vp9_read_literal(r, l - 1);
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) {
int i = 0, mk = 0, word;
while (1) {
const int b = i ? k + i - 1 : k;
const int a = 1 << b;
if (num_syms <= mk + 3 * a) {
word = decode_uniform(r, num_syms - mk) + mk;
break;
} else {
if (vp9_read_bit(r)) {
i++;
mk += a;
} else {
word = vp9_read_literal(r, b) + mk;
break;
}
}
}
return word;
static int decode_term_subexp(vp9_reader *r) {
if (!vp9_read_bit(r))
return vp9_read_literal(r, 4);
if (!vp9_read_bit(r))
return vp9_read_literal(r, 4) + 16;
if (!vp9_read_bit(r))
return vp9_read_literal(r, 5) + 32;
return decode_uniform(r) + 64;
}
void vp9_diff_update_prob(vp9_reader *r, vp9_prob* p) {
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);
}
}
......@@ -18,17 +18,6 @@
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) {
int max1 = (n - 1 - modulus / 2) / modulus + 1;
if (i % modulus == modulus / 2)
......@@ -81,29 +70,16 @@ static int remap_prob(int v, int m) {
return i;
}
static int count_term_subexp(int word, int k, int num_syms) {
int count = 0;
int i = 0;
int mk = 0;
while (1) {
int b = (i ? k + i - 1 : k);
int a = (1 << b);
if (num_syms <= mk + 3 * a) {
count += count_uniform(word - mk, num_syms - mk);
break;
} else {
int t = (word >= mk + a);
count++;
if (t) {
i = i + 1;
mk += a;
} else {
count += b;
break;
}
}
}
return count;
static int count_term_subexp(int word) {
if (word < 16)
return 5;
if (word < 32)
return 6;
if (word < 64)
return 8;
if (word < 129)
return 10;
return 11;
}
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;
}
static void encode_uniform(vp9_writer *w, int v, int n) {
int l = get_unsigned_bits(n);
int m;
if (l == 0)
return;
m = (1 << l) - n;
static void encode_uniform(vp9_writer *w, int v) {
const int l = 8;
const int m = (1 << l) - 191;
if (v < m) {
vp9_write_literal(w, v, l - 1);
} 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) {
int i = 0;
int mk = 0;
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 INLINE int write_bit_gte(vp9_writer *w, int word, int test) {
vp9_write_literal(w, word >= test, 1);
return word >= test;
}
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) {
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() {
int 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,
......
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