[x265] [PATCH 11 of 29] intrapred: updated asm and unit test code for intra_planar 4x4, 8x8, 16x16 and 32x32

dnyaneshwar at multicorewareinc.com dnyaneshwar at multicorewareinc.com
Tue Jan 13 08:11:19 CET 2015


# HG changeset patch
# User Dnyaneshwar G <dnyaneshwar at multicorewareinc.com>
# Date 1419339736 -19800
#      Tue Dec 23 18:32:16 2014 +0530
# Node ID cbeae41ef5e91685ea7126883c269538dace424d
# Parent  b0ffbe3c3bb33eaa898f10bb3ff4086c65605565
intrapred: updated asm and unit test code for intra_planar 4x4, 8x8, 16x16 and 32x32

performance improvement over previous asm code:
4x4: 246c -> 208c
8x8: 443c -> 338c
16x16: 1359c -> 828c
32x32: 5170c -> 2937c

diff -r b0ffbe3c3bb3 -r cbeae41ef5e9 source/common/x86/asm-primitives.cpp
--- a/source/common/x86/asm-primitives.cpp	Thu Dec 18 17:59:05 2014 +0530
+++ b/source/common/x86/asm-primitives.cpp	Tue Dec 23 18:32:16 2014 +0530
@@ -1696,6 +1696,11 @@
         p.intra_pred[0][BLOCK_16x16] = x265_intra_pred_planar16_sse4;
         p.intra_pred[0][BLOCK_32x32] = x265_intra_pred_planar32_sse4;
 
+        p.intra_pred_new[0][BLOCK_4x4] = x265_intra_pred_planar4_new_sse4;
+        p.intra_pred_new[0][BLOCK_8x8] = x265_intra_pred_planar8_new_sse4;
+        p.intra_pred_new[0][BLOCK_16x16] = x265_intra_pred_planar16_new_sse4;
+        p.intra_pred_new[0][BLOCK_32x32] = x265_intra_pred_planar32_new_sse4;
+
         p.intra_pred_allangs[BLOCK_4x4] = x265_all_angs_pred_4x4_sse4;
         p.intra_pred_allangs[BLOCK_8x8] = x265_all_angs_pred_8x8_sse4;
         p.intra_pred_allangs[BLOCK_16x16] = x265_all_angs_pred_16x16_sse4;
diff -r b0ffbe3c3bb3 -r cbeae41ef5e9 source/common/x86/intrapred.h
--- a/source/common/x86/intrapred.h	Thu Dec 18 17:59:05 2014 +0530
+++ b/source/common/x86/intrapred.h	Tue Dec 23 18:32:16 2014 +0530
@@ -41,6 +41,11 @@
 void x265_intra_pred_planar16_sse4(pixel* dst, intptr_t dstStride, pixel* above, pixel* left, int, int);
 void x265_intra_pred_planar32_sse4(pixel* dst, intptr_t dstStride, pixel* above, pixel* left, int, int);
 
+void x265_intra_pred_planar4_new_sse4(pixel* dst, intptr_t dstStride, pixel* above, int, int);
+void x265_intra_pred_planar8_new_sse4(pixel* dst, intptr_t dstStride, pixel* above, int, int);
+void x265_intra_pred_planar16_new_sse4(pixel* dst, intptr_t dstStride, pixel* above, int, int);
+void x265_intra_pred_planar32_new_sse4(pixel* dst, intptr_t dstStride, pixel* above, int, int);
+
 #define DECL_ANG(bsize, mode, cpu) \
     void x265_intra_pred_ang ## bsize ## _ ## mode ## _ ## cpu(pixel * dst, intptr_t dstStride, pixel * refLeft, pixel * refAbove, int dirMode, int bFilter);
 
diff -r b0ffbe3c3bb3 -r cbeae41ef5e9 source/common/x86/intrapred8.asm
--- a/source/common/x86/intrapred8.asm	Thu Dec 18 17:59:05 2014 +0530
+++ b/source/common/x86/intrapred8.asm	Tue Dec 23 18:32:16 2014 +0530
@@ -54,6 +54,17 @@
 c_mode16_18:    db 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
 tab_S2:         db 0, 1, 3, 5, 7, 9, 11, 13, 0, 0, 0, 0, 0, 0, 0, 0
 
