2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "libavutil/attributes.h"
22 #include "libavutil/cpu.h"
23 #include "libavutil/float_dsp.h"
27 void ff_vector_fmul_sse(float *dst, const float *src0, const float *src1,
29 void ff_vector_fmul_avx(float *dst, const float *src0, const float *src1,
32 void ff_vector_fmac_scalar_sse(float *dst, const float *src, float mul,
34 void ff_vector_fmac_scalar_avx(float *dst, const float *src, float mul,
36 void ff_vector_fmac_scalar_fma3(float *dst, const float *src, float mul,
39 void ff_vector_fmul_scalar_sse(float *dst, const float *src, float mul,
42 void ff_vector_dmul_scalar_sse2(double *dst, const double *src,
44 void ff_vector_dmul_scalar_avx(double *dst, const double *src,
47 void ff_vector_fmul_add_sse(float *dst, const float *src0, const float *src1,
48 const float *src2, int len);
49 void ff_vector_fmul_add_avx(float *dst, const float *src0, const float *src1,
50 const float *src2, int len);
51 void ff_vector_fmul_add_fma3(float *dst, const float *src0, const float *src1,
52 const float *src2, int len);
54 void ff_vector_fmul_reverse_sse(float *dst, const float *src0,
55 const float *src1, int len);
56 void ff_vector_fmul_reverse_avx(float *dst, const float *src0,
57 const float *src1, int len);
59 float ff_scalarproduct_float_sse(const float *v1, const float *v2, int order);
61 void ff_butterflies_float_sse(float *src0, float *src1, int len);
63 #if HAVE_6REGS && HAVE_INLINE_ASM
64 static void vector_fmul_window_3dnowext(float *dst, const float *src0,
65 const float *src1, const float *win,
69 x86_reg j = len * 4 - 8;
72 "pswapd (%5, %1), %%mm1 \n"
73 "movq (%5, %0), %%mm0 \n"
74 "pswapd (%4, %1), %%mm5 \n"
75 "movq (%3, %0), %%mm4 \n"
76 "movq %%mm0, %%mm2 \n"
77 "movq %%mm1, %%mm3 \n"
78 "pfmul %%mm4, %%mm2 \n" // src0[len + i] * win[len + i]
79 "pfmul %%mm5, %%mm3 \n" // src1[j] * win[len + j]
80 "pfmul %%mm4, %%mm1 \n" // src0[len + i] * win[len + j]
81 "pfmul %%mm5, %%mm0 \n" // src1[j] * win[len + i]
82 "pfadd %%mm3, %%mm2 \n"
83 "pfsub %%mm0, %%mm1 \n"
84 "pswapd %%mm2, %%mm2 \n"
85 "movq %%mm1, (%2, %0) \n"
86 "movq %%mm2, (%2, %1) \n"
92 : "r"(dst + len), "r"(src0 + len), "r"(src1), "r"(win + len)
96 static void vector_fmul_window_sse(float *dst, const float *src0,
97 const float *src1, const float *win, int len)
100 x86_reg j = len * 4 - 16;
103 "movaps (%5, %1), %%xmm1 \n"
104 "movaps (%5, %0), %%xmm0 \n"
105 "movaps (%4, %1), %%xmm5 \n"
106 "movaps (%3, %0), %%xmm4 \n"
107 "shufps $0x1b, %%xmm1, %%xmm1 \n"
108 "shufps $0x1b, %%xmm5, %%xmm5 \n"
109 "movaps %%xmm0, %%xmm2 \n"
110 "movaps %%xmm1, %%xmm3 \n"
111 "mulps %%xmm4, %%xmm2 \n" // src0[len + i] * win[len + i]
112 "mulps %%xmm5, %%xmm3 \n" // src1[j] * win[len + j]
113 "mulps %%xmm4, %%xmm1 \n" // src0[len + i] * win[len + j]
114 "mulps %%xmm5, %%xmm0 \n" // src1[j] * win[len + i]
115 "addps %%xmm3, %%xmm2 \n"
116 "subps %%xmm0, %%xmm1 \n"
117 "shufps $0x1b, %%xmm2, %%xmm2 \n"
118 "movaps %%xmm1, (%2, %0) \n"
119 "movaps %%xmm2, (%2, %1) \n"
124 : "r"(dst + len), "r"(src0 + len), "r"(src1), "r"(win + len)
127 #endif /* HAVE_6REGS && HAVE_INLINE_ASM */
129 av_cold void ff_float_dsp_init_x86(AVFloatDSPContext *fdsp)
131 int cpu_flags = av_get_cpu_flags();
133 #if HAVE_6REGS && HAVE_INLINE_ASM
134 if (INLINE_AMD3DNOWEXT(cpu_flags)) {
135 fdsp->vector_fmul_window = vector_fmul_window_3dnowext;
137 if (INLINE_SSE(cpu_flags)) {
138 fdsp->vector_fmul_window = vector_fmul_window_sse;
141 if (EXTERNAL_SSE(cpu_flags)) {
142 fdsp->vector_fmul = ff_vector_fmul_sse;
143 fdsp->vector_fmac_scalar = ff_vector_fmac_scalar_sse;
144 fdsp->vector_fmul_scalar = ff_vector_fmul_scalar_sse;
145 fdsp->vector_fmul_add = ff_vector_fmul_add_sse;
146 fdsp->vector_fmul_reverse = ff_vector_fmul_reverse_sse;
147 fdsp->scalarproduct_float = ff_scalarproduct_float_sse;
148 fdsp->butterflies_float = ff_butterflies_float_sse;
150 if (EXTERNAL_SSE2(cpu_flags)) {
151 fdsp->vector_dmul_scalar = ff_vector_dmul_scalar_sse2;
153 if (EXTERNAL_AVX(cpu_flags)) {
154 fdsp->vector_fmul = ff_vector_fmul_avx;
155 fdsp->vector_fmac_scalar = ff_vector_fmac_scalar_avx;
156 fdsp->vector_dmul_scalar = ff_vector_dmul_scalar_avx;
157 fdsp->vector_fmul_add = ff_vector_fmul_add_avx;
158 fdsp->vector_fmul_reverse = ff_vector_fmul_reverse_avx;
160 if (EXTERNAL_FMA3(cpu_flags)) {
161 fdsp->vector_fmac_scalar = ff_vector_fmac_scalar_fma3;
162 fdsp->vector_fmul_add = ff_vector_fmul_add_fma3;