diff options
author | Nils Wallménius <nils@rockbox.org> | 2010-10-31 14:48:40 +0000 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2010-10-31 14:48:40 +0000 |
commit | dfac9503eb2828bf93fd5f6e29a46125c4fbeeb7 (patch) | |
tree | a0e6dfa805aaefca3d1b0e557864370294b888af /apps/codecs/libtremor/codebook.c | |
parent | a177e13ee02f671d2476a2f68aeafbae49ffda69 (diff) | |
download | rockbox-dfac9503eb2828bf93fd5f6e29a46125c4fbeeb7.tar.gz rockbox-dfac9503eb2828bf93fd5f6e29a46125c4fbeeb7.zip |
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/codebook.c')
-rw-r--r-- | apps/codecs/libtremor/codebook.c | 33 |
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, | |||
277 | long *buf, int n){ | 277 | long *buf, int n){ |
278 | long *bufptr = buf; | 278 | long *bufptr = buf; |
279 | long *bufend = buf + n; | 279 | long *bufend = buf + n; |
280 | const unsigned int cachemask = (1<<book->dec_firsttablen)-1; | ||
281 | 280 | ||
282 | while (bufptr<bufend) { | 281 | while (bufptr<bufend) { |
283 | if (b->headend > 8) { | 282 | if (b->headend > 8) { |
@@ -286,34 +285,42 @@ static long decode_packed_block(codebook *book, oggpack_buffer *b, | |||
286 | unsigned long adr; | 285 | unsigned long adr; |
287 | ogg_uint32_t cache = 0; | 286 | ogg_uint32_t cache = 0; |
288 | int cachesize = 0; | 287 | int cachesize = 0; |
288 | const unsigned int cachemask = (1<<book->dec_firsttablen)-1; | ||
289 | const int book_dec_maxlength = book->dec_maxlength; | ||
290 | const ogg_uint32_t *book_dec_firsttable = book->dec_firsttable; | ||
291 | const long book_used_entries = book->used_entries; | ||
292 | const ogg_uint32_t *book_codelist = book->codelist; | ||
293 | const char *book_dec_codelengths = book->dec_codelengths; | ||
289 | 294 | ||
290 | adr = (unsigned long)b->headptr; | 295 | adr = (unsigned long)b->headptr; |
291 | bit = (adr&3)*8+b->headbit; | 296 | bit = (adr&3)*8+b->headbit; |
292 | ptr = (ogg_uint32_t *)(adr&~3); | 297 | ptr = (ogg_uint32_t*)(adr&~3); |
293 | bitend = ((adr&3)+b->headend)*8; | 298 | bitend = ((adr&3)+b->headend)*8; |
294 | while (bufptr<bufend){ | 299 | while (bufptr<bufend){ |
295 | if (UNLIKELY(cachesize<book->dec_maxlength)) { | 300 | if (UNLIKELY(cachesize<book_dec_maxlength)) { |
296 | if (bit-cachesize+32>=bitend) | 301 | if (bit-cachesize+32>=bitend) |
297 | break; | 302 | break; |
298 | bit-=cachesize; | 303 | bit-=cachesize; |
299 | cache=letoh32(ptr[bit>>5]) >> (bit&31); | 304 | cache = letoh32(ptr[bit>>5]); |
300 | if (bit&31) | 305 | if (bit&31) { |
301 | cache|=letoh32(ptr[(bit>>5)+1]) << (32-(bit&31)); | 306 | cache >>= (bit&31); |
307 | cache |= letoh32(ptr[(bit>>5)+1]) << (32-(bit&31)); | ||
308 | } | ||
302 | cachesize=32; | 309 | cachesize=32; |
303 | bit+=32; | 310 | bit+=32; |
304 | } | 311 | } |
305 | 312 | ||
306 | ogg_int32_t entry = book->dec_firsttable[cache&cachemask]; | 313 | ogg_int32_t entry = book_dec_firsttable[cache&cachemask]; |
307 | if(UNLIKELY(entry < 0)){ | 314 | if(UNLIKELY(entry < 0)){ |
308 | const long lo = (entry>>15)&0x7fff, hi = book->used_entries-(entry&0x7fff); | 315 | const long lo = (entry>>15)&0x7fff, hi = book_used_entries-(entry&0x7fff); |
309 | entry = bisect_codelist(lo, hi, cache, book->codelist); | 316 | entry = bisect_codelist(lo, hi, cache, book_codelist); |
310 | }else | 317 | }else |
311 | entry--; | 318 | entry--; |
312 | 319 | ||
313 | *bufptr++=entry; | 320 | *bufptr++ = entry; |
314 | int l=book->dec_codelengths[entry]; | 321 | int l = book_dec_codelengths[entry]; |
315 | cachesize-=l; | 322 | cachesize -= l; |
316 | cache>>=l; | 323 | cache >>= l; |
317 | } | 324 | } |
318 | 325 | ||
319 | adr=(unsigned long)b->headptr; | 326 | adr=(unsigned long)b->headptr; |