From b229f1efd394760f1360c50950807584c33f7906 Mon Sep 17 00:00:00 2001 From: pratham-mcw Date: Sat, 24 Jan 2026 16:12:16 +0530 Subject: [PATCH] Merge pull request #28243 from pratham-mcw:cvfloor-neon-opt core: add NEON support for cvFloor in fast_math.hpp #28243 - This PR adds NEON intrinsics-based implementation for the cvFloor function in fast_math.hpp for Windows-ARM64. - Both float and double overloads now use NEON intrinsics for cvFloor Function. - calchist and calchist1d function uses cvFloor function for its computations. - After adding these changes both functions showed improvement in performance. **Performance Benchmarks:** image See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch --- modules/core/include/opencv2/core/fast_math.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/core/include/opencv2/core/fast_math.hpp b/modules/core/include/opencv2/core/fast_math.hpp index 370f5b439b..48ca333a03 100644 --- a/modules/core/include/opencv2/core/fast_math.hpp +++ b/modules/core/include/opencv2/core/fast_math.hpp @@ -237,6 +237,8 @@ CV_INLINE int cvFloor( double value ) #if defined CV__FASTMATH_ENABLE_GCC_MATH_BUILTINS || \ defined CV__FASTMATH_ENABLE_CLANG_MATH_BUILTINS return (int)__builtin_floor(value); +#elif defined(_MSC_VER) && (defined(_M_ARM64) || defined(_M_ARM64EC)) + return (int)vcvtmd_s64_f64(value); #elif defined __loongarch64 int i; double tmp; @@ -264,6 +266,8 @@ CV_INLINE int cvCeil( double value ) #if defined CV__FASTMATH_ENABLE_GCC_MATH_BUILTINS || \ defined CV__FASTMATH_ENABLE_CLANG_MATH_BUILTINS return (int)__builtin_ceil(value); +#elif defined(_MSC_VER) && (defined(_M_ARM64) || defined(_M_ARM64EC)) + return (int)vcvtpd_s64_f64(value); #elif defined __loongarch64 int i; double tmp; @@ -362,6 +366,8 @@ CV_INLINE int cvFloor( float value ) #if defined CV__FASTMATH_ENABLE_GCC_MATH_BUILTINS || \ defined CV__FASTMATH_ENABLE_CLANG_MATH_BUILTINS return (int)__builtin_floorf(value); +#elif defined(_MSC_VER) && (defined(_M_ARM64) || defined(_M_ARM64EC)) + return (int)vcvtms_s32_f32(value); #elif defined __loongarch__ int i; float tmp; @@ -389,6 +395,8 @@ CV_INLINE int cvCeil( float value ) #if defined CV__FASTMATH_ENABLE_GCC_MATH_BUILTINS || \ defined CV__FASTMATH_ENABLE_CLANG_MATH_BUILTINS return (int)__builtin_ceilf(value); +#elif defined(_MSC_VER) && (defined(_M_ARM64) || defined(_M_ARM64EC)) + return (int)vcvtps_s32_f32(value); #elif defined __loongarch__ int i; float tmp;