From 0e050663d16cd5b095723bd00136873aa461d5cd Mon Sep 17 00:00:00 2001 From: Jason Garrett-Glaser Date: Fri, 15 May 2009 20:07:59 -0700 Subject: [PATCH] Faster signed golomb coding 3% faster CAVLC RDO and bitstream writing. --- common/bs.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/common/bs.h b/common/bs.h index e36549e6..eafa8f8f 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 ) -- 2.47.3