[x265] [PATCH 7 of 8] simplify logic in hideSign loop

Min Chen chenm003 at 163.com
Thu Oct 1 02:48:47 CEST 2015


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1443652351 18000
# Node ID aa62ce092d1b34cb7037b3d884136d4d647d13a9
# Parent  a5e7873453965678532178544c7e31357e205e7a
simplify logic in hideSign loop
---
 source/common/quant.cpp |   22 ++++++++++++----------
 1 files changed, 12 insertions(+), 10 deletions(-)

diff -r a5e787345396 -r aa62ce092d1b source/common/quant.cpp
--- a/source/common/quant.cpp	Wed Sep 30 17:32:27 2015 -0500
+++ b/source/common/quant.cpp	Wed Sep 30 17:32:31 2015 -0500
@@ -1268,10 +1268,10 @@
 
             if (lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD)
             {
-                uint32_t signbit = (dstCoeff[codeParams.scan[subPos + firstNZPosInCG]] > 0 ? 0 : 1);
-                int absSum = 0;
+                int absSum = dstCoeff[codeParams.scan[subPos + firstNZPosInCG]];
+                const uint32_t signbit = ((uint32_t)absSum >> 31);
 
-                for (n = firstNZPosInCG; n <= lastNZPosInCG; n++)
+                for (n = firstNZPosInCG + 1; n <= lastNZPosInCG; n++)
                     absSum += dstCoeff[codeParams.scan[n + subPos]];
 
                 if (signbit != (absSum & 1U))
@@ -1282,7 +1282,9 @@
 
                     int64_t minCostInc = MAX_INT64, curCost = MAX_INT64;
                     uint32_t minPos = 0;
-                    int8_t finalChange = 0, curChange = 0;
+                    int8_t finalChange = 0;
+                    int curChange = 0;
+                    uint32_t lastCoeff = lastCG;
 
                     for (n = (lastCG ? lastNZPosInCG : SCAN_SET_SIZE - 1); n >= 0; --n)
                     {
@@ -1300,6 +1302,7 @@
 
 #define DELTARDCOST(d0, d, deltabits) ((((int64_t)d * d - d0) << scaleBits) + ((lambda2 * (int64_t)(deltabits)) >> 8))
 
+                        const uint32_t isOne = (absLevel == 1);
                         if (dstCoeff[blkPos])
                         {
                             d = abs(signCoef) - ((unQuantLevel + preDQuantLevelDiff) >> unquantShift);
@@ -1310,16 +1313,14 @@
                              * significant coeff flag cost savings */
                             d = abs(signCoef) - ((unQuantLevel - preDQuantLevelDiff) >> unquantShift);
                             X265_CHECK((uint32_t)UNQUANT(absLevel - 1) == ((unQuantLevel - preDQuantLevelDiff) >> unquantShift), "dquant check failed\n");
-                            int isOne = (abs(dstCoeff[blkPos]) == 1);
                             int downBits = rateIncDown[blkPos] - (isOne ? (IEP_RATE + sigRateDelta[blkPos]) : 0);
                             int64_t costDown = DELTARDCOST(origDist, d, downBits);
 
-                            costDown -= (lastCG & (n == lastNZPosInCG) & isOne) * 4 * IEP_RATE;
+                            costDown -= (lastCoeff & isOne) * 4 * IEP_RATE;
                             curCost = ((n == firstNZPosInCG) & isOne) ? MAX_INT64 : costDown;
+
                             curChange = 2 * (costUp < costDown) - 1;
-
-                            if (costUp < costDown)
-                                curCost = costUp;
+                            curCost = (costUp < costDown) ? costUp : curCost;
                         }
                         else if ((n < firstNZPosInCG) & (signbit != ((uint32_t)signCoef >> 31)))
                         {
@@ -1340,9 +1341,10 @@
                         if (curCost < minCostInc)
                         {
                             minCostInc = curCost;
-                            finalChange = curChange;
+                            finalChange = (int8_t)curChange;
                             minPos = blkPos + (absLevel << 16);
                         }
+                        lastCoeff = 0;
                     }
 
                     const int absInMinPos = (minPos >> 16);



More information about the x265-devel mailing list