Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 2/2] swscale/x86/yuv2yuvX: Process tails by jumping back into the main loop.
@ 2023-09-06 14:25 Alan Kelly via ffmpeg-devel
  2023-09-06 16:37 ` Michael Niedermayer
  0 siblings, 1 reply; 2+ messages in thread
From: Alan Kelly via ffmpeg-devel @ 2023-09-06 14:25 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Alan Kelly

---
 libswscale/x86/swscale.c    | 19 ++++++++-----------
 libswscale/x86/yuv2yuvX.asm | 24 ++++++++++++++++++------
 2 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/libswscale/x86/swscale.c b/libswscale/x86/swscale.c
index 00e42b4bec..6980002e9e 100644
--- a/libswscale/x86/swscale.c
+++ b/libswscale/x86/swscale.c
@@ -194,7 +194,7 @@ static void yuv2yuvX_ ##opt(const int16_t *filter, int filterSize, \
     return; \
 }
 
-#define YUV2YUVX_FUNC(opt, step)  \
+#define YUV2YUVX_FUNC(opt, step, tail)  \
 void ff_yuv2yuvX_ ##opt(const int16_t *filter, int filterSize, int srcOffset, \
                            uint8_t *dest, int dstW,  \
                            const uint8_t *dither, int offset); \
@@ -202,17 +202,14 @@ static void yuv2yuvX_ ##opt(const int16_t *filter, int filterSize, \
                            const int16_t **src, uint8_t *dest, int dstW, \
                            const uint8_t *dither, int offset) \
 { \
-    int remainder = (dstW % step); \
-    int pixelsProcessed = dstW - remainder; \
     if(((uintptr_t)dest) & 15){ \
         yuv2yuvX_mmxext(filter, filterSize, src, dest, dstW, dither, offset); \
         return; \
     } \
-    if(pixelsProcessed > 0) \
-        ff_yuv2yuvX_ ##opt(filter, filterSize - 1, 0, dest - offset, pixelsProcessed + offset, dither, offset); \
-    if(remainder > 0){ \
-      ff_yuv2yuvX_mmxext(filter, filterSize - 1, pixelsProcessed, dest - offset, pixelsProcessed + remainder + offset, dither, offset); \
-    } \
+    if (dstW >= step) \
+        ff_yuv2yuvX_ ##opt(filter, filterSize - 1, 0, dest - offset, dstW + offset, dither, offset); \
+    else \
+        yuv2yuvX_ ##tail(filter, filterSize, src, dest, dstW, dither, offset); \
     return; \
 }
 
@@ -220,13 +217,13 @@ static void yuv2yuvX_ ##opt(const int16_t *filter, int filterSize, \
 YUV2YUVX_FUNC_MMX(mmxext, 16)
 #endif
 #if HAVE_SSE3_EXTERNAL
-YUV2YUVX_FUNC(sse3, 32)
+YUV2YUVX_FUNC(sse3, 32, mmxext)
 #endif
 #if HAVE_AVX2_EXTERNAL
-YUV2YUVX_FUNC(avx2, 64)
+YUV2YUVX_FUNC(avx2, 64, sse3)
 #endif
 #if ARCH_X86_64 && HAVE_AVX512_EXTERNAL
-YUV2YUVX_FUNC(avx512, 128)
+YUV2YUVX_FUNC(avx512, 128, avx2)
 #endif
 
 #define SCALE_FUNC(filter_n, from_bpc, to_bpc, opt) \
diff --git a/libswscale/x86/yuv2yuvX.asm b/libswscale/x86/yuv2yuvX.asm
index 57bfa09d66..03bfd6ad1d 100644
--- a/libswscale/x86/yuv2yuvX.asm
+++ b/libswscale/x86/yuv2yuvX.asm
@@ -54,6 +54,8 @@ cglobal yuv2yuvX, 7, 7, 8, filter, filterSize, src, dest, dstW, dither, offset
 %else
     movq                 xm3, [ditherq]
 %endif ; avx2
+    mov                  ditherq, dstWq
+    sub                  dstWq, mmsize * unroll
 
 %if cpuflag(avx512)
     mova                 m15, [permutation]
@@ -92,13 +94,17 @@ cglobal yuv2yuvX, 7, 7, 8, filter, filterSize, src, dest, dstW, dither, offset
 %else
     mova                 m0, [filterSizeq + 8]
 %endif
-    pmulhw               m2, m0, [srcq + offsetq * 2]
-    pmulhw               m5, m0, [srcq + offsetq * 2 + mmsize]
+    movu                 m2, [srcq + offsetq * 2]
+    movu                 m5, [srcq + offsetq * 2 + mmsize]
+    pmulhw               m2, m0, m2
+    pmulhw               m5, m0, m5
     paddw                m3, m3, m2
     paddw                m4, m4, m5
 %if cpuflag(sse3)
-    pmulhw               m2, m0, [srcq + offsetq * 2 + 2 * mmsize]
-    pmulhw               m5, m0, [srcq + offsetq * 2 + 3 * mmsize]
+    movu                 m2, [srcq + offsetq * 2 + 2 * mmsize]
+    movu                 m5, [srcq + offsetq * 2 + 3 * mmsize]
+    pmulhw               m2, m0, m2
+    pmulhw               m5, m0, m5
     paddw                m6, m6, m2
     paddw                m1, m1, m5
 %endif
@@ -131,8 +137,14 @@ cglobal yuv2yuvX, 7, 7, 8, filter, filterSize, src, dest, dstW, dither, offset
     add                  offsetq, mmsize * unroll
     mov                  filterSizeq, filterq
     cmp                  offsetq, dstWq
-    jb                  .outerloop
-    RET
+    jb                   .outerloop
+
+    mov                  dstWq, offsetq
+    mov                  offsetq, ditherq
+    sub                  offsetq, mmsize * unroll
+    cmp                  dstWq, ditherq
+    jb                   .outerloop
+    REP_RET
 %endmacro
 
 INIT_MMX mmxext
-- 
2.42.0.283.g2d96d420d3-goog

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [FFmpeg-devel] [PATCH 2/2] swscale/x86/yuv2yuvX: Process tails by jumping back into the main loop.
  2023-09-06 14:25 [FFmpeg-devel] [PATCH 2/2] swscale/x86/yuv2yuvX: Process tails by jumping back into the main loop Alan Kelly via ffmpeg-devel
@ 2023-09-06 16:37 ` Michael Niedermayer
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Niedermayer @ 2023-09-06 16:37 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 1251 bytes --]

