From b245980849aeffe1accbc5a55e79d7cbb41dd9f6 Mon Sep 17 00:00:00 2001 From: nls Date: Sun, 31 Oct 2010 14:48:40 +0000 Subject: [PATCH] libtremor: tweak a hot function for codebook decoding, mostly moving pointer lookups outside the loop. Speeds up decoding by 3-6% on Coldfire and a small speedup on arm too git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28419 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/libtremor/codebook.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/apps/codecs/libtremor/codebook.c b/apps/codecs/libtremor/codebook.c index b27c2e390..e75dddb29 100644 --- a/apps/codecs/libtremor/codebook.c +++ b/apps/codecs/libtremor/codebook.c @@ -277,7 +277,6 @@ static long decode_packed_block(codebook *book, oggpack_buffer *b, long *buf, int n){ long *bufptr = buf; long *bufend = buf + n; - const unsigned int cachemask = (1<dec_firsttablen)-1; while (bufptrheadend > 8) { @@ -286,34 +285,42 @@ static long decode_packed_block(codebook *book, oggpack_buffer *b, unsigned long adr; ogg_uint32_t cache = 0; int cachesize = 0; + const unsigned int cachemask = (1<dec_firsttablen)-1; + const int book_dec_maxlength = book->dec_maxlength; + const ogg_uint32_t *book_dec_firsttable = book->dec_firsttable; + const long book_used_entries = book->used_entries; + const ogg_uint32_t *book_codelist = book->codelist; + const char *book_dec_codelengths = book->dec_codelengths; adr = (unsigned long)b->headptr; bit = (adr&3)*8+b->headbit; - ptr = (ogg_uint32_t *)(adr&~3); + ptr = (ogg_uint32_t*)(adr&~3); bitend = ((adr&3)+b->headend)*8; while (bufptrdec_maxlength)) { + if (UNLIKELY(cachesize=bitend) break; bit-=cachesize; - cache=letoh32(ptr[bit>>5]) >> (bit&31); - if (bit&31) - cache|=letoh32(ptr[(bit>>5)+1]) << (32-(bit&31)); + cache = letoh32(ptr[bit>>5]); + if (bit&31) { + cache >>= (bit&31); + cache |= letoh32(ptr[(bit>>5)+1]) << (32-(bit&31)); + } cachesize=32; bit+=32; } - ogg_int32_t entry = book->dec_firsttable[cache&cachemask]; + ogg_int32_t entry = book_dec_firsttable[cache&cachemask]; if(UNLIKELY(entry < 0)){ - const long lo = (entry>>15)&0x7fff, hi = book->used_entries-(entry&0x7fff); - entry = bisect_codelist(lo, hi, cache, book->codelist); + const long lo = (entry>>15)&0x7fff, hi = book_used_entries-(entry&0x7fff); + entry = bisect_codelist(lo, hi, cache, book_codelist); }else entry--; - *bufptr++=entry; - int l=book->dec_codelengths[entry]; - cachesize-=l; - cache>>=l; + *bufptr++ = entry; + int l = book_dec_codelengths[entry]; + cachesize -= l; + cache >>= l; } adr=(unsigned long)b->headptr; -- 2.11.4.GIT