[x265-commits] [x265] cli: fix missing reference to superfast preset

Steve Borho steve at borho.org
Mon Mar 24 21:33:47 CET 2014


details:   http://hg.videolan.org/x265/rev/aa08b7f2d420
branches:  
changeset: 6574:aa08b7f2d420
user:      Steve Borho <steve at borho.org>
date:      Mon Mar 24 13:09:10 2014 -0500
description:
cli: fix missing reference to superfast preset
Subject: [x265] improvement TEncBinCABAC::encodeBin by temporary variant and reduce AND operator

details:   http://hg.videolan.org/x265/rev/5c5cb411263e
branches:  
changeset: 6575:5c5cb411263e
user:      Min Chen <chenm003 at 163.com>
date:      Mon Mar 24 11:57:41 2014 -0700
description:
improvement TEncBinCABAC::encodeBin by temporary variant and reduce AND operator
Subject: [x265] improvement TEncBinCABAC::writeOut by mask operator and local variant

details:   http://hg.videolan.org/x265/rev/88c66aece128
branches:  
changeset: 6576:88c66aece128
user:      Min Chen <chenm003 at 163.com>
date:      Mon Mar 24 11:58:00 2014 -0700
description:
improvement TEncBinCABAC::writeOut by mask operator and local variant
Subject: [x265] reduce g_minInGroup from uint32_t to uint8_t

details:   http://hg.videolan.org/x265/rev/f09130afa3dd
branches:  
changeset: 6577:f09130afa3dd
user:      Min Chen <chenm003 at 163.com>
date:      Mon Mar 24 11:58:22 2014 -0700
description:
reduce g_minInGroup from uint32_t to uint8_t
Subject: [x265] optimize: replace g_groupIdx[] by getGroupIdx()

details:   http://hg.videolan.org/x265/rev/b39d26118f09
branches:  
changeset: 6578:b39d26118f09
user:      Min Chen <chenm003 at 163.com>
date:      Mon Mar 24 11:58:53 2014 -0700
description:
optimize: replace g_groupIdx[] by getGroupIdx()
Subject: [x265] improvement by replace SHIFT to MASK_AND

details:   http://hg.videolan.org/x265/rev/33617683915d
branches:  
changeset: 6579:33617683915d
user:      Min Chen <chenm003 at 163.com>
date:      Mon Mar 24 11:59:32 2014 -0700
description:
improvement by replace SHIFT to MASK_AND
Subject: [x265] faster sign(X) and N^2 on TComTrQuant::xRateDistOptQuant

details:   http://hg.videolan.org/x265/rev/10e614dca6d4
branches:  
changeset: 6580:10e614dca6d4
user:      Min Chen <chenm003 at 163.com>
date:      Mon Mar 24 11:59:50 2014 -0700
description:
faster sign(X) and N^2 on TComTrQuant::xRateDistOptQuant
Subject: [x265] cleanup on TComTrQuant::getTUEntropyCodingParameters

details:   http://hg.videolan.org/x265/rev/4318d47d9348
branches:  
changeset: 6581:4318d47d9348
user:      Min Chen <chenm003 at 163.com>
date:      Mon Mar 24 12:00:06 2014 -0700
description:
cleanup on TComTrQuant::getTUEntropyCodingParameters

diffstat:

 source/Lib/TLibCommon/TComRom.cpp            |   3 +-
 source/Lib/TLibCommon/TComRom.h              |  21 +++++++++-
 source/Lib/TLibCommon/TComTrQuant.cpp        |  54 +++++----------------------
 source/Lib/TLibCommon/TComTrQuant.h          |  37 ++++++++++++++++++-
 source/Lib/TLibCommon/TypeDef.h              |   2 -
 source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp |  39 ++++++++++---------
 source/Lib/TLibEncoder/TEncSbac.cpp          |  12 +++---
 source/x265.cpp                              |   4 +-
 8 files changed, 95 insertions(+), 77 deletions(-)

diffs (truncated from 356 to 300 lines):

diff -r fdd7c6168cf4 -r 4318d47d9348 source/Lib/TLibCommon/TComRom.cpp
--- a/source/Lib/TLibCommon/TComRom.cpp	Fri Mar 21 14:44:35 2014 -0500
+++ b/source/Lib/TLibCommon/TComRom.cpp	Mon Mar 24 12:00:06 2014 -0700
@@ -433,8 +433,7 @@ uint64_t g_nSymbolCounter = 0;
 // Scanning order & context model mapping
 // ====================================================================================================================
 
-const uint32_t g_minInGroup[10] = { 0, 1, 2, 3, 4, 6, 8, 12, 16, 24 };
-const uint8_t g_groupIdx[32]   = { 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9 };
+const uint8_t g_minInGroup[10] = { 0, 1, 2, 3, 4, 6, 8, 12, 16, 24 };
 
 // Rice parameters for absolute transform levels
 const uint8_t g_goRiceRange[5] = { 7, 14, 26, 46, 78 };
