From: Jason Garrett-Glaser Date: Thu, 27 Oct 2011 21:05:56 +0000 (-0700) Subject: Remove unpredictable branch in CABAC dqp X-Git-Url: http://www.zmx.ovh/git.videolan.org/?a=commitdiff_plain;h=04a0aeefd2f5b152c5dbca4a1c6569bd27c9f721;p=x264.git Remove unpredictable branch in CABAC dqp --- diff --git a/encoder/cabac.c b/encoder/cabac.c index f3080fea..bd4ae832 100644 --- a/encoder/cabac.c +++ b/encoder/cabac.c @@ -167,7 +167,12 @@ static void x264_cabac_qp_delta( x264_t *h, x264_cabac_t *cb ) if( i_dqp != 0 ) { - int val = i_dqp <= 0 ? (-2*i_dqp) : (2*i_dqp - 1); + /* Faster than (i_dqp <= 0 ? (-2*i_dqp) : (2*i_dqp-1)). + * If you so much as sneeze on these lines, gcc will compile this suboptimally. */ + i_dqp *= 2; + int val = 1 - i_dqp; + if( val < 0 ) val = i_dqp; + val--; /* dqp is interpreted modulo (QP_MAX_SPEC+1) */ if( val >= QP_MAX_SPEC && val != QP_MAX_SPEC+1 ) val = 2*QP_MAX_SPEC+1 - val;