1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Nils Wallménius 2010-07-01 20:31:07 +00:00
parent a54bfaa69e
commit 01f91ed14d

View file

@ -215,6 +215,20 @@ static inline ogg_uint32_t bitreverse(register ogg_uint32_t x)
return ret; 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, STIN long decode_packed_entry_number(codebook *book,
oggpack_buffer *b){ oggpack_buffer *b){
int read=book->dec_maxlength; 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); long lok = oggpack_look(b,book->dec_firsttablen);
if (LIKELY(lok >= 0)) { if (LIKELY(lok >= 0)) {
long entry = book->dec_firsttable[lok]; ogg_int32_t entry = book->dec_firsttable[lok];
if(UNLIKELY(entry&0x80000000UL)){ if(UNLIKELY(entry < 0)){
lo=(entry>>15)&0x7fff; lo=(entry>>15)&0x7fff;
hi=book->used_entries-(entry&0x7fff); hi=book->used_entries-(entry&0x7fff);
}else{ }else{
@ -247,14 +261,7 @@ STIN long decode_packed_entry_number(codebook *book,
/* bisect search for the codeword in the ordered list */ /* bisect search for the codeword in the ordered list */
{ {
ogg_uint32_t testword=bitreverse((ogg_uint32_t)lok); lo = bisect_codelist(lo, hi, lok, book->codelist);
while(hi-lo>1){
long p=(hi-lo)>>1;
long test=book->codelist[lo+p]>testword;
lo+=p&(test-1);
hi-=p&(-test);
}
if(book->dec_codelengths[lo]<=read){ if(book->dec_codelengths[lo]<=read){
oggpack_adv(b, book->dec_codelengths[lo]); 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); ptr = (ogg_uint32_t *)(adr&~3);
bitend = ((adr&3)+b->headend)*8; bitend = ((adr&3)+b->headend)*8;
while (bufptr<bufend){ while (bufptr<bufend){
long entry, lo, hi;
if (UNLIKELY(cachesize<book->dec_maxlength)) { if (UNLIKELY(cachesize<book->dec_maxlength)) {
if (bit-cachesize+32>=bitend) if (bit-cachesize+32>=bitend)
break; break;
@ -296,20 +302,10 @@ static long decode_packed_block(codebook *book, oggpack_buffer *b,
bit+=32; bit+=32;
} }
entry=book->dec_firsttable[cache&((1<<book->dec_firsttablen)-1)]; ogg_int32_t entry = book->dec_firsttable[cache&((1<<book->dec_firsttablen)-1)];
if(UNLIKELY(entry&0x80000000UL)){ if(UNLIKELY(entry < 0)){
lo=(entry>>15)&0x7fff; const long lo = (entry>>15)&0x7fff, hi = book->used_entries-(entry&0x7fff);
hi=book->used_entries-(entry&0x7fff); entry = bisect_codelist(lo, hi, cache, book->codelist);
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;
}else }else
entry--; entry--;