+;; (blkSize - 1 - x)
+pw_planar4_0:         dw 3,  2,  1,  0,  3,  2,  1,  0
+pw_planar4_1:         dw 3,  3,  3,  3,  3,  3,  3,  3
+pw_planar8_0:         dw 7,  6,  5,  4,  3,  2,  1,  0
+pw_planar8_1:         dw 7,  7,  7,  7,  7,  7,  7,  7
+pw_planar16_0:        dw 15, 14, 13, 12, 11, 10, 9,  8
+pw_planar16_1:        dw 15, 15, 15, 15, 15, 15, 15, 15
+pw_planar32_1:        dw 31, 31, 31, 31, 31, 31, 31, 31
+pw_planar32_L:        dw 31, 30, 29, 28, 27, 26, 25, 24
+pw_planar32_H:        dw 23, 22, 21, 20, 19, 18, 17, 16
+
 const ang_table
 %assign x 0
 %rep 32
@@ -63,7 +74,10 @@
 
 SECTION .text
 
+cextern pw_4
 cextern pw_8
+cextern pw_16
+cextern pw_32
 cextern pw_1024
 cextern pb_unpackbd1
 cextern multiL
@@ -465,6 +479,60 @@
 
     RET
 
+;---------------------------------------------------------------------------------------
+; void intra_pred_planar(pixel* dst, intptr_t dstStride, pixel*srcPix, int, int filter)
+;---------------------------------------------------------------------------------------
+INIT_XMM sse4
+cglobal intra_pred_planar4_new, 3,3,7
+    pmovzxbw        m1, [r2 + 1]
+    pmovzxbw        m2, [r2 + 9]
+    pshufhw         m3, m1, 0               ; topRight
+    pshufd          m3, m3, 0xAA
+    pshufhw         m4, m2, 0               ; bottomLeft
+    pshufd          m4, m4, 0xAA
+
+    pmullw          m3, [multi_2Row]        ; (x + 1) * topRight
+    pmullw          m0, m1, [pw_planar4_1]  ; (blkSize - 1 - y) * above[x]
+    mova            m6, [pw_planar4_0]
+    paddw           m3, [pw_4]
+    paddw           m3, m4
+    paddw           m3, m0
+    psubw           m4, m1
+
+    pshuflw         m5, m2, 0
+    pmullw          m5, m6
+    paddw           m5, m3
+    paddw           m3, m4
+    psraw           m5, 3
+    packuswb        m5, m5
+    movd            [r0], m5
+
+    pshuflw         m5, m2, 01010101b
+    pmullw          m5, m6
+    paddw           m5, m3
+    paddw           m3, m4
+    psraw           m5, 3
+    packuswb        m5, m5
+    movd            [r0 + r1], m5
+    lea             r0, [r0 + 2 * r1]
+
+    pshuflw         m5, m2, 10101010b
+    pmullw          m5, m6
+    paddw           m5, m3
+    paddw           m3, m4
+    psraw           m5, 3
+    packuswb        m5, m5
+    movd            [r0], m5
+
+    pshuflw         m5, m2, 11111111b
+    pmullw          m5, m6
+    paddw           m5, m3
+    paddw           m3, m4
+    psraw           m5, 3
+    packuswb        m5, m5
+    movd            [r0 + r1], m5
+    RET
+
 ;-----------------------------------------------------------------------------------------------------------
 ; void intra_pred_planar(pixel* dst, intptr_t dstStride, pixel* left, pixel* above, int dirMode, int filter)
 ;-----------------------------------------------------------------------------------------------------------
@@ -525,9 +593,59 @@
     PRED_PLANAR_ROW8 5
     PRED_PLANAR_ROW8 6
     PRED_PLANAR_ROW8 7
