43 0x0200020002000200LL,};
47 0x0004000400040004LL,};
68 #define COMPILE_TEMPLATE_MMXEXT 0
69 #define RENAME(a) a ## _mmx
74 #if HAVE_MMXEXT_INLINE
76 #undef COMPILE_TEMPLATE_MMXEXT
77 #define COMPILE_TEMPLATE_MMXEXT 1
78 #define RENAME(a) a ## _mmxext
85 const int dstH=
c->dstH;
88 SwsPlane *lumPlane = &
c->slice[
c->numSlice-2].plane[0];
89 SwsPlane *chrUPlane = &
c->slice[
c->numSlice-2].plane[1];
90 SwsPlane *alpPlane = &
c->slice[
c->numSlice-2].plane[3];
92 int hasAlpha =
c->needAlpha;
102 const int chrDstY=
dstY>>
c->chrDstVSubSample;
113 const int16_t **lumSrcPtr = (
const int16_t **)(
void*) lumPlane->
line + firstLumSrcY - lumPlane->
sliceY;
114 const int16_t **chrUSrcPtr = (
const int16_t **)(
void*) chrUPlane->
line + firstChrSrcY - chrUPlane->
sliceY;
115 const int16_t **alpSrcPtr = (CONFIG_SWSCALE_ALPHA && hasAlpha) ? (
const int16_t **)(
void*) alpPlane->
line + firstLumSrcY - alpPlane->
sliceY :
NULL;
118 if (firstLumSrcY < 0 || firstLumSrcY + vLumFilterSize >
c->srcH) {
119 const int16_t **tmpY = (
const int16_t **) lumPlane->
tmp;
122 for (
i = 0;
i < neg;
i++)
123 tmpY[
i] = lumSrcPtr[neg];
124 for ( ;
i <
end;
i++)
125 tmpY[
i] = lumSrcPtr[
i];
131 const int16_t **tmpA = (
const int16_t **) alpPlane->
tmp;
133 tmpA[
i] = alpSrcPtr[neg];
134 for ( ;
i <
end;
i++)
135 tmpA[
i] = alpSrcPtr[
i];
137 tmpA[
i] = tmpA[
i - 1];
141 if (firstChrSrcY < 0 || firstChrSrcY + vChrFilterSize >
c->chrSrcH) {
142 const int16_t **tmpU = (
const int16_t **) chrUPlane->
tmp;
144 for (
i = 0;
i < neg;
i++) {
145 tmpU[
i] = chrUSrcPtr[neg];
147 for ( ;
i <
end;
i++) {
148 tmpU[
i] = chrUSrcPtr[
i];
151 tmpU[
i] = tmpU[
i - 1];
164 if (CONFIG_SWSCALE_ALPHA && hasAlpha) {
184 if (CONFIG_SWSCALE_ALPHA && hasAlpha) {
201 static void yuv2yuvX_sse3(
const int16_t *
filter,
int filterSize,
205 if(((uintptr_t)dest) & 15){
210 #define MAIN_FUNCTION \
211 "pxor %%xmm0, %%xmm0 \n\t" \
212 "punpcklbw %%xmm0, %%xmm3 \n\t" \
213 "movd %4, %%xmm1 \n\t" \
214 "punpcklwd %%xmm1, %%xmm1 \n\t" \
215 "punpckldq %%xmm1, %%xmm1 \n\t" \
216 "punpcklqdq %%xmm1, %%xmm1 \n\t" \
217 "psllw $3, %%xmm1 \n\t" \
218 "paddw %%xmm1, %%xmm3 \n\t" \
219 "psraw $4, %%xmm3 \n\t" \
220 "movdqa %%xmm3, %%xmm4 \n\t" \
221 "movdqa %%xmm3, %%xmm7 \n\t" \
222 "movl %3, %%ecx \n\t" \
223 "mov %0, %%"FF_REG_d" \n\t"\
224 "mov (%%"FF_REG_d"), %%"FF_REG_S" \n\t"\
227 "movddup 8(%%"FF_REG_d"), %%xmm0 \n\t" \
228 "movdqa (%%"FF_REG_S", %%"FF_REG_c", 2), %%xmm2 \n\t" \
229 "movdqa 16(%%"FF_REG_S", %%"FF_REG_c", 2), %%xmm5 \n\t" \
230 "add $16, %%"FF_REG_d" \n\t"\
231 "mov (%%"FF_REG_d"), %%"FF_REG_S" \n\t"\
232 "test %%"FF_REG_S", %%"FF_REG_S" \n\t"\
233 "pmulhw %%xmm0, %%xmm2 \n\t"\
234 "pmulhw %%xmm0, %%xmm5 \n\t"\
235 "paddw %%xmm2, %%xmm3 \n\t"\
236 "paddw %%xmm5, %%xmm4 \n\t"\
238 "psraw $3, %%xmm3 \n\t"\
239 "psraw $3, %%xmm4 \n\t"\
240 "packuswb %%xmm4, %%xmm3 \n\t"\
241 "movntdq %%xmm3, (%1, %%"FF_REG_c") \n\t"\
242 "add $16, %%"FF_REG_c" \n\t"\
243 "cmp %2, %%"FF_REG_c" \n\t"\
244 "movdqa %%xmm7, %%xmm3 \n\t" \
245 "movdqa %%xmm7, %%xmm4 \n\t" \
246 "mov %0, %%"FF_REG_d" \n\t"\
247 "mov (%%"FF_REG_d"), %%"FF_REG_S" \n\t"\
252 "movq %5, %%xmm3 \n\t"
253 "movdqa %%xmm3, %%xmm4 \n\t"
254 "psrlq $24, %%xmm3 \n\t"
255 "psllq $40, %%xmm4 \n\t"
256 "por %%xmm4, %%xmm3 \n\t"
260 "m"(filterSize),
"m"(((uint64_t *)
dither)[0])
261 :
XMM_CLOBBERS(
"%xmm0" ,
"%xmm1" ,
"%xmm2" ,
"%xmm3" ,
"%xmm4" ,
"%xmm5" ,
"%xmm7" ,)
262 "%"FF_REG_d,
"%"FF_REG_S,
"%"FF_REG_c
266 "movq %5, %%xmm3 \n\t"
270 "m"(filterSize),
"m"(((uint64_t *)
dither)[0])
271 :
XMM_CLOBBERS(
"%xmm0" ,
"%xmm1" ,
"%xmm2" ,
"%xmm3" ,
"%xmm4" ,
"%xmm5" ,
"%xmm7" ,)
272 "%"FF_REG_d,
"%"FF_REG_S,
"%"FF_REG_c
280 #define SCALE_FUNC(filter_n, from_bpc, to_bpc, opt) \
281 void ff_hscale ## from_bpc ## to ## to_bpc ## _ ## filter_n ## _ ## opt( \
282 SwsContext *c, int16_t *data, \
283 int dstW, const uint8_t *src, \
284 const int16_t *filter, \
285 const int32_t *filterPos, int filterSize)
287 #define SCALE_FUNCS(filter_n, opt) \
288 SCALE_FUNC(filter_n, 8, 15, opt); \
289 SCALE_FUNC(filter_n, 9, 15, opt); \
290 SCALE_FUNC(filter_n, 10, 15, opt); \
291 SCALE_FUNC(filter_n, 12, 15, opt); \
292 SCALE_FUNC(filter_n, 14, 15, opt); \
293 SCALE_FUNC(filter_n, 16, 15, opt); \
294 SCALE_FUNC(filter_n, 8, 19, opt); \
295 SCALE_FUNC(filter_n, 9, 19, opt); \
296 SCALE_FUNC(filter_n, 10, 19, opt); \
297 SCALE_FUNC(filter_n, 12, 19, opt); \
298 SCALE_FUNC(filter_n, 14, 19, opt); \
299 SCALE_FUNC(filter_n, 16, 19, opt)
301 #define SCALE_FUNCS_MMX(opt) \
302 SCALE_FUNCS(4, opt); \
303 SCALE_FUNCS(8, opt); \
306 #define SCALE_FUNCS_SSE(opt) \
307 SCALE_FUNCS(4, opt); \
308 SCALE_FUNCS(8, opt); \
309 SCALE_FUNCS(X4, opt); \
319 #define VSCALEX_FUNC(size, opt) \
320 void ff_yuv2planeX_ ## size ## _ ## opt(const int16_t *filter, int filterSize, \
321 const int16_t **src, uint8_t *dest, int dstW, \
322 const uint8_t *dither, int offset)
323 #define VSCALEX_FUNCS(opt) \
324 VSCALEX_FUNC(8, opt); \
325 VSCALEX_FUNC(9, opt); \
326 VSCALEX_FUNC(10, opt)
336 #define VSCALE_FUNC(size, opt) \
337 void ff_yuv2plane1_ ## size ## _ ## opt(const int16_t *src, uint8_t *dst, int dstW, \
338 const uint8_t *dither, int offset)
339 #define VSCALE_FUNCS(opt1, opt2) \
340 VSCALE_FUNC(8, opt1); \
341 VSCALE_FUNC(9, opt2); \
342 VSCALE_FUNC(10, opt2); \
343 VSCALE_FUNC(16, opt1)
352 #define INPUT_Y_FUNC(fmt, opt) \
353 void ff_ ## fmt ## ToY_ ## opt(uint8_t *dst, const uint8_t *src, \
354 const uint8_t *unused1, const uint8_t *unused2, \
355 int w, uint32_t *unused)
356 #define INPUT_UV_FUNC(fmt, opt) \
357 void ff_ ## fmt ## ToUV_ ## opt(uint8_t *dstU, uint8_t *dstV, \
358 const uint8_t *unused0, \
359 const uint8_t *src1, \
360 const uint8_t *src2, \
361 int w, uint32_t *unused)
362 #define INPUT_FUNC(fmt, opt) \
363 INPUT_Y_FUNC(fmt, opt); \
364 INPUT_UV_FUNC(fmt, opt)
365 #define INPUT_FUNCS(opt) \
366 INPUT_FUNC(uyvy, opt); \
367 INPUT_FUNC(yuyv, opt); \
368 INPUT_UV_FUNC(nv12, opt); \
369 INPUT_UV_FUNC(nv21, opt); \
370 INPUT_FUNC(rgba, opt); \
371 INPUT_FUNC(bgra, opt); \
372 INPUT_FUNC(argb, opt); \
373 INPUT_FUNC(abgr, opt); \
374 INPUT_FUNC(rgb24, opt); \
375 INPUT_FUNC(bgr24, opt)
390 sws_init_swscale_mmx(
c);
392 #if HAVE_MMXEXT_INLINE
394 sws_init_swscale_mmxext(
c);
397 c->yuv2planeX = yuv2yuvX_sse3;
401 #define ASSIGN_SCALE_FUNC2(hscalefn, filtersize, opt1, opt2) do { \
402 if (c->srcBpc == 8) { \
403 hscalefn = c->dstBpc <= 14 ? ff_hscale8to15_ ## filtersize ## _ ## opt2 : \
404 ff_hscale8to19_ ## filtersize ## _ ## opt1; \
405 } else if (c->srcBpc == 9) { \
406 hscalefn = c->dstBpc <= 14 ? ff_hscale9to15_ ## filtersize ## _ ## opt2 : \
407 ff_hscale9to19_ ## filtersize ## _ ## opt1; \
408 } else if (c->srcBpc == 10) { \
409 hscalefn = c->dstBpc <= 14 ? ff_hscale10to15_ ## filtersize ## _ ## opt2 : \
410 ff_hscale10to19_ ## filtersize ## _ ## opt1; \
411 } else if (c->srcBpc == 12) { \
412 hscalefn = c->dstBpc <= 14 ? ff_hscale12to15_ ## filtersize ## _ ## opt2 : \
413 ff_hscale12to19_ ## filtersize ## _ ## opt1; \
414 } else if (c->srcBpc == 14 || ((c->srcFormat==AV_PIX_FMT_PAL8||isAnyRGB(c->srcFormat)) && av_pix_fmt_desc_get(c->srcFormat)->comp[0].depth<16)) { \
415 hscalefn = c->dstBpc <= 14 ? ff_hscale14to15_ ## filtersize ## _ ## opt2 : \
416 ff_hscale14to19_ ## filtersize ## _ ## opt1; \
418 av_assert0(c->srcBpc == 16);\
419 hscalefn = c->dstBpc <= 14 ? ff_hscale16to15_ ## filtersize ## _ ## opt2 : \
420 ff_hscale16to19_ ## filtersize ## _ ## opt1; \
423 #define ASSIGN_MMX_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \
424 switch (filtersize) { \
425 case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
426 case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
427 default: ASSIGN_SCALE_FUNC2(hscalefn, X, opt1, opt2); break; \
429 #define ASSIGN_VSCALEX_FUNC(vscalefn, opt, do_16_case, condition_8bit) \
431 case 16: do_16_case; break; \
432 case 10: if (!isBE(c->dstFormat) && c->dstFormat != AV_PIX_FMT_P010LE) vscalefn = ff_yuv2planeX_10_ ## opt; break; \
433 case 9: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2planeX_9_ ## opt; break; \
434 case 8: if ((condition_8bit) && !c->use_mmx_vfilter) vscalefn = ff_yuv2planeX_8_ ## opt; break; \
436 #define ASSIGN_VSCALE_FUNC(vscalefn, opt1, opt2, opt2chk) \
438 case 16: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2plane1_16_ ## opt1; break; \
439 case 10: if (!isBE(c->dstFormat) && c->dstFormat != AV_PIX_FMT_P010LE && opt2chk) vscalefn = ff_yuv2plane1_10_ ## opt2; break; \
440 case 9: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_9_ ## opt2; break; \
441 case 8: vscalefn = ff_yuv2plane1_8_ ## opt1; break; \
442 default: av_assert0(c->dstBpc>8); \
444 #define case_rgb(x, X, opt) \
445 case AV_PIX_FMT_ ## X: \
446 c->lumToYV12 = ff_ ## x ## ToY_ ## opt; \
447 if (!c->chrSrcHSubSample) \
448 c->chrToYV12 = ff_ ## x ## ToUV_ ## opt; \
456 switch (
c->srcFormat) {
458 c->lumToYV12 = ff_yuyvToY_mmx;
460 c->alpToYV12 = ff_uyvyToY_mmx;
463 c->lumToYV12 = ff_yuyvToY_mmx;
464 c->chrToYV12 = ff_yuyvToUV_mmx;
467 c->lumToYV12 = ff_uyvyToY_mmx;
468 c->chrToYV12 = ff_uyvyToUV_mmx;
471 c->chrToYV12 = ff_nv12ToUV_mmx;
474 c->chrToYV12 = ff_nv21ToUV_mmx;
490 #define ASSIGN_SSE_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \
491 switch (filtersize) { \
492 case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
493 case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
494 default: if (filtersize & 4) ASSIGN_SCALE_FUNC2(hscalefn, X4, opt1, opt2); \
495 else ASSIGN_SCALE_FUNC2(hscalefn, X8, opt1, opt2); \
502 HAVE_ALIGNED_STACK || ARCH_X86_64);
505 switch (
c->srcFormat) {
507 c->lumToYV12 = ff_yuyvToY_sse2;
509 c->alpToYV12 = ff_uyvyToY_sse2;
512 c->lumToYV12 = ff_yuyvToY_sse2;
513 c->chrToYV12 = ff_yuyvToUV_sse2;
516 c->lumToYV12 = ff_uyvyToY_sse2;
517 c->chrToYV12 = ff_uyvyToUV_sse2;
520 c->chrToYV12 = ff_nv12ToUV_sse2;
523 c->chrToYV12 = ff_nv21ToUV_sse2;
538 switch (
c->srcFormat) {
550 if (!
isBE(
c->dstFormat))
c->yuv2planeX = ff_yuv2planeX_16_sse4,
551 HAVE_ALIGNED_STACK || ARCH_X86_64);
552 if (
c->dstBpc == 16 && !
isBE(
c->dstFormat))
553 c->yuv2plane1 = ff_yuv2plane1_16_sse4;
558 HAVE_ALIGNED_STACK || ARCH_X86_64);
561 switch (
c->srcFormat) {
563 c->chrToYV12 = ff_yuyvToUV_avx;
566 c->chrToYV12 = ff_uyvyToUV_avx;
569 c->chrToYV12 = ff_nv12ToUV_avx;
572 c->chrToYV12 = ff_nv21ToUV_avx;