[x265] [PATCH 01 of 16] reduce operators on dstCoeff[minPos] in rdoQuant()

Min Chen chenm003 at 163.com
Wed Oct 7 00:55:12 CEST 2015


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

diff -r f8b8ebdc5457 -r 4d32c813b465 source/common/quant.cpp
--- a/source/common/quant.cpp	Mon Sep 28 14:34:41 2015 +0530
+++ b/source/common/quant.cpp	Tue Oct 06 11:14:11 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