[x265] [PATCH] pixel: replace sse_sp8 vector class with intrinsic

yuvaraj at multicorewareinc.com yuvaraj at multicorewareinc.com
Wed Oct 9 14:57:12 CEST 2013


# HG changeset patch
# User Yuvaraj Venkatesh <yuvaraj at multicorewareinc.com>
# Date 1381323377 -19800
#      Wed Oct 09 18:26:17 2013 +0530
# Node ID ae06d8100683c574fc5d0b995ac308d24e89908e
# Parent  8ce339236f5abee2379da764c0454626150463a7
pixel: replace sse_sp8 vector class with intrinsic

diff -r 8ce339236f5a -r ae06d8100683 source/common/vec/sse.inc
--- a/source/common/vec/sse.inc	Wed Oct 09 17:40:09 2013 +0530
+++ b/source/common/vec/sse.inc	Wed Oct 09 18:26:17 2013 +0530
@@ -448,26 +448,37 @@
 template<int ly>
 int sse_sp8(short* fenc, intptr_t strideFenc, pixel* fref, intptr_t strideFref)
 {
-    int rows = ly;
-    Vec8s m1;
-    Vec16uc n1;
+    __m128i sum0 = _mm_setzero_si128();
+    __m128i sum1 = _mm_setzero_si128();
 
-    Vec8us diff_low(0), diff_high(0);
-    Vec4i sum_low(0), sum_high(0);
-    for (; rows != 0; rows--)
+    for(int i = 0; i < ly; i++)
     {
-        n1.load(fref);
-        m1.load(fenc);
-        diff_low = m1 - extend_low(n1);
-        diff_low = diff_low * diff_low;
-        sum_low += extend_low(diff_low);
-        sum_high += extend_high(diff_low);
+        __m128i T00, T01;
+        __m128i T10, T11, T12, T13;
+        T00 = _mm_loadu_si128((__m128i*)(fenc));
+        T01 = _mm_loadu_si128((__m128i*)(fref));
+        T01 = _mm_unpacklo_epi8(T01, _mm_setzero_si128());    //convert 8-bit to 16-bit
+
+        T10 = _mm_unpacklo_epi16(T00, _mm_setzero_si128());
+        T11 = _mm_unpacklo_epi16(T01, _mm_setzero_si128());
+        T12 = _mm_sub_epi32(T10, T11);
+        T13 = _mm_mullo_epi32(T12, T12);
+        sum0 = _mm_add_epi32(sum0, T13);
+        T10 = _mm_unpackhi_epi16(T00, _mm_setzero_si128());
+        T11 = _mm_unpackhi_epi16(T01, _mm_setzero_si128());
+        T12 = _mm_sub_epi32(T10, T11);
+        T13 = _mm_mullo_epi32(T12, T12);
+        sum1 = _mm_add_epi32(sum1, T13);
 
         fenc += strideFenc;
         fref += strideFref;
     }
+    sum0 = _mm_add_epi32(sum0, sum1);
 
-    return horizontal_add(sum_low) + horizontal_add(sum_high);
+    sum0 = _mm_hadd_epi32(sum0, _mm_setzero_si128());
+    sum0 = _mm_hadd_epi32(sum0, _mm_setzero_si128());
+
+    return _mm_cvtsi128_si32(sum0);
 }
 
 template<int ly>


More information about the x265-devel mailing list