[x265] [PATCH] psyCost_ss: C code optimization, suitable for ASM conversion

praveen at multicorewareinc.com praveen at multicorewareinc.com
Fri Dec 12 12:09:53 CET 2014


# HG changeset patch
# User Praveen Tiwari
# Date 1418382584 -19800
# Node ID 2b8284399144b547d36038ba7987c14aea9c9503
# Parent  d299428772c54533124720ee3102a3b8fa1e379f
psyCost_ss: C code optimization, suitable for ASM conversion

psy_acEnergy_ss_4x4, is combined version of satd_4x4 and sad<4, 4>, eliminating unnecessary load
operations, extra arguments(zeroBuf and 0).It also replaces SAD operation with sum of absolute
value, as the second pixel buffer is zero.

diff -r d299428772c5 -r 2b8284399144 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:39:44 2014 +0530
@@ -865,6 +865,37 @@
     }
 }
 
+int psy_acEnergy_ss_4x4(const int16_t* source, intptr_t sstride)
+{
+    sum2_t tmp[4][2];
+    sum2_t a0, a1, a2, a3, b0, b1;
+    sum2_t sum = 0;
+    sum2_t sum1 = 0;
+
+    for (int i = 0; i < 4; i++, source += sstride)
+    {
+        a0 = source[0];
+        a1 = source[1];
+        a2 = source[2];
+        a3 = source[3];
+        sum1 = sum1 + (abs(source[0]) + abs(source[1]) + abs(source[2]) + abs(source[3]));
+        b0 = (a0 + a1) + ((a0 - a1) << BITS_PER_SUM);
+        b1 = (a2 + a3) + ((a2 - a3) << BITS_PER_SUM);
+        tmp[i][0] = b0 + b1;
+        tmp[i][1] = b0 - b1;
+    }
+
+    for (int i = 0; i < 2; i++)
+    {
+        HADAMARD4(a0, a1, a2, a3, tmp[0][i], tmp[1][i], tmp[2][i], tmp[3][i]);
+        a0 = abs2(a0) + abs2(a1) + abs2(a2) + abs2(a3);
+        sum += ((sum_t)a0) + (a0 >> BITS_PER_SUM);
+    }
+
+    sum = (int)(sum >> 1);
+    return (int)(sum - (sum1 >> 2));
+}
+
 template<int size>
 int psyCost_ss(const int16_t* source, intptr_t sstride, const int16_t* recon, intptr_t rstride)
 {
@@ -892,8 +923,8 @@
     else
     {
         /* 4x4 is too small for sa8d */
-        int sourceEnergy = satd_4x4(source, sstride, zeroBuf, 0) - (sad<4, 4>(source, sstride, zeroBuf, 0) >> 2);
-        int reconEnergy = satd_4x4(recon, rstride, zeroBuf, 0) - (sad<4, 4>(recon, rstride, zeroBuf, 0) >> 2);
+        int sourceEnergy = psy_acEnergy_ss_4x4(source, sstride);
+        int reconEnergy = psy_acEnergy_ss_4x4(recon, rstride);
         return abs(sourceEnergy - reconEnergy);
     }
 }


More information about the x265-devel mailing list