diff -r fdd7c6168cf4 -r 4318d47d9348 source/Lib/TLibCommon/TComRom.h
--- a/source/Lib/TLibCommon/TComRom.h	Fri Mar 21 14:44:35 2014 -0500
+++ b/source/Lib/TLibCommon/TComRom.h	Mon Mar 24 12:00:06 2014 -0700
@@ -128,8 +128,25 @@ extern const int16_t g_chromaFilter[8][N
 // Scanning order & context mapping table
 // ====================================================================================================================
 
-extern const uint8_t g_groupIdx[32];
-extern const uint32_t g_minInGroup[10];
+//extern const uint8_t g_groupIdx[32];
+static inline uint32_t getGroupIdx(const uint32_t idx)
+{
+    uint32_t group = (idx >> 3);
+    if (idx >= 24)
+        group = 2;
+    uint32_t groupIdx = ((idx >> (group + 1)) - 2) + 4 + (group << 1);
+    if (idx <= 3)
+        groupIdx = idx;
+
+#ifdef _DEBUG
+    static const uint8_t g_groupIdx[32]   = { 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9 };
+    assert(groupIdx == g_groupIdx[idx]);
+#endif
+
+    return groupIdx;
+}
+
+extern const uint8_t g_minInGroup[10];
 
 extern const uint8_t g_goRiceRange[5];      //!< maximum value coded with Rice codes
 //extern const uint8_t g_goRicePrefixLen[5];  //!< prefix length for each maximum value
diff -r fdd7c6168cf4 -r 4318d47d9348 source/Lib/TLibCommon/TComTrQuant.cpp
--- a/source/Lib/TLibCommon/TComTrQuant.cpp	Fri Mar 21 14:44:35 2014 -0500
+++ b/source/Lib/TLibCommon/TComTrQuant.cpp	Mon Mar 24 12:00:06 2014 -0700
@@ -486,41 +486,6 @@ void TComTrQuant::xITransformSkip(int32_
     }
 }
 
