[x265] [PATCH 5 of 5] cabac: improvement performance by use negative cabac counter

Min Chen chenm003 at 163.com
Tue Oct 22 13:05:46 CEST 2013


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1382439826 -28800
# Node ID 382d51ddce26d669fcdae3bd63afcfd7c9df9847
# Parent  1b6d1eede739c7b33f3fd991ca4409565a893e95
cabac: improvement performance by use negative cabac counter

diff -r 1b6d1eede739 -r 382d51ddce26 source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp
--- a/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp	Tue Oct 22 19:02:51 2013 +0800
+++ b/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp	Tue Oct 22 19:03:46 2013 +0800
@@ -66,7 +66,7 @@
 {
     m_low              = 0;
     m_range            = 510;
-    m_bitsLeft         = 23;
+    m_bitsLeft         = -12;
     m_numBufferedBytes = 0;
     m_bufferedByte     = 0xff;
 }
@@ -81,7 +81,7 @@
         assert(0);
     }
 
-    if (m_low >> (32 - m_bitsLeft))
+    if (m_low >> (21 + m_bitsLeft))
     {
         //assert( m_numBufferedBytes > 0 );
         //assert( m_bufferedByte != 0xff );
@@ -92,7 +92,7 @@
             m_numBufferedBytes--;
         }
 
-        m_low -= 1 << (32 - m_bitsLeft);
+        m_low -= 1 << (21 + m_bitsLeft);
     }
     else
     {
@@ -106,7 +106,7 @@
             m_numBufferedBytes--;
         }
     }
-    m_bitIf->write(m_low >> 8, 24 - m_bitsLeft);
+    m_bitIf->write(m_low >> 8, 13 + m_bitsLeft);
 }
 
 void TEncBinCABAC::flush()
@@ -160,7 +160,7 @@
 void TEncBinCABAC::resetBits()
 {
     m_low              = 0;
-    m_bitsLeft         = 23;
+    m_bitsLeft         = -12;
     m_numBufferedBytes = 0;
     m_bufferedByte     = 0xff;
     m_fracBits        &= 32767;
@@ -200,7 +200,7 @@
         m_range   = lps << numBits;
         ctxModel.updateLPS();
 
-        m_bitsLeft -= numBits;
+        m_bitsLeft += numBits;
     }
     else
     {
@@ -212,7 +212,7 @@
 
         m_low <<= 1;
         m_range <<= 1;
-        m_bitsLeft--;
+        m_bitsLeft++;
     }
 
     testAndWriteOut();
@@ -241,7 +241,7 @@
     {
         m_low += m_range;
     }
-    m_bitsLeft--;
+    m_bitsLeft++;
 
     testAndWriteOut();
 }
@@ -275,14 +275,14 @@
         m_low <<= 8;
         m_low += m_range * pattern;
         binValues -= pattern << numBins;
-        m_bitsLeft -= 8;
+        m_bitsLeft += 8;
 
         testAndWriteOut();
     }
 
     m_low <<= numBins;
     m_low += m_range * binValues;
-    m_bitsLeft -= numBins;
+    m_bitsLeft += numBins;
 
     testAndWriteOut();
 }
@@ -306,7 +306,7 @@
         m_low  += m_range;
         m_low <<= 7;
         m_range = 2 << 7;
-        m_bitsLeft -= 7;
+        m_bitsLeft += 7;
     }
     else if (m_range >= 256)
     {
@@ -316,7 +316,7 @@
     {
         m_low   <<= 1;
         m_range <<= 1;
-        m_bitsLeft--;
+        m_bitsLeft++;
     }
 
     testAndWriteOut();
@@ -324,7 +324,7 @@
 
 void TEncBinCABAC::testAndWriteOut()
 {
-    if (m_bitsLeft < 12)
+    if (m_bitsLeft >= 0)
     {
         writeOut();
     }
@@ -335,10 +335,10 @@
  */
 void TEncBinCABAC::writeOut()
 {
-    UInt leadByte = m_low >> (24 - m_bitsLeft);
+    UInt leadByte = m_low >> (13 + m_bitsLeft);
 
-    m_bitsLeft += 8;
-    m_low &= 0xffffffffu >> m_bitsLeft;
+    m_bitsLeft -= 8;
+    m_low &= 0xffffffffu >> (11 - m_bitsLeft);
 
     if (leadByte == 0xff)
     {



More information about the x265-devel mailing list