From 9b4f9f45eee4d63cef3cd10f24923ed0bdd5ab7b Mon Sep 17 00:00:00 2001 From: Jim Bankoski Date: Thu, 9 Jul 2015 11:41:30 -0700 Subject: Fill buffer speed up Eliminates the byte by byte read from bool decoder, by reading in a size_t and then shifting it into place. Change-Id: Id89241977103fc3b973e4ed172a5cbf246998e5d --- vp9/decoder/vp9_reader.c | 50 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 13 deletions(-) (limited to 'vp9/decoder') diff --git a/vp9/decoder/vp9_reader.c b/vp9/decoder/vp9_reader.c index 2c96f74f4..9a46cd717 100644 --- a/vp9/decoder/vp9_reader.c +++ b/vp9/decoder/vp9_reader.c @@ -7,12 +7,24 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ +#include #include "vpx_ports/mem.h" #include "vpx_mem/vpx_mem.h" +#include "./vpx_config.h" #include "vp9/decoder/vp9_reader.h" +#include "vpx_util/endian_inl.h" + +#if CONFIG_BIG_ENDIAN +#define BIGENDIFY64(X) (X) +#define BIGENDIFY32(X) (X) +#else +#define BIGENDIFY64(X) BSwap64(X) +#define BIGENDIFY32(X) BSwap32(X) +#endif + int vp9_reader_init(vp9_reader *r, const uint8_t *buffer, size_t size, @@ -39,11 +51,9 @@ void vp9_reader_fill(vp9_reader *r) { const uint8_t *buffer_start = buffer; BD_VALUE value = r->value; int count = r->count; - int shift = BD_VALUE_SIZE - CHAR_BIT - (count + CHAR_BIT); - int loop_end = 0; const size_t bytes_left = buffer_end - buffer; const size_t bits_left = bytes_left * CHAR_BIT; - const int x = (int)(shift + CHAR_BIT - bits_left); + int shift = BD_VALUE_SIZE - CHAR_BIT - (count + CHAR_BIT); if (r->decrypt_cb) { size_t n = MIN(sizeof(r->clear_buffer), bytes_left); @@ -51,17 +61,31 @@ void vp9_reader_fill(vp9_reader *r) { buffer = r->clear_buffer; buffer_start = r->clear_buffer; } + if (bits_left > BD_VALUE_SIZE) { +#if UINTPTR_MAX == 0xffffffffffffffff + BD_VALUE big_endian_values = BIGENDIFY64(*((const BD_VALUE *) buffer)); +#else + BD_VALUE big_endian_values = BIGENDIFY32(*((const BD_VALUE *) buffer)); +#endif + const int bits = (shift & 0xfffffff8) + CHAR_BIT; + const BD_VALUE nv = big_endian_values >> (BD_VALUE_SIZE - bits); + count += bits; + buffer += (bits >> 3); + value = r->value | (nv << (shift & 0x7)); + } else { + const int bits_over = (int)(shift + CHAR_BIT - bits_left); + int loop_end = 0; + if (bits_over >= 0) { + count += LOTS_OF_BITS; + loop_end = bits_over; + } - if (x >= 0) { - count += LOTS_OF_BITS; - loop_end = x; - } - - if (x < 0 || bits_left) { - while (shift >= loop_end) { - count += CHAR_BIT; - value |= (BD_VALUE)*buffer++ << shift; - shift -= CHAR_BIT; + if (bits_over < 0 || bits_left) { + while (shift >= loop_end) { + count += CHAR_BIT; + value |= (BD_VALUE)*buffer++ << shift; + shift -= CHAR_BIT; + } } } -- cgit v1.2.3