-void TComTrQuant::getTUEntropyCodingParameters(TComDataCU*                cu,
-                                               TUEntropyCodingParameters &result,
-                                               uint32_t                   absPartIdx,
-                                               uint32_t                   log2TrSize,
-                                               TextType                   ttype)
-{
-    //set the group layout
-    const uint32_t log2TrSizeCG = log2TrSize - MLS_CG_LOG2_SIZE;
-    result.log2TrSize   = log2TrSize;
-    result.log2TrSizeCG = log2TrSizeCG;
-
-    //set the scan orders
-    result.scanType = COEFF_SCAN_TYPE(cu->getCoefScanIdx(absPartIdx, log2TrSize, ttype == TEXT_LUMA, cu->isIntra(absPartIdx)));
-    result.scan   = g_scanOrder[SCAN_GROUPED_4x4][result.scanType][log2TrSize];
-    result.scanCG = g_scanOrder[SCAN_UNGROUPED][result.scanType][log2TrSizeCG];
-
-    //set the significance map context selection parameters
-    TextType ctype = ttype == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA;
-    result.ctype = ctype;
-    if (log2TrSize == 2)
-    {
-        result.firstSignificanceMapContext = significanceMapContextSetStart[ctype][CONTEXT_TYPE_4x4];
-    }
-    else if (log2TrSize == 3)
-    {
-        result.firstSignificanceMapContext = significanceMapContextSetStart[ctype][CONTEXT_TYPE_8x8];
-        if (result.scanType != SCAN_DIAG)
-            result.firstSignificanceMapContext += nonDiagonalScan8x8ContextOffset[ctype];
-    }
-    else
-    {
-        result.firstSignificanceMapContext = significanceMapContextSetStart[ctype][CONTEXT_TYPE_NxN];
-    }
-}
-
 /** RDOQ with CABAC
  * \param cu pointer to coding unit structure
  * \param plSrcCoeff pointer to input buffer
@@ -643,7 +608,8 @@ uint32_t TComTrQuant::xRateDistOptQuant(
                 }
                 else
                 {
-                    const uint32_t ctxSig = getSigCtxInc(patternSigCtx, log2TrSize, trSize, blkPos, codingParameters);
+                    // NOTE: ttype is different to ctype, but getSigCtxInc may safety use it 
+                    const uint32_t ctxSig = getSigCtxInc(patternSigCtx, log2TrSize, trSize, blkPos, ttype, codingParameters.firstSignificanceMapContext);
                     if (maxAbsLevel < 3)
                     {
                         costSig[scanPos] = xGetRateSigCoef(0, ctxSig);
@@ -876,7 +842,8 @@ uint32_t TComTrQuant::xRateDistOptQuant(
         absSum += level;
         if (level)
             *lastPos = blkPos;
-        dstCoeff[blkPos] = (srcCoeff[blkPos] < 0) ? -level : level;
+        uint32_t mask = (int32_t)srcCoeff[blkPos] >> 31;
+        dstCoeff[blkPos] = (level ^ mask) - mask;
     }
 
     //===== clean uncoded coefficients =====
@@ -895,7 +862,7 @@ uint32_t TComTrQuant::xRateDistOptQuant(
         int tmpSum = 0;
         int n;
 
-        for (int subSet = (trSize * trSize - 1) >> LOG2_SCAN_SET_SIZE; subSet >= 0; subSet--)
+        for (int subSet = ((1 << (log2TrSize * 2)) - 1) >> LOG2_SCAN_SET_SIZE; subSet >= 0; subSet--)
         {
             int subPos = subSet << LOG2_SCAN_SET_SIZE;
             int firstNZPosInCG = SCAN_SET_SIZE, lastNZPosInCG = -1;
@@ -1054,7 +1021,8 @@ uint32_t TComTrQuant::getSigCtxInc(const
                                    const uint32_t                   log2TrSize,
                                    const uint32_t                   trSize,
                                    const uint32_t                   blkPos,
-                                   const TUEntropyCodingParameters &codingParameters)
+                                   const TextType                   ctype,
+                                   const uint32_t                   firstSignificanceMapContext)
 {
     static const uint8_t ctxIndMap[16] =
     {
@@ -1113,11 +1081,11 @@ uint32_t TComTrQuant::getSigCtxInc(const
     };
 
     int cnt = table_cnt[patternSigCtx][posXinSubset][posYinSubset];
-    int offset = codingParameters.firstSignificanceMapContext;
+    int offset = firstSignificanceMapContext;
 
     offset += cnt;
 
-    return (codingParameters.ctype == TEXT_LUMA && (posX | posY) >= 4) ? 3 + offset : offset;
+    return (ctype == TEXT_LUMA && (posX | posY) >= 4) ? 3 + offset : offset;
 }
 
 /** Get the best level in RD sense
@@ -1330,8 +1298,8 @@ inline int TComTrQuant::xGetICRate(uint3
  */
 inline double TComTrQuant::xGetRateLast(uint32_t posx, uint32_t posy) const
 {
-    uint32_t ctxX = g_groupIdx[posx];
-    uint32_t ctxY = g_groupIdx[posy];
+    uint32_t ctxX = getGroupIdx(posx);
+    uint32_t ctxY = getGroupIdx(posy);
     uint32_t cost = m_estBitsSbac->lastXBits[ctxX] + m_estBitsSbac->lastYBits[ctxY];
 
     int32_t maskX = (int32_t)(2 - posx) >> 31;
diff -r fdd7c6168cf4 -r 4318d47d9348 source/Lib/TLibCommon/TComTrQuant.h
--- a/source/Lib/TLibCommon/TComTrQuant.h	Fri Mar 21 14:44:35 2014 -0500
+++ b/source/Lib/TLibCommon/TComTrQuant.h	Mon Mar 24 12:00:06 2014 -0700
@@ -159,9 +159,42 @@ public:
     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 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 getSigCtxInc(uint32_t patternSigCtx, const uint32_t log2TrSize, const uint32_t trSize, const uint32_t blkPos, const TextType ctype, const uint32_t firstSignificanceMapContext);
     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);
+    inline static void getTUEntropyCodingParameters(TComDataCU* cu, TUEntropyCodingParameters &result, uint32_t absPartIdx, uint32_t log2TrSize, TextType ttype)
+    {
+        //set the group layout
+        const uint32_t log2TrSizeCG = log2TrSize - MLS_CG_LOG2_SIZE;
+        result.log2TrSizeCG = log2TrSizeCG;
+
+        //set the scan orders
+        result.scanType = COEFF_SCAN_TYPE(cu->getCoefScanIdx(absPartIdx, log2TrSize, ttype == TEXT_LUMA, cu->isIntra(absPartIdx)));
+        result.scan   = g_scanOrder[SCAN_GROUPED_4x4][result.scanType][log2TrSize];
+        result.scanCG = g_scanOrder[SCAN_UNGROUPED][result.scanType][log2TrSizeCG];
+
+        //set the significance map context selection parameters
+        TextType ctype = (ttype == TEXT_LUMA) ? TEXT_LUMA : TEXT_CHROMA;
+        if (log2TrSize == 2)
+        {
+            result.firstSignificanceMapContext = 0;
+            assert(significanceMapContextSetStart[ctype][CONTEXT_TYPE_4x4] == 0);
+        }
+        else if (log2TrSize == 3)
+        {
+            result.firstSignificanceMapContext = 9;
+            assert(significanceMapContextSetStart[ctype][CONTEXT_TYPE_8x8] == 9);
+            if (result.scanType != SCAN_DIAG && !ctype)
+            {
+                result.firstSignificanceMapContext += 6;
+                assert(nonDiagonalScan8x8ContextOffset[ctype] == 6);
+            }
+        }
+        else
+        {
+            result.firstSignificanceMapContext = (ctype ? 12 : 21);
+            assert(significanceMapContextSetStart[ctype][CONTEXT_TYPE_NxN] == (ctype ? 12 : 21));
+        }
+    }
     estBitsSbacStruct* m_estBitsSbac;
 
 protected:
