Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: RZ_A2M_Mbed_samples
intrin.hpp
00001 /*M/////////////////////////////////////////////////////////////////////////////////////// 00002 // 00003 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 00004 // 00005 // By downloading, copying, installing or using the software you agree to this license. 00006 // If you do not agree to this license, do not download, install, 00007 // copy or use the software. 00008 // 00009 // 00010 // License Agreement 00011 // For Open Source Computer Vision Library 00012 // 00013 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 00014 // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 00015 // Copyright (C) 2013, OpenCV Foundation, all rights reserved. 00016 // Copyright (C) 2015, Itseez Inc., all rights reserved. 00017 // Third party copyrights are property of their respective owners. 00018 // 00019 // Redistribution and use in source and binary forms, with or without modification, 00020 // are permitted provided that the following conditions are met: 00021 // 00022 // * Redistribution's of source code must retain the above copyright notice, 00023 // this list of conditions and the following disclaimer. 00024 // 00025 // * Redistribution's in binary form must reproduce the above copyright notice, 00026 // this list of conditions and the following disclaimer in the documentation 00027 // and/or other materials provided with the distribution. 00028 // 00029 // * The name of the copyright holders may not be used to endorse or promote products 00030 // derived from this software without specific prior written permission. 00031 // 00032 // This software is provided by the copyright holders and contributors "as is" and 00033 // any express or implied warranties, including, but not limited to, the implied 00034 // warranties of merchantability and fitness for a particular purpose are disclaimed. 00035 // In no event shall the Intel Corporation or contributors be liable for any direct, 00036 // indirect, incidental, special, exemplary, or consequential damages 00037 // (including, but not limited to, procurement of substitute goods or services; 00038 // loss of use, data, or profits; or business interruption) however caused 00039 // and on any theory of liability, whether in contract, strict liability, 00040 // or tort (including negligence or otherwise) arising in any way out of 00041 // the use of this software, even if advised of the possibility of such damage. 00042 // 00043 //M*/ 00044 00045 #ifndef OPENCV_HAL_INTRIN_HPP 00046 #define OPENCV_HAL_INTRIN_HPP 00047 00048 #include <cmath> 00049 #include <float.h> 00050 #include <stdlib.h> 00051 #include "opencv2/core/cvdef.h" 00052 00053 #define OPENCV_HAL_ADD(a, b) ((a) + (b)) 00054 #define OPENCV_HAL_AND(a, b) ((a) & (b)) 00055 #define OPENCV_HAL_NOP(a) (a) 00056 #define OPENCV_HAL_1ST(a, b) (a) 00057 00058 // unlike HAL API, which is in cv::hal, 00059 // we put intrinsics into cv namespace to make its 00060 // access from within opencv code more accessible 00061 namespace cv { 00062 00063 //! @addtogroup core_hal_intrin 00064 //! @{ 00065 00066 //! @cond IGNORED 00067 template<typename _Tp> struct V_TypeTraits 00068 { 00069 typedef _Tp int_type; 00070 typedef _Tp uint_type; 00071 typedef _Tp abs_type; 00072 typedef _Tp sum_type; 00073 00074 enum { delta = 0, shift = 0 }; 00075 00076 static int_type reinterpret_int(_Tp x) { return x; } 00077 static uint_type reinterpet_uint(_Tp x) { return x; } 00078 static _Tp reinterpret_from_int(int_type x) { return (_Tp)x; } 00079 }; 00080 00081 template<> struct V_TypeTraits<uchar> 00082 { 00083 typedef uchar value_type; 00084 typedef schar int_type; 00085 typedef uchar uint_type; 00086 typedef uchar abs_type; 00087 typedef int sum_type; 00088 00089 typedef ushort w_type; 00090 typedef unsigned q_type; 00091 00092 enum { delta = 128, shift = 8 }; 00093 00094 static int_type reinterpret_int(value_type x) { return (int_type)x; } 00095 static uint_type reinterpret_uint(value_type x) { return (uint_type)x; } 00096 static value_type reinterpret_from_int(int_type x) { return (value_type)x; } 00097 }; 00098 00099 template<> struct V_TypeTraits<schar> 00100 { 00101 typedef schar value_type; 00102 typedef schar int_type; 00103 typedef uchar uint_type; 00104 typedef uchar abs_type; 00105 typedef int sum_type; 00106 00107 typedef short w_type; 00108 typedef int q_type; 00109 00110 enum { delta = 128, shift = 8 }; 00111 00112 static int_type reinterpret_int(value_type x) { return (int_type)x; } 00113 static uint_type reinterpret_uint(value_type x) { return (uint_type)x; } 00114 static value_type reinterpret_from_int(int_type x) { return (value_type)x; } 00115 }; 00116 00117 template<> struct V_TypeTraits<ushort> 00118 { 00119 typedef ushort value_type; 00120 typedef short int_type; 00121 typedef ushort uint_type; 00122 typedef ushort abs_type; 00123 typedef int sum_type; 00124 00125 typedef unsigned w_type; 00126 typedef uchar nu_type; 00127 00128 enum { delta = 32768, shift = 16 }; 00129 00130 static int_type reinterpret_int(value_type x) { return (int_type)x; } 00131 static uint_type reinterpret_uint(value_type x) { return (uint_type)x; } 00132 static value_type reinterpret_from_int(int_type x) { return (value_type)x; } 00133 }; 00134 00135 template<> struct V_TypeTraits<short> 00136 { 00137 typedef short value_type; 00138 typedef short int_type; 00139 typedef ushort uint_type; 00140 typedef ushort abs_type; 00141 typedef int sum_type; 00142 00143 typedef int w_type; 00144 typedef uchar nu_type; 00145 typedef schar n_type; 00146 00147 enum { delta = 128, shift = 8 }; 00148 00149 static int_type reinterpret_int(value_type x) { return (int_type)x; } 00150 static uint_type reinterpret_uint(value_type x) { return (uint_type)x; } 00151 static value_type reinterpret_from_int(int_type x) { return (value_type)x; } 00152 }; 00153 00154 template<> struct V_TypeTraits<unsigned> 00155 { 00156 typedef unsigned value_type; 00157 typedef int int_type; 00158 typedef unsigned uint_type; 00159 typedef unsigned abs_type; 00160 typedef unsigned sum_type; 00161 00162 typedef uint64 w_type; 00163 typedef ushort nu_type; 00164 00165 static int_type reinterpret_int(value_type x) { return (int_type)x; } 00166 static uint_type reinterpret_uint(value_type x) { return (uint_type)x; } 00167 static value_type reinterpret_from_int(int_type x) { return (value_type)x; } 00168 }; 00169 00170 template<> struct V_TypeTraits<int> 00171 { 00172 typedef int value_type; 00173 typedef int int_type; 00174 typedef unsigned uint_type; 00175 typedef unsigned abs_type; 00176 typedef int sum_type; 00177 00178 typedef int64 w_type; 00179 typedef short n_type; 00180 typedef ushort nu_type; 00181 00182 static int_type reinterpret_int(value_type x) { return (int_type)x; } 00183 static uint_type reinterpret_uint(value_type x) { return (uint_type)x; } 00184 static value_type reinterpret_from_int(int_type x) { return (value_type)x; } 00185 }; 00186 00187 template<> struct V_TypeTraits<uint64> 00188 { 00189 typedef uint64 value_type; 00190 typedef int64 int_type; 00191 typedef uint64 uint_type; 00192 typedef uint64 abs_type; 00193 typedef uint64 sum_type; 00194 00195 typedef unsigned nu_type; 00196 00197 static int_type reinterpret_int(value_type x) { return (int_type)x; } 00198 static uint_type reinterpret_uint(value_type x) { return (uint_type)x; } 00199 static value_type reinterpret_from_int(int_type x) { return (value_type)x; } 00200 }; 00201 00202 template<> struct V_TypeTraits<int64> 00203 { 00204 typedef int64 value_type; 00205 typedef int64 int_type; 00206 typedef uint64 uint_type; 00207 typedef uint64 abs_type; 00208 typedef int64 sum_type; 00209 00210 typedef int nu_type; 00211 00212 static int_type reinterpret_int(value_type x) { return (int_type)x; } 00213 static uint_type reinterpret_uint(value_type x) { return (uint_type)x; } 00214 static value_type reinterpret_from_int(int_type x) { return (value_type)x; } 00215 }; 00216 00217 00218 template<> struct V_TypeTraits<float> 00219 { 00220 typedef float value_type; 00221 typedef int int_type; 00222 typedef unsigned uint_type; 00223 typedef float abs_type; 00224 typedef float sum_type; 00225 00226 typedef double w_type; 00227 00228 static int_type reinterpret_int(value_type x) 00229 { 00230 Cv32suf u; 00231 u.f = x; 00232 return u.i; 00233 } 00234 static uint_type reinterpet_uint(value_type x) 00235 { 00236 Cv32suf u; 00237 u.f = x; 00238 return u.u; 00239 } 00240 static value_type reinterpret_from_int(int_type x) 00241 { 00242 Cv32suf u; 00243 u.i = x; 00244 return u.f; 00245 } 00246 }; 00247 00248 template<> struct V_TypeTraits<double> 00249 { 00250 typedef double value_type; 00251 typedef int64 int_type; 00252 typedef uint64 uint_type; 00253 typedef double abs_type; 00254 typedef double sum_type; 00255 static int_type reinterpret_int(value_type x) 00256 { 00257 Cv64suf u; 00258 u.f = x; 00259 return u.i; 00260 } 00261 static uint_type reinterpet_uint(value_type x) 00262 { 00263 Cv64suf u; 00264 u.f = x; 00265 return u.u; 00266 } 00267 static value_type reinterpret_from_int(int_type x) 00268 { 00269 Cv64suf u; 00270 u.i = x; 00271 return u.f; 00272 } 00273 }; 00274 00275 template <typename T> struct V_SIMD128Traits 00276 { 00277 enum { nlanes = 16 / sizeof(T) }; 00278 }; 00279 00280 //! @endcond 00281 00282 //! @} 00283 00284 } 00285 00286 #ifdef CV_DOXYGEN 00287 # undef CV_SSE2 00288 # undef CV_NEON 00289 #endif 00290 00291 #if CV_SSE2 00292 00293 #include "opencv2/core/hal/intrin_sse.hpp" 00294 00295 #elif CV_NEON 00296 00297 #include "opencv2/core/hal/intrin_neon.hpp" 00298 00299 #else 00300 00301 #include "opencv2/core/hal/intrin_cpp.hpp" 00302 00303 #endif 00304 00305 //! @addtogroup core_hal_intrin 00306 //! @{ 00307 00308 #ifndef CV_SIMD128 00309 //! Set to 1 if current compiler supports vector extensions (NEON or SSE is enabled) 00310 #define CV_SIMD128 0 00311 #endif 00312 00313 #ifndef CV_SIMD128_64F 00314 //! Set to 1 if current intrinsics implementation supports 64-bit float vectors 00315 #define CV_SIMD128_64F 0 00316 #endif 00317 00318 //! @} 00319 00320 //================================================================================================== 00321 00322 //! @cond IGNORED 00323 00324 namespace cv { 00325 00326 template <typename R> struct V_RegTrait128; 00327 00328 template <> struct V_RegTrait128<uchar> { 00329 typedef v_uint8x16 reg; 00330 typedef v_uint16x8 w_reg; 00331 typedef v_uint32x4 q_reg; 00332 typedef v_uint8x16 u_reg; 00333 static v_uint8x16 zero() { return v_setzero_u8(); } 00334 static v_uint8x16 all(uchar val) { return v_setall_u8(val); } 00335 }; 00336 00337 template <> struct V_RegTrait128<schar> { 00338 typedef v_int8x16 reg; 00339 typedef v_int16x8 w_reg; 00340 typedef v_int32x4 q_reg; 00341 typedef v_uint8x16 u_reg; 00342 static v_int8x16 zero() { return v_setzero_s8(); } 00343 static v_int8x16 all(schar val) { return v_setall_s8(val); } 00344 }; 00345 00346 template <> struct V_RegTrait128<ushort> { 00347 typedef v_uint16x8 reg; 00348 typedef v_uint32x4 w_reg; 00349 typedef v_int16x8 int_reg; 00350 typedef v_uint16x8 u_reg; 00351 static v_uint16x8 zero() { return v_setzero_u16(); } 00352 static v_uint16x8 all(ushort val) { return v_setall_u16(val); } 00353 }; 00354 00355 template <> struct V_RegTrait128<short> { 00356 typedef v_int16x8 reg; 00357 typedef v_int32x4 w_reg; 00358 typedef v_uint16x8 u_reg; 00359 static v_int16x8 zero() { return v_setzero_s16(); } 00360 static v_int16x8 all(short val) { return v_setall_s16(val); } 00361 }; 00362 00363 template <> struct V_RegTrait128<unsigned> { 00364 typedef v_uint32x4 reg; 00365 typedef v_uint64x2 w_reg; 00366 typedef v_int32x4 int_reg; 00367 typedef v_uint32x4 u_reg; 00368 static v_uint32x4 zero() { return v_setzero_u32(); } 00369 static v_uint32x4 all(unsigned val) { return v_setall_u32(val); } 00370 }; 00371 00372 template <> struct V_RegTrait128<int> { 00373 typedef v_int32x4 reg; 00374 typedef v_int64x2 w_reg; 00375 typedef v_uint32x4 u_reg; 00376 static v_int32x4 zero() { return v_setzero_s32(); } 00377 static v_int32x4 all(int val) { return v_setall_s32(val); } 00378 }; 00379 00380 template <> struct V_RegTrait128<uint64> { 00381 typedef v_uint64x2 reg; 00382 static v_uint64x2 zero() { return v_setzero_u64(); } 00383 static v_uint64x2 all(uint64 val) { return v_setall_u64(val); } 00384 }; 00385 00386 template <> struct V_RegTrait128<int64> { 00387 typedef v_int64x2 reg; 00388 static v_int64x2 zero() { return v_setzero_s64(); } 00389 static v_int64x2 all(int64 val) { return v_setall_s64(val); } 00390 }; 00391 00392 template <> struct V_RegTrait128<float> { 00393 typedef v_float32x4 reg; 00394 typedef v_int32x4 int_reg; 00395 typedef v_float32x4 u_reg; 00396 static v_float32x4 zero() { return v_setzero_f32(); } 00397 static v_float32x4 all(float val) { return v_setall_f32(val); } 00398 }; 00399 00400 #if CV_SIMD128_64F 00401 template <> struct V_RegTrait128<double> { 00402 typedef v_float64x2 reg; 00403 typedef v_int32x4 int_reg; 00404 typedef v_float64x2 u_reg; 00405 static v_float64x2 zero() { return v_setzero_f64(); } 00406 static v_float64x2 all(double val) { return v_setall_f64(val); } 00407 }; 00408 #endif 00409 00410 } // cv:: 00411 00412 //! @endcond 00413 00414 #endif
Generated on Tue Jul 12 2022 18:20:17 by
1.7.2