vp10: code sign bit before absolute value in non-arithcoded header.

For reading, this makes the operation branchless, although it still
requires two shifts. For writing, this makes the operation as fast
as writing an unsigned value, branchlessly. This is also how other
codecs typically code signed, non-arithcoded bitstream elements.

See issue 1039.

Change-Id: I6a8182cc88a16842fb431688c38f6b52d7f24ead
This commit is contained in:
Ronald S. Bultje
2015-09-08 14:26:42 -04:00
parent 3c8e04e939
commit a3df343cda
6 changed files with 34 additions and 9 deletions

View File

@@ -7,6 +7,7 @@
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "./vpx_config.h"
#include "./bitreader_buffer.h"
size_t vpx_rb_bytes_read(struct vpx_read_bit_buffer *rb) {
@@ -39,3 +40,14 @@ int vpx_rb_read_signed_literal(struct vpx_read_bit_buffer *rb,
const int value = vpx_rb_read_literal(rb, bits);
return vpx_rb_read_bit(rb) ? -value : value;
}
int vpx_rb_read_inv_signed_literal(struct vpx_read_bit_buffer *rb,
int bits) {
#if CONFIG_MISC_FIXES
const int nbits = sizeof(unsigned) * 8 - bits - 1;
const unsigned value = vpx_rb_read_literal(rb, bits + 1) << nbits;
return ((int) value) >> nbits;
#else
return vpx_rb_read_signed_literal(rb, bits);
#endif
}