diff -r fdd7c6168cf4 -r 4318d47d9348 source/Lib/TLibCommon/TypeDef.h
--- a/source/Lib/TLibCommon/TypeDef.h	Fri Mar 21 14:44:35 2014 -0500
+++ b/source/Lib/TLibCommon/TypeDef.h	Mon Mar 24 12:00:06 2014 -0700
@@ -176,8 +176,6 @@ struct TUEntropyCodingParameters
     const uint16_t            *scan;
     const uint16_t            *scanCG;
     COEFF_SCAN_TYPE      scanType;
-    TextType             ctype;
-    uint32_t             log2TrSize;
     uint32_t             log2TrSizeCG;
     uint32_t             firstSignificanceMapContext;
 };
diff -r fdd7c6168cf4 -r 4318d47d9348 source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp
--- a/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp	Fri Mar 21 14:44:35 2014 -0500
+++ b/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp	Mon Mar 24 12:00:06 2014 -0700
@@ -190,25 +190,30 @@ void TEncBinCABAC::encodeBin(uint32_t bi
     }
     ctxModel.bBinsCoded = 1;
 
-    uint32_t mps = sbacGetMps(mstate);
+    uint32_t range = m_range;
     uint32_t state = sbacGetState(mstate);
-    uint32_t lps = g_lpsTable[state][(m_range >> 6) & 3];
-    m_range -= lps;
+    uint32_t lps = g_lpsTable[state][((uint8_t)range >> 6)];
+    range -= lps;
 
-    assert(lps != 0);
+    assert(lps >= 2);
 
-    int numBits = (uint32_t)(m_range - 256) >> 31;
+    int numBits = (uint32_t)(range - 256) >> 31;
     uint32_t low = m_low;
-    uint32_t range = m_range;
-    if (binValue != mps)
+
+    // NOTE: MPS must be LOWEST bit in mstate
+    assert(((binValue ^ mstate) & 1) == (binValue != sbacGetMps(mstate)));
+    if ((binValue ^ mstate) & 1)
     {
         // NOTE: lps is non-zero and the maximum of idx is 8 because lps less than 256
         //numBits   = g_renormTable[lps >> 3];
         unsigned long idx;
         CLZ32(idx, lps);
+        assert(state != 63 || idx == 1);
+
         numBits = 8 - idx;
-        if (numBits >= 6)
+        if (state >= 63)
             numBits = 6;
+        assert(numBits <= 6);
 
         low    += range;
         range   = lps;
@@ -345,9 +350,10 @@ void TEncBinCABAC::encodeBinTrm(uint32_t
 void TEncBinCABAC::writeOut()
 {
     uint32_t leadByte = m_low >> (13 + m_bitsLeft);
+    uint32_t low_mask = (uint32_t)(~0) >> (11 + 8 - m_bitsLeft);
 
     m_bitsLeft -= 8;
-    m_low &= 0xffffffffu >> (11 - m_bitsLeft);
+    m_low &= low_mask;
 
     if (leadByte == 0xff)
     {
@@ -355,25 +361,22 @@ void TEncBinCABAC::writeOut()
     }
     else
     {
-        if (m_numBufferedBytes > 0)
+        uint32_t numBufferedBytes = m_numBufferedBytes;
+        if (numBufferedBytes > 0)
         {
             uint32_t carry = leadByte >> 8;
             uint32_t byteTowrite = m_bufferedByte + carry;
-            m_bufferedByte = leadByte & 0xff;
             m_bitIf->writeByte(byteTowrite);
 
             byteTowrite = (0xff + carry) & 0xff;
-            while (m_numBufferedBytes > 1)
+            while (numBufferedBytes > 1)
             {
                 m_bitIf->writeByte(byteTowrite);
-                m_numBufferedBytes--;
+                numBufferedBytes--;
             }
         }
-        else
-        {
-            m_numBufferedBytes = 1;
-            m_bufferedByte = leadByte;
-        }
+        m_numBufferedBytes = 1;
+        m_bufferedByte = (uint8_t)leadByte;
     }
 }
 
diff -r fdd7c6168cf4 -r 4318d47d9348 source/Lib/TLibEncoder/TEncSbac.cpp


More information about the x265-commits mailing list