From: Andy Wu via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: lpageo@163.com
Subject: [FFmpeg-devel] [PATCH v2] avfilter/x86/vf_nlmeans: add AVX2 safe ssd integral image
Date: Tue, 3 Feb 2026 01:35:57 +0800
Message-ID: <20260202173557.24-1-lpageo@163.com> (raw)
Add an AVX2 implementation of compute_safe_ssd_integral_image used by vf_nlmeans.
checkasm: vf_nlmeans (x86_64, Windows/MSVC)
checkasm: vf_nlmeans (x86_64, Linux/WSL)
bench: (x86_64, Windows/MSVC) ssd_integral_image 1.94x
bench: (x86_64, Linux/WSL) ssd_integral_image 1.60x
Signed-off-by: Andy Wu <lpageo@163.com>
---
v2: wrap duplicated 8-pixel block in a macro
v2: update bench numbers (Linux/WSL and Windows/MSVC)
libavfilter/x86/vf_nlmeans.asm | 81 +++++++++++++++++++++++++++++++
libavfilter/x86/vf_nlmeans_init.c | 9 +++-
2 files changed, 89 insertions(+), 1 deletion(-)
diff --git a/libavfilter/x86/vf_nlmeans.asm b/libavfilter/x86/vf_nlmeans.asm
index 8f57801035..90cbdabe86 100644
--- a/libavfilter/x86/vf_nlmeans.asm
+++ b/libavfilter/x86/vf_nlmeans.asm
@@ -37,6 +37,87 @@ ending_lut: dd -1, -1, -1, -1, -1, -1, -1, -1,\
SECTION .text
+%macro PROCESS_8_SSD_INTEGRAL 0
+ pmovzxbd m0, [s1q + xq]
+ pmovzxbd m1, [s2q + xq]
+ psubd m0, m1
+ pmulld m0, m0
+
+ movu m1, [dst_topq + xq*4]
+ movu m2, [dst_topq + xq*4 - 4]
+ psubd m1, m2
+ paddd m0, m1
+
+ mova m5, m0
+ pslldq m5, 4
+ paddd m0, m5
+ mova m5, m0
+ pslldq m5, 8
+ paddd m0, m5
+ mova m5, m0
+ pslldq m5, 16
+ paddd m0, m5
+
+ vextracti128 xm5, m0, 0
+ pshufd xm5, xm5, 0xff
+ pxor m4, m4
+ vinserti128 m4, m4, xm5, 1
+ paddd m0, m4
+
+ movd xm5, carryd
+ vpbroadcastd m4, xm5
+ paddd m0, m4
+
+ movu [dstq + xq*4], m0
+
+ vextracti128 xm5, m0, 1
+ pshufd xm5, xm5, 0xff
+ movd carryd, xm5
+
+ add xq, 8
+%endmacro
+
+; void ff_compute_safe_ssd_integral_image(uint32_t *dst, ptrdiff_t dst_linesize_32,
+; const uint8_t *s1, ptrdiff_t linesize1,
+; const uint8_t *s2, ptrdiff_t linesize2,
+; int w, int h);
+;
+; Assumptions (see C version):
+; - w is multiple of 16 and w >= 16
+; - h >= 1
+; - dst[-1] and dst_top[-1] are readable
+
+INIT_YMM avx2
+cglobal compute_safe_ssd_integral_image, 8, 14, 6, 0, dst, dst_lz, s1, ls1, s2, ls2, w, h, dst_top, dst_stride, x, carry, tmp
+ mov wd, dword wm
+ mov hd, dword hm
+ movsxd wq, wd
+
+ mov dst_strideq, dst_lzq
+ shl dst_strideq, 2
+ mov dst_topq, dstq
+ sub dst_topq, dst_strideq
+
+.yloop:
+ xor xq, xq
+ mov carryd, [dstq - 4]
+
+.xloop:
+ ; ---- process 8 pixels ----
+ PROCESS_8_SSD_INTEGRAL
+ ; ---- process 8 pixels ----
+ PROCESS_8_SSD_INTEGRAL
+ cmp xq, wq
+ jl .xloop
+
+ add s1q, ls1q
+ add s2q, ls2q
+ add dstq, dst_strideq
+ add dst_topq, dst_strideq
+ dec hd
+ jg .yloop
+ RET
+
; void ff_compute_weights_line(const uint32_t *const iia,
; const uint32_t *const iib,
; const uint32_t *const iid,
diff --git a/libavfilter/x86/vf_nlmeans_init.c b/libavfilter/x86/vf_nlmeans_init.c
index 0adb2c7e8a..5bfdc7e028 100644
--- a/libavfilter/x86/vf_nlmeans_init.c
+++ b/libavfilter/x86/vf_nlmeans_init.c
@@ -20,6 +20,11 @@
#include "libavutil/x86/cpu.h"
#include "libavfilter/vf_nlmeans.h"
+void ff_compute_safe_ssd_integral_image_avx2(uint32_t *dst, ptrdiff_t dst_linesize_32,
+ const uint8_t *s1, ptrdiff_t linesize1,
+ const uint8_t *s2, ptrdiff_t linesize2,
+ int w, int h);
+
void ff_compute_weights_line_avx2(const uint32_t *const iia,
const uint32_t *const iib,
const uint32_t *const iid,
@@ -36,7 +41,9 @@ av_cold void ff_nlmeans_init_x86(NLMeansDSPContext *dsp)
#if ARCH_X86_64
int cpu_flags = av_get_cpu_flags();
- if (EXTERNAL_AVX2_FAST(cpu_flags))
+ if (EXTERNAL_AVX2_FAST(cpu_flags)) {
+ dsp->compute_safe_ssd_integral_image = ff_compute_safe_ssd_integral_image_avx2;
dsp->compute_weights_line = ff_compute_weights_line_avx2;
+ }
#endif
}
--
2.45.1.windows.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
next reply other threads:[~2026-02-02 17:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-02 17:35 Andy Wu via ffmpeg-devel [this message]
2026-02-03 1:39 ` [FFmpeg-devel] " mypopy--- via ffmpeg-devel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260202173557.24-1-lpageo@163.com \
--to=ffmpeg-devel@ffmpeg.org \
--cc=lpageo@163.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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