From 2e1aee80f4e7bd17bfcc5a386f5b879f9e2437bc Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Mon, 9 Oct 2006 20:44:11 +0000 Subject: optimize branchless C CABAC decoder Originally committed as revision 6607 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/cabac.c | 8 ++++++++ libavcodec/cabac.h | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/libavcodec/cabac.c b/libavcodec/cabac.c index 52e6c50e47..f69b100d60 100644 --- a/libavcodec/cabac.c +++ b/libavcodec/cabac.c @@ -133,11 +133,19 @@ void ff_init_cabac_states(CABACContext *c, uint8_t const (*lps_range)[4], c->mps_state[2*i+3]= 2*mps_state[i]+3; if( i ){ +#ifdef BRANCHLESS_CABAD + c->mps_state[-2*i-3]= 2*lps_state[i]+2; //FIXME yes this is not valid C but iam lazy, cleanup welcome + c->mps_state[-2*i-4]= 2*lps_state[i]+3; + }else{ + c->mps_state[-2*i-3]= 3; + c->mps_state[-2*i-4]= 2; +#else c->lps_state[2*i+2]= 2*lps_state[i]+2; c->lps_state[2*i+3]= 2*lps_state[i]+3; }else{ c->lps_state[2*i+2]= 3; c->lps_state[2*i+3]= 2; +#endif } } } diff --git a/libavcodec/cabac.h b/libavcodec/cabac.h index 2f8a8d9fe7..58698b73d1 100644 --- a/libavcodec/cabac.h +++ b/libavcodec/cabac.h @@ -452,7 +452,7 @@ static int get_cabac(CABACContext *c, uint8_t * const state){ int bit, lps_mask attribute_unused; c->range -= RangeLPS; -#if 1 +#ifndef BRANCHLESS_CABAD if(c->low < c->range){ bit= s&1; *state= c->mps_state[s]; @@ -475,8 +475,9 @@ static int get_cabac(CABACContext *c, uint8_t * const state){ c->low -= c->range & lps_mask; c->range += (RangeLPS - c->range) & lps_mask; - bit= (s^lps_mask)&1; - *state= c->mps_state[s - (130&lps_mask)]; + s^=lps_mask; + *state= c->mps_state[s]; + bit= s&1; lps_mask= ff_h264_norm_shift[c->range>>(CABAC_BITS+3)]; c->range<<= lps_mask; -- cgit v1.2.3