[x265] [PATCH] TComDataCU: replaced functions with tables

ashok at multicorewareinc.com ashok at multicorewareinc.com
Fri Jul 18 16:07:43 CEST 2014


# HG changeset patch
# User Ashok Kumar Mishra<ashok at multicorewareinc.com>
# Date 1405691922 -19800
#      Fri Jul 18 19:28:42 2014 +0530
# Node ID 2d5b0c143180d37f9533461a805a329703cf72db
# Parent  75545e34cc09d8fb00342a500cbc1deb2928070c
TComDataCU: replaced functions with tables

diff -r 75545e34cc09 -r 2d5b0c143180 source/Lib/TLibCommon/TComDataCU.cpp
--- a/source/Lib/TLibCommon/TComDataCU.cpp	Fri Jul 18 15:19:48 2014 +0530
+++ b/source/Lib/TLibCommon/TComDataCU.cpp	Fri Jul 18 19:28:42 2014 +0530
@@ -1498,83 +1498,16 @@
     memset(m_transformSkip[ttype] + absPartIdx, useTransformSkip, sizeof(uint8_t) * coveredPartIdxes);
 }
 
-uint8_t TComDataCU::getNumPartInter()
-{
-    uint8_t numPart = 0;
-
-    switch (m_partSizes[0])
-    {
-    case SIZE_2Nx2N:    numPart = 1;
-        break;
-    case SIZE_2NxN:     numPart = 2;
-        break;
-    case SIZE_Nx2N:     numPart = 2;
-        break;
-    case SIZE_NxN:      numPart = 4;
-        break;
-    case SIZE_2NxnU:    numPart = 2;
-        break;
-    case SIZE_2NxnD:    numPart = 2;
-        break;
-    case SIZE_nLx2N:    numPart = 2;
-        break;
-    case SIZE_nRx2N:    numPart = 2;
-        break;
-    default:            X265_CHECK(0, "unexpected part type\n");
-        break;
-    }
-
-    return numPart;
-}
-
 void TComDataCU::getPartIndexAndSize(uint32_t partIdx, uint32_t& outPartAddr, int& outWidth, int& outHeight)
 {
     int cuSize = 1 << getLog2CUSize(0);
+    int part_mode = m_partSizes[0];
+    int part_idx  = partIdx;
 
-    switch (m_partSizes[0])
-    {
-    case SIZE_2NxN:
-        outWidth = cuSize;
-        outHeight = cuSize >> 1;
-        outPartAddr = (partIdx == 0) ? 0 : m_numPartitions >> 1;
-        break;
-    case SIZE_Nx2N:
-        outWidth = cuSize >> 1;
-        outHeight = cuSize;
-        outPartAddr = (partIdx == 0) ? 0 : m_numPartitions >> 2;
-        break;
-    case SIZE_NxN:
-        outWidth = cuSize >> 1;
-        outHeight = cuSize >> 1;
-        outPartAddr = (m_numPartitions >> 2) * partIdx;
-        break;
-    case SIZE_2NxnU:
-        outWidth    = cuSize;
-        outHeight   = (partIdx == 0) ?  cuSize >> 2 : (cuSize >> 2) + (cuSize >> 1);
-        outPartAddr = (partIdx == 0) ? 0 : m_numPartitions >> 3;
-        break;
-    case SIZE_2NxnD:
-        outWidth    = cuSize;
-        outHeight   = (partIdx == 0) ?  (cuSize >> 2) + (cuSize >> 1) : cuSize >> 2;
-        outPartAddr = (partIdx == 0) ? 0 : (m_numPartitions >> 1) + (m_numPartitions >> 3);
-        break;
-    case SIZE_nLx2N:
-        outWidth    = (partIdx == 0) ? cuSize >> 2 : (cuSize >> 2) + (cuSize >> 1);
-        outHeight   = cuSize;
-        outPartAddr = (partIdx == 0) ? 0 : m_numPartitions >> 4;
-        break;
-    case SIZE_nRx2N:
-        outWidth    = (partIdx == 0) ? (cuSize >> 2) + (cuSize >> 1) : cuSize >> 2;
-        outHeight   = cuSize;
-        outPartAddr = (partIdx == 0) ? 0 : (m_numPartitions >> 2) + (m_numPartitions >> 4);
-        break;
-    default:
-        X265_CHECK(m_partSizes[0] == SIZE_2Nx2N, "unexpected part type\n");
-        outWidth = cuSize;
-        outHeight = cuSize;
-        outPartAddr = 0;
-        break;
-    }
+    int tmp = partTable[part_mode][part_idx][0];
+    outWidth = ((tmp >> 4) * cuSize) >> 2;
+    outHeight = ((tmp & 0xF) * cuSize) >> 2;
+    outPartAddr = (partAddrTable[part_mode][part_idx] * m_numPartitions) >> 4;
 }
 
 void TComDataCU::getMvField(TComDataCU* cu, uint32_t absPartIdx, int picList, TComMvField& outMvField)
