Libav
vp9dsp_init.c
Go to the documentation of this file.
1 /*
2  * VP9 SIMD optimizations
3  *
4  * Copyright (c) 2013 Ronald S. Bultje <rsbultje@gmail.com>
5  *
6  * This file is part of Libav.
7  *
8  * Libav is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * Libav is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with Libav; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "libavutil/attributes.h"
24 #include "libavutil/cpu.h"
25 #include "libavutil/internal.h"
26 #include "libavutil/mem.h"
27 #include "libavutil/x86/cpu.h"
28 #include "libavcodec/vp9.h"
29 
30 #if HAVE_YASM
31 
32 #define fpel_func(avg, sz, opt) \
33 void ff_vp9_ ## avg ## sz ## _ ## opt(uint8_t *dst, const uint8_t *src, \
34  ptrdiff_t dst_stride, \
35  ptrdiff_t src_stride, \
36  int h, int mx, int my)
37 
38 fpel_func(put, 4, mmx);
39 fpel_func(put, 8, mmx);
40 fpel_func(put, 16, sse);
41 fpel_func(put, 32, sse);
42 fpel_func(put, 64, sse);
43 fpel_func(avg, 4, mmxext);
44 fpel_func(avg, 8, mmxext);
45 fpel_func(avg, 16, sse2);
46 fpel_func(avg, 32, sse2);
47 fpel_func(avg, 64, sse2);
48 fpel_func(put, 32, avx);
49 fpel_func(put, 64, avx);
50 fpel_func(avg, 32, avx2);
51 fpel_func(avg, 64, avx2);
52 #undef fpel_func
53 
54 #define mc_func(avg, sz, dir, opt, type, f_sz) \
55 void \
56 ff_vp9_ ## avg ## _8tap_1d_ ## dir ## _ ## sz ## _ ## opt(uint8_t *dst, \
57  const uint8_t *src, \
58  ptrdiff_t dst_stride, \
59  ptrdiff_t src_stride, \
60  int h, \
61  const type (*filter)[f_sz])
62 
63 #define mc_funcs(sz, opt, type, f_sz) \
64  mc_func(put, sz, h, opt, type, f_sz); \
65  mc_func(avg, sz, h, opt, type, f_sz); \
66  mc_func(put, sz, v, opt, type, f_sz); \
67  mc_func(avg, sz, v, opt, type, f_sz)
68 
69 mc_funcs(4, mmxext, int16_t, 8);
70 mc_funcs(8, sse2, int16_t, 8);
71 mc_funcs(4, ssse3, int8_t, 32);
72 mc_funcs(8, ssse3, int8_t, 32);
73 #if ARCH_X86_64
74 mc_funcs(16, ssse3, int8_t, 32);
75 mc_funcs(32, avx2, int8_t, 32);
76 #endif
77 
78 #undef mc_funcs
79 #undef mc_func
80 
81 #define mc_rep_func(avg, sz, hsz, dir, opt, type, f_sz) \
82 static av_always_inline void \
83 ff_vp9_ ## avg ## _8tap_1d_ ## dir ## _ ## sz ## _ ## opt(uint8_t *dst, \
84  const uint8_t *src, \
85  ptrdiff_t dst_stride, \
86  ptrdiff_t src_stride, \
87  int h, \
88  const type (*filter)[f_sz]) \
89 { \
90  ff_vp9_ ## avg ## _8tap_1d_ ## dir ## _ ## hsz ## _ ## opt(dst, src, \
91  dst_stride, \
92  src_stride, \
93  h, \
94  filter); \
95  ff_vp9_ ## avg ## _8tap_1d_ ## dir ## _ ## hsz ## _ ## opt(dst + hsz, \
96  src + hsz, \
97  dst_stride, \
98  src_stride, \
99  h, filter); \
100 }
101 
102 #define mc_rep_funcs(sz, hsz, opt, type, f_sz) \
103  mc_rep_func(put, sz, hsz, h, opt, type, f_sz); \
104  mc_rep_func(avg, sz, hsz, h, opt, type, f_sz); \
105  mc_rep_func(put, sz, hsz, v, opt, type, f_sz); \
106  mc_rep_func(avg, sz, hsz, v, opt, type, f_sz)
107 
108 mc_rep_funcs(16, 8, sse2, int16_t, 8);
109 #if ARCH_X86_32
110 mc_rep_funcs(16, 8, ssse3, int8_t, 32);
111 #endif
112 mc_rep_funcs(32, 16, sse2, int16_t, 8);
113 mc_rep_funcs(32, 16, ssse3, int8_t, 32);
114 mc_rep_funcs(64, 32, sse2, int16_t, 8);
115 mc_rep_funcs(64, 32, ssse3, int8_t, 32);
116 #if ARCH_X86_64 && HAVE_AVX2_EXTERNAL
117 mc_rep_funcs(64, 32, avx2, int8_t, 32);
118 #endif
119 
120 #undef mc_rep_funcs
121 #undef mc_rep_func
122 
123 extern const int8_t ff_filters_ssse3[3][15][4][32];
124 extern const int16_t ff_filters_sse2[3][15][8][8];
125 
126 #define filter_8tap_2d_fn(op, sz, f, f_opt, fname, align, opt) \
127 static void \
128 op ## _8tap_ ## fname ## _ ## sz ## hv_ ## opt(uint8_t *dst, \
129  const uint8_t *src, \
130  ptrdiff_t dst_stride, \
131  ptrdiff_t src_stride, \
132  int h, int mx, int my) \
133 { \
134  LOCAL_ALIGNED_ ## align(uint8_t, temp, [71 * 64]); \
135  ff_vp9_put_8tap_1d_h_ ## sz ## _ ## opt(temp, src - 3 * src_stride, \
136  64, src_stride, \
137  h + 7, \
138  ff_filters_ ## f_opt[f][mx - 1]); \
139  ff_vp9_ ## op ## _8tap_1d_v_ ## sz ## _ ## opt(dst, temp + 3 * 64, \
140  dst_stride, 64, \
141  h, \
142  ff_filters_ ## f_opt[f][my - 1]); \
143 }
144 
145 #define filters_8tap_2d_fn(op, sz, align, opt, f_opt) \
146  filter_8tap_2d_fn(op, sz, FILTER_8TAP_REGULAR, f_opt, regular, align, opt) \
147  filter_8tap_2d_fn(op, sz, FILTER_8TAP_SHARP, f_opt, sharp, align, opt) \
148  filter_8tap_2d_fn(op, sz, FILTER_8TAP_SMOOTH, f_opt, smooth, align, opt)
149 
150 #define filters_8tap_2d_fn2(op, align, opt4, opt8, f_opt) \
151  filters_8tap_2d_fn(op, 64, align, opt8, f_opt) \
152  filters_8tap_2d_fn(op, 32, align, opt8, f_opt) \
153  filters_8tap_2d_fn(op, 16, align, opt8, f_opt) \
154  filters_8tap_2d_fn(op, 8, align, opt8, f_opt) \
155  filters_8tap_2d_fn(op, 4, align, opt4, f_opt)
156 
157 
158 filters_8tap_2d_fn2(put, 16, mmxext, sse2, sse2)
159 filters_8tap_2d_fn2(avg, 16, mmxext, sse2, sse2)
160 filters_8tap_2d_fn2(put, 16, ssse3, ssse3, ssse3)
161 filters_8tap_2d_fn2(avg, 16, ssse3, ssse3, ssse3)
162 #if ARCH_X86_64 && HAVE_AVX2_EXTERNAL
163 filters_8tap_2d_fn(put, 64, 32, avx2, ssse3)
164 filters_8tap_2d_fn(put, 32, 32, avx2, ssse3)
165 filters_8tap_2d_fn(avg, 64, 32, avx2, ssse3)
166 filters_8tap_2d_fn(avg, 32, 32, avx2, ssse3)
167 #endif
168 
169 #undef filters_8tap_2d_fn2
170 #undef filters_8tap_2d_fn
171 #undef filter_8tap_2d_fn
172 
173 #define filter_8tap_1d_fn(op, sz, f, f_opt, fname, dir, dvar, opt) \
174 static void \
175 op ## _8tap_ ## fname ## _ ## sz ## dir ## _ ## opt(uint8_t *dst, \
176  const uint8_t *src, \
177  ptrdiff_t dst_stride, \
178  ptrdiff_t src_stride, \
179  int h, int mx, \
180  int my) \
181 { \
182  ff_vp9_ ## op ## _8tap_1d_ ## dir ## _ ## sz ## _ ## opt(dst, src, \
183  dst_stride, \
184  src_stride, h,\
185  ff_filters_ ## f_opt[f][dvar - 1]); \
186 }
187 
188 #define filters_8tap_1d_fn(op, sz, dir, dvar, opt, f_opt) \
189  filter_8tap_1d_fn(op, sz, FILTER_8TAP_REGULAR, f_opt, regular, dir, dvar, opt) \
190  filter_8tap_1d_fn(op, sz, FILTER_8TAP_SHARP, f_opt, sharp, dir, dvar, opt) \
191  filter_8tap_1d_fn(op, sz, FILTER_8TAP_SMOOTH, f_opt, smooth, dir, dvar, opt)
192 
193 #define filters_8tap_1d_fn2(op, sz, opt, f_opt) \
194  filters_8tap_1d_fn(op, sz, h, mx, opt, f_opt) \
195  filters_8tap_1d_fn(op, sz, v, my, opt, f_opt)
196 
197 #define filters_8tap_1d_fn3(op, opt4, opt8, f_opt) \
198  filters_8tap_1d_fn2(op, 64, opt8, f_opt) \
199  filters_8tap_1d_fn2(op, 32, opt8, f_opt) \
200  filters_8tap_1d_fn2(op, 16, opt8, f_opt) \
201  filters_8tap_1d_fn2(op, 8, opt8, f_opt) \
202  filters_8tap_1d_fn2(op, 4, opt4, f_opt)
203 
204 filters_8tap_1d_fn3(put, mmxext, sse2, sse2)
205 filters_8tap_1d_fn3(avg, mmxext, sse2, sse2)
206 filters_8tap_1d_fn3(put, ssse3, ssse3, ssse3)
207 filters_8tap_1d_fn3(avg, ssse3, ssse3, ssse3)
208 #if ARCH_X86_64 && HAVE_AVX2_EXTERNAL
209 filters_8tap_1d_fn2(put, 64, avx2, ssse3)
210 filters_8tap_1d_fn2(put, 32, avx2, ssse3)
211 filters_8tap_1d_fn2(avg, 64, avx2, ssse3)
212 filters_8tap_1d_fn2(avg, 32, avx2, ssse3)
213 #endif
214 
215 #undef filters_8tap_1d_fn
216 #undef filters_8tap_1d_fn2
217 #undef filters_8tap_1d_fn3
218 #undef filter_8tap_1d_fn
219 
220 #endif /* HAVE_YASM */
221 
223 {
224 #if HAVE_YASM
225  int cpu_flags = av_get_cpu_flags();
226 
227 #define init_fpel(idx1, idx2, sz, type, opt) \
228  dsp->mc[idx1][FILTER_8TAP_SMOOTH ][idx2][0][0] = \
229  dsp->mc[idx1][FILTER_8TAP_REGULAR][idx2][0][0] = \
230  dsp->mc[idx1][FILTER_8TAP_SHARP ][idx2][0][0] = \
231  dsp->mc[idx1][FILTER_BILINEAR ][idx2][0][0] = ff_vp9_ ## type ## sz ## _ ## opt
232 
233 
234 #define init_subpel1(idx1, idx2, idxh, idxv, sz, dir, type, opt) \
235  dsp->mc[idx1][FILTER_8TAP_SMOOTH][idx2][idxh][idxv] = type ## _8tap_smooth_ ## sz ## dir ## _ ## opt; \
236  dsp->mc[idx1][FILTER_8TAP_REGULAR][idx2][idxh][idxv] = type ## _8tap_regular_ ## sz ## dir ## _ ## opt; \
237  dsp->mc[idx1][FILTER_8TAP_SHARP][idx2][idxh][idxv] = type ## _8tap_sharp_ ## sz ## dir ## _ ## opt
238 
239 #define init_subpel2(idx1, idx2, sz, type, opt) \
240  init_subpel1(idx1, idx2, 1, 1, sz, hv, type, opt); \
241  init_subpel1(idx1, idx2, 0, 1, sz, v, type, opt); \
242  init_subpel1(idx1, idx2, 1, 0, sz, h, type, opt)
243 
244 #define init_subpel3_32_64(idx, type, opt) \
245  init_subpel2(0, idx, 64, type, opt); \
246  init_subpel2(1, idx, 32, type, opt)
247 
248 #define init_subpel3_8to64(idx, type, opt) \
249  init_subpel3_32_64(idx, type, opt); \
250  init_subpel2(2, idx, 16, type, opt); \
251  init_subpel2(3, idx, 8, type, opt)
252 
253 #define init_subpel3(idx, type, opt) \
254  init_subpel3_8to64(idx, type, opt); \
255  init_subpel2(4, idx, 4, type, opt)
256 
257  if (EXTERNAL_MMX(cpu_flags)) {
258  init_fpel(4, 0, 4, put, mmx);
259  init_fpel(3, 0, 8, put, mmx);
260  }
261 
262  if (EXTERNAL_MMXEXT(cpu_flags)) {
263  init_subpel2(4, 0, 4, put, mmxext);
264  init_subpel2(4, 1, 4, avg, mmxext);
265  init_fpel(4, 1, 4, avg, mmxext);
266  init_fpel(3, 1, 8, avg, mmxext);
267  }
268 
269  if (EXTERNAL_SSE(cpu_flags)) {
270  init_fpel(2, 0, 16, put, sse);
271  init_fpel(1, 0, 32, put, sse);
272  init_fpel(0, 0, 64, put, sse);
273  }
274 
275  if (EXTERNAL_SSE2(cpu_flags)) {
276  init_subpel3_8to64(0, put, sse2);
277  init_subpel3_8to64(1, avg, sse2);
278  init_fpel(2, 1, 16, avg, sse2);
279  init_fpel(1, 1, 32, avg, sse2);
280  init_fpel(0, 1, 64, avg, sse2);
281  }
282 
283  if (EXTERNAL_SSSE3(cpu_flags)) {
284  init_subpel3(0, put, ssse3);
285  init_subpel3(1, avg, ssse3);
286  }
287 
288  if (EXTERNAL_AVX(cpu_flags)) {
289  init_fpel(1, 0, 32, put, avx);
290  init_fpel(0, 0, 64, put, avx);
291  }
292 
293  if (EXTERNAL_AVX2(cpu_flags)) {
294  init_fpel(1, 1, 32, avg, avx2);
295  init_fpel(0, 1, 64, avg, avx2);
296 
297 #if ARCH_X86_64 && HAVE_AVX2_EXTERNAL
298  init_subpel3_32_64(0, put, avx2);
299  init_subpel3_32_64(1, avg, avx2);
300 #endif /* ARCH_X86_64 && HAVE_AVX2_EXTERNAL */
301  }
302 
303 #undef init_fpel
304 #undef init_subpel1
305 #undef init_subpel2
306 #undef init_subpel3
307 
308 #endif /* HAVE_YASM */
309 }
#define EXTERNAL_MMX(flags)
Definition: cpu.h:55
memory handling functions
static int sse(MpegEncContext *s, uint8_t *src1, uint8_t *src2, int w, int h, int stride)
#define EXTERNAL_SSE(flags)
Definition: cpu.h:57
Macro definitions for various function/variable attributes.
#define init_subpel2(idx, idxh, idxv, dir, type)
#define av_cold
Definition: attributes.h:66
#define init_fpel(idx1, idx2, sz, type)
#define EXTERNAL_SSE2(flags)
Definition: cpu.h:58
av_cold void ff_vp9dsp_init_x86(VP9DSPContext *dsp)
Definition: vp9dsp_init.c:222
common internal API header
#define EXTERNAL_SSSE3(flags)
Definition: cpu.h:64
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:47
#define EXTERNAL_AVX2(flags)
Definition: cpu.h:75
#define EXTERNAL_MMXEXT(flags)
Definition: cpu.h:56
#define EXTERNAL_AVX(flags)
Definition: cpu.h:69
#define init_subpel3(idx, type)