summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorNils Wallménius <nils@rockbox.org>2010-07-01 20:31:07 +0000
committerNils Wallménius <nils@rockbox.org>2010-07-01 20:31:07 +0000
commit01f91ed14d197747f489064d28b6a7ace80ebce6 (patch)
tree9826508e82c101c82986adf40b15be492f5e9f29 /apps
parenta54bfaa69e33b22e8c872298103c5f07d4d59dc5 (diff)
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
Diffstat (limited to 'apps')
-rw-r--r--apps/codecs/libtremor/codebook.c46
1 files changed, 21 insertions, 25 deletions
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 (bufptr<bufend){
- long entry, lo, hi;
if (UNLIKELY(cachesize<book->dec_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<<book->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<<book->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--;