FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/x86/vp8dsp_init.c
Date: 2026-04-23 21:43:00
Exec Total Coverage
Lines: 80 80 100.0%
Functions: 29 29 100.0%
Branches: 18 18 100.0%

Line Branch Exec Source
1 /*
2 * VP8 DSP functions x86-optimized
3 * Copyright (c) 2010 Ronald S. Bultje <rsbultje@gmail.com>
4 * Copyright (c) 2010 Fiona Glaser <fiona@x264.com>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "libavutil/attributes.h"
24 #include "libavutil/cpu.h"
25 #include "libavutil/mem_internal.h"
26 #include "libavutil/x86/cpu.h"
27 #include "libavcodec/vp8dsp.h"
28
29 /*
30 * MC functions
31 */
32 void ff_put_vp8_epel8_h4_sse2 (uint8_t *dst, ptrdiff_t dststride,
33 const uint8_t *src, ptrdiff_t srcstride,
34 int height, int mx, int my);
35 void ff_put_vp8_epel8_h6_sse2 (uint8_t *dst, ptrdiff_t dststride,
36 const uint8_t *src, ptrdiff_t srcstride,
37 int height, int mx, int my);
38 void ff_put_vp8_epel8_v4_sse2 (uint8_t *dst, ptrdiff_t dststride,
39 const uint8_t *src, ptrdiff_t srcstride,
40 int height, int mx, int my);
41 void ff_put_vp8_epel8_v6_sse2 (uint8_t *dst, ptrdiff_t dststride,
42 const uint8_t *src, ptrdiff_t srcstride,
43 int height, int mx, int my);
44
45 void ff_put_vp8_epel4_h4_ssse3 (uint8_t *dst, ptrdiff_t dststride,
46 const uint8_t *src, ptrdiff_t srcstride,
47 int height, int mx, int my);
48 void ff_put_vp8_epel4_h6_ssse3 (uint8_t *dst, ptrdiff_t dststride,
49 const uint8_t *src, ptrdiff_t srcstride,
50 int height, int mx, int my);
51 void ff_put_vp8_epel4_v4_ssse3 (uint8_t *dst, ptrdiff_t dststride,
52 const uint8_t *src, ptrdiff_t srcstride,
53 int height, int mx, int my);
54 void ff_put_vp8_epel4_v6_ssse3 (uint8_t *dst, ptrdiff_t dststride,
55 const uint8_t *src, ptrdiff_t srcstride,
56 int height, int mx, int my);
57 void ff_put_vp8_epel8_h4_ssse3 (uint8_t *dst, ptrdiff_t dststride,
58 const uint8_t *src, ptrdiff_t srcstride,
59 int height, int mx, int my);
60 void ff_put_vp8_epel8_h6_ssse3 (uint8_t *dst, ptrdiff_t dststride,
61 const uint8_t *src, ptrdiff_t srcstride,
62 int height, int mx, int my);
63 void ff_put_vp8_epel8_v4_ssse3 (uint8_t *dst, ptrdiff_t dststride,
64 const uint8_t *src, ptrdiff_t srcstride,
65 int height, int mx, int my);
66 void ff_put_vp8_epel8_v6_ssse3 (uint8_t *dst, ptrdiff_t dststride,
67 const uint8_t *src, ptrdiff_t srcstride,
68 int height, int mx, int my);
69
70 void ff_put_vp8_bilinear8_h_sse2 (uint8_t *dst, ptrdiff_t dststride,
71 const uint8_t *src, ptrdiff_t srcstride,
72 int height, int mx, int my);
73 void ff_put_vp8_bilinear4_h_ssse3 (uint8_t *dst, ptrdiff_t dststride,
74 const uint8_t *src, ptrdiff_t srcstride,
75 int height, int mx, int my);
76 void ff_put_vp8_bilinear8_h_ssse3 (uint8_t *dst, ptrdiff_t dststride,
77 const uint8_t *src, ptrdiff_t srcstride,
78 int height, int mx, int my);
79
80 void ff_put_vp8_bilinear8_v_sse2 (uint8_t *dst, ptrdiff_t dststride,
81 const uint8_t *src, ptrdiff_t srcstride,
82 int height, int mx, int my);
83 void ff_put_vp8_bilinear4_v_ssse3 (uint8_t *dst, ptrdiff_t dststride,
84 const uint8_t *src, ptrdiff_t srcstride,
85 int height, int mx, int my);
86 void ff_put_vp8_bilinear8_v_ssse3 (uint8_t *dst, ptrdiff_t dststride,
87 const uint8_t *src, ptrdiff_t srcstride,
88 int height, int mx, int my);
89
90
91 void ff_put_vp8_pixels8_sse2(uint8_t *dst, ptrdiff_t dststride,
92 const uint8_t *src, ptrdiff_t srcstride,
93 int height, int mx, int my);
94 void ff_put_vp8_pixels16_sse(uint8_t *dst, ptrdiff_t dststride,
95 const uint8_t *src, ptrdiff_t srcstride,
96 int height, int mx, int my);
97
98 #define TAP_W16(OPT, FILTERTYPE, TAPTYPE) \
99 static void ff_put_vp8_ ## FILTERTYPE ## 16_ ## TAPTYPE ## _ ## OPT( \
100 uint8_t *dst, ptrdiff_t dststride, const uint8_t *src, \
101 ptrdiff_t srcstride, int height, int mx, int my) \
102 { \
103 ff_put_vp8_ ## FILTERTYPE ## 8_ ## TAPTYPE ## _ ## OPT( \
104 dst, dststride, src, srcstride, height, mx, my); \
105 ff_put_vp8_ ## FILTERTYPE ## 8_ ## TAPTYPE ## _ ## OPT( \
106 dst + 8, dststride, src + 8, srcstride, height, mx, my); \
107 }
108
109 4 TAP_W16(sse2, epel, h6)
110 4 TAP_W16(sse2, epel, v6)
111 4 TAP_W16(sse2, bilinear, h)
112 4 TAP_W16(sse2, bilinear, v)
113
114 2 TAP_W16(ssse3, epel, h6)
115 2 TAP_W16(ssse3, epel, v6)
116 2 TAP_W16(ssse3, bilinear, h)
117 2 TAP_W16(ssse3, bilinear, v)
118
119 #define HVTAP(OPT, ALIGN, TAPNUMX, TAPNUMY, SIZE, MAXHEIGHT) \
120 static void ff_put_vp8_epel ## SIZE ## _h ## TAPNUMX ## v ## TAPNUMY ## _ ## OPT( \
121 uint8_t *dst, ptrdiff_t dststride, const uint8_t *src, \
122 ptrdiff_t srcstride, int height, int mx, int my) \
123 { \
124 LOCAL_ALIGNED(ALIGN, uint8_t, tmp, [SIZE * (MAXHEIGHT + TAPNUMY - 1)]); \
125 uint8_t *tmpptr = tmp + SIZE * (TAPNUMY / 2 - 1); \
126 src -= srcstride * (TAPNUMY / 2 - 1); \
127 ff_put_vp8_epel ## SIZE ## _h ## TAPNUMX ## _ ## OPT( \
128 tmp, SIZE, src, srcstride, height + TAPNUMY - 1, mx, my); \
129 ff_put_vp8_epel ## SIZE ## _v ## TAPNUMY ## _ ## OPT( \
130 dst, dststride, tmpptr, SIZE, height, mx, my); \
131 }
132
133 #define HVTAPSSE2(x, y, w) \
134 HVTAP(sse2, 16, x, y, w, 16) \
135 HVTAP(ssse3, 16, x, y, w, 16)
136
137 6 HVTAPSSE2(4, 4, 8)
138 6 HVTAPSSE2(4, 6, 8)
139 6 HVTAPSSE2(6, 4, 8)
140 6 HVTAPSSE2(6, 6, 8)
141 6 HVTAPSSE2(6, 6, 16)
142
143 1 HVTAP(ssse3, 16, 4, 4, 4, 8)
144 1 HVTAP(ssse3, 16, 4, 6, 4, 8)
145 1 HVTAP(ssse3, 16, 6, 4, 4, 8)
146 1 HVTAP(ssse3, 16, 6, 6, 4, 8)
147
148 #define HVBILIN(OPT, ALIGN, SIZE, MAXHEIGHT) \
149 static void ff_put_vp8_bilinear ## SIZE ## _hv_ ## OPT( \
150 uint8_t *dst, ptrdiff_t dststride, const uint8_t *src, \
151 ptrdiff_t srcstride, int height, int mx, int my) \
152 { \
153 LOCAL_ALIGNED(ALIGN, uint8_t, tmp, [SIZE * (MAXHEIGHT + 2)]); \
154 ff_put_vp8_bilinear ## SIZE ## _h_ ## OPT( \
155 tmp, SIZE, src, srcstride, height + 1, mx, my); \
156 ff_put_vp8_bilinear ## SIZE ## _v_ ## OPT( \
157 dst, dststride, tmp, SIZE, height, mx, my); \
158 }
159
160 2 HVBILIN(sse2, 8, 8, 16)
161 2 HVBILIN(sse2, 8, 16, 16)
162 1 HVBILIN(ssse3, 8, 4, 8)
163 1 HVBILIN(ssse3, 8, 8, 16)
164 1 HVBILIN(ssse3, 8, 16, 16)
165
166 void ff_vp8_idct_dc_add_sse2(uint8_t *dst, int16_t block[16],
167 ptrdiff_t stride);
168 void ff_vp8_idct_dc_add_sse4(uint8_t *dst, int16_t block[16],
169 ptrdiff_t stride);
170 void ff_vp8_idct_dc_add4y_sse2(uint8_t *dst, int16_t block[4][16],
171 ptrdiff_t stride);
172 void ff_vp8_idct_dc_add4uv_mmx(uint8_t *dst, int16_t block[2][16],
173 ptrdiff_t stride);
174 void ff_vp8_luma_dc_wht_sse(int16_t block[4][4][16], int16_t dc[16]);
175 void ff_vp8_idct_add_sse(uint8_t *dst, int16_t block[16], ptrdiff_t stride);
176
177 #define DECLARE_LOOP_FILTER(NAME) \
178 void ff_vp8_v_loop_filter_simple_ ## NAME(uint8_t *dst, \
179 ptrdiff_t stride, \
180 int flim); \
181 void ff_vp8_h_loop_filter_simple_ ## NAME(uint8_t *dst, \
182 ptrdiff_t stride, \
183 int flim); \
184 void ff_vp8_v_loop_filter16y_inner_ ## NAME (uint8_t *dst, \
185 ptrdiff_t stride, \
186 int e, int i, int hvt); \
187 void ff_vp8_h_loop_filter16y_inner_ ## NAME (uint8_t *dst, \
188 ptrdiff_t stride, \
189 int e, int i, int hvt); \
190 void ff_vp8_v_loop_filter8uv_inner_ ## NAME (uint8_t *dstU, \
191 uint8_t *dstV, \
192 ptrdiff_t s, \
193 int e, int i, int hvt); \
194 void ff_vp8_h_loop_filter8uv_inner_ ## NAME (uint8_t *dstU, \
195 uint8_t *dstV, \
196 ptrdiff_t s, \
197 int e, int i, int hvt); \
198 void ff_vp8_v_loop_filter16y_mbedge_ ## NAME(uint8_t *dst, \
199 ptrdiff_t stride, \
200 int e, int i, int hvt); \
201 void ff_vp8_h_loop_filter16y_mbedge_ ## NAME(uint8_t *dst, \
202 ptrdiff_t stride, \
203 int e, int i, int hvt); \
204 void ff_vp8_v_loop_filter8uv_mbedge_ ## NAME(uint8_t *dstU, \
205 uint8_t *dstV, \
206 ptrdiff_t s, \
207 int e, int i, int hvt); \
208 void ff_vp8_h_loop_filter8uv_mbedge_ ## NAME(uint8_t *dstU, \
209 uint8_t *dstV, \
210 ptrdiff_t s, \
211 int e, int i, int hvt);
212
213 DECLARE_LOOP_FILTER(sse2)
214 DECLARE_LOOP_FILTER(ssse3)
215 DECLARE_LOOP_FILTER(sse4)
216
217 #define VP8_LUMA_MC_FUNC(IDX, SIZE, OPT) \
218 c->put_vp8_epel_pixels_tab[IDX][0][2] = ff_put_vp8_epel ## SIZE ## _h6_ ## OPT; \
219 c->put_vp8_epel_pixels_tab[IDX][2][0] = ff_put_vp8_epel ## SIZE ## _v6_ ## OPT; \
220 c->put_vp8_epel_pixels_tab[IDX][2][2] = ff_put_vp8_epel ## SIZE ## _h6v6_ ## OPT
221
222 #define VP8_MC_FUNC(IDX, SIZE, OPT) \
223 c->put_vp8_epel_pixels_tab[IDX][0][1] = ff_put_vp8_epel ## SIZE ## _h4_ ## OPT; \
224 c->put_vp8_epel_pixels_tab[IDX][1][0] = ff_put_vp8_epel ## SIZE ## _v4_ ## OPT; \
225 c->put_vp8_epel_pixels_tab[IDX][1][1] = ff_put_vp8_epel ## SIZE ## _h4v4_ ## OPT; \
226 c->put_vp8_epel_pixels_tab[IDX][1][2] = ff_put_vp8_epel ## SIZE ## _h6v4_ ## OPT; \
227 c->put_vp8_epel_pixels_tab[IDX][2][1] = ff_put_vp8_epel ## SIZE ## _h4v6_ ## OPT; \
228 VP8_LUMA_MC_FUNC(IDX, SIZE, OPT)
229
230 #define VP8_BILINEAR_MC_FUNC(IDX, SIZE, OPT) \
231 c->put_vp8_bilinear_pixels_tab[IDX][0][1] = ff_put_vp8_bilinear ## SIZE ## _h_ ## OPT; \
232 c->put_vp8_bilinear_pixels_tab[IDX][0][2] = ff_put_vp8_bilinear ## SIZE ## _h_ ## OPT; \
233 c->put_vp8_bilinear_pixels_tab[IDX][1][0] = ff_put_vp8_bilinear ## SIZE ## _v_ ## OPT; \
234 c->put_vp8_bilinear_pixels_tab[IDX][1][1] = ff_put_vp8_bilinear ## SIZE ## _hv_ ## OPT; \
235 c->put_vp8_bilinear_pixels_tab[IDX][1][2] = ff_put_vp8_bilinear ## SIZE ## _hv_ ## OPT; \
236 c->put_vp8_bilinear_pixels_tab[IDX][2][0] = ff_put_vp8_bilinear ## SIZE ## _v_ ## OPT; \
237 c->put_vp8_bilinear_pixels_tab[IDX][2][1] = ff_put_vp8_bilinear ## SIZE ## _hv_ ## OPT; \
238 c->put_vp8_bilinear_pixels_tab[IDX][2][2] = ff_put_vp8_bilinear ## SIZE ## _hv_ ## OPT
239
240
241 77 av_cold void ff_vp78dsp_init_x86(VP8DSPContext *c)
242 {
243 77 int cpu_flags = av_get_cpu_flags();
244
245
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 56 times.
77 if (EXTERNAL_SSE(cpu_flags)) {
246 21 c->put_vp8_epel_pixels_tab[0][0][0] =
247 21 c->put_vp8_bilinear_pixels_tab[0][0][0] = ff_put_vp8_pixels16_sse;
248 }
249
250
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 57 times.
77 if (EXTERNAL_SSE2_SLOW(cpu_flags)) {
251 20 c->put_vp8_epel_pixels_tab[1][0][0] =
252 20 c->put_vp8_bilinear_pixels_tab[1][0][0] = ff_put_vp8_pixels8_sse2;
253 20 VP8_LUMA_MC_FUNC(0, 16, sse2);
254 20 VP8_MC_FUNC(1, 8, sse2);
255 20 VP8_BILINEAR_MC_FUNC(0, 16, sse2);
256 20 VP8_BILINEAR_MC_FUNC(1, 8, sse2);
257 }
258
259 /* note that 4-tap width=16 functions are missing because w=16
260 * is only used for luma, and luma is always a copy or sixtap. */
261
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 59 times.
77 if (EXTERNAL_SSSE3(cpu_flags)) {
262 18 VP8_LUMA_MC_FUNC(0, 16, ssse3);
263 18 VP8_MC_FUNC(1, 8, ssse3);
264 18 VP8_MC_FUNC(2, 4, ssse3);
265 18 VP8_BILINEAR_MC_FUNC(0, 16, ssse3);
266 18 VP8_BILINEAR_MC_FUNC(1, 8, ssse3);
267 18 VP8_BILINEAR_MC_FUNC(2, 4, ssse3);
268 }
269 77 }
270
271 74 av_cold void ff_vp8dsp_init_x86(VP8DSPContext *c)
272 {
273 74 int cpu_flags = av_get_cpu_flags();
274
275
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 51 times.
74 if (EXTERNAL_MMX(cpu_flags)) {
276 23 c->vp8_idct_dc_add4uv = ff_vp8_idct_dc_add4uv_mmx;
277 }
278
279
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 53 times.
74 if (EXTERNAL_SSE(cpu_flags)) {
280 21 c->vp8_idct_add = ff_vp8_idct_add_sse;
281 21 c->vp8_luma_dc_wht = ff_vp8_luma_dc_wht_sse;
282 }
283
284
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 54 times.
74 if (EXTERNAL_SSE2_SLOW(cpu_flags)) {
285 20 c->vp8_v_loop_filter_simple = ff_vp8_v_loop_filter_simple_sse2;
286
287 20 c->vp8_v_loop_filter16y_inner = ff_vp8_v_loop_filter16y_inner_sse2;
288 20 c->vp8_v_loop_filter8uv_inner = ff_vp8_v_loop_filter8uv_inner_sse2;
289
290 20 c->vp8_v_loop_filter16y = ff_vp8_v_loop_filter16y_mbedge_sse2;
291 20 c->vp8_v_loop_filter8uv = ff_vp8_v_loop_filter8uv_mbedge_sse2;
292 }
293
294
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 54 times.
74 if (EXTERNAL_SSE2(cpu_flags)) {
295 20 c->vp8_idct_dc_add = ff_vp8_idct_dc_add_sse2;
296 20 c->vp8_idct_dc_add4y = ff_vp8_idct_dc_add4y_sse2;
297
298 20 c->vp8_h_loop_filter_simple = ff_vp8_h_loop_filter_simple_sse2;
299
300 20 c->vp8_h_loop_filter16y_inner = ff_vp8_h_loop_filter16y_inner_sse2;
301 20 c->vp8_h_loop_filter8uv_inner = ff_vp8_h_loop_filter8uv_inner_sse2;
302
303 20 c->vp8_h_loop_filter16y = ff_vp8_h_loop_filter16y_mbedge_sse2;
304 20 c->vp8_h_loop_filter8uv = ff_vp8_h_loop_filter8uv_mbedge_sse2;
305 }
306
307
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 56 times.
74 if (EXTERNAL_SSSE3(cpu_flags)) {
308 18 c->vp8_v_loop_filter_simple = ff_vp8_v_loop_filter_simple_ssse3;
309 18 c->vp8_h_loop_filter_simple = ff_vp8_h_loop_filter_simple_ssse3;
310
311 18 c->vp8_v_loop_filter16y_inner = ff_vp8_v_loop_filter16y_inner_ssse3;
312 18 c->vp8_h_loop_filter16y_inner = ff_vp8_h_loop_filter16y_inner_ssse3;
313 18 c->vp8_v_loop_filter8uv_inner = ff_vp8_v_loop_filter8uv_inner_ssse3;
314 18 c->vp8_h_loop_filter8uv_inner = ff_vp8_h_loop_filter8uv_inner_ssse3;
315
316 18 c->vp8_v_loop_filter16y = ff_vp8_v_loop_filter16y_mbedge_ssse3;
317 18 c->vp8_h_loop_filter16y = ff_vp8_h_loop_filter16y_mbedge_ssse3;
318 18 c->vp8_v_loop_filter8uv = ff_vp8_v_loop_filter8uv_mbedge_ssse3;
319 18 c->vp8_h_loop_filter8uv = ff_vp8_h_loop_filter8uv_mbedge_ssse3;
320 }
321
322
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 57 times.
74 if (EXTERNAL_SSE4(cpu_flags)) {
323 17 c->vp8_idct_dc_add = ff_vp8_idct_dc_add_sse4;
324
325 17 c->vp8_h_loop_filter_simple = ff_vp8_h_loop_filter_simple_sse4;
326 17 c->vp8_h_loop_filter16y = ff_vp8_h_loop_filter16y_mbedge_sse4;
327 17 c->vp8_h_loop_filter8uv = ff_vp8_h_loop_filter8uv_mbedge_sse4;
328 }
329 74 }
330