[x265] [PATCH 1 of 8] reduce operators on dstCoeff[minPos] in rdoQuant()

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


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1443652334 18000
# Node ID e6e7afbd3b23b3692d8e83ec691d1bf124dc8ad1
# Parent  6e7761bdfe23addb862483f8407b388800de7d92
reduce operators on dstCoeff[minPos] in rdoQuant()
---
 source/common/quant.cpp |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)

diff -r 6e7761bdfe23 -r e6e7afbd3b23 source/common/quant.cpp
--- a/source/common/quant.cpp	Wed Sep 30 14:57:15 2015 +0530
+++ b/source/common/quant.cpp	Wed Sep 30 17:32:14 2015 -0500
@@ -1276,7 +1276,7 @@
                      * finalChange imply absolute levels (+1 is away from zero, -1 is towards zero) */
 
                     int64_t minCostInc = MAX_INT64, curCost = MAX_INT64;
-                    int minPos = -1;
+                    uint32_t minPos = 0;
                     int8_t finalChange = 0, curChange = 0;
 
                     for (n = (lastCG ? lastNZPosInCG : SCAN_SET_SIZE - 1); n >= 0; --n)
@@ -1285,11 +1285,11 @@
                         const int signCoef    = m_resiDctCoeff[blkPos]; /* pre-quantization DCT coeff */
                         const int absLevel    = abs(dstCoeff[blkPos]);
                         // TODO: this is constant in non-scaling mode
-                        const int preDQuantLevelDiff = (unquantScale[blkPos] << per);
-                        const int unQuantLevel = (absLevel * (unquantScale[blkPos] << per) + unquantRound);
+                        const uint32_t preDQuantLevelDiff = (unquantScale[blkPos] << per);
+                        const uint32_t unQuantLevel = (absLevel * (unquantScale[blkPos] << per) + unquantRound);
 
                         int d = abs(signCoef) - (unQuantLevel >> unquantShift);
-                        X265_CHECK(UNQUANT(absLevel) == (unQuantLevel >> unquantShift), "dquant check failed\n");
+                        X265_CHECK((uint32_t)UNQUANT(absLevel) == (unQuantLevel >> unquantShift), "dquant check failed\n");
 
                         const int64_t origDist = (((int64_t)d * d));
 
@@ -1298,13 +1298,13 @@
                         if (dstCoeff[blkPos])
                         {
                             d = abs(signCoef) - ((unQuantLevel + preDQuantLevelDiff) >> unquantShift);
-                            X265_CHECK(UNQUANT(absLevel + 1) == ((unQuantLevel + preDQuantLevelDiff) >> unquantShift), "dquant check failed\n");
+                            X265_CHECK((uint32_t)UNQUANT(absLevel + 1) == ((unQuantLevel + preDQuantLevelDiff) >> unquantShift), "dquant check failed\n");
                             int64_t costUp = DELTARDCOST(origDist, d, rateIncUp[blkPos]);
 
                             /* if decrementing would make the coeff 0, we can include the
                              * significant coeff flag cost savings */
                             d = abs(signCoef) - ((unQuantLevel - preDQuantLevelDiff) >> unquantShift);
-                            X265_CHECK(UNQUANT(absLevel - 1) == ((unQuantLevel - preDQuantLevelDiff) >> unquantShift), "dquant check failed\n");
+                            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);
@@ -1327,7 +1327,7 @@
                         {
                             /* evaluate changing an uncoded coeff 0 to a coded coeff +/-1 */
                             d = abs(signCoef) - ((preDQuantLevelDiff + unquantRound) >> unquantShift);
-                            X265_CHECK(UNQUANT(1) == ((preDQuantLevelDiff + unquantRound) >> unquantShift), "dquant check failed\n");
+                            X265_CHECK((uint32_t)UNQUANT(1) == ((preDQuantLevelDiff + unquantRound) >> unquantShift), "dquant check failed\n");
                             curCost = DELTARDCOST(origDist, d, rateIncUp[blkPos] + IEP_RATE + sigRateDelta[blkPos]);
                             curChange = 1;
                         }
@@ -1336,12 +1336,15 @@
                         {
                             minCostInc = curCost;
                             finalChange = curChange;
-                            minPos = blkPos;
+                            minPos = blkPos + (absLevel << 16);
                         }
                     }
 
+                    const int absInMinPos = (minPos >> 16);
+                    minPos = (uint16_t)minPos;
+
                     // if (dstCoeff[minPos] == 32767 || dstCoeff[minPos] == -32768)
-                    if (((uint16_t)dstCoeff[minPos] + 1 == (uint16_t)0x8000) | ((uint16_t)dstCoeff[minPos] == (uint16_t)0x8000))
+                    if (absInMinPos >= 32767)
                         /* don't allow sign hiding to violate the SPEC range */
                         finalChange = -1;
 
@@ -1350,7 +1353,7 @@
                     //    numSig++;
                     //else if (finalChange == -1 && abs(dstCoeff[minPos]) == 1)
                     //    numSig--;
-                    numSig += (dstCoeff[minPos] == 0) - ((finalChange == -1) & (abs(dstCoeff[minPos]) == 1));
+                    numSig += (absInMinPos == 0) - ((finalChange == -1) & (absInMinPos == 1));
 
 
                     // NOTE: Reference code



More information about the x265-devel mailing list