../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
248 / 281
88.3%
Branches:
252 / 335
75.2%
Functions:
17 / 17
100.0%

libswscale/x86/ops.c
Line Branch Exec Source
1 /**
2 * Copyright (C) 2025-2026 Niklas Haas
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 <float.h>
22
23 #include "libavutil/avassert.h"
24 #include "libavutil/mem.h"
25 #include "libavutil/x86/cpu.h"
26
27 #include "../ops_chain.h"
28 #include "../uops.h"
29 #include "uops_macros.h"
30
31 139718 static int setup_rw_packed(const SwsImplParams *params, SwsImplResult *out)
32 {
33 139718 const SwsUOp *uop = params->uop;
34
35 /* 3-component packed reads/writes process one extra garbage word */
36
2/2
✓ Branch 2 → 3 taken 34211 times.
✓ Branch 2 → 6 taken 105507 times.
139718 if (uop->mask == SWS_COMP_ELEMS(3)) {
37
2/3
✓ Branch 3 → 4 taken 18128 times.
✓ Branch 3 → 5 taken 16083 times.
✗ Branch 3 → 6 not taken.
34211 switch (uop->uop) {
38 18128 case SWS_UOP_READ_PACKED: out->over_read[0] = sizeof(uint32_t); break;
39 16083 case SWS_UOP_WRITE_PACKED: out->over_write[0] = sizeof(uint32_t); break;
40 }
41 }
42
43 139718 return 0;
44 }
45
46 /* Private data for the filter kernels; layout hard-coded in ops_float.asm */
47 typedef struct FilterPriv {
48 void *weights;
49 size_t filter_size;
50 } FilterPriv;
51
52 static_assert(offsetof(FilterPriv, filter_size) == sizeof(void *),
53 "FilterPriv layout mismatch");
54
55 38356 static int setup_filter_v(const SwsImplParams *params, SwsImplResult *out)
56 {
57 38356 const SwsFilterWeights *filter = params->uop->data.kernel;
58
59 /* Pre-convert weights to float */
60 38356 float *weights = ff_refstruct_calloc(filter->num_weights, sizeof(float));
61
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 38356 times.
38356 if (!weights)
62 ✗ return AVERROR(ENOMEM);
63
64
2/2
✓ Branch 7 → 6 taken 12368928 times.
✓ Branch 7 → 8 taken 38356 times.
12407284 for (int i = 0; i < filter->num_weights; i++)
65 12368928 weights[i] = (float) filter->weights[i] / SWS_FILTER_SCALE;
66
67 38356 const FilterPriv priv = {
68 .weights = weights,
69 38356 .filter_size = filter->filter_size,
70 };
71
72 38356 SWS_OP_PRIV_PACK(out, priv);
73 38356 out->ref = priv.weights;
74 38356 return 0;
75 }
76
77 38251 static int hscale_sizeof_weight(const SwsUOp *uop)
78 {
79
3/4
✓ Branch 2 → 3 taken 10724 times.
✓ Branch 2 → 4 taken 19585 times.
✓ Branch 2 → 5 taken 7942 times.
✗ Branch 2 → 6 not taken.
38251 switch (uop->type) {
80 10724 case SWS_PIXEL_U8: return sizeof(int16_t);
81 19585 case SWS_PIXEL_U16: return sizeof(int16_t);
82 7942 case SWS_PIXEL_F32: return sizeof(float);
83 ✗ default: return 0;
84 }
85 }
86
87 5361 static int setup_filter_h(const SwsImplParams *params, SwsImplResult *out)
88 {
89 5361 const SwsUOp *uop = params->uop;
90 5361 const SwsFilterWeights *filter = uop->data.kernel;
91
92 /**
93 * `vpgatherdd` gathers 32 bits at a time; so if we're filtering a smaller
94 * size, we need to gather 2/4 taps simultaneously and unroll the inner
95 * loop over several packed samples.
96 */
97 5361 const int pixel_size = ff_sws_pixel_type_size(uop->type);
98 5361 const int taps_align = sizeof(int32_t) / pixel_size;
99 5361 const int filter_size = filter->filter_size;
100 5361 const int block_size = params->table->block_size;
101 5361 const size_t aligned_size = FFALIGN(filter_size, taps_align);
102 5361 const size_t line_size = FFALIGN(filter->dst_size, block_size);
103 av_assert1(FFALIGN(line_size, taps_align) == line_size);
104
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 5361 times.
5361 if (aligned_size > INT_MAX)
105 ✗ return AVERROR(EINVAL);
106
107 union {
108 void *ptr;
109 int16_t *i16;
110 float *f32;
111 } weights;
112
113 5361 const int sizeof_weight = hscale_sizeof_weight(uop);
114 5361 weights.ptr = ff_refstruct_calloc(line_size, sizeof_weight * aligned_size);
115
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 5361 times.
5361 if (!weights.ptr)
116 ✗ return AVERROR(ENOMEM);
117
118 /**
119 * Transpose filter weights to group (aligned) taps by block
120 */
121 5361 const int mmsize = block_size * 2;
122 5361 const int gather_size = mmsize / sizeof(int32_t); /* pixels per vpgatherdd */
123
2/2
✓ Branch 23 → 9 taken 31930 times.
✓ Branch 23 → 24 taken 5361 times.
37291 for (size_t x = 0; x < line_size; x += block_size) {
124 31930 const int elems = FFMIN(block_size, filter->dst_size - x);
125
2/2
✓ Branch 21 → 10 taken 85034 times.
✓ Branch 21 → 22 taken 31930 times.
116964 for (int j = 0; j < filter_size; j++) {
126 85034 const int jb = j & ~(taps_align - 1);
127 85034 const int ji = j - jb;
128 85034 const size_t idx_base = x * aligned_size + jb * block_size + ji;
129
2/2
✓ Branch 19 → 11 taken 1360544 times.
✓ Branch 19 → 20 taken 85034 times.
1445578 for (int i = 0; i < elems; i++) {
130 1360544 const int w = filter->weights[(x + i) * filter_size + j];
131 1360544 size_t idx = idx_base;
132
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 1360544 times.
1360544 if (uop->type == SWS_PIXEL_U8) {
133 /* Interleave the pixels within each lane, i.e.:
134 * [a0 a1 a2 a3 | b0 b1 b2 b3 ] pixels 0-1, taps 0-3 (lane 0)
135 * [e0 e1 e2 e3 | f0 f1 f2 f3 ] pixels 4-5, taps 0-3 (lane 1)
136 * [c0 c1 c2 c3 | d0 d1 d2 d3 ] pixels 2-3, taps 0-3 (lane 0)
137 * [g0 g1 g2 g3 | h0 h1 h2 h3 ] pixels 6-7, taps 0-3 (lane 1)
138 * [i0 i1 i2 i3 | j0 j1 j2 j3 ] pixels 8-9, taps 0-3 (lane 0)
139 * ...
140 * [o0 o1 o2 o3 | p0 p1 p2 p3 ] pixels 14-15, taps 0-3 (lane 1)
141 * (repeat for taps 4-7, etc.)
142 */
143 ✗ const int gather_base = i & ~(gather_size - 1);
144 ✗ const int gather_pos = i - gather_base;
145 ✗ const int lane_idx = gather_pos >> 2;
146 ✗ const int pos_in_lane = gather_pos & 3;
147 ✗ idx += gather_base * 4 /* which gather (m0 or m1) */
148 ✗ + (pos_in_lane >> 1) * (mmsize / 2) /* lo/hi unpack */
149 ✗ + lane_idx * 8 /* 8 ints per lane */
150 ✗ + (pos_in_lane & 1) * 4; /* 4 taps per pair */
151 } else {
152 1360544 idx += i * taps_align;
153 }
154
155
1/4
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 16 not taken.
✓ Branch 14 → 17 taken 1360544 times.
✗ Branch 14 → 18 not taken.
1360544 switch (uop->type) {
156 ✗ case SWS_PIXEL_U8: weights.i16[idx] = w; break;
157 ✗ case SWS_PIXEL_U16: weights.i16[idx] = w; break;
158 1360544 case SWS_PIXEL_F32: weights.f32[idx] = w; break;
159 }
160 }
161 }
162 }
163
164 5361 const FilterPriv priv = {
165 5361 .weights = weights.ptr,
166 .filter_size = aligned_size,
167 };
168
169 5361 SWS_OP_PRIV_PACK(out, priv);
170 5361 out->ref = priv.weights;
171
172
2/2
✓ Branch 29 → 26 taken 21444 times.
✓ Branch 29 → 30 taken 5361 times.
26805 for (int i = 0; i < 4; i++) {
173
2/2
✓ Branch 26 → 27 taken 14580 times.
✓ Branch 26 → 28 taken 6864 times.
21444 if (uop->mask & SWS_COMP(i))
174 14580 out->over_read[i] = (aligned_size - filter_size) * pixel_size;
175 }
176 5361 return 0;
177 }
178
179 38251 static bool check_filter_h_4x4(const SwsImplParams *params)
180 {
181 38251 SwsContext *ctx = params->ctx;
182 38251 const SwsUOp *uop = params->uop;
183
4/4
✓ Branch 2 → 3 taken 10745 times.
✓ Branch 2 → 5 taken 27506 times.
✓ Branch 3 → 4 taken 5361 times.
✓ Branch 3 → 5 taken 5384 times.
38251 if ((ctx->flags & SWS_BITEXACT) && uop->type == SWS_PIXEL_F32)
184 5361 return false; /* different accumulation order due to 4x4 transpose */
185
186 32890 const int cpu_flags = av_get_cpu_flags();
187
1/2
✓ Branch 6 → 7 taken 32890 times.
✗ Branch 6 → 8 not taken.
32890 if (cpu_flags & AV_CPU_FLAG_SLOW_GATHER)
188 32890 return true; /* always prefer over gathers if gathers are slow */
189
190 /**
191 * Otherwise, prefer it above a certain filter size. Empirically, this
192 * kernel seems to be faster whenever the reference/gather kernel crosses
193 * a breakpoint for the number of gathers needed, but this filter doesn't.
194 *
195 * Tested on a Lunar Lake (Intel Core Ultra 7 258V) system.
196 */
197 ✗ const SwsFilterWeights *filter = uop->data.kernel;
198
0/2
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 14 not taken.
✗ return uop->type == SWS_PIXEL_U8 && filter->filter_size > 12 ||
199
0/6
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 10 not taken.
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 12 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 14 not taken.
✗ uop->type == SWS_PIXEL_U16 && filter->filter_size > 4 ||
200
0/4
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 15 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 15 not taken.
✗ uop->type == SWS_PIXEL_F32 && filter->filter_size > 1;
201 }
202
203 32890 static int setup_filter_h_4x4(const SwsImplParams *params, SwsImplResult *out)
204 {
205 32890 const SwsUOp *uop = params->uop;
206 32890 const SwsFilterWeights *filter = uop->data.kernel;
207 32890 const int pixel_size = ff_sws_pixel_type_size(uop->type);
208 32890 const int sizeof_weights = hscale_sizeof_weight(uop);
209 32890 const int block_size = params->table->block_size;
210 32890 const int taps_align = 16 / sizeof_weights; /* taps per iteration (XMM) */
211 32890 const int pixels_align = 4; /* pixels per iteration */
212 32890 const int filter_size = filter->filter_size;
213 32890 const size_t aligned_size = FFALIGN(filter_size, taps_align);
214 32890 const int line_size = FFALIGN(filter->dst_size, block_size);
215 av_assert1(FFALIGN(line_size, pixels_align) == line_size);
216
217 union {
218 void *ptr;
219 int16_t *i16;
220 float *f32;
221 } weights;
222
223 32890 weights.ptr = ff_refstruct_calloc(line_size, aligned_size * sizeof_weights);
224
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 32890 times.
32890 if (!weights.ptr)
225 ✗ return AVERROR(ENOMEM);
226
227 /**
228 * Desired memory layout: [w][taps][pixels_align][taps_align]
229 *
230 * Example with taps_align=8, pixels_align=4:
231 * [a0, a1, ... a7] weights for pixel 0, taps 0..7
232 * [b0, b1, ... b7] weights for pixel 1, taps 0..7
233 * [c0, c1, ... c7] weights for pixel 2, taps 0..7
234 * [d0, d1, ... d7] weights for pixel 3, taps 0..7
235 * [a8, a9, ... a15] weights for pixel 0, taps 8..15
236 * ...
237 * repeat for all taps, then move on to pixels 4..7, etc.
238 */
239
2/2
✓ Branch 15 → 7 taken 3157792 times.
✓ Branch 15 → 16 taken 32890 times.
3190682 for (int x = 0; x < filter->dst_size; x++) {
240
2/2
✓ Branch 13 → 8 taken 11064480 times.
✓ Branch 13 → 14 taken 3157792 times.
14222272 for (int j = 0; j < filter_size; j++) {
241 11064480 const int xb = x & ~(pixels_align - 1);
242 11064480 const int jb = j & ~(taps_align - 1);
243 11064480 const int xi = x - xb, ji = j - jb;
244 11064480 const int w = filter->weights[x * filter_size + j];
245 11064480 const int idx = xb * aligned_size + jb * pixels_align + xi * taps_align + ji;
246
247
3/4
✓ Branch 8 → 9 taken 3576128 times.
✓ Branch 8 → 10 taken 6648544 times.
✓ Branch 8 → 11 taken 839808 times.
✗ Branch 8 → 12 not taken.
11064480 switch (uop->type) {
248 3576128 case SWS_PIXEL_U8: weights.i16[idx] = w; break;
249 6648544 case SWS_PIXEL_U16: weights.i16[idx] = w; break;
250 839808 case SWS_PIXEL_F32: weights.f32[idx] = w; break;
251 }
252 }
253 }
254
255 32890 const FilterPriv priv = {
256 32890 .weights = weights.ptr,
257 32890 .filter_size = aligned_size * sizeof_weights,
258 };
259
260 32890 SWS_OP_PRIV_PACK(out, priv);
261 32890 out->ref = priv.weights;
262
263
2/2
✓ Branch 21 → 18 taken 131560 times.
✓ Branch 21 → 22 taken 32890 times.
164450 for (int i = 0; i < 4; i++) {
264
2/2
✓ Branch 18 → 19 taken 90201 times.
✓ Branch 18 → 20 taken 41359 times.
131560 if (uop->mask & SWS_COMP(i))
265 90201 out->over_read[i] = (aligned_size - filter_size) * pixel_size;
266 }
267 32890 return 0;
268 }
269
270 69944 static int setup_scale(const SwsImplParams *params, SwsImplResult *out)
271 {
272 69944 const SwsPixel scalar = params->uop->data.scalar;
273
4/5
✓ Branch 2 → 3 taken 646 times.
✓ Branch 2 → 6 taken 1515 times.
✓ Branch 2 → 7 taken 265 times.
✓ Branch 2 → 8 taken 67518 times.
✗ Branch 2 → 9 not taken.
69944 switch (params->uop->type) {
274 646 case SWS_PIXEL_U8: {
275 646 const uint32_t u32 = scalar.u8; /* for movd */
276 646 SWS_OP_PRIV_PACK(out, u32);
277 646 break;
278 }
279 1515 case SWS_PIXEL_U16: SWS_OP_PRIV_PACK(out, scalar.u16); break;
280 265 case SWS_PIXEL_U32: SWS_OP_PRIV_PACK(out, scalar.u32); break;
281 67518 case SWS_PIXEL_F32: SWS_OP_PRIV_PACK(out, scalar.f32); break;
282 ✗ default: return AVERROR(EINVAL);
283 }
284
285 69944 return 0;
286 }
287
288 46834 static int setup_clear(const SwsImplParams *params, SwsImplResult *out)
289 {
290 46834 const SwsUOp *uop = params->uop;
291
2/2
✓ Branch 5 → 3 taken 187336 times.
✓ Branch 5 → 6 taken 46834 times.
234170 for (int i = 0; i < 4; i++)
292 187336 SWS_OP_PRIV_PACK(out, uop->data.vec4[i].u32);
293 46834 return 0;
294 }
295
296 137040 static int setup_dither(const SwsImplParams *params, SwsImplResult *out)
297 {
298 137040 ff_sws_op_priv_pack_refptr(out, av_refstruct_ref(params->uop->data.ptr));
299 137040 return 0;
300 }
301
302 105960 static void splat_lane(void *dst, SwsPixelType type, SwsPixel px)
303 {
304
2/4
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 98500 times.
✓ Branch 2 → 8 taken 7460 times.
✗ Branch 2 → 12 not taken.
105960 switch (ff_sws_pixel_type_size(type)) {
305 ✗ case 1:
306 ✗ memset(dst, px.u8, 16);
307 ✗ break;
308 98500 case 2:
309
2/2
✓ Branch 6 → 5 taken 788000 times.
✓ Branch 6 → 7 taken 98500 times.
886500 for (int i = 0; i < 8; i++)
310 788000 ((uint16_t *) dst)[i] = px.u16;
311 98500 break;
312 7460 case 4:
313
2/2
✓ Branch 10 → 9 taken 29840 times.
✓ Branch 10 → 11 taken 7460 times.
37300 for (int i = 0; i < 4; i++)
314 29840 ((uint32_t *) dst)[i] = px.u32;
315 7460 break;
316 }
317 105960 }
318
319 165632 static int setup_linear(const SwsImplParams *params, SwsImplResult *out)
320 {
321 165632 const SwsUOp *uop = params->uop;
322
2/2
✓ Branch 2 → 3 taken 160334 times.
✓ Branch 2 → 5 taken 5298 times.
165632 if (uop->type == SWS_PIXEL_F32) {
323 /* Layout hard-coded in ops_float.asm */
324 static_assert(sizeof(uop->data.mat4x5) == 4 * 5 * sizeof(float),
325 "mat4x5 layout mismatch");
326 160334 SWS_OP_PRIV_PACK(out, uop->data.mat4x5);
327 160334 return 0;
328 }
329
330 5298 uint8_t *mat = av_refstruct_allocz(4 * 5 * 16); /* one lane per component */
331
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 5298 times.
5298 if (!mat)
332 ✗ return AVERROR(ENOMEM);
333 5298 ff_sws_op_priv_pack_refptr(out, mat);
334
335
2/2
✓ Branch 17 → 10 taken 21192 times.
✓ Branch 17 → 18 taken 5298 times.
26490 for (int i = 0; i < 4; i++) {
336
2/2
✓ Branch 15 → 11 taken 105960 times.
✓ Branch 15 → 16 taken 21192 times.
127152 for (int j = 0; j < 5; j++) {
337 105960 SwsPixel px = uop->data.mat4x5[i][j];
338 105960 SwsPixelType type = uop->type;
339
2/2
✓ Branch 11 → 12 taken 33080 times.
✓ Branch 11 → 13 taken 72880 times.
105960 if (type == SWS_PIXEL_U8) {
340 33080 type = SWS_PIXEL_U16; /* for pmullw */
341 33080 px.u16 = (px.u8 << 8) | px.u8;
342 }
343
344 105960 splat_lane(mat, type, px);
345 105960 mat += 16;
346 }
347 }
348 5298 return 0;
349 }
350
351 2319220 static bool uop_is_type_invariant(const SwsUOpType uop)
352 {
353
2/2
✓ Branch 2 → 3 taken 517033 times.
✓ Branch 2 → 4 taken 1802187 times.
2319220 switch (uop) {
354 517033 case SWS_UOP_READ_PLANAR:
355 case SWS_UOP_WRITE_PLANAR:
356 case SWS_UOP_CLEAR:
357 517033 return true;
358 1802187 default:
359 1802187 return false;
360 }
361 }
362
363 #define REF_ENTRY(EXT, NAME, ...) &uop_##NAME##EXT,
364 #define DECL_ENTRY(EXT, CHECK, SETUP, NAME, ...) \
365 void ff_##NAME##EXT(void); \
366 static const SwsUOpEntry uop_##NAME##EXT = { \
367 .func = (SwsFuncPtr) ff_##NAME##EXT, \
368 .check = CHECK, \
369 .setup = SETUP, \
370 __VA_ARGS__, \
371 };
372
373 /* Define all UOPs except conversion ops and type-invariant ops */
374 #define DECL_OPS_COMMON(EXT, TYPE) \
375 SWS_FOR_STRUCT(TYPE, READ_PACKED, DECL_ENTRY, EXT, NULL, setup_rw_packed) \
376 SWS_FOR_STRUCT(TYPE, READ_NIBBLE, DECL_ENTRY, EXT, NULL, NULL) \
377 SWS_FOR_STRUCT(TYPE, READ_BIT, DECL_ENTRY, EXT, NULL, NULL) \
378 SWS_FOR_STRUCT(TYPE, READ_PALETTE, DECL_ENTRY, EXT, NULL, NULL) \
379 SWS_FOR_STRUCT(TYPE, WRITE_PACKED, DECL_ENTRY, EXT, NULL, setup_rw_packed) \
380 SWS_FOR_STRUCT(TYPE, WRITE_NIBBLE, DECL_ENTRY, EXT, NULL, NULL) \
381 SWS_FOR_STRUCT(TYPE, WRITE_BIT, DECL_ENTRY, EXT, NULL, NULL) \
382 SWS_FOR_STRUCT(TYPE, SWAP_BYTES, DECL_ENTRY, EXT, NULL, NULL) \
383 SWS_FOR_STRUCT(TYPE, EXPAND_BIT, DECL_ENTRY, EXT, NULL, NULL) \
384 SWS_FOR_STRUCT(TYPE, PERMUTE, DECL_ENTRY, EXT, NULL, NULL) \
385 SWS_FOR_STRUCT(TYPE, COPY, DECL_ENTRY, EXT, NULL, NULL) \
386 SWS_FOR_STRUCT(TYPE, SCALE, DECL_ENTRY, EXT, NULL, setup_scale) \
387 SWS_FOR_STRUCT(TYPE, ADD, DECL_ENTRY, EXT, NULL, ff_sws_setup_vec4) \
388 SWS_FOR_STRUCT(TYPE, MIN, DECL_ENTRY, EXT, NULL, ff_sws_setup_vec4) \
389 SWS_FOR_STRUCT(TYPE, MAX, DECL_ENTRY, EXT, NULL, ff_sws_setup_vec4) \
390 SWS_FOR_STRUCT(TYPE, UNPACK, DECL_ENTRY, EXT, NULL, NULL) \
391 SWS_FOR_STRUCT(TYPE, PACK, DECL_ENTRY, EXT, NULL, NULL) \
392 SWS_FOR_STRUCT(TYPE, LSHIFT, DECL_ENTRY, EXT, NULL, NULL) \
393 SWS_FOR_STRUCT(TYPE, RSHIFT, DECL_ENTRY, EXT, NULL, NULL) \
394 SWS_FOR_STRUCT(TYPE, LINEAR, DECL_ENTRY, EXT, NULL, setup_linear) \
395 SWS_FOR_STRUCT(TYPE, LINEAR_FMA, DECL_ENTRY, EXT, NULL, setup_linear) \
396 SWS_FOR_STRUCT(TYPE, DITHER, DECL_ENTRY, EXT, NULL, setup_dither) \
397 /* end of macro */
398
399 #define REF_OPS_COMMON(EXT, TYPE) \
400 SWS_FOR(TYPE, READ_PACKED, REF_ENTRY, EXT) \
401 SWS_FOR(TYPE, READ_NIBBLE, REF_ENTRY, EXT) \
402 SWS_FOR(TYPE, READ_BIT, REF_ENTRY, EXT) \
403 SWS_FOR(TYPE, READ_PALETTE, REF_ENTRY, EXT) \
404 SWS_FOR(TYPE, WRITE_PACKED, REF_ENTRY, EXT) \
405 SWS_FOR(TYPE, WRITE_NIBBLE, REF_ENTRY, EXT) \
406 SWS_FOR(TYPE, WRITE_BIT, REF_ENTRY, EXT) \
407 SWS_FOR(TYPE, SWAP_BYTES, REF_ENTRY, EXT) \
408 SWS_FOR(TYPE, EXPAND_BIT, REF_ENTRY, EXT) \
409 SWS_FOR(TYPE, PERMUTE, REF_ENTRY, EXT) \
410 SWS_FOR(TYPE, COPY, REF_ENTRY, EXT) \
411 SWS_FOR(TYPE, SCALE, REF_ENTRY, EXT) \
412 SWS_FOR(TYPE, ADD, REF_ENTRY, EXT) \
413 SWS_FOR(TYPE, MIN, REF_ENTRY, EXT) \
414 SWS_FOR(TYPE, MAX, REF_ENTRY, EXT) \
415 SWS_FOR(TYPE, UNPACK, REF_ENTRY, EXT) \
416 SWS_FOR(TYPE, PACK, REF_ENTRY, EXT) \
417 SWS_FOR(TYPE, LSHIFT, REF_ENTRY, EXT) \
418 SWS_FOR(TYPE, RSHIFT, REF_ENTRY, EXT) \
419 SWS_FOR(TYPE, LINEAR, REF_ENTRY, EXT) \
420 SWS_FOR(TYPE, LINEAR_FMA, REF_ENTRY, EXT) \
421 SWS_FOR(TYPE, DITHER, REF_ENTRY, EXT) \
422 /* end of macro */
423
424 #define DECL_TABLE_U8(EXT, SIZE, FLAG) \
425 DECL_OPS_COMMON(EXT, U8) \
426 SWS_FOR_STRUCT(U8, READ_PLANAR, DECL_ENTRY, EXT, NULL, NULL) \
427 SWS_FOR_STRUCT(U8, WRITE_PLANAR, DECL_ENTRY, EXT, NULL, NULL) \
428 SWS_FOR_STRUCT(U8, CLEAR, DECL_ENTRY, EXT, NULL, setup_clear) \
429 \
430 static const SwsUOpTable uops_u8##EXT = { \
431 .cpu_flags = AV_CPU_FLAG_##FLAG, \
432 .block_size = SIZE, \
433 .entries = { \
434 REF_OPS_COMMON(EXT, U8) \
435 SWS_FOR(U8, READ_PLANAR, REF_ENTRY, EXT) \
436 SWS_FOR(U8, WRITE_PLANAR, REF_ENTRY, EXT) \
437 SWS_FOR(U8, CLEAR, REF_ENTRY, EXT) \
438 NULL \
439 }, \
440 };
441
442 #define DECL_TABLE_U16(EXT, SIZE, FLAG) \
443 DECL_OPS_COMMON(EXT, U16) \
444 SWS_FOR_STRUCT(U8, TO_U16, DECL_ENTRY, EXT, NULL, NULL) \
445 SWS_FOR_STRUCT(U16, TO_U8, DECL_ENTRY, EXT, NULL, NULL) \
446 SWS_FOR_STRUCT(U8, EXPAND_PAIR, DECL_ENTRY, EXT, NULL, NULL) \
447 \
448 static const SwsUOpTable uops_u16##EXT = { \
449 .cpu_flags = AV_CPU_FLAG_##FLAG, \
450 .block_size = SIZE, \
451 .entries = { \
452 REF_OPS_COMMON(EXT, U16) \
453 SWS_FOR(U8, TO_U16, REF_ENTRY, EXT) \
454 SWS_FOR(U16, TO_U8, REF_ENTRY, EXT) \
455 SWS_FOR(U8, EXPAND_PAIR, REF_ENTRY, EXT) \
456 NULL \
457 }, \
458 };
459
460 #define DECL_TABLE_U32(EXT, SIZE, FLAG) \
461 DECL_OPS_COMMON(EXT, U32) \
462 SWS_FOR_STRUCT(U8, TO_U32, DECL_ENTRY, EXT, NULL, NULL) \
463 SWS_FOR_STRUCT(U32, TO_U8, DECL_ENTRY, EXT, NULL, NULL) \
464 SWS_FOR_STRUCT(U16, TO_U32, DECL_ENTRY, EXT, NULL, NULL) \
465 SWS_FOR_STRUCT(U32, TO_U16, DECL_ENTRY, EXT, NULL, NULL) \
466 SWS_FOR_STRUCT(U8, EXPAND_QUAD, DECL_ENTRY, EXT, NULL, NULL) \
467 \
468 static const SwsUOpTable uops_u32##EXT = { \
469 .cpu_flags = AV_CPU_FLAG_##FLAG, \
470 .block_size = SIZE, \
471 .entries = { \
472 REF_OPS_COMMON(EXT, U32) \
473 SWS_FOR(U8, TO_U32, REF_ENTRY, EXT) \
474 SWS_FOR(U32, TO_U8, REF_ENTRY, EXT) \
475 SWS_FOR(U16, TO_U32, REF_ENTRY, EXT) \
476 SWS_FOR(U32, TO_U16, REF_ENTRY, EXT) \
477 SWS_FOR(U8, EXPAND_QUAD, REF_ENTRY, EXT) \
478 NULL \
479 }, \
480 };
481
482 #define DECL_TABLE_F32(EXT, SIZE, FLAG) \
483 DECL_OPS_COMMON(EXT, F32) \
484 SWS_FOR_STRUCT(U8, TO_F32, DECL_ENTRY, EXT, NULL, NULL) \
485 SWS_FOR_STRUCT(F32, TO_U8, DECL_ENTRY, EXT, NULL, NULL) \
486 SWS_FOR_STRUCT(U16, TO_F32, DECL_ENTRY, EXT, NULL, NULL) \
487 SWS_FOR_STRUCT(F32, TO_U16, DECL_ENTRY, EXT, NULL, NULL) \
488 SWS_FOR_STRUCT(U8, READ_PLANAR_FH, DECL_ENTRY, EXT, NULL, setup_filter_h) \
489 SWS_FOR_STRUCT(U16, READ_PLANAR_FH, DECL_ENTRY, EXT, NULL, setup_filter_h) \
490 SWS_FOR_STRUCT(F32, READ_PLANAR_FH, DECL_ENTRY, EXT, NULL, setup_filter_h) \
491 SWS_FOR_STRUCT(U8, READ_PLANAR_FH, DECL_ENTRY, _4x4##EXT, \
492 check_filter_h_4x4, setup_filter_h_4x4) \
493 SWS_FOR_STRUCT(U16, READ_PLANAR_FH, DECL_ENTRY, _4x4##EXT, \
494 check_filter_h_4x4, setup_filter_h_4x4) \
495 SWS_FOR_STRUCT(F32, READ_PLANAR_FH, DECL_ENTRY, _4x4##EXT, \
496 check_filter_h_4x4, setup_filter_h_4x4) \
497 SWS_FOR_STRUCT(U8, READ_PLANAR_FV, DECL_ENTRY, EXT, NULL, setup_filter_v) \
498 SWS_FOR_STRUCT(U16, READ_PLANAR_FV, DECL_ENTRY, EXT, NULL, setup_filter_v) \
499 SWS_FOR_STRUCT(F32, READ_PLANAR_FV, DECL_ENTRY, EXT, NULL, setup_filter_v) \
500 SWS_FOR_STRUCT(U8, READ_PLANAR_FV_FMA, DECL_ENTRY, EXT, NULL, setup_filter_v) \
501 SWS_FOR_STRUCT(U16, READ_PLANAR_FV_FMA, DECL_ENTRY, EXT, NULL, setup_filter_v) \
502 SWS_FOR_STRUCT(F32, READ_PLANAR_FV_FMA, DECL_ENTRY, EXT, NULL, setup_filter_v) \
503 \
504 static const SwsUOpTable uops_f32##EXT = { \
505 .cpu_flags = AV_CPU_FLAG_##FLAG, \
506 .block_size = SIZE, \
507 .entries = { \
508 REF_OPS_COMMON(EXT, F32) \
509 SWS_FOR(U8, TO_F32, REF_ENTRY, EXT) \
510 SWS_FOR(F32, TO_U8, REF_ENTRY, EXT) \
511 SWS_FOR(U16, TO_F32, REF_ENTRY, EXT) \
512 SWS_FOR(F32, TO_U16, REF_ENTRY, EXT) \
513 SWS_FOR(U8, READ_PLANAR_FH, REF_ENTRY, _4x4##EXT) \
514 SWS_FOR(U16, READ_PLANAR_FH, REF_ENTRY, _4x4##EXT) \
515 SWS_FOR(F32, READ_PLANAR_FH, REF_ENTRY, _4x4##EXT) \
516 SWS_FOR(U8, READ_PLANAR_FH, REF_ENTRY, EXT) \
517 SWS_FOR(U16, READ_PLANAR_FH, REF_ENTRY, EXT) \
518 SWS_FOR(F32, READ_PLANAR_FH, REF_ENTRY, EXT) \
519 SWS_FOR(U8, READ_PLANAR_FV, REF_ENTRY, EXT) \
520 SWS_FOR(U16, READ_PLANAR_FV, REF_ENTRY, EXT) \
521 SWS_FOR(F32, READ_PLANAR_FV, REF_ENTRY, EXT) \
522 SWS_FOR(U8, READ_PLANAR_FV_FMA, REF_ENTRY, EXT) \
523 SWS_FOR(U16, READ_PLANAR_FV_FMA, REF_ENTRY, EXT) \
524 SWS_FOR(F32, READ_PLANAR_FV_FMA, REF_ENTRY, EXT) \
525 NULL \
526 }, \
527 };
528
529 DECL_TABLE_U8( _m1_sse4, 16, SSE4)
530 DECL_TABLE_U8( _m1_avx2, 32, AVX2)
531 DECL_TABLE_U8( _m2_sse4, 32, SSE4)
532 DECL_TABLE_U8( _m2_avx2, 64, AVX2)
533 DECL_TABLE_U16(_m1_avx2, 16, AVX2)
534 DECL_TABLE_U16(_m2_avx2, 32, AVX2)
535 DECL_TABLE_U32(_m2_avx2, 16, AVX2)
536 DECL_TABLE_F32(_m2_avx2, 16, AVX2)
537
538 static const SwsUOpTable *const tables[] = {
539 &uops_u8_m1_sse4,
540 &uops_u8_m1_avx2, /* order before _m2_sse4 */
541 &uops_u8_m2_sse4,
542 &uops_u8_m2_avx2,
543 &uops_u16_m1_avx2,
544 &uops_u16_m2_avx2,
545 &uops_u32_m2_avx2,
546 &uops_f32_m2_avx2,
547 };
548
549 SWS_DECL_FUNC(ff_sws_process1_x86);
550 SWS_DECL_FUNC(ff_sws_process2_x86);
551 SWS_DECL_FUNC(ff_sws_process3_x86);
552 SWS_DECL_FUNC(ff_sws_process4_x86);
553
554 /* Declare packed shuffle functions */
555 SWS_FOR_STRUCT(U8, RW_SHUFFLE, DECL_ENTRY, _sse4, NULL, NULL)
556 SWS_FOR_STRUCT(U8, RW_SHUFFLE, DECL_ENTRY, _avx2, NULL, NULL)
557 SWS_FOR_STRUCT(U8, RW_SHUFFLE, DECL_ENTRY, _avx512, NULL, NULL)
558 SWS_FOR_STRUCT(U8, RW_SHUFFLE, DECL_ENTRY, _avx512icl, NULL, NULL)
559
560 871570 static int get_mmsize(void)
561 {
562 871570 const int cpu_flags = av_get_cpu_flags();
563
2/2
✓ Branch 3 → 4 taken 281824 times.
✓ Branch 3 → 5 taken 589746 times.
871570 if (EXTERNAL_AVX512(cpu_flags))
564 281824 return 64;
565
2/2
✓ Branch 5 → 6 taken 440358 times.
✓ Branch 5 → 7 taken 149388 times.
589746 else if (EXTERNAL_AVX2(cpu_flags))
566 440358 return 32;
567
2/2
✓ Branch 7 → 8 taken 144824 times.
✓ Branch 7 → 9 taken 4564 times.
149388 else if (EXTERNAL_SSE4(cpu_flags))
568 144824 return 16;
569 else
570 4564 return AVERROR(ENOTSUP);
571 }
572
573 23156 static int movsize(const int bytes, const int mmsize)
574 {
575
2/2
✓ Branch 2 → 3 taken 22122 times.
✓ Branch 2 → 10 taken 1034 times.
45278 return bytes <= 4 ? 4 : /* movd */
576
2/2
✓ Branch 3 → 4 taken 19062 times.
✓ Branch 3 → 9 taken 3060 times.
22122 bytes <= 8 ? 8 : /* movq */
577
2/2
✓ Branch 4 → 5 taken 11374 times.
✓ Branch 4 → 8 taken 7688 times.
19062 bytes <= 16 ? 16 : /* xmm movu */
578
2/2
✓ Branch 5 → 6 taken 3648 times.
✓ Branch 5 → 7 taken 7726 times.
11374 bytes <= 32 ? 32 : /* ymm movu */
579 mmsize; /* zmm movu */
580 }
581
582 11578 static int translate_shuffle(const SwsUOp *uop, int mmsize, SwsCompiledOp *out)
583 {
584 /* We can't shuffle across lanes, so restrict the vector size to XMM
585 * whenever the read/write size would be a subset of the full vector,
586 * unless we have access to AVX-512 ICL vpermb */
587 11578 const SwsShuffleUOp *par = &uop->par.shuffle;
588
2/2
✓ Branch 2 → 3 taken 5410 times.
✓ Branch 2 → 5 taken 6168 times.
16988 const int lane_aligned = par->read_size == par->write_size &&
589
2/2
✓ Branch 3 → 4 taken 5135 times.
✓ Branch 3 → 5 taken 275 times.
5410 16 % par->read_size == 0;
590
4/4
✓ Branch 6 → 7 taken 6443 times.
✓ Branch 6 → 10 taken 5135 times.
✓ Branch 8 → 9 taken 5331 times.
✓ Branch 8 → 10 taken 1112 times.
11578 if (!lane_aligned && !EXTERNAL_AVX512ICL(av_get_cpu_flags()))
591 5331 mmsize = 16;
592
593 /* Generate the shuffle mask */
594
2/2
✓ Branch 10 → 11 taken 6443 times.
✓ Branch 10 → 12 taken 5135 times.
11578 const int mask_size = lane_aligned ? 16 : mmsize;
595 11578 int8_t *mask = av_malloc(mask_size);
596
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 11578 times.
11578 if (!mask)
597 ✗ return AVERROR(ENOMEM);
598
599 11578 const int groups = ff_sws_shuffle_mask(uop, mask, mask_size);
600
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 20 taken 11578 times.
11578 if (groups < 0) {
601 ✗ av_free(mask);
602 ✗ return groups;
603 }
604
605 11578 const int read_chunk = groups * par->read_size;
606 11578 const int write_chunk = groups * par->write_size;
607
2/2
✓ Branch 20 → 21 taken 5135 times.
✓ Branch 20 → 22 taken 6443 times.
11578 const int num_lanes = lane_aligned ? mmsize / 16 : 1;
608 11578 const int in_total = num_lanes * read_chunk;
609 11578 const int out_total = num_lanes * write_chunk;
610 11578 *out = (SwsCompiledOp) {
611 .priv = mask,
612 .free = av_free,
613 .slice_align = 1,
614 11578 .block_size = groups * uop->data.shuffle.pixels * num_lanes,
615 11578 .over_read = { movsize(in_total, mmsize) - in_total },
616 11578 .over_write = { movsize(out_total, mmsize) - out_total },
617 };
618
619 #define ASSIGN_SHUFFLE_FUNC(CPU, EXT, NAME, ...) \
620 do { \
621 const SwsUOpEntry *entry = &uop_##NAME##EXT; \
622 if (!memcmp(&uop->par, &entry->par, sizeof(uop->par))) { \
623 out->func = (SwsOpFunc) entry->func; \
624 out->cpu_flags = AV_CPU_FLAG_##CPU; \
625 } \
626 } while (0);
627
628
3/4
✓ Branch 25 → 26 taken 5827 times.
✓ Branch 25 → 71 taken 3647 times.
✓ Branch 25 → 116 taken 2104 times.
✗ Branch 25 → 206 not taken.
11578 switch (mmsize) {
629
44/44
✓ Branch 26 → 27 taken 53 times.
✓ Branch 26 → 28 taken 5774 times.
✓ Branch 28 → 29 taken 215 times.
✓ Branch 28 → 30 taken 5612 times.
✓ Branch 30 → 31 taken 107 times.
✓ Branch 30 → 32 taken 5720 times.
✓ Branch 32 → 33 taken 32 times.
✓ Branch 32 → 34 taken 5795 times.
✓ Branch 34 → 35 taken 104 times.
✓ Branch 34 → 36 taken 5723 times.
✓ Branch 36 → 37 taken 583 times.
✓ Branch 36 → 38 taken 5244 times.
✓ Branch 38 → 39 taken 572 times.
✓ Branch 38 → 40 taken 5255 times.
✓ Branch 40 → 41 taken 26 times.
✓ Branch 40 → 42 taken 5801 times.
✓ Branch 42 → 43 taken 185 times.
✓ Branch 42 → 44 taken 5642 times.
✓ Branch 44 → 45 taken 121 times.
✓ Branch 44 → 46 taken 5706 times.
✓ Branch 46 → 47 taken 59 times.
✓ Branch 46 → 48 taken 5768 times.
✓ Branch 48 → 49 taken 26 times.
✓ Branch 48 → 50 taken 5801 times.
✓ Branch 50 → 51 taken 392 times.
✓ Branch 50 → 52 taken 5435 times.
✓ Branch 52 → 53 taken 1295 times.
✓ Branch 52 → 54 taken 4532 times.
✓ Branch 54 → 55 taken 534 times.
✓ Branch 54 → 56 taken 5293 times.
✓ Branch 56 → 57 taken 404 times.
✓ Branch 56 → 58 taken 5423 times.
✓ Branch 58 → 59 taken 55 times.
✓ Branch 58 → 60 taken 5772 times.
✓ Branch 60 → 61 taken 212 times.
✓ Branch 60 → 62 taken 5615 times.
✓ Branch 62 → 63 taken 110 times.
✓ Branch 62 → 64 taken 5717 times.
✓ Branch 64 → 65 taken 289 times.
✓ Branch 64 → 66 taken 5538 times.
✓ Branch 66 → 67 taken 361 times.
✓ Branch 66 → 68 taken 5466 times.
✓ Branch 68 → 69 taken 92 times.
✓ Branch 68 → 70 taken 5735 times.
5827 case 16: SWS_FOR(U8, RW_SHUFFLE, ASSIGN_SHUFFLE_FUNC, SSE4, _sse4); break;
630
24/44
✗ Branch 71 → 72 not taken.
✓ Branch 71 → 73 taken 3647 times.
✗ Branch 73 → 74 not taken.
✓ Branch 73 → 75 taken 3647 times.
✗ Branch 75 → 76 not taken.
✓ Branch 75 → 77 taken 3647 times.
✗ Branch 77 → 78 not taken.
✓ Branch 77 → 79 taken 3647 times.
✗ Branch 79 → 80 not taken.
✓ Branch 79 → 81 taken 3647 times.
✗ Branch 81 → 82 not taken.
✓ Branch 81 → 83 taken 3647 times.
✗ Branch 83 → 84 not taken.
✓ Branch 83 → 85 taken 3647 times.
✗ Branch 85 → 86 not taken.
✓ Branch 85 → 87 taken 3647 times.
✗ Branch 87 → 88 not taken.
✓ Branch 87 → 89 taken 3647 times.
✗ Branch 89 → 90 not taken.
✓ Branch 89 → 91 taken 3647 times.
✗ Branch 91 → 92 not taken.
✓ Branch 91 → 93 taken 3647 times.
✗ Branch 93 → 94 not taken.
✓ Branch 93 → 95 taken 3647 times.
✗ Branch 95 → 96 not taken.
✓ Branch 95 → 97 taken 3647 times.
✗ Branch 97 → 98 not taken.
✓ Branch 97 → 99 taken 3647 times.
✗ Branch 99 → 100 not taken.
✓ Branch 99 → 101 taken 3647 times.
✓ Branch 101 → 102 taken 3525 times.
✓ Branch 101 → 103 taken 122 times.
✗ Branch 103 → 104 not taken.
✓ Branch 103 → 105 taken 3647 times.
✗ Branch 105 → 106 not taken.
✓ Branch 105 → 107 taken 3647 times.
✗ Branch 107 → 108 not taken.
✓ Branch 107 → 109 taken 3647 times.
✗ Branch 109 → 110 not taken.
✓ Branch 109 → 111 taken 3647 times.
✗ Branch 111 → 112 not taken.
✓ Branch 111 → 113 taken 3647 times.
✓ Branch 113 → 114 taken 122 times.
✓ Branch 113 → 115 taken 3525 times.
3647 case 32: SWS_FOR(U8, RW_SHUFFLE, ASSIGN_SHUFFLE_FUNC, AVX2, _avx2); break;
631 2104 case 64:
632
2/2
✓ Branch 116 → 117 taken 992 times.
✓ Branch 116 → 161 taken 1112 times.
2104 if (lane_aligned) {
633
24/44
✗ Branch 117 → 118 not taken.
✓ Branch 117 → 119 taken 992 times.
✗ Branch 119 → 120 not taken.
✓ Branch 119 → 121 taken 992 times.
✗ Branch 121 → 122 not taken.
✓ Branch 121 → 123 taken 992 times.
✗ Branch 123 → 124 not taken.
✓ Branch 123 → 125 taken 992 times.
✗ Branch 125 → 126 not taken.
✓ Branch 125 → 127 taken 992 times.
✗ Branch 127 → 128 not taken.
✓ Branch 127 → 129 taken 992 times.
✗ Branch 129 → 130 not taken.
✓ Branch 129 → 131 taken 992 times.
✗ Branch 131 → 132 not taken.
✓ Branch 131 → 133 taken 992 times.
✗ Branch 133 → 134 not taken.
✓ Branch 133 → 135 taken 992 times.
✗ Branch 135 → 136 not taken.
✓ Branch 135 → 137 taken 992 times.
✗ Branch 137 → 138 not taken.
✓ Branch 137 → 139 taken 992 times.
✗ Branch 139 → 140 not taken.
✓ Branch 139 → 141 taken 992 times.
✗ Branch 141 → 142 not taken.
✓ Branch 141 → 143 taken 992 times.
✗ Branch 143 → 144 not taken.
✓ Branch 143 → 145 taken 992 times.
✗ Branch 145 → 146 not taken.
✓ Branch 145 → 147 taken 992 times.
✓ Branch 147 → 148 taken 808 times.
✓ Branch 147 → 149 taken 184 times.
✗ Branch 149 → 150 not taken.
✓ Branch 149 → 151 taken 992 times.
✗ Branch 151 → 152 not taken.
✓ Branch 151 → 153 taken 992 times.
✗ Branch 153 → 154 not taken.
✓ Branch 153 → 155 taken 992 times.
✗ Branch 155 → 156 not taken.
✓ Branch 155 → 157 taken 992 times.
✗ Branch 157 → 158 not taken.
✓ Branch 157 → 159 taken 992 times.
✓ Branch 159 → 160 taken 184 times.
✓ Branch 159 → 205 taken 808 times.
992 SWS_FOR(U8, RW_SHUFFLE, ASSIGN_SHUFFLE_FUNC, AVX512, _avx512);
634 } else { /* vpermb variant */
635
40/44
✓ Branch 161 → 162 taken 16 times.
✓ Branch 161 → 163 taken 1096 times.
✓ Branch 163 → 164 taken 64 times.
✓ Branch 163 → 165 taken 1048 times.
✓ Branch 165 → 166 taken 32 times.
✓ Branch 165 → 167 taken 1080 times.
✓ Branch 167 → 168 taken 8 times.
✓ Branch 167 → 169 taken 1104 times.
✓ Branch 169 → 170 taken 32 times.
✓ Branch 169 → 171 taken 1080 times.
✓ Branch 171 → 172 taken 176 times.
✓ Branch 171 → 173 taken 936 times.
✓ Branch 173 → 174 taken 168 times.
✓ Branch 173 → 175 taken 944 times.
✓ Branch 175 → 176 taken 8 times.
✓ Branch 175 → 177 taken 1104 times.
✓ Branch 177 → 178 taken 56 times.
✓ Branch 177 → 179 taken 1056 times.
✓ Branch 179 → 180 taken 36 times.
✓ Branch 179 → 181 taken 1076 times.
✗ Branch 181 → 182 not taken.
✓ Branch 181 → 183 taken 1112 times.
✓ Branch 183 → 184 taken 8 times.
✓ Branch 183 → 185 taken 1104 times.
✗ Branch 185 → 186 not taken.
✓ Branch 185 → 187 taken 1112 times.
✓ Branch 187 → 188 taken 40 times.
✓ Branch 187 → 189 taken 1072 times.
✓ Branch 189 → 190 taken 160 times.
✓ Branch 189 → 191 taken 952 times.
✗ Branch 191 → 192 not taken.
✓ Branch 191 → 193 taken 1112 times.
✓ Branch 193 → 194 taken 16 times.
✓ Branch 193 → 195 taken 1096 times.
✓ Branch 195 → 196 taken 64 times.
✓ Branch 195 → 197 taken 1048 times.
✓ Branch 197 → 198 taken 32 times.
✓ Branch 197 → 199 taken 1080 times.
✓ Branch 199 → 200 taken 88 times.
✓ Branch 199 → 201 taken 1024 times.
✓ Branch 201 → 202 taken 108 times.
✓ Branch 201 → 203 taken 1004 times.
✗ Branch 203 → 204 not taken.
✓ Branch 203 → 205 taken 1112 times.
1112 SWS_FOR(U8, RW_SHUFFLE, ASSIGN_SHUFFLE_FUNC, AVX512ICL, _avx512icl);
636 }
637 2104 break;
638 }
639
640
1/2
✗ Branch 206 → 207 not taken.
✓ Branch 206 → 209 taken 11578 times.
11578 if (!out->func) {
641 ✗ av_free(mask);
642 ✗ return AVERROR(ENOTSUP);
643 }
644
645 11578 return 0;
646 }
647
648 440349 static int compile_uops_x86(SwsContext *ctx, const SwsUOpList *uops, SwsCompiledOp *out)
649 {
650 440349 int ret, mmsize = get_mmsize();
651
2/2
✓ Branch 3 → 4 taken 4564 times.
✓ Branch 3 → 5 taken 435785 times.
440349 if (mmsize < 0)
652 4564 return mmsize;
653
654
3/4
✓ Branch 5 → 6 taken 11578 times.
✓ Branch 5 → 13 taken 424207 times.
✓ Branch 6 → 7 taken 11578 times.
✗ Branch 6 → 13 not taken.
435785 if (uops->num_ops == 1 && uops->ops[0].uop == SWS_UOP_RW_SHUFFLE) {
655 11578 const SwsUOp *uop = &uops->ops[0];
656 11578 ret = translate_shuffle(uop, mmsize, out);
657
1/2
✓ Branch 8 → 9 taken 11578 times.
✗ Branch 8 → 12 not taken.
11578 if (ret >= 0) {
658 char name[SWS_UOP_NAME_MAX];
659 11578 ff_sws_uop_name(uop, name);
660 11578 av_log(ctx, AV_LOG_VERBOSE, "Using x86 packed shuffle fast path: %s\n", name);
661 }
662 11578 return ret;
663 }
664
665 424207 SwsOpChain *chain = ff_sws_op_chain_alloc();
666
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 424207 times.
424207 if (!chain)
667 ✗ return AVERROR(ENOMEM);
668
669 424207 *out = (SwsCompiledOp) {
670 /* Use at most two full YMM regs during the widest precision section */
671 424207 .block_size = 2 * FFMIN(mmsize, 32) / uops->pixel_size_max,
672 .slice_align = 1,
673 };
674
675
2/2
✓ Branch 24 → 17 taken 2319220 times.
✓ Branch 24 → 25 taken 299269 times.
2618489 for (int i = 0; i < uops->num_ops; i++) {
676 2319220 SwsUOp *uop = &uops->ops[i];
677 2319220 int op_block_size = out->block_size;
678
679
2/2
✓ Branch 18 → 19 taken 517033 times.
✓ Branch 18 → 20 taken 1802187 times.
2319220 if (uop_is_type_invariant(uop->uop)) {
680 517033 op_block_size *= ff_sws_pixel_type_size(uop->type);
681 517033 uop->type = SWS_PIXEL_U8;
682 }
683
684 2319220 ret = ff_sws_uop_lookup(ctx, tables, FF_ARRAY_ELEMS(tables), uop,
685 op_block_size, chain);
686
2/2
✓ Branch 21 → 22 taken 124938 times.
✓ Branch 21 → 23 taken 2194282 times.
2319220 if (ret < 0)
687 124938 goto fail;
688 }
689
690
4/5
✓ Branch 25 → 26 taken 83504 times.
✓ Branch 25 → 27 taken 12166 times.
✓ Branch 25 → 28 taken 174292 times.
✓ Branch 25 → 29 taken 29307 times.
✗ Branch 25 → 30 not taken.
299269 switch (av_popcount(uops->planes_in | uops->planes_out)) {
691 83504 case 1: out->func = ff_sws_process1_x86; break;
692 12166 case 2: out->func = ff_sws_process2_x86; break;
693 174292 case 3: out->func = ff_sws_process3_x86; break;
694 29307 case 4: out->func = ff_sws_process4_x86; break;
695 }
696
697 299269 ff_sws_uop_list_print(ctx, AV_LOG_DEBUG, uops);
698 299269 ff_sws_op_chain_attach(chain, out);
699 299269 return 0;
700
701 124938 fail:
702 124938 ff_sws_op_chain_free(chain);
703 124938 return ret;
704 }
705
706 431221 static int compile_ops_x86(SwsContext *ctx, const SwsOpList *ops, SwsCompiledOp *out)
707 {
708 431221 const int cpu_flags = av_get_cpu_flags();
709 431221 const int mmsize = get_mmsize();
710
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 431221 times.
431221 if (mmsize < 0)
711 ✗ return mmsize;
712
713 431221 SwsUOpFlags flags = SWS_UOP_FLAG_PSHUFB
714 | SWS_UOP_FLAG_EXPAND_BIT
715 | SWS_UOP_FLAG_READ_PALETTE
716 | SWS_UOP_FLAG_ADD
717 | SWS_UOP_FLAG_PUNNING;
718
2/2
✓ Branch 6 → 7 taken 360765 times.
✓ Branch 6 → 8 taken 70456 times.
431221 if (EXTERNAL_FMA3(cpu_flags))
719 360765 flags |= SWS_UOP_FLAG_FMA;
720
721 431221 SwsUOpList *uops = ff_sws_uop_list_alloc();
722
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 431221 times.
431221 if (!uops)
723 ✗ return AVERROR(ENOMEM);
724
725 431221 int ret = ff_sws_ops_translate(ctx, ops, flags, uops);
726
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 431221 times.
431221 if (ret < 0)
727 ✗ goto fail;
728
729 431221 ret = compile_uops_x86(ctx, uops, out);
730
731 431221 fail:
732 431221 ff_sws_uop_list_free(&uops);
733 431221 return ret;
734 }
735
736 const SwsOpBackend backend_x86 = {
737 .name = "x86",
738 .flags = SWS_BACKEND_X86,
739 .compile = compile_ops_x86,
740 .compile_uops = compile_uops_x86,
741 .hw_format = AV_PIX_FMT_NONE,
742 };
743