[x265] [PATCH 4 of 7] optimize: replace g_groupIdx[] by getGroupIdx()

Min Chen chenm003 at 163.com
Mon Mar 24 20:00:41 CET 2014


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1395687533 25200
# Node ID 105fa844e4e3e2c6bffb8d2ea613e56e429cdf64
# Parent  700a63ba598db1828534ee824fbb1f93fef86c0f
optimize: replace g_groupIdx[] by getGroupIdx()

diff -r 700a63ba598d -r 105fa844e4e3 source/Lib/TLibCommon/TComRom.cpp
--- a/source/Lib/TLibCommon/TComRom.cpp	Mon Mar 24 11:58:22 2014 -0700
+++ b/source/Lib/TLibCommon/TComRom.cpp	Mon Mar 24 11:58:53 2014 -0700
@@ -434,7 +434,6 @@
 // ====================================================================================================================
 
 const uint8_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 };
 
 // Rice parameters for absolute transform levels
 const uint8_t g_goRiceRange[5] = { 7, 14, 26, 46, 78 };
diff -r 700a63ba598d -r 105fa844e4e3 source/Lib/TLibCommon/TComRom.h
--- a/source/Lib/TLibCommon/TComRom.h	Mon Mar 24 11:58:22 2014 -0700
+++ b/source/Lib/TLibCommon/TComRom.h	Mon Mar 24 11:58:53 2014 -0700
@@ -128,7 +128,24 @@
 // Scanning order & context mapping table
 // ====================================================================================================================
 
-extern const uint8_t g_groupIdx[32];
+//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
diff -r 700a63ba598d -r 105fa844e4e3 source/Lib/TLibCommon/TComTrQuant.cpp
--- a/source/Lib/TLibCommon/TComTrQuant.cpp	Mon Mar 24 11:58:22 2014 -0700
+++ b/source/Lib/TLibCommon/TComTrQuant.cpp	Mon Mar 24 11:58:53 2014 -0700
@@ -1330,8 +1330,8 @@
  */
 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 700a63ba598d -r 105fa844e4e3 source/Lib/TLibEncoder/TEncSbac.cpp
--- a/source/Lib/TLibEncoder/TEncSbac.cpp	Mon Mar 24 11:58:22 2014 -0700
+++ b/source/Lib/TLibEncoder/TEncSbac.cpp	Mon Mar 24 11:58:53 2014 -0700
@@ -1988,8 +1988,8 @@
     }
 
     uint32_t ctxLast;
-    uint32_t groupIdxX = g_groupIdx[posx];
-    uint32_t groupIdxY = g_groupIdx[posy];
+    uint32_t groupIdxX = getGroupIdx(posx);
+    uint32_t groupIdxY = getGroupIdx(posy);
 
     int blkSizeOffset = ttype ? NUM_CTX_LAST_FLAG_XY_LUMA : ((log2TrSize - 2) * 3 + ((log2TrSize - 1) >> 2));
     int ctxShift = ttype ? log2TrSize - 2 : ((log2TrSize + 1) >> 2);



More information about the x265-devel mailing list