[x265] [PATCH] psyCost_pp: optimize psyCost_pp_8x8, suitable for ASM conversion

dnyaneshwar at multicorewareinc.com dnyaneshwar at multicorewareinc.com
Fri Dec 12 12:16:26 CET 2014


# HG changeset patch
# User Dnyaneshwar G <dnyaneshwar at multicorewareinc.com>
# Date 1418382914 -19800
#      Fri Dec 12 16:45:14 2014 +0530
# Node ID 57c328f3c24ec5bf8a37a5368ef56f132765842e
# Parent  ead951c5fa2678d148d08c863d8b34d8c23419aa
psyCost_pp: optimize psyCost_pp_8x8, suitable for ASM conversion

diff -r ead951c5fa26 -r 57c328f3c24e source/common/pixel.cpp
--- a/source/common/pixel.cpp	Fri Dec 12 16:34:56 2014 +0530
+++ b/source/common/pixel.cpp	Fri Dec 12 16:45:14 2014 +0530
@@ -376,6 +376,57 @@
     return (int)((_sa8d_8x8(pix1, i_pix1, pix2, i_pix2) + 2) >> 2);
 }
 
+void psy_acEnergy_pp_8x8(const pixel* src, intptr_t stride, int* energy, int dim)
+{
+    int n = 0;
+    const pixel* tmpSrc = src;
+
+    for (int k = 0; k < dim; k += 8)
+    {
+        for (int j = 0; j < dim; j += 8)
+        {
+            src = tmpSrc + k * stride + j;
+            ssum2_t tmp[8][4];
+            ssum2_t a0, a1, a2, a3, a4, a5, a6, a7, b0, b1, b2, b3;
+            ssum2_t sum = 0, sum1 = 0;
+
+            for (int i = 0; i < 8; i++, src += stride)
+            {
+                a0 = src[0];
+                a1 = src[1];
+                b0 = (a0 + a1) + ((a0 - a1) << BITS_PER_SUM);
+                a2 = src[2];
+                a3 = src[3];
+                b1 = (a2 + a3) + ((a2 - a3) << BITS_PER_SUM);
+                a4 = src[4];
+                a5 = src[5];
+                b2 = (a4 + a5) + ((a4 - a5) << BITS_PER_SUM);
+                a6 = src[6];
+                a7 = src[7];
+                sum1 += a0 + a1 + a2 + a3 + a4 + a5 + a6 + a7;
+                b3 = (a6 + a7) + ((a6 - a7) << BITS_PER_SUM);
+                HADAMARD4(tmp[i][0], tmp[i][1], tmp[i][2], tmp[i][3], b0, b1, b2, b3);
+            }
+
+            for (int i = 0; i < 4; i++)
+            {
+                HADAMARD4(a0, a1, a2, a3, tmp[0][i], tmp[1][i], tmp[2][i], tmp[3][i]);
+                HADAMARD4(a4, a5, a6, a7, tmp[4][i], tmp[5][i], tmp[6][i], tmp[7][i]);
+                b0  = abs2(a0 + a4) + abs2(a0 - a4);
+                b0 += abs2(a1 + a5) + abs2(a1 - a5);
+                b0 += abs2(a2 + a6) + abs2(a2 - a6);
+                b0 += abs2(a3 + a7) + abs2(a3 - a7);
+                sum += (sum_t)b0 + (b0 >> BITS_PER_SUM);
+            }
+
+            sum = (int)((sum + 2) >> 2);
+            sum1 >>= 2;
+
+            energy[n++] = (sum - sum1);
+        }
+    }
+}
+
 inline int _sa8d_8x8(const int16_t* pix1, intptr_t i_pix1, const int16_t* pix2, intptr_t i_pix2)
 {
     ssum2_t tmp[8][4];
@@ -834,26 +885,25 @@
 template<int size>
 int psyCost_pp(const pixel* source, intptr_t sstride, const pixel* recon, intptr_t rstride)
 {
-    static pixel zeroBuf[8] /* = { 0 } */;
-
-    if (size)
-    {
-        int dim = 1 << (size + 2);
-        uint32_t totEnergy = 0;
-        for (int i = 0; i < dim; i += 8)
-        {
-            for (int j = 0; j < dim; j+= 8)
-            {
-                /* AC energy, measured by sa8d (AC + DC) minus SAD (DC) */
-                int sourceEnergy = sa8d_8x8(source + i * sstride + j, sstride, zeroBuf, 0) - 
-                                   (sad<8, 8>(source + i * sstride + j, sstride, zeroBuf, 0) >> 2);
-                int reconEnergy =  sa8d_8x8(recon + i * rstride + j, rstride, zeroBuf, 0) - 
-                                   (sad<8, 8>(recon + i * rstride + j, rstride, zeroBuf, 0) >> 2);
-
-                totEnergy += abs(sourceEnergy - reconEnergy);
-            }
-        }
-        return totEnergy;
+    if (size)
+    {
+        int dim     = 1 << (size + 2);
+        int bufSize = dim >> (4 - size);
+        uint32_t totEnergy = 0;
+        int* sourceEnergy = X265_MALLOC(int, bufSize);
+        int* reconEnergy  = X265_MALLOC(int, bufSize);
+
+        /* AC energy, measured by sa8d (AC + DC) minus SAD (DC) */
+        psy_acEnergy_pp_8x8(source, sstride, sourceEnergy, dim);
+        psy_acEnergy_pp_8x8(recon,  rstride, reconEnergy,  dim);
+
+        for (int i = 0; i < bufSize; i++)
+            totEnergy += abs(sourceEnergy[i] - reconEnergy[i]);
+
+        X265_FREE(sourceEnergy);
+        X265_FREE(reconEnergy);
+
+        return totEnergy;
     }
     else
     {


More information about the x265-devel mailing list