[x265] [PATCH 1 of 7] improvement TEncBinCABAC::encodeBin by temporary variant and reduce AND operator

Min Chen chenm003 at 163.com
Mon Mar 24 20:00:38 CET 2014


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1395687461 25200
# Node ID 842aab45735b6b309f6945d4a9f04588ee0e8324
# Parent  fdd7c6168cf42a11240ff1c7fc7b401605524db2
improvement TEncBinCABAC::encodeBin by temporary variant and reduce AND operator

diff -r fdd7c6168cf4 -r 842aab45735b source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp
--- a/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp	Fri Mar 21 14:44:35 2014 -0500
+++ b/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp	Mon Mar 24 11:57:41 2014 -0700
@@ -190,25 +190,30 @@
     }
     ctxModel.bBinsCoded = 1;
 
-    uint32_t mps = sbacGetMps(mstate);
+    uint32_t range = m_range;
     uint32_t state = sbacGetState(mstate);
-    uint32_t lps = g_lpsTable[state][(m_range >> 6) & 3];
-    m_range -= lps;
+    uint32_t lps = g_lpsTable[state][((uint8_t)range >> 6)];
+    range -= lps;
 
-    assert(lps != 0);
+    assert(lps >= 2);
 
-    int numBits = (uint32_t)(m_range - 256) >> 31;
+    int numBits = (uint32_t)(range - 256) >> 31;
     uint32_t low = m_low;
-    uint32_t range = m_range;
-    if (binValue != mps)
+
+    // NOTE: MPS must be LOWEST bit in mstate
+    assert(((binValue ^ mstate) & 1) == (binValue != sbacGetMps(mstate)));
+    if ((binValue ^ mstate) & 1)
     {
         // NOTE: lps is non-zero and the maximum of idx is 8 because lps less than 256
         //numBits   = g_renormTable[lps >> 3];
         unsigned long idx;
         CLZ32(idx, lps);
+        assert(state != 63 || idx == 1);
+
         numBits = 8 - idx;
-        if (numBits >= 6)
+        if (state >= 63)
             numBits = 6;
+        assert(numBits <= 6);
 
         low    += range;
         range   = lps;



More information about the x265-devel mailing list