[x265] [PATCH 4 of 4] optimize: rewrite TEncSbac::xWriteCoefRemainExGolomb

Min Chen chenm003 at 163.com
Sat Mar 15 02:11:02 CET 2014


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1394845824 25200
# Node ID 09e1b2636b1a639182d121bf0021e49d1ada1bd7
# Parent  ce3fd6c2e7958975cd4286f9035182eba7726869
optimize: rewrite TEncSbac::xWriteCoefRemainExGolomb

diff -r ce3fd6c2e795 -r 09e1b2636b1a source/Lib/TLibEncoder/TEncSbac.cpp
--- a/source/Lib/TLibEncoder/TEncSbac.cpp	Fri Mar 14 18:09:38 2014 -0700
+++ b/source/Lib/TLibEncoder/TEncSbac.cpp	Fri Mar 14 18:10:24 2014 -0700
@@ -1355,29 +1355,35 @@
  * \param ruiGoRiceParam reference to Rice parameter
  * \returns void
  */
-void TEncSbac::xWriteCoefRemainExGolomb(uint32_t symbol, const uint32_t param)
+void TEncSbac::xWriteCoefRemainExGolomb(uint32_t codeNumber, const uint32_t absGoRice)
 {
-    int codeNumber  = (int)symbol;
     uint32_t length;
+    const uint32_t codeRemain = codeNumber & ((1 << absGoRice) - 1);
 
-    if (codeNumber < (COEF_REMAIN_BIN_REDUCTION << param))
+    if ((codeNumber >> absGoRice) < COEF_REMAIN_BIN_REDUCTION)
     {
-        length = codeNumber >> param;
-        codeNumber -= length << param;
-        m_binIf->encodeBinsEP((1 << (length + 1)) - 2, length + 1);
-        m_binIf->encodeBinsEP(codeNumber, param);
+        length = codeNumber >> absGoRice;
+
+        assert(codeNumber - (length << absGoRice) == (codeNumber & ((1 << absGoRice) - 1)));
+
+        assert(length + 1 + absGoRice < 32);
+        m_binIf->encodeBinsEP((((1 << (length + 1)) - 2) << absGoRice) + codeRemain, length + 1 + absGoRice);
     }
     else
     {
-        length = param;
-        codeNumber  = codeNumber - (COEF_REMAIN_BIN_REDUCTION << param);
-        while (codeNumber >= (1 << length))
+        length = 0;
+        codeNumber = (codeNumber >> absGoRice) - COEF_REMAIN_BIN_REDUCTION;
+        if (codeNumber != 0)
         {
-            codeNumber -=  (1 << (length++));
+            unsigned long idx;
+            CLZ32(idx, codeNumber + 1);
+            length = idx;
+            codeNumber -= (1 << idx) - 1;
         }
+        codeNumber = (codeNumber << absGoRice) + codeRemain;
 
-        m_binIf->encodeBinsEP((1 << (COEF_REMAIN_BIN_REDUCTION + length + 1 - param)) - 2, COEF_REMAIN_BIN_REDUCTION + length + 1 - param);
-        m_binIf->encodeBinsEP(codeNumber, length);
+        m_binIf->encodeBinsEP((1 << (COEF_REMAIN_BIN_REDUCTION + length + 1)) - 2, COEF_REMAIN_BIN_REDUCTION + length + 1);
+        m_binIf->encodeBinsEP(codeNumber, length + absGoRice);
     }
 }
 
diff -r ce3fd6c2e795 -r 09e1b2636b1a source/Lib/TLibEncoder/TEncSbac.h
--- a/source/Lib/TLibEncoder/TEncSbac.h	Fri Mar 14 18:09:38 2014 -0700
+++ b/source/Lib/TLibEncoder/TEncSbac.h	Fri Mar 14 18:10:24 2014 -0700
@@ -147,7 +147,7 @@
 
     void xWriteUnaryMaxSymbol(uint32_t symbol, ContextModel* scmModel, int offset, uint32_t maxSymbol);
     void xWriteEpExGolomb(uint32_t symbol, uint32_t count);
-    void xWriteCoefRemainExGolomb(uint32_t symbol, const uint32_t param);
+    void xWriteCoefRemainExGolomb(uint32_t symbol, const uint32_t absGoRice);
 
     void xCopyFrom(TEncSbac* src);
     void xCopyContextsFrom(TEncSbac* src);



More information about the x265-devel mailing list