From: Fiona Glaser Date: Sat, 16 May 2009 03:07:59 +0000 (-0700) Subject: Faster signed golomb coding X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=39f9a29f31293098fceed3e7d07bc860bc03b6ad;p=libx264 Faster signed golomb coding 3% faster CAVLC RDO and bitstream writing. --- diff --git a/common/bs.h b/common/bs.h index 254dbce0..68b9f5e3 100644 --- a/common/bs.h +++ b/common/bs.h @@ -219,7 +219,12 @@ static inline void bs_write_ue( bs_t *s, int val ) static inline void bs_write_se( bs_t *s, int val ) { int size = 0; - int tmp = val = val <= 0 ? -val*2+1 : val*2; + /* Faster than (val <= 0 ? -val*2+1 : val*2) */ + /* 4 instructions on x86, 3 on ARM */ + int tmp = 1 - val*2; + if( tmp < 0 ) tmp = val*2; + val = tmp; + if( tmp >= 0x100 ) { size = 16; @@ -258,7 +263,12 @@ static inline int bs_size_ue_big( unsigned int val ) static inline int bs_size_se( int val ) { - return bs_size_ue_big( val <= 0 ? -val*2 : val*2-1 ); + int tmp = 1 - val*2; + if( tmp < 0 ) tmp = val*2; + if( tmp < 256 ) + return x264_ue_size_tab[tmp]; + else + return x264_ue_size_tab[tmp>>8]+16; } static inline int bs_size_te( int x, int val )