[x265] [PATCH 3 of 5] convert for_loop to do_while in codeCoeffNxN(), because all of count are positive

Min Chen chenm003 at 163.com
Tue May 12 01:42:25 CEST 2015


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1431386745 25200
# Node ID d4eda2573100588fb6e32188d592cd648da046e9
# Parent  dae597424faeb2955f85d6af8f10cfde1df781c9
convert for_loop to do_while in codeCoeffNxN(), because all of count are positive
---
 source/encoder/entropy.cpp |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)

diff -r dae597424fae -r d4eda2573100 source/encoder/entropy.cpp
--- a/source/encoder/entropy.cpp	Mon May 11 16:25:42 2015 -0700
+++ b/source/encoder/entropy.cpp	Mon May 11 16:25:45 2015 -0700
@@ -1746,6 +1746,7 @@
         numNonZero = coeffNum[subSet];
         if (numNonZero > 0)
         {
+            uint32_t idx;
             X265_CHECK(subCoeffFlag > 0, "subCoeffFlag is zero\n");
             CLZ(lastNZPosInCG, subCoeffFlag);
             CTZ(firstNZPosInCG, subCoeffFlag);
@@ -1759,9 +1760,12 @@
             c1 = 1;
             uint8_t *baseCtxMod = bIsLuma ? &m_contextState[OFF_ONE_FLAG_CTX + 4 * ctxSet] : &m_contextState[OFF_ONE_FLAG_CTX + NUM_ONE_FLAG_CTX_LUMA + 4 * ctxSet];
 
-            int numC1Flag = X265_MIN(numNonZero, C1FLAG_NUMBER);
+            uint32_t numC1Flag = X265_MIN(numNonZero, C1FLAG_NUMBER);
             int firstC2FlagIdx = -1;
-            for (int idx = 0; idx < numC1Flag; idx++)
+
+            X265_CHECK(numC1Flag > 0, "numC1Flag check failure\n");
+            idx = 0;
+            do
             {
                 uint32_t symbol = absCoeff[idx] > 1;
                 encodeBin(symbol, baseCtxMod[c1]);
@@ -1774,7 +1778,9 @@
                 }
                 else if ((c1 < 3) && (c1 > 0))
                     c1++;
+                idx++;
             }
+            while(idx < numC1Flag);
 
             if (!c1)
             {
@@ -1797,7 +1803,8 @@
                 if (!m_bitIf)
                 {
                     // FastRd path
-                    for (int idx = 0; idx < (int)numNonZero; idx++)
+                    idx = 0;
+                    do
                     {
                         int baseLevel = (baseLevelN & 3) | firstCoeff2;
                         X265_CHECK(baseLevel == ((idx < C1FLAG_NUMBER) ? (2 + firstCoeff2) : 1), "baseLevel check failurr\n");
@@ -1829,12 +1836,15 @@
                         }
                         if (absCoeff[idx] >= 2)
                             firstCoeff2 = 0;
+                        idx++;
                     }
+                    while(idx < numNonZero);
                 }
                 else
                 {
                     // Standard path
-                    for (int idx = 0; idx < (int)numNonZero; idx++)
+                    idx = 0;
+                    do
                     {
                         int baseLevel = (baseLevelN & 3) | firstCoeff2;
                         X265_CHECK(baseLevel == ((idx < C1FLAG_NUMBER) ? (2 + firstCoeff2) : 1), "baseLevel check failurr\n");
@@ -1849,7 +1859,9 @@
                         }
                         if (absCoeff[idx] >= 2)
                             firstCoeff2 = 0;
+                        idx++;
                     }
+                    while(idx < numNonZero);
                 }
             }
         }



More information about the x265-devel mailing list