FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 FFmpeg.
7  *
8  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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/mem.h"
26 #include "libavutil/x86/asm.h"
27 #include "libavutil/x86/cpu.h"
28 #include "libavcodec/vp9dsp.h"
29 
30 #if HAVE_YASM
31 
32 #define fpel_func(avg, sz, opt) \
33 void ff_vp9_##avg##sz##_##opt(uint8_t *dst, ptrdiff_t dst_stride, \
34  const uint8_t *src, ptrdiff_t src_stride, \
35  int h, int mx, int my)
36 fpel_func(put, 4, mmx);
37 fpel_func(put, 8, mmx);
38 fpel_func(put, 16, sse);
39 fpel_func(put, 32, sse);
40 fpel_func(put, 64, sse);
41 fpel_func(avg, 4, mmxext);
42 fpel_func(avg, 8, mmxext);
43 fpel_func(avg, 16, sse2);
44 fpel_func(avg, 32, sse2);
45 fpel_func(avg, 64, sse2);
46 #undef fpel_func
47 
48 #define mc_func(avg, sz, dir, opt) \
49 void ff_vp9_##avg##_8tap_1d_##dir##_##sz##_##opt(uint8_t *dst, ptrdiff_t dst_stride, \
50  const uint8_t *src, ptrdiff_t src_stride, \
51  int h, const int8_t (*filter)[16])
52 #define mc_funcs(sz) \
53 mc_func(put, sz, h, ssse3); \
54 mc_func(avg, sz, h, ssse3); \
55 mc_func(put, sz, v, ssse3); \
56 mc_func(avg, sz, v, ssse3)
57 
58 mc_funcs(4);
59 mc_funcs(8);
60 #if ARCH_X86_64
61 mc_funcs(16);
62 #endif
63 
64 #undef mc_funcs
65 #undef mc_func
66 
67 #define mc_rep_func(avg, sz, hsz, dir, opt) \
68 static av_always_inline void \
69 ff_vp9_##avg##_8tap_1d_##dir##_##sz##_##opt(uint8_t *dst, ptrdiff_t dst_stride, \
70  const uint8_t *src, ptrdiff_t src_stride, \
71  int h, const int8_t (*filter)[16]) \
72 { \
73  ff_vp9_##avg##_8tap_1d_##dir##_##hsz##_##opt(dst, dst_stride, src, \
74  src_stride, h, filter); \
75  ff_vp9_##avg##_8tap_1d_##dir##_##hsz##_##opt(dst + hsz, dst_stride, src + hsz, \
76  src_stride, h, filter); \
77 }
78 
79 #define mc_rep_funcs(sz, hsz) \
80 mc_rep_func(put, sz, hsz, h, ssse3); \
81 mc_rep_func(avg, sz, hsz, h, ssse3); \
82 mc_rep_func(put, sz, hsz, v, ssse3); \
83 mc_rep_func(avg, sz, hsz, v, ssse3)
84 
85 #if ARCH_X86_32
86 mc_rep_funcs(16, 8);
87 #endif
88 mc_rep_funcs(32, 16);
89 mc_rep_funcs(64, 32);
90 
91 #undef mc_rep_funcs
92 #undef mc_rep_func
93 
94 extern const int8_t ff_filters_ssse3[3][15][4][16];
95 
96 #define filter_8tap_2d_fn(op, sz, f, fname) \
97 static void op##_8tap_##fname##_##sz##hv_ssse3(uint8_t *dst, ptrdiff_t dst_stride, \
98  const uint8_t *src, ptrdiff_t src_stride, \
99  int h, int mx, int my) \
100 { \
101  LOCAL_ALIGNED_16(uint8_t, temp, [71 * 64]); \
102  ff_vp9_put_8tap_1d_h_##sz##_ssse3(temp, 64, src - 3 * src_stride, src_stride, \
103  h + 7, ff_filters_ssse3[f][mx - 1]); \
104  ff_vp9_##op##_8tap_1d_v_##sz##_ssse3(dst, dst_stride, temp + 3 * 64, 64, \
105  h, ff_filters_ssse3[f][my - 1]); \
106 }
107 
108 #define filters_8tap_2d_fn(op, sz) \
109 filter_8tap_2d_fn(op, sz, FILTER_8TAP_REGULAR, regular) \
110 filter_8tap_2d_fn(op, sz, FILTER_8TAP_SHARP, sharp) \
111 filter_8tap_2d_fn(op, sz, FILTER_8TAP_SMOOTH, smooth)
112 
113 #define filters_8tap_2d_fn2(op) \
114 filters_8tap_2d_fn(op, 64) \
115 filters_8tap_2d_fn(op, 32) \
116 filters_8tap_2d_fn(op, 16) \
117 filters_8tap_2d_fn(op, 8) \
118 filters_8tap_2d_fn(op, 4)
119 
120 filters_8tap_2d_fn2(put)
121 filters_8tap_2d_fn2(avg)
122 
123 #undef filters_8tap_2d_fn2
124 #undef filters_8tap_2d_fn
125 #undef filter_8tap_2d_fn
126 
127 #define filter_8tap_1d_fn(op, sz, f, fname, dir, dvar) \
128 static void op##_8tap_##fname##_##sz##dir##_ssse3(uint8_t *dst, ptrdiff_t dst_stride, \
129  const uint8_t *src, ptrdiff_t src_stride, \
130  int h, int mx, int my) \
131 { \
132  ff_vp9_##op##_8tap_1d_##dir##_##sz##_ssse3(dst, dst_stride, src, src_stride, \
133  h, ff_filters_ssse3[f][dvar - 1]); \
134 }
135 
136 #define filters_8tap_1d_fn(op, sz, dir, dvar) \
137 filter_8tap_1d_fn(op, sz, FILTER_8TAP_REGULAR, regular, dir, dvar) \
138 filter_8tap_1d_fn(op, sz, FILTER_8TAP_SHARP, sharp, dir, dvar) \
139 filter_8tap_1d_fn(op, sz, FILTER_8TAP_SMOOTH, smooth, dir, dvar)
140 
141 #define filters_8tap_1d_fn2(op, sz) \
142 filters_8tap_1d_fn(op, sz, h, mx) \
143 filters_8tap_1d_fn(op, sz, v, my)
144 
145 #define filters_8tap_1d_fn3(op) \
146 filters_8tap_1d_fn2(op, 64) \
147 filters_8tap_1d_fn2(op, 32) \
148 filters_8tap_1d_fn2(op, 16) \
149 filters_8tap_1d_fn2(op, 8) \
150 filters_8tap_1d_fn2(op, 4)
151 
152 filters_8tap_1d_fn3(put)
153 filters_8tap_1d_fn3(avg)
154 
155 #undef filters_8tap_1d_fn
156 #undef filters_8tap_1d_fn2
157 #undef filters_8tap_1d_fn3
158 #undef filter_8tap_1d_fn
159 
160 #define itxfm_func(typea, typeb, size, opt) \
161 void ff_vp9_##typea##_##typeb##_##size##x##size##_add_##opt(uint8_t *dst, ptrdiff_t stride, \
162  int16_t *block, int eob)
163 #define itxfm_funcs(size, opt) \
164 itxfm_func(idct, idct, size, opt); \
165 itxfm_func(iadst, idct, size, opt); \
166 itxfm_func(idct, iadst, size, opt); \
167 itxfm_func(iadst, iadst, size, opt)
168 
169 itxfm_funcs(4, ssse3);
170 itxfm_funcs(8, ssse3);
171 itxfm_funcs(8, avx);
172 itxfm_funcs(16, ssse3);
173 itxfm_funcs(16, avx);
174 itxfm_func(idct, idct, 32, ssse3);
175 itxfm_func(idct, idct, 32, avx);
176 itxfm_func(iwht, iwht, 4, mmx);
177 
178 #undef itxfm_func
179 #undef itxfm_funcs
180 
181 #define lpf_funcs(size1, size2, opt) \
182 void ff_vp9_loop_filter_v_##size1##_##size2##_##opt(uint8_t *dst, ptrdiff_t stride, \
183  int E, int I, int H); \
184 void ff_vp9_loop_filter_h_##size1##_##size2##_##opt(uint8_t *dst, ptrdiff_t stride, \
185  int E, int I, int H)
186 
187 lpf_funcs(16, 16, sse2);
188 lpf_funcs(16, 16, ssse3);
189 lpf_funcs(16, 16, avx);
190 lpf_funcs(44, 16, sse2);
191 lpf_funcs(44, 16, ssse3);
192 lpf_funcs(44, 16, avx);
193 lpf_funcs(84, 16, sse2);
194 lpf_funcs(84, 16, ssse3);
195 lpf_funcs(84, 16, avx);
196 lpf_funcs(48, 16, sse2);
197 lpf_funcs(48, 16, ssse3);
198 lpf_funcs(48, 16, avx);
199 lpf_funcs(88, 16, sse2);
200 lpf_funcs(88, 16, ssse3);
201 lpf_funcs(88, 16, avx);
202 
203 #undef lpf_funcs
204 
205 #define ipred_func(size, type, opt) \
206 void ff_vp9_ipred_##type##_##size##x##size##_##opt(uint8_t *dst, ptrdiff_t stride, \
207  const uint8_t *l, const uint8_t *a)
208 
209 #define ipred_funcs(type, opt) \
210 ipred_func(4, type, opt); \
211 ipred_func(8, type, opt); \
212 ipred_func(16, type, opt); \
213 ipred_func(32, type, opt)
214 
215 ipred_funcs(dc, ssse3);
216 ipred_funcs(dc_left, ssse3);
217 ipred_funcs(dc_top, ssse3);
218 
219 #undef ipred_funcs
220 
221 ipred_func(8, v, mmx);
222 ipred_func(16, v, sse2);
223 ipred_func(32, v, sse2);
224 
225 #define ipred_func_set(size, type, opt1, opt2) \
226 ipred_func(size, type, opt1); \
227 ipred_func(size, type, opt2)
228 
229 #define ipred_funcs(type, opt1, opt2) \
230 ipred_func(4, type, opt1); \
231 ipred_func_set(8, type, opt1, opt2); \
232 ipred_func_set(16, type, opt1, opt2); \
233 ipred_func_set(32, type, opt1, opt2)
234 
235 ipred_funcs(h, ssse3, avx);
236 ipred_funcs(tm, ssse3, avx);
237 ipred_funcs(dl, ssse3, avx);
238 ipred_funcs(dr, ssse3, avx);
239 ipred_funcs(hu, ssse3, avx);
240 ipred_funcs(hd, ssse3, avx);
241 ipred_funcs(vl, ssse3, avx);
242 ipred_funcs(vr, ssse3, avx);
243 
244 ipred_func(32, dc, avx2);
245 ipred_func(32, dc_left, avx2);
246 ipred_func(32, dc_top, avx2);
247 ipred_func(32, v, avx2);
248 ipred_func(32, h, avx2);
249 ipred_func(32, tm, avx2);
250 
251 #undef ipred_funcs
252 #undef ipred_func_set
253 #undef ipred_func
254 
255 #endif /* HAVE_YASM */
256 
258 {
259 #if HAVE_YASM
260  int cpu_flags = av_get_cpu_flags();
261 
262 #define init_fpel(idx1, idx2, sz, type, opt) \
263  dsp->mc[idx1][FILTER_8TAP_SMOOTH ][idx2][0][0] = \
264  dsp->mc[idx1][FILTER_8TAP_REGULAR][idx2][0][0] = \
265  dsp->mc[idx1][FILTER_8TAP_SHARP ][idx2][0][0] = \
266  dsp->mc[idx1][FILTER_BILINEAR ][idx2][0][0] = ff_vp9_##type##sz##_##opt
267 
268 #define init_subpel1(idx1, idx2, idxh, idxv, sz, dir, type, opt) \
269  dsp->mc[idx1][FILTER_8TAP_SMOOTH ][idx2][idxh][idxv] = type##_8tap_smooth_##sz##dir##_##opt; \
270  dsp->mc[idx1][FILTER_8TAP_REGULAR][idx2][idxh][idxv] = type##_8tap_regular_##sz##dir##_##opt; \
271  dsp->mc[idx1][FILTER_8TAP_SHARP ][idx2][idxh][idxv] = type##_8tap_sharp_##sz##dir##_##opt
272 
273 #define init_subpel2(idx, idxh, idxv, dir, type, opt) \
274  init_subpel1(0, idx, idxh, idxv, 64, dir, type, opt); \
275  init_subpel1(1, idx, idxh, idxv, 32, dir, type, opt); \
276  init_subpel1(2, idx, idxh, idxv, 16, dir, type, opt); \
277  init_subpel1(3, idx, idxh, idxv, 8, dir, type, opt); \
278  init_subpel1(4, idx, idxh, idxv, 4, dir, type, opt)
279 
280 #define init_subpel3(idx, type, opt) \
281  init_subpel2(idx, 1, 1, hv, type, opt); \
282  init_subpel2(idx, 0, 1, v, type, opt); \
283  init_subpel2(idx, 1, 0, h, type, opt)
284 
285 #define init_lpf(opt) do { \
286  if (ARCH_X86_64) { \
287  dsp->loop_filter_16[0] = ff_vp9_loop_filter_h_16_16_##opt; \
288  dsp->loop_filter_16[1] = ff_vp9_loop_filter_v_16_16_##opt; \
289  dsp->loop_filter_mix2[0][0][0] = ff_vp9_loop_filter_h_44_16_##opt; \
290  dsp->loop_filter_mix2[0][0][1] = ff_vp9_loop_filter_v_44_16_##opt; \
291  dsp->loop_filter_mix2[0][1][0] = ff_vp9_loop_filter_h_48_16_##opt; \
292  dsp->loop_filter_mix2[0][1][1] = ff_vp9_loop_filter_v_48_16_##opt; \
293  dsp->loop_filter_mix2[1][0][0] = ff_vp9_loop_filter_h_84_16_##opt; \
294  dsp->loop_filter_mix2[1][0][1] = ff_vp9_loop_filter_v_84_16_##opt; \
295  dsp->loop_filter_mix2[1][1][0] = ff_vp9_loop_filter_h_88_16_##opt; \
296  dsp->loop_filter_mix2[1][1][1] = ff_vp9_loop_filter_v_88_16_##opt; \
297  } \
298 } while (0)
299 
300 #define init_ipred(tx, sz, opt) do { \
301  dsp->intra_pred[tx][HOR_PRED] = ff_vp9_ipred_h_##sz##x##sz##_##opt; \
302  dsp->intra_pred[tx][DIAG_DOWN_LEFT_PRED] = ff_vp9_ipred_dl_##sz##x##sz##_##opt; \
303  dsp->intra_pred[tx][DIAG_DOWN_RIGHT_PRED] = ff_vp9_ipred_dr_##sz##x##sz##_##opt; \
304  dsp->intra_pred[tx][HOR_DOWN_PRED] = ff_vp9_ipred_hd_##sz##x##sz##_##opt; \
305  dsp->intra_pred[tx][VERT_LEFT_PRED] = ff_vp9_ipred_vl_##sz##x##sz##_##opt; \
306  dsp->intra_pred[tx][HOR_UP_PRED] = ff_vp9_ipred_hu_##sz##x##sz##_##opt; \
307  if (ARCH_X86_64 || tx != TX_32X32) { \
308  dsp->intra_pred[tx][VERT_RIGHT_PRED] = ff_vp9_ipred_vr_##sz##x##sz##_##opt; \
309  dsp->intra_pred[tx][TM_VP8_PRED] = ff_vp9_ipred_tm_##sz##x##sz##_##opt; \
310  } \
311 } while (0)
312 #define init_dc_ipred(tx, sz, opt) do { \
313  init_ipred(tx, sz, opt); \
314  dsp->intra_pred[tx][DC_PRED] = ff_vp9_ipred_dc_##sz##x##sz##_##opt; \
315  dsp->intra_pred[tx][LEFT_DC_PRED] = ff_vp9_ipred_dc_left_##sz##x##sz##_##opt; \
316  dsp->intra_pred[tx][TOP_DC_PRED] = ff_vp9_ipred_dc_top_##sz##x##sz##_##opt; \
317 } while (0)
318 
319  if (EXTERNAL_MMX(cpu_flags)) {
320  init_fpel(4, 0, 4, put, mmx);
321  init_fpel(3, 0, 8, put, mmx);
322  dsp->itxfm_add[4 /* lossless */][DCT_DCT] =
323  dsp->itxfm_add[4 /* lossless */][ADST_DCT] =
324  dsp->itxfm_add[4 /* lossless */][DCT_ADST] =
325  dsp->itxfm_add[4 /* lossless */][ADST_ADST] = ff_vp9_iwht_iwht_4x4_add_mmx;
326  dsp->intra_pred[TX_8X8][VERT_PRED] = ff_vp9_ipred_v_8x8_mmx;
327  }
328 
329  if (EXTERNAL_MMXEXT(cpu_flags)) {
330  init_fpel(4, 1, 4, avg, mmxext);
331  init_fpel(3, 1, 8, avg, mmxext);
332  }
333 
334  if (EXTERNAL_SSE(cpu_flags)) {
335  init_fpel(2, 0, 16, put, sse);
336  init_fpel(1, 0, 32, put, sse);
337  init_fpel(0, 0, 64, put, sse);
338  }
339 
340  if (EXTERNAL_SSE2(cpu_flags)) {
341  init_fpel(2, 1, 16, avg, sse2);
342  init_fpel(1, 1, 32, avg, sse2);
343  init_fpel(0, 1, 64, avg, sse2);
344  init_lpf(sse2);
345  dsp->intra_pred[TX_16X16][VERT_PRED] = ff_vp9_ipred_v_16x16_sse2;
346  dsp->intra_pred[TX_32X32][VERT_PRED] = ff_vp9_ipred_v_32x32_sse2;
347  }
348 
349  if (EXTERNAL_SSSE3(cpu_flags)) {
350  init_subpel3(0, put, ssse3);
351  init_subpel3(1, avg, ssse3);
352  dsp->itxfm_add[TX_4X4][DCT_DCT] = ff_vp9_idct_idct_4x4_add_ssse3;
353  dsp->itxfm_add[TX_4X4][ADST_DCT] = ff_vp9_idct_iadst_4x4_add_ssse3;
354  dsp->itxfm_add[TX_4X4][DCT_ADST] = ff_vp9_iadst_idct_4x4_add_ssse3;
355  dsp->itxfm_add[TX_4X4][ADST_ADST] = ff_vp9_iadst_iadst_4x4_add_ssse3;
356  if (ARCH_X86_64) {
357  dsp->itxfm_add[TX_8X8][DCT_DCT] = ff_vp9_idct_idct_8x8_add_ssse3;
358  dsp->itxfm_add[TX_8X8][ADST_DCT] = ff_vp9_idct_iadst_8x8_add_ssse3;
359  dsp->itxfm_add[TX_8X8][DCT_ADST] = ff_vp9_iadst_idct_8x8_add_ssse3;
360  dsp->itxfm_add[TX_8X8][ADST_ADST] = ff_vp9_iadst_iadst_8x8_add_ssse3;
361  dsp->itxfm_add[TX_16X16][DCT_DCT] = ff_vp9_idct_idct_16x16_add_ssse3;
362  dsp->itxfm_add[TX_16X16][ADST_DCT] = ff_vp9_idct_iadst_16x16_add_ssse3;
363  dsp->itxfm_add[TX_16X16][DCT_ADST] = ff_vp9_iadst_idct_16x16_add_ssse3;
364  dsp->itxfm_add[TX_16X16][ADST_ADST] = ff_vp9_iadst_iadst_16x16_add_ssse3;
365  dsp->itxfm_add[TX_32X32][ADST_ADST] =
366  dsp->itxfm_add[TX_32X32][ADST_DCT] =
367  dsp->itxfm_add[TX_32X32][DCT_ADST] =
368  dsp->itxfm_add[TX_32X32][DCT_DCT] = ff_vp9_idct_idct_32x32_add_ssse3;
369  }
370  init_lpf(ssse3);
371  init_dc_ipred(TX_4X4, 4, ssse3);
372  init_dc_ipred(TX_8X8, 8, ssse3);
373  init_dc_ipred(TX_16X16, 16, ssse3);
374  init_dc_ipred(TX_32X32, 32, ssse3);
375  }
376 
377  if (EXTERNAL_AVX(cpu_flags)) {
378  if (ARCH_X86_64) {
379  dsp->itxfm_add[TX_8X8][DCT_DCT] = ff_vp9_idct_idct_8x8_add_avx;
380  dsp->itxfm_add[TX_8X8][ADST_DCT] = ff_vp9_idct_iadst_8x8_add_avx;
381  dsp->itxfm_add[TX_8X8][DCT_ADST] = ff_vp9_iadst_idct_8x8_add_avx;
382  dsp->itxfm_add[TX_8X8][ADST_ADST] = ff_vp9_iadst_iadst_8x8_add_avx;
383  dsp->itxfm_add[TX_16X16][DCT_DCT] = ff_vp9_idct_idct_16x16_add_avx;
384  dsp->itxfm_add[TX_16X16][ADST_DCT] = ff_vp9_idct_iadst_16x16_add_avx;
385  dsp->itxfm_add[TX_16X16][DCT_ADST] = ff_vp9_iadst_idct_16x16_add_avx;
386  dsp->itxfm_add[TX_16X16][ADST_ADST] = ff_vp9_iadst_iadst_16x16_add_avx;
387  dsp->itxfm_add[TX_32X32][ADST_ADST] =
388  dsp->itxfm_add[TX_32X32][ADST_DCT] =
389  dsp->itxfm_add[TX_32X32][DCT_ADST] =
390  dsp->itxfm_add[TX_32X32][DCT_DCT] = ff_vp9_idct_idct_32x32_add_avx;
391  }
392  init_lpf(avx);
393  init_ipred(TX_8X8, 8, avx);
394  init_ipred(TX_16X16, 16, avx);
395  init_ipred(TX_32X32, 32, avx);
396  }
397 
398  if (EXTERNAL_AVX2(cpu_flags)) {
399  dsp->intra_pred[TX_32X32][DC_PRED] = ff_vp9_ipred_dc_32x32_avx2;
400  dsp->intra_pred[TX_32X32][LEFT_DC_PRED] = ff_vp9_ipred_dc_left_32x32_avx2;
401  dsp->intra_pred[TX_32X32][TOP_DC_PRED] = ff_vp9_ipred_dc_top_32x32_avx2;
402  dsp->intra_pred[TX_32X32][VERT_PRED] = ff_vp9_ipred_v_32x32_avx2;
403  dsp->intra_pred[TX_32X32][HOR_PRED] = ff_vp9_ipred_h_32x32_avx2;
404  dsp->intra_pred[TX_32X32][TM_VP8_PRED] = ff_vp9_ipred_tm_32x32_avx2;
405  }
406 
407 #undef init_fpel
408 #undef init_subpel1
409 #undef init_subpel2
410 #undef init_subpel3
411 
412 #endif /* HAVE_YASM */
413 }