FFmpeg coverage


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