Fix compile errors when all SIMD is disabled.

pull/22278/head
HAN Liutong 2 years ago
parent e2bfe0ce76
commit 3e3b53f815
  1. 232
      modules/core/include/opencv2/core/hal/intrin.hpp
  2. 1
      modules/core/include/opencv2/core/hal/intrin_cpp.hpp
  3. 1
      modules/core/include/opencv2/core/saturate.hpp
  4. 294
      modules/core/test/test_intrin_utils.hpp

@ -695,237 +695,15 @@ namespace CV__SIMD_NAMESPACE {
/** @brief SIMD processing state cleanup call */
inline void vx_cleanup() { VXPREFIX(_cleanup)(); }
#if CV_SIMD
#if !CV_SIMD_SCALABLE
// Compatibility layer
#define CV_SIMD_SCALABLE 0
#define CV_SIMD_SCALABLE_64F 0
template <class T>
struct VTraits;
#if CV_SIMD512 && (!defined(CV__SIMD_FORCE_WIDTH) || CV__SIMD_FORCE_WIDTH == 512)
template <>
struct VTraits<v_uint8>
{
static inline int vlanes() { return v_uint8::nlanes; }
enum { nlanes = 64, max_nlanes = nlanes };
using lane_type = uchar;
};
template <>
struct VTraits<v_int8>
{
static inline int vlanes() { return v_int8::nlanes; }
enum { nlanes = 64, max_nlanes = nlanes };
using lane_type = schar;
};
template <>
struct VTraits<v_uint16>
{
static inline int vlanes() { return v_uint16::nlanes; }
enum { nlanes = 32, max_nlanes = nlanes };
using lane_type = ushort;
};
template <>
struct VTraits<v_int16>
{
static inline int vlanes() { return v_int16::nlanes; }
enum { nlanes = 32, max_nlanes = nlanes };
using lane_type = short;
};
template <>
struct VTraits<v_uint32>
{
static inline int vlanes() { return v_uint32::nlanes; }
enum { nlanes = 16, max_nlanes = nlanes };
using lane_type = uint;
};
template <>
struct VTraits<v_int32>
{
static inline int vlanes() { return v_int32::nlanes; }
enum { nlanes = 16, max_nlanes = nlanes };
using lane_type = int;
template<typename T> struct VTraits {
static inline int vlanes() { return T::nlanes; }
enum { nlanes = T::nlanes, max_nlanes = T::nlanes };
using lane_type = typename T::lane_type;
};
template <>
struct VTraits<v_float32>
{
static inline int vlanes() { return v_float32::nlanes; }
enum { nlanes = 16, max_nlanes = nlanes };
using lane_type = float;
};
template <>
struct VTraits<v_uint64>
{
static inline int vlanes() { return v_uint64::nlanes; }
enum { nlanes = 8, max_nlanes = nlanes };
using lane_type = uint64;
};
template <>
struct VTraits<v_int64>
{
static inline int vlanes() { return v_int64::nlanes; }
enum { nlanes = 8, max_nlanes = nlanes };
using lane_type = int64;
};
#if CV_SIMD_64F
template <>
struct VTraits<v_float64>
{
static inline int vlanes() { return v_float64::nlanes; }
enum { nlanes = 8, max_nlanes = nlanes };
using lane_type = double;
};
#endif
#elif CV_SIMD256 && (!defined(CV__SIMD_FORCE_WIDTH) || CV__SIMD_FORCE_WIDTH == 256)
template <>
struct VTraits<v_uint8>
{
static inline int vlanes() { return v_uint8::nlanes; }
enum { nlanes = 32, max_nlanes = nlanes };
using lane_type = uchar;
};
template <>
struct VTraits<v_int8>
{
static inline int vlanes() { return v_int8::nlanes; }
enum { nlanes = 32, max_nlanes = nlanes };
using lane_type = schar;
};
template <>
struct VTraits<v_uint16>
{
static inline int vlanes() { return v_uint16::nlanes; }
enum { nlanes = 16, max_nlanes = nlanes };
using lane_type = ushort;
};
template <>
struct VTraits<v_int16>
{
static inline int vlanes() { return v_int16::nlanes; }
enum { nlanes = 16, max_nlanes = nlanes };
using lane_type = short;
};
template <>
struct VTraits<v_uint32>
{
static inline int vlanes() { return v_uint32::nlanes; }
enum { nlanes = 8, max_nlanes = nlanes };
using lane_type = uint;
};
template <>
struct VTraits<v_int32>
{
static inline int vlanes() { return v_int32::nlanes; }
enum { nlanes = 8, max_nlanes = nlanes };
using lane_type = int;
};
template <>
struct VTraits<v_float32>
{
static inline int vlanes() { return v_float32::nlanes; }
enum { nlanes = 8, max_nlanes = nlanes };
using lane_type = float;
};
template <>
struct VTraits<v_uint64>
{
static inline int vlanes() { return v_uint64::nlanes; }
enum { nlanes = 4, max_nlanes = nlanes };
using lane_type = uint64;
};
template <>
struct VTraits<v_int64>
{
static inline int vlanes() { return v_int64::nlanes; }
enum { nlanes = 4, max_nlanes = nlanes };
using lane_type = int64;
};
#if CV_SIMD_64F
template <>
struct VTraits<v_float64>
{
static inline int vlanes() { return v_float64::nlanes; }
enum { nlanes = 4, max_nlanes = nlanes };
using lane_type = double;
};
#endif
#elif CV_SIMD128 && (!defined(CV__SIMD_FORCE_WIDTH) || CV__SIMD_FORCE_WIDTH == 128)
template <>
struct VTraits<v_uint8>
{
static inline int vlanes() { return v_uint8::nlanes; }
enum { nlanes = 16, max_nlanes = nlanes };
using lane_type = uchar;
};
template <>
struct VTraits<v_int8>
{
static inline int vlanes() { return v_int8::nlanes; }
enum { nlanes = 16, max_nlanes = nlanes };
using lane_type = schar;
};
template <>
struct VTraits<v_uint16>
{
static inline int vlanes() { return v_uint16::nlanes; }
enum { nlanes = 8, max_nlanes = nlanes };
using lane_type = ushort;
};
template <>
struct VTraits<v_int16>
{
static inline int vlanes() { return v_int16::nlanes; }
enum { nlanes = 8, max_nlanes = nlanes };
using lane_type = short;
};
template <>
struct VTraits<v_uint32>
{
static inline int vlanes() { return v_uint32::nlanes; }
enum { nlanes = 4, max_nlanes = nlanes };
using lane_type = uint;
};
template <>
struct VTraits<v_int32>
{
static inline int vlanes() { return v_int32::nlanes; }
enum { nlanes = 4, max_nlanes = nlanes };
using lane_type = int;
};
template <>
struct VTraits<v_float32>
{
static inline int vlanes() { return v_float32::nlanes; }
enum { nlanes = 4, max_nlanes = nlanes };
using lane_type = float;
};
template <>
struct VTraits<v_uint64>
{
static inline int vlanes() { return v_uint64::nlanes; }
enum { nlanes = 2, max_nlanes = nlanes };
using lane_type = uint64;
};
template <>
struct VTraits<v_int64>
{
static inline int vlanes() { return v_int64::nlanes; }
enum { nlanes = 2, max_nlanes = nlanes };
using lane_type = int64;
};
#if CV_SIMD_64F
template <>
struct VTraits<v_float64>
{
static inline int vlanes() { return v_float64::nlanes; }
enum { nlanes = 2, max_nlanes = nlanes };
using lane_type = double;
};
#endif
#endif
#define OPENCV_HAL_WRAP_BIN_OP_ADDSUB(_Tpvec) \
inline _Tpvec v_add(const _Tpvec& a, const _Tpvec& b) \
{ \

@ -48,6 +48,7 @@
#include <limits>
#include <cstring>
#include <algorithm>
#include "opencv2/core/utility.hpp"
#include "opencv2/core/saturate.hpp"
//! @cond IGNORED

@ -46,6 +46,7 @@
#define OPENCV_CORE_SATURATE_HPP
#include "opencv2/core/cvdef.h"
#include <climits>
#include "opencv2/core/fast_math.hpp"
namespace cv

@ -25,15 +25,30 @@ void test_hal_intrin_float16();
template <typename R> struct Data;
template <int N> struct initializer;
#if CV_SIMD
#if CV_SIMD_SCALABLE
template <> struct initializer<128>
{
template <typename R> static R init(const Data<R> & d)
{
return v_load({d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15],
d[16], d[17], d[18], d[19], d[20], d[21], d[22], d[23], d[24], d[25], d[26], d[27], d[28], d[29], d[30], d[31],
d[32], d[33], d[34], d[35], d[36], d[37], d[38], d[39], d[40], d[41], d[42], d[43], d[44], d[45], d[46], d[47],
d[48], d[49], d[50], d[51], d[52], d[53], d[54], d[55], d[56], d[57], d[58], d[59], d[60], d[61], d[62], d[63],
d[64], d[65], d[66], d[67], d[68], d[69], d[70], d[71], d[72], d[73], d[74], d[75], d[76], d[77], d[78], d[79],
d[80], d[81], d[82], d[83], d[84], d[85], d[86], d[87], d[88], d[89], d[90], d[91], d[92], d[93], d[94], d[95],
d[96], d[97], d[98], d[99], d[100], d[101], d[102], d[103], d[104], d[105], d[106], d[107], d[108], d[109], d[110], d[111],
d[112], d[113], d[114], d[115], d[116], d[117], d[118], d[119], d[120], d[121], d[122], d[123], d[124], d[125], d[126], d[127]});
}
};
template <> struct initializer<64>
{
template <typename R> static R init(const Data<R> & d)
{
return R(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15],
return v_load({d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15],
d[16], d[17], d[18], d[19], d[20], d[21], d[22], d[23], d[24], d[25], d[26], d[27], d[28], d[29], d[30], d[31],
d[32], d[33], d[34], d[35], d[36], d[37], d[38], d[39], d[40], d[41], d[42], d[43], d[44], d[45], d[46], d[47],
d[48], d[49], d[50], d[51], d[52], d[53], d[54], d[55], d[56], d[57], d[58], d[59], d[60], d[61], d[62], d[63]);
d[48], d[49], d[50], d[51], d[52], d[53], d[54], d[55], d[56], d[57], d[58], d[59], d[60], d[61], d[62], d[63]});
}
};
@ -41,8 +56,8 @@ template <> struct initializer<32>
{
template <typename R> static R init(const Data<R> & d)
{
return R(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15],
d[16], d[17], d[18], d[19], d[20], d[21], d[22], d[23], d[24], d[25], d[26], d[27], d[28], d[29], d[30], d[31]);
return v_load({d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15],
d[16], d[17], d[18], d[19], d[20], d[21], d[22], d[23], d[24], d[25], d[26], d[27], d[28], d[29], d[30], d[31]});
}
};
@ -50,7 +65,7 @@ template <> struct initializer<16>
{
template <typename R> static R init(const Data<R> & d)
{
return R(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]);
return v_load({d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]});
}
};
@ -58,7 +73,7 @@ template <> struct initializer<8>
{
template <typename R> static R init(const Data<R> & d)
{
return R(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7]);
return v_load({d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7]});
}
};
@ -66,7 +81,7 @@ template <> struct initializer<4>
{
template <typename R> static R init(const Data<R> & d)
{
return R(d[0], d[1], d[2], d[3]);
return v_load({d[0], d[1], d[2], d[3]});
}
};
@ -74,35 +89,19 @@ template <> struct initializer<2>
{
template <typename R> static R init(const Data<R> & d)
{
return R(d[0], d[1]);
return v_load({d[0], d[1]});
}
};
#else
template <> struct initializer<128>
{
template <typename R> static R init(const Data<R> & d)
{
return v_load({d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15],
d[16], d[17], d[18], d[19], d[20], d[21], d[22], d[23], d[24], d[25], d[26], d[27], d[28], d[29], d[30], d[31],
d[32], d[33], d[34], d[35], d[36], d[37], d[38], d[39], d[40], d[41], d[42], d[43], d[44], d[45], d[46], d[47],
d[48], d[49], d[50], d[51], d[52], d[53], d[54], d[55], d[56], d[57], d[58], d[59], d[60], d[61], d[62], d[63],
d[64], d[65], d[66], d[67], d[68], d[69], d[70], d[71], d[72], d[73], d[74], d[75], d[76], d[77], d[78], d[79],
d[80], d[81], d[82], d[83], d[84], d[85], d[86], d[87], d[88], d[89], d[90], d[91], d[92], d[93], d[94], d[95],
d[96], d[97], d[98], d[99], d[100], d[101], d[102], d[103], d[104], d[105], d[106], d[107], d[108], d[109], d[110], d[111],
d[112], d[113], d[114], d[115], d[116], d[117], d[118], d[119], d[120], d[121], d[122], d[123], d[124], d[125], d[126], d[127]});
}
};
template <> struct initializer<64>
{
template <typename R> static R init(const Data<R> & d)
{
return v_load({d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15],
return R(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15],
d[16], d[17], d[18], d[19], d[20], d[21], d[22], d[23], d[24], d[25], d[26], d[27], d[28], d[29], d[30], d[31],
d[32], d[33], d[34], d[35], d[36], d[37], d[38], d[39], d[40], d[41], d[42], d[43], d[44], d[45], d[46], d[47],
d[48], d[49], d[50], d[51], d[52], d[53], d[54], d[55], d[56], d[57], d[58], d[59], d[60], d[61], d[62], d[63]});
d[48], d[49], d[50], d[51], d[52], d[53], d[54], d[55], d[56], d[57], d[58], d[59], d[60], d[61], d[62], d[63]);
}
};
@ -110,8 +109,8 @@ template <> struct initializer<32>
{
template <typename R> static R init(const Data<R> & d)
{
return v_load({d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15],
d[16], d[17], d[18], d[19], d[20], d[21], d[22], d[23], d[24], d[25], d[26], d[27], d[28], d[29], d[30], d[31]});
return R(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15],
d[16], d[17], d[18], d[19], d[20], d[21], d[22], d[23], d[24], d[25], d[26], d[27], d[28], d[29], d[30], d[31]);
}
};
@ -119,7 +118,7 @@ template <> struct initializer<16>
{
template <typename R> static R init(const Data<R> & d)
{
return v_load({d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]});
return R(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]);
}
};
@ -127,7 +126,7 @@ template <> struct initializer<8>
{
template <typename R> static R init(const Data<R> & d)
{
return v_load({d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7]});
return R(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7]);
}
};
@ -135,7 +134,7 @@ template <> struct initializer<4>
{
template <typename R> static R init(const Data<R> & d)
{
return v_load({d[0], d[1], d[2], d[3]});
return R(d[0], d[1], d[2], d[3]);
}
};
@ -143,7 +142,7 @@ template <> struct initializer<2>
{
template <typename R> static R init(const Data<R> & d)
{
return v_load({d[0], d[1]});
return R(d[0], d[1]);
}
};
#endif
@ -1726,8 +1725,122 @@ template<typename R> struct TheTest
#endif
};
#if CV_SIMD_SCALABLE //Temporary
#define DUMP_ENTRY(type) printf("SIMD: %s\n", CV__TRACE_FUNCTION);
//============= 8-bit integer =====================================================================
void test_hal_intrin_uint8()
{
DUMP_ENTRY(v_uint8);
// typedef v_uint8 R;
TheTest<v_uint8>()
.test_loadstore()
.test_min_max()
;
}
void test_hal_intrin_int8()
{
DUMP_ENTRY(v_int8);
// typedef v_int8 R;
TheTest<v_int8>()
.test_loadstore()
.test_min_max()
;
}
//============= 16-bit integer =====================================================================
void test_hal_intrin_uint16()
{
DUMP_ENTRY(v_uint16);
// typedef v_uint16 R;
TheTest<v_uint16>()
.test_loadstore()
.test_min_max()
;
}
void test_hal_intrin_int16()
{
DUMP_ENTRY(v_int16);
// typedef v_int16 R;
TheTest<v_int16>()
.test_loadstore()
.test_min_max()
;
}
//============= 32-bit integer =====================================================================
void test_hal_intrin_uint32()
{
DUMP_ENTRY(v_uint32);
// typedef v_uint32 R;
TheTest<v_uint32>()
.test_loadstore()
.test_min_max()
;
}
void test_hal_intrin_int32()
{
DUMP_ENTRY(v_int32);
// typedef v_int32 R;
TheTest<v_int32>()
.test_loadstore()
.test_min_max()
;
}
//============= 64-bit integer =====================================================================
void test_hal_intrin_uint64()
{
DUMP_ENTRY(v_uint64);
// typedef v_uint64 R;
TheTest<v_uint64>()
.test_loadstore()
;
}
void test_hal_intrin_int64()
{
DUMP_ENTRY(v_int64);
// typedef v_int64 R;
TheTest<v_int64>()
.test_loadstore()
;
}
//============= Floating point =====================================================================
void test_hal_intrin_float32()
{
DUMP_ENTRY(v_float32);
// typedef v_float32 R;
TheTest<v_float32>()
.test_loadstore()
.test_min_max()
;
}
void test_hal_intrin_float64()
{
DUMP_ENTRY(v_float64);
#if CV_SIMD_64F
// typedef v_float64 R;
TheTest<v_float64>()
.test_loadstore()
.test_min_max()
;
#endif
}
#else
#if CV_SIMD
#define DUMP_ENTRY(type) printf("SIMD%d: %s\n", 8*(int)sizeof(v_uint8), CV__TRACE_FUNCTION);
//============= 8-bit integer =====================================================================
@ -2075,119 +2188,6 @@ void test_hal_intrin_float16()
std::cout << "SKIP: CV_FP16 is not available" << std::endl;
#endif
}
#elif CV_SIMD_SCALABLE //Temporary
#define DUMP_ENTRY(type) printf("SIMD: %s\n", CV__TRACE_FUNCTION);
//============= 8-bit integer =====================================================================
void test_hal_intrin_uint8()
{
DUMP_ENTRY(v_uint8);
// typedef v_uint8 R;
TheTest<v_uint8>()
.test_loadstore()
.test_min_max()
;
}
void test_hal_intrin_int8()
{
DUMP_ENTRY(v_int8);
// typedef v_int8 R;
TheTest<v_int8>()
.test_loadstore()
.test_min_max()
;
}
//============= 16-bit integer =====================================================================
void test_hal_intrin_uint16()
{
DUMP_ENTRY(v_uint16);
// typedef v_uint16 R;
TheTest<v_uint16>()
.test_loadstore()
.test_min_max()
;
}
void test_hal_intrin_int16()
{
DUMP_ENTRY(v_int16);
// typedef v_int16 R;
TheTest<v_int16>()
.test_loadstore()
.test_min_max()
;
}
//============= 32-bit integer =====================================================================
void test_hal_intrin_uint32()
{
DUMP_ENTRY(v_uint32);
// typedef v_uint32 R;
TheTest<v_uint32>()
.test_loadstore()
.test_min_max()
;
}
void test_hal_intrin_int32()
{
DUMP_ENTRY(v_int32);
// typedef v_int32 R;
TheTest<v_int32>()
.test_loadstore()
.test_min_max()
;
}
//============= 64-bit integer =====================================================================
void test_hal_intrin_uint64()
{
DUMP_ENTRY(v_uint64);
// typedef v_uint64 R;
TheTest<v_uint64>()
.test_loadstore()
;
}
void test_hal_intrin_int64()
{
DUMP_ENTRY(v_int64);
// typedef v_int64 R;
TheTest<v_int64>()
.test_loadstore()
;
}
//============= Floating point =====================================================================
void test_hal_intrin_float32()
{
DUMP_ENTRY(v_float32);
// typedef v_float32 R;
TheTest<v_float32>()
.test_loadstore()
.test_min_max()
;
}
void test_hal_intrin_float64()
{
DUMP_ENTRY(v_float64);
#if CV_SIMD_64F
// typedef v_float64 R;
TheTest<v_float64>()
.test_loadstore()
.test_min_max()
;
#endif
}
#endif

Loading…
Cancel
Save