[3/3] x86/synth_filter: add synth_filter_fma3

Message ID 1393899904-13802-4-git-send-email-jamrial@gmail.com
State New
Headers show

Commit Message

James Almer March 4, 2014, 2:25 a.m.
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/x86/dcadsp.asm    | 28 +++++++++++-----------------
 libavcodec/x86/dcadsp_init.c |  4 ++++
 2 files changed, 15 insertions(+), 17 deletions(-)

Comments

Christophe Gisquet March 14, 2014, 11:02 a.m. | #1
Hi,

2014-03-04 3:25 GMT+01:00 James Almer <jamrial@gmail.com>:
<snip>
Don't know fma3 but this is straightforward replacement of mul+add by
a mac instruction. If the avx code is ok, I don't see how this
wouldn't.
James Almer March 15, 2014, 10:04 p.m. | #2
On 14/03/14 8:02 AM, Christophe Gisquet wrote:
> Hi,
> 
> 2014-03-04 3:25 GMT+01:00 James Almer <jamrial@gmail.com>:
> <snip>
> Don't know fma3 but this is straightforward replacement of mul+add by
> a mac instruction. If the avx code is ok, I don't see how this
> wouldn't.

I just noticed i can replace the mul+sub instructions as well with a 
single fnmaddps, so I'll send an updated version with that change.

Patch

diff --git a/libavcodec/x86/dcadsp.asm b/libavcodec/x86/dcadsp.asm
index 0d7c86e..e1842ef 100644
--- a/libavcodec/x86/dcadsp.asm
+++ b/libavcodec/x86/dcadsp.asm
@@ -230,16 +230,12 @@  DCA_LFE_FIR 1
     SHUF         m11,  ptr2 + j + (15 - 3) * 4 - mmsize, m12
     mova         m12, [ptr1 + j + mmsize]
 %endif
-    mulps         m6, m6,  [win + %1 + j + 16 * 4]
+    FMULADD_PS    m2, m6,  [win + %1 + j + 16 * 4], m2, m6
     mulps         m5, m5,  [win + %1 + j]
-%if ARCH_X86_64
-    mulps        m12, m12, [win + %1 + j + mmsize + 16 * 4]
-    mulps        m11, m11, [win + %1 + j + mmsize]
-%endif
-    addps         m2, m2, m6
     subps         m1, m1, m5
 %if ARCH_X86_64
-    addps         m8, m8, m12
+    FMULADD_PS    m8, m12, [win + %1 + j + mmsize + 16 * 4], m8, m12
+    mulps        m11, m11, [win + %1 + j + mmsize]
     subps         m7, m7, m11
 %endif
     ;~ c += window[i + j + 32] * (synth_buf[16 + i + j])
@@ -250,17 +246,11 @@  DCA_LFE_FIR 1
     SHUF         m12,  ptr2 + j + (31 - 3) * 4 - mmsize, m11
     mova         m11, [ptr1 + j + mmsize + 16 * 4]
 %endif
-    mulps         m5, m5,  [win + %1 + j + 32 * 4]
-    mulps         m6, m6,  [win + %1 + j + 48 * 4]
+    FMULADD_PS    m3, m5,  [win + %1 + j + 32 * 4], m3, m5
+    FMULADD_PS    m4, m6,  [win + %1 + j + 48 * 4], m4, m6
 %if ARCH_X86_64
-    mulps        m11, m11, [win + %1 + j + mmsize + 32 * 4]
-    mulps        m12, m12, [win + %1 + j + mmsize + 48 * 4]
-%endif
-    addps         m3, m3, m5
-    addps         m4, m4, m6
-%if ARCH_X86_64
-    addps         m9, m9, m11
-    addps        m10, m10, m12
+    FMULADD_PS    m9, m11, [win + %1 + j + mmsize + 32 * 4], m9, m11
+    FMULADD_PS   m10, m12, [win + %1 + j + mmsize + 48 * 4], m10, m12
 %endif
     sub            j, 64 * 4
 %endmacro
@@ -391,3 +381,7 @@  SYNTH_FILTER
 INIT_YMM avx
 SYNTH_FILTER
 %endif
+%if HAVE_FMA3_EXTERNAL
+INIT_YMM fma3
+SYNTH_FILTER
+%endif
diff --git a/libavcodec/x86/dcadsp_init.c b/libavcodec/x86/dcadsp_init.c
index ab20635..132f75e 100644
--- a/libavcodec/x86/dcadsp_init.c
+++ b/libavcodec/x86/dcadsp_init.c
@@ -80,6 +80,7 @@  SYNTH_FILTER_FUNC(sse)
 #endif
 SYNTH_FILTER_FUNC(sse2)
 SYNTH_FILTER_FUNC(avx)
+SYNTH_FILTER_FUNC(fma3)
 
 av_cold void ff_synth_filter_init_x86(SynthFilterContext *s)
 {
@@ -96,4 +97,7 @@  av_cold void ff_synth_filter_init_x86(SynthFilterContext *s)
     if (EXTERNAL_AVX(cpu_flags)) {
         s->synth_filter_float = synth_filter_avx;
     }
+    if (EXTERNAL_FMA3(cpu_flags)) {
+        s->synth_filter_float = synth_filter_fma3;
+    }
 }