[FFmpeg-devel] [PATCH 2/3] x86/synth_filter: add synth_filter_avx

James Almer jamrial at gmail.com
Sat Mar 1 04:32:08 CET 2014


About 30 cycles faster than SSE2 on Sandy Bridge.

Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/x86/dcadsp.asm    | 31 +++++++++++++++++++++----------
 libavcodec/x86/dcadsp_init.c |  4 ++++
 2 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/libavcodec/x86/dcadsp.asm b/libavcodec/x86/dcadsp.asm
index 63d771e..15586b8 100644
--- a/libavcodec/x86/dcadsp.asm
+++ b/libavcodec/x86/dcadsp.asm
@@ -199,11 +199,15 @@ INIT_XMM sse
 DCA_LFE_FIR 0
 DCA_LFE_FIR 1
 
-%macro SHUF 2
-%if cpuflag(sse2)
-    pshufd        %1, %2, q0123
+%macro SHUF 3
+%if cpuflag(avx)
+    mova          %3, [%2 - 16]
+    vperm2f128    %1, %3, %3, 1
+    vshufps       %1, %1, %1, q0123
+%elif cpuflag(sse2)
+    pshufd        %1, [%2], q0123
 %else
-    mova          %1, %2
+    mova          %1, [%2]
     shufps        %1, %1, q0123
 %endif
 %endmacro
@@ -212,10 +216,10 @@ DCA_LFE_FIR 1
     ; reading backwards:  ptr1 = synth_buf + j + i; ptr2 = synth_buf + j - i
     ;~ a += window[i + j]      * (-synth_buf[15 - i + j])
     ;~ b += window[i + j + 16] * (synth_buf[i + j])
-    SHUF          m5, [ptr2 + j + (15 - 3) * 4]
+    SHUF          m5,  ptr2 + j + (15 - 3) * 4, m6
     mova          m6, [ptr1 + j]
 %if ARCH_X86_64
-    SHUF         m11, [ptr2 + j + (15 - 3) * 4 - mmsize]
+    SHUF         m11,  ptr2 + j + (15 - 3) * 4 - mmsize, m12
     mova         m12, [ptr1 + j + mmsize]
 %endif
     mulps         m6, [win  + %1 + j + 16 * 4]
@@ -232,10 +236,10 @@ DCA_LFE_FIR 1
 %endif
     ;~ c += window[i + j + 32] * (synth_buf[16 + i + j])
     ;~ d += window[i + j + 48] * (synth_buf[31 - i + j])
-    SHUF          m6, [ptr2 + j + (31 - 3) * 4]
+    SHUF          m6,  ptr2 + j + (31 - 3) * 4, m5
     mova          m5, [ptr1 + j + 16 * 4]
 %if ARCH_X86_64
-    SHUF         m12, [ptr2 + j + (31 - 3) * 4 - mmsize]
+    SHUF         m12,  ptr2 + j + (31 - 3) * 4 - mmsize, m11
     mova         m11, [ptr1 + j + mmsize + 16 * 4]
 %endif
     mulps         m5, [win  + %1 + j + 32 * 4]
@@ -261,13 +265,16 @@ cglobal synth_filter_inner, 0, 6 + 4 * ARCH_X86_64, 7 + 6 * ARCH_X86_64, \
                               synth_buf, synth_buf2, window, out, off, scale
 %define scale m0
 %if ARCH_X86_32 || WIN64
-    movd       scale, scalem
+    VBROADCASTSS  m0, scalem
 ; Make sure offset is in a register and not on the stack
 %define OFFQ  r4q
 %else
+    SPLATD      xmm0
+%if cpuflag(avx)
+    vinsertf128   m0, m0, xmm0, 1
+%endif
 %define OFFQ  offq
 %endif
-    SPLATD        m0
     ; prepare inner counter limit 1
     mov          r5q, 480
     sub          r5q, offmp
@@ -367,3 +374,7 @@ SYNTH_FILTER
 %endif
 INIT_XMM sse2
 SYNTH_FILTER
+%if HAVE_AVX_EXTERNAL
+INIT_YMM avx
+SYNTH_FILTER
+%endif
diff --git a/libavcodec/x86/dcadsp_init.c b/libavcodec/x86/dcadsp_init.c
index 0e84b8c..2e5c153 100644
--- a/libavcodec/x86/dcadsp_init.c
+++ b/libavcodec/x86/dcadsp_init.c
@@ -80,6 +80,7 @@ static void synth_filter_##opt(FFTContext *imdct,                              \
 SYNTH_FILTER_FUNC(sse)
 #endif
 SYNTH_FILTER_FUNC(sse2)
+SYNTH_FILTER_FUNC(avx)
 
 av_cold void ff_synth_filter_init_x86(SynthFilterContext *s)
 {
@@ -93,4 +94,7 @@ av_cold void ff_synth_filter_init_x86(SynthFilterContext *s)
     if (EXTERNAL_SSE2(cpu_flags)) {
         s->synth_filter_float = synth_filter_sse2;
     }
+    if (EXTERNAL_AVX(cpu_flags)) {
+        s->synth_filter_float = synth_filter_avx;
+    }
 }
-- 
1.8.3.2



More information about the ffmpeg-devel mailing list