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_##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_##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_##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_##avg##_8tap_1d_##dir##_##hsz##_##opt(dst, dst_stride, src, \
74  src_stride, h, filter); \
75  ff_##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_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_##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_##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 #undef ipred_funcs
245 #undef ipred_func_set
246 #undef ipred_func
247 
248 #endif /* HAVE_YASM */
249 
251 {
252 #if HAVE_YASM
253  int cpu_flags = av_get_cpu_flags();
254 
255 #define init_fpel(idx1, idx2, sz, type, opt) \
256  dsp->mc[idx1][FILTER_8TAP_SMOOTH ][idx2][0][0] = \
257  dsp->mc[idx1][FILTER_8TAP_REGULAR][idx2][0][0] = \
258  dsp->mc[idx1][FILTER_8TAP_SHARP ][idx2][0][0] = \
259  dsp->mc[idx1][FILTER_BILINEAR ][idx2][0][0] = ff_##type##sz##_##opt
260 
261 #define init_subpel1(idx1, idx2, idxh, idxv, sz, dir, type, opt) \
262  dsp->mc[idx1][FILTER_8TAP_SMOOTH ][idx2][idxh][idxv] = type##_8tap_smooth_##sz##dir##_##opt; \
263  dsp->mc[idx1][FILTER_8TAP_REGULAR][idx2][idxh][idxv] = type##_8tap_regular_##sz##dir##_##opt; \
264  dsp->mc[idx1][FILTER_8TAP_SHARP ][idx2][idxh][idxv] = type##_8tap_sharp_##sz##dir##_##opt
265 
266 #define init_subpel2(idx, idxh, idxv, dir, type, opt) \
267  init_subpel1(0, idx, idxh, idxv, 64, dir, type, opt); \
268  init_subpel1(1, idx, idxh, idxv, 32, dir, type, opt); \
269  init_subpel1(2, idx, idxh, idxv, 16, dir, type, opt); \
270  init_subpel1(3, idx, idxh, idxv, 8, dir, type, opt); \
271  init_subpel1(4, idx, idxh, idxv, 4, dir, type, opt)
272 
273 #define init_subpel3(idx, type, opt) \
274  init_subpel2(idx, 1, 1, hv, type, opt); \
275  init_subpel2(idx, 0, 1, v, type, opt); \
276  init_subpel2(idx, 1, 0, h, type, opt)
277 
278 #define init_lpf(opt) do { \
279  if (ARCH_X86_64) { \
280  dsp->loop_filter_16[0] = ff_vp9_loop_filter_h_16_16_##opt; \
281  dsp->loop_filter_16[1] = ff_vp9_loop_filter_v_16_16_##opt; \
282  dsp->loop_filter_mix2[0][0][0] = ff_vp9_loop_filter_h_44_16_##opt; \
283  dsp->loop_filter_mix2[0][0][1] = ff_vp9_loop_filter_v_44_16_##opt; \
284  dsp->loop_filter_mix2[0][1][0] = ff_vp9_loop_filter_h_48_16_##opt; \
285  dsp->loop_filter_mix2[0][1][1] = ff_vp9_loop_filter_v_48_16_##opt; \
286  dsp->loop_filter_mix2[1][0][0] = ff_vp9_loop_filter_h_84_16_##opt; \
287  dsp->loop_filter_mix2[1][0][1] = ff_vp9_loop_filter_v_84_16_##opt; \
288  dsp->loop_filter_mix2[1][1][0] = ff_vp9_loop_filter_h_88_16_##opt; \
289  dsp->loop_filter_mix2[1][1][1] = ff_vp9_loop_filter_v_88_16_##opt; \
290  } \
291 } while (0)
292 
293 #define init_ipred(tx, sz, opt) do { \
294  dsp->intra_pred[tx][HOR_PRED] = ff_vp9_ipred_h_##sz##x##sz##_##opt; \
295  dsp->intra_pred[tx][DIAG_DOWN_LEFT_PRED] = ff_vp9_ipred_dl_##sz##x##sz##_##opt; \
296  dsp->intra_pred[tx][DIAG_DOWN_RIGHT_PRED] = ff_vp9_ipred_dr_##sz##x##sz##_##opt; \
297  dsp->intra_pred[tx][HOR_DOWN_PRED] = ff_vp9_ipred_hd_##sz##x##sz##_##opt; \
298  dsp->intra_pred[tx][VERT_LEFT_PRED] = ff_vp9_ipred_vl_##sz##x##sz##_##opt; \
299  dsp->intra_pred[tx][HOR_UP_PRED] = ff_vp9_ipred_hu_##sz##x##sz##_##opt; \
300  if (ARCH_X86_64 || tx != TX_32X32) { \
301  dsp->intra_pred[tx][VERT_RIGHT_PRED] = ff_vp9_ipred_vr_##sz##x##sz##_##opt; \
302  dsp->intra_pred[tx][TM_VP8_PRED] = ff_vp9_ipred_tm_##sz##x##sz##_##opt; \
303  } \
304 } while (0)
305 #define init_dc_ipred(tx, sz, opt) do { \
306  init_ipred(tx, sz, opt); \
307  dsp->intra_pred[tx][DC_PRED] = ff_vp9_ipred_dc_##sz##x##sz##_##opt; \
308  dsp->intra_pred[tx][LEFT_DC_PRED] = ff_vp9_ipred_dc_left_##sz##x##sz##_##opt; \
309  dsp->intra_pred[tx][TOP_DC_PRED] = ff_vp9_ipred_dc_top_##sz##x##sz##_##opt; \
310 } while (0)
311 
312  if (EXTERNAL_MMX(cpu_flags)) {
313  init_fpel(4, 0, 4, put, mmx);
314  init_fpel(3, 0, 8, put, mmx);
315  dsp->itxfm_add[4 /* lossless */][DCT_DCT] =
316  dsp->itxfm_add[4 /* lossless */][ADST_DCT] =
317  dsp->itxfm_add[4 /* lossless */][DCT_ADST] =
318  dsp->itxfm_add[4 /* lossless */][ADST_ADST] = ff_vp9_iwht_iwht_4x4_add_mmx;
319  dsp->intra_pred[TX_8X8][VERT_PRED] = ff_vp9_ipred_v_8x8_mmx;
320  }
321 
322  if (EXTERNAL_MMXEXT(cpu_flags)) {
323  init_fpel(4, 1, 4, avg, mmxext);
324  init_fpel(3, 1, 8, avg, mmxext);
325  }
326 
327  if (EXTERNAL_SSE(cpu_flags)) {
328  init_fpel(2, 0, 16, put, sse);
329  init_fpel(1, 0, 32, put, sse);
330  init_fpel(0, 0, 64, put, sse);
331  }
332 
333  if (EXTERNAL_SSE2(cpu_flags)) {
334  init_fpel(2, 1, 16, avg, sse2);
335  init_fpel(1, 1, 32, avg, sse2);
336  init_fpel(0, 1, 64, avg, sse2);
337  init_lpf(sse2);
338  dsp->intra_pred[TX_16X16][VERT_PRED] = ff_vp9_ipred_v_16x16_sse2;
339  dsp->intra_pred[TX_32X32][VERT_PRED] = ff_vp9_ipred_v_32x32_sse2;
340  }
341 
342  if (EXTERNAL_SSSE3(cpu_flags)) {
343  init_subpel3(0, put, ssse3);
344  init_subpel3(1, avg, ssse3);
345  dsp->itxfm_add[TX_4X4][DCT_DCT] = ff_vp9_idct_idct_4x4_add_ssse3;
346  dsp->itxfm_add[TX_4X4][ADST_DCT] = ff_vp9_idct_iadst_4x4_add_ssse3;
347  dsp->itxfm_add[TX_4X4][DCT_ADST] = ff_vp9_iadst_idct_4x4_add_ssse3;
348  dsp->itxfm_add[TX_4X4][ADST_ADST] = ff_vp9_iadst_iadst_4x4_add_ssse3;
349  if (ARCH_X86_64) {
350  dsp->itxfm_add[TX_8X8][DCT_DCT] = ff_vp9_idct_idct_8x8_add_ssse3;
351  dsp->itxfm_add[TX_8X8][ADST_DCT] = ff_vp9_idct_iadst_8x8_add_ssse3;
352  dsp->itxfm_add[TX_8X8][DCT_ADST] = ff_vp9_iadst_idct_8x8_add_ssse3;
353  dsp->itxfm_add[TX_8X8][ADST_ADST] = ff_vp9_iadst_iadst_8x8_add_ssse3;
354  dsp->itxfm_add[TX_16X16][DCT_DCT] = ff_vp9_idct_idct_16x16_add_ssse3;
355  dsp->itxfm_add[TX_16X16][ADST_DCT] = ff_vp9_idct_iadst_16x16_add_ssse3;
356  dsp->itxfm_add[TX_16X16][DCT_ADST] = ff_vp9_iadst_idct_16x16_add_ssse3;
357  dsp->itxfm_add[TX_16X16][ADST_ADST] = ff_vp9_iadst_iadst_16x16_add_ssse3;
358  dsp->itxfm_add[TX_32X32][ADST_ADST] =
359  dsp->itxfm_add[TX_32X32][ADST_DCT] =
360  dsp->itxfm_add[TX_32X32][DCT_ADST] =
361  dsp->itxfm_add[TX_32X32][DCT_DCT] = ff_vp9_idct_idct_32x32_add_ssse3;
362  }
363  init_lpf(ssse3);
364  init_dc_ipred(TX_4X4, 4, ssse3);
365  init_dc_ipred(TX_8X8, 8, ssse3);
366  init_dc_ipred(TX_16X16, 16, ssse3);
367  init_dc_ipred(TX_32X32, 32, ssse3);
368  }
369 
370  if (EXTERNAL_AVX(cpu_flags)) {
371  if (ARCH_X86_64) {
372  dsp->itxfm_add[TX_8X8][DCT_DCT] = ff_vp9_idct_idct_8x8_add_avx;
373  dsp->itxfm_add[TX_8X8][ADST_DCT] = ff_vp9_idct_iadst_8x8_add_avx;
374  dsp->itxfm_add[TX_8X8][DCT_ADST] = ff_vp9_iadst_idct_8x8_add_avx;
375  dsp->itxfm_add[TX_8X8][ADST_ADST] = ff_vp9_iadst_iadst_8x8_add_avx;
376  dsp->itxfm_add[TX_16X16][DCT_DCT] = ff_vp9_idct_idct_16x16_add_avx;
377  dsp->itxfm_add[TX_16X16][ADST_DCT] = ff_vp9_idct_iadst_16x16_add_avx;
378  dsp->itxfm_add[TX_16X16][DCT_ADST] = ff_vp9_iadst_idct_16x16_add_avx;
379  dsp->itxfm_add[TX_16X16][ADST_ADST] = ff_vp9_iadst_iadst_16x16_add_avx;
380  dsp->itxfm_add[TX_32X32][ADST_ADST] =
381  dsp->itxfm_add[TX_32X32][ADST_DCT] =
382  dsp->itxfm_add[TX_32X32][DCT_ADST] =
383  dsp->itxfm_add[TX_32X32][DCT_DCT] = ff_vp9_idct_idct_32x32_add_avx;
384  }
385  init_lpf(avx);
386  init_ipred(TX_8X8, 8, avx);
387  init_ipred(TX_16X16, 16, avx);
388  init_ipred(TX_32X32, 32, avx);
389  }
390 
391 #undef init_fpel
392 #undef init_subpel1
393 #undef init_subpel2
394 #undef init_subpel3
395 
396 #endif /* HAVE_YASM */
397 }