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