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/cpu.h" |
27 |
|
|
#include "libavcodec/vp9dsp.h" |
28 |
|
|
#include "libavcodec/x86/vp9dsp_init.h" |
29 |
|
|
|
30 |
|
|
#if HAVE_X86ASM |
31 |
|
|
|
32 |
|
|
extern const int16_t ff_filters_16bpp[3][15][4][16]; |
33 |
|
|
|
34 |
|
|
decl_mc_funcs(4, sse2, int16_t, 16, BPC); |
35 |
|
|
decl_mc_funcs(8, sse2, int16_t, 16, BPC); |
36 |
|
|
decl_mc_funcs(16, avx2, int16_t, 16, BPC); |
37 |
|
|
|
38 |
|
1344 |
mc_rep_funcs(16, 8, 16, sse2, int16_t, 16, BPC) |
39 |
|
288 |
mc_rep_funcs(32, 16, 32, sse2, int16_t, 16, BPC) |
40 |
|
96 |
mc_rep_funcs(64, 32, 64, sse2, int16_t, 16, BPC) |
41 |
|
|
#if HAVE_AVX2_EXTERNAL |
42 |
|
288 |
mc_rep_funcs(32, 16, 32, avx2, int16_t, 16, BPC) |
43 |
|
48 |
mc_rep_funcs(64, 32, 64, avx2, int16_t, 16, BPC) |
44 |
|
|
#endif |
45 |
|
|
|
46 |
|
96 |
filters_8tap_2d_fn2(put, 16, BPC, 2, sse2, sse2, 16bpp) |
47 |
|
48 |
filters_8tap_2d_fn2(avg, 16, BPC, 2, sse2, sse2, 16bpp) |
48 |
|
|
#if HAVE_AVX2_EXTERNAL |
49 |
|
12 |
filters_8tap_2d_fn(put, 64, 32, BPC, 2, avx2, 16bpp) |
50 |
|
6 |
filters_8tap_2d_fn(avg, 64, 32, BPC, 2, avx2, 16bpp) |
51 |
|
6 |
filters_8tap_2d_fn(put, 32, 32, BPC, 2, avx2, 16bpp) |
52 |
|
6 |
filters_8tap_2d_fn(avg, 32, 32, BPC, 2, avx2, 16bpp) |
53 |
|
6 |
filters_8tap_2d_fn(put, 16, 32, BPC, 2, avx2, 16bpp) |
54 |
|
6 |
filters_8tap_2d_fn(avg, 16, 32, BPC, 2, avx2, 16bpp) |
55 |
|
|
#endif |
56 |
|
|
|
57 |
|
192 |
filters_8tap_1d_fn3(put, BPC, sse2, sse2, 16bpp) |
58 |
|
96 |
filters_8tap_1d_fn3(avg, BPC, sse2, sse2, 16bpp) |
59 |
|
|
#if HAVE_AVX2_EXTERNAL |
60 |
|
24 |
filters_8tap_1d_fn2(put, 64, BPC, avx2, 16bpp) |
61 |
|
12 |
filters_8tap_1d_fn2(avg, 64, BPC, avx2, 16bpp) |
62 |
|
12 |
filters_8tap_1d_fn2(put, 32, BPC, avx2, 16bpp) |
63 |
|
12 |
filters_8tap_1d_fn2(avg, 32, BPC, avx2, 16bpp) |
64 |
|
12 |
filters_8tap_1d_fn2(put, 16, BPC, avx2, 16bpp) |
65 |
|
12 |
filters_8tap_1d_fn2(avg, 16, BPC, avx2, 16bpp) |
66 |
|
|
#endif |
67 |
|
|
|
68 |
|
|
#define decl_lpf_func(dir, wd, bpp, opt) \ |
69 |
|
|
void ff_vp9_loop_filter_##dir##_##wd##_##bpp##_##opt(uint8_t *dst, ptrdiff_t stride, \ |
70 |
|
|
int E, int I, int H) |
71 |
|
|
|
72 |
|
|
#define decl_lpf_funcs(dir, wd, bpp) \ |
73 |
|
|
decl_lpf_func(dir, wd, bpp, sse2); \ |
74 |
|
|
decl_lpf_func(dir, wd, bpp, ssse3); \ |
75 |
|
|
decl_lpf_func(dir, wd, bpp, avx) |
76 |
|
|
|
77 |
|
|
#define decl_lpf_funcs_wd(dir) \ |
78 |
|
|
decl_lpf_funcs(dir, 4, BPC); \ |
79 |
|
|
decl_lpf_funcs(dir, 8, BPC); \ |
80 |
|
|
decl_lpf_funcs(dir, 16, BPC) |
81 |
|
|
|
82 |
|
|
decl_lpf_funcs_wd(h); |
83 |
|
|
decl_lpf_funcs_wd(v); |
84 |
|
|
|
85 |
|
|
#define lpf_16_wrapper(dir, off, bpp, opt) \ |
86 |
|
|
static void loop_filter_##dir##_16_##bpp##_##opt(uint8_t *dst, ptrdiff_t stride, \ |
87 |
|
|
int E, int I, int H) \ |
88 |
|
|
{ \ |
89 |
|
|
ff_vp9_loop_filter_##dir##_16_##bpp##_##opt(dst, stride, E, I, H); \ |
90 |
|
|
ff_vp9_loop_filter_##dir##_16_##bpp##_##opt(dst + off, stride, E, I, H); \ |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
#define lpf_16_wrappers(bpp, opt) \ |
94 |
|
|
lpf_16_wrapper(h, 8 * stride, bpp, opt) \ |
95 |
|
|
lpf_16_wrapper(v, 16, bpp, opt) |
96 |
|
|
|
97 |
|
16 |
lpf_16_wrappers(BPC, sse2) |
98 |
|
8 |
lpf_16_wrappers(BPC, ssse3) |
99 |
|
4 |
lpf_16_wrappers(BPC, avx) |
100 |
|
|
|
101 |
|
|
#define lpf_mix2_wrapper(dir, off, wd1, wd2, bpp, opt) \ |
102 |
|
|
static void loop_filter_##dir##_##wd1##wd2##_##bpp##_##opt(uint8_t *dst, ptrdiff_t stride, \ |
103 |
|
|
int E, int I, int H) \ |
104 |
|
|
{ \ |
105 |
|
|
ff_vp9_loop_filter_##dir##_##wd1##_##bpp##_##opt(dst, stride, \ |
106 |
|
|
E & 0xff, I & 0xff, H & 0xff); \ |
107 |
|
|
ff_vp9_loop_filter_##dir##_##wd2##_##bpp##_##opt(dst + off, stride, \ |
108 |
|
|
E >> 8, I >> 8, H >> 8); \ |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
#define lpf_mix2_wrappers(wd1, wd2, bpp, opt) \ |
112 |
|
|
lpf_mix2_wrapper(h, 8 * stride, wd1, wd2, bpp, opt) \ |
113 |
|
|
lpf_mix2_wrapper(v, 16, wd1, wd2, bpp, opt) |
114 |
|
|
|
115 |
|
|
#define lpf_mix2_wrappers_set(bpp, opt) \ |
116 |
|
|
lpf_mix2_wrappers(4, 4, bpp, opt) \ |
117 |
|
|
lpf_mix2_wrappers(4, 8, bpp, opt) \ |
118 |
|
|
lpf_mix2_wrappers(8, 4, bpp, opt) \ |
119 |
|
|
lpf_mix2_wrappers(8, 8, bpp, opt) \ |
120 |
|
|
|
121 |
|
64 |
lpf_mix2_wrappers_set(BPC, sse2) |
122 |
|
32 |
lpf_mix2_wrappers_set(BPC, ssse3) |
123 |
|
16 |
lpf_mix2_wrappers_set(BPC, avx) |
124 |
|
|
|
125 |
|
|
decl_ipred_fns(tm, BPC, mmxext, sse2); |
126 |
|
|
|
127 |
|
|
decl_itxfm_func(iwht, iwht, 4, BPC, mmxext); |
128 |
|
|
#if BPC == 10 |
129 |
|
|
decl_itxfm_func(idct, idct, 4, BPC, mmxext); |
130 |
|
|
decl_itxfm_funcs(4, BPC, ssse3); |
131 |
|
|
#else |
132 |
|
|
decl_itxfm_func(idct, idct, 4, BPC, sse2); |
133 |
|
|
#endif |
134 |
|
|
decl_itxfm_func(idct, iadst, 4, BPC, sse2); |
135 |
|
|
decl_itxfm_func(iadst, idct, 4, BPC, sse2); |
136 |
|
|
decl_itxfm_func(iadst, iadst, 4, BPC, sse2); |
137 |
|
|
decl_itxfm_funcs(8, BPC, sse2); |
138 |
|
|
decl_itxfm_funcs(16, BPC, sse2); |
139 |
|
|
decl_itxfm_func(idct, idct, 32, BPC, sse2); |
140 |
|
|
#endif /* HAVE_X86ASM */ |
141 |
|
|
|
142 |
|
149 |
av_cold void INIT_FUNC(VP9DSPContext *dsp, int bitexact) |
143 |
|
|
{ |
144 |
|
|
#if HAVE_X86ASM |
145 |
|
149 |
int cpu_flags = av_get_cpu_flags(); |
146 |
|
|
|
147 |
|
|
#define init_lpf_8_func(idx1, idx2, dir, wd, bpp, opt) \ |
148 |
|
|
dsp->loop_filter_8[idx1][idx2] = ff_vp9_loop_filter_##dir##_##wd##_##bpp##_##opt |
149 |
|
|
#define init_lpf_16_func(idx, dir, bpp, opt) \ |
150 |
|
|
dsp->loop_filter_16[idx] = loop_filter_##dir##_16_##bpp##_##opt |
151 |
|
|
#define init_lpf_mix2_func(idx1, idx2, idx3, dir, wd1, wd2, bpp, opt) \ |
152 |
|
|
dsp->loop_filter_mix2[idx1][idx2][idx3] = loop_filter_##dir##_##wd1##wd2##_##bpp##_##opt |
153 |
|
|
|
154 |
|
|
#define init_lpf_funcs(bpp, opt) \ |
155 |
|
|
init_lpf_8_func(0, 0, h, 4, bpp, opt); \ |
156 |
|
|
init_lpf_8_func(0, 1, v, 4, bpp, opt); \ |
157 |
|
|
init_lpf_8_func(1, 0, h, 8, bpp, opt); \ |
158 |
|
|
init_lpf_8_func(1, 1, v, 8, bpp, opt); \ |
159 |
|
|
init_lpf_8_func(2, 0, h, 16, bpp, opt); \ |
160 |
|
|
init_lpf_8_func(2, 1, v, 16, bpp, opt); \ |
161 |
|
|
init_lpf_16_func(0, h, bpp, opt); \ |
162 |
|
|
init_lpf_16_func(1, v, bpp, opt); \ |
163 |
|
|
init_lpf_mix2_func(0, 0, 0, h, 4, 4, bpp, opt); \ |
164 |
|
|
init_lpf_mix2_func(0, 1, 0, h, 4, 8, bpp, opt); \ |
165 |
|
|
init_lpf_mix2_func(1, 0, 0, h, 8, 4, bpp, opt); \ |
166 |
|
|
init_lpf_mix2_func(1, 1, 0, h, 8, 8, bpp, opt); \ |
167 |
|
|
init_lpf_mix2_func(0, 0, 1, v, 4, 4, bpp, opt); \ |
168 |
|
|
init_lpf_mix2_func(0, 1, 1, v, 4, 8, bpp, opt); \ |
169 |
|
|
init_lpf_mix2_func(1, 0, 1, v, 8, 4, bpp, opt); \ |
170 |
|
|
init_lpf_mix2_func(1, 1, 1, v, 8, 8, bpp, opt) |
171 |
|
|
|
172 |
|
|
#define init_itx_func(idxa, idxb, typea, typeb, size, bpp, opt) \ |
173 |
|
|
dsp->itxfm_add[idxa][idxb] = \ |
174 |
|
|
cat(ff_vp9_##typea##_##typeb##_##size##x##size##_add_, bpp, _##opt); |
175 |
|
|
#define init_itx_func_one(idx, typea, typeb, size, bpp, opt) \ |
176 |
|
|
init_itx_func(idx, DCT_DCT, typea, typeb, size, bpp, opt); \ |
177 |
|
|
init_itx_func(idx, ADST_DCT, typea, typeb, size, bpp, opt); \ |
178 |
|
|
init_itx_func(idx, DCT_ADST, typea, typeb, size, bpp, opt); \ |
179 |
|
|
init_itx_func(idx, ADST_ADST, typea, typeb, size, bpp, opt) |
180 |
|
|
#define init_itx_funcs(idx, size, bpp, opt) \ |
181 |
|
|
init_itx_func(idx, DCT_DCT, idct, idct, size, bpp, opt); \ |
182 |
|
|
init_itx_func(idx, ADST_DCT, idct, iadst, size, bpp, opt); \ |
183 |
|
|
init_itx_func(idx, DCT_ADST, iadst, idct, size, bpp, opt); \ |
184 |
|
|
init_itx_func(idx, ADST_ADST, iadst, iadst, size, bpp, opt); \ |
185 |
|
|
|
186 |
✓✓ |
149 |
if (EXTERNAL_MMXEXT(cpu_flags)) { |
187 |
|
110 |
init_ipred_func(tm, TM_VP8, 4, BPC, mmxext); |
188 |
✓✗ |
110 |
if (!bitexact) { |
189 |
|
110 |
init_itx_func_one(4 /* lossless */, iwht, iwht, 4, BPC, mmxext); |
190 |
|
|
#if BPC == 10 |
191 |
|
55 |
init_itx_func(TX_4X4, DCT_DCT, idct, idct, 4, 10, mmxext); |
192 |
|
|
#endif |
193 |
|
|
} |
194 |
|
|
} |
195 |
|
|
|
196 |
✓✓ |
149 |
if (EXTERNAL_SSE2(cpu_flags)) { |
197 |
|
90 |
init_subpel3(0, put, BPC, sse2); |
198 |
|
90 |
init_subpel3(1, avg, BPC, sse2); |
199 |
|
90 |
init_lpf_funcs(BPC, sse2); |
200 |
|
90 |
init_8_16_32_ipred_funcs(tm, TM_VP8, BPC, sse2); |
201 |
|
|
#if BPC == 10 |
202 |
✓✗ |
45 |
if (!bitexact) { |
203 |
|
45 |
init_itx_func(TX_4X4, ADST_DCT, idct, iadst, 4, 10, sse2); |
204 |
|
45 |
init_itx_func(TX_4X4, DCT_ADST, iadst, idct, 4, 10, sse2); |
205 |
|
45 |
init_itx_func(TX_4X4, ADST_ADST, iadst, iadst, 4, 10, sse2); |
206 |
|
|
} |
207 |
|
|
#else |
208 |
|
45 |
init_itx_funcs(TX_4X4, 4, 12, sse2); |
209 |
|
|
#endif |
210 |
|
90 |
init_itx_funcs(TX_8X8, 8, BPC, sse2); |
211 |
|
90 |
init_itx_funcs(TX_16X16, 16, BPC, sse2); |
212 |
|
90 |
init_itx_func_one(TX_32X32, idct, idct, 32, BPC, sse2); |
213 |
|
|
} |
214 |
|
|
|
215 |
✓✓ |
149 |
if (EXTERNAL_SSSE3(cpu_flags)) { |
216 |
|
70 |
init_lpf_funcs(BPC, ssse3); |
217 |
|
|
#if BPC == 10 |
218 |
✓✗ |
35 |
if (!bitexact) { |
219 |
|
35 |
init_itx_funcs(TX_4X4, 4, BPC, ssse3); |
220 |
|
|
} |
221 |
|
|
#endif |
222 |
|
|
} |
223 |
|
|
|
224 |
✓✓ |
149 |
if (EXTERNAL_AVX(cpu_flags)) { |
225 |
|
30 |
init_lpf_funcs(BPC, avx); |
226 |
|
|
} |
227 |
|
|
|
228 |
✓✓✓✗
|
149 |
if (EXTERNAL_AVX2_FAST(cpu_flags)) { |
229 |
|
|
#if HAVE_AVX2_EXTERNAL |
230 |
|
10 |
init_subpel3_32_64(0, put, BPC, avx2); |
231 |
|
10 |
init_subpel3_32_64(1, avg, BPC, avx2); |
232 |
|
10 |
init_subpel2(2, 0, 16, put, BPC, avx2); |
233 |
|
10 |
init_subpel2(2, 1, 16, avg, BPC, avx2); |
234 |
|
|
#endif |
235 |
|
|
} |
236 |
|
|
|
237 |
|
|
#endif /* HAVE_X86ASM */ |
238 |
|
|
|
239 |
|
149 |
ff_vp9dsp_init_16bpp_x86(dsp); |
240 |
|
149 |
} |