changeset 199:0f1dba8fc617 libavcodec

(commited by michael / arpi was crazy enough to give me his password) fixed a bug in get_vlc() when using the ALT_BITSTREAM_READER (rv10 & mpeg12 decoders where not working) some optimizations replaced a if() with a >> changed get_bits1() a bit so it hopefully is faster on p4
author arpi_esp
date Sat, 12 Jan 2002 20:21:51 +0000
parents 82ba367b1827
children 6ab301aaa652
files common.h
diffstat 1 files changed, 38 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/common.h	Sat Jan 12 14:36:40 2002 +0000
+++ b/common.h	Sat Jan 12 20:21:51 2002 +0000
@@ -10,6 +10,7 @@
 
 //#define ALT_BITSTREAM_READER
 //#define ALIGNED_BITSTREAM
+#define FAST_GET_FIRST_VLC
 
 #ifdef HAVE_AV_CONFIG_H
 /* only include the following when compiling package */
@@ -244,8 +245,8 @@
 	 : "0" (result1), "r" (result2), "c" (index));
 #else
     result1<<= (index&0x1F);
-    result2>>= 32-(index&0x1F);
-    if((index&0x1F)!=0) result1|= result2;
+    result2= (result2>>1) >> (31-(index&0x1F));
+    result1|= result2;
 #endif
     result1>>= 32 - n;
     index+= n;
@@ -282,8 +283,8 @@
 #ifdef ALT_BITSTREAM_READER
     int index= s->index;
     uint8_t result= s->buffer[ index>>3 ];
-    result>>= 7-(index&0x07);
-    result&=1;
+    result<<= (index&0x07);
+    result>>= 8 - 1;
     index++;
     s->index= index;
     
@@ -319,8 +320,8 @@
 	 : "0" (result1), "r" (result2), "c" (index));
 #else
     result1<<= (index&0x1F);
-    result2>>= 32-(index&0x1F);
-    if((index&0x1F)!=0) result1|= result2;
+    result2= (result2>>1) >> (31-(index&0x1F));
+    result1|= result2;
 #endif
     result1>>= 32 - n;
     
@@ -394,10 +395,33 @@
 void free_vlc(VLC *vlc);
 
 #ifdef ALT_BITSTREAM_READER
-#define SHOW_BITS(s, val, n) val= show_bits(s, n);
-#define FLUSH_BITS(n) skip_bits(s, n); 
-#define SAVE_BITS(s) ;
-#define RESTORE_BITS(s) ;
+#ifdef ALIGNED_BITSTREAM
+#ifdef ARCH_X86
+#define SHOW_BITS(s, val, n) \
+    val= be2me_32( ((uint32_t *)(s)->buffer)[bit_cnt>>5] );\
+    {uint32_t result2= be2me_32( ((uint32_t *)(s)->buffer)[(bit_cnt>>5) + 1] );\
+    asm ("shldl %%cl, %2, %0\n\t"\
+         : "=r" (val)\
+         : "0" (val), "r" (result2), "c" (bit_cnt));\
+    ((uint32_t)val)>>= 32 - n;}
+#else //ARCH_X86
+#define SHOW_BITS(s, val, n) \
+    val= be2me_32( ((uint32_t *)(s)->buffer)[bit_cnt>>5] );\
+    {uint32_t result2= be2me_32( ((uint32_t *)(s)->buffer)[(bit_cnt>>5) + 1] );\
+    val<<= (bit_cnt&0x1F);\
+    result2= (result2>>1) >> (31-(bit_cnt&0x1F));\
+    val|= result2;\
+    ((uint32_t)val)>>= 32 - n;}
+#endif //!ARCH_X86
+#else //ALIGNED_BITSTREAM
+#define SHOW_BITS(s, val, n) \
+    val= be2me_32( unaligned32( ((uint8_t *)(s)->buffer)+(bit_cnt>>3) ) );\
+    val<<= (bit_cnt&0x07);\
+    ((uint32_t)val)>>= 32 - n;
+#endif // !ALIGNED_BITSTREAM
+#define FLUSH_BITS(n) bit_cnt+=n; 
+#define SAVE_BITS(s) bit_cnt= (s)->index;
+#define RESTORE_BITS(s) (s)->index= bit_cnt;
 #else
 
 /* macro to go faster */
@@ -447,8 +471,8 @@
     int code, n, nb_bits, index;
     INT16 *table_codes;
     INT8 *table_bits;
+    int bit_cnt;
 #ifndef ALT_BITSTREAM_READER
-    int bit_cnt;
     UINT32 bit_buf;
     UINT8 *buf_ptr;
 #endif
@@ -457,7 +481,8 @@
     nb_bits = vlc->bits;
     table_codes = vlc->table_codes;
     table_bits = vlc->table_bits;
-    
+
+#ifdef FAST_GET_FIRST_VLC
     SHOW_BITS(s, index, nb_bits);
     code = table_codes[index];
     n = table_bits[index];
@@ -474,6 +499,7 @@
         table_codes = vlc->table_codes + code;
         table_bits = vlc->table_bits + code;
     }
+#endif
     for(;;) {
         SHOW_BITS(s, index, nb_bits);
         code = table_codes[index];