-
-    RET
-
+    RET
+
+;---------------------------------------------------------------------------------------
+; void intra_pred_planar(pixel* dst, intptr_t dstStride, pixel*srcPix, int, int filter)
+;---------------------------------------------------------------------------------------
+INIT_XMM sse4
+cglobal intra_pred_planar8_new, 3,3,7
+    pmovzxbw        m1, [r2 + 1]
+    pmovzxbw        m2, [r2 + 17]
+
+    movd            m3, [r2 + 9]            ; topRight   = above[8];
+    movd            m4, [r2 + 25]           ; bottomLeft = left[8];
+
+    pxor            m0, m0
+    pshufb          m3, m0
+    pshufb          m4, m0
+    punpcklbw       m3, m0                  ; v_topRight
+    punpcklbw       m4, m0                  ; v_bottomLeft
+
+    pmullw          m3, [multiL]            ; (x + 1) * topRight
+    pmullw          m0, m1, [pw_planar8_1]  ; (blkSize - 1 - y) * above[x]
+    mova            m6, [pw_planar8_0]
+    paddw           m3, [pw_8]
+    paddw           m3, m4
+    paddw           m3, m0
+    psubw           m4, m1
+
+%macro INTRA_PRED_PLANAR8 1
+%if (%1 < 4)
+    pshuflw         m5, m2, 0x55 * %1
+    pshufd          m5, m5, 0
+%else
+    pshufhw         m5, m2, 0x55 * (%1 - 4)
+    pshufd          m5, m5, 0xAA
+%endif
+    pmullw          m5, m6
+    paddw           m5, m3
+    paddw           m3, m4
+    psraw           m5, 4
+    packuswb        m5, m5
+    movh            [r0], m5
+    lea             r0, [r0 + r1]
+%endmacro
+
+    INTRA_PRED_PLANAR8 0
+    INTRA_PRED_PLANAR8 1
+    INTRA_PRED_PLANAR8 2
+    INTRA_PRED_PLANAR8 3
+    INTRA_PRED_PLANAR8 4
+    INTRA_PRED_PLANAR8 5
+    INTRA_PRED_PLANAR8 6
+    INTRA_PRED_PLANAR8 7
+    RET
 
 ;-----------------------------------------------------------------------------------------------------------
 ; void intra_pred_planar(pixel* dst, intptr_t dstStride, pixel* left, pixel* above, int dirMode, int filter)
@@ -602,6 +720,194 @@
 
     RET
 
