FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/x86/vvc/vvcdsp_init.c
Date: 2024-04-12 08:31:17
Exec Total Coverage
Lines: 42 44 95.5%
Functions: 216 216 100.0%
Branches: 25 30 83.3%

Line Branch Exec Source
1 /*
2 * VVC DSP init for x86
3 *
4 * Copyright (C) 2022-2024 Nuo Mi
5 * Copyright (c) 2023-2024 Wu Jianhua
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #include "config.h"
25
26 #include "libavutil/cpu.h"
27 #include "libavutil/x86/cpu.h"
28 #include "libavcodec/vvc/dec.h"
29 #include "libavcodec/vvc/ctu.h"
30 #include "libavcodec/vvc/dsp.h"
31 #include "libavcodec/x86/h26x/h2656dsp.h"
32
33 #if ARCH_X86_64
34 #define FW_PUT(name, depth, opt) \
35 static void ff_vvc_put_ ## name ## _ ## depth ## _##opt(int16_t *dst, const uint8_t *src, ptrdiff_t srcstride, \
36 int height, const int8_t *hf, const int8_t *vf, int width) \
37 { \
38 ff_h2656_put_## name ## _ ## depth ## _##opt(dst, 2 * MAX_PB_SIZE, src, srcstride, height, hf, vf, width); \
39 }
40
41 #define FW_PUT_TAP(fname, bitd, opt ) \
42 FW_PUT(fname##4, bitd, opt ) \
43 FW_PUT(fname##8, bitd, opt ) \
44 FW_PUT(fname##16, bitd, opt ) \
45 FW_PUT(fname##32, bitd, opt ) \
46 FW_PUT(fname##64, bitd, opt ) \
47 FW_PUT(fname##128, bitd, opt ) \
48
49 #define FW_PUT_4TAP(fname, bitd, opt) \
50 FW_PUT(fname ## 2, bitd, opt) \
51 FW_PUT_TAP(fname, bitd, opt)
52
53 #define FW_PUT_4TAP_SSE4(bitd) \
54 FW_PUT_4TAP(pixels, bitd, sse4) \
55 FW_PUT_4TAP(4tap_h, bitd, sse4) \
56 FW_PUT_4TAP(4tap_v, bitd, sse4) \
57 FW_PUT_4TAP(4tap_hv, bitd, sse4)
58
59 #define FW_PUT_8TAP_SSE4(bitd) \
60 FW_PUT_TAP(8tap_h, bitd, sse4) \
61 FW_PUT_TAP(8tap_v, bitd, sse4) \
62 FW_PUT_TAP(8tap_hv, bitd, sse4)
63
64 #define FW_PUT_SSE4(bitd) \
65 FW_PUT_4TAP_SSE4(bitd) \
66 FW_PUT_8TAP_SSE4(bitd)
67
68 914 FW_PUT_SSE4( 8)
69 1096 FW_PUT_SSE4(10)
70 1096 FW_PUT_SSE4(12)
71
72 #define FW_PUT_TAP_AVX2(n, bitd) \
73 FW_PUT(n ## tap_h32, bitd, avx2) \
74 FW_PUT(n ## tap_h64, bitd, avx2) \
75 FW_PUT(n ## tap_h128, bitd, avx2) \
76 FW_PUT(n ## tap_v32, bitd, avx2) \
77 FW_PUT(n ## tap_v64, bitd, avx2) \
78 FW_PUT(n ## tap_v128, bitd, avx2)
79
80 #define FW_PUT_AVX2(bitd) \
81 FW_PUT(pixels32, bitd, avx2) \
82 FW_PUT(pixels64, bitd, avx2) \
83 FW_PUT(pixels128, bitd, avx2) \
84 FW_PUT_TAP_AVX2(4, bitd) \
85 FW_PUT_TAP_AVX2(8, bitd) \
86
87 234 FW_PUT_AVX2( 8)
88 234 FW_PUT_AVX2(10)
89 234 FW_PUT_AVX2(12)
90
91 #define FW_PUT_TAP_16BPC_AVX2(n, bitd) \
92 FW_PUT(n ## tap_h16, bitd, avx2) \
93 FW_PUT(n ## tap_v16, bitd, avx2) \
94 FW_PUT(n ## tap_hv16, bitd, avx2) \
95 FW_PUT(n ## tap_hv32, bitd, avx2) \
96 FW_PUT(n ## tap_hv64, bitd, avx2) \
97 FW_PUT(n ## tap_hv128, bitd, avx2)
98
99 #define FW_PUT_16BPC_AVX2(bitd) \
100 FW_PUT(pixels16, bitd, avx2) \
101 FW_PUT_TAP_16BPC_AVX2(4, bitd) \
102 FW_PUT_TAP_16BPC_AVX2(8, bitd)
103
104 182 FW_PUT_16BPC_AVX2(10)
105 182 FW_PUT_16BPC_AVX2(12)
106
107 #define PEL_LINK(dst, C, W, idx1, idx2, name, D, opt) \
108 dst[C][W][idx1][idx2] = ff_vvc_put_## name ## _ ## D ## _##opt; \
109 dst ## _uni[C][W][idx1][idx2] = ff_h2656_put_uni_ ## name ## _ ## D ## _##opt; \
110
111 #define MC_TAP_LINKS(pointer, C, my, mx, fname, bitd, opt ) \
112 PEL_LINK(pointer, C, 1, my , mx , fname##4 , bitd, opt ); \
113 PEL_LINK(pointer, C, 2, my , mx , fname##8 , bitd, opt ); \
114 PEL_LINK(pointer, C, 3, my , mx , fname##16, bitd, opt ); \
115 PEL_LINK(pointer, C, 4, my , mx , fname##32, bitd, opt ); \
116 PEL_LINK(pointer, C, 5, my , mx , fname##64, bitd, opt ); \
117 PEL_LINK(pointer, C, 6, my , mx , fname##128, bitd, opt );
118
119 #define MC_8TAP_LINKS(pointer, my, mx, fname, bitd, opt) \
120 MC_TAP_LINKS(pointer, LUMA, my, mx, fname, bitd, opt)
121
122 #define MC_8TAP_LINKS_SSE4(bd) \
123 MC_8TAP_LINKS(c->inter.put, 0, 0, pixels, bd, sse4); \
124 MC_8TAP_LINKS(c->inter.put, 0, 1, 8tap_h, bd, sse4); \
125 MC_8TAP_LINKS(c->inter.put, 1, 0, 8tap_v, bd, sse4); \
126 MC_8TAP_LINKS(c->inter.put, 1, 1, 8tap_hv, bd, sse4)
127
128 #define MC_4TAP_LINKS(pointer, my, mx, fname, bitd, opt) \
129 PEL_LINK(pointer, CHROMA, 0, my , mx , fname##2 , bitd, opt ); \
130 MC_TAP_LINKS(pointer, CHROMA, my, mx, fname, bitd, opt) \
131
132 #define MC_4TAP_LINKS_SSE4(bd) \
133 MC_4TAP_LINKS(c->inter.put, 0, 0, pixels, bd, sse4); \
134 MC_4TAP_LINKS(c->inter.put, 0, 1, 4tap_h, bd, sse4); \
135 MC_4TAP_LINKS(c->inter.put, 1, 0, 4tap_v, bd, sse4); \
136 MC_4TAP_LINKS(c->inter.put, 1, 1, 4tap_hv, bd, sse4)
137
138 #define MC_LINK_SSE4(bd) \
139 MC_4TAP_LINKS_SSE4(bd) \
140 MC_8TAP_LINKS_SSE4(bd)
141
142 #define MC_TAP_LINKS_AVX2(C,tap,bd) do { \
143 PEL_LINK(c->inter.put, C, 4, 0, 0, pixels32, bd, avx2) \
144 PEL_LINK(c->inter.put, C, 5, 0, 0, pixels64, bd, avx2) \
145 PEL_LINK(c->inter.put, C, 6, 0, 0, pixels128, bd, avx2) \
146 PEL_LINK(c->inter.put, C, 4, 0, 1, tap##tap_h32, bd, avx2) \
147 PEL_LINK(c->inter.put, C, 5, 0, 1, tap##tap_h64, bd, avx2) \
148 PEL_LINK(c->inter.put, C, 6, 0, 1, tap##tap_h128, bd, avx2) \
149 PEL_LINK(c->inter.put, C, 4, 1, 0, tap##tap_v32, bd, avx2) \
150 PEL_LINK(c->inter.put, C, 5, 1, 0, tap##tap_v64, bd, avx2) \
151 PEL_LINK(c->inter.put, C, 6, 1, 0, tap##tap_v128, bd, avx2) \
152 } while (0)
153
154 #define MC_LINKS_AVX2(bd) \
155 MC_TAP_LINKS_AVX2(LUMA, 8, bd); \
156 MC_TAP_LINKS_AVX2(CHROMA, 4, bd);
157
158 #define MC_TAP_LINKS_16BPC_AVX2(C, tap, bd) do { \
159 PEL_LINK(c->inter.put, C, 3, 0, 0, pixels16, bd, avx2) \
160 PEL_LINK(c->inter.put, C, 3, 0, 1, tap##tap_h16, bd, avx2) \
161 PEL_LINK(c->inter.put, C, 3, 1, 0, tap##tap_v16, bd, avx2) \
162 PEL_LINK(c->inter.put, C, 3, 1, 1, tap##tap_hv16, bd, avx2) \
163 PEL_LINK(c->inter.put, C, 4, 1, 1, tap##tap_hv32, bd, avx2) \
164 PEL_LINK(c->inter.put, C, 5, 1, 1, tap##tap_hv64, bd, avx2) \
165 PEL_LINK(c->inter.put, C, 6, 1, 1, tap##tap_hv128, bd, avx2) \
166 } while (0)
167
168 #define MC_LINKS_16BPC_AVX2(bd) \
169 MC_TAP_LINKS_16BPC_AVX2(LUMA, 8, bd); \
170 MC_TAP_LINKS_16BPC_AVX2(CHROMA, 4, bd);
171
172 #define bf(fn, bd, opt) fn##_##bd##_##opt
173 #define BF(fn, bpc, opt) fn##_##bpc##bpc_##opt
174
175 #define AVG_BPC_FUNC(bpc, opt) \
176 void BF(ff_vvc_avg, bpc, opt)(uint8_t *dst, ptrdiff_t dst_stride, \
177 const int16_t *src0, const int16_t *src1, intptr_t width, intptr_t height, intptr_t pixel_max); \
178 void BF(ff_vvc_w_avg, bpc, opt)(uint8_t *dst, ptrdiff_t dst_stride, \
179 const int16_t *src0, const int16_t *src1, intptr_t width, intptr_t height, \
180 intptr_t denom, intptr_t w0, intptr_t w1, intptr_t o0, intptr_t o1, intptr_t pixel_max);
181
182 #define AVG_FUNCS(bpc, bd, opt) \
183 static void bf(avg, bd, opt)(uint8_t *dst, ptrdiff_t dst_stride, \
184 const int16_t *src0, const int16_t *src1, int width, int height) \
185 { \
186 BF(ff_vvc_avg, bpc, opt)(dst, dst_stride, src0, src1, width, height, (1 << bd) - 1); \
187 } \
188 static void bf(w_avg, bd, opt)(uint8_t *dst, ptrdiff_t dst_stride, \
189 const int16_t *src0, const int16_t *src1, int width, int height, \
190 int denom, int w0, int w1, int o0, int o1) \
191 { \
192 BF(ff_vvc_w_avg, bpc, opt)(dst, dst_stride, src0, src1, width, height, \
193 denom, w0, w1, o0, o1, (1 << bd) - 1); \
194 }
195
196 AVG_BPC_FUNC(8, avx2)
197 AVG_BPC_FUNC(16, avx2)
198
199 196 AVG_FUNCS(8, 8, avx2)
200 196 AVG_FUNCS(16, 10, avx2)
201 196 AVG_FUNCS(16, 12, avx2)
202
203 #define AVG_INIT(bd, opt) do { \
204 c->inter.avg = bf(avg, bd, opt); \
205 c->inter.w_avg = bf(w_avg, bd, opt); \
206 } while (0)
207 #endif
208
209 1067 void ff_vvc_dsp_init_x86(VVCDSPContext *const c, const int bd)
210 {
211 #if ARCH_X86_64
212 1067 const int cpu_flags = av_get_cpu_flags();
213
214
2/2
✓ Branch 0 taken 68 times.
✓ Branch 1 taken 999 times.
1067 if (bd == 8) {
215
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 38 times.
68 if (EXTERNAL_SSE4(cpu_flags)) {
216 30 MC_LINK_SSE4(8);
217 }
218
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
68 if (EXTERNAL_AVX2_FAST(cpu_flags)) {
219 5 MC_LINKS_AVX2(8);
220 }
221
2/2
✓ Branch 0 taken 934 times.
✓ Branch 1 taken 65 times.
999 } else if (bd == 10) {
222
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 904 times.
934 if (EXTERNAL_SSE4(cpu_flags)) {
223 30 MC_LINK_SSE4(10);
224 }
225
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 929 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
934 if (EXTERNAL_AVX2_FAST(cpu_flags)) {
226 5 MC_LINKS_AVX2(10);
227 5 MC_LINKS_16BPC_AVX2(10);
228 }
229
1/2
✓ Branch 0 taken 65 times.
✗ Branch 1 not taken.
65 } else if (bd == 12) {
230
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 35 times.
65 if (EXTERNAL_SSE4(cpu_flags)) {
231 30 MC_LINK_SSE4(12);
232 }
233
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 60 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
65 if (EXTERNAL_AVX2_FAST(cpu_flags)) {
234 5 MC_LINKS_AVX2(12);
235 5 MC_LINKS_16BPC_AVX2(12);
236 }
237 }
238
239
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 1052 times.
1067 if (EXTERNAL_AVX2(cpu_flags)) {
240
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
15 switch (bd) {
241 5 case 8:
242 5 AVG_INIT(8, avx2);
243 5 break;
244 5 case 10:
245 5 AVG_INIT(10, avx2);
246 5 break;
247 5 case 12:
248 5 AVG_INIT(12, avx2);
249 5 break;
250 default:
251 break;
252 }
253 }
254 #endif
255 1067 }
256