nareshmlx/opencv-pr huggingface dataset:
**File:** modules/python/src2/hdr_parser.py
**Change Type:** modified
**Context:** PR #24074: python: support tuple src for cv::add()/subtract()/...

**Code Changes:**
```diff
@@ -535,6 +535,13 @@ def parse_func_decl(self, decl_str, mat="Mat", docstring=""):
 
         funcname = self.get_dotted_name(funcname)
 
+        # see https://github.com/opencv/opencv/issues/24057
+        is_arithm_op_func = funcname in {"cv.add",
+                                         "cv.subtract",
+                                         "cv.absdiff",
+                                         "cv.multiply",
+                                         "cv.divide"}
```

Review comment:
I belive it is needed. Because these functions have not only `src1` `src2` but also `mask` as InputArray. I think that the mask image should be removed from the correction target. https://docs.opencv.org/4.x/d2/de8/group__core__array.html#ga10ac1bfb180e2cfda1701d06c24fdbd6 ``` void cv::add ( InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), int dtype = -1 ) Python: cv.add( src1, src2[, dst[, mask[, dtype]]] ) -> dst ```
**File:** modules/python/test/test_misc.py
**Change Type:** modified
**Context:** PR #24074: python: support tuple src for cv::add()/subtract()/...

**Code Changes:**
```diff
@@ -42,6 +42,93 @@ def get_conversion_error_msg(value, expected, actual):
 def get_no_exception_msg(value):
     return 'Exception is not risen for {} of type {}'.format(value, type(value).__name__)
 
+
+def rpad(src, dst_size, pad_value=0):
+    """Extend `src` up to `dst_size` with given value.
+
+    Args:
+        src (np.ndarray | tuple | list): 1d array like object to pad.
```

