mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
Merge pull request #24132 from hanliutong:rewrite-imgproc2
Rewrite Universal Intrinsic code by using new API: ImgProc module Part 2 #24132 The goal of this series of PRs is to modify the SIMD code blocks guarded by CV_SIMD macro in the opencv/modules/imgproc folder: rewrite them by using the new Universal Intrinsic API. This is the second part of the modification to the Imgproc module ( Part 1: #24058 ), And I tested this patch on RVV (QEMU) and AVX devices, `opencv_test_imgproc` is passed. The patch is partially auto-generated by using the [rewriter](https://github.com/hanliutong/rewriter). ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [ ] I agree to contribute to the project under Apache 2 License. - [ ] 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 - [ ] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
@@ -745,7 +745,22 @@ namespace CV__SIMD_NAMESPACE {
|
||||
inline _Tpvec v_add(const _Tpvec& f1, const _Tpvec& f2, const Args&... vf) { \
|
||||
return v_add(f1 + f2, vf...); \
|
||||
}
|
||||
#define OPENCV_HAL_WRAP_SHIFT_OP(_Tpvec) \
|
||||
inline _Tpvec v_shr(const _Tpvec& a, int n) \
|
||||
{ \
|
||||
return a >> n; \
|
||||
} \
|
||||
inline _Tpvec v_shl(const _Tpvec& a, int n) \
|
||||
{ \
|
||||
return a << n; \
|
||||
}
|
||||
|
||||
OPENCV_HAL_WRAP_SHIFT_OP(v_uint16)
|
||||
OPENCV_HAL_WRAP_SHIFT_OP(v_uint32)
|
||||
OPENCV_HAL_WRAP_SHIFT_OP(v_uint64)
|
||||
OPENCV_HAL_WRAP_SHIFT_OP(v_int16)
|
||||
OPENCV_HAL_WRAP_SHIFT_OP(v_int32)
|
||||
OPENCV_HAL_WRAP_SHIFT_OP(v_int64)
|
||||
OPENCV_HAL_WRAP_BIN_OP_ADDSUB(v_uint8)
|
||||
OPENCV_HAL_WRAP_BIN_OP_ADDSUB(v_uint16)
|
||||
OPENCV_HAL_WRAP_BIN_OP_ADDSUB(v_uint32)
|
||||
@@ -769,6 +784,12 @@ namespace CV__SIMD_NAMESPACE {
|
||||
OPENCV_HAL_WRAP_BIN_OP_ADDSUB(v_int32x4)
|
||||
OPENCV_HAL_WRAP_BIN_OP_ADDSUB(v_int64x2)
|
||||
OPENCV_HAL_WRAP_BIN_OP_ADDSUB(v_float32x4)
|
||||
OPENCV_HAL_WRAP_SHIFT_OP(v_uint16x8)
|
||||
OPENCV_HAL_WRAP_SHIFT_OP(v_uint32x4)
|
||||
OPENCV_HAL_WRAP_SHIFT_OP(v_uint64x2)
|
||||
OPENCV_HAL_WRAP_SHIFT_OP(v_int16x8)
|
||||
OPENCV_HAL_WRAP_SHIFT_OP(v_int32x4)
|
||||
OPENCV_HAL_WRAP_SHIFT_OP(v_int64x2)
|
||||
#if CV_SIMD_64F
|
||||
OPENCV_HAL_WRAP_BIN_OP_ADDSUB(v_float64x2)
|
||||
#endif
|
||||
@@ -784,6 +805,12 @@ namespace CV__SIMD_NAMESPACE {
|
||||
OPENCV_HAL_WRAP_BIN_OP_ADDSUB(v_int32x8)
|
||||
OPENCV_HAL_WRAP_BIN_OP_ADDSUB(v_int64x4)
|
||||
OPENCV_HAL_WRAP_BIN_OP_ADDSUB(v_float32x8)
|
||||
OPENCV_HAL_WRAP_SHIFT_OP(v_uint16x16)
|
||||
OPENCV_HAL_WRAP_SHIFT_OP(v_uint32x8)
|
||||
OPENCV_HAL_WRAP_SHIFT_OP(v_uint64x4)
|
||||
OPENCV_HAL_WRAP_SHIFT_OP(v_int16x16)
|
||||
OPENCV_HAL_WRAP_SHIFT_OP(v_int32x8)
|
||||
OPENCV_HAL_WRAP_SHIFT_OP(v_int64x4)
|
||||
#if CV_SIMD_64F
|
||||
OPENCV_HAL_WRAP_BIN_OP_ADDSUB(v_float64x4)
|
||||
#endif
|
||||
@@ -801,7 +828,9 @@ namespace CV__SIMD_NAMESPACE {
|
||||
inline _Tpvec v_xor(const _Tpvec& a, const _Tpvec& b) \
|
||||
{ \
|
||||
return a ^ b; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define OPENCV_HAL_WRAP_NOT_OP(_Tpvec) \
|
||||
inline _Tpvec v_not(const _Tpvec& a) \
|
||||
{ \
|
||||
return ~a; \
|
||||
@@ -815,6 +844,18 @@ namespace CV__SIMD_NAMESPACE {
|
||||
OPENCV_HAL_WRAP_BIN_OP_LOGIC(v_int16)
|
||||
OPENCV_HAL_WRAP_BIN_OP_LOGIC(v_int32)
|
||||
OPENCV_HAL_WRAP_BIN_OP_LOGIC(v_int64)
|
||||
OPENCV_HAL_WRAP_BIN_OP_LOGIC(v_float32)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_uint8)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_uint16)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_uint32)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_uint64)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_int8)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_int16)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_int32)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_int64)
|
||||
#if CV_SIMD_64F
|
||||
OPENCV_HAL_WRAP_BIN_OP_LOGIC(v_float64)
|
||||
#endif
|
||||
#if CV_SIMD_WIDTH != 16/*128*/ && CV_SIMD128
|
||||
OPENCV_HAL_WRAP_BIN_OP_LOGIC(v_uint8x16)
|
||||
OPENCV_HAL_WRAP_BIN_OP_LOGIC(v_uint16x8)
|
||||
@@ -824,6 +865,18 @@ namespace CV__SIMD_NAMESPACE {
|
||||
OPENCV_HAL_WRAP_BIN_OP_LOGIC(v_int16x8)
|
||||
OPENCV_HAL_WRAP_BIN_OP_LOGIC(v_int32x4)
|
||||
OPENCV_HAL_WRAP_BIN_OP_LOGIC(v_int64x2)
|
||||
OPENCV_HAL_WRAP_BIN_OP_LOGIC(v_float32x4)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_uint8x16)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_uint16x8)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_uint32x4)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_uint64x2)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_int8x16)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_int16x8)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_int32x4)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_int64x2)
|
||||
#if CV_SIMD_64F
|
||||
OPENCV_HAL_WRAP_BIN_OP_LOGIC(v_float64x2)
|
||||
#endif
|
||||
#endif
|
||||
#if CV_SIMD_WIDTH != 32/*256*/ && CV_SIMD256
|
||||
OPENCV_HAL_WRAP_BIN_OP_LOGIC(v_uint8x32)
|
||||
@@ -834,6 +887,18 @@ namespace CV__SIMD_NAMESPACE {
|
||||
OPENCV_HAL_WRAP_BIN_OP_LOGIC(v_int16x16)
|
||||
OPENCV_HAL_WRAP_BIN_OP_LOGIC(v_int32x8)
|
||||
OPENCV_HAL_WRAP_BIN_OP_LOGIC(v_int64x4)
|
||||
OPENCV_HAL_WRAP_BIN_OP_LOGIC(v_float32x8)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_uint8x32)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_uint16x16)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_uint32x8)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_uint64x4)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_int8x32)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_int16x16)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_int32x8)
|
||||
OPENCV_HAL_WRAP_NOT_OP(v_int64x4)
|
||||
#if CV_SIMD_64F
|
||||
OPENCV_HAL_WRAP_BIN_OP_LOGIC(v_float64x4)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define OPENCV_HAL_WRAP_BIN_OP_MUL(_Tpvec) \
|
||||
|
||||
@@ -45,6 +45,7 @@ OPENCV_HAL_IMPL_RVV_FUN_LOXEI(vuint8m2_t, u8m2, vuint8m2_t, i8)
|
||||
OPENCV_HAL_IMPL_RVV_FUN_LOXEI(vuint8m4_t, u8m4, vuint8m4_t, i8)
|
||||
OPENCV_HAL_IMPL_RVV_FUN_LOXEI(vuint8m8_t, u8m8, vuint8m8_t, i8)
|
||||
OPENCV_HAL_IMPL_RVV_FUN_LOXEI(vfloat32m1_t, f32m1, vuint32m1_t, i32)
|
||||
OPENCV_HAL_IMPL_RVV_FUN_LOXEI(vuint32m1_t, u32m1, vuint32m1_t, i32)
|
||||
#if CV_SIMD_SCALABLE_64F
|
||||
OPENCV_HAL_IMPL_RVV_FUN_LOXEI(vfloat64m1_t, f64m1, vuint32mf2_t, i32)
|
||||
#endif
|
||||
|
||||
@@ -475,6 +475,25 @@ OPENCV_HAL_IMPL_RVV_LUT(v_float32, float, m1)
|
||||
OPENCV_HAL_IMPL_RVV_LUT(v_float64, double, mf2)
|
||||
#endif
|
||||
|
||||
#define OPENCV_HAL_IMPL_RVV_LUT_VEC(_Tpvec, _Tp) \
|
||||
inline _Tpvec v_lut(const _Tp* tab, const v_int32& vidx) \
|
||||
{ \
|
||||
v_uint32 vidx_ = vmul(vreinterpret_u32m1(vidx), sizeof(_Tp), VTraits<v_int32>::vlanes()); \
|
||||
return vloxei32(tab, vidx_, VTraits<_Tpvec>::vlanes()); \
|
||||
}
|
||||
OPENCV_HAL_IMPL_RVV_LUT_VEC(v_float32, float)
|
||||
OPENCV_HAL_IMPL_RVV_LUT_VEC(v_int32, int)
|
||||
OPENCV_HAL_IMPL_RVV_LUT_VEC(v_uint32, unsigned)
|
||||
|
||||
#if CV_SIMD_SCALABLE_64F
|
||||
inline v_float64 v_lut(const double* tab, const v_int32& vidx) \
|
||||
{ \
|
||||
vuint32mf2_t vidx_ = vmul(vlmul_trunc_u32mf2(vreinterpret_u32m1(vidx)), sizeof(double), VTraits<v_float64>::vlanes()); \
|
||||
return vloxei32(tab, vidx_, VTraits<v_float64>::vlanes()); \
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
inline v_uint8 v_lut(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut((schar*)tab, idx)); }
|
||||
inline v_uint8 v_lut_pairs(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_pairs((schar*)tab, idx)); }
|
||||
inline v_uint8 v_lut_quads(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_quads((schar*)tab, idx)); }
|
||||
@@ -690,23 +709,27 @@ inline v_float64 v_not (const v_float64& a) \
|
||||
|
||||
|
||||
////////////// Bitwise shifts //////////////
|
||||
/* Usage
|
||||
1. v_shl<N>(vec);
|
||||
2. v_shl(vec, N); // instead of vec << N, when N is non-constant.
|
||||
*/
|
||||
|
||||
#define OPENCV_HAL_IMPL_RVV_UNSIGNED_SHIFT_OP(_Tpvec, vl) \
|
||||
template<int n> inline _Tpvec v_shl(const _Tpvec& a) \
|
||||
template<int s = 0> inline _Tpvec v_shl(const _Tpvec& a, int n = s) \
|
||||
{ \
|
||||
return _Tpvec(vsll(a, uint8_t(n), vl)); \
|
||||
} \
|
||||
template<int n> inline _Tpvec v_shr(const _Tpvec& a) \
|
||||
template<int s = 0> inline _Tpvec v_shr(const _Tpvec& a, int n = s) \
|
||||
{ \
|
||||
return _Tpvec(vsrl(a, uint8_t(n), vl)); \
|
||||
}
|
||||
|
||||
#define OPENCV_HAL_IMPL_RVV_SIGNED_SHIFT_OP(_Tpvec, vl) \
|
||||
template<int n> inline _Tpvec v_shl(const _Tpvec& a) \
|
||||
template<int s = 0> inline _Tpvec v_shl(const _Tpvec& a, int n = s) \
|
||||
{ \
|
||||
return _Tpvec(vsll(a, uint8_t(n), vl)); \
|
||||
} \
|
||||
template<int n> inline _Tpvec v_shr(const _Tpvec& a) \
|
||||
template<int s = 0> inline _Tpvec v_shr(const _Tpvec& a, int n = s) \
|
||||
{ \
|
||||
return _Tpvec(vsra(a, uint8_t(n), vl)); \
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user