]> git.videolan.org Git - x264.git/commitdiff
Remove unpredictable branch in CABAC dqp
authorJason Garrett-Glaser <jason@x264.com>
Thu, 27 Oct 2011 21:05:56 +0000 (14:05 -0700)
committerJason Garrett-Glaser <jason@x264.com>
Thu, 1 Dec 2011 20:27:43 +0000 (12:27 -0800)
encoder/cabac.c

index f3080fea11ad76355ffa6d08438189c23fa2e794..bd4ae8326e0d11e48d613b661a499f4b5c6d4fef 100644 (file)
@@ -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;