From cf320da17e24a2fb2ea189fac7a57c5e620d8a7e Mon Sep 17 00:00:00 2001 From: pratham-mcw Date: Fri, 25 Jul 2025 16:48:55 +0530 Subject: [PATCH] ximgproc: optimize AdaptiveManifoldFilter::h_filter for ARM64 --- .../src/adaptive_manifold_filter_n.cpp | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/ximgproc/src/adaptive_manifold_filter_n.cpp b/modules/ximgproc/src/adaptive_manifold_filter_n.cpp index 3aa58cafe73..a306ff626bb 100644 --- a/modules/ximgproc/src/adaptive_manifold_filter_n.cpp +++ b/modules/ximgproc/src/adaptive_manifold_filter_n.cpp @@ -520,11 +520,29 @@ void AdaptiveManifoldFilterN::h_filter(const Mat1f& src, Mat& dst, float sigma) float* dst_row = dst.ptr(y); dst_row[0] = src_row[0]; - for (int x = 1; x < src.cols; ++x) + int x = 1; + #if defined(_M_ARM64) + for ( ; x + 1 < src.cols; x += 2 ) { dst_row[x] = src_row[x] + a * (dst_row[x - 1] - src_row[x]); + dst_row[x + 1] = src_row[x + 1] + a * (dst_row[x] - src_row[x + 1]); } - for (int x = src.cols - 2; x >= 0; --x) + #endif + for ( ; x < src.cols; ++x ) + { + dst_row[x] = src_row[x] + a * (dst_row[x - 1] - src_row[x]); + } + + x = src.cols - 2; + + #if defined(_M_ARM64) + for ( ; x - 1 >= 0; x -= 2 ) + { + dst_row[x] = dst_row[x] + a * (dst_row[x + 1] - dst_row[x]); + dst_row[x - 1] = dst_row[x - 1] + a * (dst_row[x] - dst_row[x - 1]); + } + #endif + for ( ; x >= 0; --x ) { dst_row[x] = dst_row[x] + a * (dst_row[x + 1] - dst_row[x]); }