[x264-devel] Remove unpredictable branch in CABAC dqp

Jason Garrett-Glaser git at videolan.org
Tue Dec 6 01:00:45 CET 2011


x264 | branch: master | Jason Garrett-Glaser <jason at x264.com> | Thu Oct 27 14:05:56 2011 -0700| [04a0aeefd2f5b152c5dbca4a1c6569bd27c9f721] | committer: Jason Garrett-Glaser

Remove unpredictable branch in CABAC dqp

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=04a0aeefd2f5b152c5dbca4a1c6569bd27c9f721
---

 encoder/cabac.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/encoder/cabac.c b/encoder/cabac.c
index f3080fe..bd4ae83 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;



More information about the x264-devel mailing list