[FFmpeg-devel] [PATCH] flac/x86: add ff_flac_lpc_32_sse4()

James Almer jamrial at gmail.com
Sat Feb 1 05:38:49 CET 2014


x64
1261661 decicycles in flac_lpc_32_c, 32768 runs
1045689 decicycles in ff_flac_lpc_32_sse4, 32768 runs

1431506 decicycles in flac_lpc_32_c, 32768 runs
1209322 decicycles in ff_flac_lpc_32_sse4, 32768 runs

x86
1429597 decicycles in flac_lpc_32_c, 32768 runs
953667 decicycles in ff_flac_lpc_32_sse4, 32768 runs

1610348 decicycles in flac_lpc_32_c, 32768 runs
1079424 decicycles in ff_flac_lpc_32_sse4, 32768 runs

About 100 to 500 ms faster decoding using -threads 1 depending on song and arch.
Tested using a few 24 bits samples on an AMD FX 6300, Win7 x64 and x86.
Biggest speedup appears to be on x86 builds.

Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/flacdsp.c          |  2 ++
 libavcodec/flacdsp.h          |  1 +
 libavcodec/x86/Makefile       |  2 ++
 libavcodec/x86/flacdsp.asm    | 61 +++++++++++++++++++++++++++++++++++++++++++
 libavcodec/x86/flacdsp_init.c | 39 +++++++++++++++++++++++++++
 5 files changed, 105 insertions(+)
 create mode 100644 libavcodec/x86/flacdsp.asm
 create mode 100644 libavcodec/x86/flacdsp_init.c

diff --git a/libavcodec/flacdsp.c b/libavcodec/flacdsp.c
index 02eba3e..b15bc74 100644
--- a/libavcodec/flacdsp.c
+++ b/libavcodec/flacdsp.c
@@ -128,4 +128,6 @@ av_cold void ff_flacdsp_init(FLACDSPContext *c, enum AVSampleFormat fmt,
 
     if (ARCH_ARM)
         ff_flacdsp_init_arm(c, fmt, bps);
+    if (ARCH_X86)
+        ff_flacdsp_init_x86(c, fmt, bps);
 }
diff --git a/libavcodec/flacdsp.h b/libavcodec/flacdsp.h
index 5e66dc2..272cf2a 100644
--- a/libavcodec/flacdsp.h
+++ b/libavcodec/flacdsp.h
@@ -33,5 +33,6 @@ typedef struct FLACDSPContext {
 
 void ff_flacdsp_init(FLACDSPContext *c, enum AVSampleFormat fmt, int bps);
 void ff_flacdsp_init_arm(FLACDSPContext *c, enum AVSampleFormat fmt, int bps);
+void ff_flacdsp_init_x86(FLACDSPContext *c, enum AVSampleFormat fmt, int bps);
 
 #endif /* AVCODEC_FLACDSP_H */
diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile
index dddaae1..6d5d008 100644
--- a/libavcodec/x86/Makefile
+++ b/libavcodec/x86/Makefile
@@ -12,6 +12,7 @@ OBJS-$(CONFIG_ENCODERS)                += x86/dsputilenc_mmx.o          \
                                           x86/fdct.o                    \
                                           x86/motion_est.o
 OBJS-$(CONFIG_FFT)                     += x86/fft_init.o
+OBJS-$(CONFIG_FLAC_DECODER)            += x86/flacdsp_init.o
 OBJS-$(CONFIG_H263DSP)                 += x86/h263dsp_init.o
 OBJS-$(CONFIG_H264CHROMA)              += x86/h264chroma_init.o
 OBJS-$(CONFIG_H264DSP)                 += x86/h264dsp_init.o
@@ -70,6 +71,7 @@ YASM-OBJS-$(CONFIG_DSPUTIL)            += x86/dsputil.o                 \
                                           x86/qpel.o
 YASM-OBJS-$(CONFIG_ENCODERS)           += x86/dsputilenc.o
 YASM-OBJS-$(CONFIG_FFT)                += x86/fft.o
+YASM-OBJS-$(CONFIG_FLAC_DECODER)       += x86/flacdsp.o
 YASM-OBJS-$(CONFIG_H263DSP)            += x86/h263_loopfilter.o
 YASM-OBJS-$(CONFIG_H264CHROMA)         += x86/h264_chromamc.o           \
                                           x86/h264_chromamc_10bit.o
diff --git a/libavcodec/x86/flacdsp.asm b/libavcodec/x86/flacdsp.asm
new file mode 100644
index 0000000..1b4c287
--- /dev/null
+++ b/libavcodec/x86/flacdsp.asm
@@ -0,0 +1,61 @@
+;******************************************************************************
+;* FLAC 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 .text
+
+INIT_XMM sse4
+cglobal flac_lpc_32, 5,6,3, decoded, coeffs, pred_order, qlevel, len, cnt
+    cmp    lenq, pred_orderq
+    jle    .end
+
+.begin
+    movd   m0, [coeffsq]
+    movd   m2, [decodedq]
+    pmuldq m0, m2
+    mov    cntq, 1
+    cmp    pred_orderq, cntq
+    jz     .finish
+
+.loop
+    movd   m1, [coeffsq  + cntq*4]
+    movd   m2, [decodedq + cntq*4]
+    pmuldq m1, m2
+    paddq  m0, m1
+    add    cntq, 1
+    cmp    pred_orderq, cntq
+    jg     .loop
+
+.finish
+    movd   m1, qleveld
+    psrlq  m0, m1
+    movd   m2, [decodedq + cntq*4]
+    paddq  m2, m0
+    movd   [decodedq + cntq*4], m2
+    add    decodedq, 4
+    sub    lenq, 1
+    cmp    lenq, pred_orderq
+    jg     .begin
+
+.end
+    RET
diff --git a/libavcodec/x86/flacdsp_init.c b/libavcodec/x86/flacdsp_init.c
new file mode 100644
index 0000000..d30a41e
--- /dev/null
+++ b/libavcodec/x86/flacdsp_init.c
@@ -0,0 +1,39 @@
+/*
+ * 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/flacdsp.h"
+#include "libavutil/x86/cpu.h"
+#include "config.h"
+
+void ff_flac_lpc_32_sse4(int32_t *samples, const int coeffs[32], int order,
+                         int qlevel, int len);
+
+av_cold void ff_flacdsp_init_x86(FLACDSPContext *c, enum AVSampleFormat fmt,
+                                 int bps)
+{
+#if HAVE_YASM
+    int cpu_flags = av_get_cpu_flags();
+
+    if (EXTERNAL_SSE4(cpu_flags)) {
+        if (bps > 16)
+            c->lpc = ff_flac_lpc_32_sse4;
+    }
+#endif
+}
-- 
1.8.3.2



More information about the ffmpeg-devel mailing list