summaryrefslogtreecommitdiff
path: root/apps/codecs/libtremor
diff options
context:
space:
mode:
authorNils Wallménius <nils@rockbox.org>2010-10-31 14:48:40 +0000
committerNils Wallménius <nils@rockbox.org>2010-10-31 14:48:40 +0000
commitdfac9503eb2828bf93fd5f6e29a46125c4fbeeb7 (patch)
treea0e6dfa805aaefca3d1b0e557864370294b888af /apps/codecs/libtremor
parenta177e13ee02f671d2476a2f68aeafbae49ffda69 (diff)
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
Diffstat (limited to 'apps/codecs/libtremor')
-rw-r--r--apps/codecs/libtremor/codebook.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/apps/codecs/libtremor/codebook.c b/apps/codecs/libtremor/codebook.c
index b27c2e390f..e75dddb29c 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<<book->dec_firsttablen)-1;
while (bufptr<bufend) {
if (b->headend > 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<<book->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 (bufptr<bufend){
- if (UNLIKELY(cachesize<book->dec_maxlength)) {
+ if (UNLIKELY(cachesize<book_dec_maxlength)) {
if (bit-cachesize+32>=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;