[x265] [PATCH 4 of 8] fast RD path on encode coeff remain code in codeCoeffNxN()

Steve Borho steve at borho.org
Thu Apr 30 22:06:48 CEST 2015


On 04/30, Min Chen wrote:
> # HG changeset patch
> # User Min Chen <chenm003 at 163.com>
> # Date 1430390937 -28800
> # Node ID 1980f573179d5aab749fcce40c9e4c8a7bdc10d6
> # Parent  62549ea896fe857e2470a23b79af4356fa5af792
> fast RD path on encode coeff remain code in codeCoeffNxN()

both of your patch series are queued, this patch required a rename of
idx since it shadows another idx variable

> ---
>  source/encoder/entropy.cpp |   63 ++++++++++++++++++++++++++++++++++++-------
>  1 files changed, 52 insertions(+), 11 deletions(-)
> 
> diff -r 62549ea896fe -r 1980f573179d source/encoder/entropy.cpp
> --- a/source/encoder/entropy.cpp	Thu Apr 30 18:48:53 2015 +0800
> +++ b/source/encoder/entropy.cpp	Thu Apr 30 18:48:57 2015 +0800
> @@ -1518,7 +1518,6 @@
>      uint8_t * const baseCoeffGroupCtx = &m_contextState[OFF_SIG_CG_FLAG_CTX + (bIsLuma ? 0 : NUM_SIG_CG_FLAG_CTX)];
>      uint8_t * const baseCtx = bIsLuma ? &m_contextState[OFF_SIG_FLAG_CTX] : &m_contextState[OFF_SIG_FLAG_CTX + NUM_SIG_FLAG_CTX_LUMA];
>      uint32_t c1 = 1;
> -    uint32_t goRiceParam = 0;
>      int scanPosSigOff = scanPosLast - (lastScanSet << MLS_CG_SIZE) - 1;
>      int absCoeff[1 << MLS_CG_SIZE];
>      int numNonZero = 1;
> @@ -1532,7 +1531,6 @@
>          const uint32_t subCoeffFlag = coeffFlag[subSet];
>          uint32_t scanFlagMask = subCoeffFlag;
>          int subPosBase = subSet << MLS_CG_SIZE;
> -        goRiceParam    = 0;
>          
>          if (subSet == lastScanSet)
>          {
> @@ -1768,21 +1766,64 @@
>              const int hiddenShift = (bHideFirstSign && signHidden) ? 1 : 0;
>              encodeBinsEP((coeffSigns >> hiddenShift), numNonZero - hiddenShift);
>  
> -            int firstCoeff2 = 1;
>              if (!c1 || numNonZero > C1FLAG_NUMBER)
>              {
> -                for (int idx = 0; idx < numNonZero; idx++)
> +                uint32_t goRiceParam = 0;
> +                int firstCoeff2 = 1;
> +
> +                if (!m_bitIf)
>                  {
> -                    int baseLevel = (idx < C1FLAG_NUMBER) ? (2 + firstCoeff2) : 1;
> +                    // FastRd path
> +                    for (int idx = 0; idx < numNonZero; idx++)
> +                    {
> +                        int baseLevel = (idx < C1FLAG_NUMBER) ? (2 + firstCoeff2) : 1;
> +                        int codeNumber = absCoeff[idx] - baseLevel;
>  
> -                    if (absCoeff[idx] >= baseLevel)
> +                        if (codeNumber >= 0)
> +                        {
> +                            //writeCoefRemainExGolomb(absCoeff[idx] - baseLevel, goRiceParam);
> +                            uint32_t length = 0;
> +
> +                            if (((uint32_t)codeNumber >> goRiceParam) < COEF_REMAIN_BIN_REDUCTION)
> +                            {
> +                                length = (uint32_t)codeNumber >> goRiceParam;
> +                                m_fracBits += (length + 1 + goRiceParam) << 15;
> +                            }
> +                            else
> +                            {
> +                                codeNumber = ((uint32_t)codeNumber >> goRiceParam) - COEF_REMAIN_BIN_REDUCTION;
> +                                if (codeNumber != 0)
> +                                {
> +                                    unsigned long idx;
> +                                    CLZ(idx, codeNumber + 1);
> +                                    length = idx;
> +                                }
> +                                m_fracBits += (COEF_REMAIN_BIN_REDUCTION + length + 1 + goRiceParam + length) << 15;
> +                            }
> +
> +                            if (absCoeff[idx] > 3 * (1 << goRiceParam))
> +                                goRiceParam = std::min<uint32_t>(goRiceParam + 1, 4);
> +                        }
> +                        if (absCoeff[idx] >= 2)
> +                            firstCoeff2 = 0;
> +                    }
> +                }
> +                else
> +                {
> +                    // Standard path
> +                    for (int idx = 0; idx < numNonZero; idx++)
>                      {
> -                        writeCoefRemainExGolomb(absCoeff[idx] - baseLevel, goRiceParam);
> -                        if (absCoeff[idx] > 3 * (1 << goRiceParam))
> -                            goRiceParam = std::min<uint32_t>(goRiceParam + 1, 4);
> +                        int baseLevel = (idx < C1FLAG_NUMBER) ? (2 + firstCoeff2) : 1;
> +
> +                        if (absCoeff[idx] >= baseLevel)
> +                        {
> +                            writeCoefRemainExGolomb(absCoeff[idx] - baseLevel, goRiceParam);
> +                            if (absCoeff[idx] > 3 * (1 << goRiceParam))
> +                                goRiceParam = std::min<uint32_t>(goRiceParam + 1, 4);
> +                        }
> +                        if (absCoeff[idx] >= 2)
> +                            firstCoeff2 = 0;
>                      }
> -                    if (absCoeff[idx] >= 2)
> -                        firstCoeff2 = 0;
>                  }
>              }
>          }
> 
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel

-- 
Steve Borho


More information about the x265-devel mailing list