Review comment:
The idea behind: ```python _, max_value = get_limits(x.dtype) y[y == 0] = max_value ``` is to receive zeros in `x` where `y` is padded with zeros. Otherwise, we have to deal with `DivisionByZero` warning. So the proper handling should be a casting `y` to [result type after types promotion by NumPy](https://numpy.org/doc/stable/reference/generated/numpy.result_type.html): ```python dst_dtype = np.result_type(x, y) y = np.array(y).astype(dst_dtype) _, max_value = get_limits(dst_dtype) y[y == 0] = max_value ```
**File:** modules/python/src2/hdr_parser.py
**Change Type:** modified
**Context:** PR #24074: python: support tuple src for cv::add()/subtract()/...

**Code Changes:**
```diff
@@ -535,6 +535,13 @@ def parse_func_decl(self, decl_str, mat="Mat", docstring=""):
 
         funcname = self.get_dotted_name(funcname)
 
+        # see https://github.com/opencv/opencv/issues/24057
+        is_arithm_op_func = funcname in {"cv.add",
+                                         "cv.subtract",
+                                         "cv.absdiff",
+                                         "cv.multiply",
+                                         "cv.divide"}
```

Review comment:
It's true, but the solution looks very fragile at this point, because it relies on things that cannot be checked rather during runtime nor generation time...
**File:** modules/imgproc/src/color_lab.cpp
**Change Type:** modified
**Context:** PR #24132: Rewrite Universal Intrinsic code by using new API: ImgProc module Part 2

**Code Changes:**
```diff
@@ -56,40 +56,38 @@ template<typename _Tp> static inline _Tp splineInterpolate(_Tp x, const _Tp* tab
     return ((tab[3]*x + tab[2])*x + tab[1])*x + tab[0];
 }
 
-#if CV_SIMD
+#if (CV_SIMD || CV_SIMD_SCALABLE)
 
 template<typename _Tp> static inline cv::v_float32 splineInterpolate(const cv::v_float32& x, const _Tp* tab, int n)
 {
     using namespace cv;
```

Review comment:
Why enable this block if following blocks have not been enabled? E.g. line 3944.
**File:** modules/imgproc/src/color_yuv.simd.hpp
**Change Type:** modified
**Context:** PR #24132: Rewrite Universal Intrinsic code by using new API: ImgProc module Part 2

**Code Changes:**
```diff
@@ -49,6 +49,15 @@ void cvtOnePlaneYUVtoBGR(const uchar * src_data, size_t src_step,
 namespace {
 //constants for conversion from/to RGB and YUV, YCrCb according to BT.601
 
+#if CV_SIMD_SCALABLE
+template <class T>
+static void swap(T&a, T&b) {
+    T t = a;
+    a = b;
+    b = t;
```

Review comment:
Maybe it would be better to use a macro or a function here (maybe lambda)? There are several other places where loop unwraps to large chunk of code.
**File:** modules/imgproc/src/color_yuv.simd.hpp
**Change Type:** modified
**Context:** PR #24132: Rewrite Universal Intrinsic code by using new API: ImgProc module Part 2

**Code Changes:**
```diff
@@ -49,6 +49,15 @@ void cvtOnePlaneYUVtoBGR(const uchar * src_data, size_t src_step,
 namespace {
 //constants for conversion from/to RGB and YUV, YCrCb according to BT.601
 
+#if CV_SIMD_SCALABLE
+template <class T>
+static void swap(T&a, T&b) {
+    T t = a;
+    a = b;
+    b = t;
```

Review comment:
Use lambda instead.
**File:** modules/imgproc/src/color_lab.cpp
**Change Type:** modified
**Context:** PR #24132: Rewrite Universal Intrinsic code by using new API: ImgProc module Part 2
**Review Line:** 80

**Code Changes:**
```diff
+        tt0 = vx_load(tab + idx[0]);
+        tt1 = vx_load(tab + idx[1]);
+        tt2 = vx_load(tab + idx[2]);
+        tt3 = vx_load(tab + idx[3]);
+        v_transpose4x4(tt0, tt1, tt2, tt3,
+                        t0,  t1,  t2,  t3);
     }
     else
     {
-        t[0] = v_lut(tab + 0, ix);
-        t[1] = v_lut(tab + 1, ix);
```

Review comment:
Runtime check + macro check looks strange for me. If `CV_SIMD_WIDTH != 16` nothing happen.
**File:** modules/imgproc/src/color_lab.cpp
**Change Type:** modified
**Context:** PR #24132: Rewrite Universal Intrinsic code by using new API: ImgProc module Part 2
**Review Line:** 80

**Code Changes:**
```diff
+        tt0 = vx_load(tab + idx[0]);
+        tt1 = vx_load(tab + idx[1]);
+        tt2 = vx_load(tab + idx[2]);
+        tt3 = vx_load(tab + idx[3]);
+        v_transpose4x4(tt0, tt1, tt2, tt3,
+                        t0,  t1,  t2,  t3);
     }
     else
     {
-        t[0] = v_lut(tab + 0, ix);
-        t[1] = v_lut(tab + 1, ix);
```

Review comment:
Only keep runtime check and update API for scalable code. Test with SSE, AVX2 and RVV.
**File:** modules/imgproc/src/shapedescr.cpp
**Change Type:** modified
**Context:** PR #24166: Rewrite Universal Intrinsic code: ImgProc (CV_SIMD_WIDTH related Part)

**Code Changes:**
```diff
@@ -879,37 +879,37 @@ static Rect pointSetBoundingRect( const Mat& points )
     if( npoints == 0 )
         return Rect();
 
-#if CV_SIMD
+#if CV_SIMD // TODO: enable for CV_SIMD_SCALABLE, loop tail related.
     const int64_t* pts = points.ptr<int64_t>();
 
     if( !is_float )
     {
```

Review comment:
I think it would be better to extract a function or two here to avoid duplication of code.
**File:** modules/imgproc/src/morph.simd.hpp
**Change Type:** modified
**Context:** PR #24166: Rewrite Universal Intrinsic code: ImgProc (CV_SIMD_WIDTH related Part)

**Code Changes:**
```diff
@@ -106,12 +106,12 @@ struct MorphNoVec
     int operator()(uchar**, int, uchar*, int) const { return 0; }
 };
 
-#if CV_SIMD
+#if CV_SIMD // TODO: enable for CV_SIMD_SCALABLE, GCC 13 related
 
 template<class VecUpdate> struct MorphRowVec
 {
     typedef typename VecUpdate::vtype vtype;
```

Review comment:
Shouldn't it be: ```suggestion #if (CV_SIMD || (CV_SIMD_SCALABLE && defined(__clang__)) ``` Otherwise regular CV_SIMD will not work with GCC and MSVC on other platforms.
**File:** modules/imgproc/src/morph.simd.hpp
**Change Type:** modified
**Context:** PR #24166: Rewrite Universal Intrinsic code: ImgProc (CV_SIMD_WIDTH related Part)

**Code Changes:**
```diff
@@ -106,12 +106,12 @@ struct MorphNoVec
     int operator()(uchar**, int, uchar*, int) const { return 0; }
 };
 
-#if CV_SIMD
+#if CV_SIMD // TODO: enable for CV_SIMD_SCALABLE, GCC 13 related
 
 template<class VecUpdate> struct MorphRowVec
 {
     typedef typename VecUpdate::vtype vtype;
```

Review comment:
Both variants don't look correct. It is not a problem of SCALABLE. It is related to GCC for RISC-V platform. BTW, I still recommend to avoid trying to disable code for experimental platforms on mainline branches. Compiler could be fixed, but disabled code is in repository forever.
**File:** modules/imgproc/src/morph.simd.hpp
**Change Type:** modified
**Context:** PR #24166: Rewrite Universal Intrinsic code: ImgProc (CV_SIMD_WIDTH related Part)

**Code Changes:**
```diff
@@ -106,12 +106,12 @@ struct MorphNoVec
     int operator()(uchar**, int, uchar*, int) const { return 0; }
 };
 
-#if CV_SIMD
+#if CV_SIMD // TODO: enable for CV_SIMD_SCALABLE, GCC 13 related
 
 template<class VecUpdate> struct MorphRowVec
 {
     typedef typename VecUpdate::vtype vtype;
```

Review comment:
I got your point about the macro that we need to ensure that this code block is only disable on GCC on the RISC-V platform, then we can use `#if CV_SIMD || (CV_SIMD_SCALABLE && !(defined(__gnu_linux__) && defined(__riscv)))` to disable the code block on riscv gcc. I also got the point that we can keep `#if (CV_SIMD || CV_SIMD_SCALABLE)` and leave the broken part on riscv GCC and wait for GCC upstream to fix it. It also make sence. Which one do we prefer?
**File:** modules/imgproc/src/morph.simd.hpp
**Change Type:** modified
**Context:** PR #24166: Rewrite Universal Intrinsic code: ImgProc (CV_SIMD_WIDTH related Part)

**Code Changes:**
```diff
@@ -106,12 +106,12 @@ struct MorphNoVec
     int operator()(uchar**, int, uchar*, int) const { return 0; }
 };
 
-#if CV_SIMD
+#if CV_SIMD // TODO: enable for CV_SIMD_SCALABLE, GCC 13 related
 
 template<class VecUpdate> struct MorphRowVec
 {
     typedef typename VecUpdate::vtype vtype;
```

Review comment:
Let's disable problematic blocks in SCALABLE mode to avoid breaking more tests, it will help us to establish CI testing. And then we will gradually resolve these issues (whether they are in GCC or qemu or our implementation) and re-enable these blocks. Our main goal is to get rid of obsolete constructions while keeping builds green (gcc-13 and clang-16). It is not necessary to distinguish between clang and gcc, just leave `#if CV_SIMD` and add a `TODO:` comment.
**File:** modules/imgproc/src/shapedescr.cpp
**Change Type:** modified
**Context:** PR #24166: Rewrite Universal Intrinsic code: ImgProc (CV_SIMD_WIDTH related Part)

**Code Changes:**
```diff
@@ -879,37 +879,37 @@ static Rect pointSetBoundingRect( const Mat& points )
     if( npoints == 0 )
         return Rect();
 
-#if CV_SIMD
+#if CV_SIMD // TODO: enable for CV_SIMD_SCALABLE, loop tail related.
     const int64_t* pts = points.ptr<int64_t>();
 
     if( !is_float )
     {
```

Review comment:
Let's also disable this block for SCALABLE mode and revert all unnecessary modifications leaving only automatically replaced intrinsics constructs, otherwise it becomes too complex. This function should be refactored separately: first for wide intrinsics, then for scalable.
**File:** modules/imgproc/src/morph.simd.hpp
**Change Type:** modified
**Context:** PR #24166: Rewrite Universal Intrinsic code: ImgProc (CV_SIMD_WIDTH related Part)

**Code Changes:**
```diff
@@ -106,12 +106,12 @@ struct MorphNoVec
     int operator()(uchar**, int, uchar*, int) const { return 0; }
 };
 
-#if CV_SIMD
+#if CV_SIMD // TODO: enable for CV_SIMD_SCALABLE, GCC 13 related
 
 template<class VecUpdate> struct MorphRowVec
 {
     typedef typename VecUpdate::vtype vtype;
```

Review comment:
Done ``` #if CV_SIMD // TODO: enable for CV_SIMD_SCALABLE, GCC 13 related ```
**File:** modules/imgproc/src/shapedescr.cpp
**Change Type:** modified
**Context:** PR #24166: Rewrite Universal Intrinsic code: ImgProc (CV_SIMD_WIDTH related Part)

**Code Changes:**
```diff
@@ -879,37 +879,37 @@ static Rect pointSetBoundingRect( const Mat& points )
     if( npoints == 0 )
         return Rect();
 
-#if CV_SIMD
+#if CV_SIMD // TODO: enable for CV_SIMD_SCALABLE, loop tail related.
     const int64_t* pts = points.ptr<int64_t>();
 
     if( !is_float )
     {
```

Review comment:
Done ``` #if CV_SIMD // TODO: enable for CV_SIMD_SCALABLE, loop tail related. ```
**File:** modules/imgproc/src/accum.simd.hpp
**Change Type:** modified
**Context:** PR #24058: Rewrite Universal Intrinsic code by using new API: ImgProc module.

**Code Changes:**
```diff
@@ -139,7 +139,7 @@ void acc_general_(const T* src, AT* dst, const uchar* mask, int len, int cn, int
     }
 #if CV_AVX && !CV_AVX2
     _mm256_zeroupper();
-#elif CV_SIMD
+#elif (CV_SIMD || CV_SIMD_SCALABLE)
     vx_cleanup();
 #endif
 }
@@ -187,7 +187,7 @@ accSqr_general_( const T* src, AT* dst, const uchar* mask, int len, int cn, int
```

Review comment:
`CV_SIMD_SCALABLE_64F`?
**File:** modules/imgproc/src/resize.cpp
**Change Type:** modified
**Context:** PR #24058: Rewrite Universal Intrinsic code by using new API: ImgProc module.

**Code Changes:**
```diff
@@ -346,8 +346,8 @@ void hlineResizeCn<uint8_t, ufixedpoint16, 2, true, 1>(uint8_t* src, int, int *o
 {
     int i = 0;
     ufixedpoint16 src_0(src[0]);
-#if CV_SIMD
-    const int VECSZ = v_uint16::nlanes;
+#if (CV_SIMD || CV_SIMD_SCALABLE)
+    const int VECSZ = VTraits<v_uint16>::vlanes();
     v_uint16 v_src_0 = vx_setall_u16(*((uint16_t*)&src_0));
     for (; i <= dst_min - VECSZ; i += VECSZ, m += 2*VECSZ, dst += VECSZ) // Points that fall left from src image so became equal to leftmost src point
```

Review comment:
Shouldn't `CV_SIMD_WIDTH` be replaced with `VTraits<v_uint8>::vlanes`? Or what is the meaning of this condition? Here and below.
**File:** modules/imgproc/src/resize.cpp
**Change Type:** modified
**Context:** PR #24058: Rewrite Universal Intrinsic code by using new API: ImgProc module.
**Review Line:** 2450

**Code Changes:**
```diff
@@ -2452,27 +2447,27 @@ class ResizeAreaFastVec_SIMD_8u
         if (cn == 1)
         {
             v_uint16 masklow = vx_setall_u16(0x00ff);
-            for ( ; dx <= w - v_uint16::nlanes; dx += v_uint16::nlanes, S0 += v_uint8::nlanes, S1 += v_uint8::nlanes, D += v_uint16::nlanes)
+            for ( ; dx <= w - VTraits<v_uint16>::vlanes(); dx += VTraits<v_uint16>::vlanes(), S0 += VTraits<v_uint8>::vlanes(), S1 += VTraits<v_uint8>::vlanes(), D += VTraits<v_uint16>::vlanes())
             {
                 v_uint16 r0 = v_reinterpret_as_u16(vx_load(S0));
                 v_uint16 r1 = v_reinterpret_as_u16(vx_load(S1));
-                v_rshr_pack_store<2>(D, (r0 >> 8) + (r0 & masklow) + (r1 >> 8) + (r1 & masklow));
+                v_rshr_pack_store<2>(D, v_add(v_add(v_add(v_shr<8>(r0), v_and(r0, masklow)), v_shr<8>(r1)), v_and(r1, masklow)));
```

Review comment:
I think this block has not been enabled for `CV_SIMD_SCALABLE`. Line 2433. Or is it intended because of fixed CV_SIMD_WIDTH checks below?
**File:** modules/imgproc/src/resize.cpp
**Change Type:** modified
**Context:** PR #24058: Rewrite Universal Intrinsic code by using new API: ImgProc module.
**Review Line:** 2450

**Code Changes:**
```diff
@@ -2452,27 +2447,27 @@ class ResizeAreaFastVec_SIMD_8u
         if (cn == 1)
         {
             v_uint16 masklow = vx_setall_u16(0x00ff);
-            for ( ; dx <= w - v_uint16::nlanes; dx += v_uint16::nlanes, S0 += v_uint8::nlanes, S1 += v_uint8::nlanes, D += v_uint16::nlanes)
+            for ( ; dx <= w - VTraits<v_uint16>::vlanes(); dx += VTraits<v_uint16>::vlanes(), S0 += VTraits<v_uint8>::vlanes(), S1 += VTraits<v_uint8>::vlanes(), D += VTraits<v_uint16>::vlanes())
             {
                 v_uint16 r0 = v_reinterpret_as_u16(vx_load(S0));
                 v_uint16 r1 = v_reinterpret_as_u16(vx_load(S1));
-                v_rshr_pack_store<2>(D, (r0 >> 8) + (r0 & masklow) + (r1 >> 8) + (r1 & masklow));
+                v_rshr_pack_store<2>(D, v_add(v_add(v_add(v_shr<8>(r0), v_and(r0, masklow)), v_shr<8>(r1)), v_and(r1, masklow)));
```

Review comment:
Yes, I originally rewrote these codes, but later found that these codes cannot be used in the variable length backend due to the `CV_SIMD_WIDTH` checks. Should I revert this part?
**File:** modules/imgproc/src/accum.simd.hpp
**Change Type:** modified
**Context:** PR #24058: Rewrite Universal Intrinsic code by using new API: ImgProc module.

**Code Changes:**
```diff
@@ -139,7 +139,7 @@ void acc_general_(const T* src, AT* dst, const uchar* mask, int len, int cn, int
     }
 #if CV_AVX && !CV_AVX2
     _mm256_zeroupper();
-#elif CV_SIMD
+#elif (CV_SIMD || CV_SIMD_SCALABLE)
     vx_cleanup();
 #endif
 }
@@ -187,7 +187,7 @@ accSqr_general_( const T* src, AT* dst, const uchar* mask, int len, int cn, int
```

Review comment:
Yes, Fixed.
**File:** modules/imgproc/src/resize.cpp
**Change Type:** modified
**Context:** PR #24058: Rewrite Universal Intrinsic code by using new API: ImgProc module.

**Code Changes:**
```diff
@@ -346,8 +346,8 @@ void hlineResizeCn<uint8_t, ufixedpoint16, 2, true, 1>(uint8_t* src, int, int *o
 {
     int i = 0;
     ufixedpoint16 src_0(src[0]);
-#if CV_SIMD
-    const int VECSZ = v_uint16::nlanes;
+#if (CV_SIMD || CV_SIMD_SCALABLE)
+    const int VECSZ = VTraits<v_uint16>::vlanes();
     v_uint16 v_src_0 = vx_setall_u16(*((uint16_t*)&src_0));
     for (; i <= dst_min - VECSZ; i += VECSZ, m += 2*VECSZ, dst += VECSZ) // Points that fall left from src image so became equal to leftmost src point
```

Review comment:
Yes, we should use `VTraits<v_uint8>::vlanes()` here and below. Fixed. And I personally think that the meaning of this condition is to judge whether `S0` and `S1` (as addresses) are aligned with `CV_SIMD_WIDTH` (`CV_SIMD_WIDTH-1` acts as a mask here). If so, we can use` vx_load_aligned`, otherwise use `vx_load`. BTW, the implementation in the two load functions RVV is the same.
**File:** modules/imgproc/src/resize.cpp
**Change Type:** modified
**Context:** PR #24058: Rewrite Universal Intrinsic code by using new API: ImgProc module.
**Review Line:** 2450

**Code Changes:**
```diff
@@ -2452,27 +2447,27 @@ class ResizeAreaFastVec_SIMD_8u
         if (cn == 1)
         {
             v_uint16 masklow = vx_setall_u16(0x00ff);
-            for ( ; dx <= w - v_uint16::nlanes; dx += v_uint16::nlanes, S0 += v_uint8::nlanes, S1 += v_uint8::nlanes, D += v_uint16::nlanes)
+            for ( ; dx <= w - VTraits<v_uint16>::vlanes(); dx += VTraits<v_uint16>::vlanes(), S0 += VTraits<v_uint8>::vlanes(), S1 += VTraits<v_uint8>::vlanes(), D += VTraits<v_uint16>::vlanes())
             {
                 v_uint16 r0 = v_reinterpret_as_u16(vx_load(S0));
                 v_uint16 r1 = v_reinterpret_as_u16(vx_load(S1));
-                v_rshr_pack_store<2>(D, (r0 >> 8) + (r0 & masklow) + (r1 >> 8) + (r1 & masklow));
+                v_rshr_pack_store<2>(D, v_add(v_add(v_add(v_shr<8>(r0), v_and(r0, masklow)), v_shr<8>(r1)), v_and(r1, masklow)));
```

Review comment:
No, let's keep modifications, eventually this part might be updated to be compatible with scalable intrinsics.
**File:** modules/imgproc/src/color_rgb.simd.hpp
**Change Type:** modified
**Context:** PR #24058: Rewrite Universal Intrinsic code by using new API: ImgProc module.
**Review Line:** 145

**Code Changes:**
```diff
-            if(bi == 2)
+            if(bi == 2) {
+                #if CV_SIMD_SCALABLE
+                auto t = a; a = c; c = t; // swap(a, c);
+                #else
                 swap(a, c);
+                #endif
+            }
 
             if(dcn == 4)
             {
```

Review comment:
do we really need the swap branch?
**File:** modules/imgproc/src/color_rgb.simd.hpp
**Change Type:** modified
**Context:** PR #24058: Rewrite Universal Intrinsic code by using new API: ImgProc module.
**Review Line:** 242

**Code Changes:**
```diff
+                #if CV_SIMD_SCALABLE
+                auto t = r; r = b; b = t; // swap(b, r);
+                #else
                 swap(b, r);
-
+                #endif
+            }
             if(dcn == 4)
             {
                 v_store_interleave(dst, b, g, r, a);
@@ -289,8 +298,8 @@ struct RGB2RGB5x5
```

Review comment:
The same for swap
**File:** modules/imgproc/src/pyramids.cpp
**Change Type:** modified
**Context:** PR #24058: Rewrite Universal Intrinsic code by using new API: ImgProc module.

**Code Changes:**
```diff
@@ -84,7 +84,7 @@ template<typename T1, typename T2> int PyrUpVecV(T1**, T2**, int) { return 0; }
 
 template<typename T1, typename T2> int PyrUpVecVOneRow(T1**, T2*, int) { return 0; }
 
-#if CV_SIMD
+#if (CV_SIMD || CV_SIMD_SCALABLE)
 
 template<> int PyrDownVecH<uchar, int, 1>(const uchar* src, int* row, int width)
 {
@@ -93,10 +93,8 @@ template<> int PyrDownVecH<uchar, int, 1>(const uchar* src, int* row, int width)
```

Review comment:
typedef should be inside if CV_SIND128
**File:** modules/imgproc/src/pyramids.cpp
**Change Type:** modified
**Context:** PR #24058: Rewrite Universal Intrinsic code by using new API: ImgProc module.
**Review Line:** 479

**Code Changes:**
```diff
+        t0 = v_add(v_add(v_add(r0, r4), v_add(r2, r2)), v_shl<2>(v_add(v_add(r1, r3), r2)));
 
         *((unaligned_int*) (dst + x)) = v_reinterpret_as_s32(v_rshr_pack<8>(v_pack_u(t0, t0), v_setzero_u16())).get0();
     }
+    #else
+    for (; x <= width - 1; x += 1)
+    {
+        int r0 = *(row0 + x);
+        int r1 = *(row1 + x);
+        int r2 = *(row2 + x);
+        int r3 = *(row3 + x);
```

Review comment:
I suspect, that the branch with plain loop should be outside of `#else` to handle `CV_SIMD128` tails.
**File:** modules/imgproc/src/pyramids.cpp
**Change Type:** modified
**Context:** PR #24058: Rewrite Universal Intrinsic code by using new API: ImgProc module.
**Review Line:** 629

**Code Changes:**
```diff
+        v_int16 d = v_pack(v_add(v_add(v_r00, v_r20), v_add(v_add(v_2r10, v_2r10), v_2r10)), v_shl<2>(v_add(v_r10, v_r20)));
         *(unaligned_int*)(dst0 + x) = v_reinterpret_as_s32(v_rshr_pack_u<6>(d, vx_setzero_s16())).get0();
         *(unaligned_int*)(dst1 + x) = v_reinterpret_as_s32(v_rshr_pack_u<6>(v_combine_high(d, d), vx_setzero_s16())).get0();
     }
+    #else
+    for (; x <= width - 1; x += 1)
+    {
+        int r00 = *(row0 + x),
+            r10 = *(row1 + x),
+            r20 = *(row2 + x);
+        int _2r10 = r10 + r10;
```

Review comment:
The same for CV_SIMD128 tails here.
**File:** modules/imgproc/src/pyramids.cpp
**Change Type:** modified
**Context:** PR #24058: Rewrite Universal Intrinsic code by using new API: ImgProc module.
**Review Line:** 479

**Code Changes:**
```diff
+        t0 = v_add(v_add(v_add(r0, r4), v_add(r2, r2)), v_shl<2>(v_add(v_add(r1, r3), r2)));
 
         *((unaligned_int*) (dst + x)) = v_reinterpret_as_s32(v_rshr_pack<8>(v_pack_u(t0, t0), v_setzero_u16())).get0();
     }
+    #else
+    for (; x <= width - 1; x += 1)
+    {
+        int r0 = *(row0 + x);
+        int r1 = *(row1 + x);
+        int r2 = *(row2 + x);
+        int r3 = *(row3 + x);
```

Review comment:
The `CV_SIMD128` code block does not seem to encounter the tails, because the data is 128-bit aligned, as follows: 1. In the `CV_SIMD128` code block, for `row0~row4`, each loop loads and processes 128-bit data. 2. The `row0~row4` are `src[0]~src[4]` respectively, coming from the parameter `int** src` 3. For the call to the `PyrDownVecV` function (only one), `WT* rows[PD_SZ]` is passed in as argument. 4. The size of `rows[0]~rows[4]` is determined by `buf` and `bufstep`, and they are 16byte aligned, that is, 128-bit. ``` int bufstep = (int)alignSize(dsize.width*cn, 16); //line 928 WT* buf = alignPtr((WT*)_buf.data(), 16); //line 930 ``` If the above analysis is correct, then I think the plain loop should only work on non-CV_SIMD128 cases, that is, in `#else` BTW, this part of the code has been working like this for many years, which may indirectly means that the original implementation (128-fixed related code) does not need to consider the tail.
**File:** modules/core/test/test_operations.cpp
**Change Type:** modified
**Context:** PR #24260: Fix undefined behavior arithmetic in copyMakeBorder and adjustROI.
**Review Line:** 1388

**Code Changes:**
```diff
+{
+    Mat m(6, 6, CV_8U);
+    Mat roi(m, cv::Range(2, 4), cv::Range(2, 4));
+    // This could trigger a (negative int)*size_t when updating data,
+    // which is undefined behavior.
+    roi.adjustROI(2, 2, 2, 2);
+    EXPECT_EQ(m.data, roi.data);
+}
 
 CV_ENUM(SortRowCol, SORT_EVERY_COLUMN, SORT_EVERY_ROW)
 CV_ENUM(SortOrder, SORT_ASCENDING, SORT_DESCENDING)
```

Review comment:
I propose to add some check here.