FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/x86/h264dsp_init.c
Date: 2026-09-17 06:33:28
Exec Total Coverage
Lines: 113 113 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_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 1561 av_cold void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth,
181 const int chroma_format_idc)
182 {
183 1561 int cpu_flags = av_get_cpu_flags();
184
185
4/4
✓ Branch 0 taken 566 times.
✓ Branch 1 taken 995 times.
✓ Branch 2 taken 486 times.
✓ Branch 3 taken 80 times.
1561 if (EXTERNAL_MMXEXT(cpu_flags) && chroma_format_idc <= 1)
186 486 c->loop_filter_strength = ff_h264_loop_filter_strength_mmxext;
187
188
2/2
✓ Branch 0 taken 1224 times.
✓ Branch 1 taken 337 times.
1561 if (bit_depth == 8) {
189
2/2
✓ Branch 0 taken 322 times.
✓ Branch 1 taken 902 times.
1224 if (EXTERNAL_MMX(cpu_flags)) {
190
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 289 times.
322 if (chroma_format_idc <= 1) {
191 } else {
192 33 c->idct_add8 = ff_h264_idct_add8_422_8_mmx;
193 }
194 }
195
2/2
✓ Branch 0 taken 313 times.
✓ Branch 1 taken 911 times.
1224 if (EXTERNAL_MMXEXT(cpu_flags)) {
196 313 c->idct8_dc_add = ff_h264_idct8_dc_add_8_mmxext;
197 }
198
2/2
✓ Branch 0 taken 295 times.
✓ Branch 1 taken 929 times.
1224 if (EXTERNAL_SSE2(cpu_flags)) {
199 295 c->idct8_add = ff_h264_idct8_add_8_sse2;
200
201 295 c->idct_add16 = ff_h264_idct_add16_8_sse2;
202 295 c->idct8_add4 = ff_h264_idct8_add4_8_sse2;
203
2/2
✓ Branch 0 taken 268 times.
✓ Branch 1 taken 27 times.
295 if (chroma_format_idc <= 1)
204 268 c->idct_add8 = ff_h264_idct_add8_8_sse2;
205 295 c->idct_add16intra = ff_h264_idct_add16intra_8_sse2;
206 295 c->luma_dc_dequant_idct = ff_h264_luma_dc_dequant_idct_sse2;
207
208 295 c->weight_pixels_tab[0] = ff_h264_weight_16_sse2;
209 295 c->weight_pixels_tab[1] = ff_h264_weight_8_sse2;
210 295 c->weight_pixels_tab[2] = ff_h264_weight_4_sse2;
211
212 295 c->biweight_pixels_tab[0] = ff_h264_biweight_16_sse2;
213 295 c->biweight_pixels_tab[1] = ff_h264_biweight_8_sse2;
214 295 c->biweight_pixels_tab[2] = ff_h264_biweight_4_sse2;
215
216 295 c->v_loop_filter_luma = ff_deblock_v_luma_8_sse2;
217 295 c->h_loop_filter_luma = ff_deblock_h_luma_8_sse2;
218 295 c->v_loop_filter_luma_intra = ff_deblock_v_luma_intra_8_sse2;
219 295 c->h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_sse2;
220
221 #if ARCH_X86_64
222 295 c->h_loop_filter_luma_mbaff = ff_deblock_h_luma_mbaff_8_sse2;
223 #endif
224
225 295 c->v_loop_filter_chroma = ff_deblock_v_chroma_8_sse2;
226 295 c->v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_8_sse2;
227
2/2
✓ Branch 0 taken 268 times.
✓ Branch 1 taken 27 times.
295 if (chroma_format_idc <= 1) {
228 268 c->h_loop_filter_chroma = ff_deblock_h_chroma_8_sse2;
229 268 c->h_loop_filter_chroma_intra = ff_deblock_h_chroma_intra_8_sse2;
230 } else {
231 27 c->h_loop_filter_chroma = ff_deblock_h_chroma422_8_sse2;
232 27 c->h_loop_filter_chroma_intra = ff_deblock_h_chroma422_intra_8_sse2;
233 }
234
235 295 c->idct_add = ff_h264_idct_add_8_sse2;
236 295 c->idct_dc_add = ff_h264_idct_dc_add_8_sse2;
237 }
238
2/2
✓ Branch 0 taken 277 times.
✓ Branch 1 taken 947 times.
1224 if (EXTERNAL_SSSE3(cpu_flags)) {
239 277 c->biweight_pixels_tab[0] = ff_h264_biweight_16_ssse3;
240 277 c->biweight_pixels_tab[1] = ff_h264_biweight_8_ssse3;
241 277 c->biweight_pixels_tab[2] = ff_h264_biweight_4_ssse3;
242 }
243
2/2
✓ Branch 0 taken 232 times.
✓ Branch 1 taken 992 times.
1224 if (EXTERNAL_AVX(cpu_flags)) {
244 232 c->v_loop_filter_luma = ff_deblock_v_luma_8_avx;
245 232 c->h_loop_filter_luma = ff_deblock_h_luma_8_avx;
246 232 c->v_loop_filter_luma_intra = ff_deblock_v_luma_intra_8_avx;
247 232 c->h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_avx;
248 #if ARCH_X86_64
249 232 c->h_loop_filter_luma_mbaff = ff_deblock_h_luma_mbaff_8_avx;
250 #endif
251
252 232 c->v_loop_filter_chroma = ff_deblock_v_chroma_8_avx;
253 232 c->v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_8_avx;
254
2/2
✓ Branch 0 taken 219 times.
✓ Branch 1 taken 13 times.
232 if (chroma_format_idc <= 1) {
255 219 c->h_loop_filter_chroma = ff_deblock_h_chroma_8_avx;
256 219 c->h_loop_filter_chroma_intra = ff_deblock_h_chroma_intra_8_avx;
257 } else {
258 13 c->h_loop_filter_chroma = ff_deblock_h_chroma422_8_avx;
259 13 c->h_loop_filter_chroma_intra = ff_deblock_h_chroma422_intra_8_avx;
260 }
261
262 232 c->idct_add = ff_h264_idct_add_8_avx;
263 232 c->idct_dc_add = ff_h264_idct_dc_add_8_avx;
264 }
265
2/2
✓ Branch 0 taken 178 times.
✓ Branch 1 taken 159 times.
337 } else if (bit_depth == 10) {
266
2/2
✓ Branch 0 taken 121 times.
✓ Branch 1 taken 57 times.
178 if (EXTERNAL_MMXEXT(cpu_flags)) {
267 121 c->idct_dc_add = ff_h264_idct_dc_add_10_mmxext;
268 }
269
2/2
✓ Branch 0 taken 103 times.
✓ Branch 1 taken 75 times.
178 if (EXTERNAL_SSE2(cpu_flags)) {
270 103 c->idct_add = ff_h264_idct_add_10_sse2;
271 103 c->idct8_dc_add = ff_h264_idct8_dc_add_10_sse2;
272
273 103 c->idct_add16 = ff_h264_idct_add16_10_sse2;
274
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 21 times.
103 if (chroma_format_idc <= 1) {
275 82 c->idct_add8 = ff_h264_idct_add8_10_sse2;
276 } else {
277 21 c->idct_add8 = ff_h264_idct_add8_422_10_sse2;
278 }
279 103 c->idct_add16intra = ff_h264_idct_add16intra_10_sse2;
280 #if HAVE_ALIGNED_STACK
281 103 c->idct8_add = ff_h264_idct8_add_10_sse2;
282 103 c->idct8_add4 = ff_h264_idct8_add4_10_sse2;
283 #endif /* HAVE_ALIGNED_STACK */
284
285 103 c->weight_pixels_tab[0] = ff_h264_weight_16_10_sse2;
286 103 c->weight_pixels_tab[1] = ff_h264_weight_8_10_sse2;
287 103 c->weight_pixels_tab[2] = ff_h264_weight_4_10_sse2;
288
289 103 c->biweight_pixels_tab[0] = ff_h264_biweight_16_10_sse2;
290 103 c->biweight_pixels_tab[1] = ff_h264_biweight_8_10_sse2;
291 103 c->biweight_pixels_tab[2] = ff_h264_biweight_4_10_sse2;
292
293 103 c->v_loop_filter_chroma = ff_deblock_v_chroma_10_sse2;
294 103 c->v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_10_sse2;
295
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 21 times.
103 if (chroma_format_idc <= 1) {
296 82 c->h_loop_filter_chroma = ff_deblock_h_chroma_10_sse2;
297 } else {
298 21 c->h_loop_filter_chroma = ff_deblock_h_chroma422_10_sse2;
299 }
300 103 c->v_loop_filter_luma = ff_deblock_v_luma_10_sse2;
301 103 c->h_loop_filter_luma = ff_deblock_h_luma_10_sse2;
302 103 c->v_loop_filter_luma_intra = ff_deblock_v_luma_intra_10_sse2;
303 103 c->h_loop_filter_luma_intra = ff_deblock_h_luma_intra_10_sse2;
304 }
305
2/2
✓ Branch 0 taken 76 times.
✓ Branch 1 taken 102 times.
178 if (EXTERNAL_SSE4(cpu_flags)) {
306 76 c->weight_pixels_tab[0] = ff_h264_weight_16_10_sse4;
307 76 c->weight_pixels_tab[1] = ff_h264_weight_8_10_sse4;
308 76 c->weight_pixels_tab[2] = ff_h264_weight_4_10_sse4;
309
310 76 c->biweight_pixels_tab[0] = ff_h264_biweight_16_10_sse4;
311 76 c->biweight_pixels_tab[1] = ff_h264_biweight_8_10_sse4;
312 76 c->biweight_pixels_tab[2] = ff_h264_biweight_4_10_sse4;
313 }
314
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 138 times.
178 if (EXTERNAL_AVX(cpu_flags)) {
315 40 c->idct_dc_add =
316 40 c->idct_add = ff_h264_idct_add_10_avx;
317 40 c->idct8_dc_add = ff_h264_idct8_dc_add_10_avx;
318
319 40 c->idct_add16 = ff_h264_idct_add16_10_avx;
320
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 7 times.
40 if (chroma_format_idc <= 1) {
321 33 c->idct_add8 = ff_h264_idct_add8_10_avx;
322 } else {
323 7 c->idct_add8 = ff_h264_idct_add8_422_10_avx;
324 }
325 40 c->idct_add16intra = ff_h264_idct_add16intra_10_avx;
326 #if HAVE_ALIGNED_STACK
327 40 c->idct8_add = ff_h264_idct8_add_10_avx;
328 40 c->idct8_add4 = ff_h264_idct8_add4_10_avx;
329 #endif /* HAVE_ALIGNED_STACK */
330
331 40 c->v_loop_filter_chroma = ff_deblock_v_chroma_10_avx;
332 40 c->v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_10_avx;
333
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 7 times.
40 if (chroma_format_idc <= 1) {
334 33 c->h_loop_filter_chroma = ff_deblock_h_chroma_10_avx;
335 } else {
336 7 c->h_loop_filter_chroma = ff_deblock_h_chroma422_10_avx;
337 }
338 40 c->v_loop_filter_luma = ff_deblock_v_luma_10_avx;
339 40 c->h_loop_filter_luma = ff_deblock_h_luma_10_avx;
340 40 c->v_loop_filter_luma_intra = ff_deblock_v_luma_intra_10_avx;
341 40 c->h_loop_filter_luma_intra = ff_deblock_h_luma_intra_10_avx;
342 }
343 }
344 1561 }
345