This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch release/9.1 in repository ffmpeg.
commit 11d7fd5c9d77380eb7e193bdc9c85215dd15a771 Author: Michael Niedermayer <[email protected]> AuthorDate: Fri Nov 13 02:12:01 2026 +0100 Commit: Michael Niedermayer <[email protected]> CommitDate: Thu Nov 19 14:55:53 2026 +0100 swscale/x86: do not write past the width in the MMXEXT packed writers They output blocks of 8 pixels. The last block is moved back so that it ends at the width. Odd widths and widths below 8 use the C writers, which makes scaling to odd width RGB565 and YUYV422 about 2.5 times slower. Fixes: out of array write Fixes: bKTdZBAokzK8 Fixes: sws_scale_poc_final.c Fixes: sws_565_exact.c Fixes: sws_full_sweep.c Out of array write Replicated through API with Valgrind Found-by: Kim Jeongsu with StealthMole (cherry picked from commit ec12f19432d9838d82373f4f5300dfafa965d512) Signed-off-by: Michael Niedermayer <[email protected]> --- libswscale/x86/swscale.c | 8 +++++--- libswscale/x86/swscale_template.c | 30 +++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/libswscale/x86/swscale.c b/libswscale/x86/swscale.c index 013d7374d7..5412d3e576 100644 --- a/libswscale/x86/swscale.c +++ b/libswscale/x86/swscale.c @@ -486,6 +486,8 @@ av_cold void ff_sws_init_swscale_x86(SwsInternal *c) { int cpu_flags = av_get_cpu_flags(); enum AVPixelFormat dst_format = c->opts.dst_format; + av_unused const int use_mmxext_packed_writers = !(c->opts.flags & SWS_FULL_CHR_H_INT) && + c->opts.dst_w >= 8 && !(c->opts.dst_w & 1); c->use_mmx_vfilter = 0; @@ -495,7 +497,7 @@ av_cold void ff_sws_init_swscale_x86(SwsInternal *c) && !(c->opts.flags & SWS_BITEXACT)) { if (c->opts.flags & SWS_ACCURATE_RND) { #if HAVE_MMXEXT_INLINE - if (!(c->opts.flags & SWS_FULL_CHR_H_INT)) { + if (use_mmxext_packed_writers) { switch (c->opts.dst_format) { case AV_PIX_FMT_RGB32: c->yuv2packedX = yuv2rgb32_X_ar_mmxext; break; #if HAVE_X86_6REGS @@ -524,7 +526,7 @@ av_cold void ff_sws_init_swscale_x86(SwsInternal *c) } #endif /* HAVE_SSE2_EXTERNAL */ #if HAVE_MMXEXT_INLINE - if (!(c->opts.flags & SWS_FULL_CHR_H_INT)) { + if (use_mmxext_packed_writers) { switch (c->opts.dst_format) { case AV_PIX_FMT_RGB32: c->yuv2packedX = yuv2rgb32_X_mmxext; break; case AV_PIX_FMT_BGR32: c->yuv2packedX = yuv2bgr32_X_mmxext; break; @@ -540,7 +542,7 @@ av_cold void ff_sws_init_swscale_x86(SwsInternal *c) #endif } #if HAVE_MMXEXT_INLINE - if (!(c->opts.flags & SWS_FULL_CHR_H_INT)) { + if (use_mmxext_packed_writers) { switch (c->opts.dst_format) { case AV_PIX_FMT_RGB32: c->yuv2packed1 = yuv2rgb32_1_mmxext; diff --git a/libswscale/x86/swscale_template.c b/libswscale/x86/swscale_template.c index d8bf06d828..63f7c4a140 100644 --- a/libswscale/x86/swscale_template.c +++ b/libswscale/x86/swscale_template.c @@ -30,11 +30,21 @@ #define REAL_MOVNTQ(a,b) "movntq " #a ", " #b " \n\t" #define MOVNTQ(a,b) REAL_MOVNTQ(a,b) -#define REAL_NEXT_PIXEL_BLOCK(dstw, index) \ - "add $8, "#index" \n\t"\ +#define REAL_NEXT_PIXEL_BLOCK(dstw, index, step_back) \ + "add $16, "#index" \n\t"\ + "cmp "dstw", "#index" \n\t"\ + "lea -8("#index"), "#index" \n\t"\ + " jbe 1b \n\t"\ "cmp "dstw", "#index" \n\t"\ - " jb 1b \n\t" -#define NEXT_PIXEL_BLOCK(dstw, index) REAL_NEXT_PIXEL_BLOCK(dstw, index) + " jae 3f \n\t"\ + "add $8, "#index" \n\t"\ + "sub "dstw", "#index" \n\t"\ + step_back \ + "mov "dstw", "#index" \n\t"\ + "sub $8, "#index" \n\t"\ + " jmp 1b \n\t"\ + "3: \n\t" +#define NEXT_PIXEL_BLOCK(dstw, index, step_back) REAL_NEXT_PIXEL_BLOCK(dstw, index, step_back) #define YSCALEYUV2PACKEDX_UV \ __asm__ volatile(\ @@ -248,7 +258,7 @@ MOVNTQ( q2, 16(dst, index, 4))\ MOVNTQ( q3, 24(dst, index, 4))\ \ - NEXT_PIXEL_BLOCK(dstw, index) + NEXT_PIXEL_BLOCK(dstw, index, ) #define WRITEBGR32(dst, dstw, index, b, g, r, a, q0, q2, q3, t) REAL_WRITEBGR32(dst, dstw, index, b, g, r, a, q0, q2, q3, t) static void RENAME(yuv2rgb32_X_ar)(SwsInternal *c, const int16_t *lumFilter, @@ -365,7 +375,7 @@ static void RENAME(yuv2bgr32_X)(SwsInternal *c, const int16_t *lumFilter, MOVNTQ(%%mm2, (dst, index, 2))\ MOVNTQ(%%mm1, 8(dst, index, 2))\ \ - NEXT_PIXEL_BLOCK(dstw, index) + NEXT_PIXEL_BLOCK(dstw, index, ) #define WRITERGB16(dst, dstw, index) REAL_WRITERGB16(dst, dstw, index) static void RENAME(yuv2rgb565_X_ar)(SwsInternal *c, const int16_t *lumFilter, @@ -436,7 +446,7 @@ static void RENAME(yuv2rgb565_X)(SwsInternal *c, const int16_t *lumFilter, MOVNTQ(%%mm2, (dst, index, 2))\ MOVNTQ(%%mm1, 8(dst, index, 2))\ \ - NEXT_PIXEL_BLOCK(dstw, index) + NEXT_PIXEL_BLOCK(dstw, index, ) #define WRITERGB15(dst, dstw, index) REAL_WRITERGB15(dst, dstw, index) static void RENAME(yuv2rgb555_X_ar)(SwsInternal *c, const int16_t *lumFilter, @@ -527,7 +537,9 @@ static void RENAME(yuv2rgb555_X)(SwsInternal *c, const int16_t *lumFilter, \ "add $24, "#dst" \n\t"\ \ - NEXT_PIXEL_BLOCK(dstw, index) + NEXT_PIXEL_BLOCK(dstw, index, "sub "#index", "#dst" \n\t"\ + "sub "#index", "#dst" \n\t"\ + "sub "#index", "#dst" \n\t") #undef WRITEBGR24 #define WRITEBGR24(dst, dstw, index) WRITEBGR24MMXEXT(dst, dstw, index) @@ -596,7 +608,7 @@ static void RENAME(yuv2bgr24_X)(SwsInternal *c, const int16_t *lumFilter, MOVNTQ(%%mm1, (dst, index, 2))\ MOVNTQ(%%mm7, 8(dst, index, 2))\ \ - NEXT_PIXEL_BLOCK(dstw, index) + NEXT_PIXEL_BLOCK(dstw, index, ) #define WRITEYUY2(dst, dstw, index) REAL_WRITEYUY2(dst, dstw, index) static void RENAME(yuv2yuyv422_X_ar)(SwsInternal *c, const int16_t *lumFilter, -- To stop receiving notification emails like this one, please contact [email protected]. _______________________________________________ ffmpeg-cvslog mailing list -- [email protected] To unsubscribe send an email to [email protected]
