[x265] [PATCH 2 of 2] reduce condition jmp in codeCoeffNxN

Min Chen chenm003 at 163.com
Fri Jun 27 02:19:21 CEST 2014


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1403828348 25200
# Node ID 5e91fb51047f650f07579611d720b45c66b30595
# Parent  5bb8cc1ce689c5fc353809662a1af557e4a9e087
reduce condition jmp in codeCoeffNxN

diff -r 5bb8cc1ce689 -r 5e91fb51047f source/Lib/TLibEncoder/TEncSbac.cpp
--- a/source/Lib/TLibEncoder/TEncSbac.cpp	Thu Jun 26 17:18:50 2014 -0700
+++ b/source/Lib/TLibEncoder/TEncSbac.cpp	Thu Jun 26 17:19:08 2014 -0700
@@ -2028,8 +2028,10 @@
 
     X265_CHECK(trSize <= m_slice->getSPS()->getMaxTrSize(), "transform size out of range\n");
 
+    const uint32_t log2TrSize = g_convertToBit[trSize] + 2;
+
     // compute number of significant coefficients
-    uint32_t numSig = primitives.count_nonzero(coeff, trSize * trSize);
+    uint32_t numSig = primitives.count_nonzero(coeff, (1 << (log2TrSize << 1)));
 
 #if CHECKED_BUILD || _DEBUG
     X265_CHECK(numSig > 0, "cbf check fail\n");
@@ -2050,7 +2052,6 @@
     }
 
     ttype = ttype == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA;
-    const uint32_t log2TrSize = g_convertToBit[trSize] + 2;
 
     //select scans
     TUEntropyCodingParameters codingParameters;
@@ -2059,27 +2060,27 @@
     //----- encode significance map -----
 
     // Find position of last coefficient
-    int scanPosLast = -1;
-    int posLast;
+    int scanPosLast = 0;
+    uint32_t posLast;
     uint64_t sigCoeffGroupFlag64 = 0;
-    const uint32_t maskPosXY = (1 << (log2TrSize - MLS_CG_LOG2_SIZE)) - 1;
+    const uint32_t maskPosXY = ((uint32_t)~0 >> (31 - log2TrSize + MLS_CG_LOG2_SIZE)) >> 1;
+    assert(((1 << (log2TrSize - MLS_CG_LOG2_SIZE)) - 1) == (((uint32_t)~0 >> (31 - log2TrSize + MLS_CG_LOG2_SIZE)) >> 1));
     do
     {
-        posLast = codingParameters.scan[++scanPosLast];
-        if (coeff[posLast] != 0)
-        {
-            // get L1 sig map
-            // NOTE: the new algorithm is complicated, so I keep reference code here
-            //uint32_t posy   = posLast >> log2TrSize;
-            //uint32_t posx   = posLast - (posy << log2TrSize);
-            //uint32_t blkIdx0 = ((posy >> MLS_CG_LOG2_SIZE) << codingParameters.log2TrSizeCG) + (posx >> MLS_CG_LOG2_SIZE);
-            uint32_t blkIdx = ((posLast >> (2 * MLS_CG_LOG2_SIZE)) & ~maskPosXY) + ((posLast >> MLS_CG_LOG2_SIZE) & maskPosXY);
-            sigCoeffGroupFlag64 |= ((uint64_t)1 << blkIdx);
+        posLast = codingParameters.scan[scanPosLast++];
 
-            numSig--;
-        }
+        const uint32_t isNZCoeff = (coeff[posLast] != 0);
+        // get L1 sig map
+        // NOTE: the new algorithm is complicated, so I keep reference code here
+        //uint32_t posy   = posLast >> log2TrSize;
+        //uint32_t posx   = posLast - (posy << log2TrSize);
+        //uint32_t blkIdx0 = ((posy >> MLS_CG_LOG2_SIZE) << codingParameters.log2TrSizeCG) + (posx >> MLS_CG_LOG2_SIZE);
+        const uint32_t blkIdx = ((posLast >> (2 * MLS_CG_LOG2_SIZE)) & ~maskPosXY) + ((posLast >> MLS_CG_LOG2_SIZE) & maskPosXY);
+        sigCoeffGroupFlag64 |= ((uint64_t)isNZCoeff << blkIdx);
+        numSig -= isNZCoeff;
     }
     while (numSig > 0);
+    scanPosLast--;
 
     // Code position of last coefficient
     int posLastY = posLast >> log2TrSize;



More information about the x265-devel mailing list