[x265] [PATCH 1 of 4] faster algorithm to find firstNZPosInCG & lastNZPosInCG in Quant::signBitHidingHDQ()

Min Chen chenm003 at 163.com
Sat May 16 04:29:39 CEST 2015


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1431736219 25200
# Node ID 462ff027b5da131be170cdac6e8a798adae158f1
# Parent  e2fa20fefc2e4ee90ed0fbfbd05a67832dd4ff0d
faster algorithm to find firstNZPosInCG & lastNZPosInCG in Quant::signBitHidingHDQ()
---
 source/common/quant.cpp |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff -r e2fa20fefc2e -r 462ff027b5da source/common/quant.cpp
--- a/source/common/quant.cpp	Fri May 15 17:30:16 2015 -0700
+++ b/source/common/quant.cpp	Fri May 15 17:30:19 2015 -0700
@@ -269,13 +269,17 @@
 #endif
     const int lastScanPos = primitives.scanPosLast(codeParams.scan, coeff, coeffSign, coeffFlag, coeffNum, numSig, g_scan4x4[codeParams.scanType], trSize);
     const int cgLastScanPos = (lastScanPos >> LOG2_SCAN_SET_SIZE);
+    unsigned long tmp;
+
+    // first CG need specially processing
+    const uint32_t correctOffset = 0x0F & (lastScanPos ^ 0xF);
+    coeffFlag[cgLastScanPos] <<= correctOffset;
 
     for (int cg = cgLastScanPos; cg >= 0; cg--)
     {
         int cgStartPos = cg << LOG2_SCAN_SET_SIZE;
         int n;
 
-        const uint32_t posFirstLast = primitives.findPosFirstLast(&coeff[codeParams.scan[cgStartPos]], trSize, g_scan4x4[codeParams.scanType]);
 #if CHECKED_BUILD || _DEBUG
         for (n = SCAN_SET_SIZE - 1; n >= 0; --n)
             if (coeff[scan[n + cgStartPos]])
@@ -288,8 +292,6 @@
             X265_CHECK(lastNZPosInCG0 < 0, "all zero block check failure\n");
             continue;
         }
-        int firstNZPosInCG = (uint16_t)posFirstLast;
-        int lastNZPosInCG = posFirstLast >> 16;
 
 #if CHECKED_BUILD || _DEBUG
         for (n = 0;; n++)
@@ -297,10 +299,16 @@
                 break;
 
         int firstNZPosInCG0 = n;
+#endif
+
+        CLZ(tmp, coeffFlag[cg]);
+        const int firstNZPosInCG = (15 ^ tmp);
+
+        CTZ(tmp, coeffFlag[cg]);
+        const int lastNZPosInCG = (15 ^ tmp);
 
         X265_CHECK(firstNZPosInCG0 == firstNZPosInCG, "firstNZPosInCG0 check failure\n");
         X265_CHECK(lastNZPosInCG0 == lastNZPosInCG, "lastNZPosInCG0 check failure\n");
-#endif
 
         if (lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD)
         {



More information about the x265-devel mailing list