[FFmpeg-devel] [PATCH 04/10] lavc/flacenc: add sse4 version of the lpc encoder

James Darnley james.darnley at gmail.com
Wed Feb 12 00:11:16 CET 2014


>From 1.8 to 2.4 times faster.  Runtime is reduced by 2 to 39%.  The
speed-up generally increases with compression_level.

This lpc encoder is not used with levels < 3 so it provides no speed-up
in these cases.
---
 LICENSE                         |    1 +
 libavcodec/x86/Makefile         |    3 ++
 libavcodec/x86/flac_dsp_gpl.asm |   75 +++++++++++++++++++++++++++++++++++++++
 libavcodec/x86/flacdsp_init.c   |    4 ++
 4 files changed, 83 insertions(+), 0 deletions(-)
 create mode 100644 libavcodec/x86/flac_dsp_gpl.asm

diff --git a/LICENSE b/LICENSE
index 4f56a0b..714a340 100644
--- a/LICENSE
+++ b/LICENSE
@@ -16,6 +16,7 @@ Specifically, the GPL parts of FFmpeg are
 - libmpcodecs
 - optional x86 optimizations in the files
   libavcodec/x86/idct_mmx.c
+  libavcodec/x86/flac_dsp_gpl.asm
 - libutvideo encoding/decoding wrappers in
   libavcodec/libutvideo*.cpp
 - the X11 grabber in libavdevice/x11grab.c
diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile
index 7b56178..2cf9d2c 100644
--- a/libavcodec/x86/Makefile
+++ b/libavcodec/x86/Makefile
@@ -75,6 +75,9 @@ YASM-OBJS-$(CONFIG_DSPUTIL)            += x86/dsputil.o                 \
 YASM-OBJS-$(CONFIG_ENCODERS)           += x86/dsputilenc.o
 YASM-OBJS-$(CONFIG_FFT)                += x86/fft.o
 YASM-OBJS-$(CONFIG_FLAC_DECODER)       += x86/flacdsp.o
+ifdef CONFIG_GPL
+YASM-OBJS-$(CONFIG_FLAC_ENCODER)       += x86/flac_dsp_gpl.o
+endif
 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/flac_dsp_gpl.asm b/libavcodec/x86/flac_dsp_gpl.asm
new file mode 100644
index 0000000..9498c4c
--- /dev/null
+++ b/libavcodec/x86/flac_dsp_gpl.asm
@@ -0,0 +1,75 @@
+;*****************************************************************************
+;* FLAC DSP functions
+;*
+;* Copyright (c) 2014 James Darnley <james.darnley at gmail.com>
+;*
+;* This file is part of FFmpeg.
+;*
+;* FFmpeg is free software; you can redistribute it and/or modify
+;* it under the terms of the GNU General Public License as published by
+;* the Free Software Foundation; either version 2 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 General Public License for more details.
+;*
+;* You should have received a copy of the GNU 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"
+
+INIT_XMM sse4
+%if ARCH_X86_64
+    cglobal flac_enc_lpc_16, 6, 8, 4, 0, res, smp, len, order, coefs, shift
+    %define posj r6
+    %define negj r7
+%else
+    cglobal flac_enc_lpc_16, 6, 6, 4, 0, res, smp, len, order, coefs, shift
+    %define posj r2
+    %define negj r5
+%endif
+
+; Is it worth looping correctly over the first samples?  The most that ever need
+; to be copied is 32 so we might as well just unroll the loop and do all 32.
+%assign iter 0
+%rep 32/(mmsize/4)
+    movu m0, [smpq+iter]
+    movu [resq+iter], m0
+    %assign iter iter+mmsize
+%endrep
+
+lea resq, [resq+orderq*4]
+lea smpq, [smpq+orderq*4]
+sub lenmp, orderq
+movd m3, shiftmp
+
+.looplen:
+    pxor m0,  m0
+    xor posj, posj
+    xor negj, negj
+    .looporder:
+        movd   m2, [coefsq+posj*4] ; c = coefs[j]
+        SPLATD m2
+        movu   m1, [smpq+negj*4-4] ; s = smp[i-j-1]
+        pmulld m1,  m2
+        paddd  m0,  m1             ; p += c * s
+
+        add posj, 1
+        sub negj, 1
+        cmp posj, ordermp
+    jne .looporder
+
+    psrad m0, m3                   ; p >>= shift
+    movu  m1, [smpq]
+    psubd m1, m0                   ; smp[i] - p
+    movu  [resq], m1               ; res[i] = smp[i] - (p >> shift)
+
+    add resq, mmsize
+    add smpq, mmsize
+    sub lenmp, mmsize/4
+jg .looplen
+RET
diff --git a/libavcodec/x86/flacdsp_init.c b/libavcodec/x86/flacdsp_init.c
index 1a02522..fdec2ca 100644
--- a/libavcodec/x86/flacdsp_init.c
+++ b/libavcodec/x86/flacdsp_init.c
@@ -25,6 +25,8 @@
 void ff_flac_lpc_32_sse4(int32_t *samples, const int coeffs[32], int order,
                          int qlevel, int len);
 
+void ff_flac_enc_lpc_16_sse4(int32_t *, const int32_t *, int, int,  const int32_t *,int);
+
 av_cold void ff_flacdsp_init_x86(FLACDSPContext *c, enum AVSampleFormat fmt,
                                  int bps)
 {
@@ -34,6 +36,8 @@ av_cold void ff_flacdsp_init_x86(FLACDSPContext *c, enum AVSampleFormat fmt,
     if (EXTERNAL_SSE4(cpu_flags)) {
         if (bps > 16 && CONFIG_FLAC_DECODER)
             c->lpc = ff_flac_lpc_32_sse4;
+        if (CONFIG_GPL && bps == 16)
+            c->lpc_encode = ff_flac_enc_lpc_16_sse4;
     }
 #endif
 }
-- 
1.7.9



More information about the ffmpeg-devel mailing list