FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/x86/mpegvideoenc.c
Date: 2025-07-12 02:25:37
Exec Total Coverage
Lines: 7 18 38.9%
Functions: 1 2 50.0%
Branches: 5 8 62.5%

Line Branch Exec Source
1 /*
2 * The simplest mpeg encoder (well, it was the simplest!)
3 * Copyright (c) 2000,2001 Fabrice Bellard
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include "libavutil/attributes.h"
23 #include "libavutil/cpu.h"
24 #include "libavutil/mem_internal.h"
25 #include "libavutil/x86/asm.h"
26 #include "libavutil/x86/cpu.h"
27 #include "libavcodec/avcodec.h"
28 #include "libavcodec/mpegvideoenc.h"
29
30 /* not permutated inverse zigzag_direct + 1 for MMX quantizer */
31 DECLARE_ALIGNED(16, static const uint16_t, inv_zigzag_direct16)[64] = {
32 1, 2, 6, 7, 15, 16, 28, 29,
33 3, 5, 8, 14, 17, 27, 30, 43,
34 4, 9, 13, 18, 26, 31, 42, 44,
35 10, 12, 19, 25, 32, 41, 45, 54,
36 11, 20, 24, 33, 40, 46, 53, 55,
37 21, 23, 34, 39, 47, 52, 56, 61,
38 22, 35, 38, 48, 51, 57, 60, 62,
39 36, 37, 49, 50, 58, 59, 63, 64,
40 };
41
42 #if HAVE_6REGS
43
44 #if HAVE_SSE2_INLINE
45 #define COMPILE_TEMPLATE_SSSE3 0
46 #define RENAME(a) a ## _sse2
47 #include "mpegvideoenc_template.c"
48 #endif /* HAVE_SSE2_INLINE */
49
50 #if HAVE_SSSE3_INLINE
51 #undef COMPILE_TEMPLATE_SSSE3
52 #define COMPILE_TEMPLATE_SSSE3 1
53 #undef RENAME
54 #define RENAME(a) a ## _ssse3
55 #include "mpegvideoenc_template.c"
56 #endif /* HAVE_SSSE3_INLINE */
57
58 #endif /* HAVE_6REGS */
59
60 #if HAVE_INLINE_ASM
61 #if HAVE_SSE2_INLINE
62 static void denoise_dct_sse2(MPVEncContext *const s, int16_t block[])
63 {
64 const int intra = s->c.mb_intra;
65 int *sum= s->dct_error_sum[intra];
66 uint16_t *offset= s->dct_offset[intra];
67
68 s->dct_count[intra]++;
69
70 __asm__ volatile(
71 "pxor %%xmm7, %%xmm7 \n\t"
72 "1: \n\t"
73 "pxor %%xmm0, %%xmm0 \n\t"
74 "pxor %%xmm1, %%xmm1 \n\t"
75 "movdqa (%0), %%xmm2 \n\t"
76 "movdqa 16(%0), %%xmm3 \n\t"
77 "pcmpgtw %%xmm2, %%xmm0 \n\t"
78 "pcmpgtw %%xmm3, %%xmm1 \n\t"
79 "pxor %%xmm0, %%xmm2 \n\t"
80 "pxor %%xmm1, %%xmm3 \n\t"
81 "psubw %%xmm0, %%xmm2 \n\t"
82 "psubw %%xmm1, %%xmm3 \n\t"
83 "movdqa %%xmm2, %%xmm4 \n\t"
84 "movdqa %%xmm3, %%xmm5 \n\t"
85 "psubusw (%2), %%xmm2 \n\t"
86 "psubusw 16(%2), %%xmm3 \n\t"
87 "pxor %%xmm0, %%xmm2 \n\t"
88 "pxor %%xmm1, %%xmm3 \n\t"
89 "psubw %%xmm0, %%xmm2 \n\t"
90 "psubw %%xmm1, %%xmm3 \n\t"
91 "movdqa %%xmm2, (%0) \n\t"
92 "movdqa %%xmm3, 16(%0) \n\t"
93 "movdqa %%xmm4, %%xmm6 \n\t"
94 "movdqa %%xmm5, %%xmm0 \n\t"
95 "punpcklwd %%xmm7, %%xmm4 \n\t"
96 "punpckhwd %%xmm7, %%xmm6 \n\t"
97 "punpcklwd %%xmm7, %%xmm5 \n\t"
98 "punpckhwd %%xmm7, %%xmm0 \n\t"
99 "paddd (%1), %%xmm4 \n\t"
100 "paddd 16(%1), %%xmm6 \n\t"
101 "paddd 32(%1), %%xmm5 \n\t"
102 "paddd 48(%1), %%xmm0 \n\t"
103 "movdqa %%xmm4, (%1) \n\t"
104 "movdqa %%xmm6, 16(%1) \n\t"
105 "movdqa %%xmm5, 32(%1) \n\t"
106 "movdqa %%xmm0, 48(%1) \n\t"
107 "add $32, %0 \n\t"
108 "add $64, %1 \n\t"
109 "add $32, %2 \n\t"
110 "cmp %3, %0 \n\t"
111 " jb 1b \n\t"
112 : "+r" (block), "+r" (sum), "+r" (offset)
113 : "r"(block+64)
114 XMM_CLOBBERS_ONLY("%xmm0", "%xmm1", "%xmm2", "%xmm3",
115 "%xmm4", "%xmm5", "%xmm6", "%xmm7")
116 );
117 }
118 #endif /* HAVE_SSE2_INLINE */
119 #endif /* HAVE_INLINE_ASM */
120
121 277 av_cold void ff_dct_encode_init_x86(MPVEncContext *const s)
122 {
123 277 const int dct_algo = s->c.avctx->dct_algo;
124
125
3/4
✓ Branch 0 taken 273 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 273 times.
277 if (dct_algo == FF_DCT_AUTO || dct_algo == FF_DCT_MMX) {
126 #if HAVE_MMX_INLINE
127 4 int cpu_flags = av_get_cpu_flags();
128 #if HAVE_SSE2_INLINE
129
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (INLINE_SSE2(cpu_flags)) {
130 #if HAVE_6REGS
131 s->dct_quantize = dct_quantize_sse2;
132 #endif
133 s->denoise_dct = denoise_dct_sse2;
134 }
135 #endif
136 #if HAVE_6REGS && HAVE_SSSE3_INLINE
137
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (INLINE_SSSE3(cpu_flags))
138 s->dct_quantize = dct_quantize_ssse3;
139 #endif
140 #endif
141 }
142 277 }
143