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_MMX(W) \
144 H264_WEIGHT(W, mmxext) \
145 H264_BIWEIGHT(W, mmxext)
146
147#define H264_BIWEIGHT_SSE(W) \
148 H264_WEIGHT(W, sse2) \
149 H264_BIWEIGHT(W, sse2) \
150 H264_BIWEIGHT(W, ssse3)
151
155
156#define H264_WEIGHT_10(W, DEPTH, OPT) \
157void ff_h264_weight_ ## W ## _ ## DEPTH ## _ ## OPT(uint8_t *dst, \
158 ptrdiff_t stride, \
159 int height, \
160 int log2_denom, \
161 int weight, \
162 int offset);
163
164#define H264_BIWEIGHT_10(W, DEPTH, OPT) \
165void ff_h264_biweight_ ## W ## _ ## DEPTH ## _ ## OPT(uint8_t *dst, \
166 uint8_t *src, \
167 ptrdiff_t stride, \
168 int height, \
169 int log2_denom, \
170 int weightd, \
171 int weights, \
172 int offset);
173
174#define H264_BIWEIGHT_10_SSE(W, DEPTH) \
175 H264_WEIGHT_10(W, DEPTH, sse2) \
176 H264_WEIGHT_10(W, DEPTH, sse4) \
177 H264_BIWEIGHT_10(W, DEPTH, sse2) \
178 H264_BIWEIGHT_10(W, DEPTH, sse4)
179
183
185 const int chroma_format_idc)
186{
188
189 if (EXTERNAL_MMXEXT(cpu_flags) && chroma_format_idc <= 1)
190 c->loop_filter_strength = ff_h264_loop_filter_strength_mmxext;
191
192 if (bit_depth == 8) {
193 if (EXTERNAL_MMX(cpu_flags)) {
194 if (chroma_format_idc <= 1) {
195 } else {
196 c->idct_add8 = ff_h264_idct_add8_422_8_mmx;
197 }
198 }
200 c->idct8_dc_add = ff_h264_idct8_dc_add_8_mmxext;
201
202 c->weight_pixels_tab[2] = ff_h264_weight_4_mmxext;
203
204 c->biweight_pixels_tab[2] = ff_h264_biweight_4_mmxext;
205 }
207 c->idct8_add = ff_h264_idct8_add_8_sse2;
208
209 c->idct_add16 = ff_h264_idct_add16_8_sse2;
210 c->idct8_add4 = ff_h264_idct8_add4_8_sse2;
211 if (chroma_format_idc <= 1)
212 c->idct_add8 = ff_h264_idct_add8_8_sse2;
213 c->idct_add16intra = ff_h264_idct_add16intra_8_sse2;
214 c->luma_dc_dequant_idct = ff_h264_luma_dc_dequant_idct_sse2;
215
216 c->weight_pixels_tab[0] = ff_h264_weight_16_sse2;
217 c->weight_pixels_tab[1] = ff_h264_weight_8_sse2;
218
219 c->biweight_pixels_tab[0] = ff_h264_biweight_16_sse2;
220 c->biweight_pixels_tab[1] = ff_h264_biweight_8_sse2;
221
222 c->v_loop_filter_luma = ff_deblock_v_luma_8_sse2;
223 c->h_loop_filter_luma = ff_deblock_h_luma_8_sse2;
224 c->v_loop_filter_luma_intra = ff_deblock_v_luma_intra_8_sse2;
225 c->h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_sse2;
226
227#if ARCH_X86_64
228 c->h_loop_filter_luma_mbaff = ff_deblock_h_luma_mbaff_8_sse2;
229#endif
230
231 c->v_loop_filter_chroma = ff_deblock_v_chroma_8_sse2;
232 c->v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_8_sse2;
233 if (chroma_format_idc <= 1) {
234 c->h_loop_filter_chroma = ff_deblock_h_chroma_8_sse2;
235 c->h_loop_filter_chroma_intra = ff_deblock_h_chroma_intra_8_sse2;
236 } else {
237 c->h_loop_filter_chroma = ff_deblock_h_chroma422_8_sse2;
238 c->h_loop_filter_chroma_intra = ff_deblock_h_chroma422_intra_8_sse2;
239 }
240
241 c->idct_add = ff_h264_idct_add_8_sse2;
242 c->idct_dc_add = ff_h264_idct_dc_add_8_sse2;
243 }
245 c->biweight_pixels_tab[0] = ff_h264_biweight_16_ssse3;
246 c->biweight_pixels_tab[1] = ff_h264_biweight_8_ssse3;
247 }
248 if (EXTERNAL_AVX(cpu_flags)) {
249 c->v_loop_filter_luma = ff_deblock_v_luma_8_avx;
250 c->h_loop_filter_luma = ff_deblock_h_luma_8_avx;
251 c->v_loop_filter_luma_intra = ff_deblock_v_luma_intra_8_avx;
252 c->h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_avx;
253#if ARCH_X86_64
254 c->h_loop_filter_luma_mbaff = ff_deblock_h_luma_mbaff_8_avx;
255#endif
256
257 c->v_loop_filter_chroma = ff_deblock_v_chroma_8_avx;
258 c->v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_8_avx;
259 if (chroma_format_idc <= 1) {
260 c->h_loop_filter_chroma = ff_deblock_h_chroma_8_avx;
261 c->h_loop_filter_chroma_intra = ff_deblock_h_chroma_intra_8_avx;
262 } else {
263 c->h_loop_filter_chroma = ff_deblock_h_chroma422_8_avx;
264 c->h_loop_filter_chroma_intra = ff_deblock_h_chroma422_intra_8_avx;
265 }
266
267 c->idct_add = ff_h264_idct_add_8_avx;
268 c->idct_dc_add = ff_h264_idct_dc_add_8_avx;
269 }
270 } else if (bit_depth == 10) {
272 c->idct_dc_add = ff_h264_idct_dc_add_10_mmxext;
273 }
275 c->idct_add = ff_h264_idct_add_10_sse2;
276 c->idct8_dc_add = ff_h264_idct8_dc_add_10_sse2;
277
278 c->idct_add16 = ff_h264_idct_add16_10_sse2;
279 if (chroma_format_idc <= 1) {
280 c->idct_add8 = ff_h264_idct_add8_10_sse2;
281 } else {
282 c->idct_add8 = ff_h264_idct_add8_422_10_sse2;
283 }
284 c->idct_add16intra = ff_h264_idct_add16intra_10_sse2;
285#if HAVE_ALIGNED_STACK
286 c->idct8_add = ff_h264_idct8_add_10_sse2;
287 c->idct8_add4 = ff_h264_idct8_add4_10_sse2;
288#endif /* HAVE_ALIGNED_STACK */
289
290 c->weight_pixels_tab[0] = ff_h264_weight_16_10_sse2;
291 c->weight_pixels_tab[1] = ff_h264_weight_8_10_sse2;
292 c->weight_pixels_tab[2] = ff_h264_weight_4_10_sse2;
293
294 c->biweight_pixels_tab[0] = ff_h264_biweight_16_10_sse2;
295 c->biweight_pixels_tab[1] = ff_h264_biweight_8_10_sse2;
296 c->biweight_pixels_tab[2] = ff_h264_biweight_4_10_sse2;
297
298 c->v_loop_filter_chroma = ff_deblock_v_chroma_10_sse2;
299 c->v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_10_sse2;
300 if (chroma_format_idc <= 1) {
301 c->h_loop_filter_chroma = ff_deblock_h_chroma_10_sse2;
302 } else {
303 c->h_loop_filter_chroma = ff_deblock_h_chroma422_10_sse2;
304 }
305 c->v_loop_filter_luma = ff_deblock_v_luma_10_sse2;
306 c->h_loop_filter_luma = ff_deblock_h_luma_10_sse2;
307 c->v_loop_filter_luma_intra = ff_deblock_v_luma_intra_10_sse2;
308 c->h_loop_filter_luma_intra = ff_deblock_h_luma_intra_10_sse2;
309 }
311 c->weight_pixels_tab[0] = ff_h264_weight_16_10_sse4;
312 c->weight_pixels_tab[1] = ff_h264_weight_8_10_sse4;
313 c->weight_pixels_tab[2] = ff_h264_weight_4_10_sse4;
314
315 c->biweight_pixels_tab[0] = ff_h264_biweight_16_10_sse4;
316 c->biweight_pixels_tab[1] = ff_h264_biweight_8_10_sse4;
317 c->biweight_pixels_tab[2] = ff_h264_biweight_4_10_sse4;
318 }
319 if (EXTERNAL_AVX(cpu_flags)) {
320 c->idct_dc_add =
321 c->idct_add = ff_h264_idct_add_10_avx;
322 c->idct8_dc_add = ff_h264_idct8_dc_add_10_avx;
323
324 c->idct_add16 = ff_h264_idct_add16_10_avx;
325 if (chroma_format_idc <= 1) {
326 c->idct_add8 = ff_h264_idct_add8_10_avx;
327 } else {
328 c->idct_add8 = ff_h264_idct_add8_422_10_avx;
329 }
330 c->idct_add16intra = ff_h264_idct_add16intra_10_avx;
331#if HAVE_ALIGNED_STACK
332 c->idct8_add = ff_h264_idct8_add_10_avx;
333 c->idct8_add4 = ff_h264_idct8_add4_10_avx;
334#endif /* HAVE_ALIGNED_STACK */
335
336 c->v_loop_filter_chroma = ff_deblock_v_chroma_10_avx;
337 c->v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_10_avx;
338 if (chroma_format_idc <= 1) {
339 c->h_loop_filter_chroma = ff_deblock_h_chroma_10_avx;
340 } else {
341 c->h_loop_filter_chroma = ff_deblock_h_chroma422_10_avx;
342 }
343 c->v_loop_filter_luma = ff_deblock_v_luma_10_avx;
344 c->h_loop_filter_luma = ff_deblock_h_luma_10_avx;
345 c->v_loop_filter_luma_intra = ff_deblock_v_luma_intra_10_avx;
346 c->h_loop_filter_luma_intra = ff_deblock_h_luma_intra_10_avx;
347 }
348 }
349}
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 H264_BIWEIGHT_MMX(W)
#define LF_FUNC(DIR, TYPE, DEPTH, OPT)
#define IDCT_ADD_REP_FUNC(NUM, REP, DEPTH, OPT)