+;---------------------------------------------------------------------------------------
+; void intra_pred_planar(pixel* dst, intptr_t dstStride, pixel*srcPix, int, int filter)
+;---------------------------------------------------------------------------------------
+INIT_XMM sse4
+cglobal intra_pred_planar16_new, 3,3,8
+    pmovzxbw        m2, [r2 + 1]
+    pmovzxbw        m7, [r2 + 9]
+
+    movd            m3, [r2 + 17]               ; topRight   = above[16]
+    movd            m6, [r2 + 49]               ; bottomLeft = left[16]
+
+    pxor            m0, m0
+    pshufb          m3, m0
+    pshufb          m6, m0
+    punpcklbw       m3, m0                      ; v_topRight
+    punpcklbw       m6, m0                      ; v_bottomLeft
+
+    pmullw          m4, m3, [multiH]            ; (x + 1) * topRight
+    pmullw          m3, [multiL]                ; (x + 1) * topRight
+    pmullw          m1, m2, [pw_planar16_1]     ; (blkSize - 1 - y) * above[x]
+    pmullw          m5, m7, [pw_planar16_1]     ; (blkSize - 1 - y) * above[x]
+    paddw           m4, [pw_16]
+    paddw           m3, [pw_16]
+    paddw           m4, m6
+    paddw           m3, m6
+    paddw           m4, m5
+    paddw           m3, m1
+    psubw           m1, m6, m7
+    psubw           m6, m2
+
+    pmovzxbw        m2, [r2 + 33]
+    pmovzxbw        m7, [r2 + 41]
+
+%macro INTRA_PRED_PLANAR16 1
+%if (%1 < 4)
+    pshuflw         m5, m2, 0x55 * %1
+    pshufd          m5, m5, 0
+%else
+%if (%1 < 8)
+    pshufhw         m5, m2, 0x55 * (%1 - 4)
+    pshufd          m5, m5, 0xAA
+%else
+%if (%1 < 12)
+    pshuflw         m5, m7, 0x55 * (%1 - 8)
+    pshufd          m5, m5, 0
+%else
+    pshufhw         m5, m7, 0x55 * (%1 - 12)
+    pshufd          m5, m5, 0xAA
+%endif
+%endif
+%endif
+    pmullw          m0, m5, [pw_planar8_0]
+    pmullw          m5, [pw_planar16_0]
+    paddw           m0, m4
+    paddw           m5, m3
+    paddw           m3, m6
+    paddw           m4, m1
+    psraw           m5, 5
+    psraw           m0, 5
+    packuswb        m5, m0
+    movu            [r0], m5
+    lea             r0, [r0 + r1]
+%endmacro
+
+    INTRA_PRED_PLANAR16 0
+    INTRA_PRED_PLANAR16 1
+    INTRA_PRED_PLANAR16 2
+    INTRA_PRED_PLANAR16 3
+    INTRA_PRED_PLANAR16 4
+    INTRA_PRED_PLANAR16 5
+    INTRA_PRED_PLANAR16 6
+    INTRA_PRED_PLANAR16 7
+    INTRA_PRED_PLANAR16 8
+    INTRA_PRED_PLANAR16 9
+    INTRA_PRED_PLANAR16 10
+    INTRA_PRED_PLANAR16 11
+    INTRA_PRED_PLANAR16 12
+    INTRA_PRED_PLANAR16 13
+    INTRA_PRED_PLANAR16 14
+    INTRA_PRED_PLANAR16 15
+    RET
+
+;---------------------------------------------------------------------------------------
+; void intra_pred_planar(pixel* dst, intptr_t dstStride, pixel*srcPix, int, int filter)
+;---------------------------------------------------------------------------------------
+INIT_XMM sse4
+%if ARCH_X86_64 == 1
+cglobal intra_pred_planar32_new, 3,4,12
+%else
+cglobal intra_pred_planar32_new, 3,4,8,0-(4*mmsize)
+  %define           m8  [rsp + 0 * mmsize]
+  %define           m9  [rsp + 1 * mmsize]
+  %define           m10 [rsp + 2 * mmsize]
+  %define           m11 [rsp + 3 * mmsize]
+%endif
+    movd            m3, [r2 + 33]               ; topRight   = above[32]
+
+    pxor            m7, m7
+    pshufb          m3, m7
+    punpcklbw       m3, m7                      ; v_topRight
+
+    pmullw          m0, m3, [multiL]            ; (x + 1) * topRight
+    pmullw          m1, m3, [multiH]            ; (x + 1) * topRight
+    pmullw          m2, m3, [multiH2]           ; (x + 1) * topRight
+    pmullw          m3, [multiH3]               ; (x + 1) * topRight
+
+    movd            m6, [r2 + 97]               ; bottomLeft = left[32]
+    pshufb          m6, m7
+    punpcklbw       m6, m7                      ; v_bottomLeft
+
+    paddw           m0, m6
+    paddw           m1, m6
+    paddw           m2, m6
+    paddw           m3, m6
+    paddw           m0, [pw_32]
+    paddw           m1, [pw_32]
+    paddw           m2, [pw_32]
+    paddw           m3, [pw_32]
+
+    pmovzxbw        m4, [r2 + 1]
+    pmullw          m5, m4, [pw_planar32_1]
+    paddw           m0, m5
+    psubw           m5, m6, m4
+    mova            m8, m5
+
+    pmovzxbw        m4, [r2 + 9]
+    pmullw          m5, m4, [pw_planar32_1]
+    paddw           m1, m5
+    psubw           m5, m6, m4
+    mova            m9, m5
+
+    pmovzxbw        m4, [r2 + 17]
+    pmullw          m5, m4, [pw_planar32_1]
+    paddw           m2, m5
+    psubw           m5, m6, m4
+    mova            m10, m5
+
+    pmovzxbw        m4, [r2 + 25]
+    pmullw          m5, m4, [pw_planar32_1]
+    paddw           m3, m5
+    psubw           m5, m6, m4
+    mova            m11, m5
+    add             r2, 65                      ; (2 * blkSize + 1)
+
+%macro INTRA_PRED_PLANAR32 0
+    movd            m4, [r2]
+    pshufb          m4, m7
+    punpcklbw       m4, m7
+
+    pmullw          m5, m4, [pw_planar32_L]
+    pmullw          m6, m4, [pw_planar32_H]
+    paddw           m5, m0
+    paddw           m6, m1
+    paddw           m0, m8
+    paddw           m1, m9
+    psraw           m5, 6
+    psraw           m6, 6
+    packuswb        m5, m6
+    movu            [r0], m5
+
+    pmullw          m5, m4, [pw_planar16_0]
+    pmullw          m4, [pw_planar8_0]
+    paddw           m5, m2
+    paddw           m4, m3
+    paddw           m2, m10
+    paddw           m3, m11
+    psraw           m5, 6
+    psraw           m4, 6
+    packuswb        m5, m4
+    movu            [r0 + 16], m5
+
+    lea             r0, [r0 + r1]
+    inc             r2
+%endmacro
+
+    mov             r3, 4
+.loop:
+    INTRA_PRED_PLANAR32
+    INTRA_PRED_PLANAR32
+    INTRA_PRED_PLANAR32
+    INTRA_PRED_PLANAR32
+    INTRA_PRED_PLANAR32
+    INTRA_PRED_PLANAR32
+    INTRA_PRED_PLANAR32
+    INTRA_PRED_PLANAR32
+    dec             r3
+    jnz             .loop
+    RET
 
 ;-----------------------------------------------------------------------------------------------------------
 ; void intra_pred_planar(pixel* dst, intptr_t dstStride, pixel* left, pixel* above, int dirMode, int filter)
