[x265] [PATCH] sad[4xN]:Intrinsic code

praveen at multicorewareinc.com praveen at multicorewareinc.com
Fri Aug 23 11:30:50 CEST 2013


# HG changeset patch
# User praveentiwari
# Date 1377250238 -19800
# Node ID 17a74ee184ec71542836d0d836f40f864dc6a020
# Parent  664704e5b91d81f3b01057173aa182885d005129
sad[4xN]:Intrinsic code

diff -r 664704e5b91d -r 17a74ee184ec source/common/vec/pixel8.inc
--- a/source/common/vec/pixel8.inc	Fri Aug 23 12:12:15 2013 +0530
+++ b/source/common/vec/pixel8.inc	Fri Aug 23 15:00:38 2013 +0530
@@ -33,46 +33,406 @@
 #endif
 #pragma warning(disable: 4799) // MMX warning , EMMS
 
+#ifdef X86_64
 template<int ly>
 int sad_4(pixel * fenc, intptr_t fencstride, pixel * fref, intptr_t frefstride)
 {
-    Vec16uc m1, n1;
-
-    Vec4i sum(0);
-    Vec8us sad(0);
-    int max_iterators = (ly >> 4) << 4;
-    int row;
-
-    for (row = 0; row < max_iterators; row += 16)
+    assert((ly % 4) == 0);
+    __m128i sum0 = _mm_setzero_si128();
+    __m128i sum1 = _mm_setzero_si128();
+    __m128i T00, T01, T02, T03;
+    __m128i T10, T11, T12, T13;
+    __m128i T20 = _mm_setzero_si128();
+
+    if (ly == 4)
     {
-        for (int i = 0; i < 16; i++)
+        T00 = _mm_loadl_epi64((__m128i*)(fenc + (0) * fencstride));
+        T01 = _mm_loadl_epi64((__m128i*)(fenc + (1) * fencstride));
+        T01 = _mm_unpacklo_epi32(T00, T01);
+        T02 = _mm_loadl_epi64((__m128i*)(fenc + (2) * fencstride));
+        T03 = _mm_loadl_epi64((__m128i*)(fenc + (3) * fencstride));
+        T03 = _mm_unpacklo_epi32(T02, T03);
+        T03 = _mm_unpacklo_epi64(T01, T03);
+
+        T10 = _mm_loadl_epi64((__m128i*)(fref + (0) * frefstride));
+        T11 = _mm_loadl_epi64((__m128i*)(fref + (1) * frefstride));
+        T11 = _mm_unpacklo_epi32(T10, T11);
+        T12 = _mm_loadl_epi64((__m128i*)(fref + (2) * frefstride));
+        T13 = _mm_loadl_epi64((__m128i*)(fref + (3) * frefstride));
+        T13 = _mm_unpacklo_epi32(T12, T13);
+        T13 = _mm_unpacklo_epi64(T11, T13);
+
+        T20 = _mm_sad_epu8(T03, T13);
+        sum0 = _mm_add_epi32(sum0, T20);
+    }
+    else if (ly == 8)
+    {
+        T00 = _mm_loadl_epi64((__m128i*)(fenc + (0) * fencstride));
+        T01 = _mm_loadl_epi64((__m128i*)(fenc + (1) * fencstride));
+        T01 = _mm_unpacklo_epi32(T00, T01);
+        T02 = _mm_loadl_epi64((__m128i*)(fenc + (2) * fencstride));
+        T03 = _mm_loadl_epi64((__m128i*)(fenc + (3) * fencstride));
+        T03 = _mm_unpacklo_epi32(T02, T03);
+        T03 = _mm_unpacklo_epi64(T01, T03);
+
+        T10 = _mm_loadl_epi64((__m128i*)(fref + (0) * frefstride));
+        T11 = _mm_loadl_epi64((__m128i*)(fref + (1) * frefstride));
+        T11 = _mm_unpacklo_epi32(T10, T11);
+        T12 = _mm_loadl_epi64((__m128i*)(fref + (2) * frefstride));
+        T13 = _mm_loadl_epi64((__m128i*)(fref + (3) * frefstride));
+        T13 = _mm_unpacklo_epi32(T12, T13);
+        T13 = _mm_unpacklo_epi64(T11, T13);
+
+        T20 = _mm_sad_epu8(T03, T13);
+        sum0 = _mm_add_epi32(sum0, T20);
+
+        T00 = _mm_loadl_epi64((__m128i*)(fenc + (4) * fencstride));
+        T01 = _mm_loadl_epi64((__m128i*)(fenc + (5) * fencstride));
+        T01 = _mm_unpacklo_epi32(T00, T01);
+        T02 = _mm_loadl_epi64((__m128i*)(fenc + (6) * fencstride));
+        T03 = _mm_loadl_epi64((__m128i*)(fenc + (7) * fencstride));
+        T03 = _mm_unpacklo_epi32(T02, T03);
+        T03 = _mm_unpacklo_epi64(T01, T03);
+
+        T10 = _mm_loadl_epi64((__m128i*)(fref + (4) * frefstride));
+        T11 = _mm_loadl_epi64((__m128i*)(fref + (5) * frefstride));
+        T11 = _mm_unpacklo_epi32(T10, T11);
+        T12 = _mm_loadl_epi64((__m128i*)(fref + (6) * frefstride));
+        T13 = _mm_loadl_epi64((__m128i*)(fref + (7) * frefstride));
+        T13 = _mm_unpacklo_epi32(T12, T13);
+        T13 = _mm_unpacklo_epi64(T11, T13);
+
+        T20 = _mm_sad_epu8(T03, T13);
+        sum0 = _mm_add_epi32(sum0, T20);
+    }
+
+    else if (ly == 16)
+    {
+        T00 = _mm_loadl_epi64((__m128i*)(fenc + (0) * fencstride));
+        T01 = _mm_loadl_epi64((__m128i*)(fenc + (1) * fencstride));
+        T01 = _mm_unpacklo_epi32(T00, T01);
+        T02 = _mm_loadl_epi64((__m128i*)(fenc + (2) * fencstride));
+        T03 = _mm_loadl_epi64((__m128i*)(fenc + (3) * fencstride));
+        T03 = _mm_unpacklo_epi32(T02, T03);
+        T03 = _mm_unpacklo_epi64(T01, T03);
+
+        T10 = _mm_loadl_epi64((__m128i*)(fref + (0) * frefstride));
+        T11 = _mm_loadl_epi64((__m128i*)(fref + (1) * frefstride));
+        T11 = _mm_unpacklo_epi32(T10, T11);
+        T12 = _mm_loadl_epi64((__m128i*)(fref + (2) * frefstride));
+        T13 = _mm_loadl_epi64((__m128i*)(fref + (3) * frefstride));
+        T13 = _mm_unpacklo_epi32(T12, T13);
+        T13 = _mm_unpacklo_epi64(T11, T13);
+
+        T20 = _mm_sad_epu8(T03, T13);
+        sum0 = _mm_add_epi32(sum0, T20);
+
+        T00 = _mm_loadl_epi64((__m128i*)(fenc + (4) * fencstride));
+        T01 = _mm_loadl_epi64((__m128i*)(fenc + (5) * fencstride));
+        T01 = _mm_unpacklo_epi32(T00, T01);
+        T02 = _mm_loadl_epi64((__m128i*)(fenc + (6) * fencstride));
+        T03 = _mm_loadl_epi64((__m128i*)(fenc + (7) * fencstride));
+        T03 = _mm_unpacklo_epi32(T02, T03);
+        T03 = _mm_unpacklo_epi64(T01, T03);
+
+        T10 = _mm_loadl_epi64((__m128i*)(fref + (4) * frefstride));
+        T11 = _mm_loadl_epi64((__m128i*)(fref + (5) * frefstride));
+        T11 = _mm_unpacklo_epi32(T10, T11);
+        T12 = _mm_loadl_epi64((__m128i*)(fref + (6) * frefstride));
+        T13 = _mm_loadl_epi64((__m128i*)(fref + (7) * frefstride));
+        T13 = _mm_unpacklo_epi32(T12, T13);
+        T13 = _mm_unpacklo_epi64(T11, T13);
+
+        T20 = _mm_sad_epu8(T03, T13);
+        sum0 = _mm_add_epi32(sum0, T20);
+
+        T00 = _mm_loadl_epi64((__m128i*)(fenc + (8) * fencstride));
+        T01 = _mm_loadl_epi64((__m128i*)(fenc + (9) * fencstride));
+        T01 = _mm_unpacklo_epi32(T00, T01);
+        T02 = _mm_loadl_epi64((__m128i*)(fenc + (10) * fencstride));
+        T03 = _mm_loadl_epi64((__m128i*)(fenc + (11) * fencstride));
+        T03 = _mm_unpacklo_epi32(T02, T03);
+        T03 = _mm_unpacklo_epi64(T01, T03);
+
+        T10 = _mm_loadl_epi64((__m128i*)(fref + (8) * frefstride));
+        T11 = _mm_loadl_epi64((__m128i*)(fref + (9) * frefstride));
+        T11 = _mm_unpacklo_epi32(T10, T11);
+        T12 = _mm_loadl_epi64((__m128i*)(fref + (10) * frefstride));
+        T13 = _mm_loadl_epi64((__m128i*)(fref + (11) * frefstride));
+        T13 = _mm_unpacklo_epi32(T12, T13);
+        T13 = _mm_unpacklo_epi64(T11, T13);
+
+        T20 = _mm_sad_epu8(T03, T13);
+        sum0 = _mm_add_epi32(sum0, T20);
+
+        T00 = _mm_loadl_epi64((__m128i*)(fenc + (12) * fencstride));
+        T01 = _mm_loadl_epi64((__m128i*)(fenc + (13) * fencstride));
+        T01 = _mm_unpacklo_epi32(T00, T01);
+        T02 = _mm_loadl_epi64((__m128i*)(fenc + (14) * fencstride));
+        T03 = _mm_loadl_epi64((__m128i*)(fenc + (15) * fencstride));
+        T03 = _mm_unpacklo_epi32(T02, T03);
+        T03 = _mm_unpacklo_epi64(T01, T03);
+
+        T10 = _mm_loadl_epi64((__m128i*)(fref + (12) * frefstride));
+        T11 = _mm_loadl_epi64((__m128i*)(fref + (13) * frefstride));
+        T11 = _mm_unpacklo_epi32(T10, T11);
+        T12 = _mm_loadl_epi64((__m128i*)(fref + (14) * frefstride));
+        T13 = _mm_loadl_epi64((__m128i*)(fref + (15) * frefstride));
+        T13 = _mm_unpacklo_epi32(T12, T13);
+        T13 = _mm_unpacklo_epi64(T11, T13);
+
+        T20 = _mm_sad_epu8(T03, T13);
+        sum0 = _mm_add_epi32(sum0, T20);
+    }
+
+    else if ((ly % 8) == 0)
+    {
+        for (int i = 0; i < ly; i += 8)
         {
-            m1.fromUint32(*(uint32_t*)fenc);
-            n1.fromUint32(*(uint32_t*)fref);
-            sad.addSumAbsDiff(m1, n1);
-
-            fenc += fencstride;
-            fref += frefstride;
+            T00 = _mm_loadl_epi64((__m128i*)(fenc + (i + 0) * fencstride));
+            T01 = _mm_loadl_epi64((__m128i*)(fenc + (i + 1) * fencstride));
+            T01 = _mm_unpacklo_epi32(T00, T01);
+            T02 = _mm_loadl_epi64((__m128i*)(fenc + (i + 2) * fencstride));
+            T03 = _mm_loadl_epi64((__m128i*)(fenc + (i + 3) * fencstride));
+            T03 = _mm_unpacklo_epi32(T02, T03);
+            T03 = _mm_unpacklo_epi64(T01, T03);
+
+            T10 = _mm_loadl_epi64((__m128i*)(fref + (i + 0) * frefstride));
+            T11 = _mm_loadl_epi64((__m128i*)(fref + (i + 1) * frefstride));
+            T11 = _mm_unpacklo_epi32(T10, T11);
+            T12 = _mm_loadl_epi64((__m128i*)(fref + (i + 2) * frefstride));
+            T13 = _mm_loadl_epi64((__m128i*)(fref + (i + 3) * frefstride));
+            T13 = _mm_unpacklo_epi32(T12, T13);
+            T13 = _mm_unpacklo_epi64(T11, T13);
+
+            T20 = _mm_sad_epu8(T03, T13);
+            sum0 = _mm_add_epi32(sum0, T20);
+
+            T00 = _mm_loadl_epi64((__m128i*)(fenc + (i + 4) * fencstride));
+            T01 = _mm_loadl_epi64((__m128i*)(fenc + (i + 5) * fencstride));
+            T01 = _mm_unpacklo_epi32(T00, T01);
+            T02 = _mm_loadl_epi64((__m128i*)(fenc + (i + 6) * fencstride));
+            T03 = _mm_loadl_epi64((__m128i*)(fenc + (i + 7) * fencstride));
+            T03 = _mm_unpacklo_epi32(T02, T03);
+            T03 = _mm_unpacklo_epi64(T01, T03);
+
+            T10 = _mm_loadl_epi64((__m128i*)(fref + (i + 4) * frefstride));
+            T11 = _mm_loadl_epi64((__m128i*)(fref + (i + 5) * frefstride));
+            T11 = _mm_unpacklo_epi32(T10, T11);
+            T12 = _mm_loadl_epi64((__m128i*)(fref + (i + 6) * frefstride));
+            T13 = _mm_loadl_epi64((__m128i*)(fref + (i + 7) * frefstride));
+            T13 = _mm_unpacklo_epi32(T12, T13);
+            T13 = _mm_unpacklo_epi64(T11, T13);
+
+            T20 = _mm_sad_epu8(T03, T13);
+            sum0 = _mm_add_epi32(sum0, T20);
         }
-
-        sum += extend_low(sad);
-        sad = 0;
     }
-
-    while (row++ < ly)
+    else
     {
-        m1.fromUint32(*(uint32_t*)fenc);
-        n1.fromUint32(*(uint32_t*)fref);
-        sad.addSumAbsDiff(m1, n1);
-
-        fenc += fencstride;
-        fref += frefstride;
+        for (int i = 0; i < ly; i += 4)
+        {
+            T00 = _mm_loadl_epi64((__m128i*)(fenc + (i + 0) * fencstride));
+            T01 = _mm_loadl_epi64((__m128i*)(fenc + (i + 1) * fencstride));
+            T01 = _mm_unpacklo_epi32(T00, T01);
+            T02 = _mm_loadl_epi64((__m128i*)(fenc + (i + 2) * fencstride));
+            T03 = _mm_loadl_epi64((__m128i*)(fenc + (i + 3) * fencstride));
+            T03 = _mm_unpacklo_epi32(T02, T03);
+            T03 = _mm_unpacklo_epi64(T01, T03);
+
+            T10 = _mm_loadl_epi64((__m128i*)(fref + (i + 0) * frefstride));
+            T11 = _mm_loadl_epi64((__m128i*)(fref + (i + 1) * frefstride));
+            T11 = _mm_unpacklo_epi32(T10, T11);
+            T12 = _mm_loadl_epi64((__m128i*)(fref + (i + 2) * frefstride));
+            T13 = _mm_loadl_epi64((__m128i*)(fref + (i + 3) * frefstride));
+            T13 = _mm_unpacklo_epi32(T12, T13);
+            T13 = _mm_unpacklo_epi64(T11, T13);
+
+            T20 = _mm_sad_epu8(T03, T13);
+            sum0 = _mm_add_epi32(sum0, T20);
+        }
     }
 
-    sum += extend_low(sad);
-    return horizontal_add(sum);
+    sum1 = _mm_shuffle_epi32(sum0, 2);
+    sum0 = _mm_add_epi32(sum0, sum1);
+    return _mm_extract_epi32(sum0, 0);
 }
 
