FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/x86/h264_intrapred_init.c
Date: 2026-08-11 17:55:23
Exec Total Coverage
Lines: 123 123 100.0%
Functions: 1 1 100.0%
Branches: 61 64 95.3%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2010 Fiona Glaser <fiona@x264.com>
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 <stddef.h>
22 #include <stdint.h>
23 #include "config.h"
24 #include "libavutil/attributes.h"
25 #include "libavutil/cpu.h"
26 #include "libavutil/x86/cpu.h"
27 #include "libavcodec/codec_id.h"
28 #include "libavcodec/h264pred.h"
29
30 #define PRED4x4(TYPE, DEPTH, OPT) \
31 void ff_pred4x4_ ## TYPE ## _ ## DEPTH ## _ ## OPT (uint8_t *src, \
32 const uint8_t *topright, \
33 ptrdiff_t stride);
34
35 PRED4x4(dc, 10, sse2)
36 PRED4x4(down_left, 10, sse2)
37 PRED4x4(down_left, 10, avx)
38 PRED4x4(down_right, 10, sse2)
39 PRED4x4(down_right, 10, ssse3)
40 PRED4x4(down_right, 10, avx)
41 PRED4x4(vertical_left, 10, sse2)
42 PRED4x4(vertical_left, 10, avx)
43 PRED4x4(vertical_right, 10, sse2)
44 PRED4x4(vertical_right, 10, ssse3)
45 PRED4x4(vertical_right, 10, avx)
46 PRED4x4(horizontal_up, 10, sse2)
47 PRED4x4(horizontal_down, 10, sse2)
48 PRED4x4(horizontal_down, 10, ssse3)
49 PRED4x4(horizontal_down, 10, avx)
50
51 #define PRED8x8(TYPE, DEPTH, OPT) \
52 void ff_pred8x8_ ## TYPE ## _ ## DEPTH ## _ ## OPT (uint8_t *src, \
53 ptrdiff_t stride);
54
55 PRED8x8(dc, 10, sse2)
56 PRED8x8(top_dc, 10, sse2)
57 PRED8x8(plane, 10, sse2)
58 PRED8x8(vertical, 10, sse2)
59 PRED8x8(horizontal, 10, sse2)
60
61 #define PRED8x8L(TYPE, DEPTH, OPT)\
62 void ff_pred8x8l_ ## TYPE ## _ ## DEPTH ## _ ## OPT (uint8_t *src, \
63 int has_topleft, \
64 int has_topright, \
65 ptrdiff_t stride);
66
67 PRED8x8L(dc, 10, sse2)
68 PRED8x8L(dc, 10, avx)
69 PRED8x8L(128_dc, 10, sse2)
70 PRED8x8L(top_dc, 10, sse2)
71 PRED8x8L(top_dc, 10, avx)
72 PRED8x8L(vertical, 10, sse2)
73 PRED8x8L(vertical, 10, avx)
74 PRED8x8L(horizontal, 10, sse2)
75 PRED8x8L(horizontal, 10, ssse3)
76 PRED8x8L(horizontal, 10, avx)
77 PRED8x8L(down_left, 10, sse2)
78 PRED8x8L(down_left, 10, ssse3)
79 PRED8x8L(down_left, 10, avx)
80 PRED8x8L(down_right, 10, sse2)
81 PRED8x8L(down_right, 10, ssse3)
82 PRED8x8L(down_right, 10, avx)
83 PRED8x8L(vertical_right, 10, sse2)
84 PRED8x8L(vertical_right, 10, ssse3)
85 PRED8x8L(vertical_right, 10, avx)
86 PRED8x8L(horizontal_up, 10, sse2)
87 PRED8x8L(horizontal_up, 10, ssse3)
88 PRED8x8L(horizontal_up, 10, avx)
89
90 #define PRED16x16(TYPE, DEPTH, OPT)\
91 void ff_pred16x16_ ## TYPE ## _ ## DEPTH ## _ ## OPT (uint8_t *src, \
92 ptrdiff_t stride);
93
94 PRED16x16(dc, 10, sse2)
95 PRED16x16(top_dc, 10, sse2)
96 PRED16x16(128_dc, 10, sse2)
97 PRED16x16(left_dc, 10, sse2)
98 PRED16x16(vertical, 10, sse2)
99 PRED16x16(horizontal, 10, sse2)
100
101 /* 8-bit versions */
102 PRED16x16(vertical, 8, sse)
103 PRED16x16(horizontal, 8, sse2)
104 PRED16x16(horizontal, 8, ssse3)
105 PRED16x16(horizontal, 8, avx2)
106 PRED16x16(dc, 8, sse2)
107 PRED16x16(dc, 8, ssse3)
108 PRED16x16(plane_h264, 8, sse2)
109 PRED16x16(plane_h264, 8, ssse3)
110 PRED16x16(plane_rv40, 8, sse2)
111 PRED16x16(plane_rv40, 8, ssse3)
112 PRED16x16(plane_svq3, 8, sse2)
113 PRED16x16(plane_svq3, 8, ssse3)
114 PRED16x16(tm_vp8, 8, sse2)
115 PRED16x16(tm_vp8, 8, avx2)
116
117 PRED8x8(top_dc, 8, sse2)
118 PRED8x8(dc_rv40, 8, sse2)
119 PRED8x8(dc, 8, sse2)
120 PRED8x8(vertical, 8, sse2)
121 PRED8x8(horizontal, 8, sse2)
122 PRED8x8(horizontal, 8, ssse3)
123 PRED8x8(horizontal, 8, avx2)
124 PRED8x8(plane, 8, sse2)
125 PRED8x8(plane, 8, ssse3)
126 PRED8x8(tm_vp8, 8, sse2)
127 PRED8x8(tm_vp8, 8, ssse3)
128
129 PRED8x8L(top_dc, 8, sse2)
130 PRED8x8L(dc, 8, sse2)
131 PRED8x8L(horizontal, 8, sse2)
132 PRED8x8L(vertical, 8, sse2)
133 PRED8x8L(down_left, 8, sse2)
134 PRED8x8L(down_right, 8, sse2)
135 PRED8x8L(vertical_right, 8, sse2)
136 PRED8x8L(vertical_left, 8, sse2)
137 PRED8x8L(horizontal_up, 8, sse2)
138 PRED8x8L(horizontal_down, 8, sse2)
139 PRED8x8L(horizontal_down, 8, ssse3)
140
141 PRED4x4(dc, 8, sse2)
142 PRED4x4(down_left, 8, sse2)
143 PRED4x4(down_right, 8, sse2)
144 PRED4x4(vertical_left, 8, sse2)
145 PRED4x4(vertical_right, 8, sse2)
146 PRED4x4(horizontal_up, 8, sse2)
147 PRED4x4(horizontal_down, 8, sse2)
148 PRED4x4(tm_vp8, 8, sse2)
149 PRED4x4(tm_vp8, 8, ssse3)
150 PRED4x4(vertical_vp8, 8, sse2)
151
152 1218 av_cold void ff_h264_pred_init_x86(H264PredContext *h, int codec_id,
153 const int bit_depth,
154 const int chroma_format_idc)
155 {
156 1218 int cpu_flags = av_get_cpu_flags();
157
158
2/2
✓ Branch 0 taken 938 times.
✓ Branch 1 taken 280 times.
1218 if (bit_depth == 8) {
159
2/2
✓ Branch 0 taken 282 times.
✓ Branch 1 taken 656 times.
938 if (EXTERNAL_SSE(cpu_flags)) {
160 282 h->pred16x16[VERT_PRED8x8] = ff_pred16x16_vertical_8_sse;
161 }
162
163
2/2
✓ Branch 0 taken 262 times.
✓ Branch 1 taken 676 times.
938 if (EXTERNAL_SSE2(cpu_flags)) {
164 262 h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_8_sse2;
165 262 h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_8_sse2;
166 262 h->pred8x8l [HOR_PRED ] = ff_pred8x8l_horizontal_8_sse2;
167 262 h->pred8x8l [DC_PRED ] = ff_pred8x8l_dc_8_sse2;
168 262 h->pred8x8l [TOP_DC_PRED ] = ff_pred8x8l_top_dc_8_sse2;
169 262 h->pred8x8l [VERT_PRED ] = ff_pred8x8l_vertical_8_sse2;
170 262 h->pred8x8l [DIAG_DOWN_LEFT_PRED ] = ff_pred8x8l_down_left_8_sse2;
171 262 h->pred8x8l [DIAG_DOWN_RIGHT_PRED ] = ff_pred8x8l_down_right_8_sse2;
172 262 h->pred8x8l [VERT_RIGHT_PRED ] = ff_pred8x8l_vertical_right_8_sse2;
173 262 h->pred8x8l [VERT_LEFT_PRED ] = ff_pred8x8l_vertical_left_8_sse2;
174 262 h->pred8x8l [HOR_UP_PRED ] = ff_pred8x8l_horizontal_up_8_sse2;
175 262 h->pred8x8l [HOR_DOWN_PRED ] = ff_pred8x8l_horizontal_down_8_sse2;
176 262 h->pred4x4 [DIAG_DOWN_RIGHT_PRED ] = ff_pred4x4_down_right_8_sse2;
177 262 h->pred4x4 [VERT_RIGHT_PRED ] = ff_pred4x4_vertical_right_8_sse2;
178 262 h->pred4x4 [HOR_DOWN_PRED ] = ff_pred4x4_horizontal_down_8_sse2;
179 262 h->pred4x4 [DC_PRED ] = ff_pred4x4_dc_8_sse2;
180
2/2
✓ Branch 0 taken 215 times.
✓ Branch 1 taken 47 times.
262 if (chroma_format_idc <= 1) {
181 215 h->pred8x8 [HOR_PRED8x8 ] = ff_pred8x8_horizontal_8_sse2;
182 215 h->pred8x8 [VERT_PRED8x8 ] = ff_pred8x8_vertical_8_sse2;
183
4/4
✓ Branch 0 taken 171 times.
✓ Branch 1 taken 44 times.
✓ Branch 2 taken 81 times.
✓ Branch 3 taken 90 times.
215 if (codec_id == AV_CODEC_ID_SVQ3 || codec_id == AV_CODEC_ID_H264) {
184 125 h->pred8x8 [TOP_DC_PRED8x8] = ff_pred8x8_top_dc_8_sse2;
185 125 h->pred8x8 [DC_PRED8x8 ] = ff_pred8x8_dc_8_sse2;
186 }
187 }
188
4/4
✓ Branch 0 taken 218 times.
✓ Branch 1 taken 44 times.
✓ Branch 2 taken 128 times.
✓ Branch 3 taken 90 times.
262 if (codec_id == AV_CODEC_ID_SVQ3 || codec_id == AV_CODEC_ID_H264) {
189 172 h->pred4x4 [VERT_LEFT_PRED ] = ff_pred4x4_vertical_left_8_sse2;
190 }
191
2/2
✓ Branch 0 taken 222 times.
✓ Branch 1 taken 40 times.
262 if (codec_id != AV_CODEC_ID_RV40) {
192 222 h->pred4x4 [HOR_UP_PRED ] = ff_pred4x4_horizontal_up_8_sse2;
193 }
194
5/6
✓ Branch 0 taken 262 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 212 times.
✓ Branch 3 taken 50 times.
✓ Branch 4 taken 128 times.
✓ Branch 5 taken 84 times.
262 if (codec_id == AV_CODEC_ID_VP7 || codec_id == AV_CODEC_ID_VP8 ||
195 codec_id == AV_CODEC_ID_H264) {
196 178 h->pred4x4[DIAG_DOWN_LEFT_PRED] = ff_pred4x4_down_left_8_sse2;
197 }
198
3/4
✓ Branch 0 taken 262 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 50 times.
✓ Branch 3 taken 212 times.
262 if (codec_id == AV_CODEC_ID_VP7 || codec_id == AV_CODEC_ID_VP8) {
199 50 h->pred16x16[PLANE_PRED8x8 ] = ff_pred16x16_tm_vp8_8_sse2;
200 50 h->pred8x8 [PLANE_PRED8x8 ] = ff_pred8x8_tm_vp8_8_sse2;
201 50 h->pred8x8 [DC_PRED8x8 ] = ff_pred8x8_dc_rv40_8_sse2;
202 50 h->pred4x4 [TM_VP8_PRED ] = ff_pred4x4_tm_vp8_8_sse2;
203 50 h->pred4x4 [VERT_PRED ] = ff_pred4x4_vertical_vp8_8_sse2;
204 } else {
205
2/2
✓ Branch 0 taken 165 times.
✓ Branch 1 taken 47 times.
212 if (chroma_format_idc <= 1)
206 165 h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_plane_8_sse2;
207
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 168 times.
212 if (codec_id == AV_CODEC_ID_SVQ3) {
208 44 h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_svq3_8_sse2;
209
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 128 times.
168 } else if (codec_id == AV_CODEC_ID_RV40) {
210 40 h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_rv40_8_sse2;
211 } else {
212 128 h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_h264_8_sse2;
213 }
214 }
215 }
216
217
2/2
✓ Branch 0 taken 222 times.
✓ Branch 1 taken 716 times.
938 if (EXTERNAL_SSSE3(cpu_flags)) {
218 222 h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_8_ssse3;
219 222 h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_8_ssse3;
220
2/2
✓ Branch 0 taken 183 times.
✓ Branch 1 taken 39 times.
222 if (chroma_format_idc <= 1)
221 183 h->pred8x8 [HOR_PRED8x8 ] = ff_pred8x8_horizontal_8_ssse3;
222 222 h->pred8x8l [HOR_DOWN_PRED ] = ff_pred8x8l_horizontal_down_8_ssse3;
223
3/4
✓ Branch 0 taken 222 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
✓ Branch 3 taken 180 times.
222 if (codec_id == AV_CODEC_ID_VP7 || codec_id == AV_CODEC_ID_VP8) {
224 42 h->pred8x8 [PLANE_PRED8x8 ] = ff_pred8x8_tm_vp8_8_ssse3;
225 42 h->pred4x4 [TM_VP8_PRED ] = ff_pred4x4_tm_vp8_8_ssse3;
226 } else {
227
2/2
✓ Branch 0 taken 141 times.
✓ Branch 1 taken 39 times.
180 if (chroma_format_idc <= 1)
228 141 h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_plane_8_ssse3;
229
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 144 times.
180 if (codec_id == AV_CODEC_ID_SVQ3) {
230 36 h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_svq3_8_ssse3;
231
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 112 times.
144 } else if (codec_id == AV_CODEC_ID_RV40) {
232 32 h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_rv40_8_ssse3;
233 } else {
234 112 h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_h264_8_ssse3;
235 }
236 }
237 }
238
239
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 856 times.
938 if(EXTERNAL_AVX2(cpu_flags)){
240 82 h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_8_avx2;
241
2/2
✓ Branch 0 taken 71 times.
✓ Branch 1 taken 11 times.
82 if (chroma_format_idc <= 1)
242 71 h->pred8x8 [HOR_PRED8x8 ] = ff_pred8x8_horizontal_8_avx2;
243
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 68 times.
82 if (codec_id == AV_CODEC_ID_VP8) {
244 14 h->pred16x16[PLANE_PRED8x8 ] = ff_pred16x16_tm_vp8_8_avx2;
245 }
246 }
247
2/2
✓ Branch 0 taken 163 times.
✓ Branch 1 taken 117 times.
280 } else if (bit_depth == 10) {
248
2/2
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 71 times.
163 if (EXTERNAL_SSE2(cpu_flags)) {
249 92 h->pred4x4[DC_PRED ] = ff_pred4x4_dc_10_sse2;
250 92 h->pred4x4[DIAG_DOWN_LEFT_PRED ] = ff_pred4x4_down_left_10_sse2;
251 92 h->pred4x4[DIAG_DOWN_RIGHT_PRED] = ff_pred4x4_down_right_10_sse2;
252 92 h->pred4x4[VERT_LEFT_PRED ] = ff_pred4x4_vertical_left_10_sse2;
253 92 h->pred4x4[VERT_RIGHT_PRED ] = ff_pred4x4_vertical_right_10_sse2;
254 92 h->pred4x4[HOR_UP_PRED ] = ff_pred4x4_horizontal_up_10_sse2;
255 92 h->pred4x4[HOR_DOWN_PRED ] = ff_pred4x4_horizontal_down_10_sse2;
256
257
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 40 times.
92 if (chroma_format_idc <= 1) {
258 52 h->pred8x8[DC_PRED8x8 ] = ff_pred8x8_dc_10_sse2;
259 52 h->pred8x8[TOP_DC_PRED8x8 ] = ff_pred8x8_top_dc_10_sse2;
260 52 h->pred8x8[PLANE_PRED8x8 ] = ff_pred8x8_plane_10_sse2;
261 52 h->pred8x8[VERT_PRED8x8 ] = ff_pred8x8_vertical_10_sse2;
262 52 h->pred8x8[HOR_PRED8x8 ] = ff_pred8x8_horizontal_10_sse2;
263 }
264
265 92 h->pred8x8l[VERT_PRED ] = ff_pred8x8l_vertical_10_sse2;
266 92 h->pred8x8l[HOR_PRED ] = ff_pred8x8l_horizontal_10_sse2;
267 92 h->pred8x8l[DC_PRED ] = ff_pred8x8l_dc_10_sse2;
268 92 h->pred8x8l[DC_128_PRED ] = ff_pred8x8l_128_dc_10_sse2;
269 92 h->pred8x8l[TOP_DC_PRED ] = ff_pred8x8l_top_dc_10_sse2;
270 92 h->pred8x8l[DIAG_DOWN_LEFT_PRED ] = ff_pred8x8l_down_left_10_sse2;
271 92 h->pred8x8l[DIAG_DOWN_RIGHT_PRED] = ff_pred8x8l_down_right_10_sse2;
272 92 h->pred8x8l[VERT_RIGHT_PRED ] = ff_pred8x8l_vertical_right_10_sse2;
273 92 h->pred8x8l[HOR_UP_PRED ] = ff_pred8x8l_horizontal_up_10_sse2;
274
275 92 h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_10_sse2;
276 92 h->pred16x16[TOP_DC_PRED8x8 ] = ff_pred16x16_top_dc_10_sse2;
277 92 h->pred16x16[DC_128_PRED8x8 ] = ff_pred16x16_128_dc_10_sse2;
278 92 h->pred16x16[LEFT_DC_PRED8x8 ] = ff_pred16x16_left_dc_10_sse2;
279 92 h->pred16x16[VERT_PRED8x8 ] = ff_pred16x16_vertical_10_sse2;
280 92 h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_10_sse2;
281 }
282
2/2
✓ Branch 0 taken 76 times.
✓ Branch 1 taken 87 times.
163 if (EXTERNAL_SSSE3(cpu_flags)) {
283 76 h->pred4x4[DIAG_DOWN_RIGHT_PRED] = ff_pred4x4_down_right_10_ssse3;
284 76 h->pred4x4[VERT_RIGHT_PRED ] = ff_pred4x4_vertical_right_10_ssse3;
285 76 h->pred4x4[HOR_DOWN_PRED ] = ff_pred4x4_horizontal_down_10_ssse3;
286
287 76 h->pred8x8l[HOR_PRED ] = ff_pred8x8l_horizontal_10_ssse3;
288 76 h->pred8x8l[DIAG_DOWN_LEFT_PRED ] = ff_pred8x8l_down_left_10_ssse3;
289 76 h->pred8x8l[DIAG_DOWN_RIGHT_PRED] = ff_pred8x8l_down_right_10_ssse3;
290 76 h->pred8x8l[VERT_RIGHT_PRED ] = ff_pred8x8l_vertical_right_10_ssse3;
291 76 h->pred8x8l[HOR_UP_PRED ] = ff_pred8x8l_horizontal_up_10_ssse3;
292 }
293
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 127 times.
163 if (EXTERNAL_AVX(cpu_flags)) {
294 36 h->pred4x4[DIAG_DOWN_LEFT_PRED ] = ff_pred4x4_down_left_10_avx;
295 36 h->pred4x4[DIAG_DOWN_RIGHT_PRED] = ff_pred4x4_down_right_10_avx;
296 36 h->pred4x4[VERT_LEFT_PRED ] = ff_pred4x4_vertical_left_10_avx;
297 36 h->pred4x4[VERT_RIGHT_PRED ] = ff_pred4x4_vertical_right_10_avx;
298 36 h->pred4x4[HOR_DOWN_PRED ] = ff_pred4x4_horizontal_down_10_avx;
299
300 36 h->pred8x8l[VERT_PRED ] = ff_pred8x8l_vertical_10_avx;
301 36 h->pred8x8l[HOR_PRED ] = ff_pred8x8l_horizontal_10_avx;
302 36 h->pred8x8l[DC_PRED ] = ff_pred8x8l_dc_10_avx;
303 36 h->pred8x8l[TOP_DC_PRED ] = ff_pred8x8l_top_dc_10_avx;
304 36 h->pred8x8l[DIAG_DOWN_RIGHT_PRED] = ff_pred8x8l_down_right_10_avx;
305 36 h->pred8x8l[DIAG_DOWN_LEFT_PRED ] = ff_pred8x8l_down_left_10_avx;
306 36 h->pred8x8l[VERT_RIGHT_PRED ] = ff_pred8x8l_vertical_right_10_avx;
307 36 h->pred8x8l[HOR_UP_PRED ] = ff_pred8x8l_horizontal_up_10_avx;
308 }
309 }
310 1218 }
311