[FFmpeg-devel] [PATCH 2/2] tta/x86: tta/x86: add ff_ttafilter_process_dec_{ssse3, sse4}

James Almer jamrial at gmail.com
Tue Feb 11 00:48:42 CET 2014


1183 decicycles in ttafilter_process_dec_c, 16777114 runs, 102 skips
507 decicycles in ff_ttafilter_process_dec_ssse3, 16777143 runs, 73 skips
455 decicycles in ff_ttafilter_process_dec_sse4, 16777149 runs, 67 skips

Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/ttadsp.c          |   3 +
 libavcodec/ttadsp.h          |   1 +
 libavcodec/x86/Makefile      |   2 +
 libavcodec/x86/ttadsp.asm    | 181 +++++++++++++++++++++++++++++++++++++++++++
 libavcodec/x86/ttadsp_init.c |  38 +++++++++
 5 files changed, 225 insertions(+)
 create mode 100644 libavcodec/x86/ttadsp.asm
 create mode 100644 libavcodec/x86/ttadsp_init.c

diff --git a/libavcodec/ttadsp.c b/libavcodec/ttadsp.c
index 6abf8b0..1dd61f6 100644
--- a/libavcodec/ttadsp.c
+++ b/libavcodec/ttadsp.c
@@ -51,4 +51,7 @@ static void ttafilter_process_dec_c(TTAFilter *f, int32_t *in) {
 av_cold void ff_ttadsp_init(TTADSPContext *c)
 {
     c->ttafilter_process_dec = ttafilter_process_dec_c;
+
+    if (ARCH_X86)
+        ff_ttadsp_init_x86(c);
 }
diff --git a/libavcodec/ttadsp.h b/libavcodec/ttadsp.h
index 1435e49..2b36c8a 100644
--- a/libavcodec/ttadsp.h
+++ b/libavcodec/ttadsp.h
@@ -27,5 +27,6 @@ typedef struct TTADSPContext {
 } TTADSPContext;
 
 void ff_ttadsp_init(TTADSPContext *c);
+void ff_ttadsp_init_x86(TTADSPContext *c);
 
 #endif /* AVCODEC_TTADSP_H */
diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile
index 52ee2a8..07f2963 100644
--- a/libavcodec/x86/Makefile
+++ b/libavcodec/x86/Makefile
@@ -33,6 +33,7 @@ OBJS-$(CONFIG_RV30_DECODER)            += x86/rv34dsp_init.o
 OBJS-$(CONFIG_RV40_DECODER)            += x86/rv34dsp_init.o            \
                                           x86/rv40dsp_init.o
 OBJS-$(CONFIG_V210_DECODER)            += x86/v210-init.o
+OBJS-$(CONFIG_TTA_DECODER)             += x86/ttadsp_init.o
 OBJS-$(CONFIG_TRUEHD_DECODER)          += x86/mlpdsp.o
 OBJS-$(CONFIG_VC1_DECODER)             += x86/vc1dsp_init.o
 OBJS-$(CONFIG_VIDEODSP)                += x86/videodsp_init.o
@@ -99,6 +100,7 @@ YASM-OBJS-$(CONFIG_PRORES_LGPL_DECODER) += x86/proresdsp.o
 YASM-OBJS-$(CONFIG_RV30_DECODER)       += x86/rv34dsp.o
 YASM-OBJS-$(CONFIG_RV40_DECODER)       += x86/rv34dsp.o                 \
                                           x86/rv40dsp.o
+YASM-OBJS-$(CONFIG_TTA_DECODER)        += x86/ttadsp.o
 YASM-OBJS-$(CONFIG_V210_DECODER)       += x86/v210.o
 YASM-OBJS-$(CONFIG_VC1_DECODER)        += x86/vc1dsp.o
 YASM-OBJS-$(CONFIG_VIDEODSP)           += x86/videodsp.o
diff --git a/libavcodec/x86/ttadsp.asm b/libavcodec/x86/ttadsp.asm
new file mode 100644
index 0000000..42f62c6
--- /dev/null
+++ b/libavcodec/x86/ttadsp.asm
@@ -0,0 +1,181 @@
+;******************************************************************************
+;* TTA DSP SIMD optimizations
+;*
+;* Copyright (C) 2014 James Almer
+;*
+;* This file is part of FFmpeg.
+;*
+;* FFmpeg is free software; you can redistribute it and/or
+;* modify it under the terms of the GNU Lesser General Public
+;* License as published by the Free Software Foundation; either
+;* version 2.1 of the License, or (at your option) any later version.
+;*
+;* FFmpeg is distributed in the hope that it will be useful,
+;* but WITHOUT ANY WARRANTY; without even the implied warranty of
+;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;* Lesser General Public License for more details.
+;*
+;* You should have received a copy of the GNU Lesser General Public
+;* License along with FFmpeg; if not, write to the Free Software
+;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+;******************************************************************************
+
+%include "libavutil/x86/x86util.asm"
+
+SECTION_RODATA
+
+pd_n0113: dd ~0, ~1, ~1, ~3
+pd_1224: dd 1, 2, 2, 4
+pd_m1:   times 4 dd -1
+
+SECTION .text
+
+INIT_XMM ssse3
+cglobal ttafilter_process_dec, 2,2,8, filter, in
+    mova       m2, [filterq + 0xc ]
+    mova       m3, [filterq + 0x1c]
+    mova       m4, [filterq + 0x4c]
+    mova       m5, [filterq + 0x5c]
+
+    movd       m6, [filterq + 0x8 ]
+    pshufd     m6, m6, 0
+    psignd     m0, m4, m6
+    psignd     m1, m5, m6
+    paddd      m2, m0
+    paddd      m3, m1
+    mova       [filterq + 0xc ], m2
+    mova       [filterq + 0x1c], m3
+
+    mova       m0, [filterq + 0x8c]
+    mova       m1, [filterq + 0x9c]
+
+    pshufd     m6, m0, 0xb1
+    pshufd     m7, m2, 0xb1
+    pmuludq    m6, m7
+    pshufd     m6, m6, 0xd8
+    pmuludq    m7, m0, m2
+    pshufd     m7, m7, 0xd8
+    punpckldq  m6, m7
+
+    pshufd     m2, m1, 0xb1
+    pshufd     m7, m3, 0xb1
+    pmuludq    m2, m7
+    pshufd     m2, m2, 0xd8
+    pmuludq    m7, m1, m3
+    pshufd     m7, m7, 0xd8
+    punpckldq  m7, m2
+
+    paddd      m6, m7
+
+    punpckhqdq m7, m6, m6
+    paddd      m6, m7
+
+    movd       m7, [filterq + 0x4]
+    paddd      m7, m6
+    pshufd     m6, m6, 0x1
+    paddd      m7, m6
+
+    psrldq     m4, 4
+    pslldq     m5, 12
+    por        m4, m5
+
+    psrldq     m0, 4
+    pslldq     m6, m1, 12
+    por        m0, m6
+
+    psrad      m5, m1, 30
+    por        m5, [pd_1224]
+    pand       m5, [pd_n0113]
+
+    mova       [filterq + 0x8c], m0
+    mova       [filterq + 0x4c], m4
+    mova       [filterq + 0x5c], m5
+    movd       m6, [ind]
+    movd       [filterq + 0x8], m6
+
+    movd       m2, [filterq]
+    psrad      m7, m2
+    paddd      m6, m7
+    movd       [ind], m6
+
+    psignd     m1, [pd_m1]
+    psrldq     m1, 4
+    pslldq     m6, 12
+    pshufd     m6, m6, 0xf0
+    paddd      m1, m6
+    psrldq     m6, m1, 4
+    pshufd     m6, m6, 0xf4
+    paddd      m1, m6
+    psrldq     m6, 4
+    paddd      m1, m6
+    mova       [filterq + 0x9c], m1
+    RET
+
+INIT_XMM sse4
+cglobal ttafilter_process_dec, 2,2,7, filter, in
+    mova       m2, [filterq + 0xc ]
+    mova       m3, [filterq + 0x1c]
+    mova       m4, [filterq + 0x4c]
+    mova       m5, [filterq + 0x5c]
+
+    movd       m6, [filterq + 0x8 ] ; if (filter->error < 0) {
+    pshufd     m6, m6, 0            ;     for (int i = 0; i < 8; i++)
+    psignd     m0, m4, m6           ;         filter->qm[i] -= filter->dx[i];
+    psignd     m1, m5, m6           ; } else if (filter->error > 0) {
+    paddd      m2, m0               ;     for (int i = 0; i < 8; i++)
+    paddd      m3, m1               ;         filter->qm[i] += filter->dx[i];
+    mova       [filterq + 0xc ], m2 ; }
+    mova       [filterq + 0x1c], m3 ;
+
+    mova       m0, [filterq + 0x8c]
+    mova       m1, [filterq + 0x9c]
+
+    ; Using horizontal add (phaddd) seems to be slower than shuffling stuff around
+    pmulld     m2, m0               ;
+    pmulld     m3, m1               ; int sum = filter->round +
+    paddd      m2, m3               ;           filter->dl[0] * filter->qm[0] +
+                                    ;           filter->dl[1] * filter->qm[1] +
+    punpckhqdq m3, m2, m2           ;           filter->dl[2] * filter->qm[2] +
+    paddd      m2, m3               ;           filter->dl[3] * filter->qm[3] +
+                                    ;           filter->dl[4] * filter->qm[4] +
+    movd       m3, [filterq + 0x4]  ;           filter->dl[5] * filter->qm[5] +
+    paddd      m3, m2               ;           filter->dl[6] * filter->qm[6] +
+    pshufd     m2, m2, 0x1          ;           filter->dl[7] * filter->qm[7];
+    paddd      m3, m2               ;
+
+    psrldq     m4, 4                ; filter->dx[0] = filter->dx[1]; filter->dx[1] = filter->dx[2];
+    pslldq     m5, 12               ; filter->dx[2] = filter->dx[3]; filter->dx[3] = filter->dx[4];
+    por        m4, m5               ;
+
+    psrldq     m0, 4                ; filter->dl[0] = filter->dl[1]; filter->dl[1] = filter->dl[2];
+    pslldq     m2, m1, 12           ; filter->dl[2] = filter->dl[3]; filter->dl[3] = filter->dl[4];
+    por        m0, m2               ;
+
+    psrad      m5, m1, 30           ; filter->dx[4] = ((filter->dl[4] >> 30) | 1);
+    por        m5, [pd_1224]        ; filter->dx[5] = ((filter->dl[5] >> 30) | 2) & ~1;
+    pand       m5, [pd_n0113]       ; filter->dx[6] = ((filter->dl[6] >> 30) | 2) & ~1;
+                                    ; filter->dx[7] = ((filter->dl[7] >> 30) | 4) & ~3;
+
+    mova       [filterq + 0x8c], m0
+    mova       [filterq + 0x4c], m4
+    mova       [filterq + 0x5c], m5
+    movd       m0, [ind]            ; filter->error = *in;
+    movd       [filterq + 0x8 ], m0 ;
+
+    movd       m2, [filterq]        ; *in += (sum >> filter->shift);
+    psrad      m3, m2               ;
+    paddd      m0, m3               ;
+    movd       [ind], m0            ;
+
+    psignd     m1, [pd_m1]          ;
+    psrldq     m1, 4                ;
+    pslldq     m0, 12               ; filter->dl[4] = -filter->dl[5];
+    pshufd     m0, m0, 0xf0         ; filter->dl[5] = -filter->dl[6];
+    paddd      m1, m0               ; filter->dl[6] = *in - filter->dl[7];
+    psrldq     m0, m1, 4            ; filter->dl[7] = *in;
+    pshufd     m0, m0, 0xf4         ; filter->dl[5] += filter->dl[6];
+    paddd      m1, m0               ; filter->dl[4] += filter->dl[5];
+    psrldq     m0, 4                ;
+    paddd      m1, m0               ;
+    mova       [filterq + 0x9c], m1 ;
+    RET
diff --git a/libavcodec/x86/ttadsp_init.c b/libavcodec/x86/ttadsp_init.c
new file mode 100644
index 0000000..652f1d1
--- /dev/null
+++ b/libavcodec/x86/ttadsp_init.c
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2014 James Almer
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavcodec/ttadsp.h"
+#include "libavutil/x86/cpu.h"
+#include "config.h"
+
+void ff_ttafilter_process_dec_ssse3(TTAFilter *f, int32_t *in);
+void ff_ttafilter_process_dec_sse4(TTAFilter *f, int32_t *in);
+
+av_cold void ff_ttadsp_init_x86(TTADSPContext *c)
+{
+#if HAVE_YASM
+    int cpu_flags = av_get_cpu_flags();
+
+    if (EXTERNAL_SSSE3(cpu_flags))
+        c->ttafilter_process_dec = ff_ttafilter_process_dec_ssse3;
+    if (EXTERNAL_SSE4(cpu_flags))
+        c->ttafilter_process_dec = ff_ttafilter_process_dec_sse4;
+#endif
+}
-- 
1.8.3.2



More information about the ffmpeg-devel mailing list