FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/x86/scene_sad_init.c
Date: 2025-07-28 20:30:09
Exec Total Coverage
Lines: 16 20 80.0%
Functions: 4 6 66.7%
Branches: 20 28 71.4%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "libavutil/cpu.h"
20 #include "libavutil/x86/cpu.h"
21 #include "libavfilter/scene_sad.h"
22
23 #define SCENE_SAD_FUNC(FUNC_NAME, ASM_FUNC_NAME, MMSIZE) \
24 void ASM_FUNC_NAME(SCENE_SAD_PARAMS); \
25 \
26 static void FUNC_NAME(SCENE_SAD_PARAMS) { \
27 uint64_t sad[MMSIZE / 8] = {0}; \
28 ptrdiff_t awidth = width & ~(MMSIZE - 1); \
29 *sum = 0; \
30 ASM_FUNC_NAME(src1, stride1, src2, stride2, awidth, height, sad); \
31 for (int i = 0; i < MMSIZE / 8; i++) \
32 *sum += sad[i]; \
33 ff_scene_sad_c(src1 + awidth, stride1, \
34 src2 + awidth, stride2, \
35 width - awidth, height, sad); \
36 *sum += sad[0]; \
37 }
38
39 #define SCENE_SAD16_FUNC(FUNC_NAME, ASM_FUNC_NAME, MMSIZE) \
40 void ASM_FUNC_NAME(SCENE_SAD_PARAMS); \
41 \
42 static void FUNC_NAME(SCENE_SAD_PARAMS) { \
43 uint64_t sad[MMSIZE / 8] = {0}; \
44 ptrdiff_t bytes = (width << 1) & ~(MMSIZE - 1); \
45 *sum = 0; \
46 ASM_FUNC_NAME(src1, stride1, src2, stride2, bytes, height, sad); \
47 for (int i = 0; i < MMSIZE / 8; i++) \
48 *sum += sad[i]; \
49 ff_scene_sad16_c(src1 + bytes, stride1, \
50 src2 + bytes, stride2, \
51 width - (bytes >> 1), height, sad); \
52 *sum += sad[0]; \
53 }
54
55 #if HAVE_X86ASM
56
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 2 times.
6 SCENE_SAD_FUNC(scene_sad_sse2, ff_scene_sad8_sse2, 16)
57 #if HAVE_AVX2_EXTERNAL
58
2/2
✓ Branch 1 taken 13460 times.
✓ Branch 2 taken 3365 times.
16825 SCENE_SAD_FUNC(scene_sad_avx2, ff_scene_sad8_avx2, 32)
59
2/2
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 4 times.
20 SCENE_SAD16_FUNC(scene_sad16_avx2, ff_scene_sad16_avx2, 32)
60 #endif
61 #if HAVE_AVX512_EXTERNAL
62 SCENE_SAD_FUNC(scene_sad_avx512, ff_scene_sad8_avx512, 64)
63 SCENE_SAD16_FUNC(scene_sad16_avx512, ff_scene_sad16_avx512, 64)
64 #endif
65 #endif
66
67 87 ff_scene_sad_fn ff_scene_sad_get_fn_x86(int depth)
68 {
69 #if HAVE_X86ASM
70 87 int cpu_flags = av_get_cpu_flags();
71
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 67 times.
87 if (depth <= 8) {
72 #if HAVE_AVX512_EXTERNAL
73
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (EXTERNAL_AVX512(cpu_flags))
74 return scene_sad_avx512;
75 #endif
76 #if HAVE_AVX2_EXTERNAL
77
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
20 if (EXTERNAL_AVX2_FAST(cpu_flags))
78 4 return scene_sad_avx2;
79 #endif
80
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
16 if (EXTERNAL_SSE2(cpu_flags))
81 8 return scene_sad_sse2;
82
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 13 times.
67 } else if (depth < 16) { /* this routine is only safe up to 15 bits */
83 #if HAVE_AVX512_EXTERNAL
84
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
54 if (EXTERNAL_AVX512(cpu_flags))
85 return scene_sad16_avx512;
86 #endif
87 #if HAVE_AVX2_EXTERNAL
88
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 50 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
54 if (EXTERNAL_AVX2_FAST(cpu_flags))
89 4 return scene_sad16_avx2;
90 #endif
91 }
92 #endif
93 71 return NULL;
94 }
95