@@ -2081,63 +2014,17 @@
  */
 void TComDataCU::getPartPosition(uint32_t partIdx, int& xP, int& yP, int& nPSW, int& nPSH)
 {
-    uint32_t col = m_cuPelX;
-    uint32_t row = m_cuPelY;
-    uint32_t cuSize = 1 << getLog2CUSize(0);
-
-    switch (m_partSizes[0])
-    {
-    case SIZE_2NxN:
-        nPSW = cuSize;
-        nPSH = cuSize >> 1;
-        xP   = col;
-        yP   = (partIdx == 0) ? row : row + nPSH;
-        break;
-    case SIZE_Nx2N:
-        nPSW = cuSize >> 1;
-        nPSH = cuSize;
-        xP   = (partIdx == 0) ? col : col + nPSW;
-        yP   = row;
-        break;
-    case SIZE_NxN:
-        nPSW = cuSize >> 1;
-        nPSH = cuSize >> 1;
-        xP   = col + (partIdx & 0x1) * nPSW;
-        yP   = row + (partIdx >> 1) * nPSH;
-        break;
-    case SIZE_2NxnU:
-        nPSW = cuSize;
-        nPSH = (partIdx == 0) ?  cuSize >> 2 : (cuSize >> 2) + (cuSize >> 1);
-        xP   = col;
-        yP   = (partIdx == 0) ? row : row + cuSize - nPSH;
-        break;
-    case SIZE_2NxnD:
-        nPSW = cuSize;
-        nPSH = (partIdx == 0) ?  (cuSize >> 2) + (cuSize >> 1) : cuSize >> 2;
-        xP   = col;
-        yP   = (partIdx == 0) ? row : row + cuSize - nPSH;
-        break;
-    case SIZE_nLx2N:
-        nPSW = (partIdx == 0) ? cuSize >> 2 : (cuSize >> 2) + (cuSize >> 1);
-        nPSH = cuSize;
-        xP   = (partIdx == 0) ? col : col + cuSize - nPSW;
-        yP   = row;
-        break;
-    case SIZE_nRx2N:
-        nPSW = (partIdx == 0) ? (cuSize >> 2) + (cuSize >> 1) : cuSize >> 2;
-        nPSH = cuSize;
-        xP   = (partIdx == 0) ? col : col + cuSize - nPSW;
-        yP   = row;
-        break;
-    default:
-        X265_CHECK(m_partSizes[0] == SIZE_2Nx2N, "unexpected part type\n");
-        nPSW = cuSize;
-        nPSH = cuSize;
-        xP   = col;
-        yP   = row;
-
-        break;
-    }
+    int cuSize = 1 << getLog2CUSize(0);
+    int part_mode = m_partSizes[0];
+    int part_idx  = partIdx;
+
+    int tmp = partTable[part_mode][part_idx][0];
+    nPSW = ((tmp >> 4) * cuSize) >> 2;
+    nPSH = ((tmp & 0xF) * cuSize) >> 2;
+
+    tmp = partTable[part_mode][part_idx][1];
+    xP = ((tmp >> 4) * cuSize) >> 2;
+    yP = ((tmp & 0xF) * cuSize) >> 2;
 }
 
 /** Constructs a list of candidates for AMVP
diff -r 75545e34cc09 -r 2d5b0c143180 source/Lib/TLibCommon/TComDataCU.h
--- a/source/Lib/TLibCommon/TComDataCU.h	Fri Jul 18 15:19:48 2014 +0530
+++ b/source/Lib/TLibCommon/TComDataCU.h	Fri Jul 18 19:28:42 2014 +0530
@@ -93,6 +93,40 @@
     pixel*   m_tqBypassYuvMemBlock;
 } DataCUMemPool;
 
+// Partition count table, index represents partitioning mode.
+const uint8_t nbPartsTable[8] = { 1, 2, 2, 4, 2, 2, 2, 2 };
+
+// Partition table.
+// First index is partitioning mode. Second index is partition index.
+// Third index is 0 for partition sizes, 1 for partition offsets. The 
+// sizes and offsets are encoded as two packed 4-bit values (X,Y). 
+// X and Y represent 1/4 fractions of the block size.
+const uint8_t partTable[8][4][2] =
+{
+//        XY
+    { { 0x44, 0x00 }, { 0x00, 0x00 }, { 0x00, 0x00 }, { 0x00, 0x00 } }, // SIZE_2Nx2N.
+    { { 0x42, 0x00 }, { 0x42, 0x02 }, { 0x00, 0x00 }, { 0x00, 0x00 } }, // SIZE_2NxN.
+    { { 0x24, 0x00 }, { 0x24, 0x20 }, { 0x00, 0x00 }, { 0x00, 0x00 } }, // SIZE_Nx2N.
+    { { 0x22, 0x00 }, { 0x22, 0x20 }, { 0x22, 0x02 }, { 0x22, 0x22 } }, // SIZE_NxN.
+    { { 0x41, 0x00 }, { 0x43, 0x01 }, { 0x00, 0x00 }, { 0x00, 0x00 } }, // SIZE_2NxnU.
+    { { 0x43, 0x00 }, { 0x41, 0x03 }, { 0x00, 0x00 }, { 0x00, 0x00 } }, // SIZE_2NxnD.
+    { { 0x14, 0x00 }, { 0x34, 0x10 }, { 0x00, 0x00 }, { 0x00, 0x00 } }, // SIZE_nLx2N.
+    { { 0x34, 0x00 }, { 0x14, 0x30 }, { 0x00, 0x00 }, { 0x00, 0x00 } }  // SIZE_nRx2N.
+};
+
+// Partition Address table.
+// First index is partitioning mode. Second index is partition address.
+const uint8_t partAddrTable[8][4] =
+{
+    { 0x00, 0x00, 0x00, 0x00 }, // SIZE_2Nx2N.
+    { 0x00, 0x08, 0x08, 0x08 }, // SIZE_2NxN.
+    { 0x00, 0x04, 0x04, 0x04 }, // SIZE_Nx2N.
+    { 0x00, 0x04, 0x08, 0x0C }, // SIZE_NxN.
+    { 0x00, 0x02, 0x02, 0x02 }, // SIZE_2NxnU.
+    { 0x00, 0x0A, 0x0A, 0x0A }, // SIZE_2NxnD.
+    { 0x00, 0x01, 0x01, 0x01 }, // SIZE_nLx2N.
+    { 0x00, 0x05, 0x05, 0x05 }  // SIZE_nRx2N.
+};
 
 // ====================================================================================================================
 // Class definition
@@ -370,7 +404,7 @@
     // -------------------------------------------------------------------------------------------------------------------
 
     void          getPartIndexAndSize(uint32_t partIdx, uint32_t& ruiPartAddr, int& riWidth, int& riHeight);
-    uint8_t       getNumPartInter();
+    uint8_t       getNumPartInter() { return nbPartsTable[m_partSizes[0]]; }
     bool          isFirstAbsZorderIdxInDepth(uint32_t absPartIdx, uint32_t depth);
 
     // -------------------------------------------------------------------------------------------------------------------


More information about the x265-devel mailing list