From 04a0aeefd2f5b152c5dbca4a1c6569bd27c9f721 Mon Sep 17 00:00:00 2001 From: Jason Garrett-Glaser Date: Thu, 27 Oct 2011 14:05:56 -0700 Subject: [PATCH] Remove unpredictable branch in CABAC dqp --- encoder/cabac.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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; -- 2.47.3