Speed up VP8DX_BOOL_DECODER_FILL
authorJohn Koleszar <jkoleszar@google.com>
Tue, 26 Apr 2011 16:52:17 +0000 (12:52 -0400)
committerJohn Koleszar <jkoleszar@google.com>
Wed, 27 Apr 2011 14:25:03 +0000 (10:25 -0400)
The end-of-buffer check is hoisted out of the inner loop. Gives
about 0.5% improvement on x86_64.

Change-Id: I8e3ed08af7d33468c5c749af36c2dfa19677f971

vp8/decoder/dboolhuff.h

index b217b14..5f6b211 100644 (file)
@@ -51,19 +51,26 @@ void vp8dx_bool_decoder_fill(BOOL_DECODER *br);
 #define VP8DX_BOOL_DECODER_FILL(_count,_value,_bufptr,_bufend) \
     do \
     { \
-        int shift; \
-        for(shift = VP8_BD_VALUE_SIZE - 8 - ((_count) + 8); shift >= 0; ) \
+        int shift = VP8_BD_VALUE_SIZE - 8 - ((_count) + 8); \
+        int loop_end, x; \
+        size_t bits_left = ((_bufend)-(_bufptr))*CHAR_BIT; \
+        \
+        x = shift + CHAR_BIT - bits_left; \
+        loop_end = 0; \
+        if(x >= 0) \
         { \
-            if((_bufptr) >= (_bufend)) { \
-                (_count) += VP8_LOTS_OF_BITS; \
-                break; \
-            } \
-            (_count) += 8; \
+            (_count) += VP8_LOTS_OF_BITS; \
+            loop_end = x; \
+            if(!bits_left) break; \
+        } \
+        while(shift >= loop_end) \
+        { \
+            (_count) += CHAR_BIT; \
             (_value) |= (VP8_BD_VALUE)*(_bufptr)++ << shift; \
-            shift -= 8; \
+            shift -= CHAR_BIT; \
         } \
     } \
-    while(0)
+    while(0) \
 
 
 static int vp8dx_decode_bool(BOOL_DECODER *br, int probability) {