diff common.h @ 192:1e5f64be86fc libavcodec

another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
author uid46427
date Thu, 10 Jan 2002 00:56:05 +0000
parents ae0516eadae2
children b691dd3e9088
line wrap: on
line diff
--- a/common.h	Thu Jan 10 00:53:21 2002 +0000
+++ b/common.h	Thu Jan 10 00:56:05 2002 +0000
@@ -8,6 +8,8 @@
 #define CONFIG_WIN32
 #endif
 
+//#define ALT_BITSTREAM_READER
+
 #ifdef HAVE_AV_CONFIG_H
 /* only include the following when compiling package */
 #include "../config.h"
@@ -124,6 +126,7 @@
 
 #endif /* !CONFIG_WIN32 */
 
+
 /* debug stuff */
 #ifdef HAVE_AV_CONFIG_H
 
@@ -180,9 +183,14 @@
 /* bit input */
 
 typedef struct GetBitContext {
+#ifdef ALT_BITSTREAM_READER
+    int index;
+    UINT8 *buffer;
+#else
     UINT32 bit_buf;
     int bit_cnt;
     UINT8 *buf, *buf_ptr, *buf_end;
+#endif
 } GetBitContext;
 
 typedef struct VLC {
@@ -195,10 +203,23 @@
 void init_get_bits(GetBitContext *s, 
                    UINT8 *buffer, int buffer_size);
 
+#ifndef ALT_BITSTREAM_READER
 unsigned int get_bits_long(GetBitContext *s, int n);
 unsigned int show_bits_long(GetBitContext *s, int n);
+#endif
 
 static inline unsigned int get_bits(GetBitContext *s, int n){
+#ifdef ALT_BITSTREAM_READER
+    int index= s->index;
+    uint32_t result= be2me_32( *(uint32_t *)(((uint8_t *)s->buffer)+(index>>3)) );
+
+    result<<= (index&0x07);
+    result>>= 32 - n;
+    index+= n;
+    s->index= index;
+    
+    return result;
+#else
     if(s->bit_cnt>=n){
         /* most common case here */
         unsigned int val = s->bit_buf >> (32 - n);
@@ -210,9 +231,21 @@
 	return val;
     }
     return get_bits_long(s,n);
+#endif
 }
 
 static inline unsigned int get_bits1(GetBitContext *s){
+#ifdef ALT_BITSTREAM_READER
+    int index= s->index;
+    uint32_t result= be2me_32( *(uint32_t *)(((uint8_t *)s->buffer)+(index>>3)) );
+
+    result<<= (index&0x07);
+    result>>= 32 - 1;
+    index++;
+    s->index= index;
+    
+    return result;
+#else
     if(s->bit_cnt>0){
         /* most common case here */
         unsigned int val = s->bit_buf >> 31;
@@ -224,6 +257,7 @@
 	return val;
     }
     return get_bits_long(s,1);
+#endif
 }
 
 /* This function is identical to get_bits(), the only */
@@ -231,15 +265,28 @@
 /* it is usefull to see the buffer.                   */
 static inline unsigned int show_bits(GetBitContext *s, int n)
 {
+#ifdef ALT_BITSTREAM_READER
+    int index= s->index;
+    uint32_t result= be2me_32( *(uint32_t *)(((uint8_t *)s->buffer)+(index>>3)) );
+
+    result<<= (index&0x07);
+    result>>= 32 - n;
+    
+    return result;
+#else
     if(s->bit_cnt>=n) {
         /* most common case here */
         unsigned int val = s->bit_buf >> (32 - n);
         return val;
     }
     return show_bits_long(s,n);
+#endif
 }
 
 static inline void skip_bits(GetBitContext *s, int n){
+#ifdef ALT_BITSTREAM_READER
+    s->index+= n;
+#else
     if(s->bit_cnt>=n){
         /* most common case here */
         s->bit_buf <<= n;
@@ -250,9 +297,13 @@
     } else {
 	get_bits_long(s,n);
     }
+#endif
 }
 
 static inline void skip_bits1(GetBitContext *s){
+#ifdef ALT_BITSTREAM_READER
+    s->index++;
+#else
     if(s->bit_cnt>0){
         /* most common case here */
         s->bit_buf <<= 1;
@@ -263,11 +314,16 @@
     } else {
 	get_bits_long(s,1);
     }
+#endif
 }
 
 static inline int get_bits_count(GetBitContext *s)
 {
+#ifdef ALT_BITSTREAM_READER
+    return s->index;
+#else
     return (s->buf_ptr - s->buf) * 8 - s->bit_cnt;
+#endif
 }
 
 void align_get_bits(GetBitContext *s);
@@ -277,6 +333,13 @@
 void free_vlc(VLC *vlc);
 int get_vlc(GetBitContext *s, 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) ;
+#else
+
 /* macro to go faster */
 /* n must be <= 24 */
 /* XXX: optimize buffer end test */
@@ -317,7 +380,7 @@
     (s)->bit_buf = bit_buf;\
     (s)->bit_cnt = bit_cnt;\
 }
-
+#endif // !ALT_BITSTREAM_READER
 /* define it to include statistics code (useful only for optimizing
    codec efficiency */
 //#define STATS