FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/x86/h264dsp_init.c
Date: 2026-08-19 01:31:13
Exec Total Coverage
Lines: 112 112 100.0%
Functions: 1 1 100.0%
Branches: 42 42 100.0%

Line Branch Exec Source
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
21 #include "libavutil/attributes.h"
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) \
29 void ff_h264_idct ## NUM ## _add_ ## DEPTH ## _ ## OPT(uint8_t *dst, \
30 int16_t *block, \
31 ptrdiff_t stride);
32
33 IDCT_ADD_FUNC(, 8, sse2)
34 IDCT_ADD_FUNC(, 8, avx)
35 IDCT_ADD_FUNC(, 10, sse2)
36 IDCT_ADD_FUNC(_dc, 8, sse2)
37 IDCT_ADD_FUNC(_dc, 8, avx)
38 IDCT_ADD_FUNC(_dc, 10, mmxext)
39 IDCT_ADD_FUNC(8_dc, 8, mmxext)
40 IDCT_ADD_FUNC(8_dc, 10, sse2)
41 IDCT_ADD_FUNC(8, 8, sse2)
42 IDCT_ADD_FUNC(8, 10, sse2)
43 IDCT_ADD_FUNC(, 10, avx)
44 IDCT_ADD_FUNC(8_dc, 10, avx)
45 IDCT_ADD_FUNC(8, 10, avx)
46
47
48 #define IDCT_ADD_REP_FUNC(NUM, REP, DEPTH, OPT) \
49 void 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
53 IDCT_ADD_REP_FUNC(8, 4, 8, sse2)
54 IDCT_ADD_REP_FUNC(8, 4, 10, sse2)
55 IDCT_ADD_REP_FUNC(8, 4, 10, avx)
56 IDCT_ADD_REP_FUNC(, 16, 8, sse2)
57 IDCT_ADD_REP_FUNC(, 16, 10, sse2)
58 IDCT_ADD_REP_FUNC(, 16intra, 8, sse2)
59 IDCT_ADD_REP_FUNC(, 16intra, 10, sse2)
60 IDCT_ADD_REP_FUNC(, 16, 10, avx)
61 IDCT_ADD_REP_FUNC(, 16intra, 10, avx)
62
63
64 #define IDCT_ADD_REP_FUNC2(NUM, REP, DEPTH, OPT) \
65 void 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
69 IDCT_ADD_REP_FUNC2(, 8, 8, sse2)
70 IDCT_ADD_REP_FUNC2(, 8, 10, sse2)
71 IDCT_ADD_REP_FUNC2(, 8, 10, avx)
72
73 IDCT_ADD_REP_FUNC2(, 8_422, 8, mmx)
74
75 IDCT_ADD_REP_FUNC2(, 8_422, 10, sse2)
76 IDCT_ADD_REP_FUNC2(, 8_422, 10, avx)
77
78 void ff_h264_luma_dc_dequant_idct_sse2(int16_t *output, int16_t *input, int qmul);
79
80 /***********************************/
81 /* deblocking */
82
83 void 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) \
90 void 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) \
96 void 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) \
102 LF_FUNC(h, luma, depth, sse2) \
103 LF_IFUNC(h, luma_intra, depth, sse2) \
104 LF_FUNC(v, luma, depth, sse2) \
105 LF_IFUNC(v, luma_intra, depth, sse2) \
106 LF_FUNC(h, chroma, depth, sse2) \
107 LF_IFUNC(h, chroma_intra, depth, sse2) \
108 LF_FUNC(h, chroma422, depth, sse2) \
109 LF_IFUNC(h, chroma422_intra, depth, sse2) \
110 LF_FUNC(v, chroma, depth, sse2) \
111 LF_IFUNC(v, chroma_intra, depth, sse2) \
112 LF_FUNC(h, luma, depth, avx) \
113 LF_IFUNC(h, luma_intra, depth, avx) \
114 LF_FUNC(v, luma, depth, avx) \
115 LF_IFUNC(v, luma_intra, depth, avx) \
116 LF_FUNC(h, chroma, depth, avx) \
117 LF_IFUNC(h, chroma_intra, depth, avx) \
118 LF_FUNC(h, chroma422, depth, avx) \
119 LF_IFUNC(h, chroma422_intra, depth, avx) \
120 LF_FUNC(v, chroma, depth, avx) \
121 LF_IFUNC(v, chroma_intra, depth, avx)
122
123 LF_FUNC(h, luma_mbaff, 8, sse2)
124 LF_FUNC(h, luma_mbaff, 8, avx)
125
126 LF_FUNCS(uint8_t, 8)
127 LF_FUNCS(uint16_t, 10)
128
129 /***********************************/
130 /* weighted prediction */
131
132 #define H264_WEIGHT(W, OPT) \
133 void 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) \
138 void 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
152 H264_BIWEIGHT_SSE(16)
153 H264_BIWEIGHT_SSE(8)
154 H264_BIWEIGHT_MMX(4)
155
156 #define H264_WEIGHT_10(W, DEPTH, OPT) \
157 void 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) \
165 void 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
180 H264_BIWEIGHT_10_SSE(16, 10)
181 H264_BIWEIGHT_10_SSE(8, 10)
182 H264_BIWEIGHT_10_SSE(4, 10)
183
184 1461 av_cold void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth,
185 const int chroma_format_idc)
186 {
187 1461 int cpu_flags = av_get_cpu_flags();
188
189
4/4
✓ Branch 0 taken 507 times.
✓ Branch 1 taken 954 times.
✓ Branch 2 taken 428 times.
✓ Branch 3 taken 79 times.
1461 if (EXTERNAL_MMXEXT(cpu_flags) && chroma_format_idc <= 1)
190 428 c->loop_filter_strength = ff_h264_loop_filter_strength_mmxext;
191
192
2/2
✓ Branch 0 taken 1153 times.
✓ Branch 1 taken 308 times.
1461 if (bit_depth == 8) {
193
2/2
✓ Branch 0 taken 286 times.
✓ Branch 1 taken 867 times.
1153 if (EXTERNAL_MMX(cpu_flags)) {
194
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 253 times.
286 if (chroma_format_idc <= 1) {
195 } else {
196 33 c->idct_add8 = ff_h264_idct_add8_422_8_mmx;
197 }
198 }
199
2/2
✓ Branch 0 taken 279 times.
✓ Branch 1 taken 874 times.
1153 if (EXTERNAL_MMXEXT(cpu_flags)) {
200 279 c->idct8_dc_add = ff_h264_idct8_dc_add_8_mmxext;
201
202 279 c->weight_pixels_tab[2] = ff_h264_weight_4_mmxext;
203
204 279 c->biweight_pixels_tab[2] = ff_h264_biweight_4_mmxext;
205 }
206
2/2
✓ Branch 0 taken 265 times.
✓ Branch 1 taken 888 times.
1153 if (EXTERNAL_SSE2(cpu_flags)) {
207 265 c->idct8_add = ff_h264_idct8_add_8_sse2;
208
209 265 c->idct_add16 = ff_h264_idct_add16_8_sse2;
210 265 c->idct8_add4 = ff_h264_idct8_add4_8_sse2;
211
2/2
✓ Branch 0 taken 238 times.
✓ Branch 1 taken 27 times.
265 if (chroma_format_idc <= 1)
212 238 c->idct_add8 = ff_h264_idct_add8_8_sse2;
213 265 c->idct_add16intra = ff_h264_idct_add16intra_8_sse2;
214 265 c->luma_dc_dequant_idct = ff_h264_luma_dc_dequant_idct_sse2;
215
216 265 c->weight_pixels_tab[0] = ff_h264_weight_16_sse2;
217 265 c->weight_pixels_tab[1] = ff_h264_weight_8_sse2;
218
219 265 c->biweight_pixels_tab[0] = ff_h264_biweight_16_sse2;
220 265 c->biweight_pixels_tab[1] = ff_h264_biweight_8_sse2;
221
222 265 c->v_loop_filter_luma = ff_deblock_v_luma_8_sse2;
223 265 c->h_loop_filter_luma = ff_deblock_h_luma_8_sse2;
224 265 c->v_loop_filter_luma_intra = ff_deblock_v_luma_intra_8_sse2;
225 265 c->h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_sse2;
226
227 #if ARCH_X86_64
228 265 c->h_loop_filter_luma_mbaff = ff_deblock_h_luma_mbaff_8_sse2;
229 #endif
230
231 265 c->v_loop_filter_chroma = ff_deblock_v_chroma_8_sse2;
232 265 c->v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_8_sse2;
233
2/2
✓ Branch 0 taken 238 times.
✓ Branch 1 taken 27 times.
265 if (chroma_format_idc <= 1) {
234 238 c->h_loop_filter_chroma = ff_deblock_h_chroma_8_sse2;
235 238 c->h_loop_filter_chroma_intra = ff_deblock_h_chroma_intra_8_sse2;
236 } else {
237 27 c->h_loop_filter_chroma = ff_deblock_h_chroma422_8_sse2;
238 27 c->h_loop_filter_chroma_intra = ff_deblock_h_chroma422_intra_8_sse2;
239 }
240
241 265 c->idct_add = ff_h264_idct_add_8_sse2;
242 265 c->idct_dc_add = ff_h264_idct_dc_add_8_sse2;
243 }
244
2/2
✓ Branch 0 taken 251 times.
✓ Branch 1 taken 902 times.
1153 if (EXTERNAL_SSSE3(cpu_flags)) {
245 251 c->biweight_pixels_tab[0] = ff_h264_biweight_16_ssse3;
246 251 c->biweight_pixels_tab[1] = ff_h264_biweight_8_ssse3;
247 }
248
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 937 times.
1153 if (EXTERNAL_AVX(cpu_flags)) {
249 216 c->v_loop_filter_luma = ff_deblock_v_luma_8_avx;
250 216 c->h_loop_filter_luma = ff_deblock_h_luma_8_avx;
251 216 c->v_loop_filter_luma_intra = ff_deblock_v_luma_intra_8_avx;
252 216 c->h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_avx;
253 #if ARCH_X86_64
254 216 c->h_loop_filter_luma_mbaff = ff_deblock_h_luma_mbaff_8_avx;
255 #endif
256
257 216 c->v_loop_filter_chroma = ff_deblock_v_chroma_8_avx;
258 216 c->v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_8_avx;
259
2/2
✓ Branch 0 taken 203 times.
✓ Branch 1 taken 13 times.
216 if (chroma_format_idc <= 1) {
260 203 c->h_loop_filter_chroma = ff_deblock_h_chroma_8_avx;
261 203 c->h_loop_filter_chroma_intra = ff_deblock_h_chroma_intra_8_avx;
262 } else {
263 13 c->h_loop_filter_chroma = ff_deblock_h_chroma422_8_avx;
264 13 c->h_loop_filter_chroma_intra = ff_deblock_h_chroma422_intra_8_avx;
265 }
266
267 216 c->idct_add = ff_h264_idct_add_8_avx;
268 216 c->idct_dc_add = ff_h264_idct_dc_add_8_avx;
269 }
270
2/2
✓ Branch 0 taken 149 times.
✓ Branch 1 taken 159 times.
308 } else if (bit_depth == 10) {
271
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 53 times.
149 if (EXTERNAL_MMXEXT(cpu_flags)) {
272 96 c->idct_dc_add = ff_h264_idct_dc_add_10_mmxext;
273 }
274
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 67 times.
149 if (EXTERNAL_SSE2(cpu_flags)) {
275 82 c->idct_add = ff_h264_idct_add_10_sse2;
276 82 c->idct8_dc_add = ff_h264_idct8_dc_add_10_sse2;
277
278 82 c->idct_add16 = ff_h264_idct_add16_10_sse2;
279
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 20 times.
82 if (chroma_format_idc <= 1) {
280 62 c->idct_add8 = ff_h264_idct_add8_10_sse2;
281 } else {
282 20 c->idct_add8 = ff_h264_idct_add8_422_10_sse2;
283 }
284 82 c->idct_add16intra = ff_h264_idct_add16intra_10_sse2;
285 #if HAVE_ALIGNED_STACK
286 82 c->idct8_add = ff_h264_idct8_add_10_sse2;
287 82 c->idct8_add4 = ff_h264_idct8_add4_10_sse2;
288 #endif /* HAVE_ALIGNED_STACK */
289
290 82 c->weight_pixels_tab[0] = ff_h264_weight_16_10_sse2;
291 82 c->weight_pixels_tab[1] = ff_h264_weight_8_10_sse2;
292 82 c->weight_pixels_tab[2] = ff_h264_weight_4_10_sse2;
293
294 82 c->biweight_pixels_tab[0] = ff_h264_biweight_16_10_sse2;
295 82 c->biweight_pixels_tab[1] = ff_h264_biweight_8_10_sse2;
296 82 c->biweight_pixels_tab[2] = ff_h264_biweight_4_10_sse2;
297
298 82 c->v_loop_filter_chroma = ff_deblock_v_chroma_10_sse2;
299 82 c->v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_10_sse2;
300
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 20 times.
82 if (chroma_format_idc <= 1) {
301 62 c->h_loop_filter_chroma = ff_deblock_h_chroma_10_sse2;
302 } else {
303 20 c->h_loop_filter_chroma = ff_deblock_h_chroma422_10_sse2;
304 }
305 82 c->v_loop_filter_luma = ff_deblock_v_luma_10_sse2;
306 82 c->h_loop_filter_luma = ff_deblock_h_luma_10_sse2;
307 82 c->v_loop_filter_luma_intra = ff_deblock_v_luma_intra_10_sse2;
308 82 c->h_loop_filter_luma_intra = ff_deblock_h_luma_intra_10_sse2;
309 }
310
2/2
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 88 times.
149 if (EXTERNAL_SSE4(cpu_flags)) {
311 61 c->weight_pixels_tab[0] = ff_h264_weight_16_10_sse4;
312 61 c->weight_pixels_tab[1] = ff_h264_weight_8_10_sse4;
313 61 c->weight_pixels_tab[2] = ff_h264_weight_4_10_sse4;
314
315 61 c->biweight_pixels_tab[0] = ff_h264_biweight_16_10_sse4;
316 61 c->biweight_pixels_tab[1] = ff_h264_biweight_8_10_sse4;
317 61 c->biweight_pixels_tab[2] = ff_h264_biweight_4_10_sse4;
318 }
319
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 116 times.
149 if (EXTERNAL_AVX(cpu_flags)) {
320 33 c->idct_dc_add =
321 33 c->idct_add = ff_h264_idct_add_10_avx;
322 33 c->idct8_dc_add = ff_h264_idct8_dc_add_10_avx;
323
324 33 c->idct_add16 = ff_h264_idct_add16_10_avx;
325
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 6 times.
33 if (chroma_format_idc <= 1) {
326 27 c->idct_add8 = ff_h264_idct_add8_10_avx;
327 } else {
328 6 c->idct_add8 = ff_h264_idct_add8_422_10_avx;
329 }
330 33 c->idct_add16intra = ff_h264_idct_add16intra_10_avx;
331 #if HAVE_ALIGNED_STACK
332 33 c->idct8_add = ff_h264_idct8_add_10_avx;
333 33 c->idct8_add4 = ff_h264_idct8_add4_10_avx;
334 #endif /* HAVE_ALIGNED_STACK */
335
336 33 c->v_loop_filter_chroma = ff_deblock_v_chroma_10_avx;
337 33 c->v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_10_avx;
338
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 6 times.
33 if (chroma_format_idc <= 1) {
339 27 c->h_loop_filter_chroma = ff_deblock_h_chroma_10_avx;
340 } else {
341 6 c->h_loop_filter_chroma = ff_deblock_h_chroma422_10_avx;
342 }
343 33 c->v_loop_filter_luma = ff_deblock_v_luma_10_avx;
344 33 c->h_loop_filter_luma = ff_deblock_h_luma_10_avx;
345 33 c->v_loop_filter_luma_intra = ff_deblock_v_luma_intra_10_avx;
346 33 c->h_loop_filter_luma_intra = ff_deblock_h_luma_intra_10_avx;
347 }
348 }
349 1461 }
350