[x265] [PATCH 3 of 4] optimize: improvement TComTrQuant::getSigCtxInc, avoid shift by mask
Min Chen
chenm003 at 163.com
Sat Mar 15 02:11:01 CET 2014
# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1394845778 25200
# Node ID ce3fd6c2e7958975cd4286f9035182eba7726869
# Parent 626df01b607061744e1e8301e2de9c5c2ba62cb6
optimize: improvement TComTrQuant::getSigCtxInc, avoid shift by mask
diff -r 626df01b6070 -r ce3fd6c2e795 source/Lib/TLibCommon/TComTrQuant.cpp
--- a/source/Lib/TLibCommon/TComTrQuant.cpp Fri Mar 14 18:09:22 2014 -0700
+++ b/source/Lib/TLibCommon/TComTrQuant.cpp Fri Mar 14 18:09:38 2014 -0700
@@ -638,7 +638,7 @@
}
else
{
- uint16_t ctxSig = getSigCtxInc(patternSigCtx, codingParameters, blkPos);
+ uint16_t ctxSig = getSigCtxInc(patternSigCtx, log2TrSize, trSize, blkPos, codingParameters);
level = xGetCodedLevel(costCoeff[scanPos], costCoeff0[scanPos], costSig[scanPos],
levelDouble, maxAbsLevel, baseLevel, ctxSig, oneCtx, absCtx, goRiceParam,
c1c2Idx, qbits, scaleFactor, 0);
@@ -1014,7 +1014,7 @@
* \param height height of the block
* \returns pattern for current coefficient group
*/
-int TComTrQuant::calcPatternSigCtx(const uint64_t sigCoeffGroupFlag64, uint32_t cgPosX, uint32_t cgPosY, uint32_t log2TrSizeCG)
+uint32_t TComTrQuant::calcPatternSigCtx(const uint64_t sigCoeffGroupFlag64, uint32_t cgPosX, uint32_t cgPosY, uint32_t log2TrSizeCG)
{
if (log2TrSizeCG == 0) return 0;
@@ -1037,11 +1037,13 @@
* \param textureType texture type (TEXT_LUMA...)
* \returns ctxInc for current scan position
*/
-int TComTrQuant::getSigCtxInc(int patternSigCtx,
- const TUEntropyCodingParameters &codingParameters,
- const int blkPos)
+uint32_t TComTrQuant::getSigCtxInc(const uint32_t patternSigCtx,
+ const uint32_t log2TrSize,
+ const uint32_t trSize,
+ const uint32_t blkPos,
+ const TUEntropyCodingParameters &codingParameters)
{
- static const int ctxIndMap[16] =
+ static const uint8_t ctxIndMap[16] =
{
0, 1, 4, 5,
2, 3, 4, 5,
@@ -1051,16 +1053,17 @@
if (blkPos == 0) return 0; //special case for the DC context variable
- const int log2TrSize = codingParameters.log2TrSize;
if (log2TrSize == 2) //4x4
{
return ctxIndMap[blkPos];
}
const uint32_t posY = blkPos >> log2TrSize;
- const uint32_t posX = blkPos - (posY << log2TrSize);
+ const uint32_t posX = blkPos & (trSize - 1);
+ assert((blkPos - (posY << log2TrSize)) == posX);
- int posXinSubset = posX & 3;
+ int posXinSubset = blkPos & 3;
+ assert((posX & 3) == (blkPos & 3));
int posYinSubset = posY & 3;
// NOTE: [patternSigCtx][posXinSubset][posYinSubset]
diff -r 626df01b6070 -r ce3fd6c2e795 source/Lib/TLibCommon/TComTrQuant.h
--- a/source/Lib/TLibCommon/TComTrQuant.h Fri Mar 14 18:09:22 2014 -0700
+++ b/source/Lib/TLibCommon/TComTrQuant.h Fri Mar 14 18:09:38 2014 -0700
@@ -158,8 +158,8 @@
void setScalingList(TComScalingList *scalingList);
void processScalingListEnc(int32_t *coeff, int32_t *quantcoeff, int quantScales, uint32_t height, uint32_t width, uint32_t ratio, int sizuNum, uint32_t dc);
void processScalingListDec(int32_t *coeff, int32_t *dequantcoeff, int invQuantScales, uint32_t height, uint32_t width, uint32_t ratio, int sizuNum, uint32_t dc);
- static int calcPatternSigCtx(const uint64_t sigCoeffGroupFlag64, uint32_t cgPosX, uint32_t cgPosY, uint32_t log2TrSizeCG);
- static int getSigCtxInc(int patternSigCtx, const TUEntropyCodingParameters &codingParameters, const int blkPos);
+ static uint32_t calcPatternSigCtx(const uint64_t sigCoeffGroupFlag64, uint32_t cgPosX, uint32_t cgPosY, uint32_t log2TrSizeCG);
+ static uint32_t getSigCtxInc(uint32_t patternSigCtx, const uint32_t log2TrSize, const uint32_t trSize, const uint32_t blkPos, const TUEntropyCodingParameters &codingParameters);
static uint32_t getSigCoeffGroupCtxInc(const uint64_t sigCoeffGroupFlag64, uint32_t cgPosX, uint32_t cgPosY, const uint32_t log2TrSizeCG);
static void getTUEntropyCodingParameters(TComDataCU* cu, TUEntropyCodingParameters &result, uint32_t absPartIdx, uint32_t log2TrSize, TextType ttype);
estBitsSbacStruct* m_estBitsSbac;
diff -r 626df01b6070 -r ce3fd6c2e795 source/Lib/TLibEncoder/TEncSbac.cpp
--- a/source/Lib/TLibEncoder/TEncSbac.cpp Fri Mar 14 18:09:22 2014 -0700
+++ b/source/Lib/TLibEncoder/TEncSbac.cpp Fri Mar 14 18:09:38 2014 -0700
@@ -2166,7 +2166,7 @@
sig = (coeff[blkPos] != 0);
if (scanPosSig > subPos || subSet == 0 || numNonZero)
{
- ctxSig = TComTrQuant::getSigCtxInc(patternSigCtx, codingParameters, blkPos);
+ ctxSig = TComTrQuant::getSigCtxInc(patternSigCtx, log2TrSize, trSize, blkPos, codingParameters);
m_binIf->encodeBin(sig, baseCtx[ctxSig]);
}
if (sig)
More information about the x265-devel
mailing list