intrin.hpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. #ifndef __OPENCV_HAL_INTRIN_HPP__
  45. #define __OPENCV_HAL_INTRIN_HPP__
  46. #include <cmath>
  47. #include <float.h>
  48. #include <stdlib.h>
  49. #define OPENCV_HAL_ADD(a, b) ((a) + (b))
  50. #define OPENCV_HAL_AND(a, b) ((a) & (b))
  51. #define OPENCV_HAL_NOP(a) (a)
  52. #define OPENCV_HAL_1ST(a, b) (a)
  53. // unlike HAL API, which is in cv::hal,
  54. // we put intrinsics into cv namespace to make its
  55. // access from within opencv code more accessible
  56. namespace cv {
  57. template<typename _Tp> struct V_TypeTraits
  58. {
  59. typedef _Tp int_type;
  60. typedef _Tp uint_type;
  61. typedef _Tp abs_type;
  62. typedef _Tp sum_type;
  63. enum { delta = 0, shift = 0 };
  64. static int_type reinterpret_int(_Tp x) { return x; }
  65. static uint_type reinterpet_uint(_Tp x) { return x; }
  66. static _Tp reinterpret_from_int(int_type x) { return (_Tp)x; }
  67. };
  68. template<> struct V_TypeTraits<uchar>
  69. {
  70. typedef uchar value_type;
  71. typedef schar int_type;
  72. typedef uchar uint_type;
  73. typedef uchar abs_type;
  74. typedef int sum_type;
  75. typedef ushort w_type;
  76. enum { delta = 128, shift = 8 };
  77. static int_type reinterpret_int(value_type x) { return (int_type)x; }
  78. static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
  79. static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
  80. };
  81. template<> struct V_TypeTraits<schar>
  82. {
  83. typedef schar value_type;
  84. typedef schar int_type;
  85. typedef uchar uint_type;
  86. typedef uchar abs_type;
  87. typedef int sum_type;
  88. typedef short w_type;
  89. enum { delta = 128, shift = 8 };
  90. static int_type reinterpret_int(value_type x) { return (int_type)x; }
  91. static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
  92. static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
  93. };
  94. template<> struct V_TypeTraits<ushort>
  95. {
  96. typedef ushort value_type;
  97. typedef short int_type;
  98. typedef ushort uint_type;
  99. typedef ushort abs_type;
  100. typedef int sum_type;
  101. typedef unsigned w_type;
  102. typedef uchar nu_type;
  103. enum { delta = 32768, shift = 16 };
  104. static int_type reinterpret_int(value_type x) { return (int_type)x; }
  105. static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
  106. static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
  107. };
  108. template<> struct V_TypeTraits<short>
  109. {
  110. typedef short value_type;
  111. typedef short int_type;
  112. typedef ushort uint_type;
  113. typedef ushort abs_type;
  114. typedef int sum_type;
  115. typedef int w_type;
  116. typedef uchar nu_type;
  117. typedef schar n_type;
  118. enum { delta = 128, shift = 8 };
  119. static int_type reinterpret_int(value_type x) { return (int_type)x; }
  120. static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
  121. static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
  122. };
  123. template<> struct V_TypeTraits<unsigned>
  124. {
  125. typedef unsigned value_type;
  126. typedef int int_type;
  127. typedef unsigned uint_type;
  128. typedef unsigned abs_type;
  129. typedef unsigned sum_type;
  130. typedef uint64 w_type;
  131. typedef ushort nu_type;
  132. static int_type reinterpret_int(value_type x) { return (int_type)x; }
  133. static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
  134. static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
  135. };
  136. template<> struct V_TypeTraits<int>
  137. {
  138. typedef int value_type;
  139. typedef int int_type;
  140. typedef unsigned uint_type;
  141. typedef unsigned abs_type;
  142. typedef int sum_type;
  143. typedef int64 w_type;
  144. typedef short n_type;
  145. typedef ushort nu_type;
  146. static int_type reinterpret_int(value_type x) { return (int_type)x; }
  147. static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
  148. static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
  149. };
  150. template<> struct V_TypeTraits<uint64>
  151. {
  152. typedef uint64 value_type;
  153. typedef int64 int_type;
  154. typedef uint64 uint_type;
  155. typedef uint64 abs_type;
  156. typedef uint64 sum_type;
  157. typedef unsigned nu_type;
  158. static int_type reinterpret_int(value_type x) { return (int_type)x; }
  159. static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
  160. static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
  161. };
  162. template<> struct V_TypeTraits<int64>
  163. {
  164. typedef int64 value_type;
  165. typedef int64 int_type;
  166. typedef uint64 uint_type;
  167. typedef uint64 abs_type;
  168. typedef int64 sum_type;
  169. typedef int nu_type;
  170. static int_type reinterpret_int(value_type x) { return (int_type)x; }
  171. static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
  172. static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
  173. };
  174. template<> struct V_TypeTraits<float>
  175. {
  176. typedef float value_type;
  177. typedef int int_type;
  178. typedef unsigned uint_type;
  179. typedef float abs_type;
  180. typedef float sum_type;
  181. typedef double w_type;
  182. static int_type reinterpret_int(value_type x)
  183. {
  184. Cv32suf u;
  185. u.f = x;
  186. return u.i;
  187. }
  188. static uint_type reinterpet_uint(value_type x)
  189. {
  190. Cv32suf u;
  191. u.f = x;
  192. return u.u;
  193. }
  194. static value_type reinterpret_from_int(int_type x)
  195. {
  196. Cv32suf u;
  197. u.i = x;
  198. return u.f;
  199. }
  200. };
  201. template<> struct V_TypeTraits<double>
  202. {
  203. typedef double value_type;
  204. typedef int64 int_type;
  205. typedef uint64 uint_type;
  206. typedef double abs_type;
  207. typedef double sum_type;
  208. static int_type reinterpret_int(value_type x)
  209. {
  210. Cv64suf u;
  211. u.f = x;
  212. return u.i;
  213. }
  214. static uint_type reinterpet_uint(value_type x)
  215. {
  216. Cv64suf u;
  217. u.f = x;
  218. return u.u;
  219. }
  220. static value_type reinterpret_from_int(int_type x)
  221. {
  222. Cv64suf u;
  223. u.i = x;
  224. return u.f;
  225. }
  226. };
  227. }
  228. #if CV_SSE2
  229. #include "opencv2/hal/intrin_sse.hpp"
  230. #elif CV_NEON
  231. #include "opencv2/hal/intrin_neon.hpp"
  232. #else
  233. #include "opencv2/hal/intrin_cpp.hpp"
  234. #endif
  235. #ifndef CV_SIMD128
  236. #define CV_SIMD128 0
  237. #endif
  238. #ifndef CV_SIMD128_64F
  239. #define CV_SIMD128_64F 0
  240. #endif
  241. #endif