diff -r b0ffbe3c3bb3 -r cbeae41ef5e9 source/test/intrapredharness.cpp
--- a/source/test/intrapredharness.cpp	Thu Dec 18 17:59:05 2014 +0530
+++ b/source/test/intrapredharness.cpp	Tue Dec 23 18:32:16 2014 +0530
@@ -137,6 +137,34 @@
     return true;
 }
 
+bool IntraPredHarness::check_planar_primitive(intra_pred_new_t ref, intra_pred_new_t opt, int width)
+{
+    int j = Predict::ADI_BUF_STRIDE;
+    intptr_t stride = FENC_STRIDE;
+
+#if _DEBUG
+    memset(pixel_out_vec, 0xCD, OUTPUT_SIZE);
+    memset(pixel_out_c, 0xCD, OUTPUT_SIZE);
+#endif
+
+    for (int i = 0; i <= 100; i++)
+    {
+        ref(pixel_out_c, stride, pixel_buff + j - Predict::ADI_BUF_STRIDE, 0, 0);
+        checked(opt, pixel_out_vec, stride, pixel_buff + j - Predict::ADI_BUF_STRIDE, 0, 0);
+
+        for (int k = 0; k < width; k++)
+        {
+            if (memcmp(pixel_out_vec + k * FENC_STRIDE, pixel_out_c + k * FENC_STRIDE, width * sizeof(pixel)))
+                return false;
+        }
+
+        reportfail();
+        j += FENC_STRIDE;
+    }
+
+    return true;
+}
+
 bool IntraPredHarness::check_angular_primitive(const intra_pred_t ref[][NUM_TR_SIZE], const intra_pred_t opt[][NUM_TR_SIZE])
 {
     int j = Predict::ADI_BUF_STRIDE;
@@ -245,6 +273,15 @@
                 return false;
             }
         }
+        if (opt.intra_pred_new[0][i])
+        {
+            const int size = (1 << (i + 2));
+            if (!check_planar_primitive(ref.intra_pred_new[0][i], opt.intra_pred_new[0][i], size))
+            {
+                printf("intra_planar %dx%d failed\n", size, size);
+                return false;
+            }
+        }
         if (opt.intra_pred_new[1][i])
         {
             const int size = (1 << (i + 2));
@@ -283,6 +320,12 @@
     for (int i = BLOCK_4x4; i <= BLOCK_32x32; i++)
     {
         const int size = (1 << (i + 2));
+        if (opt.intra_pred_new[0][i])
+        {
+            printf("intra_planar_new %2dx%d", size, size);
+            REPORT_SPEEDUP(opt.intra_pred_new[0][i], ref.intra_pred_new[0][i],
+                           pixel_out_vec, FENC_STRIDE, pixel_buff + srcStride, 0, 0);
+        }
         if (opt.intra_pred[0][i])
         {
             printf("intra_planar %2dx%d", size, size);
diff -r b0ffbe3c3bb3 -r cbeae41ef5e9 source/test/intrapredharness.h
--- a/source/test/intrapredharness.h	Thu Dec 18 17:59:05 2014 +0530
+++ b/source/test/intrapredharness.h	Tue Dec 23 18:32:16 2014 +0530
@@ -44,6 +44,7 @@
     bool check_dc_primitive(intra_pred_t ref, intra_pred_t opt, int width);
     bool check_dc_primitive(intra_pred_new_t ref, intra_pred_new_t opt, int width);
     bool check_planar_primitive(intra_pred_t ref, intra_pred_t opt, int width);
+    bool check_planar_primitive(intra_pred_new_t ref, intra_pred_new_t opt, int width);
     bool check_angular_primitive(const intra_pred_t ref[][NUM_TR_SIZE], const intra_pred_t opt[][NUM_TR_SIZE]);
     bool check_allangs_primitive(const intra_allangs_t ref[], const intra_allangs_t opt[]);
 


More information about the x265-devel mailing list