FFmpeg
Loading...
Searching...
No Matches
swscale_vsx.c
Go to the documentation of this file.
1/*
2 * AltiVec-enhanced yuv2yuvX
3 *
4 * Copyright (C) 2004 Romain Dolbeau <romain@dolbeau.org>
5 * based on the equivalent C code in swscale.c
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 <inttypes.h>
25
26#include "config.h"
27#include "libswscale/swscale.h"
30#include "libavutil/cpu.h"
32#include "yuv2rgb_altivec.h"
34
35#define vzero vec_splat_s32(0)
36
37#if !HAVE_BIGENDIAN
38#define GET_LS(a,b,c,s) {\
39 ls = a;\
40 a = vec_vsx_ld(((b) << 1) + 16, s);\
41 }
42
43#define yuv2planeX_8(d1, d2, l1, src, x, perm, filter) do {\
44 vector signed short ls;\
45 vector signed int vf1, vf2, i1, i2;\
46 GET_LS(l1, x, perm, src);\
47 i1 = vec_mule(filter, ls);\
48 i2 = vec_mulo(filter, ls);\
49 vf1 = vec_mergeh(i1, i2);\
50 vf2 = vec_mergel(i1, i2);\
51 d1 = vec_add(d1, vf1);\
52 d2 = vec_add(d2, vf2);\
53 } while (0)
54
55#define LOAD_FILTER(vf,f) {\
56 vf = vec_splats(f[j]);\
57}
58#define LOAD_L1(ll1,s,p){\
59 ll1 = vec_vsx_ld(xoffset, s);\
60}
61
62// The 3 above is 2 (filterSize == 4) + 1 (sizeof(short) == 2).
63
64// The neat trick: We only care for half the elements,
65// high or low depending on (i<<3)%16 (it's 0 or 8 here),
66// and we're going to use vec_mule, so we choose
67// carefully how to "unpack" the elements into the even slots.
68#define GET_VF4(a, vf, f) {\
69 vf = (vector signed short)vec_vsx_ld(a << 3, f);\
70 vf = vec_mergeh(vf, (vector signed short)vzero);\
71}
72#define FIRST_LOAD(sv, pos, s, per) {}
73#define UPDATE_PTR(s0, d0, s1, d1) {}
74#define LOAD_SRCV(pos, a, s, per, v0, v1, vf) {\
75 vf = vec_vsx_ld(pos + a, s);\
76}
77#define LOAD_SRCV8(pos, a, s, per, v0, v1, vf) LOAD_SRCV(pos, a, s, per, v0, v1, vf)
78#define GET_VFD(a, b, f, vf0, vf1, per, vf, off) {\
79 vf = vec_vsx_ld((a * 2 * filterSize) + (b * 2) + off, f);\
80}
81
82#define FUNC(name) name ## _vsx
84#undef FUNC
85
86#undef vzero
87
88#endif /* !HAVE_BIGENDIAN */
89
90static void yuv2plane1_8_u(const int16_t *src, uint8_t *dest, int dstW,
91 const uint8_t *dither, int offset, int start)
92{
93 int i;
94 for (i = start; i < dstW; i++) {
95 int val = (src[i] + dither[(i + offset) & 7]) >> 7;
96 dest[i] = av_clip_uint8(val);
97 }
98}
99
100static void yuv2plane1_8_vsx(const int16_t *src, uint8_t *dest, int dstW,
101 const uint8_t *dither, int offset)
102{
103 const int dst_u = -(uintptr_t)dest & 15;
104 int i, j;
105 LOCAL_ALIGNED(16, int16_t, val, [16]);
106 const vec_u16 shifts = (vec_u16) {7, 7, 7, 7, 7, 7, 7, 7};
107 vec_s16 vi, vileft, ditherleft, ditherright;
108 vec_u8 vd;
109
110 for (j = 0; j < 16; j++) {
111 val[j] = dither[(dst_u + offset + j) & 7];
112 }
113
114 ditherleft = vec_ld(0, val);
115 ditherright = vec_ld(0, &val[8]);
116
117 yuv2plane1_8_u(src, dest, dst_u, dither, offset, 0);
118
119 for (i = dst_u; i < dstW - 15; i += 16) {
120
121 vi = vec_vsx_ld(0, &src[i]);
122 vi = vec_adds(ditherleft, vi);
123 vileft = vec_sra(vi, shifts);
124
125 vi = vec_vsx_ld(0, &src[i + 8]);
126 vi = vec_adds(ditherright, vi);
127 vi = vec_sra(vi, shifts);
128
129 vd = vec_packsu(vileft, vi);
130 vec_st(vd, 0, &dest[i]);
131 }
132
133 yuv2plane1_8_u(src, dest, dstW, dither, offset, i);
134}
135
136#if !HAVE_BIGENDIAN
137
138#define output_pixel(pos, val) \
139 if (big_endian) { \
140 AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
141 } else { \
142 AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
143 }
144
145static void yuv2plane1_nbps_u(const int16_t *src, uint16_t *dest, int dstW,
146 int big_endian, int output_bits, int start)
147{
148 int i;
149 int shift = 15 - output_bits;
150
151 for (i = start; i < dstW; i++) {
152 int val = src[i] + (1 << (shift - 1));
153 output_pixel(&dest[i], val);
154 }
155}
156
157static av_always_inline void yuv2plane1_nbps_vsx(const int16_t *src,
158 uint16_t *dest, int dstW,
159 const int big_endian,
160 const int output_bits)
161{
162 const int dst_u = -(uintptr_t)dest & 7;
163 const int shift = 15 - output_bits;
164 const int add = (1 << (shift - 1));
165 const int clip = (1 << output_bits) - 1;
166 const vec_u16 vadd = (vec_u16) {add, add, add, add, add, add, add, add};
167 const vec_u16 vswap = (vec_u16) vec_splat_u16(big_endian ? 8 : 0);
168 const vec_u16 vshift = (vec_u16) vec_splat_u16(shift);
169 const vec_u16 vlargest = (vec_u16) {clip, clip, clip, clip, clip, clip, clip, clip};
170 vec_u16 v;
171 int i;
172
173 yuv2plane1_nbps_u(src, dest, dst_u, big_endian, output_bits, 0);
174
175 for (i = dst_u; i < dstW - 7; i += 8) {
176 v = vec_vsx_ld(0, (const uint16_t *) &src[i]);
177 v = vec_add(v, vadd);
178 v = vec_sr(v, vshift);
179 v = vec_min(v, vlargest);
180 v = vec_rl(v, vswap);
181 vec_st(v, 0, &dest[i]);
182 }
183
184 yuv2plane1_nbps_u(src, dest, dstW, big_endian, output_bits, i);
185}
186
187static void yuv2planeX_nbps_u(const int16_t *filter, int filterSize,
188 const int16_t **src, uint16_t *dest, int dstW,
189 int big_endian, int output_bits, int start)
190{
191 int i;
192 int shift = 11 + 16 - output_bits;
193
194 for (i = start; i < dstW; i++) {
195 int val = 1 << (shift - 1);
196 int j;
197
198 for (j = 0; j < filterSize; j++)
199 val += src[j][i] * filter[j];
200
201 output_pixel(&dest[i], val);
202 }
203}
204
205static void yuv2planeX_nbps_vsx(const int16_t *filter, int filterSize,
206 const int16_t **src, uint16_t *dest, int dstW,
207 int big_endian, int output_bits)
208{
209 const int dst_u = -(uintptr_t)dest & 7;
210 const int shift = 11 + 16 - output_bits;
211 const int add = (1 << (shift - 1));
212 const int clip = (1 << output_bits) - 1;
213 const uint16_t swap = big_endian ? 8 : 0;
214 const vec_u32 vadd = (vec_u32) {add, add, add, add};
215 const vec_u32 vshift = (vec_u32) {shift, shift, shift, shift};
216 const vec_u16 vswap = (vec_u16) {swap, swap, swap, swap, swap, swap, swap, swap};
217 const vec_u16 vlargest = (vec_u16) {clip, clip, clip, clip, clip, clip, clip, clip};
218 const vec_s16 vzero = vec_splat_s16(0);
219 const vec_u8 vperm = (vec_u8) {0, 1, 8, 9, 2, 3, 10, 11, 4, 5, 12, 13, 6, 7, 14, 15};
220 vec_s16 vfilter[MAX_FILTER_SIZE], vin;
221 vec_u16 v;
222 vec_u32 vleft, vright, vtmp;
223 int i, j;
224
225 for (i = 0; i < filterSize; i++) {
226 vfilter[i] = (vec_s16) {filter[i], filter[i], filter[i], filter[i],
227 filter[i], filter[i], filter[i], filter[i]};
228 }
229
230 yuv2planeX_nbps_u(filter, filterSize, src, dest, dst_u, big_endian, output_bits, 0);
231
232 for (i = dst_u; i < dstW - 7; i += 8) {
233 vleft = vright = vadd;
234
235 for (j = 0; j < filterSize; j++) {
236 vin = vec_vsx_ld(0, &src[j][i]);
237 vtmp = (vec_u32) vec_mule(vin, vfilter[j]);
238 vleft = vec_add(vleft, vtmp);
239 vtmp = (vec_u32) vec_mulo(vin, vfilter[j]);
240 vright = vec_add(vright, vtmp);
241 }
242
243 vleft = vec_sra(vleft, vshift);
244 vright = vec_sra(vright, vshift);
245 v = vec_packsu(vleft, vright);
246 v = (vec_u16) vec_max((vec_s16) v, vzero);
247 v = vec_min(v, vlargest);
248 v = vec_rl(v, vswap);
249 v = vec_perm(v, v, vperm);
250 vec_st(v, 0, &dest[i]);
251 }
252
253 yuv2planeX_nbps_u(filter, filterSize, src, dest, dstW, big_endian, output_bits, i);
254}
255
256
257#undef output_pixel
258
259#define output_pixel(pos, val, bias, signedness) \
260 if (big_endian) { \
261 AV_WB16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
262 } else { \
263 AV_WL16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
264 }
265
266static void yuv2plane1_16_u(const int32_t *src, uint16_t *dest, int dstW,
267 int big_endian, int output_bits, int start)
268{
269 int i;
270 const int shift = 3;
271
272 for (i = start; i < dstW; i++) {
273 int val = src[i] + (1 << (shift - 1));
274 output_pixel(&dest[i], val, 0, uint);
275 }
276}
277
279 uint16_t *dest, int dstW,
280 const int big_endian,
281 int output_bits)
282{
283 const int dst_u = -(uintptr_t)dest & 7;
284 const int shift = 3;
285 const int add = (1 << (shift - 1));
286 const vec_u32 vadd = (vec_u32) {add, add, add, add};
287 const vec_u16 vswap = (vec_u16) vec_splat_u16(big_endian ? 8 : 0);
288 const vec_u32 vshift = (vec_u32) vec_splat_u32(shift);
289 vec_u32 v, v2;
290 vec_u16 vd;
291 int i;
292
293 yuv2plane1_16_u(src, dest, dst_u, big_endian, output_bits, 0);
294
295 for (i = dst_u; i < dstW - 7; i += 8) {
296 v = vec_vsx_ld(0, (const uint32_t *) &src[i]);
297 v = vec_add(v, vadd);
298 v = vec_sr(v, vshift);
299
300 v2 = vec_vsx_ld(0, (const uint32_t *) &src[i + 4]);
301 v2 = vec_add(v2, vadd);
302 v2 = vec_sr(v2, vshift);
303
304 vd = vec_packsu(v, v2);
305 vd = vec_rl(vd, vswap);
306
307 vec_st(vd, 0, &dest[i]);
308 }
309
310 yuv2plane1_16_u(src, dest, dstW, big_endian, output_bits, i);
311}
312
313#if HAVE_POWER8
314
315static void yuv2planeX_16_u(const int16_t *filter, int filterSize,
316 const int32_t **src, uint16_t *dest, int dstW,
317 int big_endian, int output_bits, int start)
318{
319 int i;
320 int shift = 15;
321
322 for (i = start; i < dstW; i++) {
323 int val = 1 << (shift - 1);
324 int j;
325
326 /* range of val is [0,0x7FFFFFFF], so 31 bits, but with lanczos/spline
327 * filters (or anything with negative coeffs, the range can be slightly
328 * wider in both directions. To account for this overflow, we subtract
329 * a constant so it always fits in the signed range (assuming a
330 * reasonable filterSize), and re-add that at the end. */
331 val -= 0x40000000;
332 for (j = 0; j < filterSize; j++)
333 val += src[j][i] * (unsigned)filter[j];
334
335 output_pixel(&dest[i], val, 0x8000, int);
336 }
337}
338
339static void yuv2planeX_16_vsx(const int16_t *filter, int filterSize,
340 const int32_t **src, uint16_t *dest, int dstW,
341 int big_endian, int output_bits)
342{
343 const int dst_u = -(uintptr_t)dest & 7;
344 const int shift = 15;
345 const int bias = 0x8000;
346 const int add = (1 << (shift - 1)) - 0x40000000;
347 const uint16_t swap = big_endian ? 8 : 0;
348 const vec_u32 vadd = (vec_u32) {add, add, add, add};
349 const vec_u32 vshift = (vec_u32) {shift, shift, shift, shift};
350 const vec_u16 vswap = (vec_u16) {swap, swap, swap, swap, swap, swap, swap, swap};
351 const vec_u16 vbias = (vec_u16) {bias, bias, bias, bias, bias, bias, bias, bias};
352 vec_s32 vfilter[MAX_FILTER_SIZE];
353 vec_u16 v;
354 vec_u32 vleft, vright, vtmp;
355 vec_s32 vin32l, vin32r;
356 int i, j;
357
358 for (i = 0; i < filterSize; i++) {
359 vfilter[i] = (vec_s32) {filter[i], filter[i], filter[i], filter[i]};
360 }
361
362 yuv2planeX_16_u(filter, filterSize, src, dest, dst_u, big_endian, output_bits, 0);
363
364 for (i = dst_u; i < dstW - 7; i += 8) {
365 vleft = vright = vadd;
366
367 for (j = 0; j < filterSize; j++) {
368 vin32l = vec_vsx_ld(0, &src[j][i]);
369 vin32r = vec_vsx_ld(0, &src[j][i + 4]);
370
371 vtmp = (vec_u32) vec_mul(vin32l, vfilter[j]);
372 vleft = vec_add(vleft, vtmp);
373 vtmp = (vec_u32) vec_mul(vin32r, vfilter[j]);
374 vright = vec_add(vright, vtmp);
375 }
376
377 vleft = vec_sra(vleft, vshift);
378 vright = vec_sra(vright, vshift);
379 v = (vec_u16) vec_packs((vec_s32) vleft, (vec_s32) vright);
380 v = vec_add(v, vbias);
381 v = vec_rl(v, vswap);
382 vec_st(v, 0, &dest[i]);
383 }
384
385 yuv2planeX_16_u(filter, filterSize, src, dest, dstW, big_endian, output_bits, i);
386}
387
388#endif /* HAVE_POWER8 */
389
390#define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \
391 yuv2NBPS1(bits, BE_LE, is_be, template_size, typeX_t) \
392 yuv2NBPSX(bits, BE_LE, is_be, template_size, typeX_t)
393
394#define yuv2NBPS1(bits, BE_LE, is_be, template_size, typeX_t) \
395static void yuv2plane1_ ## bits ## BE_LE ## _vsx(const int16_t *src, \
396 uint8_t *dest, int dstW, \
397 const uint8_t *dither, int offset) \
398{ \
399 yuv2plane1_ ## template_size ## _vsx((const typeX_t *) src, \
400 (uint16_t *) dest, dstW, is_be, bits); \
401}
402
403#define yuv2NBPSX(bits, BE_LE, is_be, template_size, typeX_t) \
404static void yuv2planeX_ ## bits ## BE_LE ## _vsx(const int16_t *filter, int filterSize, \
405 const int16_t **src, uint8_t *dest, int dstW, \
406 const uint8_t *dither, int offset)\
407{ \
408 yuv2planeX_## template_size ## _vsx(filter, \
409 filterSize, (const typeX_t **) src, \
410 (uint16_t *) dest, dstW, is_be, bits); \
411}
412
413yuv2NBPS( 9, BE, 1, nbps, int16_t)
414yuv2NBPS( 9, LE, 0, nbps, int16_t)
415yuv2NBPS(10, BE, 1, nbps, int16_t)
416yuv2NBPS(10, LE, 0, nbps, int16_t)
417yuv2NBPS(12, BE, 1, nbps, int16_t)
418yuv2NBPS(12, LE, 0, nbps, int16_t)
419yuv2NBPS(14, BE, 1, nbps, int16_t)
420yuv2NBPS(14, LE, 0, nbps, int16_t)
421
422yuv2NBPS1(16, BE, 1, 16, int32_t)
423yuv2NBPS1(16, LE, 0, 16, int32_t)
424#if HAVE_POWER8
425yuv2NBPSX(16, BE, 1, 16, int32_t)
426yuv2NBPSX(16, LE, 0, 16, int32_t)
427#endif
428
429#define WRITERGB \
430 R_l = vec_max(R_l, zero32); \
431 R_r = vec_max(R_r, zero32); \
432 G_l = vec_max(G_l, zero32); \
433 G_r = vec_max(G_r, zero32); \
434 B_l = vec_max(B_l, zero32); \
435 B_r = vec_max(B_r, zero32); \
436\
437 R_l = vec_min(R_l, rgbclip); \
438 R_r = vec_min(R_r, rgbclip); \
439 G_l = vec_min(G_l, rgbclip); \
440 G_r = vec_min(G_r, rgbclip); \
441 B_l = vec_min(B_l, rgbclip); \
442 B_r = vec_min(B_r, rgbclip); \
443\
444 R_l = vec_sr(R_l, shift22); \
445 R_r = vec_sr(R_r, shift22); \
446 G_l = vec_sr(G_l, shift22); \
447 G_r = vec_sr(G_r, shift22); \
448 B_l = vec_sr(B_l, shift22); \
449 B_r = vec_sr(B_r, shift22); \
450\
451 rd16 = vec_packsu(R_l, R_r); \
452 gd16 = vec_packsu(G_l, G_r); \
453 bd16 = vec_packsu(B_l, B_r); \
454 rd = vec_packsu(rd16, zero16); \
455 gd = vec_packsu(gd16, zero16); \
456 bd = vec_packsu(bd16, zero16); \
457\
458 switch(target) { \
459 case AV_PIX_FMT_RGB24: { \
460 DECLARE_ALIGNED(16, uint8_t, tmp_out)[16]; \
461 out0 = vec_perm(rd, gd, perm3rg0); \
462 out0 = vec_perm(out0, bd, perm3tb0); \
463 out1 = vec_perm(rd, gd, perm3rg1); \
464 out1 = vec_perm(out1, bd, perm3tb1); \
465\
466 vec_vsx_st(out0, 0, dest); \
467 vec_vsx_st(out1, 0, tmp_out); \
468 memcpy(dest + 16, tmp_out, 8); \
469\
470 dest += 24; \
471 break; } \
472 case AV_PIX_FMT_BGR24: { \
473 DECLARE_ALIGNED(16, uint8_t, tmp_out)[16]; \
474 out0 = vec_perm(bd, gd, perm3rg0); \
475 out0 = vec_perm(out0, rd, perm3tb0); \
476 out1 = vec_perm(bd, gd, perm3rg1); \
477 out1 = vec_perm(out1, rd, perm3tb1); \
478\
479 vec_vsx_st(out0, 0, dest); \
480 vec_vsx_st(out1, 0, tmp_out); \
481 memcpy(dest + 16, tmp_out, 8); \
482\
483 dest += 24; \
484 break; } \
485 case AV_PIX_FMT_BGRA: \
486 out0 = vec_mergeh(bd, gd); \
487 out1 = vec_mergeh(rd, ad); \
488\
489 tmp8 = (vec_u8) vec_mergeh((vec_u16) out0, (vec_u16) out1); \
490 vec_vsx_st(tmp8, 0, dest); \
491 tmp8 = (vec_u8) vec_mergel((vec_u16) out0, (vec_u16) out1); \
492 vec_vsx_st(tmp8, 16, dest); \
493\
494 dest += 32; \
495 break; \
496 case AV_PIX_FMT_RGBA: \
497 out0 = vec_mergeh(rd, gd); \
498 out1 = vec_mergeh(bd, ad); \
499\
500 tmp8 = (vec_u8) vec_mergeh((vec_u16) out0, (vec_u16) out1); \
501 vec_vsx_st(tmp8, 0, dest); \
502 tmp8 = (vec_u8) vec_mergel((vec_u16) out0, (vec_u16) out1); \
503 vec_vsx_st(tmp8, 16, dest); \
504\
505 dest += 32; \
506 break; \
507 case AV_PIX_FMT_ARGB: \
508 out0 = vec_mergeh(ad, rd); \
509 out1 = vec_mergeh(gd, bd); \
510\
511 tmp8 = (vec_u8) vec_mergeh((vec_u16) out0, (vec_u16) out1); \
512 vec_vsx_st(tmp8, 0, dest); \
513 tmp8 = (vec_u8) vec_mergel((vec_u16) out0, (vec_u16) out1); \
514 vec_vsx_st(tmp8, 16, dest); \
515\
516 dest += 32; \
517 break; \
518 case AV_PIX_FMT_ABGR: \
519 out0 = vec_mergeh(ad, bd); \
520 out1 = vec_mergeh(gd, rd); \
521\
522 tmp8 = (vec_u8) vec_mergeh((vec_u16) out0, (vec_u16) out1); \
523 vec_vsx_st(tmp8, 0, dest); \
524 tmp8 = (vec_u8) vec_mergel((vec_u16) out0, (vec_u16) out1); \
525 vec_vsx_st(tmp8, 16, dest); \
526\
527 dest += 32; \
528 break; \
529 }
530
531static av_always_inline void
532yuv2rgb_full_X_vsx_template(SwsInternal *c, const int16_t *lumFilter,
533 const int16_t **lumSrc, int lumFilterSize,
534 const int16_t *chrFilter, const int16_t **chrUSrc,
535 const int16_t **chrVSrc, int chrFilterSize,
536 const int16_t **alpSrc, uint8_t *dest,
537 int dstW, int y, enum AVPixelFormat target, int hasAlpha)
538{
539 vec_s16 vv;
540 vec_s32 vy32_l, vy32_r, vu32_l, vu32_r, vv32_l, vv32_r, tmp32;
541 vec_s32 R_l, R_r, G_l, G_r, B_l, B_r;
542 vec_s32 tmp, tmp2, tmp3, tmp4;
543 vec_u16 rd16, gd16, bd16;
544 vec_u8 rd, bd, gd, ad, out0, out1, tmp8;
545 vec_s16 vlumFilter[MAX_FILTER_SIZE], vchrFilter[MAX_FILTER_SIZE];
546 const vec_s32 ystart = vec_splats(1 << 9);
547 const vec_s32 uvstart = vec_splats((1 << 9) - (128 << 19));
548 const vec_u16 zero16 = vec_splat_u16(0);
549 const vec_s32 y_offset = vec_splats(c->yuv2rgb_y_offset);
550 const vec_s32 y_coeff = vec_splats(c->yuv2rgb_y_coeff);
551 const vec_s32 y_add = vec_splats(1 << 21);
552 const vec_s32 v2r_coeff = vec_splats(c->yuv2rgb_v2r_coeff);
553 const vec_s32 v2g_coeff = vec_splats(c->yuv2rgb_v2g_coeff);
554 const vec_s32 u2g_coeff = vec_splats(c->yuv2rgb_u2g_coeff);
555 const vec_s32 u2b_coeff = vec_splats(c->yuv2rgb_u2b_coeff);
556 const vec_s32 rgbclip = vec_splats(1 << 30);
557 const vec_s32 zero32 = vec_splat_s32(0);
558 const vec_u32 shift22 = vec_splats(22U);
559 const vec_u32 shift10 = vec_splat_u32(10);
560 int i, j;
561
562 // Various permutations
563 const vec_u8 perm3rg0 = (vec_u8) {0x0, 0x10, 0,
564 0x1, 0x11, 0,
565 0x2, 0x12, 0,
566 0x3, 0x13, 0,
567 0x4, 0x14, 0,
568 0x5 };
569 const vec_u8 perm3rg1 = (vec_u8) { 0x15, 0,
570 0x6, 0x16, 0,
571 0x7, 0x17, 0 };
572 const vec_u8 perm3tb0 = (vec_u8) {0x0, 0x1, 0x10,
573 0x3, 0x4, 0x11,
574 0x6, 0x7, 0x12,
575 0x9, 0xa, 0x13,
576 0xc, 0xd, 0x14,
577 0xf };
578 const vec_u8 perm3tb1 = (vec_u8) { 0x0, 0x15,
579 0x2, 0x3, 0x16,
580 0x5, 0x6, 0x17 };
581
582 ad = vec_splats((uint8_t) 255);
583
584 for (i = 0; i < lumFilterSize; i++)
585 vlumFilter[i] = vec_splats(lumFilter[i]);
586 for (i = 0; i < chrFilterSize; i++)
587 vchrFilter[i] = vec_splats(chrFilter[i]);
588
589 for (i = 0; i < dstW; i += 8) {
590 vy32_l =
591 vy32_r = ystart;
592 vu32_l =
593 vu32_r =
594 vv32_l =
595 vv32_r = uvstart;
596
597 for (j = 0; j < lumFilterSize; j++) {
598 vv = vec_ld(0, &lumSrc[j][i]);
599 tmp = vec_mule(vv, vlumFilter[j]);
600 tmp2 = vec_mulo(vv, vlumFilter[j]);
601 tmp3 = vec_mergeh(tmp, tmp2);
602 tmp4 = vec_mergel(tmp, tmp2);
603
604 vy32_l = vec_adds(vy32_l, tmp3);
605 vy32_r = vec_adds(vy32_r, tmp4);
606 }
607
608 for (j = 0; j < chrFilterSize; j++) {
609 vv = vec_ld(0, &chrUSrc[j][i]);
610 tmp = vec_mule(vv, vchrFilter[j]);
611 tmp2 = vec_mulo(vv, vchrFilter[j]);
612 tmp3 = vec_mergeh(tmp, tmp2);
613 tmp4 = vec_mergel(tmp, tmp2);
614
615 vu32_l = vec_adds(vu32_l, tmp3);
616 vu32_r = vec_adds(vu32_r, tmp4);
617
618 vv = vec_ld(0, &chrVSrc[j][i]);
619 tmp = vec_mule(vv, vchrFilter[j]);
620 tmp2 = vec_mulo(vv, vchrFilter[j]);
621 tmp3 = vec_mergeh(tmp, tmp2);
622 tmp4 = vec_mergel(tmp, tmp2);
623
624 vv32_l = vec_adds(vv32_l, tmp3);
625 vv32_r = vec_adds(vv32_r, tmp4);
626 }
627
628 vy32_l = vec_sra(vy32_l, shift10);
629 vy32_r = vec_sra(vy32_r, shift10);
630 vu32_l = vec_sra(vu32_l, shift10);
631 vu32_r = vec_sra(vu32_r, shift10);
632 vv32_l = vec_sra(vv32_l, shift10);
633 vv32_r = vec_sra(vv32_r, shift10);
634
635 vy32_l = vec_sub(vy32_l, y_offset);
636 vy32_r = vec_sub(vy32_r, y_offset);
637 vy32_l = vec_mul(vy32_l, y_coeff);
638 vy32_r = vec_mul(vy32_r, y_coeff);
639 vy32_l = vec_add(vy32_l, y_add);
640 vy32_r = vec_add(vy32_r, y_add);
641
642 R_l = vec_mul(vv32_l, v2r_coeff);
643 R_l = vec_add(R_l, vy32_l);
644 R_r = vec_mul(vv32_r, v2r_coeff);
645 R_r = vec_add(R_r, vy32_r);
646 G_l = vec_mul(vv32_l, v2g_coeff);
647 tmp32 = vec_mul(vu32_l, u2g_coeff);
648 G_l = vec_add(G_l, vy32_l);
649 G_l = vec_add(G_l, tmp32);
650 G_r = vec_mul(vv32_r, v2g_coeff);
651 tmp32 = vec_mul(vu32_r, u2g_coeff);
652 G_r = vec_add(G_r, vy32_r);
653 G_r = vec_add(G_r, tmp32);
654
655 B_l = vec_mul(vu32_l, u2b_coeff);
656 B_l = vec_add(B_l, vy32_l);
657 B_r = vec_mul(vu32_r, u2b_coeff);
658 B_r = vec_add(B_r, vy32_r);
659
661 }
662}
663
664#define SETUP(x, buf0, alpha1, buf1, alpha) { \
665 x = vec_ld(0, buf0); \
666 tmp = vec_mule(x, alpha1); \
667 tmp2 = vec_mulo(x, alpha1); \
668 tmp3 = vec_mergeh(tmp, tmp2); \
669 tmp4 = vec_mergel(tmp, tmp2); \
670\
671 x = vec_ld(0, buf1); \
672 tmp = vec_mule(x, alpha); \
673 tmp2 = vec_mulo(x, alpha); \
674 tmp5 = vec_mergeh(tmp, tmp2); \
675 tmp6 = vec_mergel(tmp, tmp2); \
676\
677 tmp3 = vec_add(tmp3, tmp5); \
678 tmp4 = vec_add(tmp4, tmp6); \
679}
680
681
682static av_always_inline void
684 const int16_t *ubuf[2], const int16_t *vbuf[2],
685 const int16_t *abuf[2], uint8_t *dest, int dstW,
686 int yalpha, int uvalpha, int y,
687 enum AVPixelFormat target, int hasAlpha)
688{
689 const int16_t *buf0 = buf[0], *buf1 = buf[1],
690 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
691 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
692 *abuf0 = hasAlpha ? abuf[0] : NULL,
693 *abuf1 = hasAlpha ? abuf[1] : NULL;
694 const int16_t yalpha1 = 4096 - yalpha;
695 const int16_t uvalpha1 = 4096 - uvalpha;
696 vec_s16 vy, vu, vv, A = vec_splat_s16(0);
697 vec_s32 vy32_l, vy32_r, vu32_l, vu32_r, vv32_l, vv32_r, tmp32;
698 vec_s32 R_l, R_r, G_l, G_r, B_l, B_r;
699 vec_s32 tmp, tmp2, tmp3, tmp4, tmp5, tmp6;
700 vec_u16 rd16, gd16, bd16;
701 vec_u8 rd, bd, gd, ad, out0, out1, tmp8;
702 const vec_s16 vyalpha1 = vec_splats(yalpha1);
703 const vec_s16 vuvalpha1 = vec_splats(uvalpha1);
704 const vec_s16 vyalpha = vec_splats((int16_t) yalpha);
705 const vec_s16 vuvalpha = vec_splats((int16_t) uvalpha);
706 const vec_u16 zero16 = vec_splat_u16(0);
707 const vec_s32 y_offset = vec_splats(c->yuv2rgb_y_offset);
708 const vec_s32 y_coeff = vec_splats(c->yuv2rgb_y_coeff);
709 const vec_s32 y_add = vec_splats(1 << 21);
710 const vec_s32 v2r_coeff = vec_splats(c->yuv2rgb_v2r_coeff);
711 const vec_s32 v2g_coeff = vec_splats(c->yuv2rgb_v2g_coeff);
712 const vec_s32 u2g_coeff = vec_splats(c->yuv2rgb_u2g_coeff);
713 const vec_s32 u2b_coeff = vec_splats(c->yuv2rgb_u2b_coeff);
714 const vec_s32 rgbclip = vec_splats(1 << 30);
715 const vec_s32 zero32 = vec_splat_s32(0);
716 const vec_u32 shift19 = vec_splats(19U);
717 const vec_u32 shift22 = vec_splats(22U);
718 const vec_u32 shift10 = vec_splat_u32(10);
719 const vec_s32 dec128 = vec_splats(128 << 19);
720 const vec_s32 add18 = vec_splats(1 << 18);
721 int i;
722
723 // Various permutations
724 const vec_u8 perm3rg0 = (vec_u8) {0x0, 0x10, 0,
725 0x1, 0x11, 0,
726 0x2, 0x12, 0,
727 0x3, 0x13, 0,
728 0x4, 0x14, 0,
729 0x5 };
730 const vec_u8 perm3rg1 = (vec_u8) { 0x15, 0,
731 0x6, 0x16, 0,
732 0x7, 0x17, 0 };
733 const vec_u8 perm3tb0 = (vec_u8) {0x0, 0x1, 0x10,
734 0x3, 0x4, 0x11,
735 0x6, 0x7, 0x12,
736 0x9, 0xa, 0x13,
737 0xc, 0xd, 0x14,
738 0xf };
739 const vec_u8 perm3tb1 = (vec_u8) { 0x0, 0x15,
740 0x2, 0x3, 0x16,
741 0x5, 0x6, 0x17 };
742
743 av_assert2(yalpha <= 4096U);
744 av_assert2(uvalpha <= 4096U);
745
746 for (i = 0; i < dstW; i += 8) {
747 SETUP(vy, &buf0[i], vyalpha1, &buf1[i], vyalpha);
748 vy32_l = vec_sra(tmp3, shift10);
749 vy32_r = vec_sra(tmp4, shift10);
750
751 SETUP(vu, &ubuf0[i], vuvalpha1, &ubuf1[i], vuvalpha);
752 tmp3 = vec_sub(tmp3, dec128);
753 tmp4 = vec_sub(tmp4, dec128);
754 vu32_l = vec_sra(tmp3, shift10);
755 vu32_r = vec_sra(tmp4, shift10);
756
757 SETUP(vv, &vbuf0[i], vuvalpha1, &vbuf1[i], vuvalpha);
758 tmp3 = vec_sub(tmp3, dec128);
759 tmp4 = vec_sub(tmp4, dec128);
760 vv32_l = vec_sra(tmp3, shift10);
761 vv32_r = vec_sra(tmp4, shift10);
762
763 if (hasAlpha) {
764 SETUP(A, &abuf0[i], vyalpha1, &abuf1[i], vyalpha);
765 tmp3 = vec_add(tmp3, add18);
766 tmp4 = vec_add(tmp4, add18);
767 tmp3 = vec_sra(tmp3, shift19);
768 tmp4 = vec_sra(tmp4, shift19);
769 A = vec_packs(tmp3, tmp4);
770 ad = vec_packsu(A, (vec_s16) zero16);
771 } else {
772 ad = vec_splats((uint8_t) 255);
773 }
774
775 vy32_l = vec_sub(vy32_l, y_offset);
776 vy32_r = vec_sub(vy32_r, y_offset);
777 vy32_l = vec_mul(vy32_l, y_coeff);
778 vy32_r = vec_mul(vy32_r, y_coeff);
779 vy32_l = vec_add(vy32_l, y_add);
780 vy32_r = vec_add(vy32_r, y_add);
781
782 R_l = vec_mul(vv32_l, v2r_coeff);
783 R_l = vec_add(R_l, vy32_l);
784 R_r = vec_mul(vv32_r, v2r_coeff);
785 R_r = vec_add(R_r, vy32_r);
786 G_l = vec_mul(vv32_l, v2g_coeff);
787 tmp32 = vec_mul(vu32_l, u2g_coeff);
788 G_l = vec_add(G_l, vy32_l);
789 G_l = vec_add(G_l, tmp32);
790 G_r = vec_mul(vv32_r, v2g_coeff);
791 tmp32 = vec_mul(vu32_r, u2g_coeff);
792 G_r = vec_add(G_r, vy32_r);
793 G_r = vec_add(G_r, tmp32);
794
795 B_l = vec_mul(vu32_l, u2b_coeff);
796 B_l = vec_add(B_l, vy32_l);
797 B_r = vec_mul(vu32_r, u2b_coeff);
798 B_r = vec_add(B_r, vy32_r);
799
801 }
802}
803
804static av_always_inline void
805yuv2rgb_2_vsx_template(SwsInternal *c, const int16_t *buf[2],
806 const int16_t *ubuf[2], const int16_t *vbuf[2],
807 const int16_t *abuf[2], uint8_t *dest, int dstW,
808 int yalpha, int uvalpha, int y,
809 enum AVPixelFormat target, int hasAlpha)
810{
811 const int16_t *buf0 = buf[0], *buf1 = buf[1],
812 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
813 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
814 *abuf0 = hasAlpha ? abuf[0] : NULL,
815 *abuf1 = hasAlpha ? abuf[1] : NULL;
816 const int16_t yalpha1 = 4096 - yalpha;
817 const int16_t uvalpha1 = 4096 - uvalpha;
818 vec_s16 vy, vu, vv, A = vec_splat_s16(0);
819 vec_s32 vy32_l, vy32_r, vu32_l, vu32_r, vv32_l, vv32_r, tmp32;
820 vec_s32 R_l, R_r, G_l, G_r, B_l, B_r, vud32_l, vud32_r, vvd32_l, vvd32_r;
821 vec_s32 tmp, tmp2, tmp3, tmp4, tmp5, tmp6;
822 vec_u16 rd16, gd16, bd16;
823 vec_u8 rd, bd, gd, ad, out0, out1, tmp8;
824 const vec_s16 vyalpha1 = vec_splats(yalpha1);
825 const vec_s16 vuvalpha1 = vec_splats(uvalpha1);
826 const vec_s16 vyalpha = vec_splats((int16_t) yalpha);
827 const vec_s16 vuvalpha = vec_splats((int16_t) uvalpha);
828 const vec_u16 zero16 = vec_splat_u16(0);
829 const vec_s32 y_offset = vec_splats(c->yuv2rgb_y_offset);
830 const vec_s32 y_coeff = vec_splats(c->yuv2rgb_y_coeff);
831 const vec_s32 y_add = vec_splats(1 << 21);
832 const vec_s32 v2r_coeff = vec_splats(c->yuv2rgb_v2r_coeff);
833 const vec_s32 v2g_coeff = vec_splats(c->yuv2rgb_v2g_coeff);
834 const vec_s32 u2g_coeff = vec_splats(c->yuv2rgb_u2g_coeff);
835 const vec_s32 u2b_coeff = vec_splats(c->yuv2rgb_u2b_coeff);
836 const vec_s32 rgbclip = vec_splats(1 << 30);
837 const vec_s32 zero32 = vec_splat_s32(0);
838 const vec_u32 shift19 = vec_splats(19U);
839 const vec_u32 shift22 = vec_splats(22U);
840 const vec_u32 shift10 = vec_splat_u32(10);
841 const vec_s32 dec128 = vec_splats(128 << 19);
842 const vec_s32 add18 = vec_splats(1 << 18);
843 int i;
844
845 // Various permutations
846 const vec_u8 doubleleft = (vec_u8) {0, 1, 2, 3,
847 0, 1, 2, 3,
848 4, 5, 6, 7,
849 4, 5, 6, 7 };
850 const vec_u8 doubleright = (vec_u8) {8, 9, 10, 11,
851 8, 9, 10, 11,
852 12, 13, 14, 15,
853 12, 13, 14, 15 };
854 const vec_u8 perm3rg0 = (vec_u8) {0x0, 0x10, 0,
855 0x1, 0x11, 0,
856 0x2, 0x12, 0,
857 0x3, 0x13, 0,
858 0x4, 0x14, 0,
859 0x5 };
860 const vec_u8 perm3rg1 = (vec_u8) { 0x15, 0,
861 0x6, 0x16, 0,
862 0x7, 0x17, 0 };
863 const vec_u8 perm3tb0 = (vec_u8) {0x0, 0x1, 0x10,
864 0x3, 0x4, 0x11,
865 0x6, 0x7, 0x12,
866 0x9, 0xa, 0x13,
867 0xc, 0xd, 0x14,
868 0xf };
869 const vec_u8 perm3tb1 = (vec_u8) { 0x0, 0x15,
870 0x2, 0x3, 0x16,
871 0x5, 0x6, 0x17 };
872
873 av_assert2(yalpha <= 4096U);
874 av_assert2(uvalpha <= 4096U);
875
876 for (i = 0; i < (dstW + 1) >> 1; i += 8) {
877 SETUP(vy, &buf0[i * 2], vyalpha1, &buf1[i * 2], vyalpha);
878 vy32_l = vec_sra(tmp3, shift10);
879 vy32_r = vec_sra(tmp4, shift10);
880
881 SETUP(vu, &ubuf0[i], vuvalpha1, &ubuf1[i], vuvalpha);
882 tmp3 = vec_sub(tmp3, dec128);
883 tmp4 = vec_sub(tmp4, dec128);
884 vu32_l = vec_sra(tmp3, shift10);
885 vu32_r = vec_sra(tmp4, shift10);
886
887 SETUP(vv, &vbuf0[i], vuvalpha1, &vbuf1[i], vuvalpha);
888 tmp3 = vec_sub(tmp3, dec128);
889 tmp4 = vec_sub(tmp4, dec128);
890 vv32_l = vec_sra(tmp3, shift10);
891 vv32_r = vec_sra(tmp4, shift10);
892
893 if (hasAlpha) {
894 SETUP(A, &abuf0[i], vyalpha1, &abuf1[i], vyalpha);
895 tmp3 = vec_add(tmp3, add18);
896 tmp4 = vec_add(tmp4, add18);
897 tmp3 = vec_sra(tmp3, shift19);
898 tmp4 = vec_sra(tmp4, shift19);
899 A = vec_packs(tmp3, tmp4);
900 ad = vec_packsu(A, (vec_s16) zero16);
901 } else {
902 ad = vec_splats((uint8_t) 255);
903 }
904
905 vy32_l = vec_sub(vy32_l, y_offset);
906 vy32_r = vec_sub(vy32_r, y_offset);
907 vy32_l = vec_mul(vy32_l, y_coeff);
908 vy32_r = vec_mul(vy32_r, y_coeff);
909 vy32_l = vec_add(vy32_l, y_add);
910 vy32_r = vec_add(vy32_r, y_add);
911
912 // Use the first UV half
913 vud32_l = vec_perm(vu32_l, vu32_l, doubleleft);
914 vud32_r = vec_perm(vu32_l, vu32_l, doubleright);
915 vvd32_l = vec_perm(vv32_l, vv32_l, doubleleft);
916 vvd32_r = vec_perm(vv32_l, vv32_l, doubleright);
917
918 R_l = vec_mul(vvd32_l, v2r_coeff);
919 R_l = vec_add(R_l, vy32_l);
920 R_r = vec_mul(vvd32_r, v2r_coeff);
921 R_r = vec_add(R_r, vy32_r);
922 G_l = vec_mul(vvd32_l, v2g_coeff);
923 tmp32 = vec_mul(vud32_l, u2g_coeff);
924 G_l = vec_add(G_l, vy32_l);
925 G_l = vec_add(G_l, tmp32);
926 G_r = vec_mul(vvd32_r, v2g_coeff);
927 tmp32 = vec_mul(vud32_r, u2g_coeff);
928 G_r = vec_add(G_r, vy32_r);
929 G_r = vec_add(G_r, tmp32);
930
931 B_l = vec_mul(vud32_l, u2b_coeff);
932 B_l = vec_add(B_l, vy32_l);
933 B_r = vec_mul(vud32_r, u2b_coeff);
934 B_r = vec_add(B_r, vy32_r);
935
937
938 // New Y for the second half
939 SETUP(vy, &buf0[i * 2 + 8], vyalpha1, &buf1[i * 2 + 8], vyalpha);
940 vy32_l = vec_sra(tmp3, shift10);
941 vy32_r = vec_sra(tmp4, shift10);
942
943 vy32_l = vec_sub(vy32_l, y_offset);
944 vy32_r = vec_sub(vy32_r, y_offset);
945 vy32_l = vec_mul(vy32_l, y_coeff);
946 vy32_r = vec_mul(vy32_r, y_coeff);
947 vy32_l = vec_add(vy32_l, y_add);
948 vy32_r = vec_add(vy32_r, y_add);
949
950 // Second UV half
951 vud32_l = vec_perm(vu32_r, vu32_r, doubleleft);
952 vud32_r = vec_perm(vu32_r, vu32_r, doubleright);
953 vvd32_l = vec_perm(vv32_r, vv32_r, doubleleft);
954 vvd32_r = vec_perm(vv32_r, vv32_r, doubleright);
955
956 R_l = vec_mul(vvd32_l, v2r_coeff);
957 R_l = vec_add(R_l, vy32_l);
958 R_r = vec_mul(vvd32_r, v2r_coeff);
959 R_r = vec_add(R_r, vy32_r);
960 G_l = vec_mul(vvd32_l, v2g_coeff);
961 tmp32 = vec_mul(vud32_l, u2g_coeff);
962 G_l = vec_add(G_l, vy32_l);
963 G_l = vec_add(G_l, tmp32);
964 G_r = vec_mul(vvd32_r, v2g_coeff);
965 tmp32 = vec_mul(vud32_r, u2g_coeff);
966 G_r = vec_add(G_r, vy32_r);
967 G_r = vec_add(G_r, tmp32);
968
969 B_l = vec_mul(vud32_l, u2b_coeff);
970 B_l = vec_add(B_l, vy32_l);
971 B_r = vec_mul(vud32_r, u2b_coeff);
972 B_r = vec_add(B_r, vy32_r);
973
975 }
976}
977
978#undef SETUP
979
980static av_always_inline void
982 const int16_t *ubuf[2], const int16_t *vbuf[2],
983 const int16_t *abuf0, uint8_t *dest, int dstW,
984 int uvalpha, int y, enum AVPixelFormat target,
985 int hasAlpha)
986{
987 const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
988 const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
989 vec_s16 vy, vu, vv, A = vec_splat_s16(0), tmp16;
990 vec_s32 vy32_l, vy32_r, vu32_l, vu32_r, vv32_l, vv32_r, tmp32, tmp32_2;
991 vec_s32 R_l, R_r, G_l, G_r, B_l, B_r;
992 vec_u16 rd16, gd16, bd16;
993 vec_u8 rd, bd, gd, ad, out0, out1, tmp8;
994 const vec_u16 zero16 = vec_splat_u16(0);
995 const vec_s32 y_offset = vec_splats(c->yuv2rgb_y_offset);
996 const vec_s32 y_coeff = vec_splats(c->yuv2rgb_y_coeff);
997 const vec_s32 y_add = vec_splats(1 << 21);
998 const vec_s32 v2r_coeff = vec_splats(c->yuv2rgb_v2r_coeff);
999 const vec_s32 v2g_coeff = vec_splats(c->yuv2rgb_v2g_coeff);
1000 const vec_s32 u2g_coeff = vec_splats(c->yuv2rgb_u2g_coeff);
1001 const vec_s32 u2b_coeff = vec_splats(c->yuv2rgb_u2b_coeff);
1002 const vec_s32 rgbclip = vec_splats(1 << 30);
1003 const vec_s32 zero32 = vec_splat_s32(0);
1004 const vec_u32 shift2 = vec_splat_u32(2);
1005 const vec_u32 shift22 = vec_splats(22U);
1006 const vec_u16 sub7 = vec_splats((uint16_t) (128 << 7));
1007 const vec_u16 sub8 = vec_splats((uint16_t) (128 << 8));
1008 const vec_s16 mul4 = vec_splat_s16(4);
1009 const vec_s16 mul8 = vec_splat_s16(8);
1010 const vec_s16 add64 = vec_splat_s16(64);
1011 const vec_u16 shift7 = vec_splat_u16(7);
1012 const vec_s16 max255 = vec_splat_s16(255);
1013 int i;
1014
1015 // Various permutations
1016 const vec_u8 perm3rg0 = (vec_u8) {0x0, 0x10, 0,
1017 0x1, 0x11, 0,
1018 0x2, 0x12, 0,
1019 0x3, 0x13, 0,
1020 0x4, 0x14, 0,
1021 0x5 };
1022 const vec_u8 perm3rg1 = (vec_u8) { 0x15, 0,
1023 0x6, 0x16, 0,
1024 0x7, 0x17, 0 };
1025 const vec_u8 perm3tb0 = (vec_u8) {0x0, 0x1, 0x10,
1026 0x3, 0x4, 0x11,
1027 0x6, 0x7, 0x12,
1028 0x9, 0xa, 0x13,
1029 0xc, 0xd, 0x14,
1030 0xf };
1031 const vec_u8 perm3tb1 = (vec_u8) { 0x0, 0x15,
1032 0x2, 0x3, 0x16,
1033 0x5, 0x6, 0x17 };
1034
1035 for (i = 0; i < dstW; i += 8) { // The x86 asm also overwrites padding bytes.
1036 vy = vec_ld(0, &buf0[i]);
1037 vy32_l = vec_unpackh(vy);
1038 vy32_r = vec_unpackl(vy);
1039 vy32_l = vec_sl(vy32_l, shift2);
1040 vy32_r = vec_sl(vy32_r, shift2);
1041
1042 vu = vec_ld(0, &ubuf0[i]);
1043 vv = vec_ld(0, &vbuf0[i]);
1044 if (uvalpha < 2048) {
1045 vu = (vec_s16) vec_sub((vec_u16) vu, sub7);
1046 vv = (vec_s16) vec_sub((vec_u16) vv, sub7);
1047
1048 tmp32 = vec_mule(vu, mul4);
1049 tmp32_2 = vec_mulo(vu, mul4);
1050 vu32_l = vec_mergeh(tmp32, tmp32_2);
1051 vu32_r = vec_mergel(tmp32, tmp32_2);
1052 tmp32 = vec_mule(vv, mul4);
1053 tmp32_2 = vec_mulo(vv, mul4);
1054 vv32_l = vec_mergeh(tmp32, tmp32_2);
1055 vv32_r = vec_mergel(tmp32, tmp32_2);
1056 } else {
1057 tmp16 = vec_ld(0, &ubuf1[i]);
1058 vu = vec_add(vu, tmp16);
1059 vu = (vec_s16) vec_sub((vec_u16) vu, sub8);
1060 tmp16 = vec_ld(0, &vbuf1[i]);
1061 vv = vec_add(vv, tmp16);
1062 vv = (vec_s16) vec_sub((vec_u16) vv, sub8);
1063
1064 vu32_l = vec_mule(vu, mul8);
1065 vu32_r = vec_mulo(vu, mul8);
1066 vv32_l = vec_mule(vv, mul8);
1067 vv32_r = vec_mulo(vv, mul8);
1068 }
1069
1070 if (hasAlpha) {
1071 A = vec_ld(0, &abuf0[i]);
1072 A = vec_add(A, add64);
1073 A = vec_sr(A, shift7);
1074 A = vec_max(A, max255);
1075 ad = vec_packsu(A, (vec_s16) zero16);
1076 } else {
1077 ad = vec_splats((uint8_t) 255);
1078 }
1079
1080 vy32_l = vec_sub(vy32_l, y_offset);
1081 vy32_r = vec_sub(vy32_r, y_offset);
1082 vy32_l = vec_mul(vy32_l, y_coeff);
1083 vy32_r = vec_mul(vy32_r, y_coeff);
1084 vy32_l = vec_add(vy32_l, y_add);
1085 vy32_r = vec_add(vy32_r, y_add);
1086
1087 R_l = vec_mul(vv32_l, v2r_coeff);
1088 R_l = vec_add(R_l, vy32_l);
1089 R_r = vec_mul(vv32_r, v2r_coeff);
1090 R_r = vec_add(R_r, vy32_r);
1091 G_l = vec_mul(vv32_l, v2g_coeff);
1092 tmp32 = vec_mul(vu32_l, u2g_coeff);
1093 G_l = vec_add(G_l, vy32_l);
1094 G_l = vec_add(G_l, tmp32);
1095 G_r = vec_mul(vv32_r, v2g_coeff);
1096 tmp32 = vec_mul(vu32_r, u2g_coeff);
1097 G_r = vec_add(G_r, vy32_r);
1098 G_r = vec_add(G_r, tmp32);
1099
1100 B_l = vec_mul(vu32_l, u2b_coeff);
1101 B_l = vec_add(B_l, vy32_l);
1102 B_r = vec_mul(vu32_r, u2b_coeff);
1103 B_r = vec_add(B_r, vy32_r);
1104
1105 WRITERGB
1106 }
1107}
1108
1109static av_always_inline void
1111 const int16_t *ubuf[2], const int16_t *vbuf[2],
1112 const int16_t *abuf0, uint8_t *dest, int dstW,
1113 int uvalpha, int y, enum AVPixelFormat target,
1114 int hasAlpha)
1115{
1116 const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1117 const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1118 vec_s16 vy, vu, vv, A = vec_splat_s16(0), tmp16;
1119 vec_s32 vy32_l, vy32_r, vu32_l, vu32_r, vv32_l, vv32_r, tmp32, tmp32_2;
1120 vec_s32 vud32_l, vud32_r, vvd32_l, vvd32_r;
1121 vec_s32 R_l, R_r, G_l, G_r, B_l, B_r;
1122 vec_u16 rd16, gd16, bd16;
1123 vec_u8 rd, bd, gd, ad, out0, out1, tmp8;
1124 const vec_u16 zero16 = vec_splat_u16(0);
1125 const vec_s32 y_offset = vec_splats(c->yuv2rgb_y_offset);
1126 const vec_s32 y_coeff = vec_splats(c->yuv2rgb_y_coeff);
1127 const vec_s32 y_add = vec_splats(1 << 21);
1128 const vec_s32 v2r_coeff = vec_splats(c->yuv2rgb_v2r_coeff);
1129 const vec_s32 v2g_coeff = vec_splats(c->yuv2rgb_v2g_coeff);
1130 const vec_s32 u2g_coeff = vec_splats(c->yuv2rgb_u2g_coeff);
1131 const vec_s32 u2b_coeff = vec_splats(c->yuv2rgb_u2b_coeff);
1132 const vec_s32 rgbclip = vec_splats(1 << 30);
1133 const vec_s32 zero32 = vec_splat_s32(0);
1134 const vec_u32 shift2 = vec_splat_u32(2);
1135 const vec_u32 shift22 = vec_splats(22U);
1136 const vec_u16 sub7 = vec_splats((uint16_t) (128 << 7));
1137 const vec_u16 sub8 = vec_splats((uint16_t) (128 << 8));
1138 const vec_s16 mul4 = vec_splat_s16(4);
1139 const vec_s16 mul8 = vec_splat_s16(8);
1140 const vec_s16 add64 = vec_splat_s16(64);
1141 const vec_u16 shift7 = vec_splat_u16(7);
1142 const vec_s16 max255 = vec_splat_s16(255);
1143 int i;
1144
1145 // Various permutations
1146 const vec_u8 doubleleft = (vec_u8) {0, 1, 2, 3,
1147 0, 1, 2, 3,
1148 4, 5, 6, 7,
1149 4, 5, 6, 7 };
1150 const vec_u8 doubleright = (vec_u8) {8, 9, 10, 11,
1151 8, 9, 10, 11,
1152 12, 13, 14, 15,
1153 12, 13, 14, 15 };
1154 const vec_u8 perm3rg0 = (vec_u8) {0x0, 0x10, 0,
1155 0x1, 0x11, 0,
1156 0x2, 0x12, 0,
1157 0x3, 0x13, 0,
1158 0x4, 0x14, 0,
1159 0x5 };
1160 const vec_u8 perm3rg1 = (vec_u8) { 0x15, 0,
1161 0x6, 0x16, 0,
1162 0x7, 0x17, 0 };
1163 const vec_u8 perm3tb0 = (vec_u8) {0x0, 0x1, 0x10,
1164 0x3, 0x4, 0x11,
1165 0x6, 0x7, 0x12,
1166 0x9, 0xa, 0x13,
1167 0xc, 0xd, 0x14,
1168 0xf };
1169 const vec_u8 perm3tb1 = (vec_u8) { 0x0, 0x15,
1170 0x2, 0x3, 0x16,
1171 0x5, 0x6, 0x17 };
1172
1173 for (i = 0; i < (dstW + 1) >> 1; i += 8) { // The x86 asm also overwrites padding bytes.
1174 vy = vec_ld(0, &buf0[i * 2]);
1175 vy32_l = vec_unpackh(vy);
1176 vy32_r = vec_unpackl(vy);
1177 vy32_l = vec_sl(vy32_l, shift2);
1178 vy32_r = vec_sl(vy32_r, shift2);
1179
1180 vu = vec_ld(0, &ubuf0[i]);
1181 vv = vec_ld(0, &vbuf0[i]);
1182 if (uvalpha < 2048) {
1183 vu = (vec_s16) vec_sub((vec_u16) vu, sub7);
1184 vv = (vec_s16) vec_sub((vec_u16) vv, sub7);
1185
1186 tmp32 = vec_mule(vu, mul4);
1187 tmp32_2 = vec_mulo(vu, mul4);
1188 vu32_l = vec_mergeh(tmp32, tmp32_2);
1189 vu32_r = vec_mergel(tmp32, tmp32_2);
1190 tmp32 = vec_mule(vv, mul4);
1191 tmp32_2 = vec_mulo(vv, mul4);
1192 vv32_l = vec_mergeh(tmp32, tmp32_2);
1193 vv32_r = vec_mergel(tmp32, tmp32_2);
1194 } else {
1195 tmp16 = vec_ld(0, &ubuf1[i]);
1196 vu = vec_add(vu, tmp16);
1197 vu = (vec_s16) vec_sub((vec_u16) vu, sub8);
1198 tmp16 = vec_ld(0, &vbuf1[i]);
1199 vv = vec_add(vv, tmp16);
1200 vv = (vec_s16) vec_sub((vec_u16) vv, sub8);
1201
1202 vu32_l = vec_mule(vu, mul8);
1203 vu32_r = vec_mulo(vu, mul8);
1204 vv32_l = vec_mule(vv, mul8);
1205 vv32_r = vec_mulo(vv, mul8);
1206 }
1207
1208 if (hasAlpha) {
1209 A = vec_ld(0, &abuf0[i]);
1210 A = vec_add(A, add64);
1211 A = vec_sr(A, shift7);
1212 A = vec_max(A, max255);
1213 ad = vec_packsu(A, (vec_s16) zero16);
1214 } else {
1215 ad = vec_splats((uint8_t) 255);
1216 }
1217
1218 vy32_l = vec_sub(vy32_l, y_offset);
1219 vy32_r = vec_sub(vy32_r, y_offset);
1220 vy32_l = vec_mul(vy32_l, y_coeff);
1221 vy32_r = vec_mul(vy32_r, y_coeff);
1222 vy32_l = vec_add(vy32_l, y_add);
1223 vy32_r = vec_add(vy32_r, y_add);
1224
1225 // Use the first UV half
1226 vud32_l = vec_perm(vu32_l, vu32_l, doubleleft);
1227 vud32_r = vec_perm(vu32_l, vu32_l, doubleright);
1228 vvd32_l = vec_perm(vv32_l, vv32_l, doubleleft);
1229 vvd32_r = vec_perm(vv32_l, vv32_l, doubleright);
1230
1231 R_l = vec_mul(vvd32_l, v2r_coeff);
1232 R_l = vec_add(R_l, vy32_l);
1233 R_r = vec_mul(vvd32_r, v2r_coeff);
1234 R_r = vec_add(R_r, vy32_r);
1235 G_l = vec_mul(vvd32_l, v2g_coeff);
1236 tmp32 = vec_mul(vud32_l, u2g_coeff);
1237 G_l = vec_add(G_l, vy32_l);
1238 G_l = vec_add(G_l, tmp32);
1239 G_r = vec_mul(vvd32_r, v2g_coeff);
1240 tmp32 = vec_mul(vud32_r, u2g_coeff);
1241 G_r = vec_add(G_r, vy32_r);
1242 G_r = vec_add(G_r, tmp32);
1243
1244 B_l = vec_mul(vud32_l, u2b_coeff);
1245 B_l = vec_add(B_l, vy32_l);
1246 B_r = vec_mul(vud32_r, u2b_coeff);
1247 B_r = vec_add(B_r, vy32_r);
1248
1249 WRITERGB
1250
1251 // New Y for the second half
1252 vy = vec_ld(16, &buf0[i * 2]);
1253 vy32_l = vec_unpackh(vy);
1254 vy32_r = vec_unpackl(vy);
1255 vy32_l = vec_sl(vy32_l, shift2);
1256 vy32_r = vec_sl(vy32_r, shift2);
1257
1258 vy32_l = vec_sub(vy32_l, y_offset);
1259 vy32_r = vec_sub(vy32_r, y_offset);
1260 vy32_l = vec_mul(vy32_l, y_coeff);
1261 vy32_r = vec_mul(vy32_r, y_coeff);
1262 vy32_l = vec_add(vy32_l, y_add);
1263 vy32_r = vec_add(vy32_r, y_add);
1264
1265 // Second UV half
1266 vud32_l = vec_perm(vu32_r, vu32_r, doubleleft);
1267 vud32_r = vec_perm(vu32_r, vu32_r, doubleright);
1268 vvd32_l = vec_perm(vv32_r, vv32_r, doubleleft);
1269 vvd32_r = vec_perm(vv32_r, vv32_r, doubleright);
1270
1271 R_l = vec_mul(vvd32_l, v2r_coeff);
1272 R_l = vec_add(R_l, vy32_l);
1273 R_r = vec_mul(vvd32_r, v2r_coeff);
1274 R_r = vec_add(R_r, vy32_r);
1275 G_l = vec_mul(vvd32_l, v2g_coeff);
1276 tmp32 = vec_mul(vud32_l, u2g_coeff);
1277 G_l = vec_add(G_l, vy32_l);
1278 G_l = vec_add(G_l, tmp32);
1279 G_r = vec_mul(vvd32_r, v2g_coeff);
1280 tmp32 = vec_mul(vud32_r, u2g_coeff);
1281 G_r = vec_add(G_r, vy32_r);
1282 G_r = vec_add(G_r, tmp32);
1283
1284 B_l = vec_mul(vud32_l, u2b_coeff);
1285 B_l = vec_add(B_l, vy32_l);
1286 B_r = vec_mul(vud32_r, u2b_coeff);
1287 B_r = vec_add(B_r, vy32_r);
1288
1289 WRITERGB
1290 }
1291}
1292
1293#undef WRITERGB
1294
1295#define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
1296static void name ## ext ## _X_vsx(SwsInternal *c, const int16_t *lumFilter, \
1297 const int16_t **lumSrc, int lumFilterSize, \
1298 const int16_t *chrFilter, const int16_t **chrUSrc, \
1299 const int16_t **chrVSrc, int chrFilterSize, \
1300 const int16_t **alpSrc, uint8_t *dest, int dstW, \
1301 int y) \
1302{ \
1303 name ## base ## _X_vsx_template(c, lumFilter, lumSrc, lumFilterSize, \
1304 chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
1305 alpSrc, dest, dstW, y, fmt, hasAlpha); \
1306}
1307
1308#define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
1309static void name ## ext ## _2_vsx(SwsInternal *c, const int16_t *buf[2], \
1310 const int16_t *ubuf[2], const int16_t *vbuf[2], \
1311 const int16_t *abuf[2], uint8_t *dest, int dstW, \
1312 int yalpha, int uvalpha, int y) \
1313{ \
1314 name ## base ## _2_vsx_template(c, buf, ubuf, vbuf, abuf, \
1315 dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
1316}
1317
1318#define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
1319static void name ## ext ## _1_vsx(SwsInternal *c, const int16_t *buf0, \
1320 const int16_t *ubuf[2], const int16_t *vbuf[2], \
1321 const int16_t *abuf0, uint8_t *dest, int dstW, \
1322 int uvalpha, int y) \
1323{ \
1324 name ## base ## _1_vsx_template(c, buf0, ubuf, vbuf, abuf0, dest, \
1325 dstW, uvalpha, y, fmt, hasAlpha); \
1326}
1327
1328YUV2RGBWRAPPER(yuv2, rgb, bgrx32, AV_PIX_FMT_BGRA, 0)
1329YUV2RGBWRAPPER(yuv2, rgb, rgbx32, AV_PIX_FMT_RGBA, 0)
1330YUV2RGBWRAPPER(yuv2, rgb, xrgb32, AV_PIX_FMT_ARGB, 0)
1331YUV2RGBWRAPPER(yuv2, rgb, xbgr32, AV_PIX_FMT_ABGR, 0)
1332
1333YUV2RGBWRAPPER(yuv2, rgb, rgb24, AV_PIX_FMT_RGB24, 0)
1334YUV2RGBWRAPPER(yuv2, rgb, bgr24, AV_PIX_FMT_BGR24, 0)
1335
1336YUV2RGBWRAPPERX2(yuv2, rgb, bgrx32, AV_PIX_FMT_BGRA, 0)
1337YUV2RGBWRAPPERX2(yuv2, rgb, rgbx32, AV_PIX_FMT_RGBA, 0)
1338YUV2RGBWRAPPERX2(yuv2, rgb, xrgb32, AV_PIX_FMT_ARGB, 0)
1339YUV2RGBWRAPPERX2(yuv2, rgb, xbgr32, AV_PIX_FMT_ABGR, 0)
1340
1341YUV2RGBWRAPPERX2(yuv2, rgb, rgb24, AV_PIX_FMT_RGB24, 0)
1342YUV2RGBWRAPPERX2(yuv2, rgb, bgr24, AV_PIX_FMT_BGR24, 0)
1343
1344YUV2RGBWRAPPER(yuv2, rgb_full, bgrx32_full, AV_PIX_FMT_BGRA, 0)
1345YUV2RGBWRAPPER(yuv2, rgb_full, rgbx32_full, AV_PIX_FMT_RGBA, 0)
1346YUV2RGBWRAPPER(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB, 0)
1347YUV2RGBWRAPPER(yuv2, rgb_full, xbgr32_full, AV_PIX_FMT_ABGR, 0)
1348
1349YUV2RGBWRAPPER(yuv2, rgb_full, rgb24_full, AV_PIX_FMT_RGB24, 0)
1350YUV2RGBWRAPPER(yuv2, rgb_full, bgr24_full, AV_PIX_FMT_BGR24, 0)
1351
1352YUV2RGBWRAPPERX2(yuv2, rgb_full, bgrx32_full, AV_PIX_FMT_BGRA, 0)
1353YUV2RGBWRAPPERX2(yuv2, rgb_full, rgbx32_full, AV_PIX_FMT_RGBA, 0)
1354YUV2RGBWRAPPERX2(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB, 0)
1355YUV2RGBWRAPPERX2(yuv2, rgb_full, xbgr32_full, AV_PIX_FMT_ABGR, 0)
1356
1357YUV2RGBWRAPPERX2(yuv2, rgb_full, rgb24_full, AV_PIX_FMT_RGB24, 0)
1358YUV2RGBWRAPPERX2(yuv2, rgb_full, bgr24_full, AV_PIX_FMT_BGR24, 0)
1359
1360YUV2RGBWRAPPERX(yuv2, rgb_full, bgrx32_full, AV_PIX_FMT_BGRA, 0)
1361YUV2RGBWRAPPERX(yuv2, rgb_full, rgbx32_full, AV_PIX_FMT_RGBA, 0)
1362YUV2RGBWRAPPERX(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB, 0)
1363YUV2RGBWRAPPERX(yuv2, rgb_full, xbgr32_full, AV_PIX_FMT_ABGR, 0)
1364
1365YUV2RGBWRAPPERX(yuv2, rgb_full, rgb24_full, AV_PIX_FMT_RGB24, 0)
1366YUV2RGBWRAPPERX(yuv2, rgb_full, bgr24_full, AV_PIX_FMT_BGR24, 0)
1367
1368static av_always_inline void
1369write422(const vec_s16 vy1, const vec_s16 vy2,
1370 const vec_s16 vu, const vec_s16 vv,
1371 uint8_t *dest, const enum AVPixelFormat target)
1372{
1373 vec_u8 vd1, vd2, tmp;
1374 const vec_u8 yuyv1 = (vec_u8) {
1375 0x0, 0x10, 0x1, 0x18,
1376 0x2, 0x11, 0x3, 0x19,
1377 0x4, 0x12, 0x5, 0x1a,
1378 0x6, 0x13, 0x7, 0x1b };
1379 const vec_u8 yuyv2 = (vec_u8) {
1380 0x8, 0x14, 0x9, 0x1c,
1381 0xa, 0x15, 0xb, 0x1d,
1382 0xc, 0x16, 0xd, 0x1e,
1383 0xe, 0x17, 0xf, 0x1f };
1384 const vec_u8 yvyu1 = (vec_u8) {
1385 0x0, 0x18, 0x1, 0x10,
1386 0x2, 0x19, 0x3, 0x11,
1387 0x4, 0x1a, 0x5, 0x12,
1388 0x6, 0x1b, 0x7, 0x13 };
1389 const vec_u8 yvyu2 = (vec_u8) {
1390 0x8, 0x1c, 0x9, 0x14,
1391 0xa, 0x1d, 0xb, 0x15,
1392 0xc, 0x1e, 0xd, 0x16,
1393 0xe, 0x1f, 0xf, 0x17 };
1394 const vec_u8 uyvy1 = (vec_u8) {
1395 0x10, 0x0, 0x18, 0x1,
1396 0x11, 0x2, 0x19, 0x3,
1397 0x12, 0x4, 0x1a, 0x5,
1398 0x13, 0x6, 0x1b, 0x7 };
1399 const vec_u8 uyvy2 = (vec_u8) {
1400 0x14, 0x8, 0x1c, 0x9,
1401 0x15, 0xa, 0x1d, 0xb,
1402 0x16, 0xc, 0x1e, 0xd,
1403 0x17, 0xe, 0x1f, 0xf };
1404
1405 vd1 = vec_packsu(vy1, vy2);
1406 vd2 = vec_packsu(vu, vv);
1407
1408 switch (target) {
1409 case AV_PIX_FMT_YUYV422:
1410 tmp = vec_perm(vd1, vd2, yuyv1);
1411 vec_st(tmp, 0, dest);
1412 tmp = vec_perm(vd1, vd2, yuyv2);
1413 vec_st(tmp, 16, dest);
1414 break;
1415 case AV_PIX_FMT_YVYU422:
1416 tmp = vec_perm(vd1, vd2, yvyu1);
1417 vec_st(tmp, 0, dest);
1418 tmp = vec_perm(vd1, vd2, yvyu2);
1419 vec_st(tmp, 16, dest);
1420 break;
1421 case AV_PIX_FMT_UYVY422:
1422 tmp = vec_perm(vd1, vd2, uyvy1);
1423 vec_st(tmp, 0, dest);
1424 tmp = vec_perm(vd1, vd2, uyvy2);
1425 vec_st(tmp, 16, dest);
1426 break;
1427 }
1428}
1429
1430static av_always_inline void
1431yuv2422_X_vsx_template(SwsInternal *c, const int16_t *lumFilter,
1432 const int16_t **lumSrc, int lumFilterSize,
1433 const int16_t *chrFilter, const int16_t **chrUSrc,
1434 const int16_t **chrVSrc, int chrFilterSize,
1435 const int16_t **alpSrc, uint8_t *dest, int dstW,
1436 int y, enum AVPixelFormat target)
1437{
1438 int i, j;
1439 vec_s16 vy1, vy2, vu, vv;
1440 vec_s32 vy32[4], vu32[2], vv32[2], tmp, tmp2, tmp3, tmp4;
1441 vec_s16 vlumFilter[MAX_FILTER_SIZE], vchrFilter[MAX_FILTER_SIZE];
1442 const vec_s32 start = vec_splats(1 << 18);
1443 const vec_u32 shift19 = vec_splats(19U);
1444
1445 for (i = 0; i < lumFilterSize; i++)
1446 vlumFilter[i] = vec_splats(lumFilter[i]);
1447 for (i = 0; i < chrFilterSize; i++)
1448 vchrFilter[i] = vec_splats(chrFilter[i]);
1449
1450 for (i = 0; i < ((dstW + 1) >> 1); i += 8) {
1451 vy32[0] =
1452 vy32[1] =
1453 vy32[2] =
1454 vy32[3] =
1455 vu32[0] =
1456 vu32[1] =
1457 vv32[0] =
1458 vv32[1] = start;
1459
1460 for (j = 0; j < lumFilterSize; j++) {
1461 vv = vec_ld(0, &lumSrc[j][i * 2]);
1462 tmp = vec_mule(vv, vlumFilter[j]);
1463 tmp2 = vec_mulo(vv, vlumFilter[j]);
1464 tmp3 = vec_mergeh(tmp, tmp2);
1465 tmp4 = vec_mergel(tmp, tmp2);
1466
1467 vy32[0] = vec_adds(vy32[0], tmp3);
1468 vy32[1] = vec_adds(vy32[1], tmp4);
1469
1470 vv = vec_ld(0, &lumSrc[j][(i + 4) * 2]);
1471 tmp = vec_mule(vv, vlumFilter[j]);
1472 tmp2 = vec_mulo(vv, vlumFilter[j]);
1473 tmp3 = vec_mergeh(tmp, tmp2);
1474 tmp4 = vec_mergel(tmp, tmp2);
1475
1476 vy32[2] = vec_adds(vy32[2], tmp3);
1477 vy32[3] = vec_adds(vy32[3], tmp4);
1478 }
1479
1480 for (j = 0; j < chrFilterSize; j++) {
1481 vv = vec_ld(0, &chrUSrc[j][i]);
1482 tmp = vec_mule(vv, vchrFilter[j]);
1483 tmp2 = vec_mulo(vv, vchrFilter[j]);
1484 tmp3 = vec_mergeh(tmp, tmp2);
1485 tmp4 = vec_mergel(tmp, tmp2);
1486
1487 vu32[0] = vec_adds(vu32[0], tmp3);
1488 vu32[1] = vec_adds(vu32[1], tmp4);
1489
1490 vv = vec_ld(0, &chrVSrc[j][i]);
1491 tmp = vec_mule(vv, vchrFilter[j]);
1492 tmp2 = vec_mulo(vv, vchrFilter[j]);
1493 tmp3 = vec_mergeh(tmp, tmp2);
1494 tmp4 = vec_mergel(tmp, tmp2);
1495
1496 vv32[0] = vec_adds(vv32[0], tmp3);
1497 vv32[1] = vec_adds(vv32[1], tmp4);
1498 }
1499
1500 for (j = 0; j < 4; j++) {
1501 vy32[j] = vec_sra(vy32[j], shift19);
1502 }
1503 for (j = 0; j < 2; j++) {
1504 vu32[j] = vec_sra(vu32[j], shift19);
1505 vv32[j] = vec_sra(vv32[j], shift19);
1506 }
1507
1508 vy1 = vec_packs(vy32[0], vy32[1]);
1509 vy2 = vec_packs(vy32[2], vy32[3]);
1510 vu = vec_packs(vu32[0], vu32[1]);
1511 vv = vec_packs(vv32[0], vv32[1]);
1512
1513 write422(vy1, vy2, vu, vv, &dest[i * 4], target);
1514 }
1515}
1516
1517#define SETUP(x, buf0, buf1, alpha) { \
1518 x = vec_ld(0, buf0); \
1519 tmp = vec_mule(x, alpha); \
1520 tmp2 = vec_mulo(x, alpha); \
1521 tmp3 = vec_mergeh(tmp, tmp2); \
1522 tmp4 = vec_mergel(tmp, tmp2); \
1523\
1524 x = vec_ld(0, buf1); \
1525 tmp = vec_mule(x, alpha); \
1526 tmp2 = vec_mulo(x, alpha); \
1527 tmp5 = vec_mergeh(tmp, tmp2); \
1528 tmp6 = vec_mergel(tmp, tmp2); \
1529\
1530 tmp3 = vec_add(tmp3, tmp5); \
1531 tmp4 = vec_add(tmp4, tmp6); \
1532\
1533 tmp3 = vec_sra(tmp3, shift19); \
1534 tmp4 = vec_sra(tmp4, shift19); \
1535 x = vec_packs(tmp3, tmp4); \
1536}
1537
1538static av_always_inline void
1539yuv2422_2_vsx_template(SwsInternal *c, const int16_t *buf[2],
1540 const int16_t *ubuf[2], const int16_t *vbuf[2],
1541 const int16_t *abuf[2], uint8_t *dest, int dstW,
1542 int yalpha, int uvalpha, int y,
1543 enum AVPixelFormat target)
1544{
1545 const int16_t *buf0 = buf[0], *buf1 = buf[1],
1546 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1547 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
1548 const int16_t yalpha1 = 4096 - yalpha;
1549 const int16_t uvalpha1 = 4096 - uvalpha;
1550 vec_s16 vy1, vy2, vu, vv;
1551 vec_s32 tmp, tmp2, tmp3, tmp4, tmp5, tmp6;
1552 const vec_s16 vyalpha1 = vec_splats(yalpha1);
1553 const vec_s16 vuvalpha1 = vec_splats(uvalpha1);
1554 const vec_u32 shift19 = vec_splats(19U);
1555 int i;
1556 av_assert2(yalpha <= 4096U);
1557 av_assert2(uvalpha <= 4096U);
1558
1559 for (i = 0; i < ((dstW + 1) >> 1); i += 8) {
1560
1561 SETUP(vy1, &buf0[i * 2], &buf1[i * 2], vyalpha1)
1562 SETUP(vy2, &buf0[(i + 4) * 2], &buf1[(i + 4) * 2], vyalpha1)
1563 SETUP(vu, &ubuf0[i], &ubuf1[i], vuvalpha1)
1564 SETUP(vv, &vbuf0[i], &vbuf1[i], vuvalpha1)
1565
1566 write422(vy1, vy2, vu, vv, &dest[i * 4], target);
1567 }
1568}
1569
1570#undef SETUP
1571
1572static av_always_inline void
1574 const int16_t *ubuf[2], const int16_t *vbuf[2],
1575 const int16_t *abuf0, uint8_t *dest, int dstW,
1576 int uvalpha, int y, enum AVPixelFormat target)
1577{
1578 const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1579 vec_s16 vy1, vy2, vu, vv, tmp;
1580 const vec_s16 add64 = vec_splats((int16_t) 64);
1581 const vec_s16 add128 = vec_splats((int16_t) 128);
1582 const vec_u16 shift7 = vec_splat_u16(7);
1583 const vec_u16 shift8 = vec_splat_u16(8);
1584 int i;
1585
1586 if (uvalpha < 2048) {
1587 for (i = 0; i < ((dstW + 1) >> 1); i += 8) {
1588 vy1 = vec_ld(0, &buf0[i * 2]);
1589 vy2 = vec_ld(0, &buf0[(i + 4) * 2]);
1590 vu = vec_ld(0, &ubuf0[i]);
1591 vv = vec_ld(0, &vbuf0[i]);
1592
1593 vy1 = vec_add(vy1, add64);
1594 vy2 = vec_add(vy2, add64);
1595 vu = vec_add(vu, add64);
1596 vv = vec_add(vv, add64);
1597
1598 vy1 = vec_sra(vy1, shift7);
1599 vy2 = vec_sra(vy2, shift7);
1600 vu = vec_sra(vu, shift7);
1601 vv = vec_sra(vv, shift7);
1602
1603 write422(vy1, vy2, vu, vv, &dest[i * 4], target);
1604 }
1605 } else {
1606 const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1607 for (i = 0; i < ((dstW + 1) >> 1); i += 8) {
1608 vy1 = vec_ld(0, &buf0[i * 2]);
1609 vy2 = vec_ld(0, &buf0[(i + 4) * 2]);
1610 vu = vec_ld(0, &ubuf0[i]);
1611 tmp = vec_ld(0, &ubuf1[i]);
1612 vu = vec_adds(vu, tmp);
1613 vv = vec_ld(0, &vbuf0[i]);
1614 tmp = vec_ld(0, &vbuf1[i]);
1615 vv = vec_adds(vv, tmp);
1616
1617 vy1 = vec_add(vy1, add64);
1618 vy2 = vec_add(vy2, add64);
1619 vu = vec_adds(vu, add128);
1620 vv = vec_adds(vv, add128);
1621
1622 vy1 = vec_sra(vy1, shift7);
1623 vy2 = vec_sra(vy2, shift7);
1624 vu = vec_sra(vu, shift8);
1625 vv = vec_sra(vv, shift8);
1626
1627 write422(vy1, vy2, vu, vv, &dest[i * 4], target);
1628 }
1629 }
1630}
1631
1632#define YUV2PACKEDWRAPPERX(name, base, ext, fmt) \
1633static void name ## ext ## _X_vsx(SwsInternal *c, const int16_t *lumFilter, \
1634 const int16_t **lumSrc, int lumFilterSize, \
1635 const int16_t *chrFilter, const int16_t **chrUSrc, \
1636 const int16_t **chrVSrc, int chrFilterSize, \
1637 const int16_t **alpSrc, uint8_t *dest, int dstW, \
1638 int y) \
1639{ \
1640 name ## base ## _X_vsx_template(c, lumFilter, lumSrc, lumFilterSize, \
1641 chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
1642 alpSrc, dest, dstW, y, fmt); \
1643}
1644
1645#define YUV2PACKEDWRAPPER2(name, base, ext, fmt) \
1646YUV2PACKEDWRAPPERX(name, base, ext, fmt) \
1647static void name ## ext ## _2_vsx(SwsInternal *c, const int16_t *buf[2], \
1648 const int16_t *ubuf[2], const int16_t *vbuf[2], \
1649 const int16_t *abuf[2], uint8_t *dest, int dstW, \
1650 int yalpha, int uvalpha, int y) \
1651{ \
1652 name ## base ## _2_vsx_template(c, buf, ubuf, vbuf, abuf, \
1653 dest, dstW, yalpha, uvalpha, y, fmt); \
1654}
1655
1656#define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
1657YUV2PACKEDWRAPPER2(name, base, ext, fmt) \
1658static void name ## ext ## _1_vsx(SwsInternal *c, const int16_t *buf0, \
1659 const int16_t *ubuf[2], const int16_t *vbuf[2], \
1660 const int16_t *abuf0, uint8_t *dest, int dstW, \
1661 int uvalpha, int y) \
1662{ \
1663 name ## base ## _1_vsx_template(c, buf0, ubuf, vbuf, \
1664 abuf0, dest, dstW, uvalpha, \
1665 y, fmt); \
1666}
1667
1668YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, AV_PIX_FMT_YUYV422)
1669YUV2PACKEDWRAPPER(yuv2, 422, yvyu422, AV_PIX_FMT_YVYU422)
1670YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422)
1671
1672static void hyscale_fast_vsx(SwsInternal *c, int16_t *dst, int dstWidth,
1673 const uint8_t *src, int srcW, int xInc)
1674{
1675 int i;
1676 unsigned int xpos = 0, xx;
1677 vec_u8 vin, vin2, vperm;
1678 vec_s8 vmul, valpha;
1679 vec_s16 vtmp, vtmp2, vtmp3, vtmp4;
1680 vec_u16 vd_l, vd_r, vcoord16[2];
1681 vec_u32 vcoord[4];
1682 const vec_u32 vadd = (vec_u32) {
1683 0,
1684 xInc * 1,
1685 xInc * 2,
1686 xInc * 3,
1687 };
1688 const vec_u16 vadd16 = (vec_u16) { // Modulo math
1689 0,
1690 xInc * 1,
1691 xInc * 2,
1692 xInc * 3,
1693 xInc * 4,
1694 xInc * 5,
1695 xInc * 6,
1696 xInc * 7,
1697 };
1698 const vec_u32 vshift16 = vec_splats((uint32_t) 16);
1699 const vec_u16 vshift9 = vec_splat_u16(9);
1700 const vec_u8 vzero = vec_splat_u8(0);
1701 const vec_u16 vshift = vec_splat_u16(7);
1702
1703 for (i = 0; i < dstWidth; i += 16) {
1704 vcoord16[0] = vec_splats((uint16_t) xpos);
1705 vcoord16[1] = vec_splats((uint16_t) (xpos + xInc * 8));
1706
1707 vcoord16[0] = vec_add(vcoord16[0], vadd16);
1708 vcoord16[1] = vec_add(vcoord16[1], vadd16);
1709
1710 vcoord16[0] = vec_sr(vcoord16[0], vshift9);
1711 vcoord16[1] = vec_sr(vcoord16[1], vshift9);
1712 valpha = (vec_s8) vec_pack(vcoord16[0], vcoord16[1]);
1713
1714 xx = xpos >> 16;
1715 vin = vec_vsx_ld(0, &src[xx]);
1716
1717 vcoord[0] = vec_splats(xpos & 0xffff);
1718 vcoord[1] = vec_splats((xpos & 0xffff) + xInc * 4);
1719 vcoord[2] = vec_splats((xpos & 0xffff) + xInc * 8);
1720 vcoord[3] = vec_splats((xpos & 0xffff) + xInc * 12);
1721
1722 vcoord[0] = vec_add(vcoord[0], vadd);
1723 vcoord[1] = vec_add(vcoord[1], vadd);
1724 vcoord[2] = vec_add(vcoord[2], vadd);
1725 vcoord[3] = vec_add(vcoord[3], vadd);
1726
1727 vcoord[0] = vec_sr(vcoord[0], vshift16);
1728 vcoord[1] = vec_sr(vcoord[1], vshift16);
1729 vcoord[2] = vec_sr(vcoord[2], vshift16);
1730 vcoord[3] = vec_sr(vcoord[3], vshift16);
1731
1732 vcoord16[0] = vec_pack(vcoord[0], vcoord[1]);
1733 vcoord16[1] = vec_pack(vcoord[2], vcoord[3]);
1734 vperm = vec_pack(vcoord16[0], vcoord16[1]);
1735
1736 vin = vec_perm(vin, vin, vperm);
1737
1738 vin2 = vec_vsx_ld(1, &src[xx]);
1739 vin2 = vec_perm(vin2, vin2, vperm);
1740
1741 vmul = (vec_s8) vec_sub(vin2, vin);
1742 vtmp = vec_mule(vmul, valpha);
1743 vtmp2 = vec_mulo(vmul, valpha);
1744 vtmp3 = vec_mergeh(vtmp, vtmp2);
1745 vtmp4 = vec_mergel(vtmp, vtmp2);
1746
1747 vd_l = (vec_u16) vec_mergeh(vin, vzero);
1748 vd_r = (vec_u16) vec_mergel(vin, vzero);
1749 vd_l = vec_sl(vd_l, vshift);
1750 vd_r = vec_sl(vd_r, vshift);
1751
1752 vd_l = vec_add(vd_l, (vec_u16) vtmp3);
1753 vd_r = vec_add(vd_r, (vec_u16) vtmp4);
1754
1755 vec_st((vec_s16) vd_l, 0, &dst[i]);
1756 vec_st((vec_s16) vd_r, 0, &dst[i + 8]);
1757
1758 xpos += xInc * 16;
1759 }
1760 for (i=dstWidth-1; (i*(int64_t)xInc)>>16 >=srcW-1; i--)
1761 dst[i] = src[srcW-1]*128;
1762}
1763
1764#define HCSCALE(in, out) \
1765 vin = vec_vsx_ld(0, &in[xx]); \
1766 vin = vec_perm(vin, vin, vperm); \
1767\
1768 vin2 = vec_vsx_ld(1, &in[xx]); \
1769 vin2 = vec_perm(vin2, vin2, vperm); \
1770\
1771 vtmp = vec_mule(vin, valphaxor); \
1772 vtmp2 = vec_mulo(vin, valphaxor); \
1773 vtmp3 = vec_mergeh(vtmp, vtmp2); \
1774 vtmp4 = vec_mergel(vtmp, vtmp2); \
1775\
1776 vtmp = vec_mule(vin2, valpha); \
1777 vtmp2 = vec_mulo(vin2, valpha); \
1778 vd_l = vec_mergeh(vtmp, vtmp2); \
1779 vd_r = vec_mergel(vtmp, vtmp2); \
1780\
1781 vd_l = vec_add(vd_l, vtmp3); \
1782 vd_r = vec_add(vd_r, vtmp4); \
1783\
1784 vec_st((vec_s16) vd_l, 0, &out[i]); \
1785 vec_st((vec_s16) vd_r, 0, &out[i + 8])
1786
1787static void hcscale_fast_vsx(SwsInternal *c, int16_t *dst1, int16_t *dst2,
1788 int dstWidth, const uint8_t *src1,
1789 const uint8_t *src2, int srcW, int xInc)
1790{
1791 int i;
1792 unsigned int xpos = 0, xx;
1793 vec_u8 vin, vin2, vperm;
1794 vec_u8 valpha, valphaxor;
1795 vec_u16 vtmp, vtmp2, vtmp3, vtmp4;
1796 vec_u16 vd_l, vd_r, vcoord16[2];
1797 vec_u32 vcoord[4];
1798 const vec_u8 vxor = vec_splats((uint8_t) 127);
1799 const vec_u32 vadd = (vec_u32) {
1800 0,
1801 xInc * 1,
1802 xInc * 2,
1803 xInc * 3,
1804 };
1805 const vec_u16 vadd16 = (vec_u16) { // Modulo math
1806 0,
1807 xInc * 1,
1808 xInc * 2,
1809 xInc * 3,
1810 xInc * 4,
1811 xInc * 5,
1812 xInc * 6,
1813 xInc * 7,
1814 };
1815 const vec_u32 vshift16 = vec_splats((uint32_t) 16);
1816 const vec_u16 vshift9 = vec_splat_u16(9);
1817
1818 for (i = 0; i < dstWidth; i += 16) {
1819 vcoord16[0] = vec_splats((uint16_t) xpos);
1820 vcoord16[1] = vec_splats((uint16_t) (xpos + xInc * 8));
1821
1822 vcoord16[0] = vec_add(vcoord16[0], vadd16);
1823 vcoord16[1] = vec_add(vcoord16[1], vadd16);
1824
1825 vcoord16[0] = vec_sr(vcoord16[0], vshift9);
1826 vcoord16[1] = vec_sr(vcoord16[1], vshift9);
1827 valpha = vec_pack(vcoord16[0], vcoord16[1]);
1828 valphaxor = vec_xor(valpha, vxor);
1829
1830 xx = xpos >> 16;
1831
1832 vcoord[0] = vec_splats(xpos & 0xffff);
1833 vcoord[1] = vec_splats((xpos & 0xffff) + xInc * 4);
1834 vcoord[2] = vec_splats((xpos & 0xffff) + xInc * 8);
1835 vcoord[3] = vec_splats((xpos & 0xffff) + xInc * 12);
1836
1837 vcoord[0] = vec_add(vcoord[0], vadd);
1838 vcoord[1] = vec_add(vcoord[1], vadd);
1839 vcoord[2] = vec_add(vcoord[2], vadd);
1840 vcoord[3] = vec_add(vcoord[3], vadd);
1841
1842 vcoord[0] = vec_sr(vcoord[0], vshift16);
1843 vcoord[1] = vec_sr(vcoord[1], vshift16);
1844 vcoord[2] = vec_sr(vcoord[2], vshift16);
1845 vcoord[3] = vec_sr(vcoord[3], vshift16);
1846
1847 vcoord16[0] = vec_pack(vcoord[0], vcoord[1]);
1848 vcoord16[1] = vec_pack(vcoord[2], vcoord[3]);
1849 vperm = vec_pack(vcoord16[0], vcoord16[1]);
1850
1851 HCSCALE(src1, dst1);
1852 HCSCALE(src2, dst2);
1853
1854 xpos += xInc * 16;
1855 }
1856 for (i=dstWidth-1; (i*(int64_t)xInc)>>16 >=srcW-1; i--) {
1857 dst1[i] = src1[srcW-1]*128;
1858 dst2[i] = src2[srcW-1]*128;
1859 }
1860}
1861
1862#undef HCSCALE
1863
1864static void hScale16To19_vsx(SwsInternal *c, int16_t *_dst, int dstW,
1865 const uint8_t *_src, const int16_t *filter,
1866 const int32_t *filterPos, int filterSize)
1867{
1868 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->opts.src_format);
1869 int i, j;
1870 int32_t *dst = (int32_t *) _dst;
1871 const uint16_t *src = (const uint16_t *) _src;
1872 int bits = desc->comp[0].depth - 1;
1873 int sh = bits - 4;
1874 vec_s16 vfilter, vin;
1875 vec_s32 vout, vtmp, vtmp2, vfilter32_l, vfilter32_r;
1876 const vec_u8 vzero = vec_splat_u8(0);
1877 const vec_u8 vunusedtab[8] = {
1878 (vec_u8) {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
1879 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf},
1880 (vec_u8) {0x0, 0x1, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
1881 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10},
1882 (vec_u8) {0x0, 0x1, 0x2, 0x3, 0x10, 0x10, 0x10, 0x10,
1883 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10},
1884 (vec_u8) {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x10, 0x10,
1885 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10},
1886 (vec_u8) {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
1887 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10},
1888 (vec_u8) {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
1889 0x8, 0x9, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10},
1890 (vec_u8) {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
1891 0x8, 0x9, 0xa, 0xb, 0x10, 0x10, 0x10, 0x10},
1892 (vec_u8) {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
1893 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0x10, 0x10},
1894 };
1895 const vec_u8 vunused = vunusedtab[filterSize % 8];
1896
1897 if ((isAnyRGB(c->opts.src_format) || c->opts.src_format==AV_PIX_FMT_PAL8) && desc->comp[0].depth<16) {
1898 sh = 9;
1899 } else if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) { /* float input are process like uint 16bpc */
1900 sh = 16 - 1 - 4;
1901 }
1902
1903 if (filterSize == 1) {
1904 for (i = 0; i < dstW; i++) {
1905 int srcPos = filterPos[i];
1906 int val = 0;
1907
1908 for (j = 0; j < filterSize; j++) {
1909 val += src[srcPos + j] * filter[filterSize * i + j];
1910 }
1911 // filter=14 bit, input=16 bit, output=30 bit, >> 11 makes 19 bit
1912 dst[i] = FFMIN(val >> sh, (1 << 19) - 1);
1913 }
1914 } else {
1915 for (i = 0; i < dstW; i++) {
1916 const int srcPos = filterPos[i];
1917 vout = vec_splat_s32(0);
1918 for (j = 0; j < filterSize; j += 8) {
1919 vin = (vec_s16) vec_vsx_ld(0, &src[srcPos + j]);
1920 if (j + 8 > filterSize) // Remove the unused elements on the last round
1921 vin = vec_perm(vin, (vec_s16) vzero, vunused);
1922
1923 vfilter = vec_vsx_ld(0, &filter[filterSize * i + j]);
1924 vfilter32_l = vec_unpackh(vfilter);
1925 vfilter32_r = vec_unpackl(vfilter);
1926
1927 vtmp = (vec_s32) vec_mergeh(vin, (vec_s16) vzero);
1928 vtmp2 = (vec_s32) vec_mergel(vin, (vec_s16) vzero);
1929
1930 vtmp = vec_mul(vtmp, vfilter32_l);
1931 vtmp2 = vec_mul(vtmp2, vfilter32_r);
1932
1933 vout = vec_adds(vout, vtmp);
1934 vout = vec_adds(vout, vtmp2);
1935 }
1936 vout = vec_sums(vout, (vec_s32) vzero);
1937 dst[i] = FFMIN(vout[3] >> sh, (1 << 19) - 1);
1938 }
1939 }
1940}
1941
1942static void hScale16To15_vsx(SwsInternal *c, int16_t *dst, int dstW,
1943 const uint8_t *_src, const int16_t *filter,
1944 const int32_t *filterPos, int filterSize)
1945{
1946 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->opts.src_format);
1947 int i, j;
1948 const uint16_t *src = (const uint16_t *) _src;
1949 int sh = desc->comp[0].depth - 1;
1950 vec_s16 vfilter, vin;
1951 vec_s32 vout, vtmp, vtmp2, vfilter32_l, vfilter32_r;
1952 const vec_u8 vzero = vec_splat_u8(0);
1953 const vec_u8 vunusedtab[8] = {
1954 (vec_u8) {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
1955 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf},
1956 (vec_u8) {0x0, 0x1, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
1957 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10},
1958 (vec_u8) {0x0, 0x1, 0x2, 0x3, 0x10, 0x10, 0x10, 0x10,
1959 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10},
1960 (vec_u8) {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x10, 0x10,
1961 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10},
1962 (vec_u8) {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
1963 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10},
1964 (vec_u8) {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
1965 0x8, 0x9, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10},
1966 (vec_u8) {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
1967 0x8, 0x9, 0xa, 0xb, 0x10, 0x10, 0x10, 0x10},
1968 (vec_u8) {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
1969 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0x10, 0x10},
1970 };
1971 const vec_u8 vunused = vunusedtab[filterSize % 8];
1972
1973 if (sh<15) {
1974 sh = isAnyRGB(c->opts.src_format) || c->opts.src_format==AV_PIX_FMT_PAL8 ? 13 : (desc->comp[0].depth - 1);
1975 } else if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) { /* float input are process like uint 16bpc */
1976 sh = 16 - 1;
1977 }
1978
1979 if (filterSize == 1) {
1980 for (i = 0; i < dstW; i++) {
1981 int srcPos = filterPos[i];
1982 int val = 0;
1983
1984 for (j = 0; j < filterSize; j++) {
1985 val += src[srcPos + j] * filter[filterSize * i + j];
1986 }
1987 // filter=14 bit, input=16 bit, output=30 bit, >> 15 makes 15 bit
1988 dst[i] = FFMIN(val >> sh, (1 << 15) - 1);
1989 }
1990 } else {
1991 for (i = 0; i < dstW; i++) {
1992 const int srcPos = filterPos[i];
1993 vout = vec_splat_s32(0);
1994 for (j = 0; j < filterSize; j += 8) {
1995 vin = (vec_s16) vec_vsx_ld(0, &src[srcPos + j]);
1996 if (j + 8 > filterSize) // Remove the unused elements on the last round
1997 vin = vec_perm(vin, (vec_s16) vzero, vunused);
1998
1999 vfilter = vec_vsx_ld(0, &filter[filterSize * i + j]);
2000 vfilter32_l = vec_unpackh(vfilter);
2001 vfilter32_r = vec_unpackl(vfilter);
2002
2003 vtmp = (vec_s32) vec_mergeh(vin, (vec_s16) vzero);
2004 vtmp2 = (vec_s32) vec_mergel(vin, (vec_s16) vzero);
2005
2006 vtmp = vec_mul(vtmp, vfilter32_l);
2007 vtmp2 = vec_mul(vtmp2, vfilter32_r);
2008
2009 vout = vec_adds(vout, vtmp);
2010 vout = vec_adds(vout, vtmp2);
2011 }
2012 vout = vec_sums(vout, (vec_s32) vzero);
2013 dst[i] = FFMIN(vout[3] >> sh, (1 << 15) - 1);
2014 }
2015 }
2016}
2017
2018#endif /* !HAVE_BIGENDIAN */
2019
2021{
2022 enum AVPixelFormat dstFormat = c->opts.dst_format;
2023 const int cpu_flags = av_get_cpu_flags();
2024 const unsigned char power8 = HAVE_POWER8 && cpu_flags & AV_CPU_FLAG_POWER8;
2025
2026#if !HAVE_BIGENDIAN
2027 if (c->srcBpc == 8) {
2028 if (c->dstBpc <= 14) {
2029 c->hyScale = c->hcScale = hScale_real_vsx;
2030 if (c->opts.flags & SWS_FAST_BILINEAR && c->opts.dst_w >= c->opts.src_w && c->chrDstW >= c->chrSrcW) {
2031 c->hyscale_fast = hyscale_fast_vsx;
2032 c->hcscale_fast = hcscale_fast_vsx;
2033 }
2034 }
2035 } else {
2036 if (power8) {
2037 c->hyScale = c->hcScale = c->dstBpc > 14 ? hScale16To19_vsx
2039 }
2040 }
2041 if (!is16BPS(dstFormat) && !isNBPS(dstFormat) && !isSemiPlanarYUV(dstFormat) && !isDataInHighBits(dstFormat) &&
2042 dstFormat != AV_PIX_FMT_GRAYF32BE && dstFormat != AV_PIX_FMT_GRAYF32LE &&
2043 !c->needAlpha) {
2044 c->yuv2planeX = yuv2planeX_vsx;
2045 }
2046#endif
2047
2048 if (!(c->opts.flags & (SWS_BITEXACT | SWS_FULL_CHR_H_INT)) && !c->needAlpha) {
2049 switch (c->dstBpc) {
2050 case 8:
2051 c->yuv2plane1 = yuv2plane1_8_vsx;
2052 break;
2053#if !HAVE_BIGENDIAN
2054 case 9:
2055 c->yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_vsx : yuv2plane1_9LE_vsx;
2056 c->yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_vsx : yuv2planeX_9LE_vsx;
2057 break;
2058 case 10:
2059 c->yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_vsx : yuv2plane1_10LE_vsx;
2060 c->yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_vsx : yuv2planeX_10LE_vsx;
2061 break;
2062 case 12:
2063 c->yuv2plane1 = isBE(dstFormat) ? yuv2plane1_12BE_vsx : yuv2plane1_12LE_vsx;
2064 c->yuv2planeX = isBE(dstFormat) ? yuv2planeX_12BE_vsx : yuv2planeX_12LE_vsx;
2065 break;
2066 case 14:
2067 c->yuv2plane1 = isBE(dstFormat) ? yuv2plane1_14BE_vsx : yuv2plane1_14LE_vsx;
2068 c->yuv2planeX = isBE(dstFormat) ? yuv2planeX_14BE_vsx : yuv2planeX_14LE_vsx;
2069 break;
2070 case 16:
2071 c->yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_vsx : yuv2plane1_16LE_vsx;
2072#if HAVE_POWER8
2074 c->yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_vsx : yuv2planeX_16LE_vsx;
2075 }
2076#endif /* HAVE_POWER8 */
2077 break;
2078#endif /* !HAVE_BIGENDIAN */
2079 }
2080 }
2081
2082 if (c->opts.flags & SWS_BITEXACT)
2083 return;
2084
2085#if !HAVE_BIGENDIAN
2086 if (c->opts.flags & SWS_FULL_CHR_H_INT) {
2087 switch (dstFormat) {
2088 case AV_PIX_FMT_RGB24:
2089 if (power8) {
2090 c->yuv2packed1 = yuv2rgb24_full_1_vsx;
2091 c->yuv2packed2 = yuv2rgb24_full_2_vsx;
2092 c->yuv2packedX = yuv2rgb24_full_X_vsx;
2093 }
2094 break;
2095 case AV_PIX_FMT_BGR24:
2096 if (power8) {
2097 c->yuv2packed1 = yuv2bgr24_full_1_vsx;
2098 c->yuv2packed2 = yuv2bgr24_full_2_vsx;
2099 c->yuv2packedX = yuv2bgr24_full_X_vsx;
2100 }
2101 break;
2102 case AV_PIX_FMT_BGRA:
2103 if (power8) {
2104 if (!c->needAlpha) {
2105 c->yuv2packed1 = yuv2bgrx32_full_1_vsx;
2106 c->yuv2packed2 = yuv2bgrx32_full_2_vsx;
2107 c->yuv2packedX = yuv2bgrx32_full_X_vsx;
2108 }
2109 }
2110 break;
2111 case AV_PIX_FMT_RGBA:
2112 if (power8) {
2113 if (!c->needAlpha) {
2114 c->yuv2packed1 = yuv2rgbx32_full_1_vsx;
2115 c->yuv2packed2 = yuv2rgbx32_full_2_vsx;
2116 c->yuv2packedX = yuv2rgbx32_full_X_vsx;
2117 }
2118 }
2119 break;
2120 case AV_PIX_FMT_ARGB:
2121 if (power8) {
2122 if (!c->needAlpha) {
2123 c->yuv2packed1 = yuv2xrgb32_full_1_vsx;
2124 c->yuv2packed2 = yuv2xrgb32_full_2_vsx;
2125 c->yuv2packedX = yuv2xrgb32_full_X_vsx;
2126 }
2127 }
2128 break;
2129 case AV_PIX_FMT_ABGR:
2130 if (power8) {
2131 if (!c->needAlpha) {
2132 c->yuv2packed1 = yuv2xbgr32_full_1_vsx;
2133 c->yuv2packed2 = yuv2xbgr32_full_2_vsx;
2134 c->yuv2packedX = yuv2xbgr32_full_X_vsx;
2135 }
2136 }
2137 break;
2138 }
2139 } else { /* !SWS_FULL_CHR_H_INT */
2140 switch (dstFormat) {
2141 case AV_PIX_FMT_YUYV422:
2142 c->yuv2packed1 = yuv2yuyv422_1_vsx;
2143 c->yuv2packed2 = yuv2yuyv422_2_vsx;
2144 c->yuv2packedX = yuv2yuyv422_X_vsx;
2145 break;
2146 case AV_PIX_FMT_YVYU422:
2147 c->yuv2packed1 = yuv2yvyu422_1_vsx;
2148 c->yuv2packed2 = yuv2yvyu422_2_vsx;
2149 c->yuv2packedX = yuv2yvyu422_X_vsx;
2150 break;
2151 case AV_PIX_FMT_UYVY422:
2152 c->yuv2packed1 = yuv2uyvy422_1_vsx;
2153 c->yuv2packed2 = yuv2uyvy422_2_vsx;
2154 c->yuv2packedX = yuv2uyvy422_X_vsx;
2155 break;
2156 case AV_PIX_FMT_BGRA:
2157 if (power8) {
2158 if (!c->needAlpha) {
2159 c->yuv2packed1 = yuv2bgrx32_1_vsx;
2160 c->yuv2packed2 = yuv2bgrx32_2_vsx;
2161 }
2162 }
2163 break;
2164 case AV_PIX_FMT_RGBA:
2165 if (power8) {
2166 if (!c->needAlpha) {
2167 c->yuv2packed1 = yuv2rgbx32_1_vsx;
2168 c->yuv2packed2 = yuv2rgbx32_2_vsx;
2169 }
2170 }
2171 break;
2172 case AV_PIX_FMT_ARGB:
2173 if (power8) {
2174 if (!c->needAlpha) {
2175 c->yuv2packed1 = yuv2xrgb32_1_vsx;
2176 c->yuv2packed2 = yuv2xrgb32_2_vsx;
2177 }
2178 }
2179 break;
2180 case AV_PIX_FMT_ABGR:
2181 if (power8) {
2182 if (!c->needAlpha) {
2183 c->yuv2packed1 = yuv2xbgr32_1_vsx;
2184 c->yuv2packed2 = yuv2xbgr32_2_vsx;
2185 }
2186 }
2187 break;
2188 case AV_PIX_FMT_RGB24:
2189 if (power8) {
2190 c->yuv2packed1 = yuv2rgb24_1_vsx;
2191 c->yuv2packed2 = yuv2rgb24_2_vsx;
2192 }
2193 break;
2194 case AV_PIX_FMT_BGR24:
2195 if (power8) {
2196 c->yuv2packed1 = yuv2bgr24_1_vsx;
2197 c->yuv2packed2 = yuv2bgr24_2_vsx;
2198 }
2199 break;
2200 }
2201 }
2202#endif /* !HAVE_BIGENDIAN */
2203}
uint8_t * _dst
Definition dsp.h:66
uint8_t ptrdiff_t const uint8_t * _src
Definition dsp.h:66
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
static double val(void *priv, double ch)
Definition aeval.c:77
#define MAX_FILTER_SIZE
#define A(x)
Definition vpx_arith.h:28
int32_t
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition avassert.h:68
static const uint8_t shifts[2][12]
Definition camellia.c:178
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define av_clip_uint8
Definition common.h:106
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static const uint8_t bits[8]
Definition fastaudio.c:100
#define vu32(v)
@ SWS_BITEXACT
Definition swscale.h:178
@ SWS_FAST_BILINEAR
Scaler selection options.
Definition swscale.h:197
@ SWS_FULL_CHR_H_INT
Perform full chroma upsampling when upscaling to RGB.
Definition swscale.h:154
const pixel * src2
unsigned offset
Definition libaomenc.c:763
static int shift(int a, int b)
Definition bonk.c:261
static const uint8_t shift2[6]
Definition dxa.c:50
Macro definitions for various function/variable attributes.
#define av_always_inline
Definition attributes.h:72
#define av_cold
Definition attributes.h:117
static atomic_int cpu_flags
Definition cpu.c:56
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition cpu.c:109
#define AV_CPU_FLAG_POWER8
ISA 2.07.
Definition cpu.h:67
const char * desc
Definition libsvtav1.c:83
#define FFMIN(a, b)
Definition macros.h:49
#define LOCAL_ALIGNED(a, t, v,...)
#define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha)
#define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha)
#define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3484
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
Definition pixdesc.h:158
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition pixfmt.h:75
@ AV_PIX_FMT_GRAYF32LE
IEEE-754 single precision Y, 32bpp, little-endian.
Definition pixfmt.h:364
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition pixfmt.h:99
@ AV_PIX_FMT_YVYU422
packed YUV 4:2:2, 16bpp, Y0 Cr Y1 Cb
Definition pixfmt.h:207
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition pixfmt.h:102
@ AV_PIX_FMT_UYVY422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition pixfmt.h:88
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition pixfmt.h:101
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition pixfmt.h:100
@ AV_PIX_FMT_GRAYF32BE
IEEE-754 single precision Y, 32bpp, big-endian.
Definition pixfmt.h:363
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition pixfmt.h:74
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition pixfmt.h:84
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition pixfmt.h:76
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
Definition rpzaenc.c:60
external API header
static av_always_inline int isDataInHighBits(enum AVPixelFormat pix_fmt)
static av_always_inline int isAnyRGB(enum AVPixelFormat pix_fmt)
static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt)
static av_always_inline int isSemiPlanarYUV(enum AVPixelFormat pix_fmt)
static av_always_inline int isBE(enum AVPixelFormat pix_fmt)
static av_always_inline int isNBPS(enum AVPixelFormat pix_fmt)
static void hScale16To15_vsx(SwsInternal *c, int16_t *dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize)
#define vzero
Definition swscale_vsx.c:35
static av_always_inline void yuv2plane1_16_vsx(const int32_t *src, uint16_t *dest, int dstW, const int big_endian, int output_bits)
static void yuv2planeX_nbps_u(const int16_t *filter, int filterSize, const int16_t **src, uint16_t *dest, int dstW, int big_endian, int output_bits, int start)
static av_always_inline void yuv2rgb_full_2_vsx_template(SwsInternal *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y, enum AVPixelFormat target, int hasAlpha)
static void hScale16To19_vsx(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize)
static void yuv2planeX_nbps_vsx(const int16_t *filter, int filterSize, const int16_t **src, uint16_t *dest, int dstW, int big_endian, int output_bits)
static av_always_inline void yuv2422_X_vsx_template(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, uint8_t *dest, int dstW, int y, enum AVPixelFormat target)
static av_always_inline void yuv2rgb_1_vsx_template(SwsInternal *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target, int hasAlpha)
static void yuv2plane1_8_u(const int16_t *src, uint8_t *dest, int dstW, const uint8_t *dither, int offset, int start)
Definition swscale_vsx.c:90
#define WRITERGB
av_cold void ff_sws_init_swscale_vsx(SwsInternal *c)
#define output_pixel(pos, val)
static av_always_inline void yuv2rgb_full_1_vsx_template(SwsInternal *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target, int hasAlpha)
static void yuv2plane1_8_vsx(const int16_t *src, uint8_t *dest, int dstW, const uint8_t *dither, int offset)
static av_always_inline void yuv2422_1_vsx_template(SwsInternal *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target)
static av_always_inline void yuv2plane1_nbps_vsx(const int16_t *src, uint16_t *dest, int dstW, const int big_endian, const int output_bits)
static void yuv2plane1_nbps_u(const int16_t *src, uint16_t *dest, int dstW, int big_endian, int output_bits, int start)
#define HCSCALE(in, out)
#define yuv2NBPSX(bits, BE_LE, is_be, template_size, typeX_t)
static void hcscale_fast_vsx(SwsInternal *c, int16_t *dst1, int16_t *dst2, int dstWidth, const uint8_t *src1, const uint8_t *src2, int srcW, int xInc)
#define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t)
static av_always_inline void yuv2rgb_2_vsx_template(SwsInternal *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y, enum AVPixelFormat target, int hasAlpha)
#define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha)
static av_always_inline void write422(const vec_s16 vy1, const vec_s16 vy2, const vec_s16 vu, const vec_s16 vv, uint8_t *dest, const enum AVPixelFormat target)
static av_always_inline void yuv2422_2_vsx_template(SwsInternal *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y, enum AVPixelFormat target)
#define SETUP(x, buf0, alpha1, buf1, alpha)
static void yuv2plane1_16_u(const int32_t *src, uint16_t *dest, int dstW, int big_endian, int output_bits, int start)
#define yuv2NBPS1(bits, BE_LE, is_be, template_size, typeX_t)
static void hyscale_fast_vsx(SwsInternal *c, int16_t *dst, int dstWidth, const uint8_t *src, int srcW, int xInc)
#define YUV2PACKEDWRAPPER(name, base, ext, fmt)
static uint8_t tmp[40]
Definition aes_ctr.c:52
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
Definition h263dsp.c:29
#define src1
Definition h264pred.c:141
#define src
Definition vp8dsp.c:248
#define mul8(a, b)
Contains misc utility macros and inline functions.
#define vec_s16
#define vec_s8
#define vec_u8
#define vec_u32
#define vec_u16
#define vec_s32
static const uint16_t dither[8][8]
Definition vf_gradfun.c:46
static int bias(int x, int c)
Definition vqcdec.c:115
static double c[64]