<div dir="ltr">Nice! Do you see any tangible performance improvement from these fixes to rdoquant on dekstop/server systems?</div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">Pradeep Ramachandran, PhD<div>Solution Architect,</div><div>Multicoreware Inc.</div><div>Ph: +91 99627 82018</div></div></div></div></div></div></div></div></div></div>
<br><div class="gmail_quote">On Thu, Sep 10, 2015 at 4:03 AM, Min Chen <span dir="ltr"><<a href="mailto:chenm003@163.com" target="_blank">chenm003@163.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># HG changeset patch<br>
# User Min Chen <<a href="mailto:chenm003@163.com">chenm003@163.com</a>><br>
# Date 1441837075 18000<br>
# Node ID 4a64832b90b8927f409e9239856281b02a1a2475<br>
# Parent 41afa68a2c9c9e591c2e95264e2edc987df45d62<br>
reduce operators on rdoQuant() compute sigHide cost<br>
---<br>
source/common/quant.cpp | 50 ++++++++++++++++++++++++++--------------------<br>
1 files changed, 28 insertions(+), 22 deletions(-)<br>
<br>
diff -r 41afa68a2c9c -r 4a64832b90b8 source/common/quant.cpp<br>
--- a/source/common/quant.cpp Wed Sep 09 17:17:25 2015 -0500<br>
+++ b/source/common/quant.cpp Wed Sep 09 17:17:55 2015 -0500<br>
@@ -555,7 +555,7 @@<br>
template<uint32_t log2TrSize><br>
uint32_t Quant::rdoQuant(const CUData& cu, int16_t* dstCoeff, TextType ttype, uint32_t absPartIdx, bool usePsy)<br>
{<br>
- int transformShift = MAX_TR_DYNAMIC_RANGE - X265_DEPTH - log2TrSize; /* Represents scaling through forward transform */<br>
+ const int transformShift = MAX_TR_DYNAMIC_RANGE - X265_DEPTH - log2TrSize; /* Represents scaling through forward transform */<br>
int scalingListType = (cu.isIntra(absPartIdx) ? 0 : 3) + ttype;<br>
const uint32_t usePsyMask = usePsy ? -1 : 0;<br>
<br>
@@ -567,7 +567,7 @@<br>
int add = (1 << (qbits - 1));<br>
const int32_t* qCoef = m_scalingList->m_quantCoef[log2TrSize - 2][scalingListType][rem];<br>
<br>
- int numCoeff = 1 << (log2TrSize * 2);<br>
+ const int numCoeff = 1 << (log2TrSize * 2);<br>
uint32_t numSig = primitives.nquant(m_resiDctCoeff, qCoef, dstCoeff, qbits, add, numCoeff);<br>
X265_CHECK((int)numSig == <a href="http://primitives.cu" rel="noreferrer" target="_blank">primitives.cu</a>[log2TrSize - 2].count_nonzero(dstCoeff), "numSig differ\n");<br>
if (!numSig)<br>
@@ -583,7 +583,7 @@<br>
const int32_t* unquantScale = m_scalingList->m_dequantCoef[log2TrSize - 2][scalingListType][rem];<br>
int unquantShift = QUANT_IQUANT_SHIFT - QUANT_SHIFT - transformShift + (m_scalingList->m_bEnabled ? 4 : 0);<br>
int unquantRound = (unquantShift > per) ? 1 << (unquantShift - per - 1) : 0;<br>
- int scaleBits = SCALE_BITS - 2 * transformShift;<br>
+ const int scaleBits = SCALE_BITS - 2 * transformShift;<br>
<br>
#define UNQUANT(lvl) (((lvl) * (unquantScale[blkPos] << per) + unquantRound) >> unquantShift)<br>
#define SIGCOST(bits) ((lambda2 * (bits)) >> 8)<br>
@@ -1046,7 +1046,7 @@<br>
c2 += (uint32_t)(c2 - 2) >> 31;<br>
c2Idx++;<br>
}<br>
- else if ((c1 < 3) && (c1 > 0) && level)<br>
+ else if (((c1 == 1) | (c1 == 2)) && level)<br>
c1++;<br>
<br>
if (dstCoeff[blkPos])<br>
@@ -1276,7 +1276,7 @@<br>
<br>
int64_t minCostInc = MAX_INT64, curCost = MAX_INT64;<br>
int minPos = -1;<br>
- int16_t finalChange = 0, curChange = 0;<br>
+ int8_t finalChange = 0, curChange = 0;<br>
<br>
for (n = (lastCG ? lastNZPosInCG : SCAN_SET_SIZE - 1); n >= 0; --n)<br>
{<br>
@@ -1285,21 +1285,21 @@<br>
int absLevel = abs(dstCoeff[blkPos]);<br>
<br>
int d = abs(signCoef) - UNQUANT(absLevel);<br>
- int64_t origDist = (((int64_t)d * d)) << scaleBits;<br>
+ const int64_t origDist = (((int64_t)d * d));<br>
<br>
-#define DELTARDCOST(d, deltabits) ((((int64_t)d * d) << scaleBits) - origDist + ((lambda2 * (int64_t)(deltabits)) >> 8))<br>
+#define DELTARDCOST(d0, d, deltabits) ((((int64_t)d * d - d0) << scaleBits) + ((lambda2 * (int64_t)(deltabits)) >> 8))<br>
<br>
if (dstCoeff[blkPos])<br>
{<br>
d = abs(signCoef) - UNQUANT(absLevel + 1);<br>
- int64_t costUp = DELTARDCOST(d, rateIncUp[blkPos]);<br>
+ int64_t costUp = DELTARDCOST(origDist, d, rateIncUp[blkPos]);<br>
<br>
/* if decrementing would make the coeff 0, we can include the<br>
* significant coeff flag cost savings */<br>
d = abs(signCoef) - UNQUANT(absLevel - 1);<br>
int isOne = (abs(dstCoeff[blkPos]) == 1);<br>
int downBits = rateIncDown[blkPos] - (isOne ? (IEP_RATE + sigRateDelta[blkPos]) : 0);<br>
- int64_t costDown = DELTARDCOST(d, downBits);<br>
+ int64_t costDown = DELTARDCOST(origDist, d, downBits);<br>
<br>
costDown -= (lastCG & (n == lastNZPosInCG) & isOne) * 4 * IEP_RATE;<br>
curCost = ((n == firstNZPosInCG) & isOne) ? MAX_INT64 : costDown;<br>
@@ -1308,8 +1308,7 @@<br>
if (costUp < costDown)<br>
curCost = costUp;<br>
}<br>
- //else if ((n < firstNZPosInCG) & (signbit != ((uint32_t)signCoef >> 31)))<br>
- else if (n < firstNZPosInCG && signbit != (signCoef >= 0 ? 0 : 1U))<br>
+ else if ((n < firstNZPosInCG) & (signbit != ((uint32_t)signCoef >> 31)))<br>
{<br>
/* don't try to make a new coded coeff before the first coeff if its<br>
* sign would be different than the first coeff, the inferred sign would<br>
@@ -1320,7 +1319,7 @@<br>
{<br>
/* evaluate changing an uncoded coeff 0 to a coded coeff +/-1 */<br>
d = abs(signCoef) - UNQUANT(1);<br>
- curCost = DELTARDCOST(d, rateIncUp[blkPos] + IEP_RATE + sigRateDelta[blkPos]);<br>
+ curCost = DELTARDCOST(origDist, d, rateIncUp[blkPos] + IEP_RATE + sigRateDelta[blkPos]);<br>
curChange = 1;<br>
}<br>
<br>
@@ -1332,19 +1331,26 @@<br>
}<br>
}<br>
<br>
- if (dstCoeff[minPos] == 32767 || dstCoeff[minPos] == -32768)<br>
+ // if (dstCoeff[minPos] == 32767 || dstCoeff[minPos] == -32768)<br>
+ if (((uint16_t)dstCoeff[minPos] + 1 == (uint16_t)0x8000) | ((uint16_t)dstCoeff[minPos] == (uint16_t)0x8000))<br>
/* don't allow sign hiding to violate the SPEC range */<br>
finalChange = -1;<br>
<br>
- if (dstCoeff[minPos] == 0)<br>
- numSig++;<br>
- else if (finalChange == -1 && abs(dstCoeff[minPos]) == 1)<br>
- numSig--;<br>
+ // NOTE: Reference code<br>
+ //if (dstCoeff[minPos] == 0)<br>
+ // numSig++;<br>
+ //else if (finalChange == -1 && abs(dstCoeff[minPos]) == 1)<br>
+ // numSig--;<br>
+ numSig += (dstCoeff[minPos] == 0) - ((finalChange == -1) & (abs(dstCoeff[minPos]) == 1));<br>
<br>
- if (m_resiDctCoeff[minPos] >= 0)<br>
- dstCoeff[minPos] += finalChange;<br>
- else<br>
- dstCoeff[minPos] -= finalChange;<br>
+<br>
+ // NOTE: Reference code<br>
+ //if (m_resiDctCoeff[minPos] >= 0)<br>
+ // dstCoeff[minPos] += finalChange;<br>
+ //else<br>
+ // dstCoeff[minPos] -= finalChange;<br>
+ const int16_t resiCoeffSign = ((int16_t)m_resiDctCoeff[minPos] >> 16);<br>
+ dstCoeff[minPos] += (((int16_t)finalChange ^ resiCoeffSign) - resiCoeffSign);<br>
}<br>
}<br>
<br>
<br>
_______________________________________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a><br>
</blockquote></div><br></div>