changeset 3991:72bae00a317f libavcodec

make lps_range a global table its constant anyway (saves 1 addition for accessing it)
author michael
date Wed, 11 Oct 2006 13:21:42 +0000
parents 746a60ba3177
children a09b5b667229
files cabac.c cabac.h h264.c
diffstat 3 files changed, 18 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/cabac.c	Wed Oct 11 12:23:40 2006 +0000
+++ b/cabac.c	Wed Oct 11 13:21:42 2006 +0000
@@ -31,7 +31,7 @@
 #include "bitstream.h"
 #include "cabac.h"
 
-const uint8_t ff_h264_lps_range[64][4]= {
+static const uint8_t lps_range[64][4]= {
 {128,176,208,240}, {128,167,197,227}, {128,158,187,216}, {123,150,178,205},
 {116,142,169,195}, {111,135,160,185}, {105,128,152,175}, {100,122,144,166},
 { 95,116,137,158}, { 90,110,130,150}, { 85,104,123,142}, { 81, 99,117,135},
@@ -50,6 +50,8 @@
 {  6,  8,  9, 11}, {  6,  7,  9, 10}, {  6,  7,  8,  9}, {  2,  2,  2,  2},
 };
 
+uint8_t ff_h264_lps_range[2*65][4];
+
 const uint8_t ff_h264_mps_state[64]= {
   1, 2, 3, 4, 5, 6, 7, 8,
   9,10,11,12,13,14,15,16,
@@ -119,14 +121,14 @@
     c->range= 0x1FE<<(CABAC_BITS + 1);
 }
 
-void ff_init_cabac_states(CABACContext *c, uint8_t const (*lps_range)[4],
+void ff_init_cabac_states(CABACContext *c,
                           uint8_t const *mps_state, uint8_t const *lps_state, int state_count){
     int i, j;
 
     for(i=0; i<state_count; i++){
         for(j=0; j<4; j++){ //FIXME check if this is worth the 1 shift we save
-            c->lps_range[2*i+0][j+4]=
-            c->lps_range[2*i+1][j+4]= lps_range[i][j];
+            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;
--- a/cabac.h	Wed Oct 11 12:23:40 2006 +0000
+++ b/cabac.h	Wed Oct 11 13:21:42 2006 +0000
@@ -41,7 +41,6 @@
 #ifdef STRICT_LIMITS
     int symCount;
 #endif
-    uint8_t lps_range[2*65][4];   ///< rangeTabLPS
     uint8_t lps_state[2*64];      ///< transIdxLPS
     uint8_t mps_state[2*64];      ///< transIdxMPS
     const uint8_t *bytestream_start;
@@ -50,7 +49,7 @@
     PutBitContext pb;
 }CABACContext;
 
-extern const uint8_t ff_h264_lps_range[64][4];
+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 const uint8_t ff_h264_norm_shift[128];
@@ -58,7 +57,7 @@
 
 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 (*lps_range)[4],
+void ff_init_cabac_states(CABACContext *c,
                           uint8_t const *mps_state, uint8_t const *lps_state, int state_count);
 
 
@@ -88,7 +87,7 @@
 }
 
 static void put_cabac(CABACContext *c, uint8_t * const state, int bit){
-    int RangeLPS= c->lps_range[*state][c->range>>6];
+    int RangeLPS= ff_h264_lps_range[*state][c->range>>6];
 
     if(bit == ((*state)&1)){
         c->range -= RangeLPS;
@@ -370,20 +369,18 @@
 
 #define LOW          "0"
 #define RANGE        "4"
-#define LPS_RANGE   "12"
-#define LPS_STATE   "12+2*65*4"
-#define MPS_STATE   "12+2*65*4+2*64"
-#define BYTESTART   "12+2*65*4+4*64"
-#define BYTE        "16+2*65*4+4*64"
-#define BYTEEND     "20+2*65*4+4*64"
+#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"
 #ifndef BRANCHLESS_CABAC_DECODER
     asm volatile(
         "movzbl (%1), %%eax                     \n\t"
         "movl "RANGE    "(%2), %%ebx            \n\t"
         "movl "RANGE    "(%2), %%edx            \n\t"
         "shrl $23, %%ebx                        \n\t"
-        "leal "LPS_RANGE"(%2, %%eax, 4), %%esi  \n\t"
-        "movzbl (%%ebx, %%esi), %%esi           \n\t"
+        "movzbl ff_h264_lps_range(%%ebx, %%eax, 4), %%esi\n\t"
         "shll $17, %%esi                        \n\t"
         "movl "LOW      "(%2), %%ebx            \n\t"
 //eax:state ebx:low, edx:range, esi:RangeLPS
@@ -453,8 +450,7 @@
         "movl "RANGE    "(%2), %%ebx            \n\t"
         "movl "RANGE    "(%2), %%edx            \n\t"
         "shrl $23, %%ebx                        \n\t"
-        "leal "LPS_RANGE"(%2, %%eax, 4), %%esi  \n\t"
-        "movzbl (%%ebx, %%esi), %%esi           \n\t"
+        "movzbl ff_h264_lps_range(%%ebx, %%eax, 4), %%esi\n\t"
         "shll $17, %%esi                        \n\t"
         "movl "LOW      "(%2), %%ebx            \n\t"
 //eax:state ebx:low, edx:range, esi:RangeLPS
@@ -520,7 +516,7 @@
 #endif
 #else
     int s = *state;
-    int RangeLPS= c->lps_range[s][c->range>>(CABAC_BITS+7)]<<(CABAC_BITS+1);
+    int RangeLPS= ff_h264_lps_range[s][c->range>>(CABAC_BITS+7)]<<(CABAC_BITS+1);
     int bit, lps_mask attribute_unused;
 
     c->range -= RangeLPS;
--- a/h264.c	Wed Oct 11 12:23:40 2006 +0000
+++ b/h264.c	Wed Oct 11 13:21:42 2006 +0000
@@ -7388,7 +7388,7 @@
         align_get_bits( &s->gb );
 
         /* init cabac */
-        ff_init_cabac_states( &h->cabac, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64 );
+        ff_init_cabac_states( &h->cabac, ff_h264_mps_state, ff_h264_lps_state, 64 );
         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);