]> git.sesse.net Git - x264/blobdiff - common/bs.h
Faster 8x8dct+CAVLC interleave
[x264] / common / bs.h
index a30cf3431f09c5818587bf63eb7afe1f8651377b..0765f50aa3ac0b9f2c2f22ce7989e1f13e644292 100644 (file)
@@ -31,6 +31,14 @@ typedef struct
     uint8_t i_size;
 } vlc_t;
 
+typedef struct
+{
+    uint16_t i_bits;
+    uint8_t  i_size;
+    /* Next level table to use */
+    uint8_t  i_next;
+} vlc_large_t;
+
 typedef struct bs_s
 {
     uint8_t *p_start;
@@ -42,10 +50,26 @@ typedef struct bs_s
     int     i_bits_encoded; /* RD only */
 } bs_t;
 
-extern const vlc_t x264_coeff_token[5][17*4];
+typedef struct
+{
+    int     last;
+    int16_t level[16];
+    uint8_t run[16];
+} 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_total_zeros[15][16];
 extern const vlc_t x264_total_zeros_dc[3][4];
-extern const vlc_t x264_run_before[7][15];
+extern const vlc_t x264_run_before[7][16];
+
+/* A larger level table size theoretically could help a bit at extremely
+ * high bitrates, but the cost in cache is usually too high for it to be
+ * useful.
+ * This size appears to be optimal for QP18 encoding on a Nehalem CPU.
+ * FIXME: Do further testing? */
+#define LEVEL_TABLE_SIZE 128
+extern vlc_large_t x264_level_token[7][LEVEL_TABLE_SIZE];
 
 static inline void bs_init( bs_t *s, void *p_data, int i_data )
 {
@@ -76,7 +100,11 @@ static inline void bs_write( bs_t *s, int i_count, uint32_t i_bits )
         s->i_left -= i_count;
         if( s->i_left <= 32 )
         {
+#ifdef WORDS_BIGENDIAN
+            *(uint32_t*)s->p = s->cur_bits >> (32 - s->i_left);
+#else
             *(uint32_t*)s->p = endian_fix( s->cur_bits << s->i_left );
+#endif
             s->i_left += 32;
             s->p += 4;
         }