changeset 3993:8b7c59b7af01 libavcodec

make state transition tables global as they are constant and the code is slightly faster that way
author michael
date Wed, 11 Oct 2006 14:44:17 +0000
parents a09b5b667229
children 2734b228fc87
files cabac.c cabac.h h264.c
diffstat 3 files changed, 31 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/cabac.c	Wed Oct 11 13:25:29 2006 +0000
+++ b/cabac.c	Wed Oct 11 14:44:17 2006 +0000
@@ -51,8 +51,10 @@
 };
 
 uint8_t ff_h264_lps_range[2*65][4];
+uint8_t ff_h264_lps_state[2*64];
+uint8_t ff_h264_mps_state[2*64];
 
-const uint8_t ff_h264_mps_state[64]= {
+static const uint8_t mps_state[64]= {
   1, 2, 3, 4, 5, 6, 7, 8,
   9,10,11,12,13,14,15,16,
  17,18,19,20,21,22,23,24,
@@ -63,7 +65,7 @@
  57,58,59,60,61,62,62,63,
 };
 
-const uint8_t ff_h264_lps_state[64]= {
+static const uint8_t lps_state[64]= {
   0, 0, 1, 2, 2, 4, 4, 5,
   6, 7, 8, 9, 9,11,11,12,
  13,13,15,15,16,16,18,18,
@@ -121,32 +123,31 @@
     c->range= 0x1FE<<(CABAC_BITS + 1);
 }
 
-void ff_init_cabac_states(CABACContext *c,
-                          uint8_t const *mps_state, uint8_t const *lps_state, int state_count){
+void ff_init_cabac_states(CABACContext *c){
     int i, j;
 
-    for(i=0; i<state_count; i++){
+    for(i=0; i<64; i++){
         for(j=0; j<4; j++){ //FIXME check if this is worth the 1 shift we save
             ff_h264_lps_range[2*i+0][j+4]=
             ff_h264_lps_range[2*i+1][j+4]= lps_range[i][j];
         }
 
-        c->mps_state[2*i+0]= 2*mps_state[i]+0;
-        c->mps_state[2*i+1]= 2*mps_state[i]+1;
+        ff_h264_mps_state[2*i+0]= 2*mps_state[i]+0;
+        ff_h264_mps_state[2*i+1]= 2*mps_state[i]+1;
 
         if( i ){
 #ifdef BRANCHLESS_CABAC_DECODER
-            c->mps_state[-2*i-1]= 2*lps_state[i]+0; //FIXME yes this is not valid C but iam lazy, cleanup welcome
-            c->mps_state[-2*i-2]= 2*lps_state[i]+1;
+            ff_h264_mps_state[-2*i-1]= 2*lps_state[i]+0; //FIXME yes this is not valid C but iam lazy, cleanup welcome
+            ff_h264_mps_state[-2*i-2]= 2*lps_state[i]+1;
         }else{
-            c->mps_state[-2*i-1]= 1;
-            c->mps_state[-2*i-2]= 0;
+            ff_h264_mps_state[-2*i-1]= 1;
+            ff_h264_mps_state[-2*i-2]= 0;
 #else
-            c->lps_state[2*i+0]= 2*lps_state[i]+0;
-            c->lps_state[2*i+1]= 2*lps_state[i]+1;
+            ff_h264_lps_state[2*i+0]= 2*lps_state[i]+0;
+            ff_h264_lps_state[2*i+1]= 2*lps_state[i]+1;
         }else{
-            c->lps_state[2*i+0]= 1;
-            c->lps_state[2*i+1]= 0;
+            ff_h264_lps_state[2*i+0]= 1;
+            ff_h264_lps_state[2*i+1]= 0;
 #endif
         }
     }
--- a/cabac.h	Wed Oct 11 13:25:29 2006 +0000
+++ b/cabac.h	Wed Oct 11 14:44:17 2006 +0000
@@ -41,8 +41,6 @@
 #ifdef STRICT_LIMITS
     int symCount;
 #endif
-    uint8_t lps_state[2*64];      ///< transIdxLPS
-    uint8_t mps_state[2*64];      ///< transIdxMPS
     const uint8_t *bytestream_start;
     const uint8_t *bytestream;
     const uint8_t *bytestream_end;
@@ -50,15 +48,14 @@
 }CABACContext;
 
 extern uint8_t ff_h264_lps_range[2*65][4];  ///< rangeTabLPS
-extern const uint8_t ff_h264_mps_state[64];
-extern const uint8_t ff_h264_lps_state[64];
+extern uint8_t ff_h264_mps_state[2*64];     ///< transIdxMPS
+extern uint8_t ff_h264_lps_state[2*64];     ///< transIdxLPS
 extern const uint8_t ff_h264_norm_shift[128];
 
 
 void ff_init_cabac_encoder(CABACContext *c, uint8_t *buf, int buf_size);
 void ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size);
-void ff_init_cabac_states(CABACContext *c,
-                          uint8_t const *mps_state, uint8_t const *lps_state, int state_count);
+void ff_init_cabac_states(CABACContext *c);
 
 
 static inline void put_cabac_bit(CABACContext *c, int b){
@@ -91,11 +88,11 @@
 
     if(bit == ((*state)&1)){
         c->range -= RangeLPS;
-        *state= c->mps_state[*state];
+        *state= ff_h264_mps_state[*state];
     }else{
         c->low += c->range - RangeLPS;
         c->range = RangeLPS;
-        *state= c->lps_state[*state];
+        *state= ff_h264_lps_state[*state];
     }
 
     renorm_cabac_encoder(c);
@@ -369,11 +366,9 @@
 
 #define LOW          "0"
 #define RANGE        "4"
-#define LPS_STATE   "12"
-#define MPS_STATE   "12+2*64"
-#define BYTESTART   "12+4*64"
-#define BYTE        "16+4*64"
-#define BYTEEND     "20+4*64"
+#define BYTESTART   "12"
+#define BYTE        "16"
+#define BYTEEND     "20"
 #ifndef BRANCHLESS_CABAC_DECODER
     asm volatile(
         "movzbl (%1), %%eax                     \n\t"
@@ -391,7 +386,7 @@
         "setb %%cl                              \n\t"
         "shl %%cl, %%edx                        \n\t"
         "shl %%cl, %%ebx                        \n\t"
-        "movzbl "MPS_STATE"(%2, %%eax), %%ecx   \n\t"
+        "movzbl "MANGLE(ff_h264_mps_state)"(%%eax), %%ecx   \n\t"
         "movb %%cl, (%1)                        \n\t"
 //eax:state ebx:low, edx:range, esi:RangeLPS
         "test %%bx, %%bx                        \n\t"
@@ -413,7 +408,7 @@
         "movzbl " MANGLE(ff_h264_norm_shift) "(%%esi), %%ecx   \n\t"
         "shll %%cl, %%ebx                       \n\t"
         "shll %%cl, %%edx                       \n\t"
-        "movzbl "LPS_STATE"(%2, %%eax), %%ecx   \n\t"
+        "movzbl "MANGLE(ff_h264_lps_state)"(%%eax), %%ecx   \n\t"
         "movb %%cl, (%1)                        \n\t"
         "addl $1, %%eax                         \n\t"
         "test %%bx, %%bx                        \n\t"
@@ -475,7 +470,7 @@
 #endif
 
 //eax:state ebx:low edx:mask esi:range
-        "movzbl "MPS_STATE"(%2, %%eax), %%ecx   \n\t"
+        "movzbl "MANGLE(ff_h264_mps_state)"(%%eax), %%ecx   \n\t"
         "movb %%cl, (%1)                        \n\t"
 
         "movl %%esi, %%edx                      \n\t"
@@ -523,12 +518,12 @@
 #ifndef BRANCHLESS_CABAC_DECODER
     if(c->low < c->range){
         bit= s&1;
-        *state= c->mps_state[s];
+        *state= ff_h264_mps_state[s];
         renorm_cabac_decoder_once(c);
     }else{
         bit= ff_h264_norm_shift[RangeLPS>>19];
         c->low -= c->range;
-        *state= c->lps_state[s];
+        *state= ff_h264_lps_state[s];
         c->range = RangeLPS<<bit;
         c->low <<= bit;
         bit= (s&1)^1;
@@ -544,7 +539,7 @@
     c->range += (RangeLPS - c->range) & lps_mask;
 
     s^=lps_mask;
-    *state= c->mps_state[s];
+    *state= ff_h264_mps_state[s];
     bit= s&1;
 
     lps_mask= ff_h264_norm_shift[c->range>>(CABAC_BITS+3)];
--- a/h264.c	Wed Oct 11 13:25:29 2006 +0000
+++ b/h264.c	Wed Oct 11 14:44:17 2006 +0000
@@ -7388,7 +7388,7 @@
         align_get_bits( &s->gb );
 
         /* init cabac */
-        ff_init_cabac_states( &h->cabac, ff_h264_mps_state, ff_h264_lps_state, 64 );
+        ff_init_cabac_states( &h->cabac);
         ff_init_cabac_decoder( &h->cabac,
                                s->gb.buffer + get_bits_count(&s->gb)/8,
                                ( s->gb.size_in_bits - get_bits_count(&s->gb) + 7)/8);