1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
16 // Copyright (C) 2015, Itseez Inc., all rights reserved.
17 // Third party copyrights are property of their respective owners.
19 // Redistribution and use in source and binary forms, with or without modification,
20 // are permitted provided that the following conditions are met:
22 // * Redistribution's of source code must retain the above copyright notice,
23 // this list of conditions and the following disclaimer.
25 // * Redistribution's in binary form must reproduce the above copyright notice,
26 // this list of conditions and the following disclaimer in the documentation
27 // and/or other materials provided with the distribution.
29 // * The name of the copyright holders may not be used to endorse or promote products
30 // derived from this software without specific prior written permission.
32 // This software is provided by the copyright holders and contributors "as is" and
33 // any express or implied warranties, including, but not limited to, the implied
34 // warranties of merchantability and fitness for a particular purpose are disclaimed.
35 // In no event shall the Intel Corporation or contributors be liable for any direct,
36 // indirect, incidental, special, exemplary, or consequential damages
37 // (including, but not limited to, procurement of substitute goods or services;
38 // loss of use, data, or profits; or business interruption) however caused
39 // and on any theory of liability, whether in contract, strict liability,
40 // or tort (including negligence or otherwise) arising in any way out of
41 // the use of this software, even if advised of the possibility of such damage.
45 #ifndef OPENCV_CORE_CVDEF_H
46 #define OPENCV_CORE_CVDEF_H
48 //! @addtogroup core_utils
51 #if !defined CV_DOXYGEN && !defined CV_IGNORE_DEBUG_BUILD_GUARD
52 #if (defined(_MSC_VER) && (defined(DEBUG) || defined(_DEBUG))) || \
53 (defined(_GLIBCXX_DEBUG) || defined(_GLIBCXX_DEBUG_PEDANTIC))
54 // Guard to prevent using of binary incompatible binaries / runtimes
55 // https://github.com/opencv/opencv/pull/9161
56 #define CV__DEBUG_NS_BEGIN namespace debug_build_guard {
57 #define CV__DEBUG_NS_END }
58 namespace cv { namespace debug_build_guard { } using namespace debug_build_guard; }
62 #ifndef CV__DEBUG_NS_BEGIN
63 #define CV__DEBUG_NS_BEGIN
64 #define CV__DEBUG_NS_END
73 #define __CV_EXPAND(x) x
77 #define __CV_CAT__(x, y) x ## y
78 #define __CV_CAT_(x, y) __CV_CAT__(x, y)
79 #define __CV_CAT(x, y) __CV_CAT_(x, y)
83 // undef problematic defines sometimes defined by system headers (windows.h in particular)
91 #include "opencv2/core/hal/interface.h"
100 # define CV_ICC __ECC
101 #elif defined __INTEL_COMPILER
102 # define CV_ICC __INTEL_COMPILER
106 # if defined __cplusplus
107 # define CV_INLINE static inline
108 # elif defined _MSC_VER
109 # define CV_INLINE __inline
111 # define CV_INLINE static
115 #if defined CV_DISABLE_OPTIMIZATION || (defined CV_ICC && !defined CV_ENABLE_UNROLLED)
116 # define CV_ENABLE_UNROLLED 0
118 # define CV_ENABLE_UNROLLED 1
122 # define CV_DECL_ALIGNED(x) __attribute__ ((aligned (x)))
123 #elif defined _MSC_VER
124 # define CV_DECL_ALIGNED(x) __declspec(align(x))
126 # define CV_DECL_ALIGNED(x)
129 /* CPU features and intrinsics support */
130 #define CV_CPU_NONE 0
133 #define CV_CPU_SSE2 3
134 #define CV_CPU_SSE3 4
135 #define CV_CPU_SSSE3 5
136 #define CV_CPU_SSE4_1 6
137 #define CV_CPU_SSE4_2 7
138 #define CV_CPU_POPCNT 8
139 #define CV_CPU_FP16 9
140 #define CV_CPU_AVX 10
141 #define CV_CPU_AVX2 11
142 #define CV_CPU_FMA3 12
144 #define CV_CPU_AVX_512F 13
145 #define CV_CPU_AVX_512BW 14
146 #define CV_CPU_AVX_512CD 15
147 #define CV_CPU_AVX_512DQ 16
148 #define CV_CPU_AVX_512ER 17
149 #define CV_CPU_AVX_512IFMA512 18 // deprecated
150 #define CV_CPU_AVX_512IFMA 18
151 #define CV_CPU_AVX_512PF 19
152 #define CV_CPU_AVX_512VBMI 20
153 #define CV_CPU_AVX_512VL 21
155 #define CV_CPU_NEON 100
157 #define CV_CPU_VSX 200
159 // CPU features groups
160 #define CV_CPU_AVX512_SKX 256
162 // when adding to this list remember to update the following enum
163 #define CV_HARDWARE_MAX_FEATURE 512
165 /** @brief Available CPU features.
186 CPU_AVX_512IFMA512 = 18, // deprecated
187 CPU_AVX_512IFMA = 18,
189 CPU_AVX_512VBMI = 20,
196 CPU_AVX512_SKX = 256, //!< Skylake-X with AVX-512F/CD/BW/DQ/VL
198 CPU_MAX_FEATURE = 512 // see CV_HARDWARE_MAX_FEATURE
202 #include "cv_cpu_dispatch.h"
205 /* fundamental constants */
206 #define CV_PI 3.1415926535897932384626433832795
207 #define CV_2PI 6.283185307179586476925286766559
208 #define CV_LOG2 0.69314718055994530941723212145818
210 #if defined __ARM_FP16_FORMAT_IEEE \
211 && !defined __CUDACC__
212 # define CV_FP16_TYPE 1
214 # define CV_FP16_TYPE 0
217 typedef union Cv16suf
225 unsigned int significand : 10;
226 unsigned int exponent : 5;
227 unsigned int sign : 1;
232 typedef union Cv32suf
239 unsigned int significand : 23;
240 unsigned int exponent : 8;
241 unsigned int sign : 1;
246 typedef union Cv64suf
254 #define OPENCV_ABI_COMPATIBILITY 400
256 #ifdef __OPENCV_BUILD
257 # define DISABLE_OPENCV_3_COMPATIBILITY
258 # define OPENCV_DISABLE_DEPRECATED_COMPATIBILITY
262 # if (defined _WIN32 || defined WINCE || defined __CYGWIN__)
263 # define CV_EXPORTS __declspec(dllexport)
264 # elif defined __GNUC__ && __GNUC__ >= 4
265 # define CV_EXPORTS __attribute__ ((visibility ("default")))
274 # define CV_EXPORTS_TEMPLATE
276 # define CV_EXPORTS_TEMPLATE CV_EXPORTS
279 #ifndef CV_DEPRECATED
280 # if defined(__GNUC__)
281 # define CV_DEPRECATED __attribute__ ((deprecated))
282 # elif defined(_MSC_VER)
283 # define CV_DEPRECATED __declspec(deprecated)
285 # define CV_DEPRECATED
291 # define CV_EXTERN_C extern "C"
297 /* special informative macros for wrapper generators */
298 #define CV_EXPORTS_W CV_EXPORTS
299 #define CV_EXPORTS_W_SIMPLE CV_EXPORTS
300 #define CV_EXPORTS_AS(synonym) CV_EXPORTS
301 #define CV_EXPORTS_W_MAP CV_EXPORTS
307 #define CV_WRAP_AS(synonym)
309 /****************************************************************************************\
310 * Matrix type (Mat) *
311 \****************************************************************************************/
313 #define CV_MAT_CN_MASK ((CV_CN_MAX - 1) << CV_CN_SHIFT)
314 #define CV_MAT_CN(flags) ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1)
315 #define CV_MAT_TYPE_MASK (CV_DEPTH_MAX*CV_CN_MAX - 1)
316 #define CV_MAT_TYPE(flags) ((flags) & CV_MAT_TYPE_MASK)
317 #define CV_MAT_CONT_FLAG_SHIFT 14
318 #define CV_MAT_CONT_FLAG (1 << CV_MAT_CONT_FLAG_SHIFT)
319 #define CV_IS_MAT_CONT(flags) ((flags) & CV_MAT_CONT_FLAG)
320 #define CV_IS_CONT_MAT CV_IS_MAT_CONT
321 #define CV_SUBMAT_FLAG_SHIFT 15
322 #define CV_SUBMAT_FLAG (1 << CV_SUBMAT_FLAG_SHIFT)
323 #define CV_IS_SUBMAT(flags) ((flags) & CV_MAT_SUBMAT_FLAG)
325 /** Size of each channel item,
326 0x8442211 = 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */
327 #define CV_ELEM_SIZE1(type) \
328 ((((sizeof(size_t)<<28)|0x8442211) >> CV_MAT_DEPTH(type)*4) & 15)
330 /** 0x3a50 = 11 10 10 01 01 00 00 ~ array of log2(sizeof(arr_type_elem)) */
331 #define CV_ELEM_SIZE(type) \
332 (CV_MAT_CN(type) << ((((sizeof(size_t)/4+1)*16384|0x3a50) >> CV_MAT_DEPTH(type)*2) & 3))
335 # define MIN(a,b) ((a) > (b) ? (b) : (a))
339 # define MAX(a,b) ((a) < (b) ? (b) : (a))
342 /****************************************************************************************\
344 \****************************************************************************************/
346 // In practice, some macro are not processed correctly (noreturn is not detected).
347 // We need to use simplified definition for them.
348 #ifndef CV_STATIC_ANALYSIS
349 # if defined(__KLOCWORK__) || defined(__clang_analyzer__) || defined(__COVERITY__)
350 # define CV_STATIC_ANALYSIS
354 /****************************************************************************************\
356 \****************************************************************************************/
357 #ifndef CV_THREAD_SANITIZER
358 # if defined(__has_feature)
359 # if __has_feature(thread_sanitizer)
360 # define CV_THREAD_SANITIZER
365 /****************************************************************************************\
366 * exchange-add operation for atomic operations on reference counters *
367 \****************************************************************************************/
370 // allow to use user-defined macro
371 #elif defined __GNUC__ || defined __clang__
372 # if defined __clang__ && __clang_major__ >= 3 && !defined __ANDROID__ && !defined __EMSCRIPTEN__ && !defined(__CUDACC__)
373 # ifdef __ATOMIC_ACQ_REL
374 # define CV_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), delta, __ATOMIC_ACQ_REL)
376 # define CV_XADD(addr, delta) __atomic_fetch_add((_Atomic(int)*)(addr), delta, 4)
379 # if defined __ATOMIC_ACQ_REL && !defined __clang__
380 // version for gcc >= 4.7
381 # define CV_XADD(addr, delta) (int)__atomic_fetch_add((unsigned*)(addr), (unsigned)(delta), __ATOMIC_ACQ_REL)
383 # define CV_XADD(addr, delta) (int)__sync_fetch_and_add((unsigned*)(addr), (unsigned)(delta))
386 #elif defined _MSC_VER && !defined RC_INVOKED
388 # define CV_XADD(addr, delta) (int)_InterlockedExchangeAdd((long volatile*)addr, delta)
390 CV_INLINE CV_XADD(int* addr, int delta) { int tmp = *addr; *addr += delta; return tmp; }
394 /****************************************************************************************\
395 * CV_NORETURN attribute *
396 \****************************************************************************************/
399 # if defined(__GNUC__)
400 # define CV_NORETURN __attribute__((__noreturn__))
401 # elif defined(_MSC_VER) && (_MSC_VER >= 1300)
402 # define CV_NORETURN __declspec(noreturn)
404 # define CV_NORETURN /* nothing by default */
409 /****************************************************************************************\
410 * CV_NODISCARD attribute *
411 * encourages the compiler to issue a warning if the return value is discarded (C++17) *
412 \****************************************************************************************/
414 # if defined(__GNUC__)
415 # define CV_NODISCARD __attribute__((__warn_unused_result__)) // at least available with GCC 3.4
416 # elif defined(__clang__) && defined(__has_attribute)
417 # if __has_attribute(__warn_unused_result__)
418 # define CV_NODISCARD __attribute__((__warn_unused_result__))
423 # define CV_NODISCARD /* nothing by default */
427 /****************************************************************************************\
429 \****************************************************************************************/
431 # if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)
440 # error "OpenCV 4.x+ requires enabled C++11 support"
443 #define CV_CXX_MOVE_SEMANTICS 1
444 #define CV_CXX_STD_ARRAY 1
447 # define CV_OVERRIDE override
450 # define CV_FINAL final
454 // Integer types portatibility
455 #ifdef OPENCV_STDINT_HEADER
456 #include OPENCV_STDINT_HEADER
457 #elif defined(__cplusplus)
458 #if defined(_MSC_VER) && _MSC_VER < 1600 /* MSVS 2010 */
460 typedef signed char int8_t;
461 typedef unsigned char uint8_t;
462 typedef signed short int16_t;
463 typedef unsigned short uint16_t;
464 typedef signed int int32_t;
465 typedef unsigned int uint32_t;
466 typedef signed __int64 int64_t;
467 typedef unsigned __int64 uint64_t;
469 #elif defined(_MSC_VER) || __cplusplus >= 201103L
484 typedef ::int8_t int8_t;
485 typedef ::uint8_t uint8_t;
486 typedef ::int16_t int16_t;
487 typedef ::uint16_t uint16_t;
488 typedef ::int32_t int32_t;
489 typedef ::uint32_t uint32_t;
490 typedef ::int64_t int64_t;
491 typedef ::uint64_t uint64_t;
502 #include "opencv2/core/fast_math.hpp" // define cvRound(double)
505 #endif // OPENCV_CORE_CVDEF_H