FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/x86/h264dsp_init.c
Date: 2026-10-30 17:37:53
Exec Total Coverage
Lines: 109 109 100.0%
Functions: 1 1 100.0%
Branches: 34 34 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, sse2)
39 IDCT_ADD_FUNC(8_dc, 8, sse2)
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, sse2)
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_SSE(W) \
144 H264_WEIGHT(W, sse2) \
145 H264_BIWEIGHT(W, sse2) \
146 H264_BIWEIGHT(W, ssse3)
147
148 H264_BIWEIGHT_SSE(16)
149 H264_BIWEIGHT_SSE(8)
150 H264_BIWEIGHT_SSE(4)
151
152 #define H264_WEIGHT_10(W, DEPTH, OPT) \
153 void 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) \
161 void 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
176 H264_BIWEIGHT_10_SSE(16, 10)
177 H264_BIWEIGHT_10_SSE(8, 10)
178 H264_BIWEIGHT_10_SSE(4, 10)
179
180 1698 av_cold void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth,
181 const int chroma_format_idc)
182 {
183 1698 int cpu_flags = av_get_cpu_flags();
184
185
4/4
✓ Branch 0 taken 665 times.
✓ Branch 1 taken 1033 times.
✓ Branch 2 taken 561 times.
✓ Branch 3 taken 104 times.
1698 if (EXTERNAL_MMXEXT(cpu_flags) && chroma_format_idc <= 1)
186 561 c->loop_filter_strength = ff_h264_loop_filter_strength_mmxext;
187
188
2/2
✓ Branch 0 taken 1331 times.
✓ Branch 1 taken 367 times.
1698 if (bit_depth == 8) {
189
2/2
✓ Branch 0 taken 366 times.
✓ Branch 1 taken 965 times.
1331 if (EXTERNAL_SSE2(cpu_flags)) {
190 366 c->idct8_add = ff_h264_idct8_add_8_sse2;
191 366 c->idct8_dc_add = ff_h264_idct8_dc_add_8_sse2;
192 366 c->idct_add16 = ff_h264_idct_add16_8_sse2;
193 366 c->idct8_add4 = ff_h264_idct8_add4_8_sse2;
194
2/2
✓ Branch 0 taken 329 times.
✓ Branch 1 taken 37 times.
366 if (chroma_format_idc <= 1)
195 329 c->idct_add8 = ff_h264_idct_add8_8_sse2;
196 else
197 37 c->idct_add8 = ff_h264_idct_add8_422_8_sse2;
198 366 c->idct_add16intra = ff_h264_idct_add16intra_8_sse2;
199 366 c->luma_dc_dequant_idct = ff_h264_luma_dc_dequant_idct_sse2;
200
201 366 c->weight_pixels_tab[0] = ff_h264_weight_16_sse2;
202 366 c->weight_pixels_tab[1] = ff_h264_weight_8_sse2;
203 366 c->weight_pixels_tab[2] = ff_h264_weight_4_sse2;
204
205 366 c->biweight_pixels_tab[0] = ff_h264_biweight_16_sse2;
206 366 c->biweight_pixels_tab[1] = ff_h264_biweight_8_sse2;
207 366 c->biweight_pixels_tab[2] = ff_h264_biweight_4_sse2;
208
209 366 c->v_loop_filter_luma = ff_deblock_v_luma_8_sse2;
210 366 c->h_loop_filter_luma = ff_deblock_h_luma_8_sse2;
211 366 c->v_loop_filter_luma_intra = ff_deblock_v_luma_intra_8_sse2;
212 366 c->h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_sse2;
213
214 #if ARCH_X86_64
215 366 c->h_loop_filter_luma_mbaff = ff_deblock_h_luma_mbaff_8_sse2;
216 #endif
217
218 366 c->v_loop_filter_chroma = ff_deblock_v_chroma_8_sse2;
219 366 c->v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_8_sse2;
220
2/2
✓ Branch 0 taken 329 times.
✓ Branch 1 taken 37 times.
366 if (chroma_format_idc <= 1) {
221 329 c->h_loop_filter_chroma = ff_deblock_h_chroma_8_sse2;
222 329 c->h_loop_filter_chroma_intra = ff_deblock_h_chroma_intra_8_sse2;
223 } else {
224 37 c->h_loop_filter_chroma = ff_deblock_h_chroma422_8_sse2;
225 37 c->h_loop_filter_chroma_intra = ff_deblock_h_chroma422_intra_8_sse2;
226 }
227
228 366 c->idct_add = ff_h264_idct_add_8_sse2;
229 366 c->idct_dc_add = ff_h264_idct_dc_add_8_sse2;
230 }
231
2/2
✓ Branch 0 taken 344 times.
✓ Branch 1 taken 987 times.
1331 if (EXTERNAL_SSSE3(cpu_flags)) {
232 344 c->biweight_pixels_tab[0] = ff_h264_biweight_16_ssse3;
233 344 c->biweight_pixels_tab[1] = ff_h264_biweight_8_ssse3;
234 344 c->biweight_pixels_tab[2] = ff_h264_biweight_4_ssse3;
235 }
236
2/2
✓ Branch 0 taken 289 times.
✓ Branch 1 taken 1042 times.
1331 if (EXTERNAL_AVX(cpu_flags)) {
237 289 c->v_loop_filter_luma = ff_deblock_v_luma_8_avx;
238 289 c->h_loop_filter_luma = ff_deblock_h_luma_8_avx;
239 289 c->v_loop_filter_luma_intra = ff_deblock_v_luma_intra_8_avx;
240 289 c->h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_avx;
241 #if ARCH_X86_64
242 289 c->h_loop_filter_luma_mbaff = ff_deblock_h_luma_mbaff_8_avx;
243 #endif
244
245 289 c->v_loop_filter_chroma = ff_deblock_v_chroma_8_avx;
246 289 c->v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_8_avx;
247
2/2
✓ Branch 0 taken 273 times.
✓ Branch 1 taken 16 times.
289 if (chroma_format_idc <= 1) {
248 273 c->h_loop_filter_chroma = ff_deblock_h_chroma_8_avx;
249 273 c->h_loop_filter_chroma_intra = ff_deblock_h_chroma_intra_8_avx;
250 } else {
251 16 c->h_loop_filter_chroma = ff_deblock_h_chroma422_8_avx;
252 16 c->h_loop_filter_chroma_intra = ff_deblock_h_chroma422_intra_8_avx;
253 }
254
255 289 c->idct_add = ff_h264_idct_add_8_avx;
256 289 c->idct_dc_add = ff_h264_idct_dc_add_8_avx;
257 }
258
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 159 times.
367 } else if (bit_depth == 10) {
259
2/2
✓ Branch 0 taken 123 times.
✓ Branch 1 taken 85 times.
208 if (EXTERNAL_SSE2(cpu_flags)) {
260 123 c->idct_dc_add = ff_h264_idct_dc_add_10_sse2;
261 123 c->idct_add = ff_h264_idct_add_10_sse2;
262 123 c->idct8_dc_add = ff_h264_idct8_dc_add_10_sse2;
263
264 123 c->idct_add16 = ff_h264_idct_add16_10_sse2;
265
2/2
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 31 times.
123 if (chroma_format_idc <= 1) {
266 92 c->idct_add8 = ff_h264_idct_add8_10_sse2;
267 } else {
268 31 c->idct_add8 = ff_h264_idct_add8_422_10_sse2;
269 }
270 123 c->idct_add16intra = ff_h264_idct_add16intra_10_sse2;
271 #if HAVE_ALIGNED_STACK
272 123 c->idct8_add = ff_h264_idct8_add_10_sse2;
273 123 c->idct8_add4 = ff_h264_idct8_add4_10_sse2;
274 #endif /* HAVE_ALIGNED_STACK */
275
276 123 c->weight_pixels_tab[0] = ff_h264_weight_16_10_sse2;
277 123 c->weight_pixels_tab[1] = ff_h264_weight_8_10_sse2;
278 123 c->weight_pixels_tab[2] = ff_h264_weight_4_10_sse2;
279
280 123 c->biweight_pixels_tab[0] = ff_h264_biweight_16_10_sse2;
281 123 c->biweight_pixels_tab[1] = ff_h264_biweight_8_10_sse2;
282 123 c->biweight_pixels_tab[2] = ff_h264_biweight_4_10_sse2;
283
284 123 c->v_loop_filter_chroma = ff_deblock_v_chroma_10_sse2;
285 123 c->v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_10_sse2;
286
2/2
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 31 times.
123 if (chroma_format_idc <= 1) {
287 92 c->h_loop_filter_chroma = ff_deblock_h_chroma_10_sse2;
288 } else {
289 31 c->h_loop_filter_chroma = ff_deblock_h_chroma422_10_sse2;
290 }
291 123 c->v_loop_filter_luma = ff_deblock_v_luma_10_sse2;
292 123 c->h_loop_filter_luma = ff_deblock_h_luma_10_sse2;
293 123 c->v_loop_filter_luma_intra = ff_deblock_v_luma_intra_10_sse2;
294 123 c->h_loop_filter_luma_intra = ff_deblock_h_luma_intra_10_sse2;
295 }
296
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 118 times.
208 if (EXTERNAL_SSE4(cpu_flags)) {
297 90 c->weight_pixels_tab[0] = ff_h264_weight_16_10_sse4;
298 90 c->weight_pixels_tab[1] = ff_h264_weight_8_10_sse4;
299 90 c->weight_pixels_tab[2] = ff_h264_weight_4_10_sse4;
300
301 90 c->biweight_pixels_tab[0] = ff_h264_biweight_16_10_sse4;
302 90 c->biweight_pixels_tab[1] = ff_h264_biweight_8_10_sse4;
303 90 c->biweight_pixels_tab[2] = ff_h264_biweight_4_10_sse4;
304 }
305
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 162 times.
208 if (EXTERNAL_AVX(cpu_flags)) {
306 46 c->idct_dc_add =
307 46 c->idct_add = ff_h264_idct_add_10_avx;
308 46 c->idct8_dc_add = ff_h264_idct8_dc_add_10_avx;
309
310 46 c->idct_add16 = ff_h264_idct_add16_10_avx;
311
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 10 times.
46 if (chroma_format_idc <= 1) {
312 36 c->idct_add8 = ff_h264_idct_add8_10_avx;
313 } else {
314 10 c->idct_add8 = ff_h264_idct_add8_422_10_avx;
315 }
316 46 c->idct_add16intra = ff_h264_idct_add16intra_10_avx;
317 #if HAVE_ALIGNED_STACK
318 46 c->idct8_add = ff_h264_idct8_add_10_avx;
319 46 c->idct8_add4 = ff_h264_idct8_add4_10_avx;
320 #endif /* HAVE_ALIGNED_STACK */
321
322 46 c->v_loop_filter_chroma = ff_deblock_v_chroma_10_avx;
323 46 c->v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_10_avx;
324
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 10 times.
46 if (chroma_format_idc <= 1) {
325 36 c->h_loop_filter_chroma = ff_deblock_h_chroma_10_avx;
326 } else {
327 10 c->h_loop_filter_chroma = ff_deblock_h_chroma422_10_avx;
328 }
329 46 c->v_loop_filter_luma = ff_deblock_v_luma_10_avx;
330 46 c->h_loop_filter_luma = ff_deblock_h_luma_10_avx;
331 46 c->v_loop_filter_luma_intra = ff_deblock_v_luma_intra_10_avx;
332 46 c->h_loop_filter_luma_intra = ff_deblock_h_luma_intra_10_avx;
333 }
334 }
335 1698 }
336