Commit 05c04cdf authored by Jason Garrett-Glaser's avatar Jason Garrett-Glaser

VP5/6/8: ~7% faster arithmetic decoding

Grab from the bitstream in 16-bit chunks instead of 8-bit chunks.
TODO: grab in 32-bit chunks on 64-bit systems.

Originally committed as revision 24783 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent d2064fd4
...@@ -194,8 +194,8 @@ static av_always_inline unsigned int vp56_rac_renorm(VP56RangeCoder *c) ...@@ -194,8 +194,8 @@ static av_always_inline unsigned int vp56_rac_renorm(VP56RangeCoder *c)
code_word <<= shift; code_word <<= shift;
bits += shift; bits += shift;
if(bits >= 0 && c->buffer < c->end) { if(bits >= 0 && c->buffer < c->end) {
code_word |= *c->buffer++ << bits; code_word |= bytestream_get_be16(&c->buffer) << bits;
bits -= 8; bits -= 16;
} }
c->bits = bits; c->bits = bits;
return code_word; return code_word;
...@@ -211,7 +211,7 @@ static av_always_inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob) ...@@ -211,7 +211,7 @@ static av_always_inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob)
{ {
unsigned int code_word = vp56_rac_renorm(c); unsigned int code_word = vp56_rac_renorm(c);
unsigned int low = 1 + (((c->high - 1) * prob) >> 8); unsigned int low = 1 + (((c->high - 1) * prob) >> 8);
unsigned int low_shift = low << 8; unsigned int low_shift = low << 16;
int bit = code_word >= low_shift; int bit = code_word >= low_shift;
c->high = bit ? c->high - low : low; c->high = bit ? c->high - low : low;
...@@ -226,7 +226,7 @@ static av_always_inline int vp56_rac_get_prob_branchy(VP56RangeCoder *c, int pro ...@@ -226,7 +226,7 @@ static av_always_inline int vp56_rac_get_prob_branchy(VP56RangeCoder *c, int pro
{ {
unsigned long code_word = vp56_rac_renorm(c); unsigned long code_word = vp56_rac_renorm(c);
unsigned low = 1 + (((c->high - 1) * prob) >> 8); unsigned low = 1 + (((c->high - 1) * prob) >> 8);
unsigned low_shift = low << 8; unsigned low_shift = low << 16;
if (code_word >= low_shift) { if (code_word >= low_shift) {
c->high -= low; c->high -= low;
...@@ -244,7 +244,7 @@ static av_always_inline int vp56_rac_get(VP56RangeCoder *c) ...@@ -244,7 +244,7 @@ static av_always_inline int vp56_rac_get(VP56RangeCoder *c)
unsigned int code_word = vp56_rac_renorm(c); unsigned int code_word = vp56_rac_renorm(c);
/* equiprobable */ /* equiprobable */
int low = (c->high + 1) >> 1; int low = (c->high + 1) >> 1;
unsigned int low_shift = low << 8; unsigned int low_shift = low << 16;
int bit = code_word >= low_shift; int bit = code_word >= low_shift;
if (bit) { if (bit) {
c->high -= low; c->high -= low;
......
...@@ -40,8 +40,8 @@ const uint8_t ff_vp56_norm_shift[256]= { ...@@ -40,8 +40,8 @@ const uint8_t ff_vp56_norm_shift[256]= {
void ff_vp56_init_range_decoder(VP56RangeCoder *c, const uint8_t *buf, int buf_size) void ff_vp56_init_range_decoder(VP56RangeCoder *c, const uint8_t *buf, int buf_size)
{ {
c->high = 255; c->high = 255;
c->bits = -8; c->bits = -16;
c->buffer = buf; c->buffer = buf;
c->end = buf + buf_size; c->end = buf + buf_size;
c->code_word = bytestream_get_be16(&c->buffer); c->code_word = bytestream_get_be24(&c->buffer);
} }
...@@ -31,7 +31,7 @@ static av_always_inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob) ...@@ -31,7 +31,7 @@ static av_always_inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob)
unsigned int code_word = vp56_rac_renorm(c); unsigned int code_word = vp56_rac_renorm(c);
unsigned int high = c->high; unsigned int high = c->high;
unsigned int low = 1 + (((high - 1) * prob) >> 8); unsigned int low = 1 + (((high - 1) * prob) >> 8);
unsigned int low_shift = low << 8; unsigned int low_shift = low << 16;
int bit = 0; int bit = 0;
__asm__( __asm__(
......
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