node-native-win-utils 1.1.1 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/README.md +144 -27
  2. package/binding.gyp +18 -5
  3. package/dist/index.d.ts +146 -4
  4. package/dist/index.js +107 -3
  5. package/include/opencv2/core/affine.hpp +678 -0
  6. package/include/opencv2/core/async.hpp +105 -0
  7. package/include/opencv2/core/base.hpp +664 -0
  8. package/include/opencv2/core/bindings_utils.hpp +325 -0
  9. package/include/opencv2/core/bufferpool.hpp +40 -0
  10. package/include/opencv2/core/check.hpp +170 -0
  11. package/include/opencv2/core/core.hpp +48 -0
  12. package/include/opencv2/core/core_c.h +3128 -0
  13. package/include/opencv2/core/cuda/block.hpp +211 -0
  14. package/include/opencv2/core/cuda/border_interpolate.hpp +722 -0
  15. package/include/opencv2/core/cuda/color.hpp +309 -0
  16. package/include/opencv2/core/cuda/common.hpp +131 -0
  17. package/include/opencv2/core/cuda/datamov_utils.hpp +113 -0
  18. package/include/opencv2/core/cuda/detail/color_detail.hpp +2018 -0
  19. package/include/opencv2/core/cuda/detail/reduce.hpp +365 -0
  20. package/include/opencv2/core/cuda/detail/reduce_key_val.hpp +502 -0
  21. package/include/opencv2/core/cuda/detail/transform_detail.hpp +392 -0
  22. package/include/opencv2/core/cuda/detail/type_traits_detail.hpp +191 -0
  23. package/include/opencv2/core/cuda/detail/vec_distance_detail.hpp +121 -0
  24. package/include/opencv2/core/cuda/dynamic_smem.hpp +88 -0
  25. package/include/opencv2/core/cuda/emulation.hpp +269 -0
  26. package/include/opencv2/core/cuda/filters.hpp +293 -0
  27. package/include/opencv2/core/cuda/funcattrib.hpp +79 -0
  28. package/include/opencv2/core/cuda/functional.hpp +805 -0
  29. package/include/opencv2/core/cuda/limits.hpp +128 -0
  30. package/include/opencv2/core/cuda/reduce.hpp +209 -0
  31. package/include/opencv2/core/cuda/saturate_cast.hpp +292 -0
  32. package/include/opencv2/core/cuda/scan.hpp +258 -0
  33. package/include/opencv2/core/cuda/simd_functions.hpp +869 -0
  34. package/include/opencv2/core/cuda/transform.hpp +75 -0
  35. package/include/opencv2/core/cuda/type_traits.hpp +90 -0
  36. package/include/opencv2/core/cuda/utility.hpp +230 -0
  37. package/include/opencv2/core/cuda/vec_distance.hpp +232 -0
  38. package/include/opencv2/core/cuda/vec_math.hpp +923 -0
  39. package/include/opencv2/core/cuda/vec_traits.hpp +288 -0
  40. package/include/opencv2/core/cuda/warp.hpp +139 -0
  41. package/include/opencv2/core/cuda/warp_reduce.hpp +76 -0
  42. package/include/opencv2/core/cuda/warp_shuffle.hpp +162 -0
  43. package/include/opencv2/core/cuda.hpp +1279 -0
  44. package/include/opencv2/core/cuda.inl.hpp +763 -0
  45. package/include/opencv2/core/cuda_stream_accessor.hpp +86 -0
  46. package/include/opencv2/core/cuda_types.hpp +144 -0
  47. package/include/opencv2/core/cv_cpu_dispatch.h +381 -0
  48. package/include/opencv2/core/cv_cpu_helper.h +550 -0
  49. package/include/opencv2/core/cvdef.h +973 -0
  50. package/include/opencv2/core/cvstd.hpp +190 -0
  51. package/include/opencv2/core/cvstd.inl.hpp +197 -0
  52. package/include/opencv2/core/cvstd_wrapper.hpp +154 -0
  53. package/include/opencv2/core/detail/async_promise.hpp +71 -0
  54. package/include/opencv2/core/detail/dispatch_helper.impl.hpp +49 -0
  55. package/include/opencv2/core/detail/exception_ptr.hpp +27 -0
  56. package/include/opencv2/core/directx.hpp +184 -0
  57. package/include/opencv2/core/dualquaternion.hpp +979 -0
  58. package/include/opencv2/core/dualquaternion.inl.hpp +487 -0
  59. package/include/opencv2/core/eigen.hpp +402 -0
  60. package/include/opencv2/core/fast_math.hpp +433 -0
  61. package/include/opencv2/core/hal/hal.hpp +256 -0
  62. package/include/opencv2/core/hal/interface.h +190 -0
  63. package/include/opencv2/core/hal/intrin.hpp +939 -0
  64. package/include/opencv2/core/hal/intrin_avx.hpp +3177 -0
  65. package/include/opencv2/core/hal/intrin_avx512.hpp +3090 -0
  66. package/include/opencv2/core/hal/intrin_cpp.hpp +3321 -0
  67. package/include/opencv2/core/hal/intrin_forward.hpp +191 -0
  68. package/include/opencv2/core/hal/intrin_lasx.hpp +3236 -0
  69. package/include/opencv2/core/hal/intrin_msa.hpp +1887 -0
  70. package/include/opencv2/core/hal/intrin_neon.hpp +2610 -0
  71. package/include/opencv2/core/hal/intrin_rvv.hpp +3320 -0
  72. package/include/opencv2/core/hal/intrin_rvv071.hpp +2545 -0
  73. package/include/opencv2/core/hal/intrin_rvv_scalable.hpp +2080 -0
  74. package/include/opencv2/core/hal/intrin_sse.hpp +3467 -0
  75. package/include/opencv2/core/hal/intrin_sse_em.hpp +180 -0
  76. package/include/opencv2/core/hal/intrin_vsx.hpp +1608 -0
  77. package/include/opencv2/core/hal/intrin_wasm.hpp +2782 -0
  78. package/include/opencv2/core/hal/msa_macros.h +1558 -0
  79. package/include/opencv2/core/hal/simd_utils.impl.hpp +186 -0
  80. package/include/opencv2/core/llapi/llapi.h +102 -0
  81. package/include/opencv2/core/mat.hpp +3775 -0
  82. package/include/opencv2/core/mat.inl.hpp +3422 -0
  83. package/include/opencv2/core/matx.hpp +1536 -0
  84. package/include/opencv2/core/neon_utils.hpp +128 -0
  85. package/include/opencv2/core/ocl.hpp +917 -0
  86. package/include/opencv2/core/ocl_genbase.hpp +69 -0
  87. package/include/opencv2/core/opencl/ocl_defs.hpp +82 -0
  88. package/include/opencv2/core/opencl/opencl_info.hpp +212 -0
  89. package/include/opencv2/core/opencl/opencl_svm.hpp +81 -0
  90. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_clblas.hpp +602 -0
  91. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_clfft.hpp +146 -0
  92. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_core.hpp +371 -0
  93. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_core_wrappers.hpp +272 -0
  94. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl.hpp +62 -0
  95. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl_wrappers.hpp +42 -0
  96. package/include/opencv2/core/opencl/runtime/opencl_clblas.hpp +53 -0
  97. package/include/opencv2/core/opencl/runtime/opencl_clfft.hpp +53 -0
  98. package/include/opencv2/core/opencl/runtime/opencl_core.hpp +84 -0
  99. package/include/opencv2/core/opencl/runtime/opencl_core_wrappers.hpp +47 -0
  100. package/include/opencv2/core/opencl/runtime/opencl_gl.hpp +53 -0
  101. package/include/opencv2/core/opencl/runtime/opencl_gl_wrappers.hpp +47 -0
  102. package/include/opencv2/core/opencl/runtime/opencl_svm_20.hpp +48 -0
  103. package/include/opencv2/core/opencl/runtime/opencl_svm_definitions.hpp +42 -0
  104. package/include/opencv2/core/opencl/runtime/opencl_svm_hsa_extension.hpp +166 -0
  105. package/include/opencv2/core/opengl.hpp +733 -0
  106. package/include/opencv2/core/openvx/ovx_defs.hpp +48 -0
  107. package/include/opencv2/core/operations.hpp +610 -0
  108. package/include/opencv2/core/optim.hpp +302 -0
  109. package/include/opencv2/core/ovx.hpp +28 -0
  110. package/include/opencv2/core/parallel/backend/parallel_for.openmp.hpp +72 -0
  111. package/include/opencv2/core/parallel/backend/parallel_for.tbb.hpp +153 -0
  112. package/include/opencv2/core/parallel/parallel_backend.hpp +90 -0
  113. package/include/opencv2/core/persistence.hpp +1350 -0
  114. package/include/opencv2/core/private/cv_cpu_include_simd_declarations.hpp +30 -0
  115. package/include/opencv2/core/private.cuda.hpp +169 -0
  116. package/include/opencv2/core/private.hpp +896 -0
  117. package/include/opencv2/core/quaternion.hpp +1696 -0
  118. package/include/opencv2/core/quaternion.inl.hpp +1063 -0
  119. package/include/opencv2/core/saturate.hpp +180 -0
  120. package/include/opencv2/core/simd_intrinsics.hpp +87 -0
  121. package/include/opencv2/core/softfloat.hpp +514 -0
  122. package/include/opencv2/core/sse_utils.hpp +652 -0
  123. package/include/opencv2/core/traits.hpp +417 -0
  124. package/include/opencv2/core/types.hpp +2457 -0
  125. package/include/opencv2/core/types_c.h +2126 -0
  126. package/include/opencv2/core/utility.hpp +1229 -0
  127. package/include/opencv2/core/utils/allocator_stats.hpp +29 -0
  128. package/include/opencv2/core/utils/allocator_stats.impl.hpp +158 -0
  129. package/include/opencv2/core/utils/buffer_area.private.hpp +136 -0
  130. package/include/opencv2/core/utils/configuration.private.hpp +22 -0
  131. package/include/opencv2/core/utils/filesystem.hpp +82 -0
  132. package/include/opencv2/core/utils/filesystem.private.hpp +66 -0
  133. package/include/opencv2/core/utils/fp_control.private.hpp +29 -0
  134. package/include/opencv2/core/utils/fp_control_utils.hpp +69 -0
  135. package/include/opencv2/core/utils/instrumentation.hpp +125 -0
  136. package/include/opencv2/core/utils/lock.private.hpp +119 -0
  137. package/include/opencv2/core/utils/logger.defines.hpp +42 -0
  138. package/include/opencv2/core/utils/logger.hpp +218 -0
  139. package/include/opencv2/core/utils/logtag.hpp +28 -0
  140. package/include/opencv2/core/utils/plugin_loader.private.hpp +165 -0
  141. package/include/opencv2/core/utils/tls.hpp +235 -0
  142. package/include/opencv2/core/utils/trace.hpp +252 -0
  143. package/include/opencv2/core/utils/trace.private.hpp +421 -0
  144. package/include/opencv2/core/va_intel.hpp +75 -0
  145. package/include/opencv2/core/version.hpp +26 -0
  146. package/include/opencv2/core/vsx_utils.hpp +1047 -0
  147. package/include/opencv2/core.hpp +3365 -0
  148. package/include/opencv2/imgcodecs/imgcodecs.hpp +48 -0
  149. package/include/opencv2/imgcodecs/imgcodecs_c.h +1 -0
  150. package/include/opencv2/imgcodecs/ios.h +59 -0
  151. package/include/opencv2/imgcodecs/legacy/constants_c.h +54 -0
  152. package/include/opencv2/imgcodecs/macosx.h +20 -0
  153. package/include/opencv2/imgcodecs.hpp +407 -0
  154. package/include/opencv2/imgproc/bindings.hpp +34 -0
  155. package/include/opencv2/imgproc/detail/gcgraph.hpp +395 -0
  156. package/include/opencv2/imgproc/hal/hal.hpp +246 -0
  157. package/include/opencv2/imgproc/hal/interface.h +46 -0
  158. package/include/opencv2/imgproc/imgproc.hpp +48 -0
  159. package/include/opencv2/imgproc/imgproc_c.h +1177 -0
  160. package/include/opencv2/imgproc/segmentation.hpp +141 -0
  161. package/include/opencv2/imgproc/types_c.h +659 -0
  162. package/include/opencv2/imgproc.hpp +5035 -0
  163. package/include/opencv2/opencv_modules.hpp +17 -0
  164. package/libs/libjpeg-turbo.lib +0 -0
  165. package/libs/libpng.lib +0 -0
  166. package/libs/opencv_core470.lib +0 -0
  167. package/libs/opencv_imgcodecs470.lib +0 -0
  168. package/libs/opencv_imgproc470.lib +0 -0
  169. package/libs/zlib.lib +0 -0
  170. package/package.json +8 -2
  171. package/prebuilds/win32-x64/node.napi.node +0 -0
  172. package/src/cpp/capturewindow.cpp +37 -47
  173. package/src/cpp/main.cpp +10 -2
  174. package/src/cpp/opencv.cpp +425 -0
