[FFmpeg-devel] [PATCH 4/4] h264: get rid of the additional helper pointers for the cabac tables

Roland Scheidegger rscheidegger_lists at hispeed.ch
Fri Apr 27 03:26:21 CEST 2012


Actually scratch this one. There's a better way to achieve this.

Roland

Am 27.04.2012 02:47, schrieb Roland Scheidegger:
> Just use offsets directly instead. This lets gcc generate better code with
> only a minor ugliness increase.
> In particular the c code should be as efficient as before the single table
> was introduced for non-pic case, and better for pic case (the latter verified,
> though only for get_cabac_noinline, as it's possible for the inline case gcc
> is able to hold all table addresses in registers anyway). Well at least better
> for x86 that is.
> ---
>  libavcodec/cabac.c           |    7 +++----
>  libavcodec/cabac_functions.h |   11 ++++-------
>  libavcodec/h264_cabac.c      |    5 ++---
>  3 files changed, 9 insertions(+), 14 deletions(-)
> 
> diff --git a/libavcodec/cabac.c b/libavcodec/cabac.c
> index 539ea32..5b4d459 100644
> --- a/libavcodec/cabac.c
> +++ b/libavcodec/cabac.c
> @@ -54,10 +54,9 @@ uint8_t ff_h264_cabac_tables[512 + 4*2*64 + 4*64 + 63] = {
>   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
>  };
>  
> -uint8_t * const ff_h264_norm_shift = ff_h264_cabac_tables + H264_NORM_SHIFT_OFFSET;
> -uint8_t * const ff_h264_lps_range = ff_h264_cabac_tables + H264_LPS_RANGE_OFFSET;
> -uint8_t * const ff_h264_mlps_state = ff_h264_cabac_tables + H264_MLPS_STATE_OFFSET;
> -uint8_t * const ff_h264_last_coeff_flag_offset_8x8 = ff_h264_cabac_tables + H264_LAST_COEFF_FLAG_OFFSET_8x8_OFFSET;
> +static uint8_t * const ff_h264_lps_range = ff_h264_cabac_tables + H264_LPS_RANGE_OFFSET;
> +static uint8_t * const ff_h264_mlps_state = ff_h264_cabac_tables + H264_MLPS_STATE_OFFSET;
> +static uint8_t * const ff_h264_last_coeff_flag_offset_8x8 = ff_h264_cabac_tables + H264_LAST_COEFF_FLAG_OFFSET_8x8_OFFSET;
>  
>  static const uint8_t lps_range[64][4]= {
>  {128,176,208,240}, {128,167,197,227}, {128,158,187,216}, {123,150,178,205},
> diff --git a/libavcodec/cabac_functions.h b/libavcodec/cabac_functions.h
> index 9db365e..db40b2c 100644
> --- a/libavcodec/cabac_functions.h
> +++ b/libavcodec/cabac_functions.h
> @@ -36,9 +36,6 @@
>  #   include "x86/cabac.h"
>  #endif
>  
> -extern uint8_t * const ff_h264_norm_shift;
> -extern uint8_t * const ff_h264_mlps_state;
> -extern uint8_t * const ff_h264_lps_range;  ///< rangeTabLPS
>  extern uint8_t ff_h264_cabac_tables[512 + 4*2*64 + 4*64 + 63];
>  
>  static void refill(CABACContext *c){
> @@ -64,7 +61,7 @@ static void refill2(CABACContext *c){
>      int i, x;
>  
>      x= c->low ^ (c->low-1);
> -    i= 7 - ff_h264_norm_shift[x>>(CABAC_BITS-1)];
> +    i= 7 - (ff_h264_cabac_tables+H264_NORM_SHIFT_OFFSET)[x>>(CABAC_BITS-1)];
>  
>      x= -CABAC_MASK;
>  
> @@ -80,7 +77,7 @@ static void refill2(CABACContext *c){
>  
>  static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const state){
>      int s = *state;
> -    int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + s];
> +    int RangeLPS= (ff_h264_cabac_tables+H264_LPS_RANGE_OFFSET)[2*(c->range&0xC0) + s];
>      int bit, lps_mask;
>  
>      c->range -= RangeLPS;
> @@ -90,10 +87,10 @@ static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const st
>      c->range += (RangeLPS - c->range) & lps_mask;
>  
>      s^=lps_mask;
> -    *state= (ff_h264_mlps_state+128)[s];
> +    *state= (ff_h264_cabac_tables+H264_MLPS_STATE_OFFSET+128)[s];
>      bit= s&1;
>  
> -    lps_mask= ff_h264_norm_shift[c->range];
> +    lps_mask= (ff_h264_cabac_tables+H264_NORM_SHIFT_OFFSET)[c->range];
>      c->range<<= lps_mask;
>      c->low  <<= lps_mask;
>      if(!(c->low & CABAC_MASK))
> diff --git a/libavcodec/h264_cabac.c b/libavcodec/h264_cabac.c
> index 7b5b128..5488bf6 100644
> --- a/libavcodec/h264_cabac.c
> +++ b/libavcodec/h264_cabac.c
> @@ -1561,8 +1561,6 @@ static av_always_inline int get_cabac_cbf_ctx( H264Context *h, int cat, int idx,
>      return base_ctx[cat] + ctx;
>  }
>  
> -extern uint8_t * const ff_h264_last_coeff_flag_offset_8x8;
> -
>  static av_always_inline void
>  decode_cabac_residual_internal(H264Context *h, DCTELEM *block,
>                                 int cat, int n, const uint8_t *scantable,
> @@ -1665,7 +1663,8 @@ decode_cabac_residual_internal(H264Context *h, DCTELEM *block,
>                                                   last_coeff_ctx_base-significant_coeff_ctx_base);
>          }
>  #else
> -        DECODE_SIGNIFICANCE( 63, sig_off[last], ff_h264_last_coeff_flag_offset_8x8[last] );
> +        DECODE_SIGNIFICANCE( 63, sig_off[last],
> +                             (ff_h264_cabac_tables+H264_LAST_COEFF_FLAG_OFFSET_8x8_OFFSET)[last] );
>      } else {
>          if (is_dc && chroma422) { // dc 422
>              DECODE_SIGNIFICANCE(7, sig_coeff_offset_dc[last], sig_coeff_offset_dc[last]);



More information about the ffmpeg-devel mailing list