mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
add universal intrinsic in StereoSGBM
* add 8 elements version of reduce operation * add tests for new universal intrinsic
This commit is contained in:
@@ -782,25 +782,37 @@ inline void v_store_f16(short* ptr, v_float16x4& a)
|
||||
{ vst1_f16(ptr, a.val); }
|
||||
#endif
|
||||
|
||||
#define OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(_Tpvec, scalartype, func, scalar_func) \
|
||||
#define OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(_Tpvec, _Tpnvec, scalartype, func, vectorfunc, suffix) \
|
||||
inline scalartype v_reduce_##func(const _Tpvec& a) \
|
||||
{ \
|
||||
scalartype CV_DECL_ALIGNED(16) buf[4]; \
|
||||
v_store_aligned(buf, a); \
|
||||
scalartype s0 = scalar_func(buf[0], buf[1]); \
|
||||
scalartype s1 = scalar_func(buf[2], buf[3]); \
|
||||
return scalar_func(s0, s1); \
|
||||
_Tpnvec##_t a0 = vp##vectorfunc##_##suffix(vget_low_##suffix(a.val), vget_high_##suffix(a.val)); \
|
||||
a0 = vp##vectorfunc##_##suffix(a0, a0); \
|
||||
return (scalartype)vget_lane_##suffix(vp##vectorfunc##_##suffix(a0, a0),0); \
|
||||
}
|
||||
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, unsigned, sum, OPENCV_HAL_ADD)
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, unsigned, max, std::max)
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, unsigned, min, std::min)
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_int32x4, int, sum, OPENCV_HAL_ADD)
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_int32x4, int, max, std::max)
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_int32x4, int, min, std::min)
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float, sum, OPENCV_HAL_ADD)
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float, max, std::max)
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float, min, std::min)
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_uint16x8, uint16x4, unsigned short, sum, add, u16)
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_uint16x8, uint16x4, unsigned short, max, max, u16)
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_uint16x8, uint16x4, unsigned short, min, min, u16)
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_int16x8, int16x4, short, sum, add, s16)
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_int16x8, int16x4, short, max, max, s16)
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_int16x8, int16x4, short, min, min, s16)
|
||||
|
||||
#define OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(_Tpvec, _Tpnvec, scalartype, func, vectorfunc, suffix) \
|
||||
inline scalartype v_reduce_##func(const _Tpvec& a) \
|
||||
{ \
|
||||
_Tpnvec##_t a0 = vp##vectorfunc##_##suffix(vget_low_##suffix(a.val), vget_high_##suffix(a.val)); \
|
||||
return (scalartype)vget_lane_##suffix(vp##vectorfunc##_##suffix(a0, vget_high_##suffix(a.val)),0); \
|
||||
}
|
||||
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, uint32x2, unsigned, sum, add, u32)
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, uint32x2, unsigned, max, max, u32)
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, uint32x2, unsigned, min, min, u32)
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_int32x4, int32x2, int, sum, add, s32)
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_int32x4, int32x2, int, max, max, s32)
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_int32x4, int32x2, int, min, min, s32)
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float32x2, float, sum, add, f32)
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float32x2, float, max, max, f32)
|
||||
OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float32x2, float, min, min, f32)
|
||||
|
||||
inline int v_signmask(const v_uint8x16& a)
|
||||
{
|
||||
|
||||
@@ -1060,6 +1060,46 @@ inline void v_store_f16(short* ptr, v_float16x4& a)
|
||||
{ _mm_storel_epi64((__m128i*)ptr, a.val); }
|
||||
#endif
|
||||
|
||||
#define OPENCV_HAL_IMPL_SSE_REDUCE_OP_8(_Tpvec, scalartype, func, suffix, sbit) \
|
||||
inline scalartype v_reduce_##func(const v_##_Tpvec& a) \
|
||||
{ \
|
||||
__m128i val = a.val; \
|
||||
val = _mm_##func##_##suffix(val, _mm_srli_si128(val,8)); \
|
||||
val = _mm_##func##_##suffix(val, _mm_srli_si128(val,4)); \
|
||||
val = _mm_##func##_##suffix(val, _mm_srli_si128(val,2)); \
|
||||
return (scalartype)_mm_cvtsi128_si32(val); \
|
||||
} \
|
||||
inline unsigned scalartype v_reduce_##func(const v_u##_Tpvec& a) \
|
||||
{ \
|
||||
__m128i val = a.val; \
|
||||
__m128i smask = _mm_set1_epi16(sbit); \
|
||||
val = _mm_xor_si128(val, smask); \
|
||||
val = _mm_##func##_##suffix(val, _mm_srli_si128(val,8)); \
|
||||
val = _mm_##func##_##suffix(val, _mm_srli_si128(val,4)); \
|
||||
val = _mm_##func##_##suffix(val, _mm_srli_si128(val,2)); \
|
||||
return (unsigned scalartype)(_mm_cvtsi128_si32(val) ^ sbit); \
|
||||
}
|
||||
#define OPENCV_HAL_IMPL_SSE_REDUCE_OP_8_SUM(_Tpvec, scalartype, suffix) \
|
||||
inline scalartype v_reduce_sum(const v_##_Tpvec& a) \
|
||||
{ \
|
||||
__m128i val = a.val; \
|
||||
val = _mm_adds_epi##suffix(val, _mm_srli_si128(val, 8)); \
|
||||
val = _mm_adds_epi##suffix(val, _mm_srli_si128(val, 4)); \
|
||||
val = _mm_adds_epi##suffix(val, _mm_srli_si128(val, 2)); \
|
||||
return (scalartype)_mm_cvtsi128_si32(val); \
|
||||
} \
|
||||
inline unsigned scalartype v_reduce_sum(const v_u##_Tpvec& a) \
|
||||
{ \
|
||||
__m128i val = a.val; \
|
||||
val = _mm_adds_epu##suffix(val, _mm_srli_si128(val, 8)); \
|
||||
val = _mm_adds_epu##suffix(val, _mm_srli_si128(val, 4)); \
|
||||
val = _mm_adds_epu##suffix(val, _mm_srli_si128(val, 2)); \
|
||||
return (unsigned scalartype)_mm_cvtsi128_si32(val); \
|
||||
}
|
||||
OPENCV_HAL_IMPL_SSE_REDUCE_OP_8(int16x8, short, max, epi16, (short)-32768)
|
||||
OPENCV_HAL_IMPL_SSE_REDUCE_OP_8(int16x8, short, min, epi16, (short)-32768)
|
||||
OPENCV_HAL_IMPL_SSE_REDUCE_OP_8_SUM(int16x8, short, 16)
|
||||
|
||||
#define OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(_Tpvec, scalartype, func, scalar_func) \
|
||||
inline scalartype v_reduce_##func(const _Tpvec& a) \
|
||||
{ \
|
||||
|
||||
@@ -449,7 +449,7 @@ template<typename R> struct TheTest
|
||||
R a = dataA;
|
||||
EXPECT_EQ((LaneType)1, v_reduce_min(a));
|
||||
EXPECT_EQ((LaneType)R::nlanes, v_reduce_max(a));
|
||||
EXPECT_EQ((LaneType)(1 + R::nlanes)*2, v_reduce_sum(a));
|
||||
EXPECT_EQ((LaneType)((1 + R::nlanes)*R::nlanes/2), v_reduce_sum(a));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -842,6 +842,7 @@ TEST(hal_intrin, uint16x8) {
|
||||
.test_logic()
|
||||
.test_min_max()
|
||||
.test_absdiff()
|
||||
.test_reduce()
|
||||
.test_mask()
|
||||
.test_pack<1>().test_pack<2>().test_pack<7>().test_pack<16>()
|
||||
.test_pack_u<1>().test_pack_u<2>().test_pack_u<7>().test_pack_u<16>()
|
||||
@@ -867,6 +868,7 @@ TEST(hal_intrin, int16x8) {
|
||||
.test_min_max()
|
||||
.test_absdiff()
|
||||
.test_abs()
|
||||
.test_reduce()
|
||||
.test_mask()
|
||||
.test_pack<1>().test_pack<2>().test_pack<7>().test_pack<16>()
|
||||
.test_unpack()
|
||||
|
||||
Reference in New Issue
Block a user