@@ -0,0 +1,2610 @@
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_HAL_INTRIN_NEON_HPP
46
+ #define OPENCV_HAL_INTRIN_NEON_HPP
47
+
48
+ #include <algorithm>
49
+ #include "opencv2/core/utility.hpp"
50
+
51
+ namespace cv
52
+ {
53
+
54
+ //! @cond IGNORED
55
+
56
+ CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN
57
+
58
+ #define CV_SIMD128 1
59
+ #if defined(__aarch64__) || defined(_M_ARM64)
60
+ #define CV_SIMD128_64F 1
61
+ #else
62
+ #define CV_SIMD128_64F 0
63
+ #endif
64
+
65
+ // The following macro checks if the code is being compiled for the
66
+ // AArch64 execution state of Armv8, to enable the 128-bit
67
+ // intrinsics. The macro `__ARM_64BIT_STATE` is the one recommended by
68
+ // the Arm C Language Extension (ACLE) specifications [1] to check the
69
+ // availability of 128-bit intrinsics, and it is supporrted by clang
70
+ // and gcc. The macro `_M_ARM64` is the equivalent one for Microsoft
71
+ // Visual Studio [2] .
72
+ //
73
+ // [1] https://developer.arm.com/documentation/101028/0012/13--Advanced-SIMD--Neon--intrinsics
74
+ // [2] https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros
75
+ #if defined(__ARM_64BIT_STATE) || defined(_M_ARM64)
76
+ #define CV_NEON_AARCH64 1
77
+ #else
78
+ #define CV_NEON_AARCH64 0
79
+ #endif
80
+
81
+
82
+ //////////// Utils ////////////
83
+
84
+ #if CV_SIMD128_64F
85
+ #define OPENCV_HAL_IMPL_NEON_UNZIP(_Tpv, _Tpvx2, suffix) \
86
+ inline void _v128_unzip(const _Tpv& a, const _Tpv& b, _Tpv& c, _Tpv& d) \
87
+ { c = vuzp1q_##suffix(a, b); d = vuzp2q_##suffix(a, b); }
88
+ #define OPENCV_HAL_IMPL_NEON_UNZIP_L(_Tpv, _Tpvx2, suffix) \
89
+ inline void _v128_unzip(const _Tpv&a, const _Tpv&b, _Tpv& c, _Tpv& d) \
90
+ { c = vuzp1_##suffix(a, b); d = vuzp2_##suffix(a, b); }
91
+ #else
92
+ #define OPENCV_HAL_IMPL_NEON_UNZIP(_Tpv, _Tpvx2, suffix) \
93
+ inline void _v128_unzip(const _Tpv& a, const _Tpv& b, _Tpv& c, _Tpv& d) \
94
+ { _Tpvx2 ab = vuzpq_##suffix(a, b); c = ab.val[0]; d = ab.val[1]; }
95
+ #define OPENCV_HAL_IMPL_NEON_UNZIP_L(_Tpv, _Tpvx2, suffix) \
96
+ inline void _v128_unzip(const _Tpv& a, const _Tpv& b, _Tpv& c, _Tpv& d) \
97
+ { _Tpvx2 ab = vuzp_##suffix(a, b); c = ab.val[0]; d = ab.val[1]; }
98
+ #endif
99
+
100
+ #if CV_SIMD128_64F
101
+ #define OPENCV_HAL_IMPL_NEON_REINTERPRET(_Tpv, suffix) \
102
+ template <typename T> static inline \
103
+ _Tpv vreinterpretq_##suffix##_f64(T a) { return (_Tpv) a; } \
104
+ template <typename T> static inline \
105
+ float64x2_t vreinterpretq_f64_##suffix(T a) { return (float64x2_t) a; }
106
+ #else
107
+ #define OPENCV_HAL_IMPL_NEON_REINTERPRET(_Tpv, suffix)
108
+ #endif
109
+
110
+ #define OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX(_Tpv, _Tpvl, suffix) \
111
+ OPENCV_HAL_IMPL_NEON_UNZIP(_Tpv##_t, _Tpv##x2_t, suffix) \
112
+ OPENCV_HAL_IMPL_NEON_UNZIP_L(_Tpvl##_t, _Tpvl##x2_t, suffix) \
113
+ OPENCV_HAL_IMPL_NEON_REINTERPRET(_Tpv##_t, suffix)
114
+
115
+ #define OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX_I64(_Tpv, _Tpvl, suffix) \
116
+ OPENCV_HAL_IMPL_NEON_REINTERPRET(_Tpv##_t, suffix)
117
+
118
+ #define OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX_F64(_Tpv, _Tpvl, suffix) \
119
+ OPENCV_HAL_IMPL_NEON_UNZIP(_Tpv##_t, _Tpv##x2_t, suffix)
120
+
121
+ OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX(uint8x16, uint8x8, u8)
122
+ OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX(int8x16, int8x8, s8)
123
+ OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX(uint16x8, uint16x4, u16)
124
+ OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX(int16x8, int16x4, s16)
125
+ OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX(uint32x4, uint32x2, u32)
126
+ OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX(int32x4, int32x2, s32)
127
+ OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX(float32x4, float32x2, f32)
128
+ OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX_I64(uint64x2, uint64x1, u64)
129
+ OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX_I64(int64x2, int64x1, s64)
130
+ #if CV_SIMD128_64F
131
+ OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX_F64(float64x2, float64x1,f64)
132
+ #endif
133
+
134
+ //////////// Types ////////////
135
+
136
+ struct v_uint8x16
137
+ {
138
+ typedef uchar lane_type;
139
+ enum { nlanes = 16 };
140
+
141
+ v_uint8x16() {}
142
+ explicit v_uint8x16(uint8x16_t v) : val(v) {}
143
+ v_uint8x16(uchar v0, uchar v1, uchar v2, uchar v3, uchar v4, uchar v5, uchar v6, uchar v7,
144
+ uchar v8, uchar v9, uchar v10, uchar v11, uchar v12, uchar v13, uchar v14, uchar v15)
145
+ {
146
+ uchar v[] = {v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15};
147
+ val = vld1q_u8(v);
148
+ }
149
+ uchar get0() const
150
+ {
151
+ return vgetq_lane_u8(val, 0);
152
+ }
153
+
154
+ uint8x16_t val;
155
+ };
156
+
157
+ struct v_int8x16
158
+ {
159
+ typedef schar lane_type;
160
+ enum { nlanes = 16 };
161
+
162
+ v_int8x16() {}
163
+ explicit v_int8x16(int8x16_t v) : val(v) {}
164
+ v_int8x16(schar v0, schar v1, schar v2, schar v3, schar v4, schar v5, schar v6, schar v7,
165
+ schar v8, schar v9, schar v10, schar v11, schar v12, schar v13, schar v14, schar v15)
166
+ {
167
+ schar v[] = {v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15};
168
+ val = vld1q_s8(v);
169
+ }
170
+ schar get0() const
171
+ {
172
+ return vgetq_lane_s8(val, 0);
173
+ }
174
+
175
+ int8x16_t val;
176
+ };
177
+
178
+ struct v_uint16x8
179
+ {
180
+ typedef ushort lane_type;
181
+ enum { nlanes = 8 };
182
+
183
+ v_uint16x8() {}
184
+ explicit v_uint16x8(uint16x8_t v) : val(v) {}
185
+ v_uint16x8(ushort v0, ushort v1, ushort v2, ushort v3, ushort v4, ushort v5, ushort v6, ushort v7)
186
+ {
187
+ ushort v[] = {v0, v1, v2, v3, v4, v5, v6, v7};
188
+ val = vld1q_u16(v);
189
+ }
190
+ ushort get0() const
191
+ {
192
+ return vgetq_lane_u16(val, 0);
193
+ }
194
+
195
+ uint16x8_t val;
196
+ };
197
+
198
+ struct v_int16x8
199
+ {
200
+ typedef short lane_type;
201
+ enum { nlanes = 8 };
202
+
203
+ v_int16x8() {}
204
+ explicit v_int16x8(int16x8_t v) : val(v) {}
205
+ v_int16x8(short v0, short v1, short v2, short v3, short v4, short v5, short v6, short v7)
206
+ {
207
+ short v[] = {v0, v1, v2, v3, v4, v5, v6, v7};
208
+ val = vld1q_s16(v);
209
+ }
210
+ short get0() const
211
+ {
212
+ return vgetq_lane_s16(val, 0);
213
+ }
214
+
215
+ int16x8_t val;
216
+ };
217
+
218
+ struct v_uint32x4
219
+ {
220
+ typedef unsigned lane_type;
221
+ enum { nlanes = 4 };
222
+
223
+ v_uint32x4() {}
224
+ explicit v_uint32x4(uint32x4_t v) : val(v) {}
225
+ v_uint32x4(unsigned v0, unsigned v1, unsigned v2, unsigned v3)
226
+ {
227
+ unsigned v[] = {v0, v1, v2, v3};
228
+ val = vld1q_u32(v);
229
+ }
230
+ unsigned get0() const
231
+ {
232
+ return vgetq_lane_u32(val, 0);
233
+ }
234
+
235
+ uint32x4_t val;
236
+ };
237
+
238
+ struct v_int32x4
239
+ {
240
+ typedef int lane_type;
241
+ enum { nlanes = 4 };
242
+
243
+ v_int32x4() {}
244
+ explicit v_int32x4(int32x4_t v) : val(v) {}
245
+ v_int32x4(int v0, int v1, int v2, int v3)
246
+ {
247
+ int v[] = {v0, v1, v2, v3};
248
+ val = vld1q_s32(v);
249
+ }
250
+ int get0() const
251
+ {
252
+ return vgetq_lane_s32(val, 0);
253
+ }
254
+ int32x4_t val;
255
+ };
256
+
257
+ struct v_float32x4
258
+ {
259
+ typedef float lane_type;
260
+ enum { nlanes = 4 };
261
+
262
+ v_float32x4() {}
263
+ explicit v_float32x4(float32x4_t v) : val(v) {}
264
+ v_float32x4(float v0, float v1, float v2, float v3)
265
+ {
266
+ float v[] = {v0, v1, v2, v3};
267
+ val = vld1q_f32(v);
268
+ }
269
+ float get0() const
270
+ {
271
+ return vgetq_lane_f32(val, 0);
272
+ }
273
+ float32x4_t val;
274
+ };
275
+
276
+ struct v_uint64x2
277
+ {
278
+ typedef uint64 lane_type;
279
+ enum { nlanes = 2 };
280
+
281
+ v_uint64x2() {}
282
+ explicit v_uint64x2(uint64x2_t v) : val(v) {}
283
+ v_uint64x2(uint64 v0, uint64 v1)
284
+ {
285
+ uint64 v[] = {v0, v1};
286
+ val = vld1q_u64(v);
287
+ }
288
+ uint64 get0() const
289
+ {
290
+ return vgetq_lane_u64(val, 0);
291
+ }
292
+ uint64x2_t val;
293
+ };
294
+
295
+ struct v_int64x2
296
+ {
297
+ typedef int64 lane_type;
298
+ enum { nlanes = 2 };
299
+
300
+ v_int64x2() {}
301
+ explicit v_int64x2(int64x2_t v) : val(v) {}
302
+ v_int64x2(int64 v0, int64 v1)
303
+ {
304
+ int64 v[] = {v0, v1};
305
+ val = vld1q_s64(v);
306
+ }
307
+ int64 get0() const
308
+ {
309
+ return vgetq_lane_s64(val, 0);
310
+ }
311
+ int64x2_t val;
312
+ };
313
+
314
+ #if CV_SIMD128_64F
315
+ struct v_float64x2
316
+ {
317
+ typedef double lane_type;
318
+ enum { nlanes = 2 };
319
+
320
+ v_float64x2() {}
321
+ explicit v_float64x2(float64x2_t v) : val(v) {}
322
+ v_float64x2(double v0, double v1)
323
+ {
324
+ double v[] = {v0, v1};
325
+ val = vld1q_f64(v);
326
+ }
327
+ double get0() const
328
+ {
329
+ return vgetq_lane_f64(val, 0);
330
+ }
331
+ float64x2_t val;
332
+ };
333
+ #endif
334
+
335
+ #define OPENCV_HAL_IMPL_NEON_INIT(_Tpv, _Tp, suffix) \
336
+ inline v_##_Tpv v_setzero_##suffix() { return v_##_Tpv(vdupq_n_##suffix((_Tp)0)); } \
337
+ inline v_##_Tpv v_setall_##suffix(_Tp v) { return v_##_Tpv(vdupq_n_##suffix(v)); } \
338
+ inline _Tpv##_t vreinterpretq_##suffix##_##suffix(_Tpv##_t v) { return v; } \
339
+ inline v_uint8x16 v_reinterpret_as_u8(const v_##_Tpv& v) { return v_uint8x16(vreinterpretq_u8_##suffix(v.val)); } \
340
+ inline v_int8x16 v_reinterpret_as_s8(const v_##_Tpv& v) { return v_int8x16(vreinterpretq_s8_##suffix(v.val)); } \
341
+ inline v_uint16x8 v_reinterpret_as_u16(const v_##_Tpv& v) { return v_uint16x8(vreinterpretq_u16_##suffix(v.val)); } \
342
+ inline v_int16x8 v_reinterpret_as_s16(const v_##_Tpv& v) { return v_int16x8(vreinterpretq_s16_##suffix(v.val)); } \
343
+ inline v_uint32x4 v_reinterpret_as_u32(const v_##_Tpv& v) { return v_uint32x4(vreinterpretq_u32_##suffix(v.val)); } \
344
+ inline v_int32x4 v_reinterpret_as_s32(const v_##_Tpv& v) { return v_int32x4(vreinterpretq_s32_##suffix(v.val)); } \
345
+ inline v_uint64x2 v_reinterpret_as_u64(const v_##_Tpv& v) { return v_uint64x2(vreinterpretq_u64_##suffix(v.val)); } \
346
+ inline v_int64x2 v_reinterpret_as_s64(const v_##_Tpv& v) { return v_int64x2(vreinterpretq_s64_##suffix(v.val)); } \
347
+ inline v_float32x4 v_reinterpret_as_f32(const v_##_Tpv& v) { return v_float32x4(vreinterpretq_f32_##suffix(v.val)); }
348
+
349
+ OPENCV_HAL_IMPL_NEON_INIT(uint8x16, uchar, u8)
350
+ OPENCV_HAL_IMPL_NEON_INIT(int8x16, schar, s8)
351
+ OPENCV_HAL_IMPL_NEON_INIT(uint16x8, ushort, u16)
352
+ OPENCV_HAL_IMPL_NEON_INIT(int16x8, short, s16)
353
+ OPENCV_HAL_IMPL_NEON_INIT(uint32x4, unsigned, u32)
354
+ OPENCV_HAL_IMPL_NEON_INIT(int32x4, int, s32)
355
+ OPENCV_HAL_IMPL_NEON_INIT(uint64x2, uint64, u64)
356
+ OPENCV_HAL_IMPL_NEON_INIT(int64x2, int64, s64)
357
+ OPENCV_HAL_IMPL_NEON_INIT(float32x4, float, f32)
358
+ #if CV_SIMD128_64F
359
+ #define OPENCV_HAL_IMPL_NEON_INIT_64(_Tpv, suffix) \
360
+ inline v_float64x2 v_reinterpret_as_f64(const v_##_Tpv& v) { return v_float64x2(vreinterpretq_f64_##suffix(v.val)); }
361
+ OPENCV_HAL_IMPL_NEON_INIT(float64x2, double, f64)
362
+ OPENCV_HAL_IMPL_NEON_INIT_64(uint8x16, u8)
363
+ OPENCV_HAL_IMPL_NEON_INIT_64(int8x16, s8)
364
+ OPENCV_HAL_IMPL_NEON_INIT_64(uint16x8, u16)
365
+ OPENCV_HAL_IMPL_NEON_INIT_64(int16x8, s16)
366
+ OPENCV_HAL_IMPL_NEON_INIT_64(uint32x4, u32)
367
+ OPENCV_HAL_IMPL_NEON_INIT_64(int32x4, s32)
368
+ OPENCV_HAL_IMPL_NEON_INIT_64(uint64x2, u64)
369
+ OPENCV_HAL_IMPL_NEON_INIT_64(int64x2, s64)
370
+ OPENCV_HAL_IMPL_NEON_INIT_64(float32x4, f32)
371
+ OPENCV_HAL_IMPL_NEON_INIT_64(float64x2, f64)
372
+ #endif
373
+
374
+ #define OPENCV_HAL_IMPL_NEON_PACK(_Tpvec, _Tp, hreg, suffix, _Tpwvec, pack, mov, rshr) \
375
+ inline _Tpvec v_##pack(const _Tpwvec& a, const _Tpwvec& b) \
376
+ { \
377
+ hreg a1 = mov(a.val), b1 = mov(b.val); \
378
+ return _Tpvec(vcombine_##suffix(a1, b1)); \
379
+ } \
380
+ inline void v_##pack##_store(_Tp* ptr, const _Tpwvec& a) \
381
+ { \
382
+ hreg a1 = mov(a.val); \
383
+ vst1_##suffix(ptr, a1); \
384
+ } \
385
+ template<int n> inline \
386
+ _Tpvec v_rshr_##pack(const _Tpwvec& a, const _Tpwvec& b) \
387
+ { \
388
+ hreg a1 = rshr(a.val, n); \
389
+ hreg b1 = rshr(b.val, n); \
390
+ return _Tpvec(vcombine_##suffix(a1, b1)); \
391
+ } \
392
+ template<int n> inline \
393
+ void v_rshr_##pack##_store(_Tp* ptr, const _Tpwvec& a) \
394
+ { \
395
+ hreg a1 = rshr(a.val, n); \
396
+ vst1_##suffix(ptr, a1); \
397
+ }
398
+
399
+ OPENCV_HAL_IMPL_NEON_PACK(v_uint8x16, uchar, uint8x8_t, u8, v_uint16x8, pack, vqmovn_u16, vqrshrn_n_u16)
400
+ OPENCV_HAL_IMPL_NEON_PACK(v_int8x16, schar, int8x8_t, s8, v_int16x8, pack, vqmovn_s16, vqrshrn_n_s16)
401
+ OPENCV_HAL_IMPL_NEON_PACK(v_uint16x8, ushort, uint16x4_t, u16, v_uint32x4, pack, vqmovn_u32, vqrshrn_n_u32)
402
+ OPENCV_HAL_IMPL_NEON_PACK(v_int16x8, short, int16x4_t, s16, v_int32x4, pack, vqmovn_s32, vqrshrn_n_s32)
403
+ OPENCV_HAL_IMPL_NEON_PACK(v_uint32x4, unsigned, uint32x2_t, u32, v_uint64x2, pack, vmovn_u64, vrshrn_n_u64)
404
+ OPENCV_HAL_IMPL_NEON_PACK(v_int32x4, int, int32x2_t, s32, v_int64x2, pack, vmovn_s64, vrshrn_n_s64)
405
+
406
+ OPENCV_HAL_IMPL_NEON_PACK(v_uint8x16, uchar, uint8x8_t, u8, v_int16x8, pack_u, vqmovun_s16, vqrshrun_n_s16)
407
+ OPENCV_HAL_IMPL_NEON_PACK(v_uint16x8, ushort, uint16x4_t, u16, v_int32x4, pack_u, vqmovun_s32, vqrshrun_n_s32)
408
+
409
+ // pack boolean
410
+ inline v_uint8x16 v_pack_b(const v_uint16x8& a, const v_uint16x8& b)
411
+ {
412
+ uint8x16_t ab = vcombine_u8(vmovn_u16(a.val), vmovn_u16(b.val));
413
+ return v_uint8x16(ab);
414
+ }
415
+
416
+ inline v_uint8x16 v_pack_b(const v_uint32x4& a, const v_uint32x4& b,
417
+ const v_uint32x4& c, const v_uint32x4& d)
418
+ {
419
+ uint16x8_t nab = vcombine_u16(vmovn_u32(a.val), vmovn_u32(b.val));
420
+ uint16x8_t ncd = vcombine_u16(vmovn_u32(c.val), vmovn_u32(d.val));
421
+ return v_uint8x16(vcombine_u8(vmovn_u16(nab), vmovn_u16(ncd)));
422
+ }
423
+
424
+ inline v_uint8x16 v_pack_b(const v_uint64x2& a, const v_uint64x2& b, const v_uint64x2& c,
425
+ const v_uint64x2& d, const v_uint64x2& e, const v_uint64x2& f,
426
+ const v_uint64x2& g, const v_uint64x2& h)
427
+ {
428
+ uint32x4_t ab = vcombine_u32(vmovn_u64(a.val), vmovn_u64(b.val));
429
+ uint32x4_t cd = vcombine_u32(vmovn_u64(c.val), vmovn_u64(d.val));
430
+ uint32x4_t ef = vcombine_u32(vmovn_u64(e.val), vmovn_u64(f.val));
431
+ uint32x4_t gh = vcombine_u32(vmovn_u64(g.val), vmovn_u64(h.val));
432
+
433
+ uint16x8_t abcd = vcombine_u16(vmovn_u32(ab), vmovn_u32(cd));
434
+ uint16x8_t efgh = vcombine_u16(vmovn_u32(ef), vmovn_u32(gh));
435
+ return v_uint8x16(vcombine_u8(vmovn_u16(abcd), vmovn_u16(efgh)));
436
+ }
437
+
438
+ inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0,
439
+ const v_float32x4& m1, const v_float32x4& m2,
440
+ const v_float32x4& m3)
441
+ {
442
+ float32x2_t vl = vget_low_f32(v.val), vh = vget_high_f32(v.val);
443
+ float32x4_t res = vmulq_lane_f32(m0.val, vl, 0);
444
+ res = vmlaq_lane_f32(res, m1.val, vl, 1);
445
+ res = vmlaq_lane_f32(res, m2.val, vh, 0);
446
+ res = vmlaq_lane_f32(res, m3.val, vh, 1);
447
+ return v_float32x4(res);
448
+ }
449
+
450
+ inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0,
451
+ const v_float32x4& m1, const v_float32x4& m2,
452
+ const v_float32x4& a)
453
+ {
454
+ float32x2_t vl = vget_low_f32(v.val), vh = vget_high_f32(v.val);
455
+ float32x4_t res = vmulq_lane_f32(m0.val, vl, 0);
456
+ res = vmlaq_lane_f32(res, m1.val, vl, 1);
457
+ res = vmlaq_lane_f32(res, m2.val, vh, 0);
458
+ res = vaddq_f32(res, a.val);
459
+ return v_float32x4(res);
460
+ }
461
+
462
+ #define OPENCV_HAL_IMPL_NEON_BIN_OP(bin_op, _Tpvec, intrin) \
463
+ inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \
464
+ { \
465
+ return _Tpvec(intrin(a.val, b.val)); \
466
+ } \
467
+ inline _Tpvec& operator bin_op##= (_Tpvec& a, const _Tpvec& b) \
468
+ { \
469
+ a.val = intrin(a.val, b.val); \
470
+ return a; \
471
+ }
472
+
473
+ OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_uint8x16, vqaddq_u8)
474
+ OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_uint8x16, vqsubq_u8)
475
+ OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_int8x16, vqaddq_s8)
476
+ OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_int8x16, vqsubq_s8)
477
+ OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_uint16x8, vqaddq_u16)
478
+ OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_uint16x8, vqsubq_u16)
479
+ OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_int16x8, vqaddq_s16)
480
+ OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_int16x8, vqsubq_s16)
481
+ OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_int32x4, vaddq_s32)
482
+ OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_int32x4, vsubq_s32)
483
+ OPENCV_HAL_IMPL_NEON_BIN_OP(*, v_int32x4, vmulq_s32)
484
+ OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_uint32x4, vaddq_u32)
485
+ OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_uint32x4, vsubq_u32)
486
+ OPENCV_HAL_IMPL_NEON_BIN_OP(*, v_uint32x4, vmulq_u32)
487
+ OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_float32x4, vaddq_f32)
488
+ OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_float32x4, vsubq_f32)
489
+ OPENCV_HAL_IMPL_NEON_BIN_OP(*, v_float32x4, vmulq_f32)
490
+ OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_int64x2, vaddq_s64)
491
+ OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_int64x2, vsubq_s64)
492
+ OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_uint64x2, vaddq_u64)
493
+ OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_uint64x2, vsubq_u64)
494
+ #if CV_SIMD128_64F
495
+ OPENCV_HAL_IMPL_NEON_BIN_OP(/, v_float32x4, vdivq_f32)
496
+ OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_float64x2, vaddq_f64)
497
+ OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_float64x2, vsubq_f64)
498
+ OPENCV_HAL_IMPL_NEON_BIN_OP(*, v_float64x2, vmulq_f64)
499
+ OPENCV_HAL_IMPL_NEON_BIN_OP(/, v_float64x2, vdivq_f64)
500
+ #else
501
+ inline v_float32x4 operator / (const v_float32x4& a, const v_float32x4& b)
502
+ {
503
+ float32x4_t reciprocal = vrecpeq_f32(b.val);
504
+ reciprocal = vmulq_f32(vrecpsq_f32(b.val, reciprocal), reciprocal);
505
+ reciprocal = vmulq_f32(vrecpsq_f32(b.val, reciprocal), reciprocal);
506
+ return v_float32x4(vmulq_f32(a.val, reciprocal));
507
+ }
508
+ inline v_float32x4& operator /= (v_float32x4& a, const v_float32x4& b)
509
+ {
510
+ float32x4_t reciprocal = vrecpeq_f32(b.val);
511
+ reciprocal = vmulq_f32(vrecpsq_f32(b.val, reciprocal), reciprocal);
512
+ reciprocal = vmulq_f32(vrecpsq_f32(b.val, reciprocal), reciprocal);
513
+ a.val = vmulq_f32(a.val, reciprocal);
514
+ return a;
515
+ }
516
+ #endif
517
+
518
+ // saturating multiply 8-bit, 16-bit
519
+ #define OPENCV_HAL_IMPL_NEON_MUL_SAT(_Tpvec, _Tpwvec) \
520
+ inline _Tpvec operator * (const _Tpvec& a, const _Tpvec& b) \
521
+ { \
522
+ _Tpwvec c, d; \
523
+ v_mul_expand(a, b, c, d); \
524
+ return v_pack(c, d); \
525
+ } \
526
+ inline _Tpvec& operator *= (_Tpvec& a, const _Tpvec& b) \
527
+ { a = a * b; return a; }
528
+
529
+ OPENCV_HAL_IMPL_NEON_MUL_SAT(v_int8x16, v_int16x8)
530
+ OPENCV_HAL_IMPL_NEON_MUL_SAT(v_uint8x16, v_uint16x8)
531
+ OPENCV_HAL_IMPL_NEON_MUL_SAT(v_int16x8, v_int32x4)
532
+ OPENCV_HAL_IMPL_NEON_MUL_SAT(v_uint16x8, v_uint32x4)
533
+
534
+ // Multiply and expand
535
+ inline void v_mul_expand(const v_int8x16& a, const v_int8x16& b,
536
+ v_int16x8& c, v_int16x8& d)
537
+ {
538
+ c.val = vmull_s8(vget_low_s8(a.val), vget_low_s8(b.val));
539
+ #if CV_NEON_AARCH64
540
+ d.val = vmull_high_s8(a.val, b.val);
541
+ #else // #if CV_NEON_AARCH64
542
+ d.val = vmull_s8(vget_high_s8(a.val), vget_high_s8(b.val));
543
+ #endif // #if CV_NEON_AARCH64
544
+ }
545
+
546
+ inline void v_mul_expand(const v_uint8x16& a, const v_uint8x16& b,
547
+ v_uint16x8& c, v_uint16x8& d)
548
+ {
549
+ c.val = vmull_u8(vget_low_u8(a.val), vget_low_u8(b.val));
550
+ #if CV_NEON_AARCH64
551
+ d.val = vmull_high_u8(a.val, b.val);
552
+ #else // #if CV_NEON_AARCH64
553
+ d.val = vmull_u8(vget_high_u8(a.val), vget_high_u8(b.val));
554
+ #endif // #if CV_NEON_AARCH64
555
+ }
556
+
557
+ inline void v_mul_expand(const v_int16x8& a, const v_int16x8& b,
558
+ v_int32x4& c, v_int32x4& d)
559
+ {
560
+ c.val = vmull_s16(vget_low_s16(a.val), vget_low_s16(b.val));
561
+ #if CV_NEON_AARCH64
562
+ d.val = vmull_high_s16(a.val, b.val);
563
+ #else // #if CV_NEON_AARCH64
564
+ d.val = vmull_s16(vget_high_s16(a.val), vget_high_s16(b.val));
565
+ #endif // #if CV_NEON_AARCH64
566
+ }
567
+
568
+ inline void v_mul_expand(const v_uint16x8& a, const v_uint16x8& b,
569
+ v_uint32x4& c, v_uint32x4& d)
570
+ {
571
+ c.val = vmull_u16(vget_low_u16(a.val), vget_low_u16(b.val));
572
+ #if CV_NEON_AARCH64
573
+ d.val = vmull_high_u16(a.val, b.val);
574
+ #else // #if CV_NEON_AARCH64
575
+ d.val = vmull_u16(vget_high_u16(a.val), vget_high_u16(b.val));
576
+ #endif // #if CV_NEON_AARCH64
577
+ }
578
+
579
+ inline void v_mul_expand(const v_uint32x4& a, const v_uint32x4& b,
580
+ v_uint64x2& c, v_uint64x2& d)
581
+ {
582
+ c.val = vmull_u32(vget_low_u32(a.val), vget_low_u32(b.val));
583
+ #if CV_NEON_AARCH64
584
+ d.val = vmull_high_u32(a.val, b.val);
585
+ #else // #if CV_NEON_AARCH64
586
+ d.val = vmull_u32(vget_high_u32(a.val), vget_high_u32(b.val));
587
+ #endif // #if CV_NEON_AARCH64
588
+ }
589
+
590
+ inline v_int16x8 v_mul_hi(const v_int16x8& a, const v_int16x8& b)
591
+ {
592
+ #if CV_NEON_AARCH64
593
+ int32x4_t c = vmull_high_s16(a.val, b.val);
594
+ #else // #if CV_NEON_AARCH64
595
+ int32x4_t c = vmull_s16(vget_high_s16(a.val), vget_high_s16(b.val));
596
+ #endif // #if CV_NEON_AARCH64
597
+ return v_int16x8(vcombine_s16(
598
+ vshrn_n_s32(vmull_s16( vget_low_s16(a.val), vget_low_s16(b.val)), 16),
599
+ vshrn_n_s32(c, 16)
600
+ ));
601
+ }
602
+ inline v_uint16x8 v_mul_hi(const v_uint16x8& a, const v_uint16x8& b)
603
+ {
604
+ #if CV_NEON_AARCH64
605
+ uint32x4_t c = vmull_high_u16(a.val, b.val);
606
+ #else // #if CV_NEON_AARCH64
607
+ uint32x4_t c = vmull_u16(vget_high_u16(a.val), vget_high_u16(b.val));
608
+ #endif // #if CV_NEON_AARCH64
609
+ return v_uint16x8(vcombine_u16(
610
+ vshrn_n_u32(vmull_u16( vget_low_u16(a.val), vget_low_u16(b.val)), 16),
611
+ vshrn_n_u32(c, 16)
612
+ ));
613
+ }
614
+
615
+ //////// Dot Product ////////
616
+
617
+ // 16 >> 32
618
+ inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b)
619
+ {
620
+ int16x8_t uzp1, uzp2;
621
+ _v128_unzip(a.val, b.val, uzp1, uzp2);
622
+ int16x4_t a0 = vget_low_s16(uzp1);
623
+ int16x4_t b0 = vget_high_s16(uzp1);
624
+ int16x4_t a1 = vget_low_s16(uzp2);
625
+ int16x4_t b1 = vget_high_s16(uzp2);
626
+ int32x4_t p = vmull_s16(a0, b0);
627
+ return v_int32x4(vmlal_s16(p, a1, b1));
628
+ }
629
+ inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c)
630
+ {
631
+ int16x8_t uzp1, uzp2;
632
+ _v128_unzip(a.val, b.val, uzp1, uzp2);
633
+ int16x4_t a0 = vget_low_s16(uzp1);
634
+ int16x4_t b0 = vget_high_s16(uzp1);
635
+ int16x4_t a1 = vget_low_s16(uzp2);
636
+ int16x4_t b1 = vget_high_s16(uzp2);
637
+ int32x4_t p = vmlal_s16(c.val, a0, b0);
638
+ return v_int32x4(vmlal_s16(p, a1, b1));
639
+ }
640
+
641
+ // 32 >> 64
642
+ inline v_int64x2 v_dotprod(const v_int32x4& a, const v_int32x4& b)
643
+ {
644
+ int32x4_t uzp1, uzp2;
645
+ _v128_unzip(a.val, b.val, uzp1, uzp2);
646
+ int32x2_t a0 = vget_low_s32(uzp1);
647
+ int32x2_t b0 = vget_high_s32(uzp1);
648
+ int32x2_t a1 = vget_low_s32(uzp2);
649
+ int32x2_t b1 = vget_high_s32(uzp2);
650
+ int64x2_t p = vmull_s32(a0, b0);
651
+ return v_int64x2(vmlal_s32(p, a1, b1));
652
+ }
653
+ inline v_int64x2 v_dotprod(const v_int32x4& a, const v_int32x4& b, const v_int64x2& c)
654
+ {
655
+ int32x4_t uzp1, uzp2;
656
+ _v128_unzip(a.val, b.val, uzp1, uzp2);
657
+ int32x2_t a0 = vget_low_s32(uzp1);
658
+ int32x2_t b0 = vget_high_s32(uzp1);
659
+ int32x2_t a1 = vget_low_s32(uzp2);
660
+ int32x2_t b1 = vget_high_s32(uzp2);
661
+ int64x2_t p = vmlal_s32(c.val, a0, b0);
662
+ return v_int64x2(vmlal_s32(p, a1, b1));
663
+ }
664
+
665
+ // 8 >> 32
666
+ #ifdef CV_NEON_DOT
667
+ #define OPENCV_HAL_IMPL_NEON_DOT_PRODUCT_OP(_Tpvec1, _Tpvec2, suffix) \
668
+ inline _Tpvec1 v_dotprod_expand(const _Tpvec2& a, const _Tpvec2& b) \
669
+ { \
670
+ return _Tpvec1(vdotq_##suffix(vdupq_n_##suffix(0), a.val, b.val));\
671
+ } \
672
+ inline _Tpvec1 v_dotprod_expand(const _Tpvec2& a, const _Tpvec2& b, const _Tpvec1& c) \
673
+ { \
674
+ return _Tpvec1(vdotq_##suffix(c.val, a.val, b.val)); \
675
+ }
676
+
677
+ OPENCV_HAL_IMPL_NEON_DOT_PRODUCT_OP(v_uint32x4, v_uint8x16, u32)
678
+ OPENCV_HAL_IMPL_NEON_DOT_PRODUCT_OP(v_int32x4, v_int8x16, s32)
679
+ #else
680
+ inline v_uint32x4 v_dotprod_expand(const v_uint8x16& a, const v_uint8x16& b)
681
+ {
682
+ const uint8x16_t zero = vreinterpretq_u8_u32(vdupq_n_u32(0));
683
+ const uint8x16_t mask = vreinterpretq_u8_u32(vdupq_n_u32(0x00FF00FF));
684
+ const uint16x8_t zero32 = vreinterpretq_u16_u32(vdupq_n_u32(0));
685
+ const uint16x8_t mask32 = vreinterpretq_u16_u32(vdupq_n_u32(0x0000FFFF));
686
+
687
+ uint16x8_t even = vmulq_u16(vreinterpretq_u16_u8(vbslq_u8(mask, a.val, zero)),
688
+ vreinterpretq_u16_u8(vbslq_u8(mask, b.val, zero)));
689
+ uint16x8_t odd = vmulq_u16(vshrq_n_u16(vreinterpretq_u16_u8(a.val), 8),
690
+ vshrq_n_u16(vreinterpretq_u16_u8(b.val), 8));
691
+
692
+ uint32x4_t s0 = vaddq_u32(vreinterpretq_u32_u16(vbslq_u16(mask32, even, zero32)),
693
+ vreinterpretq_u32_u16(vbslq_u16(mask32, odd, zero32)));
694
+ uint32x4_t s1 = vaddq_u32(vshrq_n_u32(vreinterpretq_u32_u16(even), 16),
695
+ vshrq_n_u32(vreinterpretq_u32_u16(odd), 16));
696
+ return v_uint32x4(vaddq_u32(s0, s1));
697
+ }
698
+ inline v_uint32x4 v_dotprod_expand(const v_uint8x16& a, const v_uint8x16& b,
699
+ const v_uint32x4& c)
700
+ {
701
+ return v_dotprod_expand(a, b) + c;
702
+ }
703
+
704
+ inline v_int32x4 v_dotprod_expand(const v_int8x16& a, const v_int8x16& b)
705
+ {
706
+ int16x8_t p0 = vmull_s8(vget_low_s8(a.val), vget_low_s8(b.val));
707
+ int16x8_t p1 = vmull_s8(vget_high_s8(a.val), vget_high_s8(b.val));
708
+ int16x8_t uzp1, uzp2;
709
+ _v128_unzip(p0, p1, uzp1, uzp2);
710
+ int16x8_t sum = vaddq_s16(uzp1, uzp2);
711
+ int16x4_t uzpl1, uzpl2;
712
+ _v128_unzip(vget_low_s16(sum), vget_high_s16(sum), uzpl1, uzpl2);
713
+ return v_int32x4(vaddl_s16(uzpl1, uzpl2));
714
+ }
715
+ inline v_int32x4 v_dotprod_expand(const v_int8x16& a, const v_int8x16& b,
716
+ const v_int32x4& c)
717
+ {
718
+ return v_dotprod_expand(a, b) + c;
719
+ }
720
+ #endif
721
+ // 16 >> 64
722
+ inline v_uint64x2 v_dotprod_expand(const v_uint16x8& a, const v_uint16x8& b)
723
+ {
724
+ const uint16x8_t zero = vreinterpretq_u16_u32(vdupq_n_u32(0));
725
+ const uint16x8_t mask = vreinterpretq_u16_u32(vdupq_n_u32(0x0000FFFF));
726
+
727
+ uint32x4_t even = vmulq_u32(vreinterpretq_u32_u16(vbslq_u16(mask, a.val, zero)),
728
+ vreinterpretq_u32_u16(vbslq_u16(mask, b.val, zero)));
729
+ uint32x4_t odd = vmulq_u32(vshrq_n_u32(vreinterpretq_u32_u16(a.val), 16),
730
+ vshrq_n_u32(vreinterpretq_u32_u16(b.val), 16));
731
+ uint32x4_t uzp1, uzp2;
732
+ _v128_unzip(even, odd, uzp1, uzp2);
733
+ uint64x2_t s0 = vaddl_u32(vget_low_u32(uzp1), vget_high_u32(uzp1));
734
+ uint64x2_t s1 = vaddl_u32(vget_low_u32(uzp2), vget_high_u32(uzp2));
735
+ return v_uint64x2(vaddq_u64(s0, s1));
736
+ }
737
+ inline v_uint64x2 v_dotprod_expand(const v_uint16x8& a, const v_uint16x8& b, const v_uint64x2& c)
738
+ { return v_dotprod_expand(a, b) + c; }
739
+
740
+ inline v_int64x2 v_dotprod_expand(const v_int16x8& a, const v_int16x8& b)
741
+ {
742
+ int32x4_t p0 = vmull_s16(vget_low_s16(a.val), vget_low_s16(b.val));
743
+ int32x4_t p1 = vmull_s16(vget_high_s16(a.val), vget_high_s16(b.val));
744
+
745
+ int32x4_t uzp1, uzp2;
746
+ _v128_unzip(p0, p1, uzp1, uzp2);
747
+ int32x4_t sum = vaddq_s32(uzp1, uzp2);
748
+
749
+ int32x2_t uzpl1, uzpl2;
750
+ _v128_unzip(vget_low_s32(sum), vget_high_s32(sum), uzpl1, uzpl2);
751
+ return v_int64x2(vaddl_s32(uzpl1, uzpl2));
752
+ }
753
+ inline v_int64x2 v_dotprod_expand(const v_int16x8& a, const v_int16x8& b,
754
+ const v_int64x2& c)
755
+ { return v_dotprod_expand(a, b) + c; }
756
+
757
+ // 32 >> 64f
758
+ #if CV_SIMD128_64F
759
+ inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b)
760
+ { return v_cvt_f64(v_dotprod(a, b)); }
761
+ inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b,
762
+ const v_float64x2& c)
763
+ { return v_dotprod_expand(a, b) + c; }
764
+ #endif
765
+
766
+ //////// Fast Dot Product ////////
767
+
768
+ // 16 >> 32
769
+ inline v_int32x4 v_dotprod_fast(const v_int16x8& a, const v_int16x8& b)
770
+ {
771
+ #if CV_NEON_AARCH64
772
+ int32x4_t p = vmull_s16(vget_low_s16(a.val), vget_low_s16(b.val));
773
+ return v_int32x4(vmlal_high_s16(p, a.val, b.val));
774
+ #else
775
+ int16x4_t a0 = vget_low_s16(a.val);
776
+ int16x4_t a1 = vget_high_s16(a.val);
777
+ int16x4_t b0 = vget_low_s16(b.val);
778
+ int16x4_t b1 = vget_high_s16(b.val);
779
+ int32x4_t p = vmull_s16(a0, b0);
780
+ return v_int32x4(vmlal_s16(p, a1, b1));
781
+ #endif
782
+ }
783
+ inline v_int32x4 v_dotprod_fast(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c)
784
+ {
785
+ #if CV_NEON_AARCH64
786
+ int32x4_t p = vmlal_s16(c.val, vget_low_s16(a.val), vget_low_s16(b.val));
787
+ return v_int32x4(vmlal_high_s16(p, a.val, b.val));
788
+ #else
789
+ int16x4_t a0 = vget_low_s16(a.val);
790
+ int16x4_t a1 = vget_high_s16(a.val);
791
+ int16x4_t b0 = vget_low_s16(b.val);
792
+ int16x4_t b1 = vget_high_s16(b.val);
793
+ int32x4_t p = vmlal_s16(c.val, a0, b0);
794
+ return v_int32x4(vmlal_s16(p, a1, b1));
795
+ #endif
796
+ }
797
+
798
+ // 32 >> 64
799
+ inline v_int64x2 v_dotprod_fast(const v_int32x4& a, const v_int32x4& b)
800
+ {
801
+ #if CV_NEON_AARCH64
802
+ int64x2_t p = vmull_s32(vget_low_s32(a.val), vget_low_s32(b.val));
803
+ return v_int64x2(vmlal_high_s32(p, a.val, b.val));
804
+ #else
805
+ int32x2_t a0 = vget_low_s32(a.val);
806
+ int32x2_t a1 = vget_high_s32(a.val);
807
+ int32x2_t b0 = vget_low_s32(b.val);
808
+ int32x2_t b1 = vget_high_s32(b.val);
809
+ int64x2_t p = vmull_s32(a0, b0);
810
+ return v_int64x2(vmlal_s32(p, a1, b1));
811
+ #endif
812
+ }
813
+ inline v_int64x2 v_dotprod_fast(const v_int32x4& a, const v_int32x4& b, const v_int64x2& c)
814
+ {
815
+ #if CV_NEON_AARCH64
816
+ int64x2_t p = vmlal_s32(c.val, vget_low_s32(a.val), vget_low_s32(b.val));
817
+ return v_int64x2(vmlal_high_s32(p, a.val, b.val));
818
+ #else
819
+ int32x2_t a0 = vget_low_s32(a.val);
820
+ int32x2_t a1 = vget_high_s32(a.val);
821
+ int32x2_t b0 = vget_low_s32(b.val);
822
+ int32x2_t b1 = vget_high_s32(b.val);
823
+ int64x2_t p = vmlal_s32(c.val, a0, b0);
824
+ return v_int64x2(vmlal_s32(p, a1, b1));
825
+ #endif
826
+ }
827
+
828
+ // 8 >> 32
829
+ #ifdef CV_NEON_DOT
830
+ #define OPENCV_HAL_IMPL_NEON_DOT_PRODUCT_FAST_OP(_Tpvec1, _Tpvec2, suffix) \
831
+ inline _Tpvec1 v_dotprod_expand_fast(const _Tpvec2& a, const _Tpvec2& b) \
832
+ { \
833
+ return v_dotprod_expand(a, b); \
834
+ } \
835
+ inline _Tpvec1 v_dotprod_expand_fast(const _Tpvec2& a, const _Tpvec2& b, const _Tpvec1& c) \
836
+ { \
837
+ return v_dotprod_expand(a, b, c); \
838
+ }
839
+
840
+ OPENCV_HAL_IMPL_NEON_DOT_PRODUCT_FAST_OP(v_uint32x4, v_uint8x16, u32)
841
+ OPENCV_HAL_IMPL_NEON_DOT_PRODUCT_FAST_OP(v_int32x4, v_int8x16, s32)
842
+ #else
843
+ inline v_uint32x4 v_dotprod_expand_fast(const v_uint8x16& a, const v_uint8x16& b)
844
+ {
845
+ uint16x8_t p0 = vmull_u8(vget_low_u8(a.val), vget_low_u8(b.val));
846
+ uint16x8_t p1 = vmull_u8(vget_high_u8(a.val), vget_high_u8(b.val));
847
+ uint32x4_t s0 = vaddl_u16(vget_low_u16(p0), vget_low_u16(p1));
848
+ uint32x4_t s1 = vaddl_u16(vget_high_u16(p0), vget_high_u16(p1));
849
+ return v_uint32x4(vaddq_u32(s0, s1));
850
+ }
851
+ inline v_uint32x4 v_dotprod_expand_fast(const v_uint8x16& a, const v_uint8x16& b, const v_uint32x4& c)
852
+ {
853
+ return v_dotprod_expand_fast(a, b) + c;
854
+ }
855
+
856
+ inline v_int32x4 v_dotprod_expand_fast(const v_int8x16& a, const v_int8x16& b)
857
+ {
858
+ int16x8_t prod = vmull_s8(vget_low_s8(a.val), vget_low_s8(b.val));
859
+ prod = vmlal_s8(prod, vget_high_s8(a.val), vget_high_s8(b.val));
860
+ return v_int32x4(vaddl_s16(vget_low_s16(prod), vget_high_s16(prod)));
861
+ }
862
+ inline v_int32x4 v_dotprod_expand_fast(const v_int8x16& a, const v_int8x16& b, const v_int32x4& c)
863
+ {
864
+ return v_dotprod_expand_fast(a, b) + c;
865
+ }
866
+ #endif
867
+
868
+ // 16 >> 64
869
+ inline v_uint64x2 v_dotprod_expand_fast(const v_uint16x8& a, const v_uint16x8& b)
870
+ {
871
+ uint32x4_t p0 = vmull_u16(vget_low_u16(a.val), vget_low_u16(b.val));
872
+ uint32x4_t p1 = vmull_u16(vget_high_u16(a.val), vget_high_u16(b.val));
873
+ uint64x2_t s0 = vaddl_u32(vget_low_u32(p0), vget_high_u32(p0));
874
+ uint64x2_t s1 = vaddl_u32(vget_low_u32(p1), vget_high_u32(p1));
875
+ return v_uint64x2(vaddq_u64(s0, s1));
876
+ }
877
+ inline v_uint64x2 v_dotprod_expand_fast(const v_uint16x8& a, const v_uint16x8& b, const v_uint64x2& c)
878
+ { return v_dotprod_expand_fast(a, b) + c; }
879
+
880
+ inline v_int64x2 v_dotprod_expand_fast(const v_int16x8& a, const v_int16x8& b)
881
+ {
882
+ int32x4_t prod = vmull_s16(vget_low_s16(a.val), vget_low_s16(b.val));
883
+ prod = vmlal_s16(prod, vget_high_s16(a.val), vget_high_s16(b.val));
884
+ return v_int64x2(vaddl_s32(vget_low_s32(prod), vget_high_s32(prod)));
885
+ }
886
+ inline v_int64x2 v_dotprod_expand_fast(const v_int16x8& a, const v_int16x8& b, const v_int64x2& c)
887
+ { return v_dotprod_expand_fast(a, b) + c; }
888
+
889
+ // 32 >> 64f
890
+ #if CV_SIMD128_64F
891
+ inline v_float64x2 v_dotprod_expand_fast(const v_int32x4& a, const v_int32x4& b)
892
+ { return v_cvt_f64(v_dotprod_fast(a, b)); }
893
+ inline v_float64x2 v_dotprod_expand_fast(const v_int32x4& a, const v_int32x4& b, const v_float64x2& c)
894
+ { return v_dotprod_expand_fast(a, b) + c; }
895
+ #endif
896
+
897
+
898
+ #define OPENCV_HAL_IMPL_NEON_LOGIC_OP(_Tpvec, suffix) \
899
+ OPENCV_HAL_IMPL_NEON_BIN_OP(&, _Tpvec, vandq_##suffix) \
900
+ OPENCV_HAL_IMPL_NEON_BIN_OP(|, _Tpvec, vorrq_##suffix) \
901
+ OPENCV_HAL_IMPL_NEON_BIN_OP(^, _Tpvec, veorq_##suffix) \
902
+ inline _Tpvec operator ~ (const _Tpvec& a) \
903
+ { \
904
+ return _Tpvec(vreinterpretq_##suffix##_u8(vmvnq_u8(vreinterpretq_u8_##suffix(a.val)))); \
905
+ }
906
+
907
+ OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_uint8x16, u8)
908
+ OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_int8x16, s8)
909
+ OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_uint16x8, u16)
910
+ OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_int16x8, s16)
911
+ OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_uint32x4, u32)
912
+ OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_int32x4, s32)
913
+ OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_uint64x2, u64)
914
+ OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_int64x2, s64)
915
+
916
+ #define OPENCV_HAL_IMPL_NEON_FLT_BIT_OP(bin_op, intrin) \
917
+ inline v_float32x4 operator bin_op (const v_float32x4& a, const v_float32x4& b) \
918
+ { \
919
+ return v_float32x4(vreinterpretq_f32_s32(intrin(vreinterpretq_s32_f32(a.val), vreinterpretq_s32_f32(b.val)))); \
920
+ } \
921
+ inline v_float32x4& operator bin_op##= (v_float32x4& a, const v_float32x4& b) \
922
+ { \
923
+ a.val = vreinterpretq_f32_s32(intrin(vreinterpretq_s32_f32(a.val), vreinterpretq_s32_f32(b.val))); \
924
+ return a; \
925
+ }
926
+
927
+ OPENCV_HAL_IMPL_NEON_FLT_BIT_OP(&, vandq_s32)
928
+ OPENCV_HAL_IMPL_NEON_FLT_BIT_OP(|, vorrq_s32)
929
+ OPENCV_HAL_IMPL_NEON_FLT_BIT_OP(^, veorq_s32)
930
+
931
+ inline v_float32x4 operator ~ (const v_float32x4& a)
932
+ {
933
+ return v_float32x4(vreinterpretq_f32_s32(vmvnq_s32(vreinterpretq_s32_f32(a.val))));
934
+ }
935
+
936
+ #if CV_SIMD128_64F
937
+ inline v_float32x4 v_sqrt(const v_float32x4& x)
938
+ {
939
+ return v_float32x4(vsqrtq_f32(x.val));
940
+ }
941
+
942
+ inline v_float32x4 v_invsqrt(const v_float32x4& x)
943
+ {
944
+ v_float32x4 one = v_setall_f32(1.0f);
945
+ return one / v_sqrt(x);
946
+ }
947
+ #else
948
+ inline v_float32x4 v_sqrt(const v_float32x4& x)
949
+ {
950
+ float32x4_t x1 = vmaxq_f32(x.val, vdupq_n_f32(FLT_MIN));
951
+ float32x4_t e = vrsqrteq_f32(x1);
952
+ e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(x1, e), e), e);
953
+ e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(x1, e), e), e);
954
+ return v_float32x4(vmulq_f32(x.val, e));
955
+ }
956
+
957
+ inline v_float32x4 v_invsqrt(const v_float32x4& x)
958
+ {
959
+ float32x4_t e = vrsqrteq_f32(x.val);
960
+ e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(x.val, e), e), e);
961
+ e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(x.val, e), e), e);
962
+ return v_float32x4(e);
963
+ }
964
+ #endif
965
+
966
+ #define OPENCV_HAL_IMPL_NEON_ABS(_Tpuvec, _Tpsvec, usuffix, ssuffix) \
967
+ inline _Tpuvec v_abs(const _Tpsvec& a) { return v_reinterpret_as_##usuffix(_Tpsvec(vabsq_##ssuffix(a.val))); }
968
+
969
+ OPENCV_HAL_IMPL_NEON_ABS(v_uint8x16, v_int8x16, u8, s8)
970
+ OPENCV_HAL_IMPL_NEON_ABS(v_uint16x8, v_int16x8, u16, s16)
971
+ OPENCV_HAL_IMPL_NEON_ABS(v_uint32x4, v_int32x4, u32, s32)
972
+
973
+ inline v_float32x4 v_abs(v_float32x4 x)
974
+ { return v_float32x4(vabsq_f32(x.val)); }
975
+
976
+ #if CV_SIMD128_64F
977
+ #define OPENCV_HAL_IMPL_NEON_DBL_BIT_OP(bin_op, intrin) \
978
+ inline v_float64x2 operator bin_op (const v_float64x2& a, const v_float64x2& b) \
979
+ { \
980
+ return v_float64x2(vreinterpretq_f64_s64(intrin(vreinterpretq_s64_f64(a.val), vreinterpretq_s64_f64(b.val)))); \
981
+ } \
982
+ inline v_float64x2& operator bin_op##= (v_float64x2& a, const v_float64x2& b) \
983
+ { \
984
+ a.val = vreinterpretq_f64_s64(intrin(vreinterpretq_s64_f64(a.val), vreinterpretq_s64_f64(b.val))); \
985
+ return a; \
986
+ }
987
+
988
+ OPENCV_HAL_IMPL_NEON_DBL_BIT_OP(&, vandq_s64)
989
+ OPENCV_HAL_IMPL_NEON_DBL_BIT_OP(|, vorrq_s64)
990
+ OPENCV_HAL_IMPL_NEON_DBL_BIT_OP(^, veorq_s64)
991
+
992
+ inline v_float64x2 operator ~ (const v_float64x2& a)
993
+ {
994
+ return v_float64x2(vreinterpretq_f64_s32(vmvnq_s32(vreinterpretq_s32_f64(a.val))));
995
+ }
996
+
997
+ inline v_float64x2 v_sqrt(const v_float64x2& x)
998
+ {
999
+ return v_float64x2(vsqrtq_f64(x.val));
1000
+ }
1001
+
1002
+ inline v_float64x2 v_invsqrt(const v_float64x2& x)
1003
+ {
1004
+ v_float64x2 one = v_setall_f64(1.0f);
1005
+ return one / v_sqrt(x);
1006
+ }
1007
+
1008
+ inline v_float64x2 v_abs(v_float64x2 x)
1009
+ { return v_float64x2(vabsq_f64(x.val)); }
1010
+ #endif
1011
+
1012
+ // TODO: exp, log, sin, cos
1013
+
1014
+ #define OPENCV_HAL_IMPL_NEON_BIN_FUNC(_Tpvec, func, intrin) \
1015
+ inline _Tpvec func(const _Tpvec& a, const _Tpvec& b) \
1016
+ { \
1017
+ return _Tpvec(intrin(a.val, b.val)); \
1018
+ }
1019
+
1020
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint8x16, v_min, vminq_u8)
1021
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint8x16, v_max, vmaxq_u8)
1022
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int8x16, v_min, vminq_s8)
1023
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int8x16, v_max, vmaxq_s8)
1024
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint16x8, v_min, vminq_u16)
1025
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint16x8, v_max, vmaxq_u16)
1026
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int16x8, v_min, vminq_s16)
1027
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int16x8, v_max, vmaxq_s16)
1028
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint32x4, v_min, vminq_u32)
1029
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint32x4, v_max, vmaxq_u32)
1030
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int32x4, v_min, vminq_s32)
1031
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int32x4, v_max, vmaxq_s32)
1032
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float32x4, v_min, vminq_f32)
1033
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float32x4, v_max, vmaxq_f32)
1034
+ #if CV_SIMD128_64F
1035
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float64x2, v_min, vminq_f64)
1036
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float64x2, v_max, vmaxq_f64)
1037
+ #endif
1038
+
1039
+ #if CV_SIMD128_64F
1040
+ inline int64x2_t vmvnq_s64(int64x2_t a)
1041
+ {
1042
+ int64x2_t vx = vreinterpretq_s64_u32(vdupq_n_u32(0xFFFFFFFF));
1043
+ return veorq_s64(a, vx);
1044
+ }
1045
+ inline uint64x2_t vmvnq_u64(uint64x2_t a)
1046
+ {
1047
+ uint64x2_t vx = vreinterpretq_u64_u32(vdupq_n_u32(0xFFFFFFFF));
1048
+ return veorq_u64(a, vx);
1049
+ }
1050
+ #endif
1051
+ #define OPENCV_HAL_IMPL_NEON_INT_CMP_OP(_Tpvec, cast, suffix, not_suffix) \
1052
+ inline _Tpvec operator == (const _Tpvec& a, const _Tpvec& b) \
1053
+ { return _Tpvec(cast(vceqq_##suffix(a.val, b.val))); } \
1054
+ inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \
1055
+ { return _Tpvec(cast(vmvnq_##not_suffix(vceqq_##suffix(a.val, b.val)))); } \
1056
+ inline _Tpvec operator < (const _Tpvec& a, const _Tpvec& b) \
1057
+ { return _Tpvec(cast(vcltq_##suffix(a.val, b.val))); } \
1058
+ inline _Tpvec operator > (const _Tpvec& a, const _Tpvec& b) \
1059
+ { return _Tpvec(cast(vcgtq_##suffix(a.val, b.val))); } \
1060
+ inline _Tpvec operator <= (const _Tpvec& a, const _Tpvec& b) \
1061
+ { return _Tpvec(cast(vcleq_##suffix(a.val, b.val))); } \
1062
+ inline _Tpvec operator >= (const _Tpvec& a, const _Tpvec& b) \
1063
+ { return _Tpvec(cast(vcgeq_##suffix(a.val, b.val))); }
1064
+
1065
+ OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_uint8x16, OPENCV_HAL_NOP, u8, u8)
1066
+ OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_int8x16, vreinterpretq_s8_u8, s8, u8)
1067
+ OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_uint16x8, OPENCV_HAL_NOP, u16, u16)
1068
+ OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_int16x8, vreinterpretq_s16_u16, s16, u16)
1069
+ OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_uint32x4, OPENCV_HAL_NOP, u32, u32)
1070
+ OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_int32x4, vreinterpretq_s32_u32, s32, u32)
1071
+ OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_float32x4, vreinterpretq_f32_u32, f32, u32)
1072
+ #if CV_SIMD128_64F
1073
+ OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_uint64x2, OPENCV_HAL_NOP, u64, u64)
1074
+ OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_int64x2, vreinterpretq_s64_u64, s64, u64)
1075
+ OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_float64x2, vreinterpretq_f64_u64, f64, u64)
1076
+ #endif
1077
+
1078
+ inline v_float32x4 v_not_nan(const v_float32x4& a)
1079
+ { return v_float32x4(vreinterpretq_f32_u32(vceqq_f32(a.val, a.val))); }
1080
+ #if CV_SIMD128_64F
1081
+ inline v_float64x2 v_not_nan(const v_float64x2& a)
1082
+ { return v_float64x2(vreinterpretq_f64_u64(vceqq_f64(a.val, a.val))); }
1083
+ #endif
1084
+
1085
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint8x16, v_add_wrap, vaddq_u8)
1086
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int8x16, v_add_wrap, vaddq_s8)
1087
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint16x8, v_add_wrap, vaddq_u16)
1088
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int16x8, v_add_wrap, vaddq_s16)
1089
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint8x16, v_sub_wrap, vsubq_u8)
1090
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int8x16, v_sub_wrap, vsubq_s8)
1091
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint16x8, v_sub_wrap, vsubq_u16)
1092
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int16x8, v_sub_wrap, vsubq_s16)
1093
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint8x16, v_mul_wrap, vmulq_u8)
1094
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int8x16, v_mul_wrap, vmulq_s8)
1095
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint16x8, v_mul_wrap, vmulq_u16)
1096
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int16x8, v_mul_wrap, vmulq_s16)
1097
+
1098
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint8x16, v_absdiff, vabdq_u8)
1099
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint16x8, v_absdiff, vabdq_u16)
1100
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint32x4, v_absdiff, vabdq_u32)
1101
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float32x4, v_absdiff, vabdq_f32)
1102
+ #if CV_SIMD128_64F
1103
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float64x2, v_absdiff, vabdq_f64)
1104
+ #endif
1105
+
1106
+ /** Saturating absolute difference **/
1107
+ inline v_int8x16 v_absdiffs(const v_int8x16& a, const v_int8x16& b)
1108
+ { return v_int8x16(vqabsq_s8(vqsubq_s8(a.val, b.val))); }
1109
+ inline v_int16x8 v_absdiffs(const v_int16x8& a, const v_int16x8& b)
1110
+ { return v_int16x8(vqabsq_s16(vqsubq_s16(a.val, b.val))); }
1111
+
1112
+ #define OPENCV_HAL_IMPL_NEON_BIN_FUNC2(_Tpvec, _Tpvec2, cast, func, intrin) \
1113
+ inline _Tpvec2 func(const _Tpvec& a, const _Tpvec& b) \
1114
+ { \
1115
+ return _Tpvec2(cast(intrin(a.val, b.val))); \
1116
+ }
1117
+
1118
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC2(v_int8x16, v_uint8x16, vreinterpretq_u8_s8, v_absdiff, vabdq_s8)
1119
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC2(v_int16x8, v_uint16x8, vreinterpretq_u16_s16, v_absdiff, vabdq_s16)
1120
+ OPENCV_HAL_IMPL_NEON_BIN_FUNC2(v_int32x4, v_uint32x4, vreinterpretq_u32_s32, v_absdiff, vabdq_s32)
1121
+
1122
+ inline v_float32x4 v_magnitude(const v_float32x4& a, const v_float32x4& b)
1123
+ {
1124
+ v_float32x4 x(vmlaq_f32(vmulq_f32(a.val, a.val), b.val, b.val));
1125
+ return v_sqrt(x);
1126
+ }
1127
+
1128
+ inline v_float32x4 v_sqr_magnitude(const v_float32x4& a, const v_float32x4& b)
1129
+ {
1130
+ return v_float32x4(vmlaq_f32(vmulq_f32(a.val, a.val), b.val, b.val));
1131
+ }
1132
+
1133
+ inline v_float32x4 v_fma(const v_float32x4& a, const v_float32x4& b, const v_float32x4& c)
1134
+ {
1135
+ #if CV_SIMD128_64F
1136
+ // ARMv8, which adds support for 64-bit floating-point (so CV_SIMD128_64F is defined),
1137
+ // also adds FMA support both for single- and double-precision floating-point vectors
1138
+ return v_float32x4(vfmaq_f32(c.val, a.val, b.val));
1139
+ #else
1140
+ return v_float32x4(vmlaq_f32(c.val, a.val, b.val));
1141
+ #endif
1142
+ }
1143
+
1144
+ inline v_int32x4 v_fma(const v_int32x4& a, const v_int32x4& b, const v_int32x4& c)
1145
+ {
1146
+ return v_int32x4(vmlaq_s32(c.val, a.val, b.val));
1147
+ }
1148
+
1149
+ inline v_float32x4 v_muladd(const v_float32x4& a, const v_float32x4& b, const v_float32x4& c)
1150
+ {
1151
+ return v_fma(a, b, c);
1152
+ }
1153
+
1154
+ inline v_int32x4 v_muladd(const v_int32x4& a, const v_int32x4& b, const v_int32x4& c)
1155
+ {
1156
+ return v_fma(a, b, c);
1157
+ }
1158
+
1159
+ #if CV_SIMD128_64F
1160
+ inline v_float64x2 v_magnitude(const v_float64x2& a, const v_float64x2& b)
1161
+ {
1162
+ v_float64x2 x(vaddq_f64(vmulq_f64(a.val, a.val), vmulq_f64(b.val, b.val)));
1163
+ return v_sqrt(x);
1164
+ }
1165
+
1166
+ inline v_float64x2 v_sqr_magnitude(const v_float64x2& a, const v_float64x2& b)
1167
+ {
1168
+ return v_float64x2(vaddq_f64(vmulq_f64(a.val, a.val), vmulq_f64(b.val, b.val)));
1169
+ }
1170
+
1171
+ inline v_float64x2 v_fma(const v_float64x2& a, const v_float64x2& b, const v_float64x2& c)
1172
+ {
1173
+ return v_float64x2(vfmaq_f64(c.val, a.val, b.val));
1174
+ }
1175
+
1176
+ inline v_float64x2 v_muladd(const v_float64x2& a, const v_float64x2& b, const v_float64x2& c)
1177
+ {
1178
+ return v_fma(a, b, c);
1179
+ }
1180
+ #endif
1181
+
1182
+ // trade efficiency for convenience
1183
+ #define OPENCV_HAL_IMPL_NEON_SHIFT_OP(_Tpvec, suffix, _Tps, ssuffix) \
1184
+ inline _Tpvec operator << (const _Tpvec& a, int n) \
1185
+ { return _Tpvec(vshlq_##suffix(a.val, vdupq_n_##ssuffix((_Tps)n))); } \
1186
+ inline _Tpvec operator >> (const _Tpvec& a, int n) \
1187
+ { return _Tpvec(vshlq_##suffix(a.val, vdupq_n_##ssuffix((_Tps)-n))); } \
1188
+ template<int n> inline _Tpvec v_shl(const _Tpvec& a) \
1189
+ { return _Tpvec(vshlq_n_##suffix(a.val, n)); } \
1190
+ template<int n> inline _Tpvec v_shr(const _Tpvec& a) \
1191
+ { return _Tpvec(vshrq_n_##suffix(a.val, n)); } \
1192
+ template<int n> inline _Tpvec v_rshr(const _Tpvec& a) \
1193
+ { return _Tpvec(vrshrq_n_##suffix(a.val, n)); }
1194
+
1195
+ OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_uint8x16, u8, schar, s8)
1196
+ OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_int8x16, s8, schar, s8)
1197
+ OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_uint16x8, u16, short, s16)
1198
+ OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_int16x8, s16, short, s16)
1199
+ OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_uint32x4, u32, int, s32)
1200
+ OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_int32x4, s32, int, s32)
1201
+ OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_uint64x2, u64, int64, s64)
1202
+ OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_int64x2, s64, int64, s64)
1203
+
1204
+ #define OPENCV_HAL_IMPL_NEON_ROTATE_OP(_Tpvec, suffix) \
1205
+ template<int n> inline _Tpvec v_rotate_right(const _Tpvec& a) \
1206
+ { return _Tpvec(vextq_##suffix(a.val, vdupq_n_##suffix(0), n)); } \
1207
+ template<int n> inline _Tpvec v_rotate_left(const _Tpvec& a) \
1208
+ { return _Tpvec(vextq_##suffix(vdupq_n_##suffix(0), a.val, _Tpvec::nlanes - n)); } \
1209
+ template<> inline _Tpvec v_rotate_left<0>(const _Tpvec& a) \
1210
+ { return a; } \
1211
+ template<int n> inline _Tpvec v_rotate_right(const _Tpvec& a, const _Tpvec& b) \
1212
+ { return _Tpvec(vextq_##suffix(a.val, b.val, n)); } \
1213
+ template<int n> inline _Tpvec v_rotate_left(const _Tpvec& a, const _Tpvec& b) \
1214
+ { return _Tpvec(vextq_##suffix(b.val, a.val, _Tpvec::nlanes - n)); } \
1215
+ template<> inline _Tpvec v_rotate_left<0>(const _Tpvec& a, const _Tpvec& b) \
1216
+ { CV_UNUSED(b); return a; }
1217
+
1218
+ OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_uint8x16, u8)
1219
+ OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_int8x16, s8)
1220
+ OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_uint16x8, u16)
1221
+ OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_int16x8, s16)
1222
+ OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_uint32x4, u32)
1223
+ OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_int32x4, s32)
1224
+ OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_float32x4, f32)
1225
+ OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_uint64x2, u64)
1226
+ OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_int64x2, s64)
1227
+ #if CV_SIMD128_64F
1228
+ OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_float64x2, f64)
1229
+ #endif
1230
+
1231
+ #if defined(__clang__) && defined(__aarch64__)
1232
+ // avoid LD2 instruction. details: https://github.com/opencv/opencv/issues/14863
1233
+ #define OPENCV_HAL_IMPL_NEON_LOAD_LOW_OP(_Tpvec, _Tp, suffix) \
1234
+ inline _Tpvec v_load_low(const _Tp* ptr) \
1235
+ { \
1236
+ typedef uint64 CV_DECL_ALIGNED(1) unaligned_uint64; \
1237
+ uint64 v = *(unaligned_uint64*)ptr; \
1238
+ return _Tpvec(v_reinterpret_as_##suffix(v_uint64x2(v, (uint64)123456))); \
1239
+ }
1240
+ #else
1241
+ #define OPENCV_HAL_IMPL_NEON_LOAD_LOW_OP(_Tpvec, _Tp, suffix) \
1242
+ inline _Tpvec v_load_low(const _Tp* ptr) \
1243
+ { return _Tpvec(vcombine_##suffix(vld1_##suffix(ptr), vdup_n_##suffix((_Tp)0))); }
1244
+ #endif
1245
+
1246
+ #define OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(_Tpvec, _Tp, suffix) \
1247
+ inline _Tpvec v_load(const _Tp* ptr) \
1248
+ { return _Tpvec(vld1q_##suffix(ptr)); } \
1249
+ inline _Tpvec v_load_aligned(const _Tp* ptr) \
1250
+ { return _Tpvec(vld1q_##suffix(ptr)); } \
1251
+ OPENCV_HAL_IMPL_NEON_LOAD_LOW_OP(_Tpvec, _Tp, suffix) \
1252
+ inline _Tpvec v_load_halves(const _Tp* ptr0, const _Tp* ptr1) \
1253
+ { return _Tpvec(vcombine_##suffix(vld1_##suffix(ptr0), vld1_##suffix(ptr1))); } \
1254
+ inline void v_store(_Tp* ptr, const _Tpvec& a) \
1255
+ { vst1q_##suffix(ptr, a.val); } \
1256
+ inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \
1257
+ { vst1q_##suffix(ptr, a.val); } \
1258
+ inline void v_store_aligned_nocache(_Tp* ptr, const _Tpvec& a) \
1259
+ { vst1q_##suffix(ptr, a.val); } \
1260
+ inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode /*mode*/) \
1261
+ { vst1q_##suffix(ptr, a.val); } \
1262
+ inline void v_store_low(_Tp* ptr, const _Tpvec& a) \
1263
+ { vst1_##suffix(ptr, vget_low_##suffix(a.val)); } \
1264
+ inline void v_store_high(_Tp* ptr, const _Tpvec& a) \
1265
+ { vst1_##suffix(ptr, vget_high_##suffix(a.val)); }
1266
+
1267
+ OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_uint8x16, uchar, u8)
1268
+ OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_int8x16, schar, s8)
1269
+ OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_uint16x8, ushort, u16)
1270
+ OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_int16x8, short, s16)
1271
+ OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_uint32x4, unsigned, u32)
1272
+ OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_int32x4, int, s32)
1273
+ OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_uint64x2, uint64, u64)
1274
+ OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_int64x2, int64, s64)
1275
+ OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_float32x4, float, f32)
1276
+ #if CV_SIMD128_64F
1277
+ OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_float64x2, double, f64)
1278
+ #endif
1279
+
1280
+ inline unsigned v_reduce_sum(const v_uint8x16& a)
1281
+ {
1282
+ #if CV_NEON_AARCH64
1283
+ uint16_t t0 = vaddlvq_u8(a.val);
1284
+ return t0;
1285
+ #else // #if CV_NEON_AARCH64
1286
+ uint32x4_t t0 = vpaddlq_u16(vpaddlq_u8(a.val));
1287
+ uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0));
1288
+ return vget_lane_u32(vpadd_u32(t1, t1), 0);
1289
+ #endif // #if CV_NEON_AARCH64
1290
+ }
1291
+ inline int v_reduce_sum(const v_int8x16& a)
1292
+ {
1293
+ #if CV_NEON_AARCH64
1294
+ int16_t t0 = vaddlvq_s8(a.val);
1295
+ return t0;
1296
+ #else // #if CV_NEON_AARCH64
1297
+ int32x4_t t0 = vpaddlq_s16(vpaddlq_s8(a.val));
1298
+ int32x2_t t1 = vpadd_s32(vget_low_s32(t0), vget_high_s32(t0));
1299
+ return vget_lane_s32(vpadd_s32(t1, t1), 0);
1300
+ #endif // #if CV_NEON_AARCH64
1301
+ }
1302
+ inline unsigned v_reduce_sum(const v_uint16x8& a)
1303
+ {
1304
+ #if CV_NEON_AARCH64
1305
+ uint32_t t0 = vaddlvq_u16(a.val);
1306
+ return t0;
1307
+ #else // #if CV_NEON_AARCH64
1308
+ uint32x4_t t0 = vpaddlq_u16(a.val);
1309
+ uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0));
1310
+ return vget_lane_u32(vpadd_u32(t1, t1), 0);
1311
+ #endif // #if CV_NEON_AARCH64
1312
+ }
1313
+ inline int v_reduce_sum(const v_int16x8& a)
1314
+ {
1315
+ #if CV_NEON_AARCH64
1316
+ int32_t t0 = vaddlvq_s16(a.val);
1317
+ return t0;
1318
+ #else // #if CV_NEON_AARCH64
1319
+ int32x4_t t0 = vpaddlq_s16(a.val);
1320
+ int32x2_t t1 = vpadd_s32(vget_low_s32(t0), vget_high_s32(t0));
1321
+ return vget_lane_s32(vpadd_s32(t1, t1), 0);
1322
+ #endif // #if CV_NEON_AARCH64
1323
+ }
1324
+
1325
+ #if CV_NEON_AARCH64
1326
+ #define OPENCV_HAL_IMPL_NEON_REDUCE_OP_16(_Tpvec, _Tpnvec, scalartype, func, vectorfunc, suffix) \
1327
+ inline scalartype v_reduce_##func(const _Tpvec& a) \
1328
+ { \
1329
+ return v##vectorfunc##vq_##suffix(a.val); \
1330
+ }
1331
+ #else // #if CV_NEON_AARCH64
1332
+ #define OPENCV_HAL_IMPL_NEON_REDUCE_OP_16(_Tpvec, _Tpnvec, scalartype, func, vectorfunc, suffix) \
1333
+ inline scalartype v_reduce_##func(const _Tpvec& a) \
1334
+ { \
1335
+ _Tpnvec##_t a0 = vp##vectorfunc##_##suffix(vget_low_##suffix(a.val), vget_high_##suffix(a.val)); \
1336
+ a0 = vp##vectorfunc##_##suffix(a0, a0); \
1337
+ a0 = vp##vectorfunc##_##suffix(a0, a0); \
1338
+ return (scalartype)vget_lane_##suffix(vp##vectorfunc##_##suffix(a0, a0),0); \
1339
+ }
1340
+ #endif // #if CV_NEON_AARCH64
1341
+
1342
+ OPENCV_HAL_IMPL_NEON_REDUCE_OP_16(v_uint8x16, uint8x8, uchar, max, max, u8)
1343
+ OPENCV_HAL_IMPL_NEON_REDUCE_OP_16(v_uint8x16, uint8x8, uchar, min, min, u8)
1344
+ OPENCV_HAL_IMPL_NEON_REDUCE_OP_16(v_int8x16, int8x8, schar, max, max, s8)
1345
+ OPENCV_HAL_IMPL_NEON_REDUCE_OP_16(v_int8x16, int8x8, schar, min, min, s8)
1346
+
1347
+ #if CV_NEON_AARCH64
1348
+ #define OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(_Tpvec, _Tpnvec, scalartype, func, vectorfunc, suffix) \
1349
+ inline scalartype v_reduce_##func(const _Tpvec& a) \
1350
+ { \
1351
+ return v##vectorfunc##vq_##suffix(a.val); \
1352
+ }
1353
+ #else // #if CV_NEON_AARCH64
1354
+ #define OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(_Tpvec, _Tpnvec, scalartype, func, vectorfunc, suffix) \
1355
+ inline scalartype v_reduce_##func(const _Tpvec& a) \
1356
+ { \
1357
+ _Tpnvec##_t a0 = vp##vectorfunc##_##suffix(vget_low_##suffix(a.val), vget_high_##suffix(a.val)); \
1358
+ a0 = vp##vectorfunc##_##suffix(a0, a0); \
1359
+ return (scalartype)vget_lane_##suffix(vp##vectorfunc##_##suffix(a0, a0),0); \
1360
+ }
1361
+ #endif // #if CV_NEON_AARCH64
1362
+
1363
+ OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_uint16x8, uint16x4, ushort, max, max, u16)
1364
+ OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_uint16x8, uint16x4, ushort, min, min, u16)
1365
+ OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_int16x8, int16x4, short, max, max, s16)
1366
+ OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_int16x8, int16x4, short, min, min, s16)
1367
+
1368
+ #if CV_NEON_AARCH64
1369
+ #define OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(_Tpvec, _Tpnvec, scalartype, func, vectorfunc, suffix) \
1370
+ inline scalartype v_reduce_##func(const _Tpvec& a) \
1371
+ { \
1372
+ return v##vectorfunc##vq_##suffix(a.val); \
1373
+ }
1374
+ #else // #if CV_NEON_AARCH64
1375
+ #define OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(_Tpvec, _Tpnvec, scalartype, func, vectorfunc, suffix) \
1376
+ inline scalartype v_reduce_##func(const _Tpvec& a) \
1377
+ { \
1378
+ _Tpnvec##_t a0 = vp##vectorfunc##_##suffix(vget_low_##suffix(a.val), vget_high_##suffix(a.val)); \
1379
+ return (scalartype)vget_lane_##suffix(vp##vectorfunc##_##suffix(a0, vget_high_##suffix(a.val)),0); \
1380
+ }
1381
+ #endif // #if CV_NEON_AARCH64
1382
+
1383
+ OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, uint32x2, unsigned, sum, add, u32)
1384
+ OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, uint32x2, unsigned, max, max, u32)
1385
+ OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, uint32x2, unsigned, min, min, u32)
1386
+ OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_int32x4, int32x2, int, sum, add, s32)
1387
+ OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_int32x4, int32x2, int, max, max, s32)
1388
+ OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_int32x4, int32x2, int, min, min, s32)
1389
+ OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float32x2, float, sum, add, f32)
1390
+ OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float32x2, float, max, max, f32)
1391
+ OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float32x2, float, min, min, f32)
1392
+
1393
+ inline uint64 v_reduce_sum(const v_uint64x2& a)
1394
+ {
1395
+ #if CV_NEON_AARCH64
1396
+ return vaddvq_u64(a.val);
1397
+ #else // #if CV_NEON_AARCH64
1398
+ return vget_lane_u64(vadd_u64(vget_low_u64(a.val), vget_high_u64(a.val)),0);
1399
+ #endif // #if CV_NEON_AARCH64
1400
+ }
1401
+ inline int64 v_reduce_sum(const v_int64x2& a)
1402
+ {
1403
+ #if CV_NEON_AARCH64
1404
+ return vaddvq_s64(a.val);
1405
+ #else // #if CV_NEON_AARCH64
1406
+ return vget_lane_s64(vadd_s64(vget_low_s64(a.val), vget_high_s64(a.val)),0);
1407
+ #endif // #if CV_NEON_AARCH64
1408
+ }
1409
+ #if CV_SIMD128_64F
1410
+ inline double v_reduce_sum(const v_float64x2& a)
1411
+ {
1412
+ return vaddvq_f64(a.val);
1413
+ }
1414
+ #endif
1415
+
1416
+ inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b,
1417
+ const v_float32x4& c, const v_float32x4& d)
1418
+ {
1419
+ #if CV_NEON_AARCH64
1420
+ float32x4_t ab = vpaddq_f32(a.val, b.val); // a0+a1 a2+a3 b0+b1 b2+b3
1421
+ float32x4_t cd = vpaddq_f32(c.val, d.val); // c0+c1 d0+d1 c2+c3 d2+d3
1422
+ return v_float32x4(vpaddq_f32(ab, cd)); // sumA sumB sumC sumD
1423
+ #else // #if CV_NEON_AARCH64
1424
+ float32x4x2_t ab = vtrnq_f32(a.val, b.val);
1425
+ float32x4x2_t cd = vtrnq_f32(c.val, d.val);
1426
+
1427
+ float32x4_t u0 = vaddq_f32(ab.val[0], ab.val[1]); // a0+a1 b0+b1 a2+a3 b2+b3
1428
+ float32x4_t u1 = vaddq_f32(cd.val[0], cd.val[1]); // c0+c1 d0+d1 c2+c3 d2+d3
1429
+
1430
+ float32x4_t v0 = vcombine_f32(vget_low_f32(u0), vget_low_f32(u1));
1431
+ float32x4_t v1 = vcombine_f32(vget_high_f32(u0), vget_high_f32(u1));
1432
+
1433
+ return v_float32x4(vaddq_f32(v0, v1));
1434
+ #endif // #if CV_NEON_AARCH64
1435
+ }
1436
+
1437
+ inline unsigned v_reduce_sad(const v_uint8x16& a, const v_uint8x16& b)
1438
+ {
1439
+ #if CV_NEON_AARCH64
1440
+ uint8x16_t t0 = vabdq_u8(a.val, b.val);
1441
+ uint16_t t1 = vaddlvq_u8(t0);
1442
+ return t1;
1443
+ #else // #if CV_NEON_AARCH64
1444
+ uint32x4_t t0 = vpaddlq_u16(vpaddlq_u8(vabdq_u8(a.val, b.val)));
1445
+ uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0));
1446
+ return vget_lane_u32(vpadd_u32(t1, t1), 0);
1447
+ #endif // #if CV_NEON_AARCH64
1448
+ }
1449
+ inline unsigned v_reduce_sad(const v_int8x16& a, const v_int8x16& b)
1450
+ {
1451
+ #if CV_NEON_AARCH64
1452
+ uint8x16_t t0 = vreinterpretq_u8_s8(vabdq_s8(a.val, b.val));
1453
+ uint16_t t1 = vaddlvq_u8(t0);
1454
+ return t1;
1455
+ #else // #if CV_NEON_AARCH64
1456
+ uint32x4_t t0 = vpaddlq_u16(vpaddlq_u8(vreinterpretq_u8_s8(vabdq_s8(a.val, b.val))));
1457
+ uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0));
1458
+ return vget_lane_u32(vpadd_u32(t1, t1), 0);
1459
+ #endif // #if CV_NEON_AARCH64
1460
+ }
1461
+ inline unsigned v_reduce_sad(const v_uint16x8& a, const v_uint16x8& b)
1462
+ {
1463
+ #if CV_NEON_AARCH64
1464
+ uint16x8_t t0 = vabdq_u16(a.val, b.val);
1465
+ uint32_t t1 = vaddlvq_u16(t0);
1466
+ return t1;
1467
+ #else // #if CV_NEON_AARCH64
1468
+ uint32x4_t t0 = vpaddlq_u16(vabdq_u16(a.val, b.val));
1469
+ uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0));
1470
+ return vget_lane_u32(vpadd_u32(t1, t1), 0);
1471
+ #endif // #if CV_NEON_AARCH64
1472
+ }
1473
+ inline unsigned v_reduce_sad(const v_int16x8& a, const v_int16x8& b)
1474
+ {
1475
+ #if CV_NEON_AARCH64
1476
+ uint16x8_t t0 = vreinterpretq_u16_s16(vabdq_s16(a.val, b.val));
1477
+ uint32_t t1 = vaddlvq_u16(t0);
1478
+ return t1;
1479
+ #else // #if CV_NEON_AARCH64
1480
+ uint32x4_t t0 = vpaddlq_u16(vreinterpretq_u16_s16(vabdq_s16(a.val, b.val)));
1481
+ uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0));
1482
+ return vget_lane_u32(vpadd_u32(t1, t1), 0);
1483
+ #endif // #if CV_NEON_AARCH64
1484
+ }
1485
+ inline unsigned v_reduce_sad(const v_uint32x4& a, const v_uint32x4& b)
1486
+ {
1487
+ #if CV_NEON_AARCH64
1488
+ uint32x4_t t0 = vabdq_u32(a.val, b.val);
1489
+ uint32_t t1 = vaddvq_u32(t0);
1490
+ return t1;
1491
+ #else // #if CV_NEON_AARCH64
1492
+ uint32x4_t t0 = vabdq_u32(a.val, b.val);
1493
+ uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0));
1494
+ return vget_lane_u32(vpadd_u32(t1, t1), 0);
1495
+ #endif // #if CV_NEON_AARCH64
1496
+ }
1497
+ inline unsigned v_reduce_sad(const v_int32x4& a, const v_int32x4& b)
1498
+ {
1499
+ #if CV_NEON_AARCH64
1500
+ uint32x4_t t0 = vreinterpretq_u32_s32(vabdq_s32(a.val, b.val));
1501
+ uint32_t t1 = vaddvq_u32(t0);
1502
+ return t1;
1503
+ #else // #if CV_NEON_AARCH64
1504
+ uint32x4_t t0 = vreinterpretq_u32_s32(vabdq_s32(a.val, b.val));
1505
+ uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0));
1506
+ return vget_lane_u32(vpadd_u32(t1, t1), 0);
1507
+ #endif // #if CV_NEON_AARCH64
1508
+ }
1509
+ inline float v_reduce_sad(const v_float32x4& a, const v_float32x4& b)
1510
+ {
1511
+ #if CV_NEON_AARCH64
1512
+ float32x4_t t0 = vabdq_f32(a.val, b.val);
1513
+ return vaddvq_f32(t0);
1514
+ #else // #if CV_NEON_AARCH64
1515
+ float32x4_t t0 = vabdq_f32(a.val, b.val);
1516
+ float32x2_t t1 = vpadd_f32(vget_low_f32(t0), vget_high_f32(t0));
1517
+ return vget_lane_f32(vpadd_f32(t1, t1), 0);
1518
+ #endif // #if CV_NEON_AARCH64
1519
+ }
1520
+
1521
+ inline v_uint8x16 v_popcount(const v_uint8x16& a)
1522
+ { return v_uint8x16(vcntq_u8(a.val)); }
1523
+ inline v_uint8x16 v_popcount(const v_int8x16& a)
1524
+ { return v_uint8x16(vcntq_u8(vreinterpretq_u8_s8(a.val))); }
1525
+ inline v_uint16x8 v_popcount(const v_uint16x8& a)
1526
+ { return v_uint16x8(vpaddlq_u8(vcntq_u8(vreinterpretq_u8_u16(a.val)))); }
1527
+ inline v_uint16x8 v_popcount(const v_int16x8& a)
1528
+ { return v_uint16x8(vpaddlq_u8(vcntq_u8(vreinterpretq_u8_s16(a.val)))); }
1529
+ inline v_uint32x4 v_popcount(const v_uint32x4& a)
1530
+ { return v_uint32x4(vpaddlq_u16(vpaddlq_u8(vcntq_u8(vreinterpretq_u8_u32(a.val))))); }
1531
+ inline v_uint32x4 v_popcount(const v_int32x4& a)
1532
+ { return v_uint32x4(vpaddlq_u16(vpaddlq_u8(vcntq_u8(vreinterpretq_u8_s32(a.val))))); }
1533
+ inline v_uint64x2 v_popcount(const v_uint64x2& a)
1534
+ { return v_uint64x2(vpaddlq_u32(vpaddlq_u16(vpaddlq_u8(vcntq_u8(vreinterpretq_u8_u64(a.val)))))); }
1535
+ inline v_uint64x2 v_popcount(const v_int64x2& a)
1536
+ { return v_uint64x2(vpaddlq_u32(vpaddlq_u16(vpaddlq_u8(vcntq_u8(vreinterpretq_u8_s64(a.val)))))); }
1537
+
1538
+ inline int v_signmask(const v_uint8x16& a)
1539
+ {
1540
+ #if CV_NEON_AARCH64
1541
+ const int8x16_t signPosition = {0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7};
1542
+ const uint8x16_t byteOrder = {0,8,1,9,2,10,3,11,4,12,5,13,6,14,7,15};
1543
+ uint8x16_t v0 = vshlq_u8(vshrq_n_u8(a.val, 7), signPosition);
1544
+ uint8x16_t v1 = vqtbl1q_u8(v0, byteOrder);
1545
+ uint32_t t0 = vaddlvq_u16(vreinterpretq_u16_u8(v1));
1546
+ return t0;
1547
+ #else // #if CV_NEON_AARCH64
1548
+ int8x8_t m0 = vcreate_s8(CV_BIG_UINT(0x0706050403020100));
1549
+ uint8x16_t v0 = vshlq_u8(vshrq_n_u8(a.val, 7), vcombine_s8(m0, m0));
1550
+ uint64x2_t v1 = vpaddlq_u32(vpaddlq_u16(vpaddlq_u8(v0)));
1551
+ return (int)vgetq_lane_u64(v1, 0) + ((int)vgetq_lane_u64(v1, 1) << 8);
1552
+ #endif // #if CV_NEON_AARCH64
1553
+ }
1554
+
1555
+ inline int v_signmask(const v_int8x16& a)
1556
+ { return v_signmask(v_reinterpret_as_u8(a)); }
1557
+
1558
+ inline int v_signmask(const v_uint16x8& a)
1559
+ {
1560
+ #if CV_NEON_AARCH64
1561
+ const int16x8_t signPosition = {0,1,2,3,4,5,6,7};
1562
+ uint16x8_t v0 = vshlq_u16(vshrq_n_u16(a.val, 15), signPosition);
1563
+ uint32_t t0 = vaddlvq_u16(v0);
1564
+ return t0;
1565
+ #else // #if CV_NEON_AARCH64
1566
+ int16x4_t m0 = vcreate_s16(CV_BIG_UINT(0x0003000200010000));
1567
+ uint16x8_t v0 = vshlq_u16(vshrq_n_u16(a.val, 15), vcombine_s16(m0, m0));
1568
+ uint64x2_t v1 = vpaddlq_u32(vpaddlq_u16(v0));
1569
+ return (int)vgetq_lane_u64(v1, 0) + ((int)vgetq_lane_u64(v1, 1) << 4);
1570
+ #endif // #if CV_NEON_AARCH64
1571
+ }
1572
+ inline int v_signmask(const v_int16x8& a)
1573
+ { return v_signmask(v_reinterpret_as_u16(a)); }
1574
+
1575
+ inline int v_signmask(const v_uint32x4& a)
1576
+ {
1577
+ #if CV_NEON_AARCH64
1578
+ const int32x4_t signPosition = {0,1,2,3};
1579
+ uint32x4_t v0 = vshlq_u32(vshrq_n_u32(a.val, 31), signPosition);
1580
+ uint32_t t0 = vaddvq_u32(v0);
1581
+ return t0;
1582
+ #else // #if CV_NEON_AARCH64
1583
+ int32x2_t m0 = vcreate_s32(CV_BIG_UINT(0x0000000100000000));
1584
+ uint32x4_t v0 = vshlq_u32(vshrq_n_u32(a.val, 31), vcombine_s32(m0, m0));
1585
+ uint64x2_t v1 = vpaddlq_u32(v0);
1586
+ return (int)vgetq_lane_u64(v1, 0) + ((int)vgetq_lane_u64(v1, 1) << 2);
1587
+ #endif // #if CV_NEON_AARCH64
1588
+ }
1589
+ inline int v_signmask(const v_int32x4& a)
1590
+ { return v_signmask(v_reinterpret_as_u32(a)); }
1591
+ inline int v_signmask(const v_float32x4& a)
1592
+ { return v_signmask(v_reinterpret_as_u32(a)); }
1593
+ inline int v_signmask(const v_uint64x2& a)
1594
+ {
1595
+ #if CV_NEON_AARCH64
1596
+ const int64x2_t signPosition = {0,1};
1597
+ uint64x2_t v0 = vshlq_u64(vshrq_n_u64(a.val, 63), signPosition);
1598
+ uint64_t t0 = vaddvq_u64(v0);
1599
+ return t0;
1600
+ #else // #if CV_NEON_AARCH64
1601
+ int64x1_t m0 = vdup_n_s64(0);
1602
+ uint64x2_t v0 = vshlq_u64(vshrq_n_u64(a.val, 63), vcombine_s64(m0, m0));
1603
+ return (int)vgetq_lane_u64(v0, 0) + ((int)vgetq_lane_u64(v0, 1) << 1);
1604
+ #endif // #if CV_NEON_AARCH64
1605
+ }
1606
+ inline int v_signmask(const v_int64x2& a)
1607
+ { return v_signmask(v_reinterpret_as_u64(a)); }
1608
+ #if CV_SIMD128_64F
1609
+ inline int v_signmask(const v_float64x2& a)
1610
+ { return v_signmask(v_reinterpret_as_u64(a)); }
1611
+ #endif
1612
+
1613
+ inline int v_scan_forward(const v_int8x16& a) { return trailingZeros32(v_signmask(a)); }
1614
+ inline int v_scan_forward(const v_uint8x16& a) { return trailingZeros32(v_signmask(a)); }
1615
+ inline int v_scan_forward(const v_int16x8& a) { return trailingZeros32(v_signmask(a)); }
1616
+ inline int v_scan_forward(const v_uint16x8& a) { return trailingZeros32(v_signmask(a)); }
1617
+ inline int v_scan_forward(const v_int32x4& a) { return trailingZeros32(v_signmask(a)); }
1618
+ inline int v_scan_forward(const v_uint32x4& a) { return trailingZeros32(v_signmask(a)); }
1619
+ inline int v_scan_forward(const v_float32x4& a) { return trailingZeros32(v_signmask(a)); }
1620
+ inline int v_scan_forward(const v_int64x2& a) { return trailingZeros32(v_signmask(a)); }
1621
+ inline int v_scan_forward(const v_uint64x2& a) { return trailingZeros32(v_signmask(a)); }
1622
+ #if CV_SIMD128_64F
1623
+ inline int v_scan_forward(const v_float64x2& a) { return trailingZeros32(v_signmask(a)); }
1624
+ #endif
1625
+
1626
+ #if CV_NEON_AARCH64
1627
+ #define OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(_Tpvec, suffix, shift) \
1628
+ inline bool v_check_all(const v_##_Tpvec& a) \
1629
+ { \
1630
+ return (vminvq_##suffix(a.val) >> shift) != 0; \
1631
+ } \
1632
+ inline bool v_check_any(const v_##_Tpvec& a) \
1633
+ { \
1634
+ return (vmaxvq_##suffix(a.val) >> shift) != 0; \
1635
+ }
1636
+ #else // #if CV_NEON_AARCH64
1637
+ #define OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(_Tpvec, suffix, shift) \
1638
+ inline bool v_check_all(const v_##_Tpvec& a) \
1639
+ { \
1640
+ _Tpvec##_t v0 = vshrq_n_##suffix(vmvnq_##suffix(a.val), shift); \
1641
+ uint64x2_t v1 = vreinterpretq_u64_##suffix(v0); \
1642
+ return (vgetq_lane_u64(v1, 0) | vgetq_lane_u64(v1, 1)) == 0; \
1643
+ } \
1644
+ inline bool v_check_any(const v_##_Tpvec& a) \
1645
+ { \
1646
+ _Tpvec##_t v0 = vshrq_n_##suffix(a.val, shift); \
1647
+ uint64x2_t v1 = vreinterpretq_u64_##suffix(v0); \
1648
+ return (vgetq_lane_u64(v1, 0) | vgetq_lane_u64(v1, 1)) != 0; \
1649
+ }
1650
+ #endif // #if CV_NEON_AARCH64
1651
+
1652
+ OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(uint8x16, u8, 7)
1653
+ OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(uint16x8, u16, 15)
1654
+ OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(uint32x4, u32, 31)
1655
+
1656
+ inline bool v_check_all(const v_uint64x2& a)
1657
+ {
1658
+ uint64x2_t v0 = vshrq_n_u64(a.val, 63);
1659
+ return (vgetq_lane_u64(v0, 0) & vgetq_lane_u64(v0, 1)) == 1;
1660
+ }
1661
+ inline bool v_check_any(const v_uint64x2& a)
1662
+ {
1663
+ uint64x2_t v0 = vshrq_n_u64(a.val, 63);
1664
+ return (vgetq_lane_u64(v0, 0) | vgetq_lane_u64(v0, 1)) != 0;
1665
+ }
1666
+
1667
+ inline bool v_check_all(const v_int8x16& a)
1668
+ { return v_check_all(v_reinterpret_as_u8(a)); }
1669
+ inline bool v_check_all(const v_int16x8& a)
1670
+ { return v_check_all(v_reinterpret_as_u16(a)); }
1671
+ inline bool v_check_all(const v_int32x4& a)
1672
+ { return v_check_all(v_reinterpret_as_u32(a)); }
1673
+ inline bool v_check_all(const v_float32x4& a)
1674
+ { return v_check_all(v_reinterpret_as_u32(a)); }
1675
+
1676
+ inline bool v_check_any(const v_int8x16& a)
1677
+ { return v_check_any(v_reinterpret_as_u8(a)); }
1678
+ inline bool v_check_any(const v_int16x8& a)
1679
+ { return v_check_any(v_reinterpret_as_u16(a)); }
1680
+ inline bool v_check_any(const v_int32x4& a)
1681
+ { return v_check_any(v_reinterpret_as_u32(a)); }
1682
+ inline bool v_check_any(const v_float32x4& a)
1683
+ { return v_check_any(v_reinterpret_as_u32(a)); }
1684
+
1685
+ inline bool v_check_all(const v_int64x2& a)
1686
+ { return v_check_all(v_reinterpret_as_u64(a)); }
1687
+ inline bool v_check_any(const v_int64x2& a)
1688
+ { return v_check_any(v_reinterpret_as_u64(a)); }
1689
+ #if CV_SIMD128_64F
1690
+ inline bool v_check_all(const v_float64x2& a)
1691
+ { return v_check_all(v_reinterpret_as_u64(a)); }
1692
+ inline bool v_check_any(const v_float64x2& a)
1693
+ { return v_check_any(v_reinterpret_as_u64(a)); }
1694
+ #endif
1695
+
1696
+ #define OPENCV_HAL_IMPL_NEON_SELECT(_Tpvec, suffix, usuffix) \
1697
+ inline _Tpvec v_select(const _Tpvec& mask, const _Tpvec& a, const _Tpvec& b) \
1698
+ { \
1699
+ return _Tpvec(vbslq_##suffix(vreinterpretq_##usuffix##_##suffix(mask.val), a.val, b.val)); \
1700
+ }
1701
+
1702
+ OPENCV_HAL_IMPL_NEON_SELECT(v_uint8x16, u8, u8)
1703
+ OPENCV_HAL_IMPL_NEON_SELECT(v_int8x16, s8, u8)
1704
+ OPENCV_HAL_IMPL_NEON_SELECT(v_uint16x8, u16, u16)
1705
+ OPENCV_HAL_IMPL_NEON_SELECT(v_int16x8, s16, u16)
1706
+ OPENCV_HAL_IMPL_NEON_SELECT(v_uint32x4, u32, u32)
1707
+ OPENCV_HAL_IMPL_NEON_SELECT(v_int32x4, s32, u32)
1708
+ OPENCV_HAL_IMPL_NEON_SELECT(v_float32x4, f32, u32)
1709
+ #if CV_SIMD128_64F
1710
+ OPENCV_HAL_IMPL_NEON_SELECT(v_float64x2, f64, u64)
1711
+ #endif
1712
+
1713
+ #if CV_NEON_AARCH64
1714
+ #define OPENCV_HAL_IMPL_NEON_EXPAND(_Tpvec, _Tpwvec, _Tp, suffix) \
1715
+ inline void v_expand(const _Tpvec& a, _Tpwvec& b0, _Tpwvec& b1) \
1716
+ { \
1717
+ b0.val = vmovl_##suffix(vget_low_##suffix(a.val)); \
1718
+ b1.val = vmovl_high_##suffix(a.val); \
1719
+ } \
1720
+ inline _Tpwvec v_expand_low(const _Tpvec& a) \
1721
+ { \
1722
+ return _Tpwvec(vmovl_##suffix(vget_low_##suffix(a.val))); \
1723
+ } \
1724
+ inline _Tpwvec v_expand_high(const _Tpvec& a) \
1725
+ { \
1726
+ return _Tpwvec(vmovl_high_##suffix(a.val)); \
1727
+ } \
1728
+ inline _Tpwvec v_load_expand(const _Tp* ptr) \
1729
+ { \
1730
+ return _Tpwvec(vmovl_##suffix(vld1_##suffix(ptr))); \
1731
+ }
1732
+ #else
1733
+ #define OPENCV_HAL_IMPL_NEON_EXPAND(_Tpvec, _Tpwvec, _Tp, suffix) \
1734
+ inline void v_expand(const _Tpvec& a, _Tpwvec& b0, _Tpwvec& b1) \
1735
+ { \
1736
+ b0.val = vmovl_##suffix(vget_low_##suffix(a.val)); \
1737
+ b1.val = vmovl_##suffix(vget_high_##suffix(a.val)); \
1738
+ } \
1739
+ inline _Tpwvec v_expand_low(const _Tpvec& a) \
1740
+ { \
1741
+ return _Tpwvec(vmovl_##suffix(vget_low_##suffix(a.val))); \
1742
+ } \
1743
+ inline _Tpwvec v_expand_high(const _Tpvec& a) \
1744
+ { \
1745
+ return _Tpwvec(vmovl_##suffix(vget_high_##suffix(a.val))); \
1746
+ } \
1747
+ inline _Tpwvec v_load_expand(const _Tp* ptr) \
1748
+ { \
1749
+ return _Tpwvec(vmovl_##suffix(vld1_##suffix(ptr))); \
1750
+ }
1751
+ #endif
1752
+
1753
+ OPENCV_HAL_IMPL_NEON_EXPAND(v_uint8x16, v_uint16x8, uchar, u8)
1754
+ OPENCV_HAL_IMPL_NEON_EXPAND(v_int8x16, v_int16x8, schar, s8)
1755
+ OPENCV_HAL_IMPL_NEON_EXPAND(v_uint16x8, v_uint32x4, ushort, u16)
1756
+ OPENCV_HAL_IMPL_NEON_EXPAND(v_int16x8, v_int32x4, short, s16)
1757
+ OPENCV_HAL_IMPL_NEON_EXPAND(v_uint32x4, v_uint64x2, uint, u32)
1758
+ OPENCV_HAL_IMPL_NEON_EXPAND(v_int32x4, v_int64x2, int, s32)
1759
+
1760
+ inline v_uint32x4 v_load_expand_q(const uchar* ptr)
1761
+ {
1762
+ typedef unsigned int CV_DECL_ALIGNED(1) unaligned_uint;
1763
+ uint8x8_t v0 = vcreate_u8(*(unaligned_uint*)ptr);
1764
+ uint16x4_t v1 = vget_low_u16(vmovl_u8(v0));
1765
+ return v_uint32x4(vmovl_u16(v1));
1766
+ }
1767
+
1768
+ inline v_int32x4 v_load_expand_q(const schar* ptr)
1769
+ {
1770
+ typedef unsigned int CV_DECL_ALIGNED(1) unaligned_uint;
1771
+ int8x8_t v0 = vcreate_s8(*(unaligned_uint*)ptr);
1772
+ int16x4_t v1 = vget_low_s16(vmovl_s8(v0));
1773
+ return v_int32x4(vmovl_s16(v1));
1774
+ }
1775
+
1776
+ #if defined(__aarch64__) || defined(_M_ARM64)
1777
+ #define OPENCV_HAL_IMPL_NEON_UNPACKS(_Tpvec, suffix) \
1778
+ inline void v_zip(const v_##_Tpvec& a0, const v_##_Tpvec& a1, v_##_Tpvec& b0, v_##_Tpvec& b1) \
1779
+ { \
1780
+ b0.val = vzip1q_##suffix(a0.val, a1.val); \
1781
+ b1.val = vzip2q_##suffix(a0.val, a1.val); \
1782
+ } \
1783
+ inline v_##_Tpvec v_combine_low(const v_##_Tpvec& a, const v_##_Tpvec& b) \
1784
+ { \
1785
+ return v_##_Tpvec(vcombine_##suffix(vget_low_##suffix(a.val), vget_low_##suffix(b.val))); \
1786
+ } \
1787
+ inline v_##_Tpvec v_combine_high(const v_##_Tpvec& a, const v_##_Tpvec& b) \
1788
+ { \
1789
+ return v_##_Tpvec(vcombine_##suffix(vget_high_##suffix(a.val), vget_high_##suffix(b.val))); \
1790
+ } \
1791
+ inline void v_recombine(const v_##_Tpvec& a, const v_##_Tpvec& b, v_##_Tpvec& c, v_##_Tpvec& d) \
1792
+ { \
1793
+ c.val = vcombine_##suffix(vget_low_##suffix(a.val), vget_low_##suffix(b.val)); \
1794
+ d.val = vcombine_##suffix(vget_high_##suffix(a.val), vget_high_##suffix(b.val)); \
1795
+ }
1796
+ #else
1797
+ #define OPENCV_HAL_IMPL_NEON_UNPACKS(_Tpvec, suffix) \
1798
+ inline void v_zip(const v_##_Tpvec& a0, const v_##_Tpvec& a1, v_##_Tpvec& b0, v_##_Tpvec& b1) \
1799
+ { \
1800
+ _Tpvec##x2_t p = vzipq_##suffix(a0.val, a1.val); \
1801
+ b0.val = p.val[0]; \
1802
+ b1.val = p.val[1]; \
1803
+ } \
1804
+ inline v_##_Tpvec v_combine_low(const v_##_Tpvec& a, const v_##_Tpvec& b) \
1805
+ { \
1806
+ return v_##_Tpvec(vcombine_##suffix(vget_low_##suffix(a.val), vget_low_##suffix(b.val))); \
1807
+ } \
1808
+ inline v_##_Tpvec v_combine_high(const v_##_Tpvec& a, const v_##_Tpvec& b) \
1809
+ { \
1810
+ return v_##_Tpvec(vcombine_##suffix(vget_high_##suffix(a.val), vget_high_##suffix(b.val))); \
1811
+ } \
1812
+ inline void v_recombine(const v_##_Tpvec& a, const v_##_Tpvec& b, v_##_Tpvec& c, v_##_Tpvec& d) \
1813
+ { \
1814
+ c.val = vcombine_##suffix(vget_low_##suffix(a.val), vget_low_##suffix(b.val)); \
1815
+ d.val = vcombine_##suffix(vget_high_##suffix(a.val), vget_high_##suffix(b.val)); \
1816
+ }
1817
+ #endif
1818
+
1819
+ OPENCV_HAL_IMPL_NEON_UNPACKS(uint8x16, u8)
1820
+ OPENCV_HAL_IMPL_NEON_UNPACKS(int8x16, s8)
1821
+ OPENCV_HAL_IMPL_NEON_UNPACKS(uint16x8, u16)
1822
+ OPENCV_HAL_IMPL_NEON_UNPACKS(int16x8, s16)
1823
+ OPENCV_HAL_IMPL_NEON_UNPACKS(uint32x4, u32)
1824
+ OPENCV_HAL_IMPL_NEON_UNPACKS(int32x4, s32)
1825
+ OPENCV_HAL_IMPL_NEON_UNPACKS(float32x4, f32)
1826
+ #if CV_SIMD128_64F
1827
+ OPENCV_HAL_IMPL_NEON_UNPACKS(float64x2, f64)
1828
+ #endif
1829
+
1830
+ inline v_uint8x16 v_reverse(const v_uint8x16 &a)
1831
+ {
1832
+ uint8x16_t vec = vrev64q_u8(a.val);
1833
+ return v_uint8x16(vextq_u8(vec, vec, 8));
1834
+ }
1835
+
1836
+ inline v_int8x16 v_reverse(const v_int8x16 &a)
1837
+ { return v_reinterpret_as_s8(v_reverse(v_reinterpret_as_u8(a))); }
1838
+
1839
+ inline v_uint16x8 v_reverse(const v_uint16x8 &a)
1840
+ {
1841
+ uint16x8_t vec = vrev64q_u16(a.val);
1842
+ return v_uint16x8(vextq_u16(vec, vec, 4));
1843
+ }
1844
+
1845
+ inline v_int16x8 v_reverse(const v_int16x8 &a)
1846
+ { return v_reinterpret_as_s16(v_reverse(v_reinterpret_as_u16(a))); }
1847
+
1848
+ inline v_uint32x4 v_reverse(const v_uint32x4 &a)
1849
+ {
1850
+ uint32x4_t vec = vrev64q_u32(a.val);
1851
+ return v_uint32x4(vextq_u32(vec, vec, 2));
1852
+ }
1853
+
1854
+ inline v_int32x4 v_reverse(const v_int32x4 &a)
1855
+ { return v_reinterpret_as_s32(v_reverse(v_reinterpret_as_u32(a))); }
1856
+
1857
+ inline v_float32x4 v_reverse(const v_float32x4 &a)
1858
+ { return v_reinterpret_as_f32(v_reverse(v_reinterpret_as_u32(a))); }
1859
+
1860
+ inline v_uint64x2 v_reverse(const v_uint64x2 &a)
1861
+ {
1862
+ uint64x2_t vec = a.val;
1863
+ uint64x1_t vec_lo = vget_low_u64(vec);
1864
+ uint64x1_t vec_hi = vget_high_u64(vec);
1865
+ return v_uint64x2(vcombine_u64(vec_hi, vec_lo));
1866
+ }
1867
+
1868
+ inline v_int64x2 v_reverse(const v_int64x2 &a)
1869
+ { return v_reinterpret_as_s64(v_reverse(v_reinterpret_as_u64(a))); }
1870
+
1871
+ #if CV_SIMD128_64F
1872
+ inline v_float64x2 v_reverse(const v_float64x2 &a)
1873
+ { return v_reinterpret_as_f64(v_reverse(v_reinterpret_as_u64(a))); }
1874
+ #endif
1875
+
1876
+ #define OPENCV_HAL_IMPL_NEON_EXTRACT(_Tpvec, suffix) \
1877
+ template <int s> \
1878
+ inline v_##_Tpvec v_extract(const v_##_Tpvec& a, const v_##_Tpvec& b) \
1879
+ { \
1880
+ return v_##_Tpvec(vextq_##suffix(a.val, b.val, s)); \
1881
+ }
1882
+
1883
+ OPENCV_HAL_IMPL_NEON_EXTRACT(uint8x16, u8)
1884
+ OPENCV_HAL_IMPL_NEON_EXTRACT(int8x16, s8)
1885
+ OPENCV_HAL_IMPL_NEON_EXTRACT(uint16x8, u16)
1886
+ OPENCV_HAL_IMPL_NEON_EXTRACT(int16x8, s16)
1887
+ OPENCV_HAL_IMPL_NEON_EXTRACT(uint32x4, u32)
1888
+ OPENCV_HAL_IMPL_NEON_EXTRACT(int32x4, s32)
1889
+ OPENCV_HAL_IMPL_NEON_EXTRACT(uint64x2, u64)
1890
+ OPENCV_HAL_IMPL_NEON_EXTRACT(int64x2, s64)
1891
+ OPENCV_HAL_IMPL_NEON_EXTRACT(float32x4, f32)
1892
+ #if CV_SIMD128_64F
1893
+ OPENCV_HAL_IMPL_NEON_EXTRACT(float64x2, f64)
1894
+ #endif
1895
+
1896
+ #define OPENCV_HAL_IMPL_NEON_EXTRACT_N(_Tpvec, _Tp, suffix) \
1897
+ template<int i> inline _Tp v_extract_n(_Tpvec v) { return vgetq_lane_##suffix(v.val, i); }
1898
+
1899
+ OPENCV_HAL_IMPL_NEON_EXTRACT_N(v_uint8x16, uchar, u8)
1900
+ OPENCV_HAL_IMPL_NEON_EXTRACT_N(v_int8x16, schar, s8)
1901
+ OPENCV_HAL_IMPL_NEON_EXTRACT_N(v_uint16x8, ushort, u16)
1902
+ OPENCV_HAL_IMPL_NEON_EXTRACT_N(v_int16x8, short, s16)
1903
+ OPENCV_HAL_IMPL_NEON_EXTRACT_N(v_uint32x4, uint, u32)
1904
+ OPENCV_HAL_IMPL_NEON_EXTRACT_N(v_int32x4, int, s32)
1905
+ OPENCV_HAL_IMPL_NEON_EXTRACT_N(v_uint64x2, uint64, u64)
1906
+ OPENCV_HAL_IMPL_NEON_EXTRACT_N(v_int64x2, int64, s64)
1907
+ OPENCV_HAL_IMPL_NEON_EXTRACT_N(v_float32x4, float, f32)
1908
+ #if CV_SIMD128_64F
1909
+ OPENCV_HAL_IMPL_NEON_EXTRACT_N(v_float64x2, double, f64)
1910
+ #endif
1911
+
1912
+ #define OPENCV_HAL_IMPL_NEON_BROADCAST(_Tpvec, _Tp, suffix) \
1913
+ template<int i> inline _Tpvec v_broadcast_element(_Tpvec v) { _Tp t = v_extract_n<i>(v); return v_setall_##suffix(t); }
1914
+
1915
+ OPENCV_HAL_IMPL_NEON_BROADCAST(v_uint8x16, uchar, u8)
1916
+ OPENCV_HAL_IMPL_NEON_BROADCAST(v_int8x16, schar, s8)
1917
+ OPENCV_HAL_IMPL_NEON_BROADCAST(v_uint16x8, ushort, u16)
1918
+ OPENCV_HAL_IMPL_NEON_BROADCAST(v_int16x8, short, s16)
1919
+ OPENCV_HAL_IMPL_NEON_BROADCAST(v_uint32x4, uint, u32)
1920
+ OPENCV_HAL_IMPL_NEON_BROADCAST(v_int32x4, int, s32)
1921
+ OPENCV_HAL_IMPL_NEON_BROADCAST(v_uint64x2, uint64, u64)
1922
+ OPENCV_HAL_IMPL_NEON_BROADCAST(v_int64x2, int64, s64)
1923
+ OPENCV_HAL_IMPL_NEON_BROADCAST(v_float32x4, float, f32)
1924
+ #if CV_SIMD128_64F
1925
+ OPENCV_HAL_IMPL_NEON_BROADCAST(v_float64x2, double, f64)
1926
+ #endif
1927
+
1928
+ #if CV_SIMD128_64F
1929
+ inline v_int32x4 v_round(const v_float32x4& a)
1930
+ {
1931
+ float32x4_t a_ = a.val;
1932
+ int32x4_t result;
1933
+ #if defined _MSC_VER
1934
+ result = vcvtnq_s32_f32(a_);
1935
+ #else
1936
+ __asm__ ("fcvtns %0.4s, %1.4s"
1937
+ : "=w"(result)
1938
+ : "w"(a_)
1939
+ : /* No clobbers */);
1940
+ #endif
1941
+ return v_int32x4(result);
1942
+ }
1943
+ #else
1944
+ inline v_int32x4 v_round(const v_float32x4& a)
1945
+ {
1946
+ static const int32x4_t v_sign = vdupq_n_s32(1 << 31),
1947
+ v_05 = vreinterpretq_s32_f32(vdupq_n_f32(0.5f));
1948
+
1949
+ int32x4_t v_addition = vorrq_s32(v_05, vandq_s32(v_sign, vreinterpretq_s32_f32(a.val)));
1950
+ return v_int32x4(vcvtq_s32_f32(vaddq_f32(a.val, vreinterpretq_f32_s32(v_addition))));
1951
+ }
1952
+ #endif
1953
+ inline v_int32x4 v_floor(const v_float32x4& a)
1954
+ {
1955
+ int32x4_t a1 = vcvtq_s32_f32(a.val);
1956
+ uint32x4_t mask = vcgtq_f32(vcvtq_f32_s32(a1), a.val);
1957
+ return v_int32x4(vaddq_s32(a1, vreinterpretq_s32_u32(mask)));
1958
+ }
1959
+
1960
+ inline v_int32x4 v_ceil(const v_float32x4& a)
1961
+ {
1962
+ int32x4_t a1 = vcvtq_s32_f32(a.val);
1963
+ uint32x4_t mask = vcgtq_f32(a.val, vcvtq_f32_s32(a1));
1964
+ return v_int32x4(vsubq_s32(a1, vreinterpretq_s32_u32(mask)));
1965
+ }
1966
+
1967
+ inline v_int32x4 v_trunc(const v_float32x4& a)
1968
+ { return v_int32x4(vcvtq_s32_f32(a.val)); }
1969
+
1970
+ #if CV_SIMD128_64F
1971
+ inline v_int32x4 v_round(const v_float64x2& a)
1972
+ {
1973
+ static const int32x2_t zero = vdup_n_s32(0);
1974
+ return v_int32x4(vcombine_s32(vmovn_s64(vcvtaq_s64_f64(a.val)), zero));
1975
+ }
1976
+
1977
+ inline v_int32x4 v_round(const v_float64x2& a, const v_float64x2& b)
1978
+ {
1979
+ return v_int32x4(vcombine_s32(vmovn_s64(vcvtaq_s64_f64(a.val)), vmovn_s64(vcvtaq_s64_f64(b.val))));
1980
+ }
1981
+
1982
+ inline v_int32x4 v_floor(const v_float64x2& a)
1983
+ {
1984
+ static const int32x2_t zero = vdup_n_s32(0);
1985
+ int64x2_t a1 = vcvtq_s64_f64(a.val);
1986
+ uint64x2_t mask = vcgtq_f64(vcvtq_f64_s64(a1), a.val);
1987
+ a1 = vaddq_s64(a1, vreinterpretq_s64_u64(mask));
1988
+ return v_int32x4(vcombine_s32(vmovn_s64(a1), zero));
1989
+ }
1990
+
1991
+ inline v_int32x4 v_ceil(const v_float64x2& a)
1992
+ {
1993
+ static const int32x2_t zero = vdup_n_s32(0);
1994
+ int64x2_t a1 = vcvtq_s64_f64(a.val);
1995
+ uint64x2_t mask = vcgtq_f64(a.val, vcvtq_f64_s64(a1));
1996
+ a1 = vsubq_s64(a1, vreinterpretq_s64_u64(mask));
1997
+ return v_int32x4(vcombine_s32(vmovn_s64(a1), zero));
1998
+ }
1999
+
2000
+ inline v_int32x4 v_trunc(const v_float64x2& a)
2001
+ {
2002
+ static const int32x2_t zero = vdup_n_s32(0);
2003
+ return v_int32x4(vcombine_s32(vmovn_s64(vcvtaq_s64_f64(a.val)), zero));
2004
+ }
2005
+ #endif
2006
+
2007
+ #if CV_NEON_AARCH64
2008
+ #define OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(_Tpvec, suffix) \
2009
+ inline void v_transpose4x4(const v_##_Tpvec& a0, const v_##_Tpvec& a1, \
2010
+ const v_##_Tpvec& a2, const v_##_Tpvec& a3, \
2011
+ v_##_Tpvec& b0, v_##_Tpvec& b1, \
2012
+ v_##_Tpvec& b2, v_##_Tpvec& b3) \
2013
+ { \
2014
+ /* -- Pass 1: 64b transpose */ \
2015
+ _Tpvec##_t t0 = vreinterpretq_##suffix##32_##suffix##64( \
2016
+ vtrn1q_##suffix##64(vreinterpretq_##suffix##64_##suffix##32(a0.val), \
2017
+ vreinterpretq_##suffix##64_##suffix##32(a2.val))); \
2018
+ _Tpvec##_t t1 = vreinterpretq_##suffix##32_##suffix##64( \
2019
+ vtrn1q_##suffix##64(vreinterpretq_##suffix##64_##suffix##32(a1.val), \
2020
+ vreinterpretq_##suffix##64_##suffix##32(a3.val))); \
2021
+ _Tpvec##_t t2 = vreinterpretq_##suffix##32_##suffix##64( \
2022
+ vtrn2q_##suffix##64(vreinterpretq_##suffix##64_##suffix##32(a0.val), \
2023
+ vreinterpretq_##suffix##64_##suffix##32(a2.val))); \
2024
+ _Tpvec##_t t3 = vreinterpretq_##suffix##32_##suffix##64( \
2025
+ vtrn2q_##suffix##64(vreinterpretq_##suffix##64_##suffix##32(a1.val), \
2026
+ vreinterpretq_##suffix##64_##suffix##32(a3.val))); \
2027
+ /* -- Pass 2: 32b transpose */ \
2028
+ b0.val = vtrn1q_##suffix##32(t0, t1); \
2029
+ b1.val = vtrn2q_##suffix##32(t0, t1); \
2030
+ b2.val = vtrn1q_##suffix##32(t2, t3); \
2031
+ b3.val = vtrn2q_##suffix##32(t2, t3); \
2032
+ }
2033
+
2034
+ OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(uint32x4, u)
2035
+ OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(int32x4, s)
2036
+ OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(float32x4, f)
2037
+ #else // #if CV_NEON_AARCH64
2038
+ #define OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(_Tpvec, suffix) \
2039
+ inline void v_transpose4x4(const v_##_Tpvec& a0, const v_##_Tpvec& a1, \
2040
+ const v_##_Tpvec& a2, const v_##_Tpvec& a3, \
2041
+ v_##_Tpvec& b0, v_##_Tpvec& b1, \
2042
+ v_##_Tpvec& b2, v_##_Tpvec& b3) \
2043
+ { \
2044
+ /* m00 m01 m02 m03 */ \
2045
+ /* m10 m11 m12 m13 */ \
2046
+ /* m20 m21 m22 m23 */ \
2047
+ /* m30 m31 m32 m33 */ \
2048
+ _Tpvec##x2_t t0 = vtrnq_##suffix(a0.val, a1.val); \
2049
+ _Tpvec##x2_t t1 = vtrnq_##suffix(a2.val, a3.val); \
2050
+ /* m00 m10 m02 m12 */ \
2051
+ /* m01 m11 m03 m13 */ \
2052
+ /* m20 m30 m22 m32 */ \
2053
+ /* m21 m31 m23 m33 */ \
2054
+ b0.val = vcombine_##suffix(vget_low_##suffix(t0.val[0]), vget_low_##suffix(t1.val[0])); \
2055
+ b1.val = vcombine_##suffix(vget_low_##suffix(t0.val[1]), vget_low_##suffix(t1.val[1])); \
2056
+ b2.val = vcombine_##suffix(vget_high_##suffix(t0.val[0]), vget_high_##suffix(t1.val[0])); \
2057
+ b3.val = vcombine_##suffix(vget_high_##suffix(t0.val[1]), vget_high_##suffix(t1.val[1])); \
2058
+ }
2059
+
2060
+ OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(uint32x4, u32)
2061
+ OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(int32x4, s32)
2062
+ OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(float32x4, f32)
2063
+ #endif // #if CV_NEON_AARCH64
2064
+
2065
+ #define OPENCV_HAL_IMPL_NEON_INTERLEAVED(_Tpvec, _Tp, suffix) \
2066
+ inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec& a, v_##_Tpvec& b) \
2067
+ { \
2068
+ _Tpvec##x2_t v = vld2q_##suffix(ptr); \
2069
+ a.val = v.val[0]; \
2070
+ b.val = v.val[1]; \
2071
+ } \
2072
+ inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec& a, v_##_Tpvec& b, v_##_Tpvec& c) \
2073
+ { \
2074
+ _Tpvec##x3_t v = vld3q_##suffix(ptr); \
2075
+ a.val = v.val[0]; \
2076
+ b.val = v.val[1]; \
2077
+ c.val = v.val[2]; \
2078
+ } \
2079
+ inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec& a, v_##_Tpvec& b, \
2080
+ v_##_Tpvec& c, v_##_Tpvec& d) \
2081
+ { \
2082
+ _Tpvec##x4_t v = vld4q_##suffix(ptr); \
2083
+ a.val = v.val[0]; \
2084
+ b.val = v.val[1]; \
2085
+ c.val = v.val[2]; \
2086
+ d.val = v.val[3]; \
2087
+ } \
2088
+ inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec& a, const v_##_Tpvec& b, \
2089
+ hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \
2090
+ { \
2091
+ _Tpvec##x2_t v; \
2092
+ v.val[0] = a.val; \
2093
+ v.val[1] = b.val; \
2094
+ vst2q_##suffix(ptr, v); \
2095
+ } \
2096
+ inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec& a, const v_##_Tpvec& b, \
2097
+ const v_##_Tpvec& c, hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \
2098
+ { \
2099
+ _Tpvec##x3_t v; \
2100
+ v.val[0] = a.val; \
2101
+ v.val[1] = b.val; \
2102
+ v.val[2] = c.val; \
2103
+ vst3q_##suffix(ptr, v); \
2104
+ } \
2105
+ inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec& a, const v_##_Tpvec& b, \
2106
+ const v_##_Tpvec& c, const v_##_Tpvec& d, \
2107
+ hal::StoreMode /*mode*/=hal::STORE_UNALIGNED ) \
2108
+ { \
2109
+ _Tpvec##x4_t v; \
2110
+ v.val[0] = a.val; \
2111
+ v.val[1] = b.val; \
2112
+ v.val[2] = c.val; \
2113
+ v.val[3] = d.val; \
2114
+ vst4q_##suffix(ptr, v); \
2115
+ }
2116
+
2117
+ #define OPENCV_HAL_IMPL_NEON_INTERLEAVED_INT64(tp, suffix) \
2118
+ inline void v_load_deinterleave( const tp* ptr, v_##tp##x2& a, v_##tp##x2& b ) \
2119
+ { \
2120
+ tp##x1_t a0 = vld1_##suffix(ptr); \
2121
+ tp##x1_t b0 = vld1_##suffix(ptr + 1); \
2122
+ tp##x1_t a1 = vld1_##suffix(ptr + 2); \
2123
+ tp##x1_t b1 = vld1_##suffix(ptr + 3); \
2124
+ a = v_##tp##x2(vcombine_##suffix(a0, a1)); \
2125
+ b = v_##tp##x2(vcombine_##suffix(b0, b1)); \
2126
+ } \
2127
+ \
2128
+ inline void v_load_deinterleave( const tp* ptr, v_##tp##x2& a, \
2129
+ v_##tp##x2& b, v_##tp##x2& c ) \
2130
+ { \
2131
+ tp##x1_t a0 = vld1_##suffix(ptr); \
2132
+ tp##x1_t b0 = vld1_##suffix(ptr + 1); \
2133
+ tp##x1_t c0 = vld1_##suffix(ptr + 2); \
2134
+ tp##x1_t a1 = vld1_##suffix(ptr + 3); \
2135
+ tp##x1_t b1 = vld1_##suffix(ptr + 4); \
2136
+ tp##x1_t c1 = vld1_##suffix(ptr + 5); \
2137
+ a = v_##tp##x2(vcombine_##suffix(a0, a1)); \
2138
+ b = v_##tp##x2(vcombine_##suffix(b0, b1)); \
2139
+ c = v_##tp##x2(vcombine_##suffix(c0, c1)); \
2140
+ } \
2141
+ \
2142
+ inline void v_load_deinterleave( const tp* ptr, v_##tp##x2& a, v_##tp##x2& b, \
2143
+ v_##tp##x2& c, v_##tp##x2& d ) \
2144
+ { \
2145
+ tp##x1_t a0 = vld1_##suffix(ptr); \
2146
+ tp##x1_t b0 = vld1_##suffix(ptr + 1); \
2147
+ tp##x1_t c0 = vld1_##suffix(ptr + 2); \
2148
+ tp##x1_t d0 = vld1_##suffix(ptr + 3); \
2149
+ tp##x1_t a1 = vld1_##suffix(ptr + 4); \
2150
+ tp##x1_t b1 = vld1_##suffix(ptr + 5); \
2151
+ tp##x1_t c1 = vld1_##suffix(ptr + 6); \
2152
+ tp##x1_t d1 = vld1_##suffix(ptr + 7); \
2153
+ a = v_##tp##x2(vcombine_##suffix(a0, a1)); \
2154
+ b = v_##tp##x2(vcombine_##suffix(b0, b1)); \
2155
+ c = v_##tp##x2(vcombine_##suffix(c0, c1)); \
2156
+ d = v_##tp##x2(vcombine_##suffix(d0, d1)); \
2157
+ } \
2158
+ \
2159
+ inline void v_store_interleave( tp* ptr, const v_##tp##x2& a, const v_##tp##x2& b, \
2160
+ hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \
2161
+ { \
2162
+ vst1_##suffix(ptr, vget_low_##suffix(a.val)); \
2163
+ vst1_##suffix(ptr + 1, vget_low_##suffix(b.val)); \
2164
+ vst1_##suffix(ptr + 2, vget_high_##suffix(a.val)); \
2165
+ vst1_##suffix(ptr + 3, vget_high_##suffix(b.val)); \
2166
+ } \
2167
+ \
2168
+ inline void v_store_interleave( tp* ptr, const v_##tp##x2& a, \
2169
+ const v_##tp##x2& b, const v_##tp##x2& c, \
2170
+ hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \
2171
+ { \
2172
+ vst1_##suffix(ptr, vget_low_##suffix(a.val)); \
2173
+ vst1_##suffix(ptr + 1, vget_low_##suffix(b.val)); \
2174
+ vst1_##suffix(ptr + 2, vget_low_##suffix(c.val)); \
2175
+ vst1_##suffix(ptr + 3, vget_high_##suffix(a.val)); \
2176
+ vst1_##suffix(ptr + 4, vget_high_##suffix(b.val)); \
2177
+ vst1_##suffix(ptr + 5, vget_high_##suffix(c.val)); \
2178
+ } \
2179
+ \
2180
+ inline void v_store_interleave( tp* ptr, const v_##tp##x2& a, const v_##tp##x2& b, \
2181
+ const v_##tp##x2& c, const v_##tp##x2& d, \
2182
+ hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \
2183
+ { \
2184
+ vst1_##suffix(ptr, vget_low_##suffix(a.val)); \
2185
+ vst1_##suffix(ptr + 1, vget_low_##suffix(b.val)); \
2186
+ vst1_##suffix(ptr + 2, vget_low_##suffix(c.val)); \
2187
+ vst1_##suffix(ptr + 3, vget_low_##suffix(d.val)); \
2188
+ vst1_##suffix(ptr + 4, vget_high_##suffix(a.val)); \
2189
+ vst1_##suffix(ptr + 5, vget_high_##suffix(b.val)); \
2190
+ vst1_##suffix(ptr + 6, vget_high_##suffix(c.val)); \
2191
+ vst1_##suffix(ptr + 7, vget_high_##suffix(d.val)); \
2192
+ }
2193
+
2194
+ OPENCV_HAL_IMPL_NEON_INTERLEAVED(uint8x16, uchar, u8)
2195
+ OPENCV_HAL_IMPL_NEON_INTERLEAVED(int8x16, schar, s8)
2196
+ OPENCV_HAL_IMPL_NEON_INTERLEAVED(uint16x8, ushort, u16)
2197
+ OPENCV_HAL_IMPL_NEON_INTERLEAVED(int16x8, short, s16)
2198
+ OPENCV_HAL_IMPL_NEON_INTERLEAVED(uint32x4, unsigned, u32)
2199
+ OPENCV_HAL_IMPL_NEON_INTERLEAVED(int32x4, int, s32)
2200
+ OPENCV_HAL_IMPL_NEON_INTERLEAVED(float32x4, float, f32)
2201
+ #if CV_SIMD128_64F
2202
+ OPENCV_HAL_IMPL_NEON_INTERLEAVED(float64x2, double, f64)
2203
+ #endif
2204
+
2205
+ OPENCV_HAL_IMPL_NEON_INTERLEAVED_INT64(int64, s64)
2206
+ OPENCV_HAL_IMPL_NEON_INTERLEAVED_INT64(uint64, u64)
2207
+
2208
+ inline v_float32x4 v_cvt_f32(const v_int32x4& a)
2209
+ {
2210
+ return v_float32x4(vcvtq_f32_s32(a.val));
2211
+ }
2212
+
2213
+ #if CV_SIMD128_64F
2214
+ inline v_float32x4 v_cvt_f32(const v_float64x2& a)
2215
+ {
2216
+ float32x2_t zero = vdup_n_f32(0.0f);
2217
+ return v_float32x4(vcombine_f32(vcvt_f32_f64(a.val), zero));
2218
+ }
2219
+
2220
+ inline v_float32x4 v_cvt_f32(const v_float64x2& a, const v_float64x2& b)
2221
+ {
2222
+ return v_float32x4(vcombine_f32(vcvt_f32_f64(a.val), vcvt_f32_f64(b.val)));
2223
+ }
2224
+
2225
+ inline v_float64x2 v_cvt_f64(const v_int32x4& a)
2226
+ {
2227
+ return v_float64x2(vcvt_f64_f32(vcvt_f32_s32(vget_low_s32(a.val))));
2228
+ }
2229
+
2230
+ inline v_float64x2 v_cvt_f64_high(const v_int32x4& a)
2231
+ {
2232
+ return v_float64x2(vcvt_f64_f32(vcvt_f32_s32(vget_high_s32(a.val))));
2233
+ }
2234
+
2235
+ inline v_float64x2 v_cvt_f64(const v_float32x4& a)
2236
+ {
2237
+ return v_float64x2(vcvt_f64_f32(vget_low_f32(a.val)));
2238
+ }
2239
+
2240
+ inline v_float64x2 v_cvt_f64_high(const v_float32x4& a)
2241
+ {
2242
+ return v_float64x2(vcvt_f64_f32(vget_high_f32(a.val)));
2243
+ }
2244
+
2245
+ inline v_float64x2 v_cvt_f64(const v_int64x2& a)
2246
+ { return v_float64x2(vcvtq_f64_s64(a.val)); }
2247
+
2248
+ #endif
2249
+
2250
+ ////////////// Lookup table access ////////////////////
2251
+
2252
+ inline v_int8x16 v_lut(const schar* tab, const int* idx)
2253
+ {
2254
+ schar CV_DECL_ALIGNED(32) elems[16] =
2255
+ {
2256
+ tab[idx[ 0]],
2257
+ tab[idx[ 1]],
2258
+ tab[idx[ 2]],
2259
+ tab[idx[ 3]],
2260
+ tab[idx[ 4]],
2261
+ tab[idx[ 5]],
2262
+ tab[idx[ 6]],
2263
+ tab[idx[ 7]],
2264
+ tab[idx[ 8]],
2265
+ tab[idx[ 9]],
2266
+ tab[idx[10]],
2267
+ tab[idx[11]],
2268
+ tab[idx[12]],
2269
+ tab[idx[13]],
2270
+ tab[idx[14]],
2271
+ tab[idx[15]]
2272
+ };
2273
+ return v_int8x16(vld1q_s8(elems));
2274
+ }
2275
+ inline v_int8x16 v_lut_pairs(const schar* tab, const int* idx)
2276
+ {
2277
+ schar CV_DECL_ALIGNED(32) elems[16] =
2278
+ {
2279
+ tab[idx[0]],
2280
+ tab[idx[0] + 1],
2281
+ tab[idx[1]],
2282
+ tab[idx[1] + 1],
2283
+ tab[idx[2]],
2284
+ tab[idx[2] + 1],
2285
+ tab[idx[3]],
2286
+ tab[idx[3] + 1],
2287
+ tab[idx[4]],
2288
+ tab[idx[4] + 1],
2289
+ tab[idx[5]],
2290
+ tab[idx[5] + 1],
2291
+ tab[idx[6]],
2292
+ tab[idx[6] + 1],
2293
+ tab[idx[7]],
2294
+ tab[idx[7] + 1]
2295
+ };
2296
+ return v_int8x16(vld1q_s8(elems));
2297
+ }
2298
+ inline v_int8x16 v_lut_quads(const schar* tab, const int* idx)
2299
+ {
2300
+ schar CV_DECL_ALIGNED(32) elems[16] =
2301
+ {
2302
+ tab[idx[0]],
2303
+ tab[idx[0] + 1],
2304
+ tab[idx[0] + 2],
2305
+ tab[idx[0] + 3],
2306
+ tab[idx[1]],
2307
+ tab[idx[1] + 1],
2308
+ tab[idx[1] + 2],
2309
+ tab[idx[1] + 3],
2310
+ tab[idx[2]],
2311
+ tab[idx[2] + 1],
2312
+ tab[idx[2] + 2],
2313
+ tab[idx[2] + 3],
2314
+ tab[idx[3]],
2315
+ tab[idx[3] + 1],
2316
+ tab[idx[3] + 2],
2317
+ tab[idx[3] + 3]
2318
+ };
2319
+ return v_int8x16(vld1q_s8(elems));
2320
+ }
2321
+ inline v_uint8x16 v_lut(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut((schar*)tab, idx)); }
2322
+ inline v_uint8x16 v_lut_pairs(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_pairs((schar*)tab, idx)); }
2323
+ inline v_uint8x16 v_lut_quads(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_quads((schar*)tab, idx)); }
2324
+
2325
+ inline v_int16x8 v_lut(const short* tab, const int* idx)
2326
+ {
2327
+ short CV_DECL_ALIGNED(32) elems[8] =
2328
+ {
2329
+ tab[idx[0]],
2330
+ tab[idx[1]],
2331
+ tab[idx[2]],
2332
+ tab[idx[3]],
2333
+ tab[idx[4]],
2334
+ tab[idx[5]],
2335
+ tab[idx[6]],
2336
+ tab[idx[7]]
2337
+ };
2338
+ return v_int16x8(vld1q_s16(elems));
2339
+ }
2340
+ inline v_int16x8 v_lut_pairs(const short* tab, const int* idx)
2341
+ {
2342
+ short CV_DECL_ALIGNED(32) elems[8] =
2343
+ {
2344
+ tab[idx[0]],
2345
+ tab[idx[0] + 1],
2346
+ tab[idx[1]],
2347
+ tab[idx[1] + 1],
2348
+ tab[idx[2]],
2349
+ tab[idx[2] + 1],
2350
+ tab[idx[3]],
2351
+ tab[idx[3] + 1]
2352
+ };
2353
+ return v_int16x8(vld1q_s16(elems));
2354
+ }
2355
+ inline v_int16x8 v_lut_quads(const short* tab, const int* idx)
2356
+ {
2357
+ return v_int16x8(vcombine_s16(vld1_s16(tab + idx[0]), vld1_s16(tab + idx[1])));
2358
+ }
2359
+ inline v_uint16x8 v_lut(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut((short*)tab, idx)); }
2360
+ inline v_uint16x8 v_lut_pairs(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_pairs((short*)tab, idx)); }
2361
+ inline v_uint16x8 v_lut_quads(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_quads((short*)tab, idx)); }
2362
+
2363
+ inline v_int32x4 v_lut(const int* tab, const int* idx)
2364
+ {
2365
+ int CV_DECL_ALIGNED(32) elems[4] =
2366
+ {
2367
+ tab[idx[0]],
2368
+ tab[idx[1]],
2369
+ tab[idx[2]],
2370
+ tab[idx[3]]
2371
+ };
2372
+ return v_int32x4(vld1q_s32(elems));
2373
+ }
2374
+ inline v_int32x4 v_lut_pairs(const int* tab, const int* idx)
2375
+ {
2376
+ return v_int32x4(vcombine_s32(vld1_s32(tab + idx[0]), vld1_s32(tab + idx[1])));
2377
+ }
2378
+ inline v_int32x4 v_lut_quads(const int* tab, const int* idx)
2379
+ {
2380
+ return v_int32x4(vld1q_s32(tab + idx[0]));
2381
+ }
2382
+ inline v_uint32x4 v_lut(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut((int*)tab, idx)); }
2383
+ inline v_uint32x4 v_lut_pairs(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_pairs((int*)tab, idx)); }
2384
+ inline v_uint32x4 v_lut_quads(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_quads((int*)tab, idx)); }
2385
+
2386
+ inline v_int64x2 v_lut(const int64_t* tab, const int* idx)
2387
+ {
2388
+ return v_int64x2(vcombine_s64(vcreate_s64(tab[idx[0]]), vcreate_s64(tab[idx[1]])));
2389
+ }
2390
+ inline v_int64x2 v_lut_pairs(const int64_t* tab, const int* idx)
2391
+ {
2392
+ return v_int64x2(vld1q_s64(tab + idx[0]));
2393
+ }
2394
+ inline v_uint64x2 v_lut(const uint64_t* tab, const int* idx) { return v_reinterpret_as_u64(v_lut((const int64_t *)tab, idx)); }
2395
+ inline v_uint64x2 v_lut_pairs(const uint64_t* tab, const int* idx) { return v_reinterpret_as_u64(v_lut_pairs((const int64_t *)tab, idx)); }
2396
+
2397
+ inline v_float32x4 v_lut(const float* tab, const int* idx)
2398
+ {
2399
+ float CV_DECL_ALIGNED(32) elems[4] =
2400
+ {
2401
+ tab[idx[0]],
2402
+ tab[idx[1]],
2403
+ tab[idx[2]],
2404
+ tab[idx[3]]
2405
+ };
2406
+ return v_float32x4(vld1q_f32(elems));
2407
+ }
2408
+ inline v_float32x4 v_lut_pairs(const float* tab, const int* idx)
2409
+ {
2410
+ typedef uint64 CV_DECL_ALIGNED(1) unaligned_uint64;
2411
+
2412
+ uint64 CV_DECL_ALIGNED(32) elems[2] =
2413
+ {
2414
+ *(unaligned_uint64*)(tab + idx[0]),
2415
+ *(unaligned_uint64*)(tab + idx[1])
2416
+ };
2417
+ return v_float32x4(vreinterpretq_f32_u64(vld1q_u64(elems)));
2418
+ }
2419
+ inline v_float32x4 v_lut_quads(const float* tab, const int* idx)
2420
+ {
2421
+ return v_float32x4(vld1q_f32(tab + idx[0]));
2422
+ }
2423
+
2424
+ inline v_int32x4 v_lut(const int* tab, const v_int32x4& idxvec)
2425
+ {
2426
+ int CV_DECL_ALIGNED(32) elems[4] =
2427
+ {
2428
+ tab[vgetq_lane_s32(idxvec.val, 0)],
2429
+ tab[vgetq_lane_s32(idxvec.val, 1)],
2430
+ tab[vgetq_lane_s32(idxvec.val, 2)],
2431
+ tab[vgetq_lane_s32(idxvec.val, 3)]
2432
+ };
2433
+ return v_int32x4(vld1q_s32(elems));
2434
+ }
2435
+
2436
+ inline v_uint32x4 v_lut(const unsigned* tab, const v_int32x4& idxvec)
2437
+ {
2438
+ unsigned CV_DECL_ALIGNED(32) elems[4] =
2439
+ {
2440
+ tab[vgetq_lane_s32(idxvec.val, 0)],
2441
+ tab[vgetq_lane_s32(idxvec.val, 1)],
2442
+ tab[vgetq_lane_s32(idxvec.val, 2)],
2443
+ tab[vgetq_lane_s32(idxvec.val, 3)]
2444
+ };
2445
+ return v_uint32x4(vld1q_u32(elems));
2446
+ }
2447
+
2448
+ inline v_float32x4 v_lut(const float* tab, const v_int32x4& idxvec)
2449
+ {
2450
+ float CV_DECL_ALIGNED(32) elems[4] =
2451
+ {
2452
+ tab[vgetq_lane_s32(idxvec.val, 0)],
2453
+ tab[vgetq_lane_s32(idxvec.val, 1)],
2454
+ tab[vgetq_lane_s32(idxvec.val, 2)],
2455
+ tab[vgetq_lane_s32(idxvec.val, 3)]
2456
+ };
2457
+ return v_float32x4(vld1q_f32(elems));
2458
+ }
2459
+
2460
+ inline void v_lut_deinterleave(const float* tab, const v_int32x4& idxvec, v_float32x4& x, v_float32x4& y)
2461
+ {
2462
+ /*int CV_DECL_ALIGNED(32) idx[4];
2463
+ v_store(idx, idxvec);
2464
+
2465
+ float32x4_t xy02 = vcombine_f32(vld1_f32(tab + idx[0]), vld1_f32(tab + idx[2]));
2466
+ float32x4_t xy13 = vcombine_f32(vld1_f32(tab + idx[1]), vld1_f32(tab + idx[3]));
2467
+
2468
+ float32x4x2_t xxyy = vuzpq_f32(xy02, xy13);
2469
+ x = v_float32x4(xxyy.val[0]);
2470
+ y = v_float32x4(xxyy.val[1]);*/
2471
+ int CV_DECL_ALIGNED(32) idx[4];
2472
+ v_store_aligned(idx, idxvec);
2473
+
2474
+ x = v_float32x4(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]);
2475
+ y = v_float32x4(tab[idx[0]+1], tab[idx[1]+1], tab[idx[2]+1], tab[idx[3]+1]);
2476
+ }
2477
+
2478
+ inline v_int8x16 v_interleave_pairs(const v_int8x16& vec)
2479
+ {
2480
+ return v_int8x16(vcombine_s8(vtbl1_s8(vget_low_s8(vec.val), vcreate_s8(0x0705060403010200)), vtbl1_s8(vget_high_s8(vec.val), vcreate_s8(0x0705060403010200))));
2481
+ }
2482
+ inline v_uint8x16 v_interleave_pairs(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_interleave_pairs(v_reinterpret_as_s8(vec))); }
2483
+ inline v_int8x16 v_interleave_quads(const v_int8x16& vec)
2484
+ {
2485
+ return v_int8x16(vcombine_s8(vtbl1_s8(vget_low_s8(vec.val), vcreate_s8(0x0703060205010400)), vtbl1_s8(vget_high_s8(vec.val), vcreate_s8(0x0703060205010400))));
2486
+ }
2487
+ inline v_uint8x16 v_interleave_quads(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_interleave_quads(v_reinterpret_as_s8(vec))); }
2488
+
2489
+ inline v_int16x8 v_interleave_pairs(const v_int16x8& vec)
2490
+ {
2491
+ return v_int16x8(vreinterpretq_s16_s8(vcombine_s8(vtbl1_s8(vget_low_s8(vreinterpretq_s8_s16(vec.val)), vcreate_s8(0x0706030205040100)), vtbl1_s8(vget_high_s8(vreinterpretq_s8_s16(vec.val)), vcreate_s8(0x0706030205040100)))));
2492
+ }
2493
+ inline v_uint16x8 v_interleave_pairs(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_interleave_pairs(v_reinterpret_as_s16(vec))); }
2494
+ inline v_int16x8 v_interleave_quads(const v_int16x8& vec)
2495
+ {
2496
+ int16x4x2_t res = vzip_s16(vget_low_s16(vec.val), vget_high_s16(vec.val));
2497
+ return v_int16x8(vcombine_s16(res.val[0], res.val[1]));
2498
+ }
2499
+ inline v_uint16x8 v_interleave_quads(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_interleave_quads(v_reinterpret_as_s16(vec))); }
2500
+
2501
+ inline v_int32x4 v_interleave_pairs(const v_int32x4& vec)
2502
+ {
2503
+ int32x2x2_t res = vzip_s32(vget_low_s32(vec.val), vget_high_s32(vec.val));
2504
+ return v_int32x4(vcombine_s32(res.val[0], res.val[1]));
2505
+ }
2506
+ inline v_uint32x4 v_interleave_pairs(const v_uint32x4& vec) { return v_reinterpret_as_u32(v_interleave_pairs(v_reinterpret_as_s32(vec))); }
2507
+ inline v_float32x4 v_interleave_pairs(const v_float32x4& vec) { return v_reinterpret_as_f32(v_interleave_pairs(v_reinterpret_as_s32(vec))); }
2508
+
2509
+ inline v_int8x16 v_pack_triplets(const v_int8x16& vec)
2510
+ {
2511
+ return v_int8x16(vextq_s8(vcombine_s8(vtbl1_s8(vget_low_s8(vec.val), vcreate_s8(0x0605040201000000)), vtbl1_s8(vget_high_s8(vec.val), vcreate_s8(0x0807060504020100))), vdupq_n_s8(0), 2));
2512
+ }
2513
+ inline v_uint8x16 v_pack_triplets(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_pack_triplets(v_reinterpret_as_s8(vec))); }
2514
+
2515
+ inline v_int16x8 v_pack_triplets(const v_int16x8& vec)
2516
+ {
2517
+ return v_int16x8(vreinterpretq_s16_s8(vextq_s8(vcombine_s8(vtbl1_s8(vget_low_s8(vreinterpretq_s8_s16(vec.val)), vcreate_s8(0x0504030201000000)), vget_high_s8(vreinterpretq_s8_s16(vec.val))), vdupq_n_s8(0), 2)));
2518
+ }
2519
+ inline v_uint16x8 v_pack_triplets(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_pack_triplets(v_reinterpret_as_s16(vec))); }
2520
+
2521
+ inline v_int32x4 v_pack_triplets(const v_int32x4& vec) { return vec; }
2522
+ inline v_uint32x4 v_pack_triplets(const v_uint32x4& vec) { return vec; }
2523
+ inline v_float32x4 v_pack_triplets(const v_float32x4& vec) { return vec; }
2524
+
2525
+ #if CV_SIMD128_64F
2526
+ inline v_float64x2 v_lut(const double* tab, const int* idx)
2527
+ {
2528
+ double CV_DECL_ALIGNED(32) elems[2] =
2529
+ {
2530
+ tab[idx[0]],
2531
+ tab[idx[1]]
2532
+ };
2533
+ return v_float64x2(vld1q_f64(elems));
2534
+ }
2535
+
2536
+ inline v_float64x2 v_lut_pairs(const double* tab, const int* idx)
2537
+ {
2538
+ return v_float64x2(vld1q_f64(tab + idx[0]));
2539
+ }
2540
+
2541
+ inline v_float64x2 v_lut(const double* tab, const v_int32x4& idxvec)
2542
+ {
2543
+ double CV_DECL_ALIGNED(32) elems[2] =
2544
+ {
2545
+ tab[vgetq_lane_s32(idxvec.val, 0)],
2546
+ tab[vgetq_lane_s32(idxvec.val, 1)],
2547
+ };
2548
+ return v_float64x2(vld1q_f64(elems));
2549
+ }
2550
+
2551
+ inline void v_lut_deinterleave(const double* tab, const v_int32x4& idxvec, v_float64x2& x, v_float64x2& y)
2552
+ {
2553
+ int CV_DECL_ALIGNED(32) idx[4];
2554
+ v_store_aligned(idx, idxvec);
2555
+
2556
+ x = v_float64x2(tab[idx[0]], tab[idx[1]]);
2557
+ y = v_float64x2(tab[idx[0]+1], tab[idx[1]+1]);
2558
+ }
2559
+ #endif
2560
+
2561
+ ////// FP16 support ///////
2562
+ #if CV_FP16
2563
+ inline v_float32x4 v_load_expand(const float16_t* ptr)
2564
+ {
2565
+ float16x4_t v =
2566
+ #ifndef vld1_f16 // APPLE compiler defines vld1_f16 as macro
2567
+ (float16x4_t)vld1_s16((const short*)ptr);
2568
+ #else
2569
+ vld1_f16((const __fp16*)ptr);
2570
+ #endif
2571
+ return v_float32x4(vcvt_f32_f16(v));
2572
+ }
2573
+
2574
+ inline void v_pack_store(float16_t* ptr, const v_float32x4& v)
2575
+ {
2576
+ float16x4_t hv = vcvt_f16_f32(v.val);
2577
+
2578
+ #ifndef vst1_f16 // APPLE compiler defines vst1_f16 as macro
2579
+ vst1_s16((short*)ptr, (int16x4_t)hv);
2580
+ #else
2581
+ vst1_f16((__fp16*)ptr, hv);
2582
+ #endif
2583
+ }
2584
+ #else
2585
+ inline v_float32x4 v_load_expand(const float16_t* ptr)
2586
+ {
2587
+ const int N = 4;
2588
+ float buf[N];
2589
+ for( int i = 0; i < N; i++ ) buf[i] = (float)ptr[i];
2590
+ return v_load(buf);
2591
+ }
2592
+
2593
+ inline void v_pack_store(float16_t* ptr, const v_float32x4& v)
2594
+ {
2595
+ const int N = 4;
2596
+ float buf[N];
2597
+ v_store(buf, v);
2598
+ for( int i = 0; i < N; i++ ) ptr[i] = float16_t(buf[i]);
2599
+ }
2600
+ #endif
2601
+
2602
+ inline void v_cleanup() {}
2603
+
2604
+ CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END
2605
+
2606
+ //! @endcond
2607
+
2608
+ }
2609
+
2610
+ #endif