Repository: opencv/opencv
File: modules/imgproc/src/geometry.cpp (C++)

Code before:

    if( !is_float )
    {
        const int32_t* pts = points.ptr<int32_t>();
        xmin = xmax = pts[0];
        ymin = ymax = pts[1];
#if CV_SIMD || CV_SIMD_SCALABLE
        int64_t firstval = 0;
        std::memcpy(&firstval, pts, sizeof(int32_t) * 2);
        v_int32 minval, maxval;
        minval = maxval = v_reinterpret_as_s32(vx_setall_s64(firstval)); //min[0]=pt.x, min[1]=pt.y, min[2]=pt.x, min[3]=pt.y
        const int nlanes = VTraits<v_int32>::vlanes()/2;
        for (; i < npoints; i += nlanes)
        {
            if (i > npoints - nlanes)
            {
                if (i == 0)
                    break;
                i = npoints - nlanes;
            }
            v_int32 ptXY2 = vx_load(pts + 2 * i);
            minval = v_min(ptXY2, minval);
            maxval = v_max(ptXY2, maxval);
        }
        constexpr int max_nlanes = VTraits<v_int32>::max_nlanes;
        int arr_minval[max_nlanes], arr_maxval[max_nlanes];
        vx_store(arr_minval, minval);
        vx_store(arr_maxval, maxval);
        xmin = arr_minval[0];
        ymin = arr_minval[1];
        xmax = arr_maxval[0];
        ymax = arr_maxval[1];
        for (int j = 1; j < nlanes; j++)
        {
            if (xmin > arr_minval[2*j])   xmin = arr_minval[2*j];
            if (ymin > arr_minval[2*j+1]) ymin = arr_minval[2*j+1];
            if (xmax < arr_maxval[2*j])   xmax = arr_maxval[2*j];
            if (ymax < arr_maxval[2*j+1]) ymax = arr_maxval[2*j+1];
        }
#endif
        for( ; i < npoints; i++ )
        {
            int pt_x = pts[2*i];
            int pt_y = pts[2*i+1];

            if( xmin > pt_x )
                xmin = pt_x;

            if( xmax < pt_x )
                xmax = pt_x;


Review comment (suggestion):
We can do better than this if we have something like vtrn1q and vtrn2q in universal intrinsics, which does something like this:

```
v: [x1 y1 x2 y2]

vtrn1q(v, v): [x1 x1 x2 x2]
vtrn2q(v, v): [y1 y1 y2 y2]
```

Code after:

    if( !is_float )
    {
        const int32_t* pts = points.ptr<int32_t>();
        int64_t firstval = 0;
        std::memcpy(&firstval, pts, sizeof(pts[0]) * 2);
        xmin = xmax = pts[0];
        ymin = ymax = pts[1];
#if CV_SIMD || CV_SIMD_SCALABLE
        v_int32 minval, maxval;
        minval = maxval = v_reinterpret_as_s32(vx_setall_s64(firstval)); //min[0]=pt.x, min[1]=pt.y, min[2]=pt.x, min[3]=pt.y
        const int nlanes = VTraits<v_int32>::vlanes()/2;
        for (; i < npoints; i += nlanes)
        {
            if (i > npoints - nlanes)
            {
                if (i == 0)
                    break;
                i = npoints - nlanes;
            }
            v_int32 ptXY2 = vx_load(pts + 2 * i);
            minval = v_min(ptXY2, minval);
            maxval = v_max(ptXY2, maxval);
        }
        constexpr int max_nlanes = VTraits<v_int32>::max_nlanes;
        int arr_minval[max_nlanes], arr_maxval[max_nlanes];
        vx_store(arr_minval, minval);
        vx_store(arr_maxval, maxval);
        for (int j = 0; j < nlanes; j++)
        {
            xmin = std::min(xmin, arr_minval[2*j]);
            ymin = std::min(ymin, arr_minval[2*j+1]);
            xmax = std::max(xmax, arr_maxval[2*j]);
            ymax = std::max(ymax, arr_maxval[2*j+1]);
        }
#endif
        for( ; i < npoints; i++ )
        {
            int pt_x = pts[2*i];
            int pt_y = pts[2*i+1];

            xmin = std::min(xmin, pt_x);
            xmax = std::max(xmax, pt_x);
            ymin = std::min(ymin, pt_y);
            ymax = std::max(ymax, pt_y);
        }
    }
    else
    {
        const float* pts = points.ptr<float>();
        int64_t firstval = 0;