FFmpeg
Loading...
Searching...
No Matches
h264dsp_init.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2004-2005 Michael Niedermayer, Loren Merritt
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
22#include "libavutil/cpu.h"
23#include "libavutil/x86/cpu.h"
24#include "libavcodec/h264dsp.h"
25
26/***********************************/
27/* IDCT */
28#define IDCT_ADD_FUNC(NUM, DEPTH, OPT) \
29void ff_h264_idct ## NUM ## _add_ ## DEPTH ## _ ## OPT(uint8_t *dst, \
30 int16_t *block, \
31 ptrdiff_t stride);
32
33IDCT_ADD_FUNC(, 8, sse2)
34IDCT_ADD_FUNC(, 8, avx)
35IDCT_ADD_FUNC(, 10, sse2)
36IDCT_ADD_FUNC(_dc, 8, sse2)
37IDCT_ADD_FUNC(_dc, 8, avx)
38IDCT_ADD_FUNC(_dc, 10, mmxext)
39IDCT_ADD_FUNC(8_dc, 8, mmxext)
40IDCT_ADD_FUNC(8_dc, 10, sse2)
41IDCT_ADD_FUNC(8, 8, sse2)
42IDCT_ADD_FUNC(8, 10, sse2)
43IDCT_ADD_FUNC(, 10, avx)
44IDCT_ADD_FUNC(8_dc, 10, avx)
45IDCT_ADD_FUNC(8, 10, avx)
46
47
48#define IDCT_ADD_REP_FUNC(NUM, REP, DEPTH, OPT) \
49void ff_h264_idct ## NUM ## _add ## REP ## _ ## DEPTH ## _ ## OPT \
50 (uint8_t *dst, const int *block_offset, \
51 int16_t *block, ptrdiff_t stride, const uint8_t nnzc[5 * 8]);
52
53IDCT_ADD_REP_FUNC(8, 4, 8, sse2)
54IDCT_ADD_REP_FUNC(8, 4, 10, sse2)
55IDCT_ADD_REP_FUNC(8, 4, 10, avx)
56IDCT_ADD_REP_FUNC(, 16, 8, sse2)
57IDCT_ADD_REP_FUNC(, 16, 10, sse2)
58IDCT_ADD_REP_FUNC(, 16intra, 8, sse2)
59IDCT_ADD_REP_FUNC(, 16intra, 10, sse2)
60IDCT_ADD_REP_FUNC(, 16, 10, avx)
61IDCT_ADD_REP_FUNC(, 16intra, 10, avx)
62
63
64#define IDCT_ADD_REP_FUNC2(NUM, REP, DEPTH, OPT) \
65void ff_h264_idct ## NUM ## _add ## REP ## _ ## DEPTH ## _ ## OPT \
66 (uint8_t **dst, const int *block_offset, \
67 int16_t *block, ptrdiff_t stride, const uint8_t nnzc[15 * 8]);
68
69IDCT_ADD_REP_FUNC2(, 8, 8, sse2)
70IDCT_ADD_REP_FUNC2(, 8, 10, sse2)
71IDCT_ADD_REP_FUNC2(, 8, 10, avx)
72
73IDCT_ADD_REP_FUNC2(, 8_422, 8, mmx)
74
75IDCT_ADD_REP_FUNC2(, 8_422, 10, sse2)
76IDCT_ADD_REP_FUNC2(, 8_422, 10, avx)
77
78void ff_h264_luma_dc_dequant_idct_sse2(int16_t *output, int16_t *input, int qmul);
79
80/***********************************/
81/* deblocking */
82
83void ff_h264_loop_filter_strength_mmxext(int16_t bS[2][4][4], uint8_t nnz[40],
84 int8_t ref[2][40],
85 int16_t mv[2][40][2],
86 int bidir, int edges, int step,
87 int mask_mv0, int mask_mv1, int field);
88
89#define LF_FUNC(DIR, TYPE, DEPTH, OPT) \
90void ff_deblock_ ## DIR ## _ ## TYPE ## _ ## DEPTH ## _ ## OPT(uint8_t *pix, \
91 ptrdiff_t stride, \
92 int alpha, \
93 int beta, \
94 int8_t *tc0);
95#define LF_IFUNC(DIR, TYPE, DEPTH, OPT) \
96void ff_deblock_ ## DIR ## _ ## TYPE ## _ ## DEPTH ## _ ## OPT(uint8_t *pix, \
97 ptrdiff_t stride, \
98 int alpha, \
99 int beta);
100
101#define LF_FUNCS(type, depth) \
102LF_FUNC(h, luma, depth, sse2) \
103LF_IFUNC(h, luma_intra, depth, sse2) \
104LF_FUNC(v, luma, depth, sse2) \
105LF_IFUNC(v, luma_intra, depth, sse2) \
106LF_FUNC(h, chroma, depth, sse2) \
107LF_IFUNC(h, chroma_intra, depth, sse2) \
108LF_FUNC(h, chroma422, depth, sse2) \
109LF_IFUNC(h, chroma422_intra, depth, sse2) \
110LF_FUNC(v, chroma, depth, sse2) \
111LF_IFUNC(v, chroma_intra, depth, sse2) \
112LF_FUNC(h, luma, depth, avx) \
113LF_IFUNC(h, luma_intra, depth, avx) \
114LF_FUNC(v, luma, depth, avx) \
115LF_IFUNC(v, luma_intra, depth, avx) \
116LF_FUNC(h, chroma, depth, avx) \
117LF_IFUNC(h, chroma_intra, depth, avx) \
118LF_FUNC(h, chroma422, depth, avx) \
119LF_IFUNC(h, chroma422_intra, depth, avx) \
120LF_FUNC(v, chroma, depth, avx) \
121LF_IFUNC(v, chroma_intra, depth, avx)
122
123LF_FUNC(h, luma_mbaff, 8, sse2)
124LF_FUNC(h, luma_mbaff, 8, avx)
125
126LF_FUNCS(uint8_t, 8)
127LF_FUNCS(uint16_t, 10)
128
129/***********************************/
130/* weighted prediction */
131
132#define H264_WEIGHT(W, OPT) \
133void ff_h264_weight_ ## W ## _ ## OPT(uint8_t *dst, ptrdiff_t stride, \
134 int height, int log2_denom, \
135 int weight, int offset);
136
137#define H264_BIWEIGHT(W, OPT) \
138void ff_h264_biweight_ ## W ## _ ## OPT(uint8_t *dst, uint8_t *src, \
139 ptrdiff_t stride, int height, \
140 int log2_denom, int weightd, \
141 int weights, int offset);
142
143#define H264_BIWEIGHT_SSE(W) \
144 H264_WEIGHT(W, sse2) \
145 H264_BIWEIGHT(W, sse2) \
146 H264_BIWEIGHT(W, ssse3)
147
151
152#define H264_WEIGHT_10(W, DEPTH, OPT) \
153void ff_h264_weight_ ## W ## _ ## DEPTH ## _ ## OPT(uint8_t *dst, \
154 ptrdiff_t stride, \
155 int height, \
156 int log2_denom, \
157 int weight, \
158 int offset);
159
160#define H264_BIWEIGHT_10(W, DEPTH, OPT) \
161void ff_h264_biweight_ ## W ## _ ## DEPTH ## _ ## OPT(uint8_t *dst, \
162 uint8_t *src, \
163 ptrdiff_t stride, \
164 int height, \
165 int log2_denom, \
166 int weightd, \
167 int weights, \
168 int offset);
169
170#define H264_BIWEIGHT_10_SSE(W, DEPTH) \
171 H264_WEIGHT_10(W, DEPTH, sse2) \
172 H264_WEIGHT_10(W, DEPTH, sse4) \
173 H264_BIWEIGHT_10(W, DEPTH, sse2) \
174 H264_BIWEIGHT_10(W, DEPTH, sse4)
175
179
181 const int chroma_format_idc)
182{
184
185 if (EXTERNAL_MMXEXT(cpu_flags) && chroma_format_idc <= 1)
186 c->loop_filter_strength = ff_h264_loop_filter_strength_mmxext;
187
188 if (bit_depth == 8) {
189 if (EXTERNAL_MMX(cpu_flags)) {
190 if (chroma_format_idc <= 1) {
191 } else {
192 c->idct_add8 = ff_h264_idct_add8_422_8_mmx;
193 }
194 }
196 c->idct8_dc_add = ff_h264_idct8_dc_add_8_mmxext;
197 }
199 c->idct8_add = ff_h264_idct8_add_8_sse2;
200
201 c->idct_add16 = ff_h264_idct_add16_8_sse2;
202 c->idct8_add4 = ff_h264_idct8_add4_8_sse2;
203 if (chroma_format_idc <= 1)
204 c->idct_add8 = ff_h264_idct_add8_8_sse2;
205 c->idct_add16intra = ff_h264_idct_add16intra_8_sse2;
206 c->luma_dc_dequant_idct = ff_h264_luma_dc_dequant_idct_sse2;
207
208 c->weight_pixels_tab[0] = ff_h264_weight_16_sse2;
209 c->weight_pixels_tab[1] = ff_h264_weight_8_sse2;
210 c->weight_pixels_tab[2] = ff_h264_weight_4_sse2;
211
212 c->biweight_pixels_tab[0] = ff_h264_biweight_16_sse2;
213 c->biweight_pixels_tab[1] = ff_h264_biweight_8_sse2;
214 c->biweight_pixels_tab[2] = ff_h264_biweight_4_sse2;
215
216 c->v_loop_filter_luma = ff_deblock_v_luma_8_sse2;
217 c->h_loop_filter_luma = ff_deblock_h_luma_8_sse2;
218 c->v_loop_filter_luma_intra = ff_deblock_v_luma_intra_8_sse2;
219 c->h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_sse2;
220
221#if ARCH_X86_64
222 c->h_loop_filter_luma_mbaff = ff_deblock_h_luma_mbaff_8_sse2;
223#endif
224
225 c->v_loop_filter_chroma = ff_deblock_v_chroma_8_sse2;
226 c->v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_8_sse2;
227 if (chroma_format_idc <= 1) {
228 c->h_loop_filter_chroma = ff_deblock_h_chroma_8_sse2;
229 c->h_loop_filter_chroma_intra = ff_deblock_h_chroma_intra_8_sse2;
230 } else {
231 c->h_loop_filter_chroma = ff_deblock_h_chroma422_8_sse2;
232 c->h_loop_filter_chroma_intra = ff_deblock_h_chroma422_intra_8_sse2;
233 }
234
235 c->idct_add = ff_h264_idct_add_8_sse2;
236 c->idct_dc_add = ff_h264_idct_dc_add_8_sse2;
237 }
239 c->biweight_pixels_tab[0] = ff_h264_biweight_16_ssse3;
240 c->biweight_pixels_tab[1] = ff_h264_biweight_8_ssse3;
241 c->biweight_pixels_tab[2] = ff_h264_biweight_4_ssse3;
242 }
243 if (EXTERNAL_AVX(cpu_flags)) {
244 c->v_loop_filter_luma = ff_deblock_v_luma_8_avx;
245 c->h_loop_filter_luma = ff_deblock_h_luma_8_avx;
246 c->v_loop_filter_luma_intra = ff_deblock_v_luma_intra_8_avx;
247 c->h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_avx;
248#if ARCH_X86_64
249 c->h_loop_filter_luma_mbaff = ff_deblock_h_luma_mbaff_8_avx;
250#endif
251
252 c->v_loop_filter_chroma = ff_deblock_v_chroma_8_avx;
253 c->v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_8_avx;
254 if (chroma_format_idc <= 1) {
255 c->h_loop_filter_chroma = ff_deblock_h_chroma_8_avx;
256 c->h_loop_filter_chroma_intra = ff_deblock_h_chroma_intra_8_avx;
257 } else {
258 c->h_loop_filter_chroma = ff_deblock_h_chroma422_8_avx;
259 c->h_loop_filter_chroma_intra = ff_deblock_h_chroma422_intra_8_avx;
260 }
261
262 c->idct_add = ff_h264_idct_add_8_avx;
263 c->idct_dc_add = ff_h264_idct_dc_add_8_avx;
264 }
265 } else if (bit_depth == 10) {
267 c->idct_dc_add = ff_h264_idct_dc_add_10_mmxext;
268 }
270 c->idct_add = ff_h264_idct_add_10_sse2;
271 c->idct8_dc_add = ff_h264_idct8_dc_add_10_sse2;
272
273 c->idct_add16 = ff_h264_idct_add16_10_sse2;
274 if (chroma_format_idc <= 1) {
275 c->idct_add8 = ff_h264_idct_add8_10_sse2;
276 } else {
277 c->idct_add8 = ff_h264_idct_add8_422_10_sse2;
278 }
279 c->idct_add16intra = ff_h264_idct_add16intra_10_sse2;
280#if HAVE_ALIGNED_STACK
281 c->idct8_add = ff_h264_idct8_add_10_sse2;
282 c->idct8_add4 = ff_h264_idct8_add4_10_sse2;
283#endif /* HAVE_ALIGNED_STACK */
284
285 c->weight_pixels_tab[0] = ff_h264_weight_16_10_sse2;
286 c->weight_pixels_tab[1] = ff_h264_weight_8_10_sse2;
287 c->weight_pixels_tab[2] = ff_h264_weight_4_10_sse2;
288
289 c->biweight_pixels_tab[0] = ff_h264_biweight_16_10_sse2;
290 c->biweight_pixels_tab[1] = ff_h264_biweight_8_10_sse2;
291 c->biweight_pixels_tab[2] = ff_h264_biweight_4_10_sse2;
292
293 c->v_loop_filter_chroma = ff_deblock_v_chroma_10_sse2;
294 c->v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_10_sse2;
295 if (chroma_format_idc <= 1) {
296 c->h_loop_filter_chroma = ff_deblock_h_chroma_10_sse2;
297 } else {
298 c->h_loop_filter_chroma = ff_deblock_h_chroma422_10_sse2;
299 }
300 c->v_loop_filter_luma = ff_deblock_v_luma_10_sse2;
301 c->h_loop_filter_luma = ff_deblock_h_luma_10_sse2;
302 c->v_loop_filter_luma_intra = ff_deblock_v_luma_intra_10_sse2;
303 c->h_loop_filter_luma_intra = ff_deblock_h_luma_intra_10_sse2;
304 }
306 c->weight_pixels_tab[0] = ff_h264_weight_16_10_sse4;
307 c->weight_pixels_tab[1] = ff_h264_weight_8_10_sse4;
308 c->weight_pixels_tab[2] = ff_h264_weight_4_10_sse4;
309
310 c->biweight_pixels_tab[0] = ff_h264_biweight_16_10_sse4;
311 c->biweight_pixels_tab[1] = ff_h264_biweight_8_10_sse4;
312 c->biweight_pixels_tab[2] = ff_h264_biweight_4_10_sse4;
313 }
314 if (EXTERNAL_AVX(cpu_flags)) {
315 c->idct_dc_add =
316 c->idct_add = ff_h264_idct_add_10_avx;
317 c->idct8_dc_add = ff_h264_idct8_dc_add_10_avx;
318
319 c->idct_add16 = ff_h264_idct_add16_10_avx;
320 if (chroma_format_idc <= 1) {
321 c->idct_add8 = ff_h264_idct_add8_10_avx;
322 } else {
323 c->idct_add8 = ff_h264_idct_add8_422_10_avx;
324 }
325 c->idct_add16intra = ff_h264_idct_add16intra_10_avx;
326#if HAVE_ALIGNED_STACK
327 c->idct8_add = ff_h264_idct8_add_10_avx;
328 c->idct8_add4 = ff_h264_idct8_add4_10_avx;
329#endif /* HAVE_ALIGNED_STACK */
330
331 c->v_loop_filter_chroma = ff_deblock_v_chroma_10_avx;
332 c->v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_10_avx;
333 if (chroma_format_idc <= 1) {
334 c->h_loop_filter_chroma = ff_deblock_h_chroma_10_avx;
335 } else {
336 c->h_loop_filter_chroma = ff_deblock_h_chroma422_10_avx;
337 }
338 c->v_loop_filter_luma = ff_deblock_v_luma_10_avx;
339 c->h_loop_filter_luma = ff_deblock_h_luma_10_avx;
340 c->v_loop_filter_luma_intra = ff_deblock_v_luma_intra_10_avx;
341 c->h_loop_filter_luma_intra = ff_deblock_h_luma_intra_10_avx;
342 }
343 }
344}
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition af_astats.c:246
H.264 DSP functions.
void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth, const int chroma_format_idc)
static const int8_t mv[256][2]
Definition 4xm.c:81
Macro definitions for various function/variable attributes.
#define av_cold
Definition attributes.h:117
static atomic_int cpu_flags
Definition cpu.c:56
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition cpu.c:109
#define EXTERNAL_AVX(flags)
Definition cpu.h:64
#define EXTERNAL_MMXEXT(flags)
Definition cpu.h:51
#define EXTERNAL_SSSE3(flags)
Definition cpu.h:59
#define EXTERNAL_MMX(flags)
Definition cpu.h:50
#define EXTERNAL_SSE4(flags)
Definition cpu.h:62
#define EXTERNAL_SSE2(flags)
Definition cpu.h:53
Context for storing H.264 DSP functions.
Definition h264dsp.h:42
static int ref[MAX_W *MAX_W]
static double c[64]
#define IDCT_ADD_REP_FUNC2(NUM, REP, DEPTH, OPT)
void ff_h264_luma_dc_dequant_idct_sse2(int16_t *output, int16_t *input, int qmul)
void ff_h264_loop_filter_strength_mmxext(int16_t bS[2][4][4], uint8_t nnz[40], int8_t ref[2][40], int16_t mv[2][40][2], int bidir, int edges, int step, int mask_mv0, int mask_mv1, int field)
#define H264_BIWEIGHT_SSE(W)
#define LF_FUNCS(type, depth)
#define IDCT_ADD_FUNC(NUM, DEPTH, OPT)
#define H264_BIWEIGHT_10_SSE(W, DEPTH)
#define LF_FUNC(DIR, TYPE, DEPTH, OPT)
#define IDCT_ADD_REP_FUNC(NUM, REP, DEPTH, OPT)