x86/float_dsp_init.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
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.
8  *
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.
13  *
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
17  */
18 
19 #include "config.h"
20 
21 #include "libavutil/cpu.h"
22 #include "libavutil/float_dsp.h"
23 #include "cpu.h"
24 #include "asm.h"
25 
26 void ff_vector_fmul_sse(float *dst, const float *src0, const float *src1,
27  int len);
28 void ff_vector_fmul_avx(float *dst, const float *src0, const float *src1,
29  int len);
30 
31 void ff_vector_fmac_scalar_sse(float *dst, const float *src, float mul,
32  int len);
33 void ff_vector_fmac_scalar_avx(float *dst, const float *src, float mul,
34  int len);
35 
36 void ff_vector_fmul_scalar_sse(float *dst, const float *src, float mul,
37  int len);
38 
39 void ff_vector_dmul_scalar_sse2(double *dst, const double *src,
40  double mul, int len);
41 void ff_vector_dmul_scalar_avx(double *dst, const double *src,
42  double mul, int len);
43 
44 void ff_vector_fmul_add_sse(float *dst, const float *src0, const float *src1,
45  const float *src2, int len);
46 void ff_vector_fmul_add_avx(float *dst, const float *src0, const float *src1,
47  const float *src2, int len);
48 
49 void ff_vector_fmul_reverse_sse(float *dst, const float *src0,
50  const float *src1, int len);
51 void ff_vector_fmul_reverse_avx(float *dst, const float *src0,
52  const float *src1, int len);
53 
54 float ff_scalarproduct_float_sse(const float *v1, const float *v2, int order);
55 
56 void ff_butterflies_float_sse(float *src0, float *src1, int len);
57 
58 #if HAVE_6REGS && HAVE_INLINE_ASM
59 static void vector_fmul_window_3dnowext(float *dst, const float *src0,
60  const float *src1, const float *win,
61  int len)
62 {
63  x86_reg i = -len * 4;
64  x86_reg j = len * 4 - 8;
65  __asm__ volatile (
66  "1: \n"
67  "pswapd (%5, %1), %%mm1 \n"
68  "movq (%5, %0), %%mm0 \n"
69  "pswapd (%4, %1), %%mm5 \n"
70  "movq (%3, %0), %%mm4 \n"
71  "movq %%mm0, %%mm2 \n"
72  "movq %%mm1, %%mm3 \n"
73  "pfmul %%mm4, %%mm2 \n" // src0[len + i] * win[len + i]
74  "pfmul %%mm5, %%mm3 \n" // src1[j] * win[len + j]
75  "pfmul %%mm4, %%mm1 \n" // src0[len + i] * win[len + j]
76  "pfmul %%mm5, %%mm0 \n" // src1[j] * win[len + i]
77  "pfadd %%mm3, %%mm2 \n"
78  "pfsub %%mm0, %%mm1 \n"
79  "pswapd %%mm2, %%mm2 \n"
80  "movq %%mm1, (%2, %0) \n"
81  "movq %%mm2, (%2, %1) \n"
82  "sub $8, %1 \n"
83  "add $8, %0 \n"
84  "jl 1b \n"
85  "femms \n"
86  : "+r"(i), "+r"(j)
87  : "r"(dst + len), "r"(src0 + len), "r"(src1), "r"(win + len)
88  );
89 }
90 
91 static void vector_fmul_window_sse(float *dst, const float *src0,
92  const float *src1, const float *win, int len)
93 {
94  x86_reg i = -len * 4;
95  x86_reg j = len * 4 - 16;
96  __asm__ volatile (
97  "1: \n"
98  "movaps (%5, %1), %%xmm1 \n"
99  "movaps (%5, %0), %%xmm0 \n"
100  "movaps (%4, %1), %%xmm5 \n"
101  "movaps (%3, %0), %%xmm4 \n"
102  "shufps $0x1b, %%xmm1, %%xmm1 \n"
103  "shufps $0x1b, %%xmm5, %%xmm5 \n"
104  "movaps %%xmm0, %%xmm2 \n"
105  "movaps %%xmm1, %%xmm3 \n"
106  "mulps %%xmm4, %%xmm2 \n" // src0[len + i] * win[len + i]
107  "mulps %%xmm5, %%xmm3 \n" // src1[j] * win[len + j]
108  "mulps %%xmm4, %%xmm1 \n" // src0[len + i] * win[len + j]
109  "mulps %%xmm5, %%xmm0 \n" // src1[j] * win[len + i]
110  "addps %%xmm3, %%xmm2 \n"
111  "subps %%xmm0, %%xmm1 \n"
112  "shufps $0x1b, %%xmm2, %%xmm2 \n"
113  "movaps %%xmm1, (%2, %0) \n"
114  "movaps %%xmm2, (%2, %1) \n"
115  "sub $16, %1 \n"
116  "add $16, %0 \n"
117  "jl 1b \n"
118  : "+r"(i), "+r"(j)
119  : "r"(dst + len), "r"(src0 + len), "r"(src1), "r"(win + len)
120  );
121 }
122 #endif /* HAVE_6REGS && HAVE_INLINE_ASM */
123 
125 {
126  int mm_flags = av_get_cpu_flags();
127 
128 #if HAVE_6REGS && HAVE_INLINE_ASM
129  if (INLINE_AMD3DNOWEXT(mm_flags)) {
130  fdsp->vector_fmul_window = vector_fmul_window_3dnowext;
131  }
132  if (INLINE_SSE(mm_flags)) {
133  fdsp->vector_fmul_window = vector_fmul_window_sse;
134  }
135 #endif
136  if (EXTERNAL_SSE(mm_flags)) {
144  }
145  if (EXTERNAL_SSE2(mm_flags)) {
147  }
148  if (EXTERNAL_AVX(mm_flags)) {
154  }
155 }
float(* scalarproduct_float)(const float *v1, const float *v2, int len)
Calculate the scalar product of two vectors of floats.
Definition: float_dsp.h:161
#define EXTERNAL_SSE(flags)
Definition: x86/cpu.h:35
void(* vector_fmac_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float and add to destination vector.
Definition: float_dsp.h:54
void ff_vector_fmul_reverse_avx(float *dst, const float *src0, const float *src1, int len)
void(* vector_fmul)(float *dst, const float *src0, const float *src1, int len)
Calculate the product of two vectors of floats and store the result in a vector of floats...
Definition: float_dsp.h:38
float ff_scalarproduct_float_sse(const float *v1, const float *v2, int order)
#define EXTERNAL_SSE2(flags)
Definition: x86/cpu.h:36
void(* vector_fmul_window)(float *dst, const float *src0, const float *src1, const float *win, int len)
Overlap/add with window function.
Definition: float_dsp.h:103
void(* vector_dmul_scalar)(double *dst, const double *src, double mul, int len)
Multiply a vector of double by a scalar double.
Definition: float_dsp.h:84
void ff_vector_fmul_add_avx(float *dst, const float *src0, const float *src1, const float *src2, int len)
void ff_vector_fmac_scalar_avx(float *dst, const float *src, float mul, int len)
#define INLINE_SSE(flags)
Definition: x86/cpu.h:48
void ff_vector_dmul_scalar_sse2(double *dst, const double *src, double mul, int len)
AVS_Value src
Definition: avisynth_c.h:523
void ff_butterflies_float_sse(float *src0, float *src1, int len)
void(* butterflies_float)(float *av_restrict v1, float *av_restrict v2, int len)
Calculate the sum and difference of two vectors of floats.
Definition: float_dsp.h:150
void ff_vector_dmul_scalar_avx(double *dst, const double *src, double mul, int len)
synthesis window for stochastic i
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float.
Definition: float_dsp.h:69
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:30
void ff_vector_fmul_sse(float *dst, const float *src0, const float *src1, int len)
void ff_vector_fmac_scalar_sse(float *dst, const float *src, float mul, int len)
void ff_vector_fmul_scalar_sse(float *dst, const float *src, float mul, int len)
void ff_vector_fmul_reverse_sse(float *dst, const float *src0, const float *src1, int len)
void(* vector_fmul_add)(float *dst, const float *src0, const float *src1, const float *src2, int len)
Calculate the product of two vectors of floats, add a third vector of floats and store the result in ...
Definition: float_dsp.h:121
void ff_vector_fmul_add_sse(float *dst, const float *src0, const float *src1, const float *src2, int len)
int x86_reg
int len
else dst[i][x+y *dst_stride[i]]
Definition: vf_mcdeint.c:160
void ff_float_dsp_init_x86(AVFloatDSPContext *fdsp)
#define INLINE_AMD3DNOWEXT(flags)
Definition: x86/cpu.h:45
void ff_vector_fmul_avx(float *dst, const float *src0, const float *src1, int len)
#define EXTERNAL_AVX(flags)
Definition: x86/cpu.h:41
void(* vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len)
Calculate the product of two vectors of floats, and store the result in a vector of floats...
Definition: float_dsp.h:140