summaryrefslogtreecommitdiff
path: root/libavcodec/x86
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec/x86')
-rw-r--r--libavcodec/x86/Makefile2
-rw-r--r--libavcodec/x86/mdct15.asm141
-rw-r--r--libavcodec/x86/mdct15_init.c95
3 files changed, 238 insertions, 0 deletions
diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile
index e65118d134..b86700b675 100644
--- a/libavcodec/x86/Makefile
+++ b/libavcodec/x86/Makefile
@@ -25,6 +25,7 @@ OBJS-$(CONFIG_HUFFYUVDSP) += x86/huffyuvdsp_init.o
OBJS-$(CONFIG_HUFFYUVENCDSP) += x86/huffyuvencdsp_init.o
OBJS-$(CONFIG_IDCTDSP) += x86/idctdsp_init.o
OBJS-$(CONFIG_LPC) += x86/lpc.o
+OBJS-$(CONFIG_MDCT15) += x86/mdct15_init.o
OBJS-$(CONFIG_ME_CMP) += x86/me_cmp_init.o
OBJS-$(CONFIG_MPEGAUDIODSP) += x86/mpegaudiodsp.o
OBJS-$(CONFIG_MPEGVIDEO) += x86/mpegvideo.o \
@@ -117,6 +118,7 @@ X86ASM-OBJS-$(CONFIG_IDCTDSP) += x86/idctdsp.o
X86ASM-OBJS-$(CONFIG_LLAUDDSP) += x86/lossless_audiodsp.o
X86ASM-OBJS-$(CONFIG_LLVIDDSP) += x86/lossless_videodsp.o
X86ASM-OBJS-$(CONFIG_LLVIDENCDSP) += x86/lossless_videoencdsp.o
+X86ASM-OBJS-$(CONFIG_MDCT15) += x86/mdct15.o
X86ASM-OBJS-$(CONFIG_ME_CMP) += x86/me_cmp.o
X86ASM-OBJS-$(CONFIG_MPEGAUDIODSP) += x86/imdct36.o
X86ASM-OBJS-$(CONFIG_MPEGVIDEOENC) += x86/mpegvideoencdsp.o
diff --git a/libavcodec/x86/mdct15.asm b/libavcodec/x86/mdct15.asm
new file mode 100644
index 0000000000..8d01675956
--- /dev/null
+++ b/libavcodec/x86/mdct15.asm
@@ -0,0 +1,141 @@
+;******************************************************************************
+;* SIMD optimized non-power-of-two MDCT functions
+;*
+;* Copyright (C) 2017 Rostislav Pehlivanov <atomnuker@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 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"
+
+%if ARCH_X86_64
+
+SECTION_RODATA
+
+sign_adjust_5: dd 0x00000000, 0x80000000, 0x80000000, 0x00000000
+
+SECTION .text
+
+%macro FFT5 3 ; %1 - in_offset, %2 - dst1 (64bit used), %3 - dst2
+ VBROADCASTSD m0, [inq + %1] ; in[ 0].re, in[ 0].im, in[ 0].re, in[ 0].im
+ movsd xm1, [inq + 1*16 + 8 + %1] ; in[ 3].re, in[ 3].im, 0, 0
+ movsd xm4, [inq + 6*16 + 0 + %1] ; in[12].re, in[12].im, 0, 0
+ movhps xm1, [inq + 3*16 + 0 + %1] ; in[ 3].re, in[ 3].im, in[ 6].re, in[ 6].im
+ movhps xm4, [inq + 4*16 + 8 + %1] ; in[12].re, in[12].im, in[ 9].re, in[ 9].im
+
+ subps xm2, xm1, xm4 ; t[2].im, t[2].re, t[3].im, t[3].re
+ addps xm1, xm4 ; t[0].re, t[0].im, t[1].re, t[1].im
+
+ movhlps %2, xm1 ; t[0].re, t[1].re, t[0].im, t[1].im
+ addps %2, xm1
+ addps %2, xm0 ; DC[0].re, DC[0].im, junk...
+ movlhps %2, %2 ; DC[0].re, DC[0].im, DC[0].re, DC[0].im
+
+ shufps xm3, xm1, xm2, q0110 ; t[0].re, t[0].im, t[2].re, t[2].im
+ shufps xm1, xm2, q2332 ; t[1].re, t[1].im, t[3].re, t[3].im
+
+ mulps xm%3, xm1, xm5
+ mulps xm4, xm3, xm6
+ mulps xm1, xm6
+
+ xorps xm1, xm7
+ mulps xm3, xm5
+ addsubps xm3, xm1 ; t[0].re, t[0].im, t[2].re, t[2].im
+ subps xm%3, xm4 ; t[4].re, t[4].im, t[5].re, t[5].im
+
+ movhlps xm2, xm%3, xm3 ; t[2].re, t[2].im, t[5].re, t[5].im
+ movlhps xm3, xm%3 ; t[0].re, t[0].im, t[4].re, t[4].im
+
+ xorps xm2, xm7
+ addps xm%3, xm2, xm3
+ subps xm3, xm2
+
+ shufps xm3, xm3, q1032
+ vinsertf128 m%3, m%3, xm3, 1 ; All ACs (tmp[1] through to tmp[4])
+ addps m%3, m0 ; Finally offset with DCs
+%endmacro
+
+%macro BUTTERFLIES_DC 2 ; %1 - exptab_offset, %2 - out
+ mulps xm0, xm9, [exptabq + %1 + 16*0]
+ mulps xm1, xm10, [exptabq + %1 + 16*1]
+
+ haddps xm0, xm1
+ movhlps xm1, xm0 ; t[0].re, t[1].re, t[0].im, t[1].im
+
+ addps xm0, xm1
+ addps xm0, xm8
+
+ movsd [%2q], xm0
+%endmacro
+
+%macro BUTTERFLIES_AC 2 ; exptab, exptab_offset, src1, src2, src3, out (uses m0-m3)
+ mulps m0, m12, [exptabq + 64*0 + 0*mmsize + %1]
+ mulps m1, m12, [exptabq + 64*0 + 1*mmsize + %1]
+ mulps m2, m13, [exptabq + 64*1 + 0*mmsize + %1]
+ mulps m3, m13, [exptabq + 64*1 + 1*mmsize + %1]
+
+ addps m0, m2
+ addps m1, m3
+ addps m0, m11
+
+ shufps m1, m1, q2301
+ addps m0, m1
+
+ vextractf128 xm1, m0, 1
+
+ movlps [%2q + strideq*1], xm0
+ movhps [%2q + strideq*2], xm0
+ movlps [%2q + stride3q], xm1
+ movhps [%2q + strideq*4], xm1
+%endmacro
+
+;*****************************************************************************************
+;void ff_fft15_avx(FFTComplex *out, FFTComplex *in, FFTComplex *exptab, ptrdiff_t stride);
+;*****************************************************************************************
+INIT_YMM avx
+cglobal fft15, 4, 6, 14, out, in, exptab, stride, stride3, stride5
+%define out0q inq
+ shl strideq, 3
+
+ movaps xm5, [exptabq + 480 + 16*0]
+ movaps xm6, [exptabq + 480 + 16*1]
+ movaps xm7, [sign_adjust_5]
+
+ FFT5 0, xm8, 11
+ FFT5 8, xm9, 12
+ FFT5 16, xm10, 13
+
+ lea stride3q, [strideq + strideq*2]
+ lea stride5q, [strideq + strideq*4]
+
+ mov out0q, outq
+
+ BUTTERFLIES_DC (8*6 + 4*0)*2*4, out0
+ lea outq, [out0q + stride5q*1]
+ BUTTERFLIES_DC (8*6 + 4*1)*2*4, out
+ lea outq, [out0q + stride5q*2]
+ BUTTERFLIES_DC (8*6 + 4*2)*2*4, out
+
+ BUTTERFLIES_AC (8*0)*2*4, out0
+ lea outq, [out0q + stride5q*1]
+ BUTTERFLIES_AC (8*2)*2*4, out
+ lea outq, [out0q + stride5q*2]
+ BUTTERFLIES_AC (8*4)*2*4, out
+
+ RET
+
+%endif
diff --git a/libavcodec/x86/mdct15_init.c b/libavcodec/x86/mdct15_init.c
new file mode 100644
index 0000000000..ba3d94c2ec
--- /dev/null
+++ b/libavcodec/x86/mdct15_init.c
@@ -0,0 +1,95 @@
+/*
+ * SIMD optimized non-power-of-two MDCT functions
+ *
+ * Copyright (C) 2017 Rostislav Pehlivanov <atomnuker@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 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 "config.h"
+
+#include "libavutil/x86/cpu.h"
+#include "libavcodec/mdct15.h"
+
+void ff_fft15_avx(FFTComplex *out, FFTComplex *in, FFTComplex *exptab, ptrdiff_t stride);
+
+static void perm_twiddles(MDCT15Context *s)
+{
+ int k;
+ FFTComplex exp_5point[4];
+
+ FFTComplex tmp[21], tmp2[30];
+ memcpy(tmp, s->exptab, sizeof(FFTComplex)*21);
+
+ /* 15-point FFT twiddles */
+ for (k = 0; k < 5; k++) {
+ tmp2[6*k + 0] = tmp[k + 0];
+ tmp2[6*k + 2] = tmp[k + 5];
+ tmp2[6*k + 4] = tmp[k + 10];
+
+ tmp2[6*k + 1] = tmp[2 * (k + 0)];
+ tmp2[6*k + 3] = tmp[2 * (k + 5)];
+ tmp2[6*k + 5] = tmp[2 * k + 5 ];
+ }
+
+ for (k = 0; k < 6; k++) {
+ FFTComplex ac_exp[] = {
+ { tmp2[6*1 + k].re, tmp2[6*1 + k].re },
+ { tmp2[6*2 + k].re, tmp2[6*2 + k].re },
+ { tmp2[6*3 + k].re, tmp2[6*3 + k].re },
+ { tmp2[6*4 + k].re, tmp2[6*4 + k].re },
+ { tmp2[6*1 + k].im, -tmp2[6*1 + k].im },
+ { tmp2[6*2 + k].im, -tmp2[6*2 + k].im },
+ { tmp2[6*3 + k].im, -tmp2[6*3 + k].im },
+ { tmp2[6*4 + k].im, -tmp2[6*4 + k].im },
+ };
+ memcpy(s->exptab + 8*k, ac_exp, 8*sizeof(FFTComplex));
+ }
+
+ /* Specialcase when k = 0 */
+ for (k = 0; k < 3; k++) {
+ FFTComplex dc_exp[] = {
+ { tmp2[2*k + 0].re, -tmp2[2*k + 0].im },
+ { tmp2[2*k + 0].im, tmp2[2*k + 0].re },
+ { tmp2[2*k + 1].re, -tmp2[2*k + 1].im },
+ { tmp2[2*k + 1].im, tmp2[2*k + 1].re },
+ };
+ memcpy(s->exptab + 8*6 + 4*k, dc_exp, 4*sizeof(FFTComplex));
+ }
+
+ /* 5-point FFT twiddles */
+ exp_5point[0].re = exp_5point[0].im = tmp[19].re;
+ exp_5point[1].re = exp_5point[1].im = tmp[19].im;
+ exp_5point[2].re = exp_5point[2].im = tmp[20].re;
+ exp_5point[3].re = exp_5point[3].im = tmp[20].im;
+
+ memcpy(s->exptab + 8*6 + 4*3, exp_5point, 4*sizeof(FFTComplex));
+}
+
+av_cold void ff_mdct15_init_x86(MDCT15Context *s)
+{
+ int adjust_twiddles = 0;
+ int cpu_flags = av_get_cpu_flags();
+
+ if (ARCH_X86_64 && EXTERNAL_AVX(cpu_flags)) {
+ s->fft15 = ff_fft15_avx;
+ adjust_twiddles = 1;
+ }
+
+ if (adjust_twiddles)
+ perm_twiddles(s);
+}