]> git.sesse.net Git - x264/blobdiff - common/bs.h
Faster chroma CBP handling
[x264] / common / bs.h
index afe6b5af7bdd7134ea9d2451f9d2d8ce5d8bc4dd..a090988b11eddb8c36632efe2d03fd33bda7fa86 100644 (file)
@@ -58,7 +58,7 @@ typedef struct
 } x264_run_level_t;
 
 extern const vlc_t x264_coeff0_token[5];
-extern const vlc_t x264_coeff_token[5][16*4];
+extern const vlc_t x264_coeff_token[5][16][4];
 extern const vlc_t x264_total_zeros[15][16];
 extern const vlc_t x264_total_zeros_dc[3][4];
 extern const vlc_t x264_run_before[7][16];
@@ -77,7 +77,7 @@ static inline void bs_init( bs_t *s, void *p_data, int i_data )
     s->p       = s->p_start = (uint8_t*)p_data - offset;
     s->p_end   = (uint8_t*)p_data + i_data;
     s->i_left  = (WORD_SIZE - offset)*8;
-    s->cur_bits = endian_fix32(*(uint32_t *)(s->p));
+    s->cur_bits = endian_fix32( M32(s->p) );
     s->cur_bits >>= (4-offset)*8;
 }
 static inline int bs_pos( bs_t *s )
@@ -92,6 +92,18 @@ static inline void bs_flush( bs_t *s )
     s->p += WORD_SIZE - s->i_left / 8;
     s->i_left = WORD_SIZE*8;
 }
+/* The inverse of bs_flush: prepare the bitstream to be written to again. */
+static inline void bs_realign( bs_t *s )
+{
+    int offset = ((intptr_t)s->p & 3);
+    if( offset )
+    {
+        s->p       = (uint8_t*)s->p - offset;
+        s->i_left  = (WORD_SIZE - offset)*8;
+        s->cur_bits = endian_fix32( M32(s->p) );
+        s->cur_bits >>= (4-offset)*8;
+    }
+}
 
 static inline void bs_write( bs_t *s, int i_count, uint32_t i_bits )
 {
@@ -160,6 +172,11 @@ static inline void bs_align_1( bs_t *s )
     bs_write( s, s->i_left&7, (1 << (s->i_left&7)) - 1 );
     bs_flush( s );
 }
+static inline void bs_align_10( bs_t *s )
+{
+    if( s->i_left&7 )
+        bs_write( s, s->i_left&7, 1 << ( (s->i_left&7) - 1 ) );
+}
 
 /* golomb functions */
 
@@ -240,12 +257,12 @@ static inline void bs_rbsp_trailing( bs_t *s )
     bs_write( s, s->i_left&7, 0  );
 }
 
-static inline int bs_size_ue( unsigned int val )
+static ALWAYS_INLINE int bs_size_ue( unsigned int val )
 {
     return x264_ue_size_tab[val+1];
 }
 
-static inline int bs_size_ue_big( unsigned int val )
+static ALWAYS_INLINE int bs_size_ue_big( unsigned int val )
 {
     if( val < 255 )
         return x264_ue_size_tab[val+1];
@@ -253,7 +270,7 @@ static inline int bs_size_ue_big( unsigned int val )
         return x264_ue_size_tab[(val+1)>>8] + 16;
 }
 
-static inline int bs_size_se( int val )
+static ALWAYS_INLINE int bs_size_se( int val )
 {
     int tmp = 1 - val*2;
     if( tmp < 0 ) tmp = val*2;
@@ -263,7 +280,7 @@ static inline int bs_size_se( int val )
         return x264_ue_size_tab[tmp>>8]+16;
 }
 
-static inline int bs_size_te( int x, int val )
+static ALWAYS_INLINE int bs_size_te( int x, int val )
 {
     if( x == 1 )
         return 1;