core: add "namespace cv" in CV_StaticAssert fallback implementation
[platform/upstream/opencv.git] / modules / core / include / opencv2 / core / cvdef.h
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
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.
8 //
9 //
10 //                          License Agreement
11 //                For Open Source Computer Vision Library
12 //
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.
18 //
19 // Redistribution and use in source and binary forms, with or without modification,
20 // are permitted provided that the following conditions are met:
21 //
22 //   * Redistribution's of source code must retain the above copyright notice,
23 //     this list of conditions and the following disclaimer.
24 //
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.
28 //
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.
31 //
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.
42 //
43 //M*/
44
45 #ifndef OPENCV_CORE_CVDEF_H
46 #define OPENCV_CORE_CVDEF_H
47
48 //! @addtogroup core_utils
49 //! @{
50
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; }
59 #endif
60 #endif
61
62 #ifndef CV__DEBUG_NS_BEGIN
63 #define CV__DEBUG_NS_BEGIN
64 #define CV__DEBUG_NS_END
65 #endif
66
67
68 #ifdef __OPENCV_BUILD
69 #include "cvconfig.h"
70 #endif
71
72 #ifndef __CV_EXPAND
73 #define __CV_EXPAND(x) x
74 #endif
75
76 #ifndef __CV_CAT
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)
80 #endif
81
82 #define __CV_VA_NUM_ARGS_HELPER(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N
83 #define __CV_VA_NUM_ARGS(...) __CV_VA_NUM_ARGS_HELPER(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
84
85 #if defined __GNUC__
86 #define CV_Func __func__
87 #elif defined _MSC_VER
88 #define CV_Func __FUNCTION__
89 #else
90 #define CV_Func ""
91 #endif
92
93 //! @cond IGNORED
94
95 //////////////// static assert /////////////////
96 #define CVAUX_CONCAT_EXP(a, b) a##b
97 #define CVAUX_CONCAT(a, b) CVAUX_CONCAT_EXP(a,b)
98
99 #if defined(__clang__)
100 #  ifndef __has_extension
101 #    define __has_extension __has_feature /* compatibility, for older versions of clang */
102 #  endif
103 #  if __has_extension(cxx_static_assert)
104 #    define CV_StaticAssert(condition, reason)    static_assert((condition), reason " " #condition)
105 #  elif __has_extension(c_static_assert)
106 #    define CV_StaticAssert(condition, reason)    _Static_assert((condition), reason " " #condition)
107 #  endif
108 #elif defined(__GNUC__)
109 #  if (defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L)
110 #    define CV_StaticAssert(condition, reason)    static_assert((condition), reason " " #condition)
111 #  endif
112 #elif defined(_MSC_VER)
113 #  if _MSC_VER >= 1600 /* MSVC 10 */
114 #    define CV_StaticAssert(condition, reason)    static_assert((condition), reason " " #condition)
115 #  endif
116 #endif
117 #ifndef CV_StaticAssert
118 #  if !defined(__clang__) && defined(__GNUC__) && (__GNUC__*100 + __GNUC_MINOR__ > 302)
119 #    define CV_StaticAssert(condition, reason) ({ extern int __attribute__((error("CV_StaticAssert: " reason " " #condition))) CV_StaticAssert(); ((condition) ? 0 : CV_StaticAssert()); })
120 #  else
121 namespace cv {
122      template <bool x> struct CV_StaticAssert_failed;
123      template <> struct CV_StaticAssert_failed<true> { enum { val = 1 }; };
124      template<int x> struct CV_StaticAssert_test {};
125 }
126 #    define CV_StaticAssert(condition, reason)\
127        typedef cv::CV_StaticAssert_test< sizeof(cv::CV_StaticAssert_failed< static_cast<bool>(condition) >) > CVAUX_CONCAT(CV_StaticAssert_failed_at_, __LINE__)
128 #  endif
129 #endif
130
131 // Suppress warning "-Wdeprecated-declarations" / C4996
132 #if defined(_MSC_VER)
133     #define CV_DO_PRAGMA(x) __pragma(x)
134 #elif defined(__GNUC__)
135     #define CV_DO_PRAGMA(x) _Pragma (#x)
136 #else
137     #define CV_DO_PRAGMA(x)
138 #endif
139
140 #ifdef _MSC_VER
141 #define CV_SUPPRESS_DEPRECATED_START \
142     CV_DO_PRAGMA(warning(push)) \
143     CV_DO_PRAGMA(warning(disable: 4996))
144 #define CV_SUPPRESS_DEPRECATED_END CV_DO_PRAGMA(warning(pop))
145 #elif defined (__clang__) || ((__GNUC__)  && (__GNUC__*100 + __GNUC_MINOR__ > 405))
146 #define CV_SUPPRESS_DEPRECATED_START \
147     CV_DO_PRAGMA(GCC diagnostic push) \
148     CV_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations")
149 #define CV_SUPPRESS_DEPRECATED_END CV_DO_PRAGMA(GCC diagnostic pop)
150 #else
151 #define CV_SUPPRESS_DEPRECATED_START
152 #define CV_SUPPRESS_DEPRECATED_END
153 #endif
154
155 #define CV_UNUSED(name) (void)name
156
157 #if defined __GNUC__ && !defined __EXCEPTIONS
158 #define CV_TRY
159 #define CV_CATCH(A, B) for (A B; false; )
160 #define CV_CATCH_ALL if (false)
161 #define CV_THROW(A) abort()
162 #define CV_RETHROW() abort()
163 #else
164 #define CV_TRY try
165 #define CV_CATCH(A, B) catch(const A & B)
166 #define CV_CATCH_ALL catch(...)
167 #define CV_THROW(A) throw A
168 #define CV_RETHROW() throw
169 #endif
170
171 //! @endcond
172
173 // undef problematic defines sometimes defined by system headers (windows.h in particular)
174 #undef small
175 #undef min
176 #undef max
177 #undef abs
178 #undef Complex
179
180 #include <limits.h>
181 #include "opencv2/core/hal/interface.h"
182
183 #if defined __ICL
184 #  define CV_ICC   __ICL
185 #elif defined __ICC
186 #  define CV_ICC   __ICC
187 #elif defined __ECL
188 #  define CV_ICC   __ECL
189 #elif defined __ECC
190 #  define CV_ICC   __ECC
191 #elif defined __INTEL_COMPILER
192 #  define CV_ICC   __INTEL_COMPILER
193 #endif
194
195 #ifndef CV_INLINE
196 #  if defined __cplusplus
197 #    define CV_INLINE static inline
198 #  elif defined _MSC_VER
199 #    define CV_INLINE __inline
200 #  else
201 #    define CV_INLINE static
202 #  endif
203 #endif
204
205 #ifndef CV_ALWAYS_INLINE
206 #if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
207 #define CV_ALWAYS_INLINE inline __attribute__((always_inline))
208 #elif defined(_MSC_VER)
209 #define CV_ALWAYS_INLINE __forceinline
210 #else
211 #define CV_ALWAYS_INLINE inline
212 #endif
213 #endif
214
215 #if defined CV_DISABLE_OPTIMIZATION || (defined CV_ICC && !defined CV_ENABLE_UNROLLED)
216 #  define CV_ENABLE_UNROLLED 0
217 #else
218 #  define CV_ENABLE_UNROLLED 1
219 #endif
220
221 #ifdef __GNUC__
222 #  define CV_DECL_ALIGNED(x) __attribute__ ((aligned (x)))
223 #elif defined _MSC_VER
224 #  define CV_DECL_ALIGNED(x) __declspec(align(x))
225 #else
226 #  define CV_DECL_ALIGNED(x)
227 #endif
228
229 /* CPU features and intrinsics support */
230 #define CV_CPU_NONE             0
231 #define CV_CPU_MMX              1
232 #define CV_CPU_SSE              2
233 #define CV_CPU_SSE2             3
234 #define CV_CPU_SSE3             4
235 #define CV_CPU_SSSE3            5
236 #define CV_CPU_SSE4_1           6
237 #define CV_CPU_SSE4_2           7
238 #define CV_CPU_POPCNT           8
239 #define CV_CPU_FP16             9
240 #define CV_CPU_AVX              10
241 #define CV_CPU_AVX2             11
242 #define CV_CPU_FMA3             12
243
244 #define CV_CPU_AVX_512F         13
245 #define CV_CPU_AVX_512BW        14
246 #define CV_CPU_AVX_512CD        15
247 #define CV_CPU_AVX_512DQ        16
248 #define CV_CPU_AVX_512ER        17
249 #define CV_CPU_AVX_512IFMA512   18 // deprecated
250 #define CV_CPU_AVX_512IFMA      18
251 #define CV_CPU_AVX_512PF        19
252 #define CV_CPU_AVX_512VBMI      20
253 #define CV_CPU_AVX_512VL        21
254 #define CV_CPU_AVX_512VBMI2     22
255 #define CV_CPU_AVX_512VNNI      23
256 #define CV_CPU_AVX_512BITALG    24
257 #define CV_CPU_AVX_512VPOPCNTDQ 25
258 #define CV_CPU_AVX_5124VNNIW    26
259 #define CV_CPU_AVX_5124FMAPS    27
260
261 #define CV_CPU_NEON             100
262
263 #define CV_CPU_MSA              150
264
265 #define CV_CPU_VSX              200
266 #define CV_CPU_VSX3             201
267
268 // CPU features groups
269 #define CV_CPU_AVX512_SKX       256
270 #define CV_CPU_AVX512_COMMON    257
271 #define CV_CPU_AVX512_KNL       258
272 #define CV_CPU_AVX512_KNM       259
273 #define CV_CPU_AVX512_CNL       260
274 #define CV_CPU_AVX512_CLX       261
275 #define CV_CPU_AVX512_ICL       262
276
277 // when adding to this list remember to update the following enum
278 #define CV_HARDWARE_MAX_FEATURE 512
279
280 /** @brief Available CPU features.
281 */
282 enum CpuFeatures {
283     CPU_MMX             = 1,
284     CPU_SSE             = 2,
285     CPU_SSE2            = 3,
286     CPU_SSE3            = 4,
287     CPU_SSSE3           = 5,
288     CPU_SSE4_1          = 6,
289     CPU_SSE4_2          = 7,
290     CPU_POPCNT          = 8,
291     CPU_FP16            = 9,
292     CPU_AVX             = 10,
293     CPU_AVX2            = 11,
294     CPU_FMA3            = 12,
295
296     CPU_AVX_512F        = 13,
297     CPU_AVX_512BW       = 14,
298     CPU_AVX_512CD       = 15,
299     CPU_AVX_512DQ       = 16,
300     CPU_AVX_512ER       = 17,
301     CPU_AVX_512IFMA512  = 18, // deprecated
302     CPU_AVX_512IFMA     = 18,
303     CPU_AVX_512PF       = 19,
304     CPU_AVX_512VBMI     = 20,
305     CPU_AVX_512VL       = 21,
306     CPU_AVX_512VBMI2    = 22,
307     CPU_AVX_512VNNI     = 23,
308     CPU_AVX_512BITALG   = 24,
309     CPU_AVX_512VPOPCNTDQ= 25,
310     CPU_AVX_5124VNNIW   = 26,
311     CPU_AVX_5124FMAPS   = 27,
312
313     CPU_NEON            = 100,
314
315     CPU_MSA             = 150,
316
317     CPU_VSX             = 200,
318     CPU_VSX3            = 201,
319
320     CPU_AVX512_SKX      = 256, //!< Skylake-X with AVX-512F/CD/BW/DQ/VL
321     CPU_AVX512_COMMON   = 257, //!< Common instructions AVX-512F/CD for all CPUs that support AVX-512
322     CPU_AVX512_KNL      = 258, //!< Knights Landing with AVX-512F/CD/ER/PF
323     CPU_AVX512_KNM      = 259, //!< Knights Mill with AVX-512F/CD/ER/PF/4FMAPS/4VNNIW/VPOPCNTDQ
324     CPU_AVX512_CNL      = 260, //!< Cannon Lake with AVX-512F/CD/BW/DQ/VL/IFMA/VBMI
325     CPU_AVX512_CLX      = 261, //!< Cascade Lake with AVX-512F/CD/BW/DQ/VL/VNNI
326     CPU_AVX512_ICL      = 262, //!< Ice Lake with AVX-512F/CD/BW/DQ/VL/IFMA/VBMI/VNNI/VBMI2/BITALG/VPOPCNTDQ
327
328     CPU_MAX_FEATURE     = 512  // see CV_HARDWARE_MAX_FEATURE
329 };
330
331
332 #include "cv_cpu_dispatch.h"
333
334
335 /* fundamental constants */
336 #define CV_PI   3.1415926535897932384626433832795
337 #define CV_2PI  6.283185307179586476925286766559
338 #define CV_LOG2 0.69314718055994530941723212145818
339
340 #if defined __ARM_FP16_FORMAT_IEEE \
341     && !defined __CUDACC__
342 #  define CV_FP16_TYPE 1
343 #else
344 #  define CV_FP16_TYPE 0
345 #endif
346
347 typedef union Cv16suf
348 {
349     short i;
350     ushort u;
351 #if CV_FP16_TYPE
352     __fp16 h;
353 #endif
354 }
355 Cv16suf;
356
357 typedef union Cv32suf
358 {
359     int i;
360     unsigned u;
361     float f;
362 }
363 Cv32suf;
364
365 typedef union Cv64suf
366 {
367     int64 i;
368     uint64 u;
369     double f;
370 }
371 Cv64suf;
372
373 #define OPENCV_ABI_COMPATIBILITY 300
374
375 #ifdef __OPENCV_BUILD
376 #  define DISABLE_OPENCV_24_COMPATIBILITY
377 #  define OPENCV_DISABLE_DEPRECATED_COMPATIBILITY
378 #endif
379
380 #ifndef CV_EXPORTS
381 # if (defined _WIN32 || defined WINCE || defined __CYGWIN__) && defined(CVAPI_EXPORTS)
382 #   define CV_EXPORTS __declspec(dllexport)
383 # elif defined __GNUC__ && __GNUC__ >= 4 && (defined(CVAPI_EXPORTS) || defined(__APPLE__))
384 #   define CV_EXPORTS __attribute__ ((visibility ("default")))
385 # endif
386 #endif
387
388 #ifndef CV_EXPORTS
389 # define CV_EXPORTS
390 #endif
391
392 #ifdef _MSC_VER
393 #   define CV_EXPORTS_TEMPLATE
394 #else
395 #   define CV_EXPORTS_TEMPLATE CV_EXPORTS
396 #endif
397
398 #ifndef CV_DEPRECATED
399 #  if defined(__GNUC__)
400 #    define CV_DEPRECATED __attribute__ ((deprecated))
401 #  elif defined(_MSC_VER)
402 #    define CV_DEPRECATED __declspec(deprecated)
403 #  else
404 #    define CV_DEPRECATED
405 #  endif
406 #endif
407
408 #ifndef CV_DEPRECATED_EXTERNAL
409 #  if defined(__OPENCV_BUILD)
410 #    define CV_DEPRECATED_EXTERNAL /* nothing */
411 #  else
412 #    define CV_DEPRECATED_EXTERNAL CV_DEPRECATED
413 #  endif
414 #endif
415
416
417 #ifndef CV_EXTERN_C
418 #  ifdef __cplusplus
419 #    define CV_EXTERN_C extern "C"
420 #  else
421 #    define CV_EXTERN_C
422 #  endif
423 #endif
424
425 /* special informative macros for wrapper generators */
426 #define CV_EXPORTS_W CV_EXPORTS
427 #define CV_EXPORTS_W_SIMPLE CV_EXPORTS
428 #define CV_EXPORTS_AS(synonym) CV_EXPORTS
429 #define CV_EXPORTS_W_MAP CV_EXPORTS
430 #define CV_IN_OUT
431 #define CV_OUT
432 #define CV_PROP
433 #define CV_PROP_RW
434 #define CV_WRAP
435 #define CV_WRAP_AS(synonym)
436
437 /****************************************************************************************\
438 *                                  Matrix type (Mat)                                     *
439 \****************************************************************************************/
440
441 #define CV_MAT_CN_MASK          ((CV_CN_MAX - 1) << CV_CN_SHIFT)
442 #define CV_MAT_CN(flags)        ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1)
443 #define CV_MAT_TYPE_MASK        (CV_DEPTH_MAX*CV_CN_MAX - 1)
444 #define CV_MAT_TYPE(flags)      ((flags) & CV_MAT_TYPE_MASK)
445 #define CV_MAT_CONT_FLAG_SHIFT  14
446 #define CV_MAT_CONT_FLAG        (1 << CV_MAT_CONT_FLAG_SHIFT)
447 #define CV_IS_MAT_CONT(flags)   ((flags) & CV_MAT_CONT_FLAG)
448 #define CV_IS_CONT_MAT          CV_IS_MAT_CONT
449 #define CV_SUBMAT_FLAG_SHIFT    15
450 #define CV_SUBMAT_FLAG          (1 << CV_SUBMAT_FLAG_SHIFT)
451 #define CV_IS_SUBMAT(flags)     ((flags) & CV_MAT_SUBMAT_FLAG)
452
453 /** Size of each channel item,
454    0x8442211 = 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */
455 #define CV_ELEM_SIZE1(type) \
456     ((((sizeof(size_t)<<28)|0x8442211) >> CV_MAT_DEPTH(type)*4) & 15)
457
458 /** 0x3a50 = 11 10 10 01 01 00 00 ~ array of log2(sizeof(arr_type_elem)) */
459 #define CV_ELEM_SIZE(type) \
460     (CV_MAT_CN(type) << ((((sizeof(size_t)/4+1)*16384|0x3a50) >> CV_MAT_DEPTH(type)*2) & 3))
461
462 #ifndef MIN
463 #  define MIN(a,b)  ((a) > (b) ? (b) : (a))
464 #endif
465
466 #ifndef MAX
467 #  define MAX(a,b)  ((a) < (b) ? (b) : (a))
468 #endif
469
470 /****************************************************************************************\
471 *                                    static analysys                                     *
472 \****************************************************************************************/
473
474 // In practice, some macro are not processed correctly (noreturn is not detected).
475 // We need to use simplified definition for them.
476 #ifndef CV_STATIC_ANALYSIS
477 # if defined(__KLOCWORK__) || defined(__clang_analyzer__) || defined(__COVERITY__)
478 #   define CV_STATIC_ANALYSIS 1
479 # endif
480 #else
481 # if defined(CV_STATIC_ANALYSIS) && !(__CV_CAT(1, CV_STATIC_ANALYSIS) == 1)  // defined and not empty
482 #   if 0 == CV_STATIC_ANALYSIS
483 #     undef CV_STATIC_ANALYSIS
484 #   endif
485 # endif
486 #endif
487
488 /****************************************************************************************\
489 *                                    Thread sanitizer                                    *
490 \****************************************************************************************/
491 #ifndef CV_THREAD_SANITIZER
492 # if defined(__has_feature)
493 #   if __has_feature(thread_sanitizer)
494 #     define CV_THREAD_SANITIZER
495 #   endif
496 # endif
497 #endif
498
499 /****************************************************************************************\
500 *          exchange-add operation for atomic operations on reference counters            *
501 \****************************************************************************************/
502
503 #ifdef CV_XADD
504   // allow to use user-defined macro
505 #elif defined __GNUC__ || defined __clang__
506 #  if defined __clang__ && __clang_major__ >= 3 && !defined __ANDROID__ && !defined __EMSCRIPTEN__ && !defined(__CUDACC__)  && !defined __INTEL_COMPILER
507 #    ifdef __ATOMIC_ACQ_REL
508 #      define CV_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), delta, __ATOMIC_ACQ_REL)
509 #    else
510 #      define CV_XADD(addr, delta) __atomic_fetch_add((_Atomic(int)*)(addr), delta, 4)
511 #    endif
512 #  else
513 #    if defined __ATOMIC_ACQ_REL && !defined __clang__
514        // version for gcc >= 4.7
515 #      define CV_XADD(addr, delta) (int)__atomic_fetch_add((unsigned*)(addr), (unsigned)(delta), __ATOMIC_ACQ_REL)
516 #    else
517 #      define CV_XADD(addr, delta) (int)__sync_fetch_and_add((unsigned*)(addr), (unsigned)(delta))
518 #    endif
519 #  endif
520 #elif defined _MSC_VER && !defined RC_INVOKED
521 #  include <intrin.h>
522 #  define CV_XADD(addr, delta) (int)_InterlockedExchangeAdd((long volatile*)addr, delta)
523 #else
524    CV_INLINE CV_XADD(int* addr, int delta) { int tmp = *addr; *addr += delta; return tmp; }
525 #endif
526
527
528 /****************************************************************************************\
529 *                                  CV_NORETURN attribute                                 *
530 \****************************************************************************************/
531
532 #ifndef CV_NORETURN
533 #  if defined(__GNUC__)
534 #    define CV_NORETURN __attribute__((__noreturn__))
535 #  elif defined(_MSC_VER) && (_MSC_VER >= 1300)
536 #    define CV_NORETURN __declspec(noreturn)
537 #  else
538 #    define CV_NORETURN /* nothing by default */
539 #  endif
540 #endif
541
542
543 /****************************************************************************************\
544 *                                  CV_NODISCARD attribute                                *
545 * encourages the compiler to issue a warning if the return value is discarded (C++17)    *
546 \****************************************************************************************/
547 #ifndef CV_NODISCARD
548 #  if defined(__GNUC__)
549 #    define CV_NODISCARD __attribute__((__warn_unused_result__)) // at least available with GCC 3.4
550 #  elif defined(__clang__) && defined(__has_attribute)
551 #    if __has_attribute(__warn_unused_result__)
552 #      define CV_NODISCARD __attribute__((__warn_unused_result__))
553 #    endif
554 #  endif
555 #endif
556 #ifndef CV_NODISCARD
557 #  define CV_NODISCARD /* nothing by default */
558 #endif
559
560
561 /****************************************************************************************\
562 *                                    C++ 11                                              *
563 \****************************************************************************************/
564 #ifndef CV_CXX11
565 #  if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)
566 #    define CV_CXX11 1
567 #  endif
568 #else
569 #  if CV_CXX11 == 0
570 #    undef CV_CXX11
571 #  endif
572 #endif
573
574
575 /****************************************************************************************\
576 *                                    C++ Move semantics                                  *
577 \****************************************************************************************/
578
579 #ifndef CV_CXX_MOVE_SEMANTICS
580 #  if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) || (defined(_MSC_VER) && _MSC_VER >= 1600)
581 #    define CV_CXX_MOVE_SEMANTICS 1
582 #  elif defined(__clang)
583 #    if __has_feature(cxx_rvalue_references)
584 #      define CV_CXX_MOVE_SEMANTICS 1
585 #    endif
586 #  endif
587 #else
588 #  if CV_CXX_MOVE_SEMANTICS == 0
589 #    undef CV_CXX_MOVE_SEMANTICS
590 #  endif
591 #endif
592
593 #ifdef CV_CXX_MOVE_SEMANTICS
594 #define CV_CXX_MOVE(x) std::move(x)
595 #else
596 #define CV_CXX_MOVE(x) (x)
597 #endif
598
599
600 /****************************************************************************************\
601 *                                    C++11 std::array                                    *
602 \****************************************************************************************/
603
604 #ifndef CV_CXX_STD_ARRAY
605 #  if __cplusplus >= 201103L || (defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS 2015*/)
606 #    define CV_CXX_STD_ARRAY 1
607 #    include <array>
608 #  endif
609 #else
610 #  if CV_CXX_STD_ARRAY == 0
611 #    undef CV_CXX_STD_ARRAY
612 #  endif
613 #endif
614
615
616 /****************************************************************************************\
617 *                                 C++11 override / final                                 *
618 \****************************************************************************************/
619
620 #ifndef CV_OVERRIDE
621 #  ifdef CV_CXX11
622 #    define CV_OVERRIDE override
623 #  endif
624 #endif
625 #ifndef CV_OVERRIDE
626 #  define CV_OVERRIDE
627 #endif
628
629 #ifndef CV_FINAL
630 #  ifdef CV_CXX11
631 #    define CV_FINAL final
632 #  endif
633 #endif
634 #ifndef CV_FINAL
635 #  define CV_FINAL
636 #endif
637
638 /****************************************************************************************\
639 *                                     C++11 noexcept                                     *
640 \****************************************************************************************/
641
642 #ifndef CV_NOEXCEPT
643 #  if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS 2015*/)
644 #    define CV_NOEXCEPT noexcept
645 #  endif
646 #endif
647 #ifndef CV_NOEXCEPT
648 #  define CV_NOEXCEPT
649 #endif
650
651
652
653 // Integer types portatibility
654 #ifdef OPENCV_STDINT_HEADER
655 #include OPENCV_STDINT_HEADER
656 #elif defined(__cplusplus)
657 #if defined(_MSC_VER) && _MSC_VER < 1600 /* MSVS 2010 */
658 namespace cv {
659 typedef signed char int8_t;
660 typedef unsigned char uint8_t;
661 typedef signed short int16_t;
662 typedef unsigned short uint16_t;
663 typedef signed int int32_t;
664 typedef unsigned int uint32_t;
665 typedef signed __int64 int64_t;
666 typedef unsigned __int64 uint64_t;
667 }
668 #elif defined(_MSC_VER) || __cplusplus >= 201103L
669 #include <cstdint>
670 namespace cv {
671 using std::int8_t;
672 using std::uint8_t;
673 using std::int16_t;
674 using std::uint16_t;
675 using std::int32_t;
676 using std::uint32_t;
677 using std::int64_t;
678 using std::uint64_t;
679 }
680 #else
681 #include <stdint.h>
682 namespace cv {
683 typedef ::int8_t int8_t;
684 typedef ::uint8_t uint8_t;
685 typedef ::int16_t int16_t;
686 typedef ::uint16_t uint16_t;
687 typedef ::int32_t int32_t;
688 typedef ::uint32_t uint32_t;
689 typedef ::int64_t int64_t;
690 typedef ::uint64_t uint64_t;
691 }
692 #endif
693 #else // pure C
694 #include <stdint.h>
695 #endif
696
697 #ifdef __cplusplus
698 namespace cv
699 {
700
701 class float16_t
702 {
703 public:
704 #if CV_FP16_TYPE
705
706     float16_t() {}
707     explicit float16_t(float x) { h = (__fp16)x; }
708     operator float() const { return (float)h; }
709     static float16_t fromBits(ushort w)
710     {
711         Cv16suf u;
712         u.u = w;
713         float16_t result;
714         result.h = u.h;
715         return result;
716     }
717     static float16_t zero()
718     {
719         float16_t result;
720         result.h = (__fp16)0;
721         return result;
722     }
723     ushort bits() const
724     {
725         Cv16suf u;
726         u.h = h;
727         return u.u;
728     }
729 protected:
730     __fp16 h;
731
732 #else
733     float16_t() {}
734     explicit float16_t(float x)
735     {
736     #if CV_AVX2
737         __m128 v = _mm_load_ss(&x);
738         w = (ushort)_mm_cvtsi128_si32(_mm_cvtps_ph(v, 0));
739     #else
740         Cv32suf in;
741         in.f = x;
742         unsigned sign = in.u & 0x80000000;
743         in.u ^= sign;
744
745         if( in.u >= 0x47800000 )
746             w = (ushort)(in.u > 0x7f800000 ? 0x7e00 : 0x7c00);
747         else
748         {
749             if (in.u < 0x38800000)
750             {
751                 in.f += 0.5f;
752                 w = (ushort)(in.u - 0x3f000000);
753             }
754             else
755             {
756                 unsigned t = in.u + 0xc8000fff;
757                 w = (ushort)((t + ((in.u >> 13) & 1)) >> 13);
758             }
759         }
760
761         w = (ushort)(w | (sign >> 16));
762     #endif
763     }
764
765     operator float() const
766     {
767     #if CV_AVX2
768         float f;
769         _mm_store_ss(&f, _mm_cvtph_ps(_mm_cvtsi32_si128(w)));
770         return f;
771     #else
772         Cv32suf out;
773
774         unsigned t = ((w & 0x7fff) << 13) + 0x38000000;
775         unsigned sign = (w & 0x8000) << 16;
776         unsigned e = w & 0x7c00;
777
778         out.u = t + (1 << 23);
779         out.u = (e >= 0x7c00 ? t + 0x38000000 :
780                  e == 0 ? (out.f -= 6.103515625e-05f, out.u) : t) | sign;
781         return out.f;
782     #endif
783     }
784
785     static float16_t fromBits(ushort b)
786     {
787         float16_t result;
788         result.w = b;
789         return result;
790     }
791     static float16_t zero()
792     {
793         float16_t result;
794         result.w = (ushort)0;
795         return result;
796     }
797     ushort bits() const { return w; }
798 protected:
799     ushort w;
800
801 #endif
802 };
803
804 }
805 #endif
806
807 //! @}
808
809 #ifndef __cplusplus
810 #include "opencv2/core/fast_math.hpp" // define cvRound(double)
811 #endif
812
813 #endif // OPENCV_CORE_CVDEF_H