+#else /* ifdef X86_64 */
+
+template<int ly>
+int sad_4(pixel * fenc, intptr_t fencstride, pixel * fref, intptr_t frefstride)
+{
+    assert((ly % 4) == 0);
+
+    __m64 sum0 = _mm_setzero_si64();
+
+    __m64 T00, T01, T02, T03;
+    __m64 T10, T11, T12, T13;
+    __m64 T20, T21, T22, T23;
+
+    if ((ly % 16) == 0)
+    {
+        for (int i = 0; i < ly; i += 16)
+        {
+            T00 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 0) * fencstride));
+            T01 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 1) * fencstride));
+            T02 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 2) * fencstride));
+            T03 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 3) * fencstride));
+
+            T10 = _mm_cvtsi32_si64(*(int*)(fref + (i + 0) * frefstride));
+            T11 = _mm_cvtsi32_si64(*(int*)(fref + (i + 1) * frefstride));
+            T12 = _mm_cvtsi32_si64(*(int*)(fref + (i + 2) * frefstride));
+            T13 = _mm_cvtsi32_si64(*(int*)(fref + (i + 3) * frefstride));
+
+            T20 = _mm_sad_pu8(T00, T10);
+            T21 = _mm_sad_pu8(T01, T11);
+            T22 = _mm_sad_pu8(T02, T12);
+            T23 = _mm_sad_pu8(T03, T13);
+
+            sum0 = _mm_add_pi16(sum0, T20);
+            sum0 = _mm_add_pi16(sum0, T21);
+            sum0 = _mm_add_pi16(sum0, T22);
+            sum0 = _mm_add_pi16(sum0, T23);
+
+            T00 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 4) * fencstride));
+            T01 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 5) * fencstride));
+            T02 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 6) * fencstride));
+            T03 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 7) * fencstride));
+
+            T10 = _mm_cvtsi32_si64(*(int*)(fref + (i + 4) * frefstride));
+            T11 = _mm_cvtsi32_si64(*(int*)(fref + (i + 5) * frefstride));
+            T12 = _mm_cvtsi32_si64(*(int*)(fref + (i + 6) * frefstride));
+            T13 = _mm_cvtsi32_si64(*(int*)(fref + (i + 7) * frefstride));
+
+            T20 = _mm_sad_pu8(T00, T10);
+            T21 = _mm_sad_pu8(T01, T11);
+            T22 = _mm_sad_pu8(T02, T12);
+            T23 = _mm_sad_pu8(T03, T13);
+
+            sum0 = _mm_add_pi16(sum0, T20);
+            sum0 = _mm_add_pi16(sum0, T21);
+            sum0 = _mm_add_pi16(sum0, T22);
+            sum0 = _mm_add_pi16(sum0, T23);
+
+            T00 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 8) * fencstride));
+            T01 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 9) * fencstride));
+            T02 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 10) * fencstride));
+            T03 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 11) * fencstride));
+
+            T10 = _mm_cvtsi32_si64(*(int*)(fref + (i + 8) * frefstride));
+            T11 = _mm_cvtsi32_si64(*(int*)(fref + (i + 9) * frefstride));
+            T12 = _mm_cvtsi32_si64(*(int*)(fref + (i + 10) * frefstride));
+            T13 = _mm_cvtsi32_si64(*(int*)(fref + (i + 11) * frefstride));
+
+            T20 = _mm_sad_pu8(T00, T10);
+            T21 = _mm_sad_pu8(T01, T11);
+            T22 = _mm_sad_pu8(T02, T12);
+            T23 = _mm_sad_pu8(T03, T13);
+
+            sum0 = _mm_add_pi16(sum0, T20);
+            sum0 = _mm_add_pi16(sum0, T21);
+            sum0 = _mm_add_pi16(sum0, T22);
+            sum0 = _mm_add_pi16(sum0, T23);
+
+            T00 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 12) * fencstride));
+            T01 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 13) * fencstride));
+            T02 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 14) * fencstride));
+            T03 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 15) * fencstride));
+
+            T10 = _mm_cvtsi32_si64(*(int*)(fref + (i + 12) * frefstride));
+            T11 = _mm_cvtsi32_si64(*(int*)(fref + (i + 13) * frefstride));
+            T12 = _mm_cvtsi32_si64(*(int*)(fref + (i + 14) * frefstride));
+            T13 = _mm_cvtsi32_si64(*(int*)(fref + (i + 15) * frefstride));
+
+            T20 = _mm_sad_pu8(T00, T10);
+            T21 = _mm_sad_pu8(T01, T11);
+            T22 = _mm_sad_pu8(T02, T12);
+            T23 = _mm_sad_pu8(T03, T13);
+
+            sum0 = _mm_add_pi16(sum0, T20);
+            sum0 = _mm_add_pi16(sum0, T21);
+            sum0 = _mm_add_pi16(sum0, T22);
+            sum0 = _mm_add_pi16(sum0, T23);
+        }
+    }
+    else if ((ly % 8) == 0)
+    {
+        for (int i = 0; i < ly; i += 8)
+        {
+            T00 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 0) * fencstride));
+            T01 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 1) * fencstride));
+            T02 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 2) * fencstride));
+            T03 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 3) * fencstride));
+
+            T10 = _mm_cvtsi32_si64(*(int*)(fref + (i + 0) * frefstride));
+            T11 = _mm_cvtsi32_si64(*(int*)(fref + (i + 1) * frefstride));
+            T12 = _mm_cvtsi32_si64(*(int*)(fref + (i + 2) * frefstride));
+            T13 = _mm_cvtsi32_si64(*(int*)(fref + (i + 3) * frefstride));
+
+            T20 = _mm_sad_pu8(T00, T10);
+            T21 = _mm_sad_pu8(T01, T11);
+            T22 = _mm_sad_pu8(T02, T12);
+            T23 = _mm_sad_pu8(T03, T13);
+
+            sum0 = _mm_add_pi16(sum0, T20);
+            sum0 = _mm_add_pi16(sum0, T21);
+            sum0 = _mm_add_pi16(sum0, T22);
+            sum0 = _mm_add_pi16(sum0, T23);
+
+            T00 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 4) * fencstride));
+            T01 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 5) * fencstride));
+            T02 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 6) * fencstride));
+            T03 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 7) * fencstride));
+
+            T10 = _mm_cvtsi32_si64(*(int*)(fref + (i + 4) * frefstride));
+            T11 = _mm_cvtsi32_si64(*(int*)(fref + (i + 5) * frefstride));
+            T12 = _mm_cvtsi32_si64(*(int*)(fref + (i + 6) * frefstride));
+            T13 = _mm_cvtsi32_si64(*(int*)(fref + (i + 7) * frefstride));
+
+            T20 = _mm_sad_pu8(T00, T10);
+            T21 = _mm_sad_pu8(T01, T11);
+            T22 = _mm_sad_pu8(T02, T12);
+            T23 = _mm_sad_pu8(T03, T13);
+
+            sum0 = _mm_add_pi16(sum0, T20);
+            sum0 = _mm_add_pi16(sum0, T21);
+            sum0 = _mm_add_pi16(sum0, T22);
+            sum0 = _mm_add_pi16(sum0, T23);
+        }
+    }
+    else
+    {
+        for (int i = 0; i < ly; i += 4)
+        {
+            T00 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 0) * fencstride));
+            T01 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 1) * fencstride));
+            T02 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 2) * fencstride));
+            T03 = _mm_cvtsi32_si64(*(int*)(fenc + (i + 3) * fencstride));
+
+            T10 = _mm_cvtsi32_si64(*(int*)(fref + (i + 0) * frefstride));
+            T11 = _mm_cvtsi32_si64(*(int*)(fref + (i + 1) * frefstride));
+            T12 = _mm_cvtsi32_si64(*(int*)(fref + (i + 2) * frefstride));
+            T13 = _mm_cvtsi32_si64(*(int*)(fref + (i + 3) * frefstride));
+
+            T20 = _mm_sad_pu8(T00, T10);
+            T21 = _mm_sad_pu8(T01, T11);
+            T22 = _mm_sad_pu8(T02, T12);
+            T23 = _mm_sad_pu8(T03, T13);
+
+            sum0 = _mm_add_pi16(sum0, T20);
+            sum0 = _mm_add_pi16(sum0, T21);
+            sum0 = _mm_add_pi16(sum0, T22);
+            sum0 = _mm_add_pi16(sum0, T23);
+        }
+    }
+    // 8 * 255 -> 11 bits x 8 -> 14 bits
+    int sum = _m_to_int(sum0);
+    return sum;
+}
+
+#endif /* ifdef X86_64 */
+
 #ifdef X86_64
 template<int ly>
 int sad_8(pixel * fenc, intptr_t fencstride, pixel * fref, intptr_t frefstride)


More information about the x265-devel mailing list