From 01f91ed14d197747f489064d28b6a7ace80ebce6 Mon Sep 17 00:00:00 2001 From: Nils Wallménius Date: Thu, 1 Jul 2010 20:31:07 +0000 Subject: Factor out sane code list bisection code and use instead of insane code, clean up some tests for readability's sake. Gives a small speedup on h300 (coldfire, 0.1-0.6MHz) and a tiny speedup on gigabeat s (armv6 0.1-0.2MHz), no real difference on PP. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27223 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/libtremor/codebook.c | 46 ++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 25 deletions(-) (limited to 'apps/codecs') diff --git a/apps/codecs/libtremor/codebook.c b/apps/codecs/libtremor/codebook.c index c938f2f73d..772a81c7f9 100644 --- a/apps/codecs/libtremor/codebook.c +++ b/apps/codecs/libtremor/codebook.c @@ -215,6 +215,20 @@ static inline ogg_uint32_t bitreverse(register ogg_uint32_t x) return ret; } +static inline long bisect_codelist(long lo, long hi, ogg_uint32_t cache, + const ogg_uint32_t *codelist) +{ + ogg_uint32_t testword=bitreverse(cache); + long p; + while(LIKELY(p = (hi-lo) >> 1) > 0){ + if(codelist[lo+p] > testword) + hi -= p; + else + lo += p; + } + return lo; +} + STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){ int read=book->dec_maxlength; @@ -222,8 +236,8 @@ STIN long decode_packed_entry_number(codebook *book, long lok = oggpack_look(b,book->dec_firsttablen); if (LIKELY(lok >= 0)) { - long entry = book->dec_firsttable[lok]; - if(UNLIKELY(entry&0x80000000UL)){ + ogg_int32_t entry = book->dec_firsttable[lok]; + if(UNLIKELY(entry < 0)){ lo=(entry>>15)&0x7fff; hi=book->used_entries-(entry&0x7fff); }else{ @@ -247,14 +261,7 @@ STIN long decode_packed_entry_number(codebook *book, /* bisect search for the codeword in the ordered list */ { - ogg_uint32_t testword=bitreverse((ogg_uint32_t)lok); - - while(hi-lo>1){ - long p=(hi-lo)>>1; - long test=book->codelist[lo+p]>testword; - lo+=p&(test-1); - hi-=p&(-test); - } + lo = bisect_codelist(lo, hi, lok, book->codelist); if(book->dec_codelengths[lo]<=read){ oggpack_adv(b, book->dec_codelengths[lo]); @@ -284,7 +291,6 @@ static long decode_packed_block(codebook *book, oggpack_buffer *b, ptr = (ogg_uint32_t *)(adr&~3); bitend = ((adr&3)+b->headend)*8; while (bufptrdec_maxlength)) { if (bit-cachesize+32>=bitend) break; @@ -296,20 +302,10 @@ static long decode_packed_block(codebook *book, oggpack_buffer *b, bit+=32; } - entry=book->dec_firsttable[cache&((1<dec_firsttablen)-1)]; - if(UNLIKELY(entry&0x80000000UL)){ - lo=(entry>>15)&0x7fff; - hi=book->used_entries-(entry&0x7fff); - ogg_uint32_t testword=bitreverse((ogg_uint32_t)cache); - - while(LIKELY(hi-lo>1)){ - long p=(hi-lo)>>1; - if (book->codelist[lo+p]>testword) - hi-=p; - else - lo+=p; - } - entry=lo; + ogg_int32_t entry = book->dec_firsttable[cache&((1<dec_firsttablen)-1)]; + if(UNLIKELY(entry < 0)){ + const long lo = (entry>>15)&0x7fff, hi = book->used_entries-(entry&0x7fff); + entry = bisect_codelist(lo, hi, cache, book->codelist); }else entry--; -- cgit v1.2.3