On Wed, Sep 06, 2023 at 04:25:00PM +0200, Alan Kelly via ffmpeg-devel wrote:
> ---
>  libswscale/x86/swscale.c    | 19 ++++++++-----------
>  libswscale/x86/yuv2yuvX.asm | 24 ++++++++++++++++++------
>  2 files changed, 26 insertions(+), 17 deletions(-)

ffmpeg -i lena.pnm -vf scale=32:32,scale=4:4 -bitexact -y file4x4.jpg

  Duration: N/A, bitrate: N/A
  Stream #0:0: Video: ppm, rgb24, 256x256, 25 fps, 25 tbr, 25 tbn
Stream mapping:
  Stream #0:0 -> #0:0 (ppm (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler @ 0x55763d89b740] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55763d8ab0c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55763d89b740] deprecated pixel format used, make sure you did set range correctly
Segmentation fault (core dumped)

tell me if you cannot reproduce then ill generate a proper backtrace

thx

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Rewriting code that is poorly written but fully understood is good.
Rewriting code that one doesnt understand is a sign that one is less smart
than the original author, trying to rewrite it will not make it better.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-09-06 16:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-06 14:25 [FFmpeg-devel] [PATCH 2/2] swscale/x86/yuv2yuvX: Process tails by jumping back into the main loop Alan Kelly via ffmpeg-devel
2023-09-06 16:37 ` Michael Niedermayer

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git