react-native-executorch 0.4.8 → 0.5.1-rc.0

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 (1021) hide show
  1. package/android/CMakeLists.txt +17 -0
  2. package/android/build.gradle +76 -13
  3. package/android/libs/classes.jar +0 -0
  4. package/android/src/main/cpp/CMakeLists.txt +73 -0
  5. package/android/src/main/cpp/ETInstallerModule.cpp +76 -0
  6. package/android/src/main/cpp/ETInstallerModule.h +43 -0
  7. package/android/src/main/java/com/swmansion/rnexecutorch/ETInstaller.kt +66 -0
  8. package/android/src/main/java/com/swmansion/rnexecutorch/LLM.kt +3 -3
  9. package/android/src/main/java/com/swmansion/rnexecutorch/RnExecutorchPackage.kt +7 -113
  10. package/common/ada/ada.cpp +17406 -0
  11. package/common/ada/ada.h +10274 -0
  12. package/common/pfft/pfft.c +2205 -0
  13. package/common/pfft/pfft.h +185 -0
  14. package/common/rnexecutorch/Log.h +489 -0
  15. package/common/rnexecutorch/RnExecutorchInstaller.cpp +78 -0
  16. package/common/rnexecutorch/RnExecutorchInstaller.h +112 -0
  17. package/common/rnexecutorch/TokenizerModule.cpp +52 -0
  18. package/common/rnexecutorch/TokenizerModule.h +26 -0
  19. package/common/rnexecutorch/data_processing/FFT.cpp +21 -0
  20. package/common/rnexecutorch/data_processing/FFT.h +23 -0
  21. package/common/rnexecutorch/data_processing/FileUtils.h +30 -0
  22. package/common/rnexecutorch/data_processing/ImageProcessing.cpp +240 -0
  23. package/common/rnexecutorch/data_processing/ImageProcessing.h +55 -0
  24. package/common/rnexecutorch/data_processing/Numerical.cpp +82 -0
  25. package/common/rnexecutorch/data_processing/Numerical.h +23 -0
  26. package/common/rnexecutorch/data_processing/base64.cpp +110 -0
  27. package/common/rnexecutorch/data_processing/base64.h +46 -0
  28. package/common/rnexecutorch/data_processing/dsp.cpp +65 -0
  29. package/common/rnexecutorch/data_processing/dsp.h +12 -0
  30. package/common/rnexecutorch/host_objects/JSTensorViewIn.h +12 -0
  31. package/common/rnexecutorch/host_objects/JSTensorViewOut.h +22 -0
  32. package/common/rnexecutorch/host_objects/JsiConversions.h +410 -0
  33. package/common/rnexecutorch/host_objects/ModelHostObject.h +239 -0
  34. package/common/rnexecutorch/jsi/JsiHostObject.cpp +108 -0
  35. package/common/rnexecutorch/jsi/JsiHostObject.h +87 -0
  36. package/common/rnexecutorch/jsi/OwningArrayBuffer.h +40 -0
  37. package/common/rnexecutorch/jsi/Promise.cpp +20 -0
  38. package/common/rnexecutorch/jsi/Promise.h +69 -0
  39. package/common/rnexecutorch/jsi/RuntimeAwareCache.h +58 -0
  40. package/common/rnexecutorch/jsi/RuntimeLifecycleMonitor.cpp +53 -0
  41. package/common/rnexecutorch/jsi/RuntimeLifecycleMonitor.h +35 -0
  42. package/common/rnexecutorch/metaprogramming/ConstructorHelpers.h +131 -0
  43. package/common/rnexecutorch/metaprogramming/FunctionHelpers.h +50 -0
  44. package/common/rnexecutorch/metaprogramming/TypeConcepts.h +37 -0
  45. package/common/rnexecutorch/models/BaseModel.cpp +181 -0
  46. package/common/rnexecutorch/models/BaseModel.h +47 -0
  47. package/common/rnexecutorch/models/EncoderDecoderBase.cpp +21 -0
  48. package/common/rnexecutorch/models/EncoderDecoderBase.h +31 -0
  49. package/common/rnexecutorch/models/classification/Classification.cpp +72 -0
  50. package/common/rnexecutorch/models/classification/Classification.h +26 -0
  51. package/{ios/RnExecutorch/models/classification/Constants.mm → common/rnexecutorch/models/classification/Constants.h} +7 -2
  52. package/common/rnexecutorch/models/embeddings/BaseEmbeddings.cpp +27 -0
  53. package/common/rnexecutorch/models/embeddings/BaseEmbeddings.h +17 -0
  54. package/common/rnexecutorch/models/embeddings/image/ImageEmbeddings.cpp +45 -0
  55. package/common/rnexecutorch/models/embeddings/image/ImageEmbeddings.h +23 -0
  56. package/common/rnexecutorch/models/embeddings/text/TextEmbeddings.cpp +61 -0
  57. package/common/rnexecutorch/models/embeddings/text/TextEmbeddings.h +26 -0
  58. package/{ios/RnExecutorch/models/image_segmentation/Constants.mm → common/rnexecutorch/models/image_segmentation/Constants.h} +7 -2
  59. package/common/rnexecutorch/models/image_segmentation/ImageSegmentation.cpp +173 -0
  60. package/common/rnexecutorch/models/image_segmentation/ImageSegmentation.h +43 -0
  61. package/{ios/RnExecutorch/utils/Constants.mm → common/rnexecutorch/models/object_detection/Constants.h} +9 -2
  62. package/common/rnexecutorch/models/object_detection/ObjectDetection.cpp +82 -0
  63. package/common/rnexecutorch/models/object_detection/ObjectDetection.h +31 -0
  64. package/{ios/RnExecutorch/utils/ObjectDetectionUtils.mm → common/rnexecutorch/models/object_detection/Utils.cpp} +10 -30
  65. package/common/rnexecutorch/models/object_detection/Utils.h +17 -0
  66. package/common/rnexecutorch/models/ocr/CTCLabelConverter.cpp +88 -0
  67. package/common/rnexecutorch/models/ocr/CTCLabelConverter.h +29 -0
  68. package/common/rnexecutorch/models/ocr/Constants.h +34 -0
  69. package/common/rnexecutorch/models/ocr/Detector.cpp +102 -0
  70. package/common/rnexecutorch/models/ocr/Detector.h +30 -0
  71. package/common/rnexecutorch/models/ocr/DetectorUtils.cpp +703 -0
  72. package/common/rnexecutorch/models/ocr/DetectorUtils.h +80 -0
  73. package/common/rnexecutorch/models/ocr/OCR.cpp +52 -0
  74. package/common/rnexecutorch/models/ocr/OCR.h +36 -0
  75. package/common/rnexecutorch/models/ocr/RecognitionHandler.cpp +107 -0
  76. package/common/rnexecutorch/models/ocr/RecognitionHandler.h +40 -0
  77. package/common/rnexecutorch/models/ocr/RecognitionHandlerUtils.cpp +153 -0
  78. package/common/rnexecutorch/models/ocr/RecognitionHandlerUtils.h +72 -0
  79. package/common/rnexecutorch/models/ocr/Recognizer.cpp +80 -0
  80. package/common/rnexecutorch/models/ocr/Recognizer.h +36 -0
  81. package/common/rnexecutorch/models/ocr/RecognizerUtils.cpp +202 -0
  82. package/common/rnexecutorch/models/ocr/RecognizerUtils.h +70 -0
  83. package/common/rnexecutorch/models/ocr/Types.h +37 -0
  84. package/common/rnexecutorch/models/speech_to_text/MoonshineStrategy.cpp +31 -0
  85. package/common/rnexecutorch/models/speech_to_text/MoonshineStrategy.h +21 -0
  86. package/common/rnexecutorch/models/speech_to_text/SpeechToText.cpp +70 -0
  87. package/common/rnexecutorch/models/speech_to_text/SpeechToText.h +31 -0
  88. package/common/rnexecutorch/models/speech_to_text/SpeechToTextStrategy.h +26 -0
  89. package/common/rnexecutorch/models/speech_to_text/WhisperStrategy.cpp +38 -0
  90. package/common/rnexecutorch/models/speech_to_text/WhisperStrategy.h +25 -0
  91. package/common/rnexecutorch/models/style_transfer/StyleTransfer.cpp +55 -0
  92. package/common/rnexecutorch/models/style_transfer/StyleTransfer.h +29 -0
  93. package/common/rnexecutorch/models/vertical_ocr/VerticalDetector.cpp +92 -0
  94. package/common/rnexecutorch/models/vertical_ocr/VerticalDetector.h +49 -0
  95. package/common/rnexecutorch/models/vertical_ocr/VerticalOCR.cpp +180 -0
  96. package/common/rnexecutorch/models/vertical_ocr/VerticalOCR.h +78 -0
  97. package/common/rnexecutorch/tests/LogTest.cpp +530 -0
  98. package/common/rnexecutorch/tests/README.md +20 -0
  99. package/common/rnexecutorch/tests/run_all_tests.sh +14 -0
  100. package/common/rnexecutorch/tests/run_test.sh +18 -0
  101. package/ios/ExecutorchLib.xcframework/Info.plist +4 -4
  102. package/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/ExecutorchLib +0 -0
  103. package/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Info.plist +0 -0
  104. package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/ExecutorchLib +0 -0
  105. package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Info.plist +0 -0
  106. package/ios/RnExecutorch/ETInstaller.h +8 -0
  107. package/ios/RnExecutorch/ETInstaller.mm +56 -0
  108. package/ios/RnExecutorch/utils/Conversions.h +8 -9
  109. package/ios/RnExecutorch/utils/Numerical.h +2 -0
  110. package/ios/RnExecutorch.xcodeproj/project.pbxproj +73 -0
  111. package/lib/common/Logger.d.ts +8 -0
  112. package/lib/common/Logger.js +19 -0
  113. package/lib/constants/modelUrls.d.ts +89 -0
  114. package/lib/constants/modelUrls.js +116 -0
  115. package/lib/constants/sttDefaults.js +66 -0
  116. package/lib/controllers/LLMController.js +210 -0
  117. package/lib/controllers/OCRController.js +65 -0
  118. package/lib/controllers/SpeechToTextController.d.ts +52 -0
  119. package/lib/controllers/SpeechToTextController.js +343 -0
  120. package/lib/hooks/natural_language_processing/useSpeechToText.js +44 -0
  121. package/lib/index.d.ts +50 -0
  122. package/{src/index.tsx → lib/index.js} +22 -10
  123. package/lib/module/Error.js +2 -0
  124. package/lib/module/Error.js.map +1 -1
  125. package/lib/module/common/Logger.js +23 -0
  126. package/lib/module/common/Logger.js.map +1 -0
  127. package/lib/module/constants/llmDefaults.js +8 -0
  128. package/lib/module/constants/llmDefaults.js.map +1 -1
  129. package/lib/module/constants/modelUrls.js +300 -84
  130. package/lib/module/constants/modelUrls.js.map +1 -1
  131. package/lib/module/constants/ocr/models.js +181 -286
  132. package/lib/module/constants/ocr/models.js.map +1 -1
  133. package/lib/module/constants/ocr/symbols.js +63 -63
  134. package/lib/module/constants/sttDefaults.js +12 -10
  135. package/lib/module/constants/sttDefaults.js.map +1 -1
  136. package/lib/module/controllers/LLMController.js +17 -11
  137. package/lib/module/controllers/LLMController.js.map +1 -1
  138. package/lib/module/controllers/OCRController.js +16 -9
  139. package/lib/module/controllers/OCRController.js.map +1 -1
  140. package/lib/module/controllers/SpeechToTextController.js +32 -19
  141. package/lib/module/controllers/SpeechToTextController.js.map +1 -1
  142. package/lib/module/controllers/VerticalOCRController.js +16 -9
  143. package/lib/module/controllers/VerticalOCRController.js.map +1 -1
  144. package/lib/module/hooks/computer_vision/useClassification.js +5 -5
  145. package/lib/module/hooks/computer_vision/useClassification.js.map +1 -1
  146. package/lib/module/hooks/computer_vision/useImageEmbeddings.js +13 -0
  147. package/lib/module/hooks/computer_vision/useImageEmbeddings.js.map +1 -0
  148. package/lib/module/hooks/computer_vision/useImageSegmentation.js +4 -4
  149. package/lib/module/hooks/computer_vision/useImageSegmentation.js.map +1 -1
  150. package/lib/module/hooks/computer_vision/useOCR.js +14 -15
  151. package/lib/module/hooks/computer_vision/useOCR.js.map +1 -1
  152. package/lib/module/hooks/computer_vision/useObjectDetection.js +5 -5
  153. package/lib/module/hooks/computer_vision/useObjectDetection.js.map +1 -1
  154. package/lib/module/hooks/computer_vision/useStyleTransfer.js +5 -5
  155. package/lib/module/hooks/computer_vision/useStyleTransfer.js.map +1 -1
  156. package/lib/module/hooks/computer_vision/useVerticalOCR.js +16 -17
  157. package/lib/module/hooks/computer_vision/useVerticalOCR.js.map +1 -1
  158. package/lib/module/hooks/general/useExecutorchModule.js +5 -3
  159. package/lib/module/hooks/general/useExecutorchModule.js.map +1 -1
  160. package/lib/module/hooks/natural_language_processing/useLLM.js +22 -25
  161. package/lib/module/hooks/natural_language_processing/useLLM.js.map +1 -1
  162. package/lib/module/hooks/natural_language_processing/useSpeechToText.js +16 -14
  163. package/lib/module/hooks/natural_language_processing/useSpeechToText.js.map +1 -1
  164. package/lib/module/hooks/natural_language_processing/useTextEmbeddings.js +4 -5
  165. package/lib/module/hooks/natural_language_processing/useTextEmbeddings.js.map +1 -1
  166. package/lib/module/hooks/natural_language_processing/useTokenizer.js +20 -19
  167. package/lib/module/hooks/natural_language_processing/useTokenizer.js.map +1 -1
  168. package/lib/module/hooks/useNonStaticModule.js +52 -0
  169. package/lib/module/hooks/useNonStaticModule.js.map +1 -0
  170. package/lib/module/index.js +16 -2
  171. package/lib/module/index.js.map +1 -1
  172. package/lib/module/modules/BaseModule.js +6 -3
  173. package/lib/module/modules/BaseModule.js.map +1 -1
  174. package/lib/module/modules/BaseNonStaticModule.js +17 -0
  175. package/lib/module/modules/BaseNonStaticModule.js.map +1 -0
  176. package/lib/module/modules/computer_vision/ClassificationModule.js +13 -8
  177. package/lib/module/modules/computer_vision/ClassificationModule.js.map +1 -1
  178. package/lib/module/modules/computer_vision/ImageEmbeddingsModule.js +19 -0
  179. package/lib/module/modules/computer_vision/ImageEmbeddingsModule.js.map +1 -0
  180. package/lib/module/modules/computer_vision/ImageSegmentationModule.js +21 -19
  181. package/lib/module/modules/computer_vision/ImageSegmentationModule.js.map +1 -1
  182. package/lib/module/modules/computer_vision/OCRModule.js +13 -10
  183. package/lib/module/modules/computer_vision/OCRModule.js.map +1 -1
  184. package/lib/module/modules/computer_vision/ObjectDetectionModule.js +13 -8
  185. package/lib/module/modules/computer_vision/ObjectDetectionModule.js.map +1 -1
  186. package/lib/module/modules/computer_vision/StyleTransferModule.js +13 -8
  187. package/lib/module/modules/computer_vision/StyleTransferModule.js.map +1 -1
  188. package/lib/module/modules/computer_vision/VerticalOCRModule.js +15 -10
  189. package/lib/module/modules/computer_vision/VerticalOCRModule.js.map +1 -1
  190. package/lib/module/modules/general/ExecutorchModule.js +10 -36
  191. package/lib/module/modules/general/ExecutorchModule.js.map +1 -1
  192. package/lib/module/modules/natural_language_processing/LLMModule.js +18 -22
  193. package/lib/module/modules/natural_language_processing/LLMModule.js.map +1 -1
  194. package/lib/module/modules/natural_language_processing/SpeechToTextModule.js +27 -16
  195. package/lib/module/modules/natural_language_processing/SpeechToTextModule.js.map +1 -1
  196. package/lib/module/modules/natural_language_processing/TextEmbeddingsModule.js +15 -8
  197. package/lib/module/modules/natural_language_processing/TextEmbeddingsModule.js.map +1 -1
  198. package/lib/module/modules/natural_language_processing/TokenizerModule.js +20 -14
  199. package/lib/module/modules/natural_language_processing/TokenizerModule.js.map +1 -1
  200. package/lib/module/native/NativeETInstaller.js +5 -0
  201. package/lib/module/native/NativeETInstaller.js.map +1 -0
  202. package/lib/module/native/RnExecutorchModules.js +2 -11
  203. package/lib/module/native/RnExecutorchModules.js.map +1 -1
  204. package/lib/module/types/common.js +25 -8
  205. package/lib/module/types/common.js.map +1 -1
  206. package/lib/module/types/stt.js +6 -0
  207. package/lib/module/types/stt.js.map +1 -1
  208. package/lib/module/utils/ResourceFetcher.js +276 -114
  209. package/lib/module/utils/ResourceFetcher.js.map +1 -1
  210. package/lib/module/utils/ResourceFetcherUtils.js +155 -0
  211. package/lib/module/utils/ResourceFetcherUtils.js.map +1 -0
  212. package/lib/module/utils/llm.js +41 -1
  213. package/lib/module/utils/llm.js.map +1 -1
  214. package/lib/modules/natural_language_processing/SpeechToTextModule.d.ts +14 -0
  215. package/lib/modules/natural_language_processing/SpeechToTextModule.js +30 -0
  216. package/lib/modules/natural_language_processing/TokenizerModule.js +29 -0
  217. package/lib/native/RnExecutorchModules.d.ts +3 -0
  218. package/lib/native/RnExecutorchModules.js +16 -0
  219. package/lib/typescript/Error.d.ts +2 -0
  220. package/lib/typescript/Error.d.ts.map +1 -1
  221. package/lib/typescript/common/Logger.d.ts +9 -0
  222. package/lib/typescript/common/Logger.d.ts.map +1 -0
  223. package/lib/typescript/constants/llmDefaults.d.ts +1 -0
  224. package/lib/typescript/constants/llmDefaults.d.ts.map +1 -1
  225. package/lib/typescript/constants/modelUrls.d.ts +223 -79
  226. package/lib/typescript/constants/modelUrls.d.ts.map +1 -1
  227. package/lib/typescript/constants/ocr/models.d.ts +882 -284
  228. package/lib/typescript/constants/ocr/models.d.ts.map +1 -1
  229. package/lib/typescript/constants/sttDefaults.d.ts +1 -0
  230. package/lib/typescript/constants/sttDefaults.d.ts.map +1 -1
  231. package/lib/typescript/controllers/LLMController.d.ts +3 -4
  232. package/lib/typescript/controllers/LLMController.d.ts.map +1 -1
  233. package/lib/typescript/controllers/OCRController.d.ts +5 -6
  234. package/lib/typescript/controllers/OCRController.d.ts.map +1 -1
  235. package/lib/typescript/controllers/SpeechToTextController.d.ts +11 -6
  236. package/lib/typescript/controllers/SpeechToTextController.d.ts.map +1 -1
  237. package/lib/typescript/controllers/VerticalOCRController.d.ts +5 -6
  238. package/lib/typescript/controllers/VerticalOCRController.d.ts.map +1 -1
  239. package/lib/typescript/hooks/computer_vision/useClassification.d.ts +8 -6
  240. package/lib/typescript/hooks/computer_vision/useClassification.d.ts.map +1 -1
  241. package/lib/typescript/hooks/computer_vision/useImageEmbeddings.d.ts +16 -0
  242. package/lib/typescript/hooks/computer_vision/useImageEmbeddings.d.ts.map +1 -0
  243. package/lib/typescript/hooks/computer_vision/useImageSegmentation.d.ts +5 -3
  244. package/lib/typescript/hooks/computer_vision/useImageSegmentation.d.ts.map +1 -1
  245. package/lib/typescript/hooks/computer_vision/useOCR.d.ts +4 -4
  246. package/lib/typescript/hooks/computer_vision/useOCR.d.ts.map +1 -1
  247. package/lib/typescript/hooks/computer_vision/useObjectDetection.d.ts +5 -3
  248. package/lib/typescript/hooks/computer_vision/useObjectDetection.d.ts.map +1 -1
  249. package/lib/typescript/hooks/computer_vision/useStyleTransfer.d.ts +5 -3
  250. package/lib/typescript/hooks/computer_vision/useStyleTransfer.d.ts.map +1 -1
  251. package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts +3 -5
  252. package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts.map +1 -1
  253. package/lib/typescript/hooks/general/useExecutorchModule.d.ts +1 -1
  254. package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts +6 -4
  255. package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts.map +1 -1
  256. package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts +7 -5
  257. package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts.map +1 -1
  258. package/lib/typescript/hooks/natural_language_processing/useTextEmbeddings.d.ts +9 -5
  259. package/lib/typescript/hooks/natural_language_processing/useTextEmbeddings.d.ts.map +1 -1
  260. package/lib/typescript/hooks/natural_language_processing/useTokenizer.d.ts +6 -4
  261. package/lib/typescript/hooks/natural_language_processing/useTokenizer.d.ts.map +1 -1
  262. package/lib/typescript/hooks/useNonStaticModule.d.ts +21 -0
  263. package/lib/typescript/hooks/useNonStaticModule.d.ts.map +1 -0
  264. package/lib/typescript/index.d.ts +18 -2
  265. package/lib/typescript/index.d.ts.map +1 -1
  266. package/lib/typescript/modules/BaseModule.d.ts +1 -1
  267. package/lib/typescript/modules/BaseModule.d.ts.map +1 -1
  268. package/lib/typescript/modules/BaseNonStaticModule.d.ts +10 -0
  269. package/lib/typescript/modules/BaseNonStaticModule.d.ts.map +1 -0
  270. package/lib/typescript/modules/computer_vision/ClassificationModule.d.ts +6 -6
  271. package/lib/typescript/modules/computer_vision/ClassificationModule.d.ts.map +1 -1
  272. package/lib/typescript/modules/computer_vision/ImageEmbeddingsModule.d.ts +9 -0
  273. package/lib/typescript/modules/computer_vision/ImageEmbeddingsModule.d.ts.map +1 -0
  274. package/lib/typescript/modules/computer_vision/ImageSegmentationModule.d.ts +8 -28
  275. package/lib/typescript/modules/computer_vision/ImageSegmentationModule.d.ts.map +1 -1
  276. package/lib/typescript/modules/computer_vision/OCRModule.d.ts +8 -7
  277. package/lib/typescript/modules/computer_vision/OCRModule.d.ts.map +1 -1
  278. package/lib/typescript/modules/computer_vision/ObjectDetectionModule.d.ts +7 -5
  279. package/lib/typescript/modules/computer_vision/ObjectDetectionModule.d.ts.map +1 -1
  280. package/lib/typescript/modules/computer_vision/StyleTransferModule.d.ts +6 -5
  281. package/lib/typescript/modules/computer_vision/StyleTransferModule.d.ts.map +1 -1
  282. package/lib/typescript/modules/computer_vision/VerticalOCRModule.d.ts +7 -8
  283. package/lib/typescript/modules/computer_vision/VerticalOCRModule.d.ts.map +1 -1
  284. package/lib/typescript/modules/general/ExecutorchModule.d.ts +5 -8
  285. package/lib/typescript/modules/general/ExecutorchModule.d.ts.map +1 -1
  286. package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts +16 -16
  287. package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts.map +1 -1
  288. package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts +19 -9
  289. package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts.map +1 -1
  290. package/lib/typescript/modules/natural_language_processing/TextEmbeddingsModule.d.ts +7 -5
  291. package/lib/typescript/modules/natural_language_processing/TextEmbeddingsModule.d.ts.map +1 -1
  292. package/lib/typescript/modules/natural_language_processing/TokenizerModule.d.ts +10 -9
  293. package/lib/typescript/modules/natural_language_processing/TokenizerModule.d.ts.map +1 -1
  294. package/lib/typescript/native/{NativeStyleTransfer.d.ts → NativeETInstaller.d.ts} +2 -3
  295. package/lib/typescript/native/NativeETInstaller.d.ts.map +1 -0
  296. package/lib/typescript/native/RnExecutorchModules.d.ts +3 -21
  297. package/lib/typescript/native/RnExecutorchModules.d.ts.map +1 -1
  298. package/lib/typescript/types/common.d.ts +30 -2
  299. package/lib/typescript/types/common.d.ts.map +1 -1
  300. package/lib/typescript/types/stt.d.ts +5 -1
  301. package/lib/typescript/types/stt.d.ts.map +1 -1
  302. package/lib/typescript/utils/ResourceFetcher.d.ts +18 -10
  303. package/lib/typescript/utils/ResourceFetcher.d.ts.map +1 -1
  304. package/lib/typescript/utils/ResourceFetcherUtils.d.ts +55 -0
  305. package/lib/typescript/utils/ResourceFetcherUtils.d.ts.map +1 -0
  306. package/lib/typescript/utils/llm.d.ts +4 -0
  307. package/lib/typescript/utils/llm.d.ts.map +1 -1
  308. package/lib/utils/ResourceFetcherUtils.js +119 -0
  309. package/lib/utils/llm.js +72 -0
  310. package/package.json +22 -64
  311. package/react-native-executorch.podspec +75 -3
  312. package/src/Error.ts +2 -0
  313. package/src/common/Logger.ts +25 -0
  314. package/src/constants/llmDefaults.ts +11 -0
  315. package/src/constants/modelUrls.ts +365 -168
  316. package/src/constants/ocr/models.ts +826 -395
  317. package/src/constants/ocr/symbols.ts +63 -63
  318. package/src/constants/sttDefaults.ts +14 -18
  319. package/src/controllers/LLMController.ts +28 -18
  320. package/src/controllers/OCRController.ts +24 -15
  321. package/src/controllers/SpeechToTextController.ts +53 -40
  322. package/src/controllers/VerticalOCRController.ts +24 -14
  323. package/src/hooks/computer_vision/useClassification.ts +10 -11
  324. package/src/hooks/computer_vision/useImageEmbeddings.ts +15 -0
  325. package/src/hooks/computer_vision/useImageSegmentation.ts +5 -8
  326. package/src/hooks/computer_vision/useOCR.ts +29 -21
  327. package/src/hooks/computer_vision/useObjectDetection.ts +6 -9
  328. package/src/hooks/computer_vision/useStyleTransfer.ts +6 -6
  329. package/src/hooks/computer_vision/useVerticalOCR.ts +30 -27
  330. package/src/hooks/general/useExecutorchModule.ts +3 -3
  331. package/src/hooks/natural_language_processing/useLLM.ts +38 -28
  332. package/src/hooks/natural_language_processing/useSpeechToText.ts +34 -26
  333. package/src/hooks/natural_language_processing/useTextEmbeddings.ts +11 -11
  334. package/src/hooks/natural_language_processing/useTokenizer.ts +22 -22
  335. package/src/hooks/useNonStaticModule.ts +74 -0
  336. package/src/index.ts +108 -0
  337. package/src/modules/BaseModule.ts +9 -3
  338. package/src/modules/BaseNonStaticModule.ts +26 -0
  339. package/src/modules/computer_vision/ClassificationModule.ts +20 -11
  340. package/src/modules/computer_vision/ImageEmbeddingsModule.ts +26 -0
  341. package/src/modules/computer_vision/ImageSegmentationModule.ts +35 -27
  342. package/src/modules/computer_vision/OCRModule.ts +23 -15
  343. package/src/modules/computer_vision/ObjectDetectionModule.ts +24 -11
  344. package/src/modules/computer_vision/StyleTransferModule.ts +20 -11
  345. package/src/modules/computer_vision/VerticalOCRModule.ts +25 -21
  346. package/src/modules/general/ExecutorchModule.ts +18 -48
  347. package/src/modules/natural_language_processing/LLMModule.ts +27 -30
  348. package/src/modules/natural_language_processing/SpeechToTextModule.ts +42 -37
  349. package/src/modules/natural_language_processing/TextEmbeddingsModule.ts +27 -12
  350. package/src/modules/natural_language_processing/TokenizerModule.ts +27 -17
  351. package/src/native/NativeETInstaller.ts +8 -0
  352. package/src/native/RnExecutorchModules.ts +4 -46
  353. package/src/types/common.ts +40 -12
  354. package/src/types/stt.ts +5 -1
  355. package/src/utils/ResourceFetcher.ts +338 -119
  356. package/src/utils/ResourceFetcherUtils.ts +186 -0
  357. package/src/utils/llm.ts +65 -1
  358. package/third-party/android/libs/executorch/arm64-v8a/libexecutorch.so +0 -0
  359. package/third-party/android/libs/executorch/x86_64/libexecutorch.so +0 -0
  360. package/third-party/android/libs/opencv/arm64-v8a/libopencv_core.a +0 -0
  361. package/third-party/android/libs/opencv/arm64-v8a/libopencv_features2d.a +0 -0
  362. package/third-party/android/libs/opencv/arm64-v8a/libopencv_highgui.a +0 -0
  363. package/third-party/android/libs/opencv/arm64-v8a/libopencv_imgproc.a +0 -0
  364. package/third-party/android/libs/opencv/arm64-v8a/libopencv_photo.a +0 -0
  365. package/third-party/android/libs/opencv/arm64-v8a/libopencv_video.a +0 -0
  366. package/third-party/android/libs/opencv/x86_64/libopencv_core.a +0 -0
  367. package/third-party/android/libs/opencv/x86_64/libopencv_features2d.a +0 -0
  368. package/third-party/android/libs/opencv/x86_64/libopencv_highgui.a +0 -0
  369. package/third-party/android/libs/opencv/x86_64/libopencv_imgproc.a +0 -0
  370. package/third-party/android/libs/opencv/x86_64/libopencv_photo.a +0 -0
  371. package/third-party/android/libs/opencv/x86_64/libopencv_video.a +0 -0
  372. package/third-party/android/libs/opencv-third-party/arm64-v8a/libkleidicv.a +0 -0
  373. package/third-party/android/libs/opencv-third-party/arm64-v8a/libkleidicv_hal.a +0 -0
  374. package/third-party/android/libs/opencv-third-party/arm64-v8a/libkleidicv_thread.a +0 -0
  375. package/third-party/include/c10/macros/Export.h +163 -0
  376. package/third-party/include/c10/macros/Macros.h +497 -0
  377. package/third-party/include/c10/util/BFloat16-inl.h +342 -0
  378. package/third-party/include/c10/util/BFloat16-math.h +266 -0
  379. package/third-party/include/c10/util/BFloat16.h +125 -0
  380. package/third-party/include/c10/util/Half-inl.h +347 -0
  381. package/third-party/include/c10/util/Half.h +416 -0
  382. package/third-party/include/c10/util/TypeSafeSignMath.h +133 -0
  383. package/third-party/include/c10/util/bit_cast.h +43 -0
  384. package/third-party/include/c10/util/floating_point_utils.h +33 -0
  385. package/third-party/include/c10/util/irange.h +107 -0
  386. package/third-party/include/executorch/ExecuTorch.h +13 -0
  387. package/third-party/include/executorch/ExecuTorchError.h +16 -0
  388. package/third-party/include/executorch/ExecuTorchLog.h +76 -0
  389. package/third-party/include/executorch/ExecuTorchModule.h +286 -0
  390. package/third-party/include/executorch/ExecuTorchTensor.h +742 -0
  391. package/third-party/include/executorch/ExecuTorchValue.h +219 -0
  392. package/third-party/include/executorch/extension/module/module.h +492 -0
  393. package/third-party/include/executorch/extension/tensor/tensor.h +13 -0
  394. package/third-party/include/executorch/extension/tensor/tensor_accessor.h +190 -0
  395. package/third-party/include/executorch/extension/tensor/tensor_ptr.h +347 -0
  396. package/third-party/include/executorch/extension/tensor/tensor_ptr_maker.h +653 -0
  397. package/third-party/include/executorch/runtime/backend/backend_execution_context.h +71 -0
  398. package/third-party/include/executorch/runtime/backend/backend_init_context.h +72 -0
  399. package/third-party/include/executorch/runtime/backend/interface.h +166 -0
  400. package/third-party/include/executorch/runtime/core/array_ref.h +235 -0
  401. package/third-party/include/executorch/runtime/core/data_loader.h +136 -0
  402. package/third-party/include/executorch/runtime/core/defines.h +20 -0
  403. package/third-party/include/executorch/runtime/core/error.h +229 -0
  404. package/third-party/include/executorch/runtime/core/evalue.h +521 -0
  405. package/third-party/include/executorch/runtime/core/event_tracer.h +565 -0
  406. package/third-party/include/executorch/runtime/core/event_tracer_hooks.h +323 -0
  407. package/third-party/include/executorch/runtime/core/event_tracer_hooks_delegate.h +197 -0
  408. package/third-party/include/executorch/runtime/core/exec_aten/exec_aten.h +147 -0
  409. package/third-party/include/executorch/runtime/core/exec_aten/util/dim_order_util.h +263 -0
  410. package/third-party/include/executorch/runtime/core/exec_aten/util/scalar_type_util.h +1331 -0
  411. package/third-party/include/executorch/runtime/core/exec_aten/util/tensor_dimension_limit.h +21 -0
  412. package/third-party/include/executorch/runtime/core/exec_aten/util/tensor_shape_to_c_string.h +69 -0
  413. package/third-party/include/executorch/runtime/core/exec_aten/util/tensor_util.h +1250 -0
  414. package/third-party/include/executorch/runtime/core/freeable_buffer.h +107 -0
  415. package/third-party/include/executorch/runtime/core/hierarchical_allocator.h +107 -0
  416. package/third-party/include/executorch/runtime/core/memory_allocator.h +198 -0
  417. package/third-party/include/executorch/runtime/core/named_data_map.h +86 -0
  418. package/third-party/include/executorch/runtime/core/portable_type/bfloat16.h +27 -0
  419. package/third-party/include/executorch/runtime/core/portable_type/bfloat16_math.h +14 -0
  420. package/third-party/include/executorch/runtime/core/portable_type/bits_types.h +83 -0
  421. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Export.h +163 -0
  422. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Macros.h +497 -0
  423. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-inl.h +342 -0
  424. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-math.h +266 -0
  425. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16.h +125 -0
  426. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/Half-inl.h +347 -0
  427. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/Half.h +416 -0
  428. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/TypeSafeSignMath.h +133 -0
  429. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/bit_cast.h +43 -0
  430. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/floating_point_utils.h +33 -0
  431. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/irange.h +107 -0
  432. package/third-party/include/executorch/runtime/core/portable_type/complex.h +44 -0
  433. package/third-party/include/executorch/runtime/core/portable_type/device.h +70 -0
  434. package/third-party/include/executorch/runtime/core/portable_type/half.h +27 -0
  435. package/third-party/include/executorch/runtime/core/portable_type/optional.h +36 -0
  436. package/third-party/include/executorch/runtime/core/portable_type/qint_types.h +83 -0
  437. package/third-party/include/executorch/runtime/core/portable_type/scalar.h +110 -0
  438. package/third-party/include/executorch/runtime/core/portable_type/scalar_type.h +154 -0
  439. package/third-party/include/executorch/runtime/core/portable_type/string_view.h +29 -0
  440. package/third-party/include/executorch/runtime/core/portable_type/tensor.h +142 -0
  441. package/third-party/include/executorch/runtime/core/portable_type/tensor_impl.h +261 -0
  442. package/third-party/include/executorch/runtime/core/portable_type/tensor_options.h +60 -0
  443. package/third-party/include/executorch/runtime/core/result.h +258 -0
  444. package/third-party/include/executorch/runtime/core/span.h +93 -0
  445. package/third-party/include/executorch/runtime/core/tag.h +71 -0
  446. package/third-party/include/executorch/runtime/core/tensor_layout.h +79 -0
  447. package/third-party/include/executorch/runtime/core/tensor_shape_dynamism.h +39 -0
  448. package/third-party/include/executorch/runtime/executor/memory_manager.h +113 -0
  449. package/third-party/include/executorch/runtime/executor/method.h +387 -0
  450. package/third-party/include/executorch/runtime/executor/method_meta.h +251 -0
  451. package/third-party/include/executorch/runtime/executor/program.h +320 -0
  452. package/third-party/include/executorch/runtime/executor/pte_data_map.h +144 -0
  453. package/third-party/include/executorch/runtime/executor/tensor_parser.h +156 -0
  454. package/third-party/include/executorch/runtime/kernel/kernel_runtime_context.h +122 -0
  455. package/third-party/include/executorch/runtime/kernel/operator_registry.h +278 -0
  456. package/third-party/include/executorch/runtime/platform/abort.h +36 -0
  457. package/third-party/include/executorch/runtime/platform/assert.h +119 -0
  458. package/third-party/include/executorch/runtime/platform/clock.h +43 -0
  459. package/third-party/include/executorch/runtime/platform/compat_unistd.h +75 -0
  460. package/third-party/include/executorch/runtime/platform/compiler.h +191 -0
  461. package/third-party/include/executorch/runtime/platform/log.h +177 -0
  462. package/third-party/include/executorch/runtime/platform/platform.h +133 -0
  463. package/third-party/include/executorch/runtime/platform/profiler.h +292 -0
  464. package/third-party/include/executorch/runtime/platform/runtime.h +35 -0
  465. package/third-party/include/executorch/runtime/platform/system.h +49 -0
  466. package/third-party/include/executorch/runtime/platform/types.h +24 -0
  467. package/third-party/include/executorch/schema/extended_header.h +76 -0
  468. package/third-party/include/opencv2/core/affine.hpp +676 -0
  469. package/third-party/include/opencv2/core/async.hpp +107 -0
  470. package/third-party/include/opencv2/core/base.hpp +735 -0
  471. package/third-party/include/opencv2/core/bindings_utils.hpp +279 -0
  472. package/third-party/include/opencv2/core/bufferpool.hpp +39 -0
  473. package/third-party/include/opencv2/core/check.hpp +231 -0
  474. package/third-party/include/opencv2/core/core.hpp +55 -0
  475. package/third-party/include/opencv2/core/core_c.h +3261 -0
  476. package/third-party/include/opencv2/core/cv_cpu_dispatch.h +404 -0
  477. package/third-party/include/opencv2/core/cv_cpu_helper.h +856 -0
  478. package/third-party/include/opencv2/core/cvdef.h +1003 -0
  479. package/third-party/include/opencv2/core/cvstd.hpp +196 -0
  480. package/third-party/include/opencv2/core/cvstd.inl.hpp +188 -0
  481. package/third-party/include/opencv2/core/cvstd_wrapper.hpp +187 -0
  482. package/third-party/include/opencv2/core/detail/async_promise.hpp +73 -0
  483. package/third-party/include/opencv2/core/detail/dispatch_helper.impl.hpp +48 -0
  484. package/third-party/include/opencv2/core/detail/exception_ptr.hpp +24 -0
  485. package/third-party/include/opencv2/core/dualquaternion.hpp +1054 -0
  486. package/third-party/include/opencv2/core/dualquaternion.inl.hpp +464 -0
  487. package/third-party/include/opencv2/core/eigen.hpp +405 -0
  488. package/third-party/include/opencv2/core/fast_math.hpp +433 -0
  489. package/third-party/include/opencv2/core/hal/hal.hpp +451 -0
  490. package/third-party/include/opencv2/core/hal/interface.h +191 -0
  491. package/third-party/include/opencv2/core/hal/intrin.hpp +1222 -0
  492. package/third-party/include/opencv2/core/hal/intrin_avx.hpp +3378 -0
  493. package/third-party/include/opencv2/core/hal/intrin_avx512.hpp +3688 -0
  494. package/third-party/include/opencv2/core/hal/intrin_cpp.hpp +3446 -0
  495. package/third-party/include/opencv2/core/hal/intrin_forward.hpp +195 -0
  496. package/third-party/include/opencv2/core/hal/intrin_lasx.hpp +3243 -0
  497. package/third-party/include/opencv2/core/hal/intrin_lsx.hpp +2671 -0
  498. package/third-party/include/opencv2/core/hal/intrin_math.hpp +772 -0
  499. package/third-party/include/opencv2/core/hal/intrin_msa.hpp +1973 -0
  500. package/third-party/include/opencv2/core/hal/intrin_neon.hpp +2710 -0
  501. package/third-party/include/opencv2/core/hal/intrin_rvv071.hpp +3452 -0
  502. package/third-party/include/opencv2/core/hal/intrin_rvv_scalable.hpp +2559 -0
  503. package/third-party/include/opencv2/core/hal/intrin_sse.hpp +3528 -0
  504. package/third-party/include/opencv2/core/hal/intrin_sse_em.hpp +175 -0
  505. package/third-party/include/opencv2/core/hal/intrin_vsx.hpp +1756 -0
  506. package/third-party/include/opencv2/core/hal/intrin_wasm.hpp +2911 -0
  507. package/third-party/include/opencv2/core/hal/msa_macros.h +2079 -0
  508. package/third-party/include/opencv2/core/hal/simd_utils.impl.hpp +313 -0
  509. package/third-party/include/opencv2/core/mat.hpp +3842 -0
  510. package/third-party/include/opencv2/core/mat.inl.hpp +2753 -0
  511. package/third-party/include/opencv2/core/matx.hpp +603 -0
  512. package/third-party/include/opencv2/core/matx.inl.hpp +1132 -0
  513. package/third-party/include/opencv2/core/neon_utils.hpp +127 -0
  514. package/third-party/include/opencv2/core/operations.hpp +610 -0
  515. package/third-party/include/opencv2/core/optim.hpp +362 -0
  516. package/third-party/include/opencv2/core/parallel/backend/parallel_for.openmp.hpp +66 -0
  517. package/third-party/include/opencv2/core/parallel/backend/parallel_for.tbb.hpp +148 -0
  518. package/third-party/include/opencv2/core/parallel/parallel_backend.hpp +108 -0
  519. package/third-party/include/opencv2/core/persistence.hpp +1321 -0
  520. package/third-party/include/opencv2/core/quaternion.hpp +1889 -0
  521. package/third-party/include/opencv2/core/quaternion.inl.hpp +907 -0
  522. package/third-party/include/opencv2/core/saturate.hpp +347 -0
  523. package/third-party/include/opencv2/core/simd_intrinsics.hpp +90 -0
  524. package/third-party/include/opencv2/core/softfloat.hpp +657 -0
  525. package/third-party/include/opencv2/core/sse_utils.hpp +861 -0
  526. package/third-party/include/opencv2/core/traits.hpp +417 -0
  527. package/third-party/include/opencv2/core/types.hpp +2368 -0
  528. package/third-party/include/opencv2/core/types_c.h +2064 -0
  529. package/third-party/include/opencv2/core/utility.hpp +1296 -0
  530. package/third-party/include/opencv2/core/utils/allocator_stats.hpp +31 -0
  531. package/third-party/include/opencv2/core/utils/allocator_stats.impl.hpp +111 -0
  532. package/third-party/include/opencv2/core/utils/filesystem.hpp +91 -0
  533. package/third-party/include/opencv2/core/utils/fp_control_utils.hpp +70 -0
  534. package/third-party/include/opencv2/core/utils/instrumentation.hpp +127 -0
  535. package/third-party/include/opencv2/core/utils/logger.defines.hpp +50 -0
  536. package/third-party/include/opencv2/core/utils/logger.hpp +258 -0
  537. package/third-party/include/opencv2/core/utils/logtag.hpp +27 -0
  538. package/third-party/include/opencv2/core/utils/tls.hpp +230 -0
  539. package/third-party/include/opencv2/core/utils/trace.hpp +281 -0
  540. package/third-party/include/opencv2/core/version.hpp +29 -0
  541. package/third-party/include/opencv2/core/vsx_utils.hpp +1115 -0
  542. package/third-party/include/opencv2/core.hpp +3699 -0
  543. package/third-party/include/opencv2/cvconfig.h +155 -0
  544. package/third-party/include/opencv2/dnn/dnn.hpp +51 -0
  545. package/third-party/include/opencv2/dnn.hpp +17 -0
  546. package/third-party/include/opencv2/features2d/features2d.hpp +55 -0
  547. package/third-party/include/opencv2/features2d/hal/interface.h +32 -0
  548. package/third-party/include/opencv2/features2d.hpp +1756 -0
  549. package/third-party/include/opencv2/highgui/highgui.hpp +113 -0
  550. package/third-party/include/opencv2/highgui.hpp +17 -0
  551. package/third-party/include/opencv2/imgproc/bindings.hpp +34 -0
  552. package/third-party/include/opencv2/imgproc/detail/gcgraph.hpp +355 -0
  553. package/third-party/include/opencv2/imgproc/detail/legacy.hpp +35 -0
  554. package/third-party/include/opencv2/imgproc/hal/hal.hpp +246 -0
  555. package/third-party/include/opencv2/imgproc/hal/interface.h +52 -0
  556. package/third-party/include/opencv2/imgproc/imgproc.hpp +55 -0
  557. package/third-party/include/opencv2/imgproc/imgproc_c.h +1261 -0
  558. package/third-party/include/opencv2/imgproc/segmentation.hpp +168 -0
  559. package/third-party/include/opencv2/imgproc/types_c.h +632 -0
  560. package/third-party/include/opencv2/imgproc.hpp +5956 -0
  561. package/third-party/include/opencv2/opencv.hpp +102 -0
  562. package/third-party/include/opencv2/opencv_modules.hpp +19 -0
  563. package/third-party/include/opencv2/photo/legacy/constants_c.h +10 -0
  564. package/third-party/include/opencv2/photo/photo.hpp +55 -0
  565. package/third-party/include/opencv2/photo.hpp +975 -0
  566. package/third-party/include/opencv2/video/background_segm.hpp +341 -0
  567. package/third-party/include/opencv2/video/detail/tracking.detail.hpp +435 -0
  568. package/third-party/include/opencv2/video/legacy/constants_c.h +15 -0
  569. package/third-party/include/opencv2/video/tracking.hpp +1014 -0
  570. package/third-party/include/opencv2/video/video.hpp +55 -0
  571. package/third-party/include/opencv2/video.hpp +65 -0
  572. package/third-party/include/tokenizers-cpp/tokenizers_c.h +61 -0
  573. package/third-party/include/tokenizers-cpp/tokenizers_cpp.h +118 -0
  574. package/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/ETModel.h +27 -0
  575. package/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/ETModel.mm +249 -0
  576. package/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/HuggingFaceTokenizer.h +14 -0
  577. package/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/HuggingFaceTokenizer.mm +80 -0
  578. package/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/LLaMARunner.h +32 -0
  579. package/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/LLaMARunner.mm +95 -0
  580. package/third-party/ios/ExecutorchLib/ExecutorchLib/InputType.h +12 -0
  581. package/third-party/ios/ExecutorchLib/ExecutorchLib/Utils.hpp +217 -0
  582. package/third-party/ios/ExecutorchLib/ExecutorchLib/model/Model.cpp +11 -0
  583. package/third-party/ios/ExecutorchLib/ExecutorchLib/model/Model.h +11 -0
  584. package/third-party/ios/ExecutorchLib/ExecutorchLib/runner/irunner.h +48 -0
  585. package/third-party/ios/ExecutorchLib/ExecutorchLib/runner/runner.cpp +278 -0
  586. package/third-party/ios/ExecutorchLib/ExecutorchLib/runner/runner.h +67 -0
  587. package/third-party/ios/ExecutorchLib/ExecutorchLib/runner/stats.h +164 -0
  588. package/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_decoder_runner.cpp +65 -0
  589. package/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_decoder_runner.h +105 -0
  590. package/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_prefiller.cpp +91 -0
  591. package/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_prefiller.h +51 -0
  592. package/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_token_generator.h +162 -0
  593. package/third-party/ios/ExecutorchLib/ExecutorchLib/runner/util.h +108 -0
  594. package/third-party/ios/ExecutorchLib/ExecutorchLib/sampler/sampler.cpp +193 -0
  595. package/third-party/ios/ExecutorchLib/ExecutorchLib/sampler/sampler.h +64 -0
  596. package/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/base64.h +202 -0
  597. package/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/bpe_tokenizer.cpp +313 -0
  598. package/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/bpe_tokenizer.h +57 -0
  599. package/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/llama_tiktoken.cpp +78 -0
  600. package/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/llama_tiktoken.h +23 -0
  601. package/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/tiktoken.cpp +427 -0
  602. package/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/tiktoken.h +87 -0
  603. package/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/tokenizer.h +76 -0
  604. package/third-party/ios/ExecutorchLib/ExecutorchLib.xcodeproj/project.pbxproj +683 -0
  605. package/third-party/ios/ExecutorchLib/ExecutorchLib.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  606. package/third-party/ios/ExecutorchLib/ExecutorchLib.xcodeproj/project.xcworkspace/xcuserdata/norbertklockiewicz.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  607. package/third-party/ios/ExecutorchLib/ExecutorchLib.xcodeproj/xcuserdata/norbertklockiewicz.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  608. package/third-party/ios/ExecutorchLib/build.sh +44 -0
  609. package/third-party/ios/ExecutorchLib/frameworks/backend_coreml.xcframework/Info.plist +43 -0
  610. package/third-party/ios/ExecutorchLib/frameworks/backend_coreml.xcframework/ios-arm64/libbackend_coreml_ios.a +0 -0
  611. package/third-party/ios/ExecutorchLib/frameworks/backend_coreml.xcframework/ios-arm64-simulator/libbackend_coreml_simulator.a +0 -0
  612. package/third-party/ios/ExecutorchLib/frameworks/backend_mps.xcframework/Info.plist +43 -0
  613. package/third-party/ios/ExecutorchLib/frameworks/backend_mps.xcframework/ios-arm64/libbackend_mps_ios.a +0 -0
  614. package/third-party/ios/ExecutorchLib/frameworks/backend_mps.xcframework/ios-arm64-simulator/libbackend_mps_simulator.a +0 -0
  615. package/third-party/ios/ExecutorchLib/frameworks/backend_xnnpack.xcframework/Info.plist +43 -0
  616. package/third-party/ios/ExecutorchLib/frameworks/backend_xnnpack.xcframework/ios-arm64/libbackend_xnnpack_ios.a +0 -0
  617. package/third-party/ios/ExecutorchLib/frameworks/backend_xnnpack.xcframework/ios-arm64-simulator/libbackend_xnnpack_simulator.a +0 -0
  618. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/Info.plist +47 -0
  619. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/c10/macros/Export.h +163 -0
  620. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/c10/macros/Macros.h +497 -0
  621. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/c10/util/BFloat16-inl.h +342 -0
  622. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/c10/util/BFloat16-math.h +266 -0
  623. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/c10/util/BFloat16.h +125 -0
  624. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/c10/util/Half-inl.h +347 -0
  625. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/c10/util/Half.h +416 -0
  626. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/c10/util/TypeSafeSignMath.h +133 -0
  627. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/c10/util/bit_cast.h +43 -0
  628. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/c10/util/floating_point_utils.h +33 -0
  629. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/c10/util/irange.h +107 -0
  630. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/ExecuTorch.h +13 -0
  631. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/ExecuTorchError.h +16 -0
  632. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/ExecuTorchLog.h +76 -0
  633. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/ExecuTorchModule.h +286 -0
  634. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/ExecuTorchTensor.h +742 -0
  635. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/ExecuTorchValue.h +219 -0
  636. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/extension/module/module.h +492 -0
  637. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/extension/tensor/tensor.h +13 -0
  638. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/extension/tensor/tensor_accessor.h +190 -0
  639. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/extension/tensor/tensor_ptr.h +347 -0
  640. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/extension/tensor/tensor_ptr_maker.h +653 -0
  641. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/backend/backend_execution_context.h +71 -0
  642. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/backend/backend_init_context.h +72 -0
  643. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/backend/interface.h +166 -0
  644. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/array_ref.h +235 -0
  645. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/data_loader.h +136 -0
  646. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/defines.h +20 -0
  647. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/error.h +229 -0
  648. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/evalue.h +521 -0
  649. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/event_tracer.h +565 -0
  650. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/event_tracer_hooks.h +323 -0
  651. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/event_tracer_hooks_delegate.h +197 -0
  652. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/exec_aten.h +147 -0
  653. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/util/dim_order_util.h +263 -0
  654. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/util/scalar_type_util.h +1331 -0
  655. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/util/tensor_dimension_limit.h +21 -0
  656. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/util/tensor_shape_to_c_string.h +69 -0
  657. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/util/tensor_util.h +1250 -0
  658. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/freeable_buffer.h +107 -0
  659. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/hierarchical_allocator.h +107 -0
  660. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/memory_allocator.h +198 -0
  661. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/named_data_map.h +86 -0
  662. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/bfloat16.h +27 -0
  663. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/bfloat16_math.h +14 -0
  664. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/bits_types.h +83 -0
  665. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/c10/c10/macros/Export.h +163 -0
  666. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/c10/c10/macros/Macros.h +497 -0
  667. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-inl.h +342 -0
  668. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-math.h +266 -0
  669. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/c10/c10/util/BFloat16.h +125 -0
  670. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/c10/c10/util/Half-inl.h +347 -0
  671. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/c10/c10/util/Half.h +416 -0
  672. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/c10/c10/util/TypeSafeSignMath.h +133 -0
  673. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/c10/c10/util/bit_cast.h +43 -0
  674. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/c10/c10/util/floating_point_utils.h +33 -0
  675. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/c10/c10/util/irange.h +107 -0
  676. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/complex.h +44 -0
  677. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/device.h +70 -0
  678. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/half.h +27 -0
  679. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/optional.h +36 -0
  680. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/qint_types.h +83 -0
  681. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/scalar.h +110 -0
  682. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/scalar_type.h +154 -0
  683. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/string_view.h +29 -0
  684. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/tensor.h +142 -0
  685. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/tensor_impl.h +261 -0
  686. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/tensor_options.h +60 -0
  687. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/result.h +258 -0
  688. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/span.h +93 -0
  689. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/tag.h +71 -0
  690. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/tensor_layout.h +79 -0
  691. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/tensor_shape_dynamism.h +39 -0
  692. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/memory_manager.h +113 -0
  693. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/method.h +387 -0
  694. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/method_meta.h +251 -0
  695. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/program.h +320 -0
  696. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/pte_data_map.h +144 -0
  697. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/tensor_parser.h +156 -0
  698. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/kernel/kernel_runtime_context.h +122 -0
  699. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/kernel/operator_registry.h +278 -0
  700. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/abort.h +36 -0
  701. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/assert.h +119 -0
  702. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/clock.h +43 -0
  703. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/compat_unistd.h +75 -0
  704. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/compiler.h +191 -0
  705. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/log.h +177 -0
  706. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/platform.h +133 -0
  707. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/profiler.h +292 -0
  708. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/runtime.h +35 -0
  709. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/system.h +49 -0
  710. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/types.h +24 -0
  711. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/schema/extended_header.h +76 -0
  712. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/module.modulemap +5 -0
  713. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/libexecutorch_ios.a +0 -0
  714. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/c10/macros/Export.h +163 -0
  715. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/c10/macros/Macros.h +497 -0
  716. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/c10/util/BFloat16-inl.h +342 -0
  717. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/c10/util/BFloat16-math.h +266 -0
  718. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/c10/util/BFloat16.h +125 -0
  719. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/c10/util/Half-inl.h +347 -0
  720. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/c10/util/Half.h +416 -0
  721. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/c10/util/TypeSafeSignMath.h +133 -0
  722. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/c10/util/bit_cast.h +43 -0
  723. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/c10/util/floating_point_utils.h +33 -0
  724. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/c10/util/irange.h +107 -0
  725. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/ExecuTorch.h +13 -0
  726. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/ExecuTorchError.h +16 -0
  727. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/ExecuTorchLog.h +76 -0
  728. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/ExecuTorchModule.h +286 -0
  729. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/ExecuTorchTensor.h +742 -0
  730. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/ExecuTorchValue.h +219 -0
  731. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/extension/module/module.h +492 -0
  732. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/extension/tensor/tensor.h +13 -0
  733. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/extension/tensor/tensor_accessor.h +190 -0
  734. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/extension/tensor/tensor_ptr.h +347 -0
  735. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/extension/tensor/tensor_ptr_maker.h +653 -0
  736. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/backend/backend_execution_context.h +71 -0
  737. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/backend/backend_init_context.h +72 -0
  738. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/backend/interface.h +166 -0
  739. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/array_ref.h +235 -0
  740. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/data_loader.h +136 -0
  741. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/defines.h +20 -0
  742. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/error.h +229 -0
  743. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/evalue.h +521 -0
  744. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/event_tracer.h +565 -0
  745. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/event_tracer_hooks.h +323 -0
  746. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/event_tracer_hooks_delegate.h +197 -0
  747. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/exec_aten.h +147 -0
  748. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/util/dim_order_util.h +263 -0
  749. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/util/scalar_type_util.h +1331 -0
  750. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/util/tensor_dimension_limit.h +21 -0
  751. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/util/tensor_shape_to_c_string.h +69 -0
  752. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/util/tensor_util.h +1250 -0
  753. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/freeable_buffer.h +107 -0
  754. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/hierarchical_allocator.h +107 -0
  755. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/memory_allocator.h +198 -0
  756. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/named_data_map.h +86 -0
  757. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/bfloat16.h +27 -0
  758. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/bfloat16_math.h +14 -0
  759. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/bits_types.h +83 -0
  760. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/c10/c10/macros/Export.h +163 -0
  761. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/c10/c10/macros/Macros.h +497 -0
  762. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-inl.h +342 -0
  763. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-math.h +266 -0
  764. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/c10/c10/util/BFloat16.h +125 -0
  765. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/c10/c10/util/Half-inl.h +347 -0
  766. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/c10/c10/util/Half.h +416 -0
  767. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/c10/c10/util/TypeSafeSignMath.h +133 -0
  768. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/c10/c10/util/bit_cast.h +43 -0
  769. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/c10/c10/util/floating_point_utils.h +33 -0
  770. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/c10/c10/util/irange.h +107 -0
  771. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/complex.h +44 -0
  772. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/device.h +70 -0
  773. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/half.h +27 -0
  774. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/optional.h +36 -0
  775. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/qint_types.h +83 -0
  776. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/scalar.h +110 -0
  777. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/scalar_type.h +154 -0
  778. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/string_view.h +29 -0
  779. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/tensor.h +142 -0
  780. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/tensor_impl.h +261 -0
  781. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/tensor_options.h +60 -0
  782. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/result.h +258 -0
  783. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/span.h +93 -0
  784. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/tag.h +71 -0
  785. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/tensor_layout.h +79 -0
  786. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/tensor_shape_dynamism.h +39 -0
  787. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/memory_manager.h +113 -0
  788. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/method.h +387 -0
  789. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/method_meta.h +251 -0
  790. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/program.h +320 -0
  791. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/pte_data_map.h +144 -0
  792. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/tensor_parser.h +156 -0
  793. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/kernel/kernel_runtime_context.h +122 -0
  794. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/kernel/operator_registry.h +278 -0
  795. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/abort.h +36 -0
  796. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/assert.h +119 -0
  797. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/clock.h +43 -0
  798. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/compat_unistd.h +75 -0
  799. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/compiler.h +191 -0
  800. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/log.h +177 -0
  801. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/platform.h +133 -0
  802. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/profiler.h +292 -0
  803. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/runtime.h +35 -0
  804. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/system.h +49 -0
  805. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/types.h +24 -0
  806. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/schema/extended_header.h +76 -0
  807. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/module.modulemap +5 -0
  808. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/libexecutorch_simulator.a +0 -0
  809. package/third-party/ios/ExecutorchLib/frameworks/kernels_custom.xcframework/Info.plist +43 -0
  810. package/third-party/ios/ExecutorchLib/frameworks/kernels_custom.xcframework/ios-arm64/libkernels_custom_ios.a +0 -0
  811. package/third-party/ios/ExecutorchLib/frameworks/kernels_custom.xcframework/ios-arm64-simulator/libkernels_custom_simulator.a +0 -0
  812. package/third-party/ios/ExecutorchLib/frameworks/kernels_optimized.xcframework/Info.plist +43 -0
  813. package/third-party/ios/ExecutorchLib/frameworks/kernels_optimized.xcframework/ios-arm64/libkernels_optimized_ios.a +0 -0
  814. package/third-party/ios/ExecutorchLib/frameworks/kernels_optimized.xcframework/ios-arm64-simulator/libkernels_optimized_simulator.a +0 -0
  815. package/third-party/ios/ExecutorchLib/frameworks/kernels_portable.xcframework/Info.plist +43 -0
  816. package/third-party/ios/ExecutorchLib/frameworks/kernels_portable.xcframework/ios-arm64/libkernels_portable_ios.a +0 -0
  817. package/third-party/ios/ExecutorchLib/frameworks/kernels_portable.xcframework/ios-arm64-simulator/libkernels_portable_simulator.a +0 -0
  818. package/third-party/ios/ExecutorchLib/frameworks/kernels_quantized.xcframework/Info.plist +43 -0
  819. package/third-party/ios/ExecutorchLib/frameworks/kernels_quantized.xcframework/ios-arm64/libkernels_quantized_ios.a +0 -0
  820. package/third-party/ios/ExecutorchLib/frameworks/kernels_quantized.xcframework/ios-arm64-simulator/libkernels_quantized_simulator.a +0 -0
  821. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/Info.plist +43 -0
  822. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/bitmap256.h +82 -0
  823. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/filtered_re2.h +111 -0
  824. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/pod_array.h +43 -0
  825. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/prefilter.h +130 -0
  826. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/prefilter_tree.h +139 -0
  827. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/prog.h +483 -0
  828. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/re2.h +994 -0
  829. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/regexp.h +692 -0
  830. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/set.h +85 -0
  831. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/sparse_array.h +367 -0
  832. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/sparse_set.h +241 -0
  833. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/stringpiece.h +205 -0
  834. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/unicode_casefold.h +78 -0
  835. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/unicode_groups.h +64 -0
  836. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/walker-inl.h +235 -0
  837. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Info.plist +26 -0
  838. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/re2 +0 -0
  839. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/bitmap256.h +82 -0
  840. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/filtered_re2.h +111 -0
  841. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/pod_array.h +43 -0
  842. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/prefilter.h +130 -0
  843. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/prefilter_tree.h +139 -0
  844. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/prog.h +483 -0
  845. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/re2.h +994 -0
  846. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/regexp.h +692 -0
  847. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/set.h +85 -0
  848. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/sparse_array.h +367 -0
  849. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/sparse_set.h +241 -0
  850. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/stringpiece.h +205 -0
  851. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/unicode_casefold.h +78 -0
  852. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/unicode_groups.h +64 -0
  853. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/walker-inl.h +235 -0
  854. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Info.plist +26 -0
  855. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/re2 +0 -0
  856. package/third-party/ios/ios.toolchain.cmake +1122 -0
  857. package/LICENSE +0 -79
  858. package/README.md +0 -148
  859. package/android/src/main/java/com/swmansion/rnexecutorch/Classification.kt +0 -64
  860. package/android/src/main/java/com/swmansion/rnexecutorch/ETModule.kt +0 -90
  861. package/android/src/main/java/com/swmansion/rnexecutorch/ImageSegmentation.kt +0 -58
  862. package/android/src/main/java/com/swmansion/rnexecutorch/OCR.kt +0 -90
  863. package/android/src/main/java/com/swmansion/rnexecutorch/ObjectDetection.kt +0 -64
  864. package/android/src/main/java/com/swmansion/rnexecutorch/SpeechToText.kt +0 -91
  865. package/android/src/main/java/com/swmansion/rnexecutorch/StyleTransfer.kt +0 -54
  866. package/android/src/main/java/com/swmansion/rnexecutorch/TextEmbeddings.kt +0 -51
  867. package/android/src/main/java/com/swmansion/rnexecutorch/Tokenizer.kt +0 -86
  868. package/android/src/main/java/com/swmansion/rnexecutorch/VerticalOCR.kt +0 -179
  869. package/android/src/main/java/com/swmansion/rnexecutorch/models/BaseModel.kt +0 -54
  870. package/android/src/main/java/com/swmansion/rnexecutorch/models/TextEmbeddings/TextEmbeddingsModel.kt +0 -48
  871. package/android/src/main/java/com/swmansion/rnexecutorch/models/TextEmbeddings/TextEmbeddingsUtils.kt +0 -37
  872. package/android/src/main/java/com/swmansion/rnexecutorch/models/classification/ClassificationModel.kt +0 -46
  873. package/android/src/main/java/com/swmansion/rnexecutorch/models/classification/Constants.kt +0 -1005
  874. package/android/src/main/java/com/swmansion/rnexecutorch/models/imageSegmentation/Constants.kt +0 -26
  875. package/android/src/main/java/com/swmansion/rnexecutorch/models/imageSegmentation/ImageSegmentationModel.kt +0 -142
  876. package/android/src/main/java/com/swmansion/rnexecutorch/models/objectDetection/SSDLiteLargeModel.kt +0 -74
  877. package/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/Detector.kt +0 -82
  878. package/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/RecognitionHandler.kt +0 -117
  879. package/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/Recognizer.kt +0 -51
  880. package/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/VerticalDetector.kt +0 -89
  881. package/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/CTCLabelConverter.kt +0 -58
  882. package/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/Constants.kt +0 -31
  883. package/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/DetectorUtils.kt +0 -608
  884. package/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/RecognizerUtils.kt +0 -430
  885. package/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/BaseS2TDecoder.kt +0 -39
  886. package/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/BaseS2TModule.kt +0 -43
  887. package/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/Moonshine.kt +0 -16
  888. package/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/MoonshineDecoder.kt +0 -23
  889. package/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/MoonshineEncoder.kt +0 -20
  890. package/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/Whisper.kt +0 -16
  891. package/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/WhisperDecoder.kt +0 -22
  892. package/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/WhisperEncoder.kt +0 -29
  893. package/android/src/main/java/com/swmansion/rnexecutorch/models/styleTransfer/StyleTransferModel.kt +0 -43
  894. package/android/src/main/java/com/swmansion/rnexecutorch/utils/ArrayUtils.kt +0 -87
  895. package/android/src/main/java/com/swmansion/rnexecutorch/utils/ETError.kt +0 -34
  896. package/android/src/main/java/com/swmansion/rnexecutorch/utils/ImageProcessor.kt +0 -237
  897. package/android/src/main/java/com/swmansion/rnexecutorch/utils/Numerical.kt +0 -8
  898. package/android/src/main/java/com/swmansion/rnexecutorch/utils/ObjectDetectionUtils.kt +0 -201
  899. package/android/src/main/java/com/swmansion/rnexecutorch/utils/STFT.kt +0 -50
  900. package/android/src/main/java/com/swmansion/rnexecutorch/utils/TensorUtils.kt +0 -103
  901. package/ios/RnExecutorch/Classification.h +0 -5
  902. package/ios/RnExecutorch/Classification.mm +0 -54
  903. package/ios/RnExecutorch/ETModule.h +0 -5
  904. package/ios/RnExecutorch/ETModule.mm +0 -75
  905. package/ios/RnExecutorch/ImageSegmentation.h +0 -5
  906. package/ios/RnExecutorch/ImageSegmentation.mm +0 -60
  907. package/ios/RnExecutorch/OCR.h +0 -5
  908. package/ios/RnExecutorch/OCR.mm +0 -96
  909. package/ios/RnExecutorch/ObjectDetection.h +0 -5
  910. package/ios/RnExecutorch/ObjectDetection.mm +0 -56
  911. package/ios/RnExecutorch/SpeechToText.h +0 -5
  912. package/ios/RnExecutorch/SpeechToText.mm +0 -125
  913. package/ios/RnExecutorch/StyleTransfer.h +0 -5
  914. package/ios/RnExecutorch/StyleTransfer.mm +0 -55
  915. package/ios/RnExecutorch/TextEmbeddings.h +0 -5
  916. package/ios/RnExecutorch/TextEmbeddings.mm +0 -62
  917. package/ios/RnExecutorch/Tokenizer.h +0 -5
  918. package/ios/RnExecutorch/Tokenizer.mm +0 -83
  919. package/ios/RnExecutorch/VerticalOCR.h +0 -5
  920. package/ios/RnExecutorch/VerticalOCR.mm +0 -183
  921. package/ios/RnExecutorch/models/BaseModel.h +0 -21
  922. package/ios/RnExecutorch/models/BaseModel.mm +0 -43
  923. package/ios/RnExecutorch/models/classification/ClassificationModel.h +0 -10
  924. package/ios/RnExecutorch/models/classification/ClassificationModel.mm +0 -53
  925. package/ios/RnExecutorch/models/classification/Constants.h +0 -3
  926. package/ios/RnExecutorch/models/image_segmentation/Constants.h +0 -4
  927. package/ios/RnExecutorch/models/image_segmentation/ImageSegmentationModel.h +0 -10
  928. package/ios/RnExecutorch/models/image_segmentation/ImageSegmentationModel.mm +0 -146
  929. package/ios/RnExecutorch/models/object_detection/SSDLiteLargeModel.hpp +0 -11
  930. package/ios/RnExecutorch/models/object_detection/SSDLiteLargeModel.mm +0 -64
  931. package/ios/RnExecutorch/models/ocr/Detector.h +0 -9
  932. package/ios/RnExecutorch/models/ocr/Detector.mm +0 -101
  933. package/ios/RnExecutorch/models/ocr/RecognitionHandler.h +0 -16
  934. package/ios/RnExecutorch/models/ocr/RecognitionHandler.mm +0 -135
  935. package/ios/RnExecutorch/models/ocr/Recognizer.h +0 -8
  936. package/ios/RnExecutorch/models/ocr/Recognizer.mm +0 -77
  937. package/ios/RnExecutorch/models/ocr/VerticalDetector.h +0 -10
  938. package/ios/RnExecutorch/models/ocr/VerticalDetector.mm +0 -118
  939. package/ios/RnExecutorch/models/ocr/utils/CTCLabelConverter.h +0 -16
  940. package/ios/RnExecutorch/models/ocr/utils/CTCLabelConverter.mm +0 -80
  941. package/ios/RnExecutorch/models/ocr/utils/Constants.h +0 -26
  942. package/ios/RnExecutorch/models/ocr/utils/DetectorUtils.h +0 -31
  943. package/ios/RnExecutorch/models/ocr/utils/DetectorUtils.mm +0 -754
  944. package/ios/RnExecutorch/models/ocr/utils/OCRUtils.h +0 -10
  945. package/ios/RnExecutorch/models/ocr/utils/OCRUtils.mm +0 -67
  946. package/ios/RnExecutorch/models/ocr/utils/RecognizerUtils.h +0 -35
  947. package/ios/RnExecutorch/models/ocr/utils/RecognizerUtils.mm +0 -331
  948. package/ios/RnExecutorch/models/stt/Moonshine.hpp +0 -13
  949. package/ios/RnExecutorch/models/stt/Moonshine.mm +0 -64
  950. package/ios/RnExecutorch/models/stt/MoonshineDecoder.hpp +0 -16
  951. package/ios/RnExecutorch/models/stt/MoonshineDecoder.mm +0 -24
  952. package/ios/RnExecutorch/models/stt/MoonshineEncoder.hpp +0 -15
  953. package/ios/RnExecutorch/models/stt/MoonshineEncoder.mm +0 -18
  954. package/ios/RnExecutorch/models/stt/SpeechToTextBaseModel.hpp +0 -26
  955. package/ios/RnExecutorch/models/stt/SpeechToTextBaseModel.mm +0 -19
  956. package/ios/RnExecutorch/models/stt/Whisper.hpp +0 -12
  957. package/ios/RnExecutorch/models/stt/Whisper.mm +0 -68
  958. package/ios/RnExecutorch/models/stt/WhisperDecoder.hpp +0 -16
  959. package/ios/RnExecutorch/models/stt/WhisperDecoder.mm +0 -22
  960. package/ios/RnExecutorch/models/stt/WhisperEncoder.hpp +0 -15
  961. package/ios/RnExecutorch/models/stt/WhisperEncoder.mm +0 -21
  962. package/ios/RnExecutorch/models/style_transfer/StyleTransferModel.h +0 -11
  963. package/ios/RnExecutorch/models/style_transfer/StyleTransferModel.mm +0 -50
  964. package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsModel.h +0 -15
  965. package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsModel.mm +0 -45
  966. package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsUtils.h +0 -8
  967. package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsUtils.mm +0 -49
  968. package/ios/RnExecutorch/utils/Constants.h +0 -8
  969. package/ios/RnExecutorch/utils/ObjectDetectionUtils.hpp +0 -23
  970. package/ios/RnExecutorch/utils/SFFT.hpp +0 -13
  971. package/ios/RnExecutorch/utils/SFFT.mm +0 -71
  972. package/lib/module/native/NativeClassification.js +0 -5
  973. package/lib/module/native/NativeClassification.js.map +0 -1
  974. package/lib/module/native/NativeETModule.js +0 -5
  975. package/lib/module/native/NativeETModule.js.map +0 -1
  976. package/lib/module/native/NativeImageSegmentation.js +0 -5
  977. package/lib/module/native/NativeImageSegmentation.js.map +0 -1
  978. package/lib/module/native/NativeOCR.js +0 -5
  979. package/lib/module/native/NativeOCR.js.map +0 -1
  980. package/lib/module/native/NativeObjectDetection.js +0 -5
  981. package/lib/module/native/NativeObjectDetection.js.map +0 -1
  982. package/lib/module/native/NativeSpeechToText.js +0 -5
  983. package/lib/module/native/NativeSpeechToText.js.map +0 -1
  984. package/lib/module/native/NativeStyleTransfer.js +0 -5
  985. package/lib/module/native/NativeStyleTransfer.js.map +0 -1
  986. package/lib/module/native/NativeTextEmbeddings.js +0 -5
  987. package/lib/module/native/NativeTextEmbeddings.js.map +0 -1
  988. package/lib/module/native/NativeTokenizer.js +0 -5
  989. package/lib/module/native/NativeTokenizer.js.map +0 -1
  990. package/lib/module/native/NativeVerticalOCR.js +0 -5
  991. package/lib/module/native/NativeVerticalOCR.js.map +0 -1
  992. package/lib/module/package.json +0 -1
  993. package/lib/typescript/native/NativeClassification.d.ts +0 -10
  994. package/lib/typescript/native/NativeClassification.d.ts.map +0 -1
  995. package/lib/typescript/native/NativeETModule.d.ts +0 -9
  996. package/lib/typescript/native/NativeETModule.d.ts.map +0 -1
  997. package/lib/typescript/native/NativeImageSegmentation.d.ts +0 -10
  998. package/lib/typescript/native/NativeImageSegmentation.d.ts.map +0 -1
  999. package/lib/typescript/native/NativeOCR.d.ts +0 -9
  1000. package/lib/typescript/native/NativeOCR.d.ts.map +0 -1
  1001. package/lib/typescript/native/NativeObjectDetection.d.ts +0 -9
  1002. package/lib/typescript/native/NativeObjectDetection.d.ts.map +0 -1
  1003. package/lib/typescript/native/NativeSpeechToText.d.ts +0 -12
  1004. package/lib/typescript/native/NativeSpeechToText.d.ts.map +0 -1
  1005. package/lib/typescript/native/NativeStyleTransfer.d.ts.map +0 -1
  1006. package/lib/typescript/native/NativeTextEmbeddings.d.ts +0 -8
  1007. package/lib/typescript/native/NativeTextEmbeddings.d.ts.map +0 -1
  1008. package/lib/typescript/native/NativeTokenizer.d.ts +0 -12
  1009. package/lib/typescript/native/NativeTokenizer.d.ts.map +0 -1
  1010. package/lib/typescript/native/NativeVerticalOCR.d.ts +0 -9
  1011. package/lib/typescript/native/NativeVerticalOCR.d.ts.map +0 -1
  1012. package/src/native/NativeClassification.ts +0 -9
  1013. package/src/native/NativeETModule.ts +0 -14
  1014. package/src/native/NativeImageSegmentation.ts +0 -14
  1015. package/src/native/NativeOCR.ts +0 -16
  1016. package/src/native/NativeObjectDetection.ts +0 -10
  1017. package/src/native/NativeSpeechToText.ts +0 -17
  1018. package/src/native/NativeStyleTransfer.ts +0 -10
  1019. package/src/native/NativeTextEmbeddings.ts +0 -9
  1020. package/src/native/NativeTokenizer.ts +0 -13
  1021. package/src/native/NativeVerticalOCR.ts +0 -16
@@ -0,0 +1,3528 @@
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
6
+ license.
7
+ // If you do not agree to this license, do not download, install,
8
+ // copy or use the software.
9
+ //
10
+ //
11
+ // License Agreement
12
+ // For Open Source Computer Vision Library
13
+ //
14
+ // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
15
+ // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
16
+ // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
17
+ // Copyright (C) 2015, Itseez Inc., all rights reserved.
18
+ // Third party copyrights are property of their respective owners.
19
+ //
20
+ // Redistribution and use in source and binary forms, with or without
21
+ modification,
22
+ // are permitted provided that the following conditions are met:
23
+ //
24
+ // * Redistribution's of source code must retain the above copyright notice,
25
+ // this list of conditions and the following disclaimer.
26
+ //
27
+ // * Redistribution's in binary form must reproduce the above copyright
28
+ notice,
29
+ // this list of conditions and the following disclaimer in the documentation
30
+ // and/or other materials provided with the distribution.
31
+ //
32
+ // * The name of the copyright holders may not be used to endorse or promote
33
+ products
34
+ // derived from this software without specific prior written permission.
35
+ //
36
+ // This software is provided by the copyright holders and contributors "as is"
37
+ and
38
+ // any express or implied warranties, including, but not limited to, the implied
39
+ // warranties of merchantability and fitness for a particular purpose are
40
+ disclaimed.
41
+ // In no event shall the Intel Corporation or contributors be liable for any
42
+ direct,
43
+ // indirect, incidental, special, exemplary, or consequential damages
44
+ // (including, but not limited to, procurement of substitute goods or services;
45
+ // loss of use, data, or profits; or business interruption) however caused
46
+ // and on any theory of liability, whether in contract, strict liability,
47
+ // or tort (including negligence or otherwise) arising in any way out of
48
+ // the use of this software, even if advised of the possibility of such damage.
49
+ //
50
+ //M*/
51
+
52
+ #ifndef OPENCV_HAL_SSE_HPP
53
+ #define OPENCV_HAL_SSE_HPP
54
+
55
+ #include "opencv2/core/utility.hpp"
56
+ #include <algorithm>
57
+
58
+ #define CV_SIMD128 1
59
+ #define CV_SIMD128_64F 1
60
+ #define CV_SIMD128_FP16 0 // no native operations with FP16 type.
61
+
62
+ namespace cv {
63
+
64
+ //! @cond IGNORED
65
+
66
+ //
67
+ // Compilation troubleshooting:
68
+ // - MSVC: error C2719: 'a': formal parameter with requested alignment of 16
69
+ // won't be aligned
70
+ // Replace parameter declaration to const reference:
71
+ // -v_int32x4 a
72
+ // +const v_int32x4& a
73
+ //
74
+
75
+ CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN
76
+
77
+ ///////// Types ////////////
78
+
79
+ struct v_uint8x16 {
80
+ typedef uchar lane_type;
81
+ typedef __m128i vector_type;
82
+ enum { nlanes = 16 };
83
+
84
+ /* coverity[uninit_ctor]: suppress warning */
85
+ v_uint8x16() {}
86
+ explicit v_uint8x16(__m128i v) : val(v) {}
87
+ v_uint8x16(uchar v0, uchar v1, uchar v2, uchar v3, uchar v4, uchar v5,
88
+ uchar v6, uchar v7, uchar v8, uchar v9, uchar v10, uchar v11,
89
+ uchar v12, uchar v13, uchar v14, uchar v15) {
90
+ val = _mm_setr_epi8((char)v0, (char)v1, (char)v2, (char)v3, (char)v4,
91
+ (char)v5, (char)v6, (char)v7, (char)v8, (char)v9,
92
+ (char)v10, (char)v11, (char)v12, (char)v13, (char)v14,
93
+ (char)v15);
94
+ }
95
+
96
+ uchar get0() const { return (uchar)_mm_cvtsi128_si32(val); }
97
+
98
+ __m128i val;
99
+ };
100
+
101
+ struct v_int8x16 {
102
+ typedef schar lane_type;
103
+ typedef __m128i vector_type;
104
+ enum { nlanes = 16 };
105
+
106
+ /* coverity[uninit_ctor]: suppress warning */
107
+ v_int8x16() {}
108
+ explicit v_int8x16(__m128i v) : val(v) {}
109
+ v_int8x16(schar v0, schar v1, schar v2, schar v3, schar v4, schar v5,
110
+ schar v6, schar v7, schar v8, schar v9, schar v10, schar v11,
111
+ schar v12, schar v13, schar v14, schar v15) {
112
+ val = _mm_setr_epi8((char)v0, (char)v1, (char)v2, (char)v3, (char)v4,
113
+ (char)v5, (char)v6, (char)v7, (char)v8, (char)v9,
114
+ (char)v10, (char)v11, (char)v12, (char)v13, (char)v14,
115
+ (char)v15);
116
+ }
117
+
118
+ schar get0() const { return (schar)_mm_cvtsi128_si32(val); }
119
+
120
+ __m128i val;
121
+ };
122
+
123
+ struct v_uint16x8 {
124
+ typedef ushort lane_type;
125
+ typedef __m128i vector_type;
126
+ enum { nlanes = 8 };
127
+
128
+ /* coverity[uninit_ctor]: suppress warning */
129
+ v_uint16x8() {}
130
+ explicit v_uint16x8(__m128i v) : val(v) {}
131
+ v_uint16x8(ushort v0, ushort v1, ushort v2, ushort v3, ushort v4, ushort v5,
132
+ ushort v6, ushort v7) {
133
+ val = _mm_setr_epi16((short)v0, (short)v1, (short)v2, (short)v3, (short)v4,
134
+ (short)v5, (short)v6, (short)v7);
135
+ }
136
+
137
+ ushort get0() const { return (ushort)_mm_cvtsi128_si32(val); }
138
+
139
+ __m128i val;
140
+ };
141
+
142
+ struct v_int16x8 {
143
+ typedef short lane_type;
144
+ typedef __m128i vector_type;
145
+ enum { nlanes = 8 };
146
+
147
+ /* coverity[uninit_ctor]: suppress warning */
148
+ v_int16x8() {}
149
+ explicit v_int16x8(__m128i v) : val(v) {}
150
+ v_int16x8(short v0, short v1, short v2, short v3, short v4, short v5,
151
+ short v6, short v7) {
152
+ val = _mm_setr_epi16((short)v0, (short)v1, (short)v2, (short)v3, (short)v4,
153
+ (short)v5, (short)v6, (short)v7);
154
+ }
155
+
156
+ short get0() const { return (short)_mm_cvtsi128_si32(val); }
157
+
158
+ __m128i val;
159
+ };
160
+
161
+ struct v_uint32x4 {
162
+ typedef unsigned lane_type;
163
+ typedef __m128i vector_type;
164
+ enum { nlanes = 4 };
165
+
166
+ /* coverity[uninit_ctor]: suppress warning */
167
+ v_uint32x4() {}
168
+ explicit v_uint32x4(__m128i v) : val(v) {}
169
+ v_uint32x4(unsigned v0, unsigned v1, unsigned v2, unsigned v3) {
170
+ val = _mm_setr_epi32((int)v0, (int)v1, (int)v2, (int)v3);
171
+ }
172
+
173
+ unsigned get0() const { return (unsigned)_mm_cvtsi128_si32(val); }
174
+
175
+ __m128i val;
176
+ };
177
+
178
+ struct v_int32x4 {
179
+ typedef int lane_type;
180
+ typedef __m128i vector_type;
181
+ enum { nlanes = 4 };
182
+
183
+ /* coverity[uninit_ctor]: suppress warning */
184
+ v_int32x4() {}
185
+ explicit v_int32x4(__m128i v) : val(v) {}
186
+ v_int32x4(int v0, int v1, int v2, int v3) {
187
+ val = _mm_setr_epi32(v0, v1, v2, v3);
188
+ }
189
+
190
+ int get0() const { return _mm_cvtsi128_si32(val); }
191
+
192
+ __m128i val;
193
+ };
194
+
195
+ struct v_float32x4 {
196
+ typedef float lane_type;
197
+ typedef __m128 vector_type;
198
+ enum { nlanes = 4 };
199
+
200
+ /* coverity[uninit_ctor]: suppress warning */
201
+ v_float32x4() {}
202
+ explicit v_float32x4(__m128 v) : val(v) {}
203
+ v_float32x4(float v0, float v1, float v2, float v3) {
204
+ val = _mm_setr_ps(v0, v1, v2, v3);
205
+ }
206
+
207
+ float get0() const { return _mm_cvtss_f32(val); }
208
+
209
+ __m128 val;
210
+ };
211
+
212
+ struct v_uint64x2 {
213
+ typedef uint64 lane_type;
214
+ typedef __m128i vector_type;
215
+ enum { nlanes = 2 };
216
+
217
+ /* coverity[uninit_ctor]: suppress warning */
218
+ v_uint64x2() {}
219
+ explicit v_uint64x2(__m128i v) : val(v) {}
220
+ v_uint64x2(uint64 v0, uint64 v1) {
221
+ #if defined(_MSC_VER) && _MSC_VER >= 1920 /*MSVS 2019*/ && defined(_M_X64) && \
222
+ !defined(__clang__)
223
+ val = _mm_setr_epi64x((int64_t)v0, (int64_t)v1);
224
+ #elif defined(__GNUC__)
225
+ val = _mm_setr_epi64((__m64)v0, (__m64)v1);
226
+ #else
227
+ val = _mm_setr_epi32((int)v0, (int)(v0 >> 32), (int)v1, (int)(v1 >> 32));
228
+ #endif
229
+ }
230
+
231
+ uint64 get0() const {
232
+ #if !defined(__x86_64__) && !defined(_M_X64)
233
+ int a = _mm_cvtsi128_si32(val);
234
+ int b = _mm_cvtsi128_si32(_mm_srli_epi64(val, 32));
235
+ return (unsigned)a | ((uint64)(unsigned)b << 32);
236
+ #else
237
+ return (uint64)_mm_cvtsi128_si64(val);
238
+ #endif
239
+ }
240
+
241
+ __m128i val;
242
+ };
243
+
244
+ struct v_int64x2 {
245
+ typedef int64 lane_type;
246
+ typedef __m128i vector_type;
247
+ enum { nlanes = 2 };
248
+
249
+ /* coverity[uninit_ctor]: suppress warning */
250
+ v_int64x2() {}
251
+ explicit v_int64x2(__m128i v) : val(v) {}
252
+ v_int64x2(int64 v0, int64 v1) {
253
+ #if defined(_MSC_VER) && _MSC_VER >= 1920 /*MSVS 2019*/ && defined(_M_X64) && \
254
+ !defined(__clang__)
255
+ val = _mm_setr_epi64x((int64_t)v0, (int64_t)v1);
256
+ #elif defined(__GNUC__)
257
+ val = _mm_setr_epi64((__m64)v0, (__m64)v1);
258
+ #else
259
+ val = _mm_setr_epi32((int)v0, (int)(v0 >> 32), (int)v1, (int)(v1 >> 32));
260
+ #endif
261
+ }
262
+
263
+ int64 get0() const {
264
+ #if !defined(__x86_64__) && !defined(_M_X64)
265
+ int a = _mm_cvtsi128_si32(val);
266
+ int b = _mm_cvtsi128_si32(_mm_srli_epi64(val, 32));
267
+ return (int64)((unsigned)a | ((uint64)(unsigned)b << 32));
268
+ #else
269
+ return _mm_cvtsi128_si64(val);
270
+ #endif
271
+ }
272
+
273
+ __m128i val;
274
+ };
275
+
276
+ struct v_float64x2 {
277
+ typedef double lane_type;
278
+ typedef __m128d vector_type;
279
+ enum { nlanes = 2 };
280
+
281
+ /* coverity[uninit_ctor]: suppress warning */
282
+ v_float64x2() {}
283
+ explicit v_float64x2(__m128d v) : val(v) {}
284
+ v_float64x2(double v0, double v1) { val = _mm_setr_pd(v0, v1); }
285
+
286
+ double get0() const { return _mm_cvtsd_f64(val); }
287
+
288
+ __m128d val;
289
+ };
290
+
291
+ namespace hal_sse_internal {
292
+ template <typename to_sse_type, typename from_sse_type>
293
+ to_sse_type v_sse_reinterpret_as(const from_sse_type &val);
294
+
295
+ #define OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(to_sse_type, from_sse_type, \
296
+ sse_cast_intrin) \
297
+ template <> \
298
+ inline to_sse_type v_sse_reinterpret_as(const from_sse_type &a) { \
299
+ return sse_cast_intrin(a); \
300
+ }
301
+
302
+ OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128i, __m128i, OPENCV_HAL_NOP)
303
+ OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128i, __m128, _mm_castps_si128)
304
+ OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128i, __m128d, _mm_castpd_si128)
305
+ OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128, __m128i, _mm_castsi128_ps)
306
+ OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128, __m128, OPENCV_HAL_NOP)
307
+ OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128, __m128d, _mm_castpd_ps)
308
+ OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128d, __m128i, _mm_castsi128_pd)
309
+ OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128d, __m128, _mm_castps_pd)
310
+ OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128d, __m128d, OPENCV_HAL_NOP)
311
+ } // namespace hal_sse_internal
312
+
313
+ #define OPENCV_HAL_IMPL_SSE_INITVEC(_Tpvec, _Tp, suffix, zsuffix, ssuffix, \
314
+ _Tps, cast) \
315
+ inline _Tpvec v_setzero_##suffix() { \
316
+ return _Tpvec(_mm_setzero_##zsuffix()); \
317
+ } \
318
+ inline _Tpvec v_setall_##suffix(_Tp v) { \
319
+ return _Tpvec(_mm_set1_##ssuffix((_Tps)v)); \
320
+ } \
321
+ template <> inline _Tpvec v_setzero_() { return v_setzero_##suffix(); } \
322
+ template <> inline _Tpvec v_setall_(_Tp v) { return v_setall_##suffix(v); } \
323
+ template <typename _Tpvec0> \
324
+ inline _Tpvec v_reinterpret_as_##suffix(const _Tpvec0 &a) { \
325
+ return _Tpvec(cast(a.val)); \
326
+ }
327
+
328
+ OPENCV_HAL_IMPL_SSE_INITVEC(v_uint8x16, uchar, u8, si128, epi8, schar,
329
+ OPENCV_HAL_NOP)
330
+ OPENCV_HAL_IMPL_SSE_INITVEC(v_int8x16, schar, s8, si128, epi8, schar,
331
+ OPENCV_HAL_NOP)
332
+ OPENCV_HAL_IMPL_SSE_INITVEC(v_uint16x8, ushort, u16, si128, epi16, short,
333
+ OPENCV_HAL_NOP)
334
+ OPENCV_HAL_IMPL_SSE_INITVEC(v_int16x8, short, s16, si128, epi16, short,
335
+ OPENCV_HAL_NOP)
336
+ OPENCV_HAL_IMPL_SSE_INITVEC(v_uint32x4, unsigned, u32, si128, epi32, int,
337
+ OPENCV_HAL_NOP)
338
+ OPENCV_HAL_IMPL_SSE_INITVEC(v_int32x4, int, s32, si128, epi32, int,
339
+ OPENCV_HAL_NOP)
340
+ OPENCV_HAL_IMPL_SSE_INITVEC(v_float32x4, float, f32, ps, ps, float,
341
+ _mm_castsi128_ps)
342
+ OPENCV_HAL_IMPL_SSE_INITVEC(v_float64x2, double, f64, pd, pd, double,
343
+ _mm_castsi128_pd)
344
+
345
+ inline v_uint64x2 v_setzero_u64() { return v_uint64x2(_mm_setzero_si128()); }
346
+ inline v_int64x2 v_setzero_s64() { return v_int64x2(_mm_setzero_si128()); }
347
+ inline v_uint64x2 v_setall_u64(uint64 val) { return v_uint64x2(val, val); }
348
+ inline v_int64x2 v_setall_s64(int64 val) { return v_int64x2(val, val); }
349
+
350
+ template <> inline v_uint64x2 v_setzero_() { return v_setzero_u64(); }
351
+ template <> inline v_int64x2 v_setzero_() { return v_setzero_s64(); }
352
+ template <> inline v_uint64x2 v_setall_(uint64 val) {
353
+ return v_setall_u64(val);
354
+ }
355
+ template <> inline v_int64x2 v_setall_(int64 val) { return v_setall_s64(val); }
356
+
357
+ template <typename _Tpvec>
358
+ inline v_uint64x2 v_reinterpret_as_u64(const _Tpvec &a) {
359
+ return v_uint64x2(a.val);
360
+ }
361
+ template <typename _Tpvec>
362
+ inline v_int64x2 v_reinterpret_as_s64(const _Tpvec &a) {
363
+ return v_int64x2(a.val);
364
+ }
365
+ inline v_float32x4 v_reinterpret_as_f32(const v_uint64x2 &a) {
366
+ return v_float32x4(_mm_castsi128_ps(a.val));
367
+ }
368
+ inline v_float32x4 v_reinterpret_as_f32(const v_int64x2 &a) {
369
+ return v_float32x4(_mm_castsi128_ps(a.val));
370
+ }
371
+ inline v_float64x2 v_reinterpret_as_f64(const v_uint64x2 &a) {
372
+ return v_float64x2(_mm_castsi128_pd(a.val));
373
+ }
374
+ inline v_float64x2 v_reinterpret_as_f64(const v_int64x2 &a) {
375
+ return v_float64x2(_mm_castsi128_pd(a.val));
376
+ }
377
+
378
+ #define OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(_Tpvec, suffix) \
379
+ inline _Tpvec v_reinterpret_as_##suffix(const v_float32x4 &a) { \
380
+ return _Tpvec(_mm_castps_si128(a.val)); \
381
+ } \
382
+ inline _Tpvec v_reinterpret_as_##suffix(const v_float64x2 &a) { \
383
+ return _Tpvec(_mm_castpd_si128(a.val)); \
384
+ }
385
+
386
+ OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_uint8x16, u8)
387
+ OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_int8x16, s8)
388
+ OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_uint16x8, u16)
389
+ OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_int16x8, s16)
390
+ OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_uint32x4, u32)
391
+ OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_int32x4, s32)
392
+ OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_uint64x2, u64)
393
+ OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_int64x2, s64)
394
+
395
+ inline v_float32x4 v_reinterpret_as_f32(const v_float32x4 &a) { return a; }
396
+ inline v_float64x2 v_reinterpret_as_f64(const v_float64x2 &a) { return a; }
397
+ inline v_float32x4 v_reinterpret_as_f32(const v_float64x2 &a) {
398
+ return v_float32x4(_mm_castpd_ps(a.val));
399
+ }
400
+ inline v_float64x2 v_reinterpret_as_f64(const v_float32x4 &a) {
401
+ return v_float64x2(_mm_castps_pd(a.val));
402
+ }
403
+
404
+ //////////////// PACK ///////////////
405
+ inline v_uint8x16 v_pack(const v_uint16x8 &a, const v_uint16x8 &b) {
406
+ __m128i delta = _mm_set1_epi16(255);
407
+ return v_uint8x16(
408
+ _mm_packus_epi16(_mm_subs_epu16(a.val, _mm_subs_epu16(a.val, delta)),
409
+ _mm_subs_epu16(b.val, _mm_subs_epu16(b.val, delta))));
410
+ }
411
+
412
+ inline void v_pack_store(uchar *ptr, const v_uint16x8 &a) {
413
+ __m128i delta = _mm_set1_epi16(255);
414
+ __m128i a1 = _mm_subs_epu16(a.val, _mm_subs_epu16(a.val, delta));
415
+ _mm_storel_epi64((__m128i *)ptr, _mm_packus_epi16(a1, a1));
416
+ }
417
+
418
+ inline v_uint8x16 v_pack_u(const v_int16x8 &a, const v_int16x8 &b) {
419
+ return v_uint8x16(_mm_packus_epi16(a.val, b.val));
420
+ }
421
+
422
+ inline void v_pack_u_store(uchar *ptr, const v_int16x8 &a) {
423
+ _mm_storel_epi64((__m128i *)ptr, _mm_packus_epi16(a.val, a.val));
424
+ }
425
+
426
+ template <int n>
427
+ inline v_uint8x16 v_rshr_pack(const v_uint16x8 &a, const v_uint16x8 &b) {
428
+ // we assume that n > 0, and so the shifted 16-bit values can be treated as
429
+ // signed numbers.
430
+ __m128i delta = _mm_set1_epi16((short)(1 << (n - 1)));
431
+ return v_uint8x16(
432
+ _mm_packus_epi16(_mm_srli_epi16(_mm_adds_epu16(a.val, delta), n),
433
+ _mm_srli_epi16(_mm_adds_epu16(b.val, delta), n)));
434
+ }
435
+
436
+ template <int n>
437
+ inline void v_rshr_pack_store(uchar *ptr, const v_uint16x8 &a) {
438
+ __m128i delta = _mm_set1_epi16((short)(1 << (n - 1)));
439
+ __m128i a1 = _mm_srli_epi16(_mm_adds_epu16(a.val, delta), n);
440
+ _mm_storel_epi64((__m128i *)ptr, _mm_packus_epi16(a1, a1));
441
+ }
442
+
443
+ template <int n>
444
+ inline v_uint8x16 v_rshr_pack_u(const v_int16x8 &a, const v_int16x8 &b) {
445
+ __m128i delta = _mm_set1_epi16((short)(1 << (n - 1)));
446
+ return v_uint8x16(
447
+ _mm_packus_epi16(_mm_srai_epi16(_mm_adds_epi16(a.val, delta), n),
448
+ _mm_srai_epi16(_mm_adds_epi16(b.val, delta), n)));
449
+ }
450
+
451
+ template <int n>
452
+ inline void v_rshr_pack_u_store(uchar *ptr, const v_int16x8 &a) {
453
+ __m128i delta = _mm_set1_epi16((short)(1 << (n - 1)));
454
+ __m128i a1 = _mm_srai_epi16(_mm_adds_epi16(a.val, delta), n);
455
+ _mm_storel_epi64((__m128i *)ptr, _mm_packus_epi16(a1, a1));
456
+ }
457
+
458
+ inline v_int8x16 v_pack(const v_int16x8 &a, const v_int16x8 &b) {
459
+ return v_int8x16(_mm_packs_epi16(a.val, b.val));
460
+ }
461
+
462
+ inline void v_pack_store(schar *ptr, const v_int16x8 &a) {
463
+ _mm_storel_epi64((__m128i *)ptr, _mm_packs_epi16(a.val, a.val));
464
+ }
465
+
466
+ template <int n>
467
+ inline v_int8x16 v_rshr_pack(const v_int16x8 &a, const v_int16x8 &b) {
468
+ // we assume that n > 0, and so the shifted 16-bit values can be treated as
469
+ // signed numbers.
470
+ __m128i delta = _mm_set1_epi16((short)(1 << (n - 1)));
471
+ return v_int8x16(
472
+ _mm_packs_epi16(_mm_srai_epi16(_mm_adds_epi16(a.val, delta), n),
473
+ _mm_srai_epi16(_mm_adds_epi16(b.val, delta), n)));
474
+ }
475
+ template <int n> inline void v_rshr_pack_store(schar *ptr, const v_int16x8 &a) {
476
+ // we assume that n > 0, and so the shifted 16-bit values can be treated as
477
+ // signed numbers.
478
+ __m128i delta = _mm_set1_epi16((short)(1 << (n - 1)));
479
+ __m128i a1 = _mm_srai_epi16(_mm_adds_epi16(a.val, delta), n);
480
+ _mm_storel_epi64((__m128i *)ptr, _mm_packs_epi16(a1, a1));
481
+ }
482
+
483
+ // byte-wise "mask ? a : b"
484
+ inline __m128i v_select_si128(__m128i mask, __m128i a, __m128i b) {
485
+ #if CV_SSE4_1
486
+ return _mm_blendv_epi8(b, a, mask);
487
+ #else
488
+ return _mm_xor_si128(b, _mm_and_si128(_mm_xor_si128(a, b), mask));
489
+ #endif
490
+ }
491
+
492
+ inline v_uint16x8 v_pack(const v_uint32x4 &a, const v_uint32x4 &b) {
493
+ return v_uint16x8(_v128_packs_epu32(a.val, b.val));
494
+ }
495
+
496
+ inline void v_pack_store(ushort *ptr, const v_uint32x4 &a) {
497
+ __m128i z = _mm_setzero_si128(), maxval32 = _mm_set1_epi32(65535),
498
+ delta32 = _mm_set1_epi32(32768);
499
+ __m128i a1 = _mm_sub_epi32(
500
+ v_select_si128(_mm_cmpgt_epi32(z, a.val), maxval32, a.val), delta32);
501
+ __m128i r = _mm_packs_epi32(a1, a1);
502
+ _mm_storel_epi64((__m128i *)ptr, _mm_sub_epi16(r, _mm_set1_epi16(-32768)));
503
+ }
504
+
505
+ template <int n>
506
+ inline v_uint16x8 v_rshr_pack(const v_uint32x4 &a, const v_uint32x4 &b) {
507
+ __m128i delta = _mm_set1_epi32(1 << (n - 1)), delta32 = _mm_set1_epi32(32768);
508
+ __m128i a1 =
509
+ _mm_sub_epi32(_mm_srli_epi32(_mm_add_epi32(a.val, delta), n), delta32);
510
+ __m128i b1 =
511
+ _mm_sub_epi32(_mm_srli_epi32(_mm_add_epi32(b.val, delta), n), delta32);
512
+ return v_uint16x8(
513
+ _mm_sub_epi16(_mm_packs_epi32(a1, b1), _mm_set1_epi16(-32768)));
514
+ }
515
+
516
+ template <int n>
517
+ inline void v_rshr_pack_store(ushort *ptr, const v_uint32x4 &a) {
518
+ __m128i delta = _mm_set1_epi32(1 << (n - 1)), delta32 = _mm_set1_epi32(32768);
519
+ __m128i a1 =
520
+ _mm_sub_epi32(_mm_srli_epi32(_mm_add_epi32(a.val, delta), n), delta32);
521
+ __m128i a2 = _mm_sub_epi16(_mm_packs_epi32(a1, a1), _mm_set1_epi16(-32768));
522
+ _mm_storel_epi64((__m128i *)ptr, a2);
523
+ }
524
+
525
+ inline v_uint16x8 v_pack_u(const v_int32x4 &a, const v_int32x4 &b) {
526
+ #if CV_SSE4_1
527
+ return v_uint16x8(_mm_packus_epi32(a.val, b.val));
528
+ #else
529
+ __m128i delta32 = _mm_set1_epi32(32768);
530
+
531
+ // preliminary saturate negative values to zero
532
+ __m128i a1 = _mm_and_si128(a.val, _mm_cmpgt_epi32(a.val, _mm_set1_epi32(0)));
533
+ __m128i b1 = _mm_and_si128(b.val, _mm_cmpgt_epi32(b.val, _mm_set1_epi32(0)));
534
+
535
+ __m128i r =
536
+ _mm_packs_epi32(_mm_sub_epi32(a1, delta32), _mm_sub_epi32(b1, delta32));
537
+ return v_uint16x8(_mm_sub_epi16(r, _mm_set1_epi16(-32768)));
538
+ #endif
539
+ }
540
+
541
+ inline void v_pack_u_store(ushort *ptr, const v_int32x4 &a) {
542
+ #if CV_SSE4_1
543
+ _mm_storel_epi64((__m128i *)ptr, _mm_packus_epi32(a.val, a.val));
544
+ #else
545
+ __m128i delta32 = _mm_set1_epi32(32768);
546
+ __m128i a1 = _mm_sub_epi32(a.val, delta32);
547
+ __m128i r = _mm_sub_epi16(_mm_packs_epi32(a1, a1), _mm_set1_epi16(-32768));
548
+ _mm_storel_epi64((__m128i *)ptr, r);
549
+ #endif
550
+ }
551
+
552
+ template <int n>
553
+ inline v_uint16x8 v_rshr_pack_u(const v_int32x4 &a, const v_int32x4 &b) {
554
+ #if CV_SSE4_1
555
+ __m128i delta = _mm_set1_epi32(1 << (n - 1));
556
+ return v_uint16x8(
557
+ _mm_packus_epi32(_mm_srai_epi32(_mm_add_epi32(a.val, delta), n),
558
+ _mm_srai_epi32(_mm_add_epi32(b.val, delta), n)));
559
+ #else
560
+ __m128i delta = _mm_set1_epi32(1 << (n - 1)), delta32 = _mm_set1_epi32(32768);
561
+ __m128i a1 =
562
+ _mm_sub_epi32(_mm_srai_epi32(_mm_add_epi32(a.val, delta), n), delta32);
563
+ __m128i a2 = _mm_sub_epi16(_mm_packs_epi32(a1, a1), _mm_set1_epi16(-32768));
564
+ __m128i b1 =
565
+ _mm_sub_epi32(_mm_srai_epi32(_mm_add_epi32(b.val, delta), n), delta32);
566
+ __m128i b2 = _mm_sub_epi16(_mm_packs_epi32(b1, b1), _mm_set1_epi16(-32768));
567
+ return v_uint16x8(_mm_unpacklo_epi64(a2, b2));
568
+ #endif
569
+ }
570
+
571
+ template <int n>
572
+ inline void v_rshr_pack_u_store(ushort *ptr, const v_int32x4 &a) {
573
+ #if CV_SSE4_1
574
+ __m128i delta = _mm_set1_epi32(1 << (n - 1));
575
+ __m128i a1 = _mm_srai_epi32(_mm_add_epi32(a.val, delta), n);
576
+ _mm_storel_epi64((__m128i *)ptr, _mm_packus_epi32(a1, a1));
577
+ #else
578
+ __m128i delta = _mm_set1_epi32(1 << (n - 1)), delta32 = _mm_set1_epi32(32768);
579
+ __m128i a1 =
580
+ _mm_sub_epi32(_mm_srai_epi32(_mm_add_epi32(a.val, delta), n), delta32);
581
+ __m128i a2 = _mm_sub_epi16(_mm_packs_epi32(a1, a1), _mm_set1_epi16(-32768));
582
+ _mm_storel_epi64((__m128i *)ptr, a2);
583
+ #endif
584
+ }
585
+
586
+ inline v_int16x8 v_pack(const v_int32x4 &a, const v_int32x4 &b) {
587
+ return v_int16x8(_mm_packs_epi32(a.val, b.val));
588
+ }
589
+
590
+ inline void v_pack_store(short *ptr, const v_int32x4 &a) {
591
+ _mm_storel_epi64((__m128i *)ptr, _mm_packs_epi32(a.val, a.val));
592
+ }
593
+
594
+ template <int n>
595
+ inline v_int16x8 v_rshr_pack(const v_int32x4 &a, const v_int32x4 &b) {
596
+ __m128i delta = _mm_set1_epi32(1 << (n - 1));
597
+ return v_int16x8(
598
+ _mm_packs_epi32(_mm_srai_epi32(_mm_add_epi32(a.val, delta), n),
599
+ _mm_srai_epi32(_mm_add_epi32(b.val, delta), n)));
600
+ }
601
+
602
+ template <int n> inline void v_rshr_pack_store(short *ptr, const v_int32x4 &a) {
603
+ __m128i delta = _mm_set1_epi32(1 << (n - 1));
604
+ __m128i a1 = _mm_srai_epi32(_mm_add_epi32(a.val, delta), n);
605
+ _mm_storel_epi64((__m128i *)ptr, _mm_packs_epi32(a1, a1));
606
+ }
607
+
608
+ // [a0 0 | b0 0] [a1 0 | b1 0]
609
+ inline v_uint32x4 v_pack(const v_uint64x2 &a, const v_uint64x2 &b) {
610
+ __m128i v0 = _mm_unpacklo_epi32(a.val, b.val); // a0 a1 0 0
611
+ __m128i v1 = _mm_unpackhi_epi32(a.val, b.val); // b0 b1 0 0
612
+ return v_uint32x4(_mm_unpacklo_epi32(v0, v1));
613
+ }
614
+
615
+ inline void v_pack_store(unsigned *ptr, const v_uint64x2 &a) {
616
+ __m128i a1 = _mm_shuffle_epi32(a.val, _MM_SHUFFLE(0, 2, 2, 0));
617
+ _mm_storel_epi64((__m128i *)ptr, a1);
618
+ }
619
+
620
+ // [a0 0 | b0 0] [a1 0 | b1 0]
621
+ inline v_int32x4 v_pack(const v_int64x2 &a, const v_int64x2 &b) {
622
+ __m128i v0 = _mm_unpacklo_epi32(a.val, b.val); // a0 a1 0 0
623
+ __m128i v1 = _mm_unpackhi_epi32(a.val, b.val); // b0 b1 0 0
624
+ return v_int32x4(_mm_unpacklo_epi32(v0, v1));
625
+ }
626
+
627
+ inline void v_pack_store(int *ptr, const v_int64x2 &a) {
628
+ __m128i a1 = _mm_shuffle_epi32(a.val, _MM_SHUFFLE(0, 2, 2, 0));
629
+ _mm_storel_epi64((__m128i *)ptr, a1);
630
+ }
631
+
632
+ template <int n>
633
+ inline v_uint32x4 v_rshr_pack(const v_uint64x2 &a, const v_uint64x2 &b) {
634
+ uint64 delta = (uint64)1 << (n - 1);
635
+ v_uint64x2 delta2(delta, delta);
636
+ __m128i a1 = _mm_srli_epi64(_mm_add_epi64(a.val, delta2.val), n);
637
+ __m128i b1 = _mm_srli_epi64(_mm_add_epi64(b.val, delta2.val), n);
638
+ __m128i v0 = _mm_unpacklo_epi32(a1, b1); // a0 a1 0 0
639
+ __m128i v1 = _mm_unpackhi_epi32(a1, b1); // b0 b1 0 0
640
+ return v_uint32x4(_mm_unpacklo_epi32(v0, v1));
641
+ }
642
+
643
+ template <int n>
644
+ inline void v_rshr_pack_store(unsigned *ptr, const v_uint64x2 &a) {
645
+ uint64 delta = (uint64)1 << (n - 1);
646
+ v_uint64x2 delta2(delta, delta);
647
+ __m128i a1 = _mm_srli_epi64(_mm_add_epi64(a.val, delta2.val), n);
648
+ __m128i a2 = _mm_shuffle_epi32(a1, _MM_SHUFFLE(0, 2, 2, 0));
649
+ _mm_storel_epi64((__m128i *)ptr, a2);
650
+ }
651
+
652
+ inline __m128i v_sign_epi64(__m128i a) {
653
+ return _mm_shuffle_epi32(_mm_srai_epi32(a, 31),
654
+ _MM_SHUFFLE(3, 3, 1, 1)); // x m0 | x m1
655
+ }
656
+
657
+ inline __m128i v_srai_epi64(__m128i a, int imm) {
658
+ __m128i smask = v_sign_epi64(a);
659
+ return _mm_xor_si128(_mm_srli_epi64(_mm_xor_si128(a, smask), imm), smask);
660
+ }
661
+
662
+ template <int n>
663
+ inline v_int32x4 v_rshr_pack(const v_int64x2 &a, const v_int64x2 &b) {
664
+ int64 delta = (int64)1 << (n - 1);
665
+ v_int64x2 delta2(delta, delta);
666
+ __m128i a1 = v_srai_epi64(_mm_add_epi64(a.val, delta2.val), n);
667
+ __m128i b1 = v_srai_epi64(_mm_add_epi64(b.val, delta2.val), n);
668
+ __m128i v0 = _mm_unpacklo_epi32(a1, b1); // a0 a1 0 0
669
+ __m128i v1 = _mm_unpackhi_epi32(a1, b1); // b0 b1 0 0
670
+ return v_int32x4(_mm_unpacklo_epi32(v0, v1));
671
+ }
672
+
673
+ template <int n> inline void v_rshr_pack_store(int *ptr, const v_int64x2 &a) {
674
+ int64 delta = (int64)1 << (n - 1);
675
+ v_int64x2 delta2(delta, delta);
676
+ __m128i a1 = v_srai_epi64(_mm_add_epi64(a.val, delta2.val), n);
677
+ __m128i a2 = _mm_shuffle_epi32(a1, _MM_SHUFFLE(0, 2, 2, 0));
678
+ _mm_storel_epi64((__m128i *)ptr, a2);
679
+ }
680
+
681
+ // pack boolean
682
+ inline v_uint8x16 v_pack_b(const v_uint16x8 &a, const v_uint16x8 &b) {
683
+ __m128i ab = _mm_packs_epi16(a.val, b.val);
684
+ return v_uint8x16(ab);
685
+ }
686
+
687
+ inline v_uint8x16 v_pack_b(const v_uint32x4 &a, const v_uint32x4 &b,
688
+ const v_uint32x4 &c, const v_uint32x4 &d) {
689
+ __m128i ab = _mm_packs_epi32(a.val, b.val);
690
+ __m128i cd = _mm_packs_epi32(c.val, d.val);
691
+ return v_uint8x16(_mm_packs_epi16(ab, cd));
692
+ }
693
+
694
+ inline v_uint8x16 v_pack_b(const v_uint64x2 &a, const v_uint64x2 &b,
695
+ const v_uint64x2 &c, const v_uint64x2 &d,
696
+ const v_uint64x2 &e, const v_uint64x2 &f,
697
+ const v_uint64x2 &g, const v_uint64x2 &h) {
698
+ __m128i ab = _mm_packs_epi32(a.val, b.val);
699
+ __m128i cd = _mm_packs_epi32(c.val, d.val);
700
+ __m128i ef = _mm_packs_epi32(e.val, f.val);
701
+ __m128i gh = _mm_packs_epi32(g.val, h.val);
702
+
703
+ __m128i abcd = _mm_packs_epi32(ab, cd);
704
+ __m128i efgh = _mm_packs_epi32(ef, gh);
705
+ return v_uint8x16(_mm_packs_epi16(abcd, efgh));
706
+ }
707
+
708
+ inline v_float32x4 v_matmul(const v_float32x4 &v, const v_float32x4 &m0,
709
+ const v_float32x4 &m1, const v_float32x4 &m2,
710
+ const v_float32x4 &m3) {
711
+ __m128 v0 =
712
+ _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(0, 0, 0, 0)), m0.val);
713
+ __m128 v1 =
714
+ _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(1, 1, 1, 1)), m1.val);
715
+ __m128 v2 =
716
+ _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(2, 2, 2, 2)), m2.val);
717
+ __m128 v3 =
718
+ _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(3, 3, 3, 3)), m3.val);
719
+
720
+ return v_float32x4(_mm_add_ps(_mm_add_ps(v0, v1), _mm_add_ps(v2, v3)));
721
+ }
722
+
723
+ inline v_float32x4 v_matmuladd(const v_float32x4 &v, const v_float32x4 &m0,
724
+ const v_float32x4 &m1, const v_float32x4 &m2,
725
+ const v_float32x4 &a) {
726
+ __m128 v0 =
727
+ _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(0, 0, 0, 0)), m0.val);
728
+ __m128 v1 =
729
+ _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(1, 1, 1, 1)), m1.val);
730
+ __m128 v2 =
731
+ _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(2, 2, 2, 2)), m2.val);
732
+
733
+ return v_float32x4(_mm_add_ps(_mm_add_ps(v0, v1), _mm_add_ps(v2, a.val)));
734
+ }
735
+
736
+ #define OPENCV_HAL_IMPL_SSE_BIN_OP(bin_op, _Tpvec, intrin) \
737
+ inline _Tpvec bin_op(const _Tpvec &a, const _Tpvec &b) { \
738
+ return _Tpvec(intrin(a.val, b.val)); \
739
+ }
740
+
741
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_add, v_uint8x16, _mm_adds_epu8)
742
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_sub, v_uint8x16, _mm_subs_epu8)
743
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_add, v_int8x16, _mm_adds_epi8)
744
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_sub, v_int8x16, _mm_subs_epi8)
745
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_add, v_uint16x8, _mm_adds_epu16)
746
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_sub, v_uint16x8, _mm_subs_epu16)
747
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_add, v_int16x8, _mm_adds_epi16)
748
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_sub, v_int16x8, _mm_subs_epi16)
749
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_add, v_uint32x4, _mm_add_epi32)
750
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_sub, v_uint32x4, _mm_sub_epi32)
751
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_mul, v_uint32x4, _v128_mullo_epi32)
752
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_add, v_int32x4, _mm_add_epi32)
753
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_sub, v_int32x4, _mm_sub_epi32)
754
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_mul, v_int32x4, _v128_mullo_epi32)
755
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_add, v_float32x4, _mm_add_ps)
756
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_sub, v_float32x4, _mm_sub_ps)
757
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_mul, v_float32x4, _mm_mul_ps)
758
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_div, v_float32x4, _mm_div_ps)
759
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_add, v_float64x2, _mm_add_pd)
760
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_sub, v_float64x2, _mm_sub_pd)
761
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_mul, v_float64x2, _mm_mul_pd)
762
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_div, v_float64x2, _mm_div_pd)
763
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_add, v_uint64x2, _mm_add_epi64)
764
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_sub, v_uint64x2, _mm_sub_epi64)
765
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_add, v_int64x2, _mm_add_epi64)
766
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_sub, v_int64x2, _mm_sub_epi64)
767
+
768
+ // saturating multiply 8-bit, 16-bit
769
+ #define OPENCV_HAL_IMPL_SSE_MUL_SAT(_Tpvec, _Tpwvec) \
770
+ inline _Tpvec v_mul(const _Tpvec &a, const _Tpvec &b) { \
771
+ _Tpwvec c, d; \
772
+ v_mul_expand(a, b, c, d); \
773
+ return v_pack(c, d); \
774
+ }
775
+
776
+ OPENCV_HAL_IMPL_SSE_MUL_SAT(v_uint8x16, v_uint16x8)
777
+ OPENCV_HAL_IMPL_SSE_MUL_SAT(v_int8x16, v_int16x8)
778
+ OPENCV_HAL_IMPL_SSE_MUL_SAT(v_uint16x8, v_uint32x4)
779
+ OPENCV_HAL_IMPL_SSE_MUL_SAT(v_int16x8, v_int32x4)
780
+
781
+ // Multiply and expand
782
+ inline void v_mul_expand(const v_uint8x16 &a, const v_uint8x16 &b,
783
+ v_uint16x8 &c, v_uint16x8 &d) {
784
+ v_uint16x8 a0, a1, b0, b1;
785
+ v_expand(a, a0, a1);
786
+ v_expand(b, b0, b1);
787
+ c = v_mul_wrap(a0, b0);
788
+ d = v_mul_wrap(a1, b1);
789
+ }
790
+
791
+ inline void v_mul_expand(const v_int8x16 &a, const v_int8x16 &b, v_int16x8 &c,
792
+ v_int16x8 &d) {
793
+ v_int16x8 a0, a1, b0, b1;
794
+ v_expand(a, a0, a1);
795
+ v_expand(b, b0, b1);
796
+ c = v_mul_wrap(a0, b0);
797
+ d = v_mul_wrap(a1, b1);
798
+ }
799
+
800
+ inline void v_mul_expand(const v_int16x8 &a, const v_int16x8 &b, v_int32x4 &c,
801
+ v_int32x4 &d) {
802
+ __m128i v0 = _mm_mullo_epi16(a.val, b.val);
803
+ __m128i v1 = _mm_mulhi_epi16(a.val, b.val);
804
+ c.val = _mm_unpacklo_epi16(v0, v1);
805
+ d.val = _mm_unpackhi_epi16(v0, v1);
806
+ }
807
+
808
+ inline void v_mul_expand(const v_uint16x8 &a, const v_uint16x8 &b,
809
+ v_uint32x4 &c, v_uint32x4 &d) {
810
+ __m128i v0 = _mm_mullo_epi16(a.val, b.val);
811
+ __m128i v1 = _mm_mulhi_epu16(a.val, b.val);
812
+ c.val = _mm_unpacklo_epi16(v0, v1);
813
+ d.val = _mm_unpackhi_epi16(v0, v1);
814
+ }
815
+
816
+ inline void v_mul_expand(const v_uint32x4 &a, const v_uint32x4 &b,
817
+ v_uint64x2 &c, v_uint64x2 &d) {
818
+ __m128i c0 = _mm_mul_epu32(a.val, b.val);
819
+ __m128i c1 =
820
+ _mm_mul_epu32(_mm_srli_epi64(a.val, 32), _mm_srli_epi64(b.val, 32));
821
+ c.val = _mm_unpacklo_epi64(c0, c1);
822
+ d.val = _mm_unpackhi_epi64(c0, c1);
823
+ }
824
+
825
+ inline v_int16x8 v_mul_hi(const v_int16x8 &a, const v_int16x8 &b) {
826
+ return v_int16x8(_mm_mulhi_epi16(a.val, b.val));
827
+ }
828
+ inline v_uint16x8 v_mul_hi(const v_uint16x8 &a, const v_uint16x8 &b) {
829
+ return v_uint16x8(_mm_mulhi_epu16(a.val, b.val));
830
+ }
831
+
832
+ //////// Dot Product ////////
833
+
834
+ // 16 >> 32
835
+ inline v_int32x4 v_dotprod(const v_int16x8 &a, const v_int16x8 &b) {
836
+ return v_int32x4(_mm_madd_epi16(a.val, b.val));
837
+ }
838
+ inline v_int32x4 v_dotprod(const v_int16x8 &a, const v_int16x8 &b,
839
+ const v_int32x4 &c) {
840
+ return v_add(v_dotprod(a, b), c);
841
+ }
842
+
843
+ // 32 >> 64
844
+ inline v_int64x2 v_dotprod(const v_int32x4 &a, const v_int32x4 &b) {
845
+ #if CV_SSE4_1
846
+ __m128i even = _mm_mul_epi32(a.val, b.val);
847
+ __m128i odd =
848
+ _mm_mul_epi32(_mm_srli_epi64(a.val, 32), _mm_srli_epi64(b.val, 32));
849
+ return v_int64x2(_mm_add_epi64(even, odd));
850
+ #else
851
+ __m128i even_u = _mm_mul_epu32(a.val, b.val);
852
+ __m128i odd_u =
853
+ _mm_mul_epu32(_mm_srli_epi64(a.val, 32), _mm_srli_epi64(b.val, 32));
854
+ // convert unsigned to signed high multiplication (from: Agner Fog(veclib) and
855
+ // H S Warren: Hacker's delight, 2003, p. 132)
856
+ __m128i a_sign = _mm_srai_epi32(a.val, 31);
857
+ __m128i b_sign = _mm_srai_epi32(b.val, 31);
858
+ // |x * sign of x
859
+ __m128i axb = _mm_and_si128(a.val, b_sign);
860
+ __m128i bxa = _mm_and_si128(b.val, a_sign);
861
+ // sum of sign corrections
862
+ __m128i ssum = _mm_add_epi32(bxa, axb);
863
+ __m128i even_ssum = _mm_slli_epi64(ssum, 32);
864
+ __m128i odd_ssum = _mm_and_si128(ssum, _mm_set_epi32(-1, 0, -1, 0));
865
+ // convert to signed and prod
866
+ return v_int64x2(_mm_add_epi64(_mm_sub_epi64(even_u, even_ssum),
867
+ _mm_sub_epi64(odd_u, odd_ssum)));
868
+ #endif
869
+ }
870
+ inline v_int64x2 v_dotprod(const v_int32x4 &a, const v_int32x4 &b,
871
+ const v_int64x2 &c) {
872
+ return v_add(v_dotprod(a, b), c);
873
+ }
874
+
875
+ // 8 >> 32
876
+ inline v_uint32x4 v_dotprod_expand(const v_uint8x16 &a, const v_uint8x16 &b) {
877
+ __m128i a0 = _mm_srli_epi16(_mm_slli_si128(a.val, 1), 8); // even
878
+ __m128i a1 = _mm_srli_epi16(a.val, 8); // odd
879
+ __m128i b0 = _mm_srli_epi16(_mm_slli_si128(b.val, 1), 8);
880
+ __m128i b1 = _mm_srli_epi16(b.val, 8);
881
+ __m128i p0 = _mm_madd_epi16(a0, b0);
882
+ __m128i p1 = _mm_madd_epi16(a1, b1);
883
+ return v_uint32x4(_mm_add_epi32(p0, p1));
884
+ }
885
+ inline v_uint32x4 v_dotprod_expand(const v_uint8x16 &a, const v_uint8x16 &b,
886
+ const v_uint32x4 &c) {
887
+ return v_add(v_dotprod_expand(a, b), c);
888
+ }
889
+
890
+ inline v_int32x4 v_dotprod_expand(const v_int8x16 &a, const v_int8x16 &b) {
891
+ __m128i a0 = _mm_srai_epi16(_mm_slli_si128(a.val, 1), 8); // even
892
+ __m128i a1 = _mm_srai_epi16(a.val, 8); // odd
893
+ __m128i b0 = _mm_srai_epi16(_mm_slli_si128(b.val, 1), 8);
894
+ __m128i b1 = _mm_srai_epi16(b.val, 8);
895
+ __m128i p0 = _mm_madd_epi16(a0, b0);
896
+ __m128i p1 = _mm_madd_epi16(a1, b1);
897
+ return v_int32x4(_mm_add_epi32(p0, p1));
898
+ }
899
+ inline v_int32x4 v_dotprod_expand(const v_int8x16 &a, const v_int8x16 &b,
900
+ const v_int32x4 &c) {
901
+ return v_add(v_dotprod_expand(a, b), c);
902
+ }
903
+
904
+ // 16 >> 64
905
+ inline v_uint64x2 v_dotprod_expand(const v_uint16x8 &a, const v_uint16x8 &b) {
906
+ v_uint32x4 c, d;
907
+ v_mul_expand(a, b, c, d);
908
+
909
+ v_uint64x2 c0, c1, d0, d1;
910
+ v_expand(c, c0, c1);
911
+ v_expand(d, d0, d1);
912
+
913
+ c0 = v_add(c0, c1);
914
+ d0 = v_add(d0, d1);
915
+ return v_uint64x2(_mm_add_epi64(_mm_unpacklo_epi64(c0.val, d0.val),
916
+ _mm_unpackhi_epi64(c0.val, d0.val)));
917
+ }
918
+ inline v_uint64x2 v_dotprod_expand(const v_uint16x8 &a, const v_uint16x8 &b,
919
+ const v_uint64x2 &c) {
920
+ return v_add(v_dotprod_expand(a, b), c);
921
+ }
922
+
923
+ inline v_int64x2 v_dotprod_expand(const v_int16x8 &a, const v_int16x8 &b) {
924
+ v_int32x4 prod = v_dotprod(a, b);
925
+ v_int64x2 c, d;
926
+ v_expand(prod, c, d);
927
+ return v_int64x2(_mm_add_epi64(_mm_unpacklo_epi64(c.val, d.val),
928
+ _mm_unpackhi_epi64(c.val, d.val)));
929
+ }
930
+ inline v_int64x2 v_dotprod_expand(const v_int16x8 &a, const v_int16x8 &b,
931
+ const v_int64x2 &c) {
932
+ return v_add(v_dotprod_expand(a, b), c);
933
+ }
934
+
935
+ // 32 >> 64f
936
+ inline v_float64x2 v_dotprod_expand(const v_int32x4 &a, const v_int32x4 &b) {
937
+ #if CV_SSE4_1
938
+ return v_cvt_f64(v_dotprod(a, b));
939
+ #else
940
+ v_float64x2 c = v_mul(v_cvt_f64(a), v_cvt_f64(b));
941
+ v_float64x2 d = v_mul(v_cvt_f64_high(a), v_cvt_f64_high(b));
942
+
943
+ return v_float64x2(
944
+ _mm_add_pd(_mm_unpacklo_pd(c.val, d.val), _mm_unpackhi_pd(c.val, d.val)));
945
+ #endif
946
+ }
947
+ inline v_float64x2 v_dotprod_expand(const v_int32x4 &a, const v_int32x4 &b,
948
+ const v_float64x2 &c) {
949
+ return v_add(v_dotprod_expand(a, b), c);
950
+ }
951
+
952
+ //////// Fast Dot Product ////////
953
+
954
+ // 16 >> 32
955
+ inline v_int32x4 v_dotprod_fast(const v_int16x8 &a, const v_int16x8 &b) {
956
+ return v_dotprod(a, b);
957
+ }
958
+ inline v_int32x4 v_dotprod_fast(const v_int16x8 &a, const v_int16x8 &b,
959
+ const v_int32x4 &c) {
960
+ return v_add(v_dotprod(a, b), c);
961
+ }
962
+
963
+ // 32 >> 64
964
+ inline v_int64x2 v_dotprod_fast(const v_int32x4 &a, const v_int32x4 &b) {
965
+ return v_dotprod(a, b);
966
+ }
967
+ inline v_int64x2 v_dotprod_fast(const v_int32x4 &a, const v_int32x4 &b,
968
+ const v_int64x2 &c) {
969
+ return v_add(v_dotprod_fast(a, b), c);
970
+ }
971
+
972
+ // 8 >> 32
973
+ inline v_uint32x4 v_dotprod_expand_fast(const v_uint8x16 &a,
974
+ const v_uint8x16 &b) {
975
+ __m128i a0 = v_expand_low(a).val;
976
+ __m128i a1 = v_expand_high(a).val;
977
+ __m128i b0 = v_expand_low(b).val;
978
+ __m128i b1 = v_expand_high(b).val;
979
+ __m128i p0 = _mm_madd_epi16(a0, b0);
980
+ __m128i p1 = _mm_madd_epi16(a1, b1);
981
+ return v_uint32x4(_mm_add_epi32(p0, p1));
982
+ }
983
+ inline v_uint32x4 v_dotprod_expand_fast(const v_uint8x16 &a,
984
+ const v_uint8x16 &b,
985
+ const v_uint32x4 &c) {
986
+ return v_add(v_dotprod_expand_fast(a, b), c);
987
+ }
988
+
989
+ inline v_int32x4 v_dotprod_expand_fast(const v_int8x16 &a, const v_int8x16 &b) {
990
+ #if CV_SSE4_1
991
+ __m128i a0 = _mm_cvtepi8_epi16(a.val);
992
+ __m128i a1 = v_expand_high(a).val;
993
+ __m128i b0 = _mm_cvtepi8_epi16(b.val);
994
+ __m128i b1 = v_expand_high(b).val;
995
+ __m128i p0 = _mm_madd_epi16(a0, b0);
996
+ __m128i p1 = _mm_madd_epi16(a1, b1);
997
+ return v_int32x4(_mm_add_epi32(p0, p1));
998
+ #else
999
+ return v_dotprod_expand(a, b);
1000
+ #endif
1001
+ }
1002
+ inline v_int32x4 v_dotprod_expand_fast(const v_int8x16 &a, const v_int8x16 &b,
1003
+ const v_int32x4 &c) {
1004
+ return v_add(v_dotprod_expand_fast(a, b), c);
1005
+ }
1006
+
1007
+ // 16 >> 64
1008
+ inline v_uint64x2 v_dotprod_expand_fast(const v_uint16x8 &a,
1009
+ const v_uint16x8 &b) {
1010
+ v_uint32x4 c, d;
1011
+ v_mul_expand(a, b, c, d);
1012
+
1013
+ v_uint64x2 c0, c1, d0, d1;
1014
+ v_expand(c, c0, c1);
1015
+ v_expand(d, d0, d1);
1016
+
1017
+ c0 = v_add(c0, c1);
1018
+ d0 = v_add(d0, d1);
1019
+ return v_add(c0, d0);
1020
+ }
1021
+ inline v_uint64x2 v_dotprod_expand_fast(const v_uint16x8 &a,
1022
+ const v_uint16x8 &b,
1023
+ const v_uint64x2 &c) {
1024
+ return v_add(v_dotprod_expand_fast(a, b), c);
1025
+ }
1026
+
1027
+ inline v_int64x2 v_dotprod_expand_fast(const v_int16x8 &a, const v_int16x8 &b) {
1028
+ v_int32x4 prod = v_dotprod(a, b);
1029
+ v_int64x2 c, d;
1030
+ v_expand(prod, c, d);
1031
+ return v_add(c, d);
1032
+ }
1033
+ inline v_int64x2 v_dotprod_expand_fast(const v_int16x8 &a, const v_int16x8 &b,
1034
+ const v_int64x2 &c) {
1035
+ return v_add(v_dotprod_expand_fast(a, b), c);
1036
+ }
1037
+
1038
+ // 32 >> 64f
1039
+ v_float64x2 v_fma(const v_float64x2 &a, const v_float64x2 &b,
1040
+ const v_float64x2 &c);
1041
+ inline v_float64x2 v_dotprod_expand_fast(const v_int32x4 &a,
1042
+ const v_int32x4 &b) {
1043
+ return v_fma(v_cvt_f64(a), v_cvt_f64(b),
1044
+ v_mul(v_cvt_f64_high(a), v_cvt_f64_high(b)));
1045
+ }
1046
+ inline v_float64x2 v_dotprod_expand_fast(const v_int32x4 &a, const v_int32x4 &b,
1047
+ const v_float64x2 &c) {
1048
+ return v_fma(v_cvt_f64(a), v_cvt_f64(b),
1049
+ v_fma(v_cvt_f64_high(a), v_cvt_f64_high(b), c));
1050
+ }
1051
+
1052
+ #define OPENCV_HAL_IMPL_SSE_LOGIC_OP(_Tpvec, suffix, not_const) \
1053
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_and, _Tpvec, _mm_and_##suffix) \
1054
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_or, _Tpvec, _mm_or_##suffix) \
1055
+ OPENCV_HAL_IMPL_SSE_BIN_OP(v_xor, _Tpvec, _mm_xor_##suffix) \
1056
+ inline _Tpvec v_not(const _Tpvec &a) { \
1057
+ return _Tpvec(_mm_xor_##suffix(a.val, not_const)); \
1058
+ }
1059
+
1060
+ OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_uint8x16, si128, _mm_set1_epi32(-1))
1061
+ OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_int8x16, si128, _mm_set1_epi32(-1))
1062
+ OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_uint16x8, si128, _mm_set1_epi32(-1))
1063
+ OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_int16x8, si128, _mm_set1_epi32(-1))
1064
+ OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_uint32x4, si128, _mm_set1_epi32(-1))
1065
+ OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_int32x4, si128, _mm_set1_epi32(-1))
1066
+ OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_uint64x2, si128, _mm_set1_epi32(-1))
1067
+ OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_int64x2, si128, _mm_set1_epi32(-1))
1068
+ OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_float32x4, ps,
1069
+ _mm_castsi128_ps(_mm_set1_epi32(-1)))
1070
+ OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_float64x2, pd,
1071
+ _mm_castsi128_pd(_mm_set1_epi32(-1)))
1072
+
1073
+ inline v_float32x4 v_sqrt(const v_float32x4 &x) {
1074
+ return v_float32x4(_mm_sqrt_ps(x.val));
1075
+ }
1076
+
1077
+ inline v_float32x4 v_invsqrt(const v_float32x4 &x) {
1078
+ const __m128 _0_5 = _mm_set1_ps(0.5f), _1_5 = _mm_set1_ps(1.5f);
1079
+ __m128 t = x.val;
1080
+ __m128 h = _mm_mul_ps(t, _0_5);
1081
+ t = _mm_rsqrt_ps(t);
1082
+ t = _mm_mul_ps(t, _mm_sub_ps(_1_5, _mm_mul_ps(_mm_mul_ps(t, t), h)));
1083
+ return v_float32x4(t);
1084
+ }
1085
+
1086
+ inline v_float64x2 v_sqrt(const v_float64x2 &x) {
1087
+ return v_float64x2(_mm_sqrt_pd(x.val));
1088
+ }
1089
+
1090
+ inline v_float64x2 v_invsqrt(const v_float64x2 &x) {
1091
+ const __m128d v_1 = _mm_set1_pd(1.);
1092
+ return v_float64x2(_mm_div_pd(v_1, _mm_sqrt_pd(x.val)));
1093
+ }
1094
+
1095
+ #define OPENCV_HAL_IMPL_SSE_ABS_INT_FUNC(_Tpuvec, _Tpsvec, func, suffix, \
1096
+ subWidth) \
1097
+ inline _Tpuvec v_abs(const _Tpsvec &x) { \
1098
+ return _Tpuvec(_mm_##func##_ep##suffix( \
1099
+ x.val, _mm_sub_ep##subWidth(_mm_setzero_si128(), x.val))); \
1100
+ }
1101
+
1102
+ OPENCV_HAL_IMPL_SSE_ABS_INT_FUNC(v_uint8x16, v_int8x16, min, u8, i8)
1103
+ OPENCV_HAL_IMPL_SSE_ABS_INT_FUNC(v_uint16x8, v_int16x8, max, i16, i16)
1104
+ inline v_uint32x4 v_abs(const v_int32x4 &x) {
1105
+ __m128i s = _mm_srli_epi32(x.val, 31);
1106
+ __m128i f = _mm_srai_epi32(x.val, 31);
1107
+ return v_uint32x4(_mm_add_epi32(_mm_xor_si128(x.val, f), s));
1108
+ }
1109
+ inline v_float32x4 v_abs(const v_float32x4 &x) {
1110
+ return v_float32x4(
1111
+ _mm_and_ps(x.val, _mm_castsi128_ps(_mm_set1_epi32(0x7fffffff))));
1112
+ }
1113
+ inline v_float64x2 v_abs(const v_float64x2 &x) {
1114
+ return v_float64x2(_mm_and_pd(
1115
+ x.val, _mm_castsi128_pd(_mm_srli_epi64(_mm_set1_epi32(-1), 1))));
1116
+ }
1117
+
1118
+ // TODO: exp, log, sin, cos
1119
+
1120
+ #define OPENCV_HAL_IMPL_SSE_BIN_FUNC(_Tpvec, func, intrin) \
1121
+ inline _Tpvec func(const _Tpvec &a, const _Tpvec &b) { \
1122
+ return _Tpvec(intrin(a.val, b.val)); \
1123
+ }
1124
+
1125
+ OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint8x16, v_min, _mm_min_epu8)
1126
+ OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint8x16, v_max, _mm_max_epu8)
1127
+ OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_int16x8, v_min, _mm_min_epi16)
1128
+ OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_int16x8, v_max, _mm_max_epi16)
1129
+ OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_float32x4, v_min, _mm_min_ps)
1130
+ OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_float32x4, v_max, _mm_max_ps)
1131
+ OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_float64x2, v_min, _mm_min_pd)
1132
+ OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_float64x2, v_max, _mm_max_pd)
1133
+
1134
+ inline v_int8x16 v_min(const v_int8x16 &a, const v_int8x16 &b) {
1135
+ #if CV_SSE4_1
1136
+ return v_int8x16(_mm_min_epi8(a.val, b.val));
1137
+ #else
1138
+ __m128i delta = _mm_set1_epi8((char)-128);
1139
+ return v_int8x16(
1140
+ _mm_xor_si128(delta, _mm_min_epu8(_mm_xor_si128(a.val, delta),
1141
+ _mm_xor_si128(b.val, delta))));
1142
+ #endif
1143
+ }
1144
+ inline v_int8x16 v_max(const v_int8x16 &a, const v_int8x16 &b) {
1145
+ #if CV_SSE4_1
1146
+ return v_int8x16(_mm_max_epi8(a.val, b.val));
1147
+ #else
1148
+ __m128i delta = _mm_set1_epi8((char)-128);
1149
+ return v_int8x16(
1150
+ _mm_xor_si128(delta, _mm_max_epu8(_mm_xor_si128(a.val, delta),
1151
+ _mm_xor_si128(b.val, delta))));
1152
+ #endif
1153
+ }
1154
+ inline v_uint16x8 v_min(const v_uint16x8 &a, const v_uint16x8 &b) {
1155
+ #if CV_SSE4_1
1156
+ return v_uint16x8(_mm_min_epu16(a.val, b.val));
1157
+ #else
1158
+ return v_uint16x8(_mm_subs_epu16(a.val, _mm_subs_epu16(a.val, b.val)));
1159
+ #endif
1160
+ }
1161
+ inline v_uint16x8 v_max(const v_uint16x8 &a, const v_uint16x8 &b) {
1162
+ #if CV_SSE4_1
1163
+ return v_uint16x8(_mm_max_epu16(a.val, b.val));
1164
+ #else
1165
+ return v_uint16x8(_mm_adds_epu16(_mm_subs_epu16(a.val, b.val), b.val));
1166
+ #endif
1167
+ }
1168
+ inline v_uint32x4 v_min(const v_uint32x4 &a, const v_uint32x4 &b) {
1169
+ #if CV_SSE4_1
1170
+ return v_uint32x4(_mm_min_epu32(a.val, b.val));
1171
+ #else
1172
+ __m128i delta = _mm_set1_epi32((int)0x80000000);
1173
+ __m128i mask =
1174
+ _mm_cmpgt_epi32(_mm_xor_si128(a.val, delta), _mm_xor_si128(b.val, delta));
1175
+ return v_uint32x4(v_select_si128(mask, b.val, a.val));
1176
+ #endif
1177
+ }
1178
+ inline v_uint32x4 v_max(const v_uint32x4 &a, const v_uint32x4 &b) {
1179
+ #if CV_SSE4_1
1180
+ return v_uint32x4(_mm_max_epu32(a.val, b.val));
1181
+ #else
1182
+ __m128i delta = _mm_set1_epi32((int)0x80000000);
1183
+ __m128i mask =
1184
+ _mm_cmpgt_epi32(_mm_xor_si128(a.val, delta), _mm_xor_si128(b.val, delta));
1185
+ return v_uint32x4(v_select_si128(mask, a.val, b.val));
1186
+ #endif
1187
+ }
1188
+ inline v_int32x4 v_min(const v_int32x4 &a, const v_int32x4 &b) {
1189
+ #if CV_SSE4_1
1190
+ return v_int32x4(_mm_min_epi32(a.val, b.val));
1191
+ #else
1192
+ return v_int32x4(v_select_si128(_mm_cmpgt_epi32(a.val, b.val), b.val, a.val));
1193
+ #endif
1194
+ }
1195
+ inline v_int32x4 v_max(const v_int32x4 &a, const v_int32x4 &b) {
1196
+ #if CV_SSE4_1
1197
+ return v_int32x4(_mm_max_epi32(a.val, b.val));
1198
+ #else
1199
+ return v_int32x4(v_select_si128(_mm_cmpgt_epi32(a.val, b.val), a.val, b.val));
1200
+ #endif
1201
+ }
1202
+
1203
+ #define OPENCV_HAL_IMPL_SSE_INT_CMP_OP(_Tpuvec, _Tpsvec, suffix, sbit) \
1204
+ inline _Tpuvec v_eq(const _Tpuvec &a, const _Tpuvec &b) { \
1205
+ return _Tpuvec(_mm_cmpeq_##suffix(a.val, b.val)); \
1206
+ } \
1207
+ inline _Tpuvec v_ne(const _Tpuvec &a, const _Tpuvec &b) { \
1208
+ __m128i not_mask = _mm_set1_epi32(-1); \
1209
+ return _Tpuvec(_mm_xor_si128(_mm_cmpeq_##suffix(a.val, b.val), not_mask)); \
1210
+ } \
1211
+ inline _Tpsvec v_eq(const _Tpsvec &a, const _Tpsvec &b) { \
1212
+ return _Tpsvec(_mm_cmpeq_##suffix(a.val, b.val)); \
1213
+ } \
1214
+ inline _Tpsvec v_ne(const _Tpsvec &a, const _Tpsvec &b) { \
1215
+ __m128i not_mask = _mm_set1_epi32(-1); \
1216
+ return _Tpsvec(_mm_xor_si128(_mm_cmpeq_##suffix(a.val, b.val), not_mask)); \
1217
+ } \
1218
+ inline _Tpuvec v_lt(const _Tpuvec &a, const _Tpuvec &b) { \
1219
+ __m128i smask = _mm_set1_##suffix(sbit); \
1220
+ return _Tpuvec(_mm_cmpgt_##suffix(_mm_xor_si128(b.val, smask), \
1221
+ _mm_xor_si128(a.val, smask))); \
1222
+ } \
1223
+ inline _Tpuvec v_gt(const _Tpuvec &a, const _Tpuvec &b) { \
1224
+ __m128i smask = _mm_set1_##suffix(sbit); \
1225
+ return _Tpuvec(_mm_cmpgt_##suffix(_mm_xor_si128(a.val, smask), \
1226
+ _mm_xor_si128(b.val, smask))); \
1227
+ } \
1228
+ inline _Tpuvec v_le(const _Tpuvec &a, const _Tpuvec &b) { \
1229
+ __m128i smask = _mm_set1_##suffix(sbit); \
1230
+ __m128i not_mask = _mm_set1_epi32(-1); \
1231
+ __m128i res = _mm_cmpgt_##suffix(_mm_xor_si128(a.val, smask), \
1232
+ _mm_xor_si128(b.val, smask)); \
1233
+ return _Tpuvec(_mm_xor_si128(res, not_mask)); \
1234
+ } \
1235
+ inline _Tpuvec v_ge(const _Tpuvec &a, const _Tpuvec &b) { \
1236
+ __m128i smask = _mm_set1_##suffix(sbit); \
1237
+ __m128i not_mask = _mm_set1_epi32(-1); \
1238
+ __m128i res = _mm_cmpgt_##suffix(_mm_xor_si128(b.val, smask), \
1239
+ _mm_xor_si128(a.val, smask)); \
1240
+ return _Tpuvec(_mm_xor_si128(res, not_mask)); \
1241
+ } \
1242
+ inline _Tpsvec v_lt(const _Tpsvec &a, const _Tpsvec &b) { \
1243
+ return _Tpsvec(_mm_cmpgt_##suffix(b.val, a.val)); \
1244
+ } \
1245
+ inline _Tpsvec v_gt(const _Tpsvec &a, const _Tpsvec &b) { \
1246
+ return _Tpsvec(_mm_cmpgt_##suffix(a.val, b.val)); \
1247
+ } \
1248
+ inline _Tpsvec v_le(const _Tpsvec &a, const _Tpsvec &b) { \
1249
+ __m128i not_mask = _mm_set1_epi32(-1); \
1250
+ return _Tpsvec(_mm_xor_si128(_mm_cmpgt_##suffix(a.val, b.val), not_mask)); \
1251
+ } \
1252
+ inline _Tpsvec v_ge(const _Tpsvec &a, const _Tpsvec &b) { \
1253
+ __m128i not_mask = _mm_set1_epi32(-1); \
1254
+ return _Tpsvec(_mm_xor_si128(_mm_cmpgt_##suffix(b.val, a.val), not_mask)); \
1255
+ }
1256
+
1257
+ OPENCV_HAL_IMPL_SSE_INT_CMP_OP(v_uint8x16, v_int8x16, epi8, (char)-128)
1258
+ OPENCV_HAL_IMPL_SSE_INT_CMP_OP(v_uint16x8, v_int16x8, epi16, (short)-32768)
1259
+ OPENCV_HAL_IMPL_SSE_INT_CMP_OP(v_uint32x4, v_int32x4, epi32, (int)0x80000000)
1260
+
1261
+ #define OPENCV_HAL_IMPL_SSE_FLT_CMP_OP(_Tpvec, suffix) \
1262
+ inline _Tpvec v_eq(const _Tpvec &a, const _Tpvec &b) { \
1263
+ return _Tpvec(_mm_cmpeq_##suffix(a.val, b.val)); \
1264
+ } \
1265
+ inline _Tpvec v_ne(const _Tpvec &a, const _Tpvec &b) { \
1266
+ return _Tpvec(_mm_cmpneq_##suffix(a.val, b.val)); \
1267
+ } \
1268
+ inline _Tpvec v_lt(const _Tpvec &a, const _Tpvec &b) { \
1269
+ return _Tpvec(_mm_cmplt_##suffix(a.val, b.val)); \
1270
+ } \
1271
+ inline _Tpvec v_gt(const _Tpvec &a, const _Tpvec &b) { \
1272
+ return _Tpvec(_mm_cmpgt_##suffix(a.val, b.val)); \
1273
+ } \
1274
+ inline _Tpvec v_le(const _Tpvec &a, const _Tpvec &b) { \
1275
+ return _Tpvec(_mm_cmple_##suffix(a.val, b.val)); \
1276
+ } \
1277
+ inline _Tpvec v_ge(const _Tpvec &a, const _Tpvec &b) { \
1278
+ return _Tpvec(_mm_cmpge_##suffix(a.val, b.val)); \
1279
+ }
1280
+
1281
+ OPENCV_HAL_IMPL_SSE_FLT_CMP_OP(v_float32x4, ps)
1282
+ OPENCV_HAL_IMPL_SSE_FLT_CMP_OP(v_float64x2, pd)
1283
+
1284
+ #if CV_SSE4_1
1285
+ #define OPENCV_HAL_IMPL_SSE_64BIT_CMP_OP(_Tpvec) \
1286
+ inline _Tpvec v_eq(const _Tpvec &a, const _Tpvec &b) { \
1287
+ return _Tpvec(_mm_cmpeq_epi64(a.val, b.val)); \
1288
+ } \
1289
+ inline _Tpvec v_ne(const _Tpvec &a, const _Tpvec &b) { \
1290
+ return v_not(v_eq(a, b)); \
1291
+ }
1292
+ #else
1293
+ #define OPENCV_HAL_IMPL_SSE_64BIT_CMP_OP(_Tpvec) \
1294
+ inline _Tpvec v_eq(const _Tpvec &a, const _Tpvec &b) { \
1295
+ __m128i cmp = _mm_cmpeq_epi32(a.val, b.val); \
1296
+ return _Tpvec( \
1297
+ _mm_and_si128(cmp, _mm_shuffle_epi32(cmp, _MM_SHUFFLE(2, 3, 0, 1)))); \
1298
+ } \
1299
+ inline _Tpvec v_ne(const _Tpvec &a, const _Tpvec &b) { \
1300
+ return v_not(v_eq(a, b)); \
1301
+ }
1302
+ #endif
1303
+
1304
+ OPENCV_HAL_IMPL_SSE_64BIT_CMP_OP(v_uint64x2)
1305
+ OPENCV_HAL_IMPL_SSE_64BIT_CMP_OP(v_int64x2)
1306
+
1307
+ inline v_float32x4 v_not_nan(const v_float32x4 &a) {
1308
+ return v_float32x4(_mm_cmpord_ps(a.val, a.val));
1309
+ }
1310
+ inline v_float64x2 v_not_nan(const v_float64x2 &a) {
1311
+ return v_float64x2(_mm_cmpord_pd(a.val, a.val));
1312
+ }
1313
+
1314
+ OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint8x16, v_add_wrap, _mm_add_epi8)
1315
+ OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_int8x16, v_add_wrap, _mm_add_epi8)
1316
+ OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint16x8, v_add_wrap, _mm_add_epi16)
1317
+ OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_int16x8, v_add_wrap, _mm_add_epi16)
1318
+ OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint8x16, v_sub_wrap, _mm_sub_epi8)
1319
+ OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_int8x16, v_sub_wrap, _mm_sub_epi8)
1320
+ OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint16x8, v_sub_wrap, _mm_sub_epi16)
1321
+ OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_int16x8, v_sub_wrap, _mm_sub_epi16)
1322
+ OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint16x8, v_mul_wrap, _mm_mullo_epi16)
1323
+ OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_int16x8, v_mul_wrap, _mm_mullo_epi16)
1324
+
1325
+ inline v_uint8x16 v_mul_wrap(const v_uint8x16 &a, const v_uint8x16 &b) {
1326
+ __m128i ad = _mm_srai_epi16(a.val, 8);
1327
+ __m128i bd = _mm_srai_epi16(b.val, 8);
1328
+ __m128i p0 = _mm_mullo_epi16(a.val, b.val); // even
1329
+ __m128i p1 = _mm_slli_epi16(_mm_mullo_epi16(ad, bd), 8); // odd
1330
+ const __m128i b01 = _mm_set1_epi32(0xFF00FF00);
1331
+ return v_uint8x16(_v128_blendv_epi8(p0, p1, b01));
1332
+ }
1333
+ inline v_int8x16 v_mul_wrap(const v_int8x16 &a, const v_int8x16 &b) {
1334
+ return v_reinterpret_as_s8(
1335
+ v_mul_wrap(v_reinterpret_as_u8(a), v_reinterpret_as_u8(b)));
1336
+ }
1337
+
1338
+ /** Absolute difference **/
1339
+
1340
+ inline v_uint8x16 v_absdiff(const v_uint8x16 &a, const v_uint8x16 &b) {
1341
+ return v_add_wrap(v_sub(a, b), v_sub(b, a));
1342
+ }
1343
+ inline v_uint16x8 v_absdiff(const v_uint16x8 &a, const v_uint16x8 &b) {
1344
+ return v_add_wrap(v_sub(a, b), v_sub(b, a));
1345
+ }
1346
+ inline v_uint32x4 v_absdiff(const v_uint32x4 &a, const v_uint32x4 &b) {
1347
+ return v_sub(v_max(a, b), v_min(a, b));
1348
+ }
1349
+
1350
+ inline v_uint8x16 v_absdiff(const v_int8x16 &a, const v_int8x16 &b) {
1351
+ v_int8x16 d = v_sub_wrap(a, b);
1352
+ v_int8x16 m = v_lt(a, b);
1353
+ return v_reinterpret_as_u8(v_sub_wrap(v_xor(d, m), m));
1354
+ }
1355
+ inline v_uint16x8 v_absdiff(const v_int16x8 &a, const v_int16x8 &b) {
1356
+ return v_reinterpret_as_u16(v_sub_wrap(v_max(a, b), v_min(a, b)));
1357
+ }
1358
+ inline v_uint32x4 v_absdiff(const v_int32x4 &a, const v_int32x4 &b) {
1359
+ v_int32x4 d = v_sub(a, b);
1360
+ v_int32x4 m = v_lt(a, b);
1361
+ return v_reinterpret_as_u32(v_sub(v_xor(d, m), m));
1362
+ }
1363
+
1364
+ /** Saturating absolute difference **/
1365
+ inline v_int8x16 v_absdiffs(const v_int8x16 &a, const v_int8x16 &b) {
1366
+ v_int8x16 d = v_sub(a, b);
1367
+ v_int8x16 m = v_lt(a, b);
1368
+ return v_sub(v_xor(d, m), m);
1369
+ }
1370
+ inline v_int16x8 v_absdiffs(const v_int16x8 &a, const v_int16x8 &b) {
1371
+ return v_sub(v_max(a, b), v_min(a, b));
1372
+ }
1373
+
1374
+ inline v_int32x4 v_fma(const v_int32x4 &a, const v_int32x4 &b,
1375
+ const v_int32x4 &c) {
1376
+ return v_add(v_mul(a, b), c);
1377
+ }
1378
+
1379
+ inline v_int32x4 v_muladd(const v_int32x4 &a, const v_int32x4 &b,
1380
+ const v_int32x4 &c) {
1381
+ return v_fma(a, b, c);
1382
+ }
1383
+
1384
+ inline v_float32x4 v_fma(const v_float32x4 &a, const v_float32x4 &b,
1385
+ const v_float32x4 &c) {
1386
+ #if CV_FMA3
1387
+ return v_float32x4(_mm_fmadd_ps(a.val, b.val, c.val));
1388
+ #else
1389
+ return v_float32x4(_mm_add_ps(_mm_mul_ps(a.val, b.val), c.val));
1390
+ #endif
1391
+ }
1392
+
1393
+ inline v_float64x2 v_fma(const v_float64x2 &a, const v_float64x2 &b,
1394
+ const v_float64x2 &c) {
1395
+ #if CV_FMA3
1396
+ return v_float64x2(_mm_fmadd_pd(a.val, b.val, c.val));
1397
+ #else
1398
+ return v_float64x2(_mm_add_pd(_mm_mul_pd(a.val, b.val), c.val));
1399
+ #endif
1400
+ }
1401
+
1402
+ #define OPENCV_HAL_IMPL_SSE_MISC_FLT_OP(_Tpvec, _Tp, _Tpreg, suffix, \
1403
+ absmask_vec) \
1404
+ inline _Tpvec v_absdiff(const _Tpvec &a, const _Tpvec &b) { \
1405
+ _Tpreg absmask = _mm_castsi128_##suffix(absmask_vec); \
1406
+ return _Tpvec(_mm_and_##suffix(_mm_sub_##suffix(a.val, b.val), absmask)); \
1407
+ } \
1408
+ inline _Tpvec v_magnitude(const _Tpvec &a, const _Tpvec &b) { \
1409
+ _Tpvec res = v_fma(a, a, v_mul(b, b)); \
1410
+ return _Tpvec(_mm_sqrt_##suffix(res.val)); \
1411
+ } \
1412
+ inline _Tpvec v_sqr_magnitude(const _Tpvec &a, const _Tpvec &b) { \
1413
+ return v_fma(a, a, v_mul(b, b)); \
1414
+ } \
1415
+ inline _Tpvec v_muladd(const _Tpvec &a, const _Tpvec &b, const _Tpvec &c) { \
1416
+ return v_fma(a, b, c); \
1417
+ }
1418
+
1419
+ OPENCV_HAL_IMPL_SSE_MISC_FLT_OP(v_float32x4, float, __m128, ps,
1420
+ _mm_set1_epi32((int)0x7fffffff))
1421
+ OPENCV_HAL_IMPL_SSE_MISC_FLT_OP(v_float64x2, double, __m128d, pd,
1422
+ _mm_srli_epi64(_mm_set1_epi32(-1), 1))
1423
+
1424
+ #define OPENCV_HAL_IMPL_SSE_SHIFT_OP(_Tpuvec, _Tpsvec, suffix, srai) \
1425
+ inline _Tpuvec v_shl(const _Tpuvec &a, int imm) { \
1426
+ return _Tpuvec(_mm_slli_##suffix(a.val, imm)); \
1427
+ } \
1428
+ inline _Tpsvec v_shl(const _Tpsvec &a, int imm) { \
1429
+ return _Tpsvec(_mm_slli_##suffix(a.val, imm)); \
1430
+ } \
1431
+ inline _Tpuvec v_shr(const _Tpuvec &a, int imm) { \
1432
+ return _Tpuvec(_mm_srli_##suffix(a.val, imm)); \
1433
+ } \
1434
+ inline _Tpsvec v_shr(const _Tpsvec &a, int imm) { \
1435
+ return _Tpsvec(srai(a.val, imm)); \
1436
+ } \
1437
+ template <int imm> inline _Tpuvec v_shl(const _Tpuvec &a) { \
1438
+ return _Tpuvec(_mm_slli_##suffix(a.val, imm)); \
1439
+ } \
1440
+ template <int imm> inline _Tpsvec v_shl(const _Tpsvec &a) { \
1441
+ return _Tpsvec(_mm_slli_##suffix(a.val, imm)); \
1442
+ } \
1443
+ template <int imm> inline _Tpuvec v_shr(const _Tpuvec &a) { \
1444
+ return _Tpuvec(_mm_srli_##suffix(a.val, imm)); \
1445
+ } \
1446
+ template <int imm> inline _Tpsvec v_shr(const _Tpsvec &a) { \
1447
+ return _Tpsvec(srai(a.val, imm)); \
1448
+ }
1449
+
1450
+ OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint16x8, v_int16x8, epi16, _mm_srai_epi16)
1451
+ OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint32x4, v_int32x4, epi32, _mm_srai_epi32)
1452
+ OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint64x2, v_int64x2, epi64, v_srai_epi64)
1453
+
1454
+ namespace hal_sse_internal {
1455
+ template <int imm, bool is_invalid = ((imm < 0) || (imm > 16)),
1456
+ bool is_first = (imm == 0), bool is_half = (imm == 8),
1457
+ bool is_second = (imm == 16),
1458
+ bool is_other =
1459
+ (((imm > 0) && (imm < 8)) || ((imm > 8) && (imm < 16)))>
1460
+ class v_sse_palignr_u8_class;
1461
+
1462
+ template <int imm>
1463
+ class v_sse_palignr_u8_class<imm, true, false, false, false, false>;
1464
+
1465
+ template <int imm>
1466
+ class v_sse_palignr_u8_class<imm, false, true, false, false, false> {
1467
+ public:
1468
+ inline __m128i operator()(const __m128i &a, const __m128i &) const {
1469
+ return a;
1470
+ }
1471
+ };
1472
+
1473
+ template <int imm>
1474
+ class v_sse_palignr_u8_class<imm, false, false, true, false, false> {
1475
+ public:
1476
+ inline __m128i operator()(const __m128i &a, const __m128i &b) const {
1477
+ return _mm_unpacklo_epi64(_mm_unpackhi_epi64(a, a), b);
1478
+ }
1479
+ };
1480
+
1481
+ template <int imm>
1482
+ class v_sse_palignr_u8_class<imm, false, false, false, true, false> {
1483
+ public:
1484
+ inline __m128i operator()(const __m128i &, const __m128i &b) const {
1485
+ return b;
1486
+ }
1487
+ };
1488
+
1489
+ template <int imm>
1490
+ class v_sse_palignr_u8_class<imm, false, false, false, false, true> {
1491
+ #if CV_SSSE3
1492
+ public:
1493
+ inline __m128i operator()(const __m128i &a, const __m128i &b) const {
1494
+ return _mm_alignr_epi8(b, a, imm);
1495
+ }
1496
+ #else
1497
+ public:
1498
+ inline __m128i operator()(const __m128i &a, const __m128i &b) const {
1499
+ enum { imm2 = (sizeof(__m128i) - imm) };
1500
+ return _mm_or_si128(_mm_srli_si128(a, imm), _mm_slli_si128(b, imm2));
1501
+ }
1502
+ #endif
1503
+ };
1504
+
1505
+ template <int imm>
1506
+ inline __m128i v_sse_palignr_u8(const __m128i &a, const __m128i &b) {
1507
+ CV_StaticAssert((imm >= 0) && (imm <= 16),
1508
+ "Invalid imm for v_sse_palignr_u8.");
1509
+ return v_sse_palignr_u8_class<imm>()(a, b);
1510
+ }
1511
+ } // namespace hal_sse_internal
1512
+
1513
+ template <int imm, typename _Tpvec>
1514
+ inline _Tpvec v_rotate_right(const _Tpvec &a) {
1515
+ using namespace hal_sse_internal;
1516
+ enum { imm2 = (imm * sizeof(typename _Tpvec::lane_type)) };
1517
+ return _Tpvec(v_sse_reinterpret_as<typename _Tpvec::vector_type>(
1518
+ _mm_srli_si128(v_sse_reinterpret_as<__m128i>(a.val), imm2)));
1519
+ }
1520
+
1521
+ template <int imm, typename _Tpvec>
1522
+ inline _Tpvec v_rotate_left(const _Tpvec &a) {
1523
+ using namespace hal_sse_internal;
1524
+ enum { imm2 = (imm * sizeof(typename _Tpvec::lane_type)) };
1525
+ return _Tpvec(v_sse_reinterpret_as<typename _Tpvec::vector_type>(
1526
+ _mm_slli_si128(v_sse_reinterpret_as<__m128i>(a.val), imm2)));
1527
+ }
1528
+
1529
+ template <int imm, typename _Tpvec>
1530
+ inline _Tpvec v_rotate_right(const _Tpvec &a, const _Tpvec &b) {
1531
+ using namespace hal_sse_internal;
1532
+ enum { imm2 = (imm * sizeof(typename _Tpvec::lane_type)) };
1533
+ return _Tpvec(v_sse_reinterpret_as<typename _Tpvec::vector_type>(
1534
+ v_sse_palignr_u8<imm2>(v_sse_reinterpret_as<__m128i>(a.val),
1535
+ v_sse_reinterpret_as<__m128i>(b.val))));
1536
+ }
1537
+
1538
+ template <int imm, typename _Tpvec>
1539
+ inline _Tpvec v_rotate_left(const _Tpvec &a, const _Tpvec &b) {
1540
+ using namespace hal_sse_internal;
1541
+ enum { imm2 = ((_Tpvec::nlanes - imm) * sizeof(typename _Tpvec::lane_type)) };
1542
+ return _Tpvec(v_sse_reinterpret_as<typename _Tpvec::vector_type>(
1543
+ v_sse_palignr_u8<imm2>(v_sse_reinterpret_as<__m128i>(b.val),
1544
+ v_sse_reinterpret_as<__m128i>(a.val))));
1545
+ }
1546
+
1547
+ #define OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(_Tpvec, _Tp) \
1548
+ inline _Tpvec v_load(const _Tp *ptr) { \
1549
+ return _Tpvec(_mm_loadu_si128((const __m128i *)ptr)); \
1550
+ } \
1551
+ inline _Tpvec v_load_aligned(const _Tp *ptr) { \
1552
+ return _Tpvec(_mm_load_si128((const __m128i *)ptr)); \
1553
+ } \
1554
+ inline _Tpvec v_load_low(const _Tp *ptr) { \
1555
+ return _Tpvec(_mm_loadl_epi64((const __m128i *)ptr)); \
1556
+ } \
1557
+ inline _Tpvec v_load_halves(const _Tp *ptr0, const _Tp *ptr1) { \
1558
+ return _Tpvec(_mm_unpacklo_epi64(_mm_loadl_epi64((const __m128i *)ptr0), \
1559
+ _mm_loadl_epi64((const __m128i *)ptr1))); \
1560
+ } \
1561
+ inline void v_store(_Tp *ptr, const _Tpvec &a) { \
1562
+ _mm_storeu_si128((__m128i *)ptr, a.val); \
1563
+ } \
1564
+ inline void v_store_aligned(_Tp *ptr, const _Tpvec &a) { \
1565
+ _mm_store_si128((__m128i *)ptr, a.val); \
1566
+ } \
1567
+ inline void v_store_aligned_nocache(_Tp *ptr, const _Tpvec &a) { \
1568
+ _mm_stream_si128((__m128i *)ptr, a.val); \
1569
+ } \
1570
+ inline void v_store(_Tp *ptr, const _Tpvec &a, hal::StoreMode mode) { \
1571
+ if (mode == hal::STORE_UNALIGNED) \
1572
+ _mm_storeu_si128((__m128i *)ptr, a.val); \
1573
+ else if (mode == hal::STORE_ALIGNED_NOCACHE) \
1574
+ _mm_stream_si128((__m128i *)ptr, a.val); \
1575
+ else \
1576
+ _mm_store_si128((__m128i *)ptr, a.val); \
1577
+ } \
1578
+ inline void v_store_low(_Tp *ptr, const _Tpvec &a) { \
1579
+ _mm_storel_epi64((__m128i *)ptr, a.val); \
1580
+ } \
1581
+ inline void v_store_high(_Tp *ptr, const _Tpvec &a) { \
1582
+ _mm_storel_epi64((__m128i *)ptr, _mm_unpackhi_epi64(a.val, a.val)); \
1583
+ }
1584
+
1585
+ OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_uint8x16, uchar)
1586
+ OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_int8x16, schar)
1587
+ OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_uint16x8, ushort)
1588
+ OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_int16x8, short)
1589
+ OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_uint32x4, unsigned)
1590
+ OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_int32x4, int)
1591
+ OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_uint64x2, uint64)
1592
+ OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_int64x2, int64)
1593
+
1594
+ #define OPENCV_HAL_IMPL_SSE_LOADSTORE_FLT_OP(_Tpvec, _Tp, suffix) \
1595
+ inline _Tpvec v_load(const _Tp *ptr) { \
1596
+ return _Tpvec(_mm_loadu_##suffix(ptr)); \
1597
+ } \
1598
+ inline _Tpvec v_load_aligned(const _Tp *ptr) { \
1599
+ return _Tpvec(_mm_load_##suffix(ptr)); \
1600
+ } \
1601
+ inline _Tpvec v_load_low(const _Tp *ptr) { \
1602
+ return _Tpvec( \
1603
+ _mm_castsi128_##suffix(_mm_loadl_epi64((const __m128i *)ptr))); \
1604
+ } \
1605
+ inline _Tpvec v_load_halves(const _Tp *ptr0, const _Tp *ptr1) { \
1606
+ return _Tpvec(_mm_castsi128_##suffix( \
1607
+ _mm_unpacklo_epi64(_mm_loadl_epi64((const __m128i *)ptr0), \
1608
+ _mm_loadl_epi64((const __m128i *)ptr1)))); \
1609
+ } \
1610
+ inline void v_store(_Tp *ptr, const _Tpvec &a) { \
1611
+ _mm_storeu_##suffix(ptr, a.val); \
1612
+ } \
1613
+ inline void v_store_aligned(_Tp *ptr, const _Tpvec &a) { \
1614
+ _mm_store_##suffix(ptr, a.val); \
1615
+ } \
1616
+ inline void v_store_aligned_nocache(_Tp *ptr, const _Tpvec &a) { \
1617
+ _mm_stream_##suffix(ptr, a.val); \
1618
+ } \
1619
+ inline void v_store(_Tp *ptr, const _Tpvec &a, hal::StoreMode mode) { \
1620
+ if (mode == hal::STORE_UNALIGNED) \
1621
+ _mm_storeu_##suffix(ptr, a.val); \
1622
+ else if (mode == hal::STORE_ALIGNED_NOCACHE) \
1623
+ _mm_stream_##suffix(ptr, a.val); \
1624
+ else \
1625
+ _mm_store_##suffix(ptr, a.val); \
1626
+ } \
1627
+ inline void v_store_low(_Tp *ptr, const _Tpvec &a) { \
1628
+ _mm_storel_epi64((__m128i *)ptr, _mm_cast##suffix##_si128(a.val)); \
1629
+ } \
1630
+ inline void v_store_high(_Tp *ptr, const _Tpvec &a) { \
1631
+ __m128i a1 = _mm_cast##suffix##_si128(a.val); \
1632
+ _mm_storel_epi64((__m128i *)ptr, _mm_unpackhi_epi64(a1, a1)); \
1633
+ }
1634
+
1635
+ OPENCV_HAL_IMPL_SSE_LOADSTORE_FLT_OP(v_float32x4, float, ps)
1636
+ OPENCV_HAL_IMPL_SSE_LOADSTORE_FLT_OP(v_float64x2, double, pd)
1637
+
1638
+ inline unsigned v_reduce_sum(const v_uint8x16 &a) {
1639
+ __m128i half = _mm_sad_epu8(a.val, _mm_setzero_si128());
1640
+ return (unsigned)_mm_cvtsi128_si32(
1641
+ _mm_add_epi32(half, _mm_unpackhi_epi64(half, half)));
1642
+ }
1643
+ inline int v_reduce_sum(const v_int8x16 &a) {
1644
+ __m128i half = _mm_set1_epi8((schar)-128);
1645
+ half = _mm_sad_epu8(_mm_xor_si128(a.val, half), _mm_setzero_si128());
1646
+ return _mm_cvtsi128_si32(
1647
+ _mm_add_epi32(half, _mm_unpackhi_epi64(half, half))) -
1648
+ 2048;
1649
+ }
1650
+ #define OPENCV_HAL_IMPL_SSE_REDUCE_OP_16(func) \
1651
+ inline schar v_reduce_##func(const v_int8x16 &a) { \
1652
+ __m128i val = a.val; \
1653
+ __m128i smask = _mm_set1_epi8((schar) - 128); \
1654
+ val = _mm_xor_si128(val, smask); \
1655
+ val = _mm_##func##_epu8(val, _mm_srli_si128(val, 8)); \
1656
+ val = _mm_##func##_epu8(val, _mm_srli_si128(val, 4)); \
1657
+ val = _mm_##func##_epu8(val, _mm_srli_si128(val, 2)); \
1658
+ val = _mm_##func##_epu8(val, _mm_srli_si128(val, 1)); \
1659
+ return (schar)_mm_cvtsi128_si32(val) ^ (schar) - 128; \
1660
+ } \
1661
+ inline uchar v_reduce_##func(const v_uint8x16 &a) { \
1662
+ __m128i val = a.val; \
1663
+ val = _mm_##func##_epu8(val, _mm_srli_si128(val, 8)); \
1664
+ val = _mm_##func##_epu8(val, _mm_srli_si128(val, 4)); \
1665
+ val = _mm_##func##_epu8(val, _mm_srli_si128(val, 2)); \
1666
+ val = _mm_##func##_epu8(val, _mm_srli_si128(val, 1)); \
1667
+ return (uchar)_mm_cvtsi128_si32(val); \
1668
+ }
1669
+ OPENCV_HAL_IMPL_SSE_REDUCE_OP_16(max)
1670
+ OPENCV_HAL_IMPL_SSE_REDUCE_OP_16(min)
1671
+
1672
+ #define OPENCV_HAL_IMPL_SSE_REDUCE_OP_8(_Tpvec, scalartype, func, suffix, \
1673
+ sbit) \
1674
+ inline scalartype v_reduce_##func(const v_##_Tpvec &a) { \
1675
+ __m128i val = a.val; \
1676
+ val = _mm_##func##_##suffix(val, _mm_srli_si128(val, 8)); \
1677
+ val = _mm_##func##_##suffix(val, _mm_srli_si128(val, 4)); \
1678
+ val = _mm_##func##_##suffix(val, _mm_srli_si128(val, 2)); \
1679
+ return (scalartype)_mm_cvtsi128_si32(val); \
1680
+ } \
1681
+ inline unsigned scalartype v_reduce_##func(const v_u##_Tpvec &a) { \
1682
+ __m128i val = a.val; \
1683
+ __m128i smask = _mm_set1_epi16(sbit); \
1684
+ val = _mm_xor_si128(val, smask); \
1685
+ val = _mm_##func##_##suffix(val, _mm_srli_si128(val, 8)); \
1686
+ val = _mm_##func##_##suffix(val, _mm_srli_si128(val, 4)); \
1687
+ val = _mm_##func##_##suffix(val, _mm_srli_si128(val, 2)); \
1688
+ return (unsigned scalartype)(_mm_cvtsi128_si32(val) ^ sbit); \
1689
+ }
1690
+ OPENCV_HAL_IMPL_SSE_REDUCE_OP_8(int16x8, short, max, epi16, (short)-32768)
1691
+ OPENCV_HAL_IMPL_SSE_REDUCE_OP_8(int16x8, short, min, epi16, (short)-32768)
1692
+
1693
+ #define OPENCV_HAL_IMPL_SSE_REDUCE_OP_4_SUM( \
1694
+ _Tpvec, scalartype, regtype, suffix, cast_from, cast_to, extract) \
1695
+ inline scalartype v_reduce_sum(const _Tpvec &a) { \
1696
+ regtype val = a.val; \
1697
+ val = _mm_add_##suffix(val, cast_to(_mm_srli_si128(cast_from(val), 8))); \
1698
+ val = _mm_add_##suffix(val, cast_to(_mm_srli_si128(cast_from(val), 4))); \
1699
+ return (scalartype)_mm_cvt##extract(val); \
1700
+ }
1701
+
1702
+ #define OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(_Tpvec, scalartype, func, scalar_func) \
1703
+ inline scalartype v_reduce_##func(const _Tpvec &a) { \
1704
+ scalartype CV_DECL_ALIGNED(16) buf[4]; \
1705
+ v_store_aligned(buf, a); \
1706
+ scalartype s0 = scalar_func(buf[0], buf[1]); \
1707
+ scalartype s1 = scalar_func(buf[2], buf[3]); \
1708
+ return scalar_func(s0, s1); \
1709
+ }
1710
+
1711
+ OPENCV_HAL_IMPL_SSE_REDUCE_OP_4_SUM(v_uint32x4, unsigned, __m128i, epi32,
1712
+ OPENCV_HAL_NOP, OPENCV_HAL_NOP, si128_si32)
1713
+ OPENCV_HAL_IMPL_SSE_REDUCE_OP_4_SUM(v_int32x4, int, __m128i, epi32,
1714
+ OPENCV_HAL_NOP, OPENCV_HAL_NOP, si128_si32)
1715
+ OPENCV_HAL_IMPL_SSE_REDUCE_OP_4_SUM(v_float32x4, float, __m128, ps,
1716
+ _mm_castps_si128, _mm_castsi128_ps, ss_f32)
1717
+
1718
+ inline int v_reduce_sum(const v_int16x8 &a) {
1719
+ return v_reduce_sum(v_add(v_expand_low(a), v_expand_high(a)));
1720
+ }
1721
+ inline unsigned v_reduce_sum(const v_uint16x8 &a) {
1722
+ return v_reduce_sum(v_add(v_expand_low(a), v_expand_high(a)));
1723
+ }
1724
+
1725
+ inline uint64 v_reduce_sum(const v_uint64x2 &a) {
1726
+ uint64 CV_DECL_ALIGNED(32) idx[2];
1727
+ v_store_aligned(idx, a);
1728
+ return idx[0] + idx[1];
1729
+ }
1730
+ inline int64 v_reduce_sum(const v_int64x2 &a) {
1731
+ int64 CV_DECL_ALIGNED(32) idx[2];
1732
+ v_store_aligned(idx, a);
1733
+ return idx[0] + idx[1];
1734
+ }
1735
+ inline double v_reduce_sum(const v_float64x2 &a) {
1736
+ double CV_DECL_ALIGNED(32) idx[2];
1737
+ v_store_aligned(idx, a);
1738
+ return idx[0] + idx[1];
1739
+ }
1740
+
1741
+ inline v_float32x4 v_reduce_sum4(const v_float32x4 &a, const v_float32x4 &b,
1742
+ const v_float32x4 &c, const v_float32x4 &d) {
1743
+ #if CV_SSE3
1744
+ __m128 ab = _mm_hadd_ps(a.val, b.val);
1745
+ __m128 cd = _mm_hadd_ps(c.val, d.val);
1746
+ return v_float32x4(_mm_hadd_ps(ab, cd));
1747
+ #else
1748
+ __m128 ac =
1749
+ _mm_add_ps(_mm_unpacklo_ps(a.val, c.val), _mm_unpackhi_ps(a.val, c.val));
1750
+ __m128 bd =
1751
+ _mm_add_ps(_mm_unpacklo_ps(b.val, d.val), _mm_unpackhi_ps(b.val, d.val));
1752
+ return v_float32x4(
1753
+ _mm_add_ps(_mm_unpacklo_ps(ac, bd), _mm_unpackhi_ps(ac, bd)));
1754
+ #endif
1755
+ }
1756
+
1757
+ OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_uint32x4, unsigned, max, std::max)
1758
+ OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_uint32x4, unsigned, min, std::min)
1759
+ OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_int32x4, int, max, std::max)
1760
+ OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_int32x4, int, min, std::min)
1761
+ OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_float32x4, float, max, std::max)
1762
+ OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_float32x4, float, min, std::min)
1763
+
1764
+ inline unsigned v_reduce_sad(const v_uint8x16 &a, const v_uint8x16 &b) {
1765
+ __m128i half = _mm_sad_epu8(a.val, b.val);
1766
+ return (unsigned)_mm_cvtsi128_si32(
1767
+ _mm_add_epi32(half, _mm_unpackhi_epi64(half, half)));
1768
+ }
1769
+ inline unsigned v_reduce_sad(const v_int8x16 &a, const v_int8x16 &b) {
1770
+ __m128i half = _mm_set1_epi8(0x7f);
1771
+ half = _mm_sad_epu8(_mm_add_epi8(a.val, half), _mm_add_epi8(b.val, half));
1772
+ return (unsigned)_mm_cvtsi128_si32(
1773
+ _mm_add_epi32(half, _mm_unpackhi_epi64(half, half)));
1774
+ }
1775
+ inline unsigned v_reduce_sad(const v_uint16x8 &a, const v_uint16x8 &b) {
1776
+ v_uint32x4 l, h;
1777
+ v_expand(v_absdiff(a, b), l, h);
1778
+ return v_reduce_sum(v_add(l, h));
1779
+ }
1780
+ inline unsigned v_reduce_sad(const v_int16x8 &a, const v_int16x8 &b) {
1781
+ v_uint32x4 l, h;
1782
+ v_expand(v_absdiff(a, b), l, h);
1783
+ return v_reduce_sum(v_add(l, h));
1784
+ }
1785
+ inline unsigned v_reduce_sad(const v_uint32x4 &a, const v_uint32x4 &b) {
1786
+ return v_reduce_sum(v_absdiff(a, b));
1787
+ }
1788
+ inline unsigned v_reduce_sad(const v_int32x4 &a, const v_int32x4 &b) {
1789
+ return v_reduce_sum(v_absdiff(a, b));
1790
+ }
1791
+ inline float v_reduce_sad(const v_float32x4 &a, const v_float32x4 &b) {
1792
+ return v_reduce_sum(v_absdiff(a, b));
1793
+ }
1794
+
1795
+ inline v_uint8x16 v_popcount(const v_uint8x16 &a) {
1796
+ __m128i m1 = _mm_set1_epi32(0x55555555);
1797
+ __m128i m2 = _mm_set1_epi32(0x33333333);
1798
+ __m128i m4 = _mm_set1_epi32(0x0f0f0f0f);
1799
+ __m128i p = a.val;
1800
+ p = _mm_add_epi32(_mm_and_si128(_mm_srli_epi32(p, 1), m1),
1801
+ _mm_and_si128(p, m1));
1802
+ p = _mm_add_epi32(_mm_and_si128(_mm_srli_epi32(p, 2), m2),
1803
+ _mm_and_si128(p, m2));
1804
+ p = _mm_add_epi32(_mm_and_si128(_mm_srli_epi32(p, 4), m4),
1805
+ _mm_and_si128(p, m4));
1806
+ return v_uint8x16(p);
1807
+ }
1808
+ inline v_uint16x8 v_popcount(const v_uint16x8 &a) {
1809
+ v_uint8x16 p = v_popcount(v_reinterpret_as_u8(a));
1810
+ p = v_add(p, v_rotate_right<1>(p));
1811
+ return v_and(v_reinterpret_as_u16(p), v_setall_u16(0x00ff));
1812
+ }
1813
+ inline v_uint32x4 v_popcount(const v_uint32x4 &a) {
1814
+ v_uint8x16 p = v_popcount(v_reinterpret_as_u8(a));
1815
+ p = v_add(p, v_rotate_right<1>(p));
1816
+ p = v_add(p, v_rotate_right<2>(p));
1817
+ return v_and(v_reinterpret_as_u32(p), v_setall_u32(0x000000ff));
1818
+ }
1819
+ inline v_uint64x2 v_popcount(const v_uint64x2 &a) {
1820
+ return v_uint64x2(_mm_sad_epu8(v_popcount(v_reinterpret_as_u8(a)).val,
1821
+ _mm_setzero_si128()));
1822
+ }
1823
+ inline v_uint8x16 v_popcount(const v_int8x16 &a) {
1824
+ return v_popcount(v_reinterpret_as_u8(a));
1825
+ }
1826
+ inline v_uint16x8 v_popcount(const v_int16x8 &a) {
1827
+ return v_popcount(v_reinterpret_as_u16(a));
1828
+ }
1829
+ inline v_uint32x4 v_popcount(const v_int32x4 &a) {
1830
+ return v_popcount(v_reinterpret_as_u32(a));
1831
+ }
1832
+ inline v_uint64x2 v_popcount(const v_int64x2 &a) {
1833
+ return v_popcount(v_reinterpret_as_u64(a));
1834
+ }
1835
+
1836
+ #define OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(_Tpvec, suffix, cast_op, allmask) \
1837
+ inline int v_signmask(const _Tpvec &a) { \
1838
+ return _mm_movemask_##suffix(cast_op(a.val)); \
1839
+ } \
1840
+ inline bool v_check_all(const _Tpvec &a) { \
1841
+ return _mm_movemask_##suffix(cast_op(a.val)) == allmask; \
1842
+ } \
1843
+ inline bool v_check_any(const _Tpvec &a) { \
1844
+ return _mm_movemask_##suffix(cast_op(a.val)) != 0; \
1845
+ }
1846
+ OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_uint8x16, epi8, OPENCV_HAL_NOP, 65535)
1847
+ OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_int8x16, epi8, OPENCV_HAL_NOP, 65535)
1848
+ OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_uint32x4, ps, _mm_castsi128_ps, 15)
1849
+ OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_int32x4, ps, _mm_castsi128_ps, 15)
1850
+ OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_uint64x2, pd, _mm_castsi128_pd, 3)
1851
+ OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_int64x2, pd, _mm_castsi128_pd, 3)
1852
+ OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_float32x4, ps, OPENCV_HAL_NOP, 15)
1853
+ OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_float64x2, pd, OPENCV_HAL_NOP, 3)
1854
+
1855
+ #define OPENCV_HAL_IMPL_SSE_CHECK_SIGNS_SHORT(_Tpvec) \
1856
+ inline int v_signmask(const _Tpvec &a) { \
1857
+ return _mm_movemask_epi8(_mm_packs_epi16(a.val, a.val)) & 255; \
1858
+ } \
1859
+ inline bool v_check_all(const _Tpvec &a) { \
1860
+ return (_mm_movemask_epi8(a.val) & 0xaaaa) == 0xaaaa; \
1861
+ } \
1862
+ inline bool v_check_any(const _Tpvec &a) { \
1863
+ return (_mm_movemask_epi8(a.val) & 0xaaaa) != 0; \
1864
+ }
1865
+ OPENCV_HAL_IMPL_SSE_CHECK_SIGNS_SHORT(v_uint16x8)
1866
+ OPENCV_HAL_IMPL_SSE_CHECK_SIGNS_SHORT(v_int16x8)
1867
+
1868
+ inline int v_scan_forward(const v_int8x16 &a) {
1869
+ return trailingZeros32(v_signmask(v_reinterpret_as_s8(a)));
1870
+ }
1871
+ inline int v_scan_forward(const v_uint8x16 &a) {
1872
+ return trailingZeros32(v_signmask(v_reinterpret_as_s8(a)));
1873
+ }
1874
+ inline int v_scan_forward(const v_int16x8 &a) {
1875
+ return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 2;
1876
+ }
1877
+ inline int v_scan_forward(const v_uint16x8 &a) {
1878
+ return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 2;
1879
+ }
1880
+ inline int v_scan_forward(const v_int32x4 &a) {
1881
+ return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 4;
1882
+ }
1883
+ inline int v_scan_forward(const v_uint32x4 &a) {
1884
+ return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 4;
1885
+ }
1886
+ inline int v_scan_forward(const v_float32x4 &a) {
1887
+ return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 4;
1888
+ }
1889
+ inline int v_scan_forward(const v_int64x2 &a) {
1890
+ return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 8;
1891
+ }
1892
+ inline int v_scan_forward(const v_uint64x2 &a) {
1893
+ return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 8;
1894
+ }
1895
+ inline int v_scan_forward(const v_float64x2 &a) {
1896
+ return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 8;
1897
+ }
1898
+
1899
+ #if CV_SSE4_1
1900
+ #define OPENCV_HAL_IMPL_SSE_SELECT(_Tpvec, cast_ret, cast, suffix) \
1901
+ inline _Tpvec v_select(const _Tpvec &mask, const _Tpvec &a, \
1902
+ const _Tpvec &b) { \
1903
+ return _Tpvec(cast_ret( \
1904
+ _mm_blendv_##suffix(cast(b.val), cast(a.val), cast(mask.val)))); \
1905
+ }
1906
+
1907
+ OPENCV_HAL_IMPL_SSE_SELECT(v_uint8x16, OPENCV_HAL_NOP, OPENCV_HAL_NOP, epi8)
1908
+ OPENCV_HAL_IMPL_SSE_SELECT(v_int8x16, OPENCV_HAL_NOP, OPENCV_HAL_NOP, epi8)
1909
+ OPENCV_HAL_IMPL_SSE_SELECT(v_uint16x8, OPENCV_HAL_NOP, OPENCV_HAL_NOP, epi8)
1910
+ OPENCV_HAL_IMPL_SSE_SELECT(v_int16x8, OPENCV_HAL_NOP, OPENCV_HAL_NOP, epi8)
1911
+ OPENCV_HAL_IMPL_SSE_SELECT(v_uint32x4, _mm_castps_si128, _mm_castsi128_ps, ps)
1912
+ OPENCV_HAL_IMPL_SSE_SELECT(v_int32x4, _mm_castps_si128, _mm_castsi128_ps, ps)
1913
+ // OPENCV_HAL_IMPL_SSE_SELECT(v_uint64x2, TBD, TBD, pd)
1914
+ // OPENCV_HAL_IMPL_SSE_SELECT(v_int64x2, TBD, TBD, ps)
1915
+ OPENCV_HAL_IMPL_SSE_SELECT(v_float32x4, OPENCV_HAL_NOP, OPENCV_HAL_NOP, ps)
1916
+ OPENCV_HAL_IMPL_SSE_SELECT(v_float64x2, OPENCV_HAL_NOP, OPENCV_HAL_NOP, pd)
1917
+
1918
+ #else // CV_SSE4_1
1919
+
1920
+ #define OPENCV_HAL_IMPL_SSE_SELECT(_Tpvec, suffix) \
1921
+ inline _Tpvec v_select(const _Tpvec &mask, const _Tpvec &a, \
1922
+ const _Tpvec &b) { \
1923
+ return _Tpvec(_mm_xor_##suffix( \
1924
+ b.val, _mm_and_##suffix(_mm_xor_##suffix(b.val, a.val), mask.val))); \
1925
+ }
1926
+
1927
+ OPENCV_HAL_IMPL_SSE_SELECT(v_uint8x16, si128)
1928
+ OPENCV_HAL_IMPL_SSE_SELECT(v_int8x16, si128)
1929
+ OPENCV_HAL_IMPL_SSE_SELECT(v_uint16x8, si128)
1930
+ OPENCV_HAL_IMPL_SSE_SELECT(v_int16x8, si128)
1931
+ OPENCV_HAL_IMPL_SSE_SELECT(v_uint32x4, si128)
1932
+ OPENCV_HAL_IMPL_SSE_SELECT(v_int32x4, si128)
1933
+ // OPENCV_HAL_IMPL_SSE_SELECT(v_uint64x2, si128)
1934
+ // OPENCV_HAL_IMPL_SSE_SELECT(v_int64x2, si128)
1935
+ OPENCV_HAL_IMPL_SSE_SELECT(v_float32x4, ps)
1936
+ OPENCV_HAL_IMPL_SSE_SELECT(v_float64x2, pd)
1937
+ #endif
1938
+
1939
+ /* Expand */
1940
+ #define OPENCV_HAL_IMPL_SSE_EXPAND(_Tpvec, _Tpwvec, _Tp, intrin) \
1941
+ inline void v_expand(const _Tpvec &a, _Tpwvec &b0, _Tpwvec &b1) { \
1942
+ b0.val = intrin(a.val); \
1943
+ b1.val = __CV_CAT(intrin, _high)(a.val); \
1944
+ } \
1945
+ inline _Tpwvec v_expand_low(const _Tpvec &a) { \
1946
+ return _Tpwvec(intrin(a.val)); \
1947
+ } \
1948
+ inline _Tpwvec v_expand_high(const _Tpvec &a) { \
1949
+ return _Tpwvec(__CV_CAT(intrin, _high)(a.val)); \
1950
+ } \
1951
+ inline _Tpwvec v_load_expand(const _Tp *ptr) { \
1952
+ __m128i a = _mm_loadl_epi64((const __m128i *)ptr); \
1953
+ return _Tpwvec(intrin(a)); \
1954
+ }
1955
+
1956
+ OPENCV_HAL_IMPL_SSE_EXPAND(v_uint8x16, v_uint16x8, uchar, _v128_cvtepu8_epi16)
1957
+ OPENCV_HAL_IMPL_SSE_EXPAND(v_int8x16, v_int16x8, schar, _v128_cvtepi8_epi16)
1958
+ OPENCV_HAL_IMPL_SSE_EXPAND(v_uint16x8, v_uint32x4, ushort, _v128_cvtepu16_epi32)
1959
+ OPENCV_HAL_IMPL_SSE_EXPAND(v_int16x8, v_int32x4, short, _v128_cvtepi16_epi32)
1960
+ OPENCV_HAL_IMPL_SSE_EXPAND(v_uint32x4, v_uint64x2, unsigned,
1961
+ _v128_cvtepu32_epi64)
1962
+ OPENCV_HAL_IMPL_SSE_EXPAND(v_int32x4, v_int64x2, int, _v128_cvtepi32_epi64)
1963
+
1964
+ #define OPENCV_HAL_IMPL_SSE_EXPAND_Q(_Tpvec, _Tp, intrin) \
1965
+ inline _Tpvec v_load_expand_q(const _Tp *ptr) { \
1966
+ typedef int CV_DECL_ALIGNED(1) unaligned_int; \
1967
+ __m128i a = _mm_cvtsi32_si128(*(const unaligned_int *)ptr); \
1968
+ return _Tpvec(intrin(a)); \
1969
+ }
1970
+
1971
+ OPENCV_HAL_IMPL_SSE_EXPAND_Q(v_uint32x4, uchar, _v128_cvtepu8_epi32)
1972
+ OPENCV_HAL_IMPL_SSE_EXPAND_Q(v_int32x4, schar, _v128_cvtepi8_epi32)
1973
+
1974
+ #define OPENCV_HAL_IMPL_SSE_UNPACKS(_Tpvec, suffix, cast_from, cast_to) \
1975
+ inline void v_zip(const _Tpvec &a0, const _Tpvec &a1, _Tpvec &b0, \
1976
+ _Tpvec &b1) { \
1977
+ b0.val = _mm_unpacklo_##suffix(a0.val, a1.val); \
1978
+ b1.val = _mm_unpackhi_##suffix(a0.val, a1.val); \
1979
+ } \
1980
+ inline _Tpvec v_combine_low(const _Tpvec &a, const _Tpvec &b) { \
1981
+ __m128i a1 = cast_from(a.val), b1 = cast_from(b.val); \
1982
+ return _Tpvec(cast_to(_mm_unpacklo_epi64(a1, b1))); \
1983
+ } \
1984
+ inline _Tpvec v_combine_high(const _Tpvec &a, const _Tpvec &b) { \
1985
+ __m128i a1 = cast_from(a.val), b1 = cast_from(b.val); \
1986
+ return _Tpvec(cast_to(_mm_unpackhi_epi64(a1, b1))); \
1987
+ } \
1988
+ inline void v_recombine(const _Tpvec &a, const _Tpvec &b, _Tpvec &c, \
1989
+ _Tpvec &d) { \
1990
+ __m128i a1 = cast_from(a.val), b1 = cast_from(b.val); \
1991
+ c.val = cast_to(_mm_unpacklo_epi64(a1, b1)); \
1992
+ d.val = cast_to(_mm_unpackhi_epi64(a1, b1)); \
1993
+ }
1994
+
1995
+ OPENCV_HAL_IMPL_SSE_UNPACKS(v_uint8x16, epi8, OPENCV_HAL_NOP, OPENCV_HAL_NOP)
1996
+ OPENCV_HAL_IMPL_SSE_UNPACKS(v_int8x16, epi8, OPENCV_HAL_NOP, OPENCV_HAL_NOP)
1997
+ OPENCV_HAL_IMPL_SSE_UNPACKS(v_uint16x8, epi16, OPENCV_HAL_NOP, OPENCV_HAL_NOP)
1998
+ OPENCV_HAL_IMPL_SSE_UNPACKS(v_int16x8, epi16, OPENCV_HAL_NOP, OPENCV_HAL_NOP)
1999
+ OPENCV_HAL_IMPL_SSE_UNPACKS(v_uint32x4, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP)
2000
+ OPENCV_HAL_IMPL_SSE_UNPACKS(v_int32x4, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP)
2001
+ OPENCV_HAL_IMPL_SSE_UNPACKS(v_float32x4, ps, _mm_castps_si128, _mm_castsi128_ps)
2002
+ OPENCV_HAL_IMPL_SSE_UNPACKS(v_float64x2, pd, _mm_castpd_si128, _mm_castsi128_pd)
2003
+
2004
+ inline v_uint8x16 v_reverse(const v_uint8x16 &a) {
2005
+ #if CV_SSSE3
2006
+ static const __m128i perm =
2007
+ _mm_setr_epi8(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
2008
+ return v_uint8x16(_mm_shuffle_epi8(a.val, perm));
2009
+ #else
2010
+ uchar CV_DECL_ALIGNED(32) d[16];
2011
+ v_store_aligned(d, a);
2012
+ return v_uint8x16(d[15], d[14], d[13], d[12], d[11], d[10], d[9], d[8], d[7],
2013
+ d[6], d[5], d[4], d[3], d[2], d[1], d[0]);
2014
+ #endif
2015
+ }
2016
+
2017
+ inline v_int8x16 v_reverse(const v_int8x16 &a) {
2018
+ return v_reinterpret_as_s8(v_reverse(v_reinterpret_as_u8(a)));
2019
+ }
2020
+
2021
+ inline v_uint16x8 v_reverse(const v_uint16x8 &a) {
2022
+ #if CV_SSSE3
2023
+ static const __m128i perm =
2024
+ _mm_setr_epi8(14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1);
2025
+ return v_uint16x8(_mm_shuffle_epi8(a.val, perm));
2026
+ #else
2027
+ __m128i r = _mm_shuffle_epi32(a.val, _MM_SHUFFLE(0, 1, 2, 3));
2028
+ r = _mm_shufflelo_epi16(r, _MM_SHUFFLE(2, 3, 0, 1));
2029
+ r = _mm_shufflehi_epi16(r, _MM_SHUFFLE(2, 3, 0, 1));
2030
+ return v_uint16x8(r);
2031
+ #endif
2032
+ }
2033
+
2034
+ inline v_int16x8 v_reverse(const v_int16x8 &a) {
2035
+ return v_reinterpret_as_s16(v_reverse(v_reinterpret_as_u16(a)));
2036
+ }
2037
+
2038
+ inline v_uint32x4 v_reverse(const v_uint32x4 &a) {
2039
+ return v_uint32x4(_mm_shuffle_epi32(a.val, _MM_SHUFFLE(0, 1, 2, 3)));
2040
+ }
2041
+
2042
+ inline v_int32x4 v_reverse(const v_int32x4 &a) {
2043
+ return v_reinterpret_as_s32(v_reverse(v_reinterpret_as_u32(a)));
2044
+ }
2045
+
2046
+ inline v_float32x4 v_reverse(const v_float32x4 &a) {
2047
+ return v_reinterpret_as_f32(v_reverse(v_reinterpret_as_u32(a)));
2048
+ }
2049
+
2050
+ inline v_uint64x2 v_reverse(const v_uint64x2 &a) {
2051
+ return v_uint64x2(_mm_shuffle_epi32(a.val, _MM_SHUFFLE(1, 0, 3, 2)));
2052
+ }
2053
+
2054
+ inline v_int64x2 v_reverse(const v_int64x2 &a) {
2055
+ return v_reinterpret_as_s64(v_reverse(v_reinterpret_as_u64(a)));
2056
+ }
2057
+
2058
+ inline v_float64x2 v_reverse(const v_float64x2 &a) {
2059
+ return v_reinterpret_as_f64(v_reverse(v_reinterpret_as_u64(a)));
2060
+ }
2061
+
2062
+ template <int s, typename _Tpvec>
2063
+ inline _Tpvec v_extract(const _Tpvec &a, const _Tpvec &b) {
2064
+ return v_rotate_right<s>(a, b);
2065
+ }
2066
+
2067
+ inline v_int32x4 v_round(const v_float32x4 &a) {
2068
+ return v_int32x4(_mm_cvtps_epi32(a.val));
2069
+ }
2070
+
2071
+ inline v_int32x4 v_floor(const v_float32x4 &a) {
2072
+ __m128i a1 = _mm_cvtps_epi32(a.val);
2073
+ __m128i mask = _mm_castps_si128(_mm_cmpgt_ps(_mm_cvtepi32_ps(a1), a.val));
2074
+ return v_int32x4(_mm_add_epi32(a1, mask));
2075
+ }
2076
+
2077
+ inline v_int32x4 v_ceil(const v_float32x4 &a) {
2078
+ __m128i a1 = _mm_cvtps_epi32(a.val);
2079
+ __m128i mask = _mm_castps_si128(_mm_cmpgt_ps(a.val, _mm_cvtepi32_ps(a1)));
2080
+ return v_int32x4(_mm_sub_epi32(a1, mask));
2081
+ }
2082
+
2083
+ inline v_int32x4 v_trunc(const v_float32x4 &a) {
2084
+ return v_int32x4(_mm_cvttps_epi32(a.val));
2085
+ }
2086
+
2087
+ inline v_int32x4 v_round(const v_float64x2 &a) {
2088
+ return v_int32x4(_mm_cvtpd_epi32(a.val));
2089
+ }
2090
+
2091
+ inline v_int32x4 v_round(const v_float64x2 &a, const v_float64x2 &b) {
2092
+ __m128i ai = _mm_cvtpd_epi32(a.val), bi = _mm_cvtpd_epi32(b.val);
2093
+ return v_int32x4(_mm_unpacklo_epi64(ai, bi));
2094
+ }
2095
+
2096
+ inline v_int32x4 v_floor(const v_float64x2 &a) {
2097
+ __m128i a1 = _mm_cvtpd_epi32(a.val);
2098
+ __m128i mask = _mm_castpd_si128(_mm_cmpgt_pd(_mm_cvtepi32_pd(a1), a.val));
2099
+ mask = _mm_srli_si128(_mm_slli_si128(mask, 4), 8); // m0 m0 m1 m1 => m0 m1 0 0
2100
+ return v_int32x4(_mm_add_epi32(a1, mask));
2101
+ }
2102
+
2103
+ inline v_int32x4 v_ceil(const v_float64x2 &a) {
2104
+ __m128i a1 = _mm_cvtpd_epi32(a.val);
2105
+ __m128i mask = _mm_castpd_si128(_mm_cmpgt_pd(a.val, _mm_cvtepi32_pd(a1)));
2106
+ mask = _mm_srli_si128(_mm_slli_si128(mask, 4), 8); // m0 m0 m1 m1 => m0 m1 0 0
2107
+ return v_int32x4(_mm_sub_epi32(a1, mask));
2108
+ }
2109
+
2110
+ inline v_int32x4 v_trunc(const v_float64x2 &a) {
2111
+ return v_int32x4(_mm_cvttpd_epi32(a.val));
2112
+ }
2113
+
2114
+ #define OPENCV_HAL_IMPL_SSE_TRANSPOSE4x4(_Tpvec, suffix, cast_from, cast_to) \
2115
+ inline void v_transpose4x4(const _Tpvec &a0, const _Tpvec &a1, \
2116
+ const _Tpvec &a2, const _Tpvec &a3, _Tpvec &b0, \
2117
+ _Tpvec &b1, _Tpvec &b2, _Tpvec &b3) { \
2118
+ __m128i t0 = cast_from(_mm_unpacklo_##suffix(a0.val, a1.val)); \
2119
+ __m128i t1 = cast_from(_mm_unpacklo_##suffix(a2.val, a3.val)); \
2120
+ __m128i t2 = cast_from(_mm_unpackhi_##suffix(a0.val, a1.val)); \
2121
+ __m128i t3 = cast_from(_mm_unpackhi_##suffix(a2.val, a3.val)); \
2122
+ \
2123
+ b0.val = cast_to(_mm_unpacklo_epi64(t0, t1)); \
2124
+ b1.val = cast_to(_mm_unpackhi_epi64(t0, t1)); \
2125
+ b2.val = cast_to(_mm_unpacklo_epi64(t2, t3)); \
2126
+ b3.val = cast_to(_mm_unpackhi_epi64(t2, t3)); \
2127
+ }
2128
+
2129
+ OPENCV_HAL_IMPL_SSE_TRANSPOSE4x4(v_uint32x4, epi32, OPENCV_HAL_NOP,
2130
+ OPENCV_HAL_NOP)
2131
+ OPENCV_HAL_IMPL_SSE_TRANSPOSE4x4(v_int32x4, epi32, OPENCV_HAL_NOP,
2132
+ OPENCV_HAL_NOP)
2133
+ OPENCV_HAL_IMPL_SSE_TRANSPOSE4x4(v_float32x4, ps, _mm_castps_si128,
2134
+ _mm_castsi128_ps)
2135
+
2136
+ // load deinterleave
2137
+ inline void v_load_deinterleave(const uchar *ptr, v_uint8x16 &a,
2138
+ v_uint8x16 &b) {
2139
+ __m128i t00 = _mm_loadu_si128((const __m128i *)ptr);
2140
+ __m128i t01 = _mm_loadu_si128((const __m128i *)(ptr + 16));
2141
+
2142
+ __m128i t10 = _mm_unpacklo_epi8(t00, t01);
2143
+ __m128i t11 = _mm_unpackhi_epi8(t00, t01);
2144
+
2145
+ __m128i t20 = _mm_unpacklo_epi8(t10, t11);
2146
+ __m128i t21 = _mm_unpackhi_epi8(t10, t11);
2147
+
2148
+ __m128i t30 = _mm_unpacklo_epi8(t20, t21);
2149
+ __m128i t31 = _mm_unpackhi_epi8(t20, t21);
2150
+
2151
+ a.val = _mm_unpacklo_epi8(t30, t31);
2152
+ b.val = _mm_unpackhi_epi8(t30, t31);
2153
+ }
2154
+
2155
+ inline void v_load_deinterleave(const uchar *ptr, v_uint8x16 &a, v_uint8x16 &b,
2156
+ v_uint8x16 &c) {
2157
+ #if CV_SSE4_1
2158
+ const __m128i m0 =
2159
+ _mm_setr_epi8(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0);
2160
+ const __m128i m1 =
2161
+ _mm_setr_epi8(0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0);
2162
+ __m128i s0 = _mm_loadu_si128((const __m128i *)ptr);
2163
+ __m128i s1 = _mm_loadu_si128((const __m128i *)(ptr + 16));
2164
+ __m128i s2 = _mm_loadu_si128((const __m128i *)(ptr + 32));
2165
+ __m128i a0 = _mm_blendv_epi8(_mm_blendv_epi8(s0, s1, m0), s2, m1);
2166
+ __m128i b0 = _mm_blendv_epi8(_mm_blendv_epi8(s1, s2, m0), s0, m1);
2167
+ __m128i c0 = _mm_blendv_epi8(_mm_blendv_epi8(s2, s0, m0), s1, m1);
2168
+ const __m128i sh_b =
2169
+ _mm_setr_epi8(0, 3, 6, 9, 12, 15, 2, 5, 8, 11, 14, 1, 4, 7, 10, 13);
2170
+ const __m128i sh_g =
2171
+ _mm_setr_epi8(1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, 5, 8, 11, 14);
2172
+ const __m128i sh_r =
2173
+ _mm_setr_epi8(2, 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15);
2174
+ a0 = _mm_shuffle_epi8(a0, sh_b);
2175
+ b0 = _mm_shuffle_epi8(b0, sh_g);
2176
+ c0 = _mm_shuffle_epi8(c0, sh_r);
2177
+ a.val = a0;
2178
+ b.val = b0;
2179
+ c.val = c0;
2180
+ #elif CV_SSSE3
2181
+ const __m128i m0 =
2182
+ _mm_setr_epi8(0, 3, 6, 9, 12, 15, 1, 4, 7, 10, 13, 2, 5, 8, 11, 14);
2183
+ const __m128i m1 = _mm_alignr_epi8(m0, m0, 11);
2184
+ const __m128i m2 = _mm_alignr_epi8(m0, m0, 6);
2185
+
2186
+ __m128i t0 = _mm_loadu_si128((const __m128i *)ptr);
2187
+ __m128i t1 = _mm_loadu_si128((const __m128i *)(ptr + 16));
2188
+ __m128i t2 = _mm_loadu_si128((const __m128i *)(ptr + 32));
2189
+
2190
+ __m128i s0 = _mm_shuffle_epi8(t0, m0);
2191
+ __m128i s1 = _mm_shuffle_epi8(t1, m1);
2192
+ __m128i s2 = _mm_shuffle_epi8(t2, m2);
2193
+
2194
+ t0 = _mm_alignr_epi8(s1, _mm_slli_si128(s0, 10), 5);
2195
+ a.val = _mm_alignr_epi8(s2, t0, 5);
2196
+
2197
+ t1 = _mm_alignr_epi8(_mm_srli_si128(s1, 5), _mm_slli_si128(s0, 5), 6);
2198
+ b.val = _mm_alignr_epi8(_mm_srli_si128(s2, 5), t1, 5);
2199
+
2200
+ t2 = _mm_alignr_epi8(_mm_srli_si128(s2, 10), s1, 11);
2201
+ c.val = _mm_alignr_epi8(t2, s0, 11);
2202
+ #else
2203
+ __m128i t00 = _mm_loadu_si128((const __m128i *)ptr);
2204
+ __m128i t01 = _mm_loadu_si128((const __m128i *)(ptr + 16));
2205
+ __m128i t02 = _mm_loadu_si128((const __m128i *)(ptr + 32));
2206
+
2207
+ __m128i t10 = _mm_unpacklo_epi8(t00, _mm_unpackhi_epi64(t01, t01));
2208
+ __m128i t11 = _mm_unpacklo_epi8(_mm_unpackhi_epi64(t00, t00), t02);
2209
+ __m128i t12 = _mm_unpacklo_epi8(t01, _mm_unpackhi_epi64(t02, t02));
2210
+
2211
+ __m128i t20 = _mm_unpacklo_epi8(t10, _mm_unpackhi_epi64(t11, t11));
2212
+ __m128i t21 = _mm_unpacklo_epi8(_mm_unpackhi_epi64(t10, t10), t12);
2213
+ __m128i t22 = _mm_unpacklo_epi8(t11, _mm_unpackhi_epi64(t12, t12));
2214
+
2215
+ __m128i t30 = _mm_unpacklo_epi8(t20, _mm_unpackhi_epi64(t21, t21));
2216
+ __m128i t31 = _mm_unpacklo_epi8(_mm_unpackhi_epi64(t20, t20), t22);
2217
+ __m128i t32 = _mm_unpacklo_epi8(t21, _mm_unpackhi_epi64(t22, t22));
2218
+
2219
+ a.val = _mm_unpacklo_epi8(t30, _mm_unpackhi_epi64(t31, t31));
2220
+ b.val = _mm_unpacklo_epi8(_mm_unpackhi_epi64(t30, t30), t32);
2221
+ c.val = _mm_unpacklo_epi8(t31, _mm_unpackhi_epi64(t32, t32));
2222
+ #endif
2223
+ }
2224
+
2225
+ inline void v_load_deinterleave(const uchar *ptr, v_uint8x16 &a, v_uint8x16 &b,
2226
+ v_uint8x16 &c, v_uint8x16 &d) {
2227
+ __m128i u0 =
2228
+ _mm_loadu_si128((const __m128i *)ptr); // a0 b0 c0 d0 a1 b1 c1 d1 ...
2229
+ __m128i u1 = _mm_loadu_si128((const __m128i *)(ptr + 16)); // a4 b4 c4 d4 ...
2230
+ __m128i u2 = _mm_loadu_si128((const __m128i *)(ptr + 32)); // a8 b8 c8 d8 ...
2231
+ __m128i u3 =
2232
+ _mm_loadu_si128((const __m128i *)(ptr + 48)); // a12 b12 c12 d12 ...
2233
+
2234
+ __m128i v0 = _mm_unpacklo_epi8(u0, u2); // a0 a8 b0 b8 ...
2235
+ __m128i v1 = _mm_unpackhi_epi8(u0, u2); // a2 a10 b2 b10 ...
2236
+ __m128i v2 = _mm_unpacklo_epi8(u1, u3); // a4 a12 b4 b12 ...
2237
+ __m128i v3 = _mm_unpackhi_epi8(u1, u3); // a6 a14 b6 b14 ...
2238
+
2239
+ u0 = _mm_unpacklo_epi8(v0, v2); // a0 a4 a8 a12 ...
2240
+ u1 = _mm_unpacklo_epi8(v1, v3); // a2 a6 a10 a14 ...
2241
+ u2 = _mm_unpackhi_epi8(v0, v2); // a1 a5 a9 a13 ...
2242
+ u3 = _mm_unpackhi_epi8(v1, v3); // a3 a7 a11 a15 ...
2243
+
2244
+ v0 = _mm_unpacklo_epi8(u0, u1); // a0 a2 a4 a6 ...
2245
+ v1 = _mm_unpacklo_epi8(u2, u3); // a1 a3 a5 a7 ...
2246
+ v2 = _mm_unpackhi_epi8(u0, u1); // c0 c2 c4 c6 ...
2247
+ v3 = _mm_unpackhi_epi8(u2, u3); // c1 c3 c5 c7 ...
2248
+
2249
+ a.val = _mm_unpacklo_epi8(v0, v1);
2250
+ b.val = _mm_unpackhi_epi8(v0, v1);
2251
+ c.val = _mm_unpacklo_epi8(v2, v3);
2252
+ d.val = _mm_unpackhi_epi8(v2, v3);
2253
+ }
2254
+
2255
+ inline void v_load_deinterleave(const ushort *ptr, v_uint16x8 &a,
2256
+ v_uint16x8 &b) {
2257
+ __m128i v0 = _mm_loadu_si128((__m128i *)(ptr)); // a0 b0 a1 b1 a2 b2 a3 b3
2258
+ __m128i v1 = _mm_loadu_si128((__m128i *)(ptr + 8)); // a4 b4 a5 b5 a6 b6 a7 b7
2259
+
2260
+ __m128i v2 = _mm_unpacklo_epi16(v0, v1); // a0 a4 b0 b4 a1 a5 b1 b5
2261
+ __m128i v3 = _mm_unpackhi_epi16(v0, v1); // a2 a6 b2 b6 a3 a7 b3 b7
2262
+ __m128i v4 = _mm_unpacklo_epi16(v2, v3); // a0 a2 a4 a6 b0 b2 b4 b6
2263
+ __m128i v5 = _mm_unpackhi_epi16(v2, v3); // a1 a3 a5 a7 b1 b3 b5 b7
2264
+
2265
+ a.val = _mm_unpacklo_epi16(v4, v5); // a0 a1 a2 a3 a4 a5 a6 a7
2266
+ b.val = _mm_unpackhi_epi16(v4, v5); // b0 b1 ab b3 b4 b5 b6 b7
2267
+ }
2268
+
2269
+ inline void v_load_deinterleave(const ushort *ptr, v_uint16x8 &a, v_uint16x8 &b,
2270
+ v_uint16x8 &c) {
2271
+ #if CV_SSE4_1
2272
+ __m128i v0 = _mm_loadu_si128((__m128i *)(ptr));
2273
+ __m128i v1 = _mm_loadu_si128((__m128i *)(ptr + 8));
2274
+ __m128i v2 = _mm_loadu_si128((__m128i *)(ptr + 16));
2275
+ __m128i a0 = _mm_blend_epi16(_mm_blend_epi16(v0, v1, 0x92), v2, 0x24);
2276
+ __m128i b0 = _mm_blend_epi16(_mm_blend_epi16(v2, v0, 0x92), v1, 0x24);
2277
+ __m128i c0 = _mm_blend_epi16(_mm_blend_epi16(v1, v2, 0x92), v0, 0x24);
2278
+
2279
+ const __m128i sh_a =
2280
+ _mm_setr_epi8(0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5, 10, 11);
2281
+ const __m128i sh_b =
2282
+ _mm_setr_epi8(2, 3, 8, 9, 14, 15, 4, 5, 10, 11, 0, 1, 6, 7, 12, 13);
2283
+ const __m128i sh_c =
2284
+ _mm_setr_epi8(4, 5, 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15);
2285
+ a0 = _mm_shuffle_epi8(a0, sh_a);
2286
+ b0 = _mm_shuffle_epi8(b0, sh_b);
2287
+ c0 = _mm_shuffle_epi8(c0, sh_c);
2288
+
2289
+ a.val = a0;
2290
+ b.val = b0;
2291
+ c.val = c0;
2292
+ #else
2293
+ __m128i t00 = _mm_loadu_si128((const __m128i *)ptr);
2294
+ __m128i t01 = _mm_loadu_si128((const __m128i *)(ptr + 8));
2295
+ __m128i t02 = _mm_loadu_si128((const __m128i *)(ptr + 16));
2296
+
2297
+ __m128i t10 = _mm_unpacklo_epi16(t00, _mm_unpackhi_epi64(t01, t01));
2298
+ __m128i t11 = _mm_unpacklo_epi16(_mm_unpackhi_epi64(t00, t00), t02);
2299
+ __m128i t12 = _mm_unpacklo_epi16(t01, _mm_unpackhi_epi64(t02, t02));
2300
+
2301
+ __m128i t20 = _mm_unpacklo_epi16(t10, _mm_unpackhi_epi64(t11, t11));
2302
+ __m128i t21 = _mm_unpacklo_epi16(_mm_unpackhi_epi64(t10, t10), t12);
2303
+ __m128i t22 = _mm_unpacklo_epi16(t11, _mm_unpackhi_epi64(t12, t12));
2304
+
2305
+ a.val = _mm_unpacklo_epi16(t20, _mm_unpackhi_epi64(t21, t21));
2306
+ b.val = _mm_unpacklo_epi16(_mm_unpackhi_epi64(t20, t20), t22);
2307
+ c.val = _mm_unpacklo_epi16(t21, _mm_unpackhi_epi64(t22, t22));
2308
+ #endif
2309
+ }
2310
+
2311
+ inline void v_load_deinterleave(const ushort *ptr, v_uint16x8 &a, v_uint16x8 &b,
2312
+ v_uint16x8 &c, v_uint16x8 &d) {
2313
+ __m128i u0 = _mm_loadu_si128((const __m128i *)ptr); // a0 b0 c0 d0 a1 b1 c1 d1
2314
+ __m128i u1 = _mm_loadu_si128((const __m128i *)(ptr + 8)); // a2 b2 c2 d2 ...
2315
+ __m128i u2 = _mm_loadu_si128((const __m128i *)(ptr + 16)); // a4 b4 c4 d4 ...
2316
+ __m128i u3 = _mm_loadu_si128((const __m128i *)(ptr + 24)); // a6 b6 c6 d6 ...
2317
+
2318
+ __m128i v0 = _mm_unpacklo_epi16(u0, u2); // a0 a4 b0 b4 ...
2319
+ __m128i v1 = _mm_unpackhi_epi16(u0, u2); // a1 a5 b1 b5 ...
2320
+ __m128i v2 = _mm_unpacklo_epi16(u1, u3); // a2 a6 b2 b6 ...
2321
+ __m128i v3 = _mm_unpackhi_epi16(u1, u3); // a3 a7 b3 b7 ...
2322
+
2323
+ u0 = _mm_unpacklo_epi16(v0, v2); // a0 a2 a4 a6 ...
2324
+ u1 = _mm_unpacklo_epi16(v1, v3); // a1 a3 a5 a7 ...
2325
+ u2 = _mm_unpackhi_epi16(v0, v2); // c0 c2 c4 c6 ...
2326
+ u3 = _mm_unpackhi_epi16(v1, v3); // c1 c3 c5 c7 ...
2327
+
2328
+ a.val = _mm_unpacklo_epi16(u0, u1);
2329
+ b.val = _mm_unpackhi_epi16(u0, u1);
2330
+ c.val = _mm_unpacklo_epi16(u2, u3);
2331
+ d.val = _mm_unpackhi_epi16(u2, u3);
2332
+ }
2333
+
2334
+ inline void v_load_deinterleave(const unsigned *ptr, v_uint32x4 &a,
2335
+ v_uint32x4 &b) {
2336
+ __m128i v0 = _mm_loadu_si128((__m128i *)(ptr)); // a0 b0 a1 b1
2337
+ __m128i v1 = _mm_loadu_si128((__m128i *)(ptr + 4)); // a2 b2 a3 b3
2338
+
2339
+ __m128i v2 = _mm_unpacklo_epi32(v0, v1); // a0 a2 b0 b2
2340
+ __m128i v3 = _mm_unpackhi_epi32(v0, v1); // a1 a3 b1 b3
2341
+
2342
+ a.val = _mm_unpacklo_epi32(v2, v3); // a0 a1 a2 a3
2343
+ b.val = _mm_unpackhi_epi32(v2, v3); // b0 b1 ab b3
2344
+ }
2345
+
2346
+ inline void v_load_deinterleave(const unsigned *ptr, v_uint32x4 &a,
2347
+ v_uint32x4 &b, v_uint32x4 &c) {
2348
+ __m128i t00 = _mm_loadu_si128((const __m128i *)ptr);
2349
+ __m128i t01 = _mm_loadu_si128((const __m128i *)(ptr + 4));
2350
+ __m128i t02 = _mm_loadu_si128((const __m128i *)(ptr + 8));
2351
+
2352
+ __m128i t10 = _mm_unpacklo_epi32(t00, _mm_unpackhi_epi64(t01, t01));
2353
+ __m128i t11 = _mm_unpacklo_epi32(_mm_unpackhi_epi64(t00, t00), t02);
2354
+ __m128i t12 = _mm_unpacklo_epi32(t01, _mm_unpackhi_epi64(t02, t02));
2355
+
2356
+ a.val = _mm_unpacklo_epi32(t10, _mm_unpackhi_epi64(t11, t11));
2357
+ b.val = _mm_unpacklo_epi32(_mm_unpackhi_epi64(t10, t10), t12);
2358
+ c.val = _mm_unpacklo_epi32(t11, _mm_unpackhi_epi64(t12, t12));
2359
+ }
2360
+
2361
+ inline void v_load_deinterleave(const unsigned *ptr, v_uint32x4 &a,
2362
+ v_uint32x4 &b, v_uint32x4 &c, v_uint32x4 &d) {
2363
+ v_uint32x4 s0(_mm_loadu_si128((const __m128i *)ptr)); // a0 b0 c0 d0
2364
+ v_uint32x4 s1(_mm_loadu_si128((const __m128i *)(ptr + 4))); // a1 b1 c1 d1
2365
+ v_uint32x4 s2(_mm_loadu_si128((const __m128i *)(ptr + 8))); // a2 b2 c2 d2
2366
+ v_uint32x4 s3(_mm_loadu_si128((const __m128i *)(ptr + 12))); // a3 b3 c3 d3
2367
+
2368
+ v_transpose4x4(s0, s1, s2, s3, a, b, c, d);
2369
+ }
2370
+
2371
+ inline void v_load_deinterleave(const float *ptr, v_float32x4 &a,
2372
+ v_float32x4 &b) {
2373
+ __m128 u0 = _mm_loadu_ps(ptr); // a0 b0 a1 b1
2374
+ __m128 u1 = _mm_loadu_ps((ptr + 4)); // a2 b2 a3 b3
2375
+
2376
+ a.val = _mm_shuffle_ps(u0, u1, _MM_SHUFFLE(2, 0, 2, 0)); // a0 a1 a2 a3
2377
+ b.val = _mm_shuffle_ps(u0, u1, _MM_SHUFFLE(3, 1, 3, 1)); // b0 b1 ab b3
2378
+ }
2379
+
2380
+ inline void v_load_deinterleave(const float *ptr, v_float32x4 &a,
2381
+ v_float32x4 &b, v_float32x4 &c) {
2382
+ __m128 t0 = _mm_loadu_ps(ptr + 0);
2383
+ __m128 t1 = _mm_loadu_ps(ptr + 4);
2384
+ __m128 t2 = _mm_loadu_ps(ptr + 8);
2385
+
2386
+ __m128 at12 = _mm_shuffle_ps(t1, t2, _MM_SHUFFLE(0, 1, 0, 2));
2387
+ a.val = _mm_shuffle_ps(t0, at12, _MM_SHUFFLE(2, 0, 3, 0));
2388
+
2389
+ __m128 bt01 = _mm_shuffle_ps(t0, t1, _MM_SHUFFLE(0, 0, 0, 1));
2390
+ __m128 bt12 = _mm_shuffle_ps(t1, t2, _MM_SHUFFLE(0, 2, 0, 3));
2391
+ b.val = _mm_shuffle_ps(bt01, bt12, _MM_SHUFFLE(2, 0, 2, 0));
2392
+
2393
+ __m128 ct01 = _mm_shuffle_ps(t0, t1, _MM_SHUFFLE(0, 1, 0, 2));
2394
+ c.val = _mm_shuffle_ps(ct01, t2, _MM_SHUFFLE(3, 0, 2, 0));
2395
+ }
2396
+
2397
+ inline void v_load_deinterleave(const float *ptr, v_float32x4 &a,
2398
+ v_float32x4 &b, v_float32x4 &c,
2399
+ v_float32x4 &d) {
2400
+ __m128 t0 = _mm_loadu_ps(ptr + 0);
2401
+ __m128 t1 = _mm_loadu_ps(ptr + 4);
2402
+ __m128 t2 = _mm_loadu_ps(ptr + 8);
2403
+ __m128 t3 = _mm_loadu_ps(ptr + 12);
2404
+ __m128 t02lo = _mm_unpacklo_ps(t0, t2);
2405
+ __m128 t13lo = _mm_unpacklo_ps(t1, t3);
2406
+ __m128 t02hi = _mm_unpackhi_ps(t0, t2);
2407
+ __m128 t13hi = _mm_unpackhi_ps(t1, t3);
2408
+ a.val = _mm_unpacklo_ps(t02lo, t13lo);
2409
+ b.val = _mm_unpackhi_ps(t02lo, t13lo);
2410
+ c.val = _mm_unpacklo_ps(t02hi, t13hi);
2411
+ d.val = _mm_unpackhi_ps(t02hi, t13hi);
2412
+ }
2413
+
2414
+ inline void v_load_deinterleave(const uint64 *ptr, v_uint64x2 &a,
2415
+ v_uint64x2 &b) {
2416
+ __m128i t0 = _mm_loadu_si128((const __m128i *)ptr);
2417
+ __m128i t1 = _mm_loadu_si128((const __m128i *)(ptr + 2));
2418
+
2419
+ a = v_uint64x2(_mm_unpacklo_epi64(t0, t1));
2420
+ b = v_uint64x2(_mm_unpackhi_epi64(t0, t1));
2421
+ }
2422
+
2423
+ inline void v_load_deinterleave(const uint64 *ptr, v_uint64x2 &a, v_uint64x2 &b,
2424
+ v_uint64x2 &c) {
2425
+ __m128i t0 = _mm_loadu_si128((const __m128i *)ptr); // a0, b0
2426
+ __m128i t1 = _mm_loadu_si128((const __m128i *)(ptr + 2)); // c0, a1
2427
+ __m128i t2 = _mm_loadu_si128((const __m128i *)(ptr + 4)); // b1, c1
2428
+
2429
+ t1 = _mm_shuffle_epi32(t1, 0x4e); // a1, c0
2430
+
2431
+ a = v_uint64x2(_mm_unpacklo_epi64(t0, t1));
2432
+ b = v_uint64x2(_mm_unpacklo_epi64(_mm_unpackhi_epi64(t0, t0), t2));
2433
+ c = v_uint64x2(_mm_unpackhi_epi64(t1, t2));
2434
+ }
2435
+
2436
+ inline void v_load_deinterleave(const uint64 *ptr, v_uint64x2 &a, v_uint64x2 &b,
2437
+ v_uint64x2 &c, v_uint64x2 &d) {
2438
+ __m128i t0 = _mm_loadu_si128((const __m128i *)ptr); // a0 b0
2439
+ __m128i t1 = _mm_loadu_si128((const __m128i *)(ptr + 2)); // c0 d0
2440
+ __m128i t2 = _mm_loadu_si128((const __m128i *)(ptr + 4)); // a1 b1
2441
+ __m128i t3 = _mm_loadu_si128((const __m128i *)(ptr + 6)); // c1 d1
2442
+
2443
+ a = v_uint64x2(_mm_unpacklo_epi64(t0, t2));
2444
+ b = v_uint64x2(_mm_unpackhi_epi64(t0, t2));
2445
+ c = v_uint64x2(_mm_unpacklo_epi64(t1, t3));
2446
+ d = v_uint64x2(_mm_unpackhi_epi64(t1, t3));
2447
+ }
2448
+
2449
+ // store interleave
2450
+
2451
+ inline void v_store_interleave(uchar *ptr, const v_uint8x16 &a,
2452
+ const v_uint8x16 &b,
2453
+ hal::StoreMode mode = hal::STORE_UNALIGNED) {
2454
+ __m128i v0 = _mm_unpacklo_epi8(a.val, b.val);
2455
+ __m128i v1 = _mm_unpackhi_epi8(a.val, b.val);
2456
+
2457
+ if (mode == hal::STORE_ALIGNED_NOCACHE) {
2458
+ _mm_stream_si128((__m128i *)(ptr), v0);
2459
+ _mm_stream_si128((__m128i *)(ptr + 16), v1);
2460
+ } else if (mode == hal::STORE_ALIGNED) {
2461
+ _mm_store_si128((__m128i *)(ptr), v0);
2462
+ _mm_store_si128((__m128i *)(ptr + 16), v1);
2463
+ } else {
2464
+ _mm_storeu_si128((__m128i *)(ptr), v0);
2465
+ _mm_storeu_si128((__m128i *)(ptr + 16), v1);
2466
+ }
2467
+ }
2468
+
2469
+ inline void v_store_interleave(uchar *ptr, const v_uint8x16 &a,
2470
+ const v_uint8x16 &b, const v_uint8x16 &c,
2471
+ hal::StoreMode mode = hal::STORE_UNALIGNED) {
2472
+ #if CV_SSE4_1
2473
+ const __m128i sh_a =
2474
+ _mm_setr_epi8(0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10, 5);
2475
+ const __m128i sh_b =
2476
+ _mm_setr_epi8(5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10);
2477
+ const __m128i sh_c =
2478
+ _mm_setr_epi8(10, 5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15);
2479
+ __m128i a0 = _mm_shuffle_epi8(a.val, sh_a);
2480
+ __m128i b0 = _mm_shuffle_epi8(b.val, sh_b);
2481
+ __m128i c0 = _mm_shuffle_epi8(c.val, sh_c);
2482
+
2483
+ const __m128i m0 =
2484
+ _mm_setr_epi8(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0);
2485
+ const __m128i m1 =
2486
+ _mm_setr_epi8(0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0);
2487
+ __m128i v0 = _mm_blendv_epi8(_mm_blendv_epi8(a0, b0, m1), c0, m0);
2488
+ __m128i v1 = _mm_blendv_epi8(_mm_blendv_epi8(b0, c0, m1), a0, m0);
2489
+ __m128i v2 = _mm_blendv_epi8(_mm_blendv_epi8(c0, a0, m1), b0, m0);
2490
+ #elif CV_SSSE3
2491
+ const __m128i m0 =
2492
+ _mm_setr_epi8(0, 6, 11, 1, 7, 12, 2, 8, 13, 3, 9, 14, 4, 10, 15, 5);
2493
+ const __m128i m1 =
2494
+ _mm_setr_epi8(5, 11, 0, 6, 12, 1, 7, 13, 2, 8, 14, 3, 9, 15, 4, 10);
2495
+ const __m128i m2 =
2496
+ _mm_setr_epi8(10, 0, 5, 11, 1, 6, 12, 2, 7, 13, 3, 8, 14, 4, 9, 15);
2497
+
2498
+ __m128i t0 = _mm_alignr_epi8(b.val, _mm_slli_si128(a.val, 10), 5);
2499
+ t0 = _mm_alignr_epi8(c.val, t0, 5);
2500
+ __m128i v0 = _mm_shuffle_epi8(t0, m0);
2501
+
2502
+ __m128i t1 =
2503
+ _mm_alignr_epi8(_mm_srli_si128(b.val, 5), _mm_slli_si128(a.val, 5), 6);
2504
+ t1 = _mm_alignr_epi8(_mm_srli_si128(c.val, 5), t1, 5);
2505
+ __m128i v1 = _mm_shuffle_epi8(t1, m1);
2506
+
2507
+ __m128i t2 = _mm_alignr_epi8(_mm_srli_si128(c.val, 10), b.val, 11);
2508
+ t2 = _mm_alignr_epi8(t2, a.val, 11);
2509
+ __m128i v2 = _mm_shuffle_epi8(t2, m2);
2510
+ #else
2511
+ __m128i z = _mm_setzero_si128();
2512
+ __m128i ab0 = _mm_unpacklo_epi8(a.val, b.val);
2513
+ __m128i ab1 = _mm_unpackhi_epi8(a.val, b.val);
2514
+ __m128i c0 = _mm_unpacklo_epi8(c.val, z);
2515
+ __m128i c1 = _mm_unpackhi_epi8(c.val, z);
2516
+
2517
+ __m128i p00 = _mm_unpacklo_epi16(ab0, c0);
2518
+ __m128i p01 = _mm_unpackhi_epi16(ab0, c0);
2519
+ __m128i p02 = _mm_unpacklo_epi16(ab1, c1);
2520
+ __m128i p03 = _mm_unpackhi_epi16(ab1, c1);
2521
+
2522
+ __m128i p10 = _mm_unpacklo_epi32(p00, p01);
2523
+ __m128i p11 = _mm_unpackhi_epi32(p00, p01);
2524
+ __m128i p12 = _mm_unpacklo_epi32(p02, p03);
2525
+ __m128i p13 = _mm_unpackhi_epi32(p02, p03);
2526
+
2527
+ __m128i p20 = _mm_unpacklo_epi64(p10, p11);
2528
+ __m128i p21 = _mm_unpackhi_epi64(p10, p11);
2529
+ __m128i p22 = _mm_unpacklo_epi64(p12, p13);
2530
+ __m128i p23 = _mm_unpackhi_epi64(p12, p13);
2531
+
2532
+ p20 = _mm_slli_si128(p20, 1);
2533
+ p22 = _mm_slli_si128(p22, 1);
2534
+
2535
+ __m128i p30 = _mm_slli_epi64(_mm_unpacklo_epi32(p20, p21), 8);
2536
+ __m128i p31 = _mm_srli_epi64(_mm_unpackhi_epi32(p20, p21), 8);
2537
+ __m128i p32 = _mm_slli_epi64(_mm_unpacklo_epi32(p22, p23), 8);
2538
+ __m128i p33 = _mm_srli_epi64(_mm_unpackhi_epi32(p22, p23), 8);
2539
+
2540
+ __m128i p40 = _mm_unpacklo_epi64(p30, p31);
2541
+ __m128i p41 = _mm_unpackhi_epi64(p30, p31);
2542
+ __m128i p42 = _mm_unpacklo_epi64(p32, p33);
2543
+ __m128i p43 = _mm_unpackhi_epi64(p32, p33);
2544
+
2545
+ __m128i v0 = _mm_or_si128(_mm_srli_si128(p40, 2), _mm_slli_si128(p41, 10));
2546
+ __m128i v1 = _mm_or_si128(_mm_srli_si128(p41, 6), _mm_slli_si128(p42, 6));
2547
+ __m128i v2 = _mm_or_si128(_mm_srli_si128(p42, 10), _mm_slli_si128(p43, 2));
2548
+ #endif
2549
+
2550
+ if (mode == hal::STORE_ALIGNED_NOCACHE) {
2551
+ _mm_stream_si128((__m128i *)(ptr), v0);
2552
+ _mm_stream_si128((__m128i *)(ptr + 16), v1);
2553
+ _mm_stream_si128((__m128i *)(ptr + 32), v2);
2554
+ } else if (mode == hal::STORE_ALIGNED) {
2555
+ _mm_store_si128((__m128i *)(ptr), v0);
2556
+ _mm_store_si128((__m128i *)(ptr + 16), v1);
2557
+ _mm_store_si128((__m128i *)(ptr + 32), v2);
2558
+ } else {
2559
+ _mm_storeu_si128((__m128i *)(ptr), v0);
2560
+ _mm_storeu_si128((__m128i *)(ptr + 16), v1);
2561
+ _mm_storeu_si128((__m128i *)(ptr + 32), v2);
2562
+ }
2563
+ }
2564
+
2565
+ inline void v_store_interleave(uchar *ptr, const v_uint8x16 &a,
2566
+ const v_uint8x16 &b, const v_uint8x16 &c,
2567
+ const v_uint8x16 &d,
2568
+ hal::StoreMode mode = hal::STORE_UNALIGNED) {
2569
+ // a0 a1 a2 a3 ....
2570
+ // b0 b1 b2 b3 ....
2571
+ // c0 c1 c2 c3 ....
2572
+ // d0 d1 d2 d3 ....
2573
+ __m128i u0 = _mm_unpacklo_epi8(a.val, c.val); // a0 c0 a1 c1 ...
2574
+ __m128i u1 = _mm_unpackhi_epi8(a.val, c.val); // a8 c8 a9 c9 ...
2575
+ __m128i u2 = _mm_unpacklo_epi8(b.val, d.val); // b0 d0 b1 d1 ...
2576
+ __m128i u3 = _mm_unpackhi_epi8(b.val, d.val); // b8 d8 b9 d9 ...
2577
+
2578
+ __m128i v0 = _mm_unpacklo_epi8(u0, u2); // a0 b0 c0 d0 ...
2579
+ __m128i v1 = _mm_unpackhi_epi8(u0, u2); // a4 b4 c4 d4 ...
2580
+ __m128i v2 = _mm_unpacklo_epi8(u1, u3); // a8 b8 c8 d8 ...
2581
+ __m128i v3 = _mm_unpackhi_epi8(u1, u3); // a12 b12 c12 d12 ...
2582
+
2583
+ if (mode == hal::STORE_ALIGNED_NOCACHE) {
2584
+ _mm_stream_si128((__m128i *)(ptr), v0);
2585
+ _mm_stream_si128((__m128i *)(ptr + 16), v1);
2586
+ _mm_stream_si128((__m128i *)(ptr + 32), v2);
2587
+ _mm_stream_si128((__m128i *)(ptr + 48), v3);
2588
+ } else if (mode == hal::STORE_ALIGNED) {
2589
+ _mm_store_si128((__m128i *)(ptr), v0);
2590
+ _mm_store_si128((__m128i *)(ptr + 16), v1);
2591
+ _mm_store_si128((__m128i *)(ptr + 32), v2);
2592
+ _mm_store_si128((__m128i *)(ptr + 48), v3);
2593
+ } else {
2594
+ _mm_storeu_si128((__m128i *)(ptr), v0);
2595
+ _mm_storeu_si128((__m128i *)(ptr + 16), v1);
2596
+ _mm_storeu_si128((__m128i *)(ptr + 32), v2);
2597
+ _mm_storeu_si128((__m128i *)(ptr + 48), v3);
2598
+ }
2599
+ }
2600
+
2601
+ inline void v_store_interleave(ushort *ptr, const v_uint16x8 &a,
2602
+ const v_uint16x8 &b,
2603
+ hal::StoreMode mode = hal::STORE_UNALIGNED) {
2604
+ __m128i v0 = _mm_unpacklo_epi16(a.val, b.val);
2605
+ __m128i v1 = _mm_unpackhi_epi16(a.val, b.val);
2606
+
2607
+ if (mode == hal::STORE_ALIGNED_NOCACHE) {
2608
+ _mm_stream_si128((__m128i *)(ptr), v0);
2609
+ _mm_stream_si128((__m128i *)(ptr + 8), v1);
2610
+ } else if (mode == hal::STORE_ALIGNED) {
2611
+ _mm_store_si128((__m128i *)(ptr), v0);
2612
+ _mm_store_si128((__m128i *)(ptr + 8), v1);
2613
+ } else {
2614
+ _mm_storeu_si128((__m128i *)(ptr), v0);
2615
+ _mm_storeu_si128((__m128i *)(ptr + 8), v1);
2616
+ }
2617
+ }
2618
+
2619
+ inline void v_store_interleave(ushort *ptr, const v_uint16x8 &a,
2620
+ const v_uint16x8 &b, const v_uint16x8 &c,
2621
+ hal::StoreMode mode = hal::STORE_UNALIGNED) {
2622
+ #if CV_SSE4_1
2623
+ const __m128i sh_a =
2624
+ _mm_setr_epi8(0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5, 10, 11);
2625
+ const __m128i sh_b =
2626
+ _mm_setr_epi8(10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5);
2627
+ const __m128i sh_c =
2628
+ _mm_setr_epi8(4, 5, 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15);
2629
+ __m128i a0 = _mm_shuffle_epi8(a.val, sh_a);
2630
+ __m128i b0 = _mm_shuffle_epi8(b.val, sh_b);
2631
+ __m128i c0 = _mm_shuffle_epi8(c.val, sh_c);
2632
+
2633
+ __m128i v0 = _mm_blend_epi16(_mm_blend_epi16(a0, b0, 0x92), c0, 0x24);
2634
+ __m128i v1 = _mm_blend_epi16(_mm_blend_epi16(c0, a0, 0x92), b0, 0x24);
2635
+ __m128i v2 = _mm_blend_epi16(_mm_blend_epi16(b0, c0, 0x92), a0, 0x24);
2636
+ #else
2637
+ __m128i z = _mm_setzero_si128();
2638
+ __m128i ab0 = _mm_unpacklo_epi16(a.val, b.val);
2639
+ __m128i ab1 = _mm_unpackhi_epi16(a.val, b.val);
2640
+ __m128i c0 = _mm_unpacklo_epi16(c.val, z);
2641
+ __m128i c1 = _mm_unpackhi_epi16(c.val, z);
2642
+
2643
+ __m128i p10 = _mm_unpacklo_epi32(ab0, c0);
2644
+ __m128i p11 = _mm_unpackhi_epi32(ab0, c0);
2645
+ __m128i p12 = _mm_unpacklo_epi32(ab1, c1);
2646
+ __m128i p13 = _mm_unpackhi_epi32(ab1, c1);
2647
+
2648
+ __m128i p20 = _mm_unpacklo_epi64(p10, p11);
2649
+ __m128i p21 = _mm_unpackhi_epi64(p10, p11);
2650
+ __m128i p22 = _mm_unpacklo_epi64(p12, p13);
2651
+ __m128i p23 = _mm_unpackhi_epi64(p12, p13);
2652
+
2653
+ p20 = _mm_slli_si128(p20, 2);
2654
+ p22 = _mm_slli_si128(p22, 2);
2655
+
2656
+ __m128i p30 = _mm_unpacklo_epi64(p20, p21);
2657
+ __m128i p31 = _mm_unpackhi_epi64(p20, p21);
2658
+ __m128i p32 = _mm_unpacklo_epi64(p22, p23);
2659
+ __m128i p33 = _mm_unpackhi_epi64(p22, p23);
2660
+
2661
+ __m128i v0 = _mm_or_si128(_mm_srli_si128(p30, 2), _mm_slli_si128(p31, 10));
2662
+ __m128i v1 = _mm_or_si128(_mm_srli_si128(p31, 6), _mm_slli_si128(p32, 6));
2663
+ __m128i v2 = _mm_or_si128(_mm_srli_si128(p32, 10), _mm_slli_si128(p33, 2));
2664
+ #endif
2665
+ if (mode == hal::STORE_ALIGNED_NOCACHE) {
2666
+ _mm_stream_si128((__m128i *)(ptr), v0);
2667
+ _mm_stream_si128((__m128i *)(ptr + 8), v1);
2668
+ _mm_stream_si128((__m128i *)(ptr + 16), v2);
2669
+ } else if (mode == hal::STORE_ALIGNED) {
2670
+ _mm_store_si128((__m128i *)(ptr), v0);
2671
+ _mm_store_si128((__m128i *)(ptr + 8), v1);
2672
+ _mm_store_si128((__m128i *)(ptr + 16), v2);
2673
+ } else {
2674
+ _mm_storeu_si128((__m128i *)(ptr), v0);
2675
+ _mm_storeu_si128((__m128i *)(ptr + 8), v1);
2676
+ _mm_storeu_si128((__m128i *)(ptr + 16), v2);
2677
+ }
2678
+ }
2679
+
2680
+ inline void v_store_interleave(ushort *ptr, const v_uint16x8 &a,
2681
+ const v_uint16x8 &b, const v_uint16x8 &c,
2682
+ const v_uint16x8 &d,
2683
+ hal::StoreMode mode = hal::STORE_UNALIGNED) {
2684
+ // a0 a1 a2 a3 ....
2685
+ // b0 b1 b2 b3 ....
2686
+ // c0 c1 c2 c3 ....
2687
+ // d0 d1 d2 d3 ....
2688
+ __m128i u0 = _mm_unpacklo_epi16(a.val, c.val); // a0 c0 a1 c1 ...
2689
+ __m128i u1 = _mm_unpackhi_epi16(a.val, c.val); // a4 c4 a5 c5 ...
2690
+ __m128i u2 = _mm_unpacklo_epi16(b.val, d.val); // b0 d0 b1 d1 ...
2691
+ __m128i u3 = _mm_unpackhi_epi16(b.val, d.val); // b4 d4 b5 d5 ...
2692
+
2693
+ __m128i v0 = _mm_unpacklo_epi16(u0, u2); // a0 b0 c0 d0 ...
2694
+ __m128i v1 = _mm_unpackhi_epi16(u0, u2); // a2 b2 c2 d2 ...
2695
+ __m128i v2 = _mm_unpacklo_epi16(u1, u3); // a4 b4 c4 d4 ...
2696
+ __m128i v3 = _mm_unpackhi_epi16(u1, u3); // a6 b6 c6 d6 ...
2697
+
2698
+ if (mode == hal::STORE_ALIGNED_NOCACHE) {
2699
+ _mm_stream_si128((__m128i *)(ptr), v0);
2700
+ _mm_stream_si128((__m128i *)(ptr + 8), v1);
2701
+ _mm_stream_si128((__m128i *)(ptr + 16), v2);
2702
+ _mm_stream_si128((__m128i *)(ptr + 24), v3);
2703
+ } else if (mode == hal::STORE_ALIGNED) {
2704
+ _mm_store_si128((__m128i *)(ptr), v0);
2705
+ _mm_store_si128((__m128i *)(ptr + 8), v1);
2706
+ _mm_store_si128((__m128i *)(ptr + 16), v2);
2707
+ _mm_store_si128((__m128i *)(ptr + 24), v3);
2708
+ } else {
2709
+ _mm_storeu_si128((__m128i *)(ptr), v0);
2710
+ _mm_storeu_si128((__m128i *)(ptr + 8), v1);
2711
+ _mm_storeu_si128((__m128i *)(ptr + 16), v2);
2712
+ _mm_storeu_si128((__m128i *)(ptr + 24), v3);
2713
+ }
2714
+ }
2715
+
2716
+ inline void v_store_interleave(unsigned *ptr, const v_uint32x4 &a,
2717
+ const v_uint32x4 &b,
2718
+ hal::StoreMode mode = hal::STORE_UNALIGNED) {
2719
+ __m128i v0 = _mm_unpacklo_epi32(a.val, b.val);
2720
+ __m128i v1 = _mm_unpackhi_epi32(a.val, b.val);
2721
+
2722
+ if (mode == hal::STORE_ALIGNED_NOCACHE) {
2723
+ _mm_stream_si128((__m128i *)(ptr), v0);
2724
+ _mm_stream_si128((__m128i *)(ptr + 4), v1);
2725
+ } else if (mode == hal::STORE_ALIGNED) {
2726
+ _mm_store_si128((__m128i *)(ptr), v0);
2727
+ _mm_store_si128((__m128i *)(ptr + 4), v1);
2728
+ } else {
2729
+ _mm_storeu_si128((__m128i *)(ptr), v0);
2730
+ _mm_storeu_si128((__m128i *)(ptr + 4), v1);
2731
+ }
2732
+ }
2733
+
2734
+ inline void v_store_interleave(unsigned *ptr, const v_uint32x4 &a,
2735
+ const v_uint32x4 &b, const v_uint32x4 &c,
2736
+ hal::StoreMode mode = hal::STORE_UNALIGNED) {
2737
+ v_uint32x4 z = v_setzero_u32(), u0, u1, u2, u3;
2738
+ v_transpose4x4(a, b, c, z, u0, u1, u2, u3);
2739
+
2740
+ __m128i v0 = _mm_or_si128(u0.val, _mm_slli_si128(u1.val, 12));
2741
+ __m128i v1 =
2742
+ _mm_or_si128(_mm_srli_si128(u1.val, 4), _mm_slli_si128(u2.val, 8));
2743
+ __m128i v2 =
2744
+ _mm_or_si128(_mm_srli_si128(u2.val, 8), _mm_slli_si128(u3.val, 4));
2745
+
2746
+ if (mode == hal::STORE_ALIGNED_NOCACHE) {
2747
+ _mm_stream_si128((__m128i *)(ptr), v0);
2748
+ _mm_stream_si128((__m128i *)(ptr + 4), v1);
2749
+ _mm_stream_si128((__m128i *)(ptr + 8), v2);
2750
+ } else if (mode == hal::STORE_ALIGNED) {
2751
+ _mm_store_si128((__m128i *)(ptr), v0);
2752
+ _mm_store_si128((__m128i *)(ptr + 4), v1);
2753
+ _mm_store_si128((__m128i *)(ptr + 8), v2);
2754
+ } else {
2755
+ _mm_storeu_si128((__m128i *)(ptr), v0);
2756
+ _mm_storeu_si128((__m128i *)(ptr + 4), v1);
2757
+ _mm_storeu_si128((__m128i *)(ptr + 8), v2);
2758
+ }
2759
+ }
2760
+
2761
+ inline void v_store_interleave(unsigned *ptr, const v_uint32x4 &a,
2762
+ const v_uint32x4 &b, const v_uint32x4 &c,
2763
+ const v_uint32x4 &d,
2764
+ hal::StoreMode mode = hal::STORE_UNALIGNED) {
2765
+ v_uint32x4 v0, v1, v2, v3;
2766
+ v_transpose4x4(a, b, c, d, v0, v1, v2, v3);
2767
+
2768
+ if (mode == hal::STORE_ALIGNED_NOCACHE) {
2769
+ _mm_stream_si128((__m128i *)(ptr), v0.val);
2770
+ _mm_stream_si128((__m128i *)(ptr + 4), v1.val);
2771
+ _mm_stream_si128((__m128i *)(ptr + 8), v2.val);
2772
+ _mm_stream_si128((__m128i *)(ptr + 12), v3.val);
2773
+ } else if (mode == hal::STORE_ALIGNED) {
2774
+ _mm_store_si128((__m128i *)(ptr), v0.val);
2775
+ _mm_store_si128((__m128i *)(ptr + 4), v1.val);
2776
+ _mm_store_si128((__m128i *)(ptr + 8), v2.val);
2777
+ _mm_store_si128((__m128i *)(ptr + 12), v3.val);
2778
+ } else {
2779
+ _mm_storeu_si128((__m128i *)(ptr), v0.val);
2780
+ _mm_storeu_si128((__m128i *)(ptr + 4), v1.val);
2781
+ _mm_storeu_si128((__m128i *)(ptr + 8), v2.val);
2782
+ _mm_storeu_si128((__m128i *)(ptr + 12), v3.val);
2783
+ }
2784
+ }
2785
+
2786
+ // 2-channel, float only
2787
+ inline void v_store_interleave(float *ptr, const v_float32x4 &a,
2788
+ const v_float32x4 &b,
2789
+ hal::StoreMode mode = hal::STORE_UNALIGNED) {
2790
+ __m128 v0 = _mm_unpacklo_ps(a.val, b.val); // a0 b0 a1 b1
2791
+ __m128 v1 = _mm_unpackhi_ps(a.val, b.val); // a2 b2 a3 b3
2792
+
2793
+ if (mode == hal::STORE_ALIGNED_NOCACHE) {
2794
+ _mm_stream_ps(ptr, v0);
2795
+ _mm_stream_ps(ptr + 4, v1);
2796
+ } else if (mode == hal::STORE_ALIGNED) {
2797
+ _mm_store_ps(ptr, v0);
2798
+ _mm_store_ps(ptr + 4, v1);
2799
+ } else {
2800
+ _mm_storeu_ps(ptr, v0);
2801
+ _mm_storeu_ps(ptr + 4, v1);
2802
+ }
2803
+ }
2804
+
2805
+ inline void v_store_interleave(float *ptr, const v_float32x4 &a,
2806
+ const v_float32x4 &b, const v_float32x4 &c,
2807
+ hal::StoreMode mode = hal::STORE_UNALIGNED) {
2808
+ __m128 u0 = _mm_shuffle_ps(a.val, b.val, _MM_SHUFFLE(0, 0, 0, 0));
2809
+ __m128 u1 = _mm_shuffle_ps(c.val, a.val, _MM_SHUFFLE(1, 1, 0, 0));
2810
+ __m128 v0 = _mm_shuffle_ps(u0, u1, _MM_SHUFFLE(2, 0, 2, 0));
2811
+ __m128 u2 = _mm_shuffle_ps(b.val, c.val, _MM_SHUFFLE(1, 1, 1, 1));
2812
+ __m128 u3 = _mm_shuffle_ps(a.val, b.val, _MM_SHUFFLE(2, 2, 2, 2));
2813
+ __m128 v1 = _mm_shuffle_ps(u2, u3, _MM_SHUFFLE(2, 0, 2, 0));
2814
+ __m128 u4 = _mm_shuffle_ps(c.val, a.val, _MM_SHUFFLE(3, 3, 2, 2));
2815
+ __m128 u5 = _mm_shuffle_ps(b.val, c.val, _MM_SHUFFLE(3, 3, 3, 3));
2816
+ __m128 v2 = _mm_shuffle_ps(u4, u5, _MM_SHUFFLE(2, 0, 2, 0));
2817
+
2818
+ if (mode == hal::STORE_ALIGNED_NOCACHE) {
2819
+ _mm_stream_ps(ptr, v0);
2820
+ _mm_stream_ps(ptr + 4, v1);
2821
+ _mm_stream_ps(ptr + 8, v2);
2822
+ } else if (mode == hal::STORE_ALIGNED) {
2823
+ _mm_store_ps(ptr, v0);
2824
+ _mm_store_ps(ptr + 4, v1);
2825
+ _mm_store_ps(ptr + 8, v2);
2826
+ } else {
2827
+ _mm_storeu_ps(ptr, v0);
2828
+ _mm_storeu_ps(ptr + 4, v1);
2829
+ _mm_storeu_ps(ptr + 8, v2);
2830
+ }
2831
+ }
2832
+
2833
+ inline void v_store_interleave(float *ptr, const v_float32x4 &a,
2834
+ const v_float32x4 &b, const v_float32x4 &c,
2835
+ const v_float32x4 &d,
2836
+ hal::StoreMode mode = hal::STORE_UNALIGNED) {
2837
+ __m128 u0 = _mm_unpacklo_ps(a.val, c.val);
2838
+ __m128 u1 = _mm_unpacklo_ps(b.val, d.val);
2839
+ __m128 u2 = _mm_unpackhi_ps(a.val, c.val);
2840
+ __m128 u3 = _mm_unpackhi_ps(b.val, d.val);
2841
+ __m128 v0 = _mm_unpacklo_ps(u0, u1);
2842
+ __m128 v2 = _mm_unpacklo_ps(u2, u3);
2843
+ __m128 v1 = _mm_unpackhi_ps(u0, u1);
2844
+ __m128 v3 = _mm_unpackhi_ps(u2, u3);
2845
+
2846
+ if (mode == hal::STORE_ALIGNED_NOCACHE) {
2847
+ _mm_stream_ps(ptr, v0);
2848
+ _mm_stream_ps(ptr + 4, v1);
2849
+ _mm_stream_ps(ptr + 8, v2);
2850
+ _mm_stream_ps(ptr + 12, v3);
2851
+ } else if (mode == hal::STORE_ALIGNED) {
2852
+ _mm_store_ps(ptr, v0);
2853
+ _mm_store_ps(ptr + 4, v1);
2854
+ _mm_store_ps(ptr + 8, v2);
2855
+ _mm_store_ps(ptr + 12, v3);
2856
+ } else {
2857
+ _mm_storeu_ps(ptr, v0);
2858
+ _mm_storeu_ps(ptr + 4, v1);
2859
+ _mm_storeu_ps(ptr + 8, v2);
2860
+ _mm_storeu_ps(ptr + 12, v3);
2861
+ }
2862
+ }
2863
+
2864
+ inline void v_store_interleave(uint64 *ptr, const v_uint64x2 &a,
2865
+ const v_uint64x2 &b,
2866
+ hal::StoreMode mode = hal::STORE_UNALIGNED) {
2867
+ __m128i v0 = _mm_unpacklo_epi64(a.val, b.val);
2868
+ __m128i v1 = _mm_unpackhi_epi64(a.val, b.val);
2869
+
2870
+ if (mode == hal::STORE_ALIGNED_NOCACHE) {
2871
+ _mm_stream_si128((__m128i *)(ptr), v0);
2872
+ _mm_stream_si128((__m128i *)(ptr + 2), v1);
2873
+ } else if (mode == hal::STORE_ALIGNED) {
2874
+ _mm_store_si128((__m128i *)(ptr), v0);
2875
+ _mm_store_si128((__m128i *)(ptr + 2), v1);
2876
+ } else {
2877
+ _mm_storeu_si128((__m128i *)(ptr), v0);
2878
+ _mm_storeu_si128((__m128i *)(ptr + 2), v1);
2879
+ }
2880
+ }
2881
+
2882
+ inline void v_store_interleave(uint64 *ptr, const v_uint64x2 &a,
2883
+ const v_uint64x2 &b, const v_uint64x2 &c,
2884
+ hal::StoreMode mode = hal::STORE_UNALIGNED) {
2885
+ __m128i v0 = _mm_unpacklo_epi64(a.val, b.val);
2886
+ __m128i v1 = _mm_unpacklo_epi64(c.val, _mm_unpackhi_epi64(a.val, a.val));
2887
+ __m128i v2 = _mm_unpackhi_epi64(b.val, c.val);
2888
+
2889
+ if (mode == hal::STORE_ALIGNED_NOCACHE) {
2890
+ _mm_stream_si128((__m128i *)(ptr), v0);
2891
+ _mm_stream_si128((__m128i *)(ptr + 2), v1);
2892
+ _mm_stream_si128((__m128i *)(ptr + 4), v2);
2893
+ } else if (mode == hal::STORE_ALIGNED) {
2894
+ _mm_store_si128((__m128i *)(ptr), v0);
2895
+ _mm_store_si128((__m128i *)(ptr + 2), v1);
2896
+ _mm_store_si128((__m128i *)(ptr + 4), v2);
2897
+ } else {
2898
+ _mm_storeu_si128((__m128i *)(ptr), v0);
2899
+ _mm_storeu_si128((__m128i *)(ptr + 2), v1);
2900
+ _mm_storeu_si128((__m128i *)(ptr + 4), v2);
2901
+ }
2902
+ }
2903
+
2904
+ inline void v_store_interleave(uint64 *ptr, const v_uint64x2 &a,
2905
+ const v_uint64x2 &b, const v_uint64x2 &c,
2906
+ const v_uint64x2 &d,
2907
+ hal::StoreMode mode = hal::STORE_UNALIGNED) {
2908
+ __m128i v0 = _mm_unpacklo_epi64(a.val, b.val);
2909
+ __m128i v1 = _mm_unpacklo_epi64(c.val, d.val);
2910
+ __m128i v2 = _mm_unpackhi_epi64(a.val, b.val);
2911
+ __m128i v3 = _mm_unpackhi_epi64(c.val, d.val);
2912
+
2913
+ if (mode == hal::STORE_ALIGNED_NOCACHE) {
2914
+ _mm_stream_si128((__m128i *)(ptr), v0);
2915
+ _mm_stream_si128((__m128i *)(ptr + 2), v1);
2916
+ _mm_stream_si128((__m128i *)(ptr + 4), v2);
2917
+ _mm_stream_si128((__m128i *)(ptr + 6), v3);
2918
+ } else if (mode == hal::STORE_ALIGNED) {
2919
+ _mm_store_si128((__m128i *)(ptr), v0);
2920
+ _mm_store_si128((__m128i *)(ptr + 2), v1);
2921
+ _mm_store_si128((__m128i *)(ptr + 4), v2);
2922
+ _mm_store_si128((__m128i *)(ptr + 6), v3);
2923
+ } else {
2924
+ _mm_storeu_si128((__m128i *)(ptr), v0);
2925
+ _mm_storeu_si128((__m128i *)(ptr + 2), v1);
2926
+ _mm_storeu_si128((__m128i *)(ptr + 4), v2);
2927
+ _mm_storeu_si128((__m128i *)(ptr + 6), v3);
2928
+ }
2929
+ }
2930
+
2931
+ #define OPENCV_HAL_IMPL_SSE_LOADSTORE_INTERLEAVE(_Tpvec0, _Tp0, suffix0, \
2932
+ _Tpvec1, _Tp1, suffix1) \
2933
+ inline void v_load_deinterleave(const _Tp0 *ptr, _Tpvec0 &a0, _Tpvec0 &b0) { \
2934
+ _Tpvec1 a1, b1; \
2935
+ v_load_deinterleave((const _Tp1 *)ptr, a1, b1); \
2936
+ a0 = v_reinterpret_as_##suffix0(a1); \
2937
+ b0 = v_reinterpret_as_##suffix0(b1); \
2938
+ } \
2939
+ inline void v_load_deinterleave(const _Tp0 *ptr, _Tpvec0 &a0, _Tpvec0 &b0, \
2940
+ _Tpvec0 &c0) { \
2941
+ _Tpvec1 a1, b1, c1; \
2942
+ v_load_deinterleave((const _Tp1 *)ptr, a1, b1, c1); \
2943
+ a0 = v_reinterpret_as_##suffix0(a1); \
2944
+ b0 = v_reinterpret_as_##suffix0(b1); \
2945
+ c0 = v_reinterpret_as_##suffix0(c1); \
2946
+ } \
2947
+ inline void v_load_deinterleave(const _Tp0 *ptr, _Tpvec0 &a0, _Tpvec0 &b0, \
2948
+ _Tpvec0 &c0, _Tpvec0 &d0) { \
2949
+ _Tpvec1 a1, b1, c1, d1; \
2950
+ v_load_deinterleave((const _Tp1 *)ptr, a1, b1, c1, d1); \
2951
+ a0 = v_reinterpret_as_##suffix0(a1); \
2952
+ b0 = v_reinterpret_as_##suffix0(b1); \
2953
+ c0 = v_reinterpret_as_##suffix0(c1); \
2954
+ d0 = v_reinterpret_as_##suffix0(d1); \
2955
+ } \
2956
+ inline void v_store_interleave(_Tp0 *ptr, const _Tpvec0 &a0, \
2957
+ const _Tpvec0 &b0, \
2958
+ hal::StoreMode mode = hal::STORE_UNALIGNED) { \
2959
+ _Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \
2960
+ _Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \
2961
+ v_store_interleave((_Tp1 *)ptr, a1, b1, mode); \
2962
+ } \
2963
+ inline void v_store_interleave(_Tp0 *ptr, const _Tpvec0 &a0, \
2964
+ const _Tpvec0 &b0, const _Tpvec0 &c0, \
2965
+ hal::StoreMode mode = hal::STORE_UNALIGNED) { \
2966
+ _Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \
2967
+ _Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \
2968
+ _Tpvec1 c1 = v_reinterpret_as_##suffix1(c0); \
2969
+ v_store_interleave((_Tp1 *)ptr, a1, b1, c1, mode); \
2970
+ } \
2971
+ inline void v_store_interleave( \
2972
+ _Tp0 *ptr, const _Tpvec0 &a0, const _Tpvec0 &b0, const _Tpvec0 &c0, \
2973
+ const _Tpvec0 &d0, hal::StoreMode mode = hal::STORE_UNALIGNED) { \
2974
+ _Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \
2975
+ _Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \
2976
+ _Tpvec1 c1 = v_reinterpret_as_##suffix1(c0); \
2977
+ _Tpvec1 d1 = v_reinterpret_as_##suffix1(d0); \
2978
+ v_store_interleave((_Tp1 *)ptr, a1, b1, c1, d1, mode); \
2979
+ }
2980
+
2981
+ OPENCV_HAL_IMPL_SSE_LOADSTORE_INTERLEAVE(v_int8x16, schar, s8, v_uint8x16,
2982
+ uchar, u8)
2983
+ OPENCV_HAL_IMPL_SSE_LOADSTORE_INTERLEAVE(v_int16x8, short, s16, v_uint16x8,
2984
+ ushort, u16)
2985
+ OPENCV_HAL_IMPL_SSE_LOADSTORE_INTERLEAVE(v_int32x4, int, s32, v_uint32x4,
2986
+ unsigned, u32)
2987
+ OPENCV_HAL_IMPL_SSE_LOADSTORE_INTERLEAVE(v_int64x2, int64, s64, v_uint64x2,
2988
+ uint64, u64)
2989
+ OPENCV_HAL_IMPL_SSE_LOADSTORE_INTERLEAVE(v_float64x2, double, f64, v_uint64x2,
2990
+ uint64, u64)
2991
+
2992
+ inline v_float32x4 v_cvt_f32(const v_int32x4 &a) {
2993
+ return v_float32x4(_mm_cvtepi32_ps(a.val));
2994
+ }
2995
+
2996
+ inline v_float32x4 v_cvt_f32(const v_float64x2 &a) {
2997
+ return v_float32x4(_mm_cvtpd_ps(a.val));
2998
+ }
2999
+
3000
+ inline v_float32x4 v_cvt_f32(const v_float64x2 &a, const v_float64x2 &b) {
3001
+ return v_float32x4(_mm_movelh_ps(_mm_cvtpd_ps(a.val), _mm_cvtpd_ps(b.val)));
3002
+ }
3003
+
3004
+ inline v_float64x2 v_cvt_f64(const v_int32x4 &a) {
3005
+ return v_float64x2(_mm_cvtepi32_pd(a.val));
3006
+ }
3007
+
3008
+ inline v_float64x2 v_cvt_f64_high(const v_int32x4 &a) {
3009
+ return v_float64x2(_mm_cvtepi32_pd(_mm_srli_si128(a.val, 8)));
3010
+ }
3011
+
3012
+ inline v_float64x2 v_cvt_f64(const v_float32x4 &a) {
3013
+ return v_float64x2(_mm_cvtps_pd(a.val));
3014
+ }
3015
+
3016
+ inline v_float64x2 v_cvt_f64_high(const v_float32x4 &a) {
3017
+ return v_float64x2(_mm_cvtps_pd(_mm_movehl_ps(a.val, a.val)));
3018
+ }
3019
+
3020
+ // from (Mysticial and wim) https://stackoverflow.com/q/41144668
3021
+ inline v_float64x2 v_cvt_f64(const v_int64x2 &v) {
3022
+ // constants encoded as floating-point
3023
+ __m128i magic_i_hi32 = _mm_set1_epi64x(0x4530000080000000); // 2^84 + 2^63
3024
+ __m128i magic_i_all =
3025
+ _mm_set1_epi64x(0x4530000080100000); // 2^84 + 2^63 + 2^52
3026
+ __m128d magic_d_all = _mm_castsi128_pd(magic_i_all);
3027
+ // Blend the 32 lowest significant bits of v with magic_int_lo
3028
+ #if CV_SSE4_1
3029
+ __m128i magic_i_lo = _mm_set1_epi64x(0x4330000000000000); // 2^52
3030
+ __m128i v_lo = _mm_blend_epi16(v.val, magic_i_lo, 0xcc);
3031
+ #else
3032
+ __m128i magic_i_lo = _mm_set1_epi32(0x43300000); // 2^52
3033
+ __m128i v_lo = _mm_unpacklo_epi32(
3034
+ _mm_shuffle_epi32(v.val, _MM_SHUFFLE(0, 0, 2, 0)), magic_i_lo);
3035
+ #endif
3036
+ // Extract the 32 most significant bits of v
3037
+ __m128i v_hi = _mm_srli_epi64(v.val, 32);
3038
+ // Flip the msb of v_hi and blend with 0x45300000
3039
+ v_hi = _mm_xor_si128(v_hi, magic_i_hi32);
3040
+ // Compute in double precision
3041
+ __m128d v_hi_dbl = _mm_sub_pd(_mm_castsi128_pd(v_hi), magic_d_all);
3042
+ // (v_hi - magic_d_all) + v_lo Do not assume associativity of floating point
3043
+ // addition
3044
+ __m128d result = _mm_add_pd(v_hi_dbl, _mm_castsi128_pd(v_lo));
3045
+ return v_float64x2(result);
3046
+ }
3047
+
3048
+ ////////////// Lookup table access ////////////////////
3049
+
3050
+ inline v_int8x16 v_lut(const schar *tab, const int *idx) {
3051
+ #if defined(_MSC_VER)
3052
+ return v_int8x16(
3053
+ _mm_setr_epi8(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]],
3054
+ tab[idx[4]], tab[idx[5]], tab[idx[6]], tab[idx[7]],
3055
+ tab[idx[8]], tab[idx[9]], tab[idx[10]], tab[idx[11]],
3056
+ tab[idx[12]], tab[idx[13]], tab[idx[14]], tab[idx[15]]));
3057
+ #else
3058
+ return v_int8x16(_mm_setr_epi64(
3059
+ _mm_setr_pi8(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]],
3060
+ tab[idx[4]], tab[idx[5]], tab[idx[6]], tab[idx[7]]),
3061
+ _mm_setr_pi8(tab[idx[8]], tab[idx[9]], tab[idx[10]], tab[idx[11]],
3062
+ tab[idx[12]], tab[idx[13]], tab[idx[14]], tab[idx[15]])));
3063
+ #endif
3064
+ }
3065
+ inline v_int8x16 v_lut_pairs(const schar *tab, const int *idx) {
3066
+ #if defined(_MSC_VER)
3067
+ return v_int8x16(_mm_setr_epi16(
3068
+ *(const short *)(tab + idx[0]), *(const short *)(tab + idx[1]),
3069
+ *(const short *)(tab + idx[2]), *(const short *)(tab + idx[3]),
3070
+ *(const short *)(tab + idx[4]), *(const short *)(tab + idx[5]),
3071
+ *(const short *)(tab + idx[6]), *(const short *)(tab + idx[7])));
3072
+ #else
3073
+ return v_int8x16(_mm_setr_epi64(
3074
+ _mm_setr_pi16(
3075
+ *(const short *)(tab + idx[0]), *(const short *)(tab + idx[1]),
3076
+ *(const short *)(tab + idx[2]), *(const short *)(tab + idx[3])),
3077
+ _mm_setr_pi16(
3078
+ *(const short *)(tab + idx[4]), *(const short *)(tab + idx[5]),
3079
+ *(const short *)(tab + idx[6]), *(const short *)(tab + idx[7]))));
3080
+ #endif
3081
+ }
3082
+ inline v_int8x16 v_lut_quads(const schar *tab, const int *idx) {
3083
+ #if defined(_MSC_VER)
3084
+ return v_int8x16(_mm_setr_epi32(
3085
+ *(const int *)(tab + idx[0]), *(const int *)(tab + idx[1]),
3086
+ *(const int *)(tab + idx[2]), *(const int *)(tab + idx[3])));
3087
+ #else
3088
+ return v_int8x16(_mm_setr_epi64(
3089
+ _mm_setr_pi32(*(const int *)(tab + idx[0]), *(const int *)(tab + idx[1])),
3090
+ _mm_setr_pi32(*(const int *)(tab + idx[2]),
3091
+ *(const int *)(tab + idx[3]))));
3092
+ #endif
3093
+ }
3094
+ inline v_uint8x16 v_lut(const uchar *tab, const int *idx) {
3095
+ return v_reinterpret_as_u8(v_lut((const schar *)tab, idx));
3096
+ }
3097
+ inline v_uint8x16 v_lut_pairs(const uchar *tab, const int *idx) {
3098
+ return v_reinterpret_as_u8(v_lut_pairs((const schar *)tab, idx));
3099
+ }
3100
+ inline v_uint8x16 v_lut_quads(const uchar *tab, const int *idx) {
3101
+ return v_reinterpret_as_u8(v_lut_quads((const schar *)tab, idx));
3102
+ }
3103
+
3104
+ inline v_int16x8 v_lut(const short *tab, const int *idx) {
3105
+ #if defined(_MSC_VER)
3106
+ return v_int16x8(_mm_setr_epi16(tab[idx[0]], tab[idx[1]], tab[idx[2]],
3107
+ tab[idx[3]], tab[idx[4]], tab[idx[5]],
3108
+ tab[idx[6]], tab[idx[7]]));
3109
+ #else
3110
+ return v_int16x8(_mm_setr_epi64(
3111
+ _mm_setr_pi16(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]),
3112
+ _mm_setr_pi16(tab[idx[4]], tab[idx[5]], tab[idx[6]], tab[idx[7]])));
3113
+ #endif
3114
+ }
3115
+ inline v_int16x8 v_lut_pairs(const short *tab, const int *idx) {
3116
+ #if defined(_MSC_VER)
3117
+ return v_int16x8(_mm_setr_epi32(
3118
+ *(const int *)(tab + idx[0]), *(const int *)(tab + idx[1]),
3119
+ *(const int *)(tab + idx[2]), *(const int *)(tab + idx[3])));
3120
+ #else
3121
+ return v_int16x8(_mm_setr_epi64(
3122
+ _mm_setr_pi32(*(const int *)(tab + idx[0]), *(const int *)(tab + idx[1])),
3123
+ _mm_setr_pi32(*(const int *)(tab + idx[2]),
3124
+ *(const int *)(tab + idx[3]))));
3125
+ #endif
3126
+ }
3127
+ inline v_int16x8 v_lut_quads(const short *tab, const int *idx) {
3128
+ return v_int16x8(_mm_set_epi64x(*(const int64_t *)(tab + idx[1]),
3129
+ *(const int64_t *)(tab + idx[0])));
3130
+ }
3131
+ inline v_uint16x8 v_lut(const ushort *tab, const int *idx) {
3132
+ return v_reinterpret_as_u16(v_lut((const short *)tab, idx));
3133
+ }
3134
+ inline v_uint16x8 v_lut_pairs(const ushort *tab, const int *idx) {
3135
+ return v_reinterpret_as_u16(v_lut_pairs((const short *)tab, idx));
3136
+ }
3137
+ inline v_uint16x8 v_lut_quads(const ushort *tab, const int *idx) {
3138
+ return v_reinterpret_as_u16(v_lut_quads((const short *)tab, idx));
3139
+ }
3140
+
3141
+ inline v_int32x4 v_lut(const int *tab, const int *idx) {
3142
+ #if defined(_MSC_VER)
3143
+ return v_int32x4(
3144
+ _mm_setr_epi32(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]));
3145
+ #else
3146
+ return v_int32x4(_mm_setr_epi64(_mm_setr_pi32(tab[idx[0]], tab[idx[1]]),
3147
+ _mm_setr_pi32(tab[idx[2]], tab[idx[3]])));
3148
+ #endif
3149
+ }
3150
+ inline v_int32x4 v_lut_pairs(const int *tab, const int *idx) {
3151
+ return v_int32x4(_mm_set_epi64x(*(const int64_t *)(tab + idx[1]),
3152
+ *(const int64_t *)(tab + idx[0])));
3153
+ }
3154
+ inline v_int32x4 v_lut_quads(const int *tab, const int *idx) {
3155
+ return v_int32x4(_mm_loadu_si128((const __m128i *)(tab + idx[0])));
3156
+ }
3157
+ inline v_uint32x4 v_lut(const unsigned *tab, const int *idx) {
3158
+ return v_reinterpret_as_u32(v_lut((const int *)tab, idx));
3159
+ }
3160
+ inline v_uint32x4 v_lut_pairs(const unsigned *tab, const int *idx) {
3161
+ return v_reinterpret_as_u32(v_lut_pairs((const int *)tab, idx));
3162
+ }
3163
+ inline v_uint32x4 v_lut_quads(const unsigned *tab, const int *idx) {
3164
+ return v_reinterpret_as_u32(v_lut_quads((const int *)tab, idx));
3165
+ }
3166
+
3167
+ inline v_int64x2 v_lut(const int64_t *tab, const int *idx) {
3168
+ return v_int64x2(_mm_set_epi64x(tab[idx[1]], tab[idx[0]]));
3169
+ }
3170
+ inline v_int64x2 v_lut_pairs(const int64_t *tab, const int *idx) {
3171
+ return v_int64x2(_mm_loadu_si128((const __m128i *)(tab + idx[0])));
3172
+ }
3173
+ inline v_uint64x2 v_lut(const uint64_t *tab, const int *idx) {
3174
+ return v_reinterpret_as_u64(v_lut((const int64_t *)tab, idx));
3175
+ }
3176
+ inline v_uint64x2 v_lut_pairs(const uint64_t *tab, const int *idx) {
3177
+ return v_reinterpret_as_u64(v_lut_pairs((const int64_t *)tab, idx));
3178
+ }
3179
+
3180
+ inline v_float32x4 v_lut(const float *tab, const int *idx) {
3181
+ return v_float32x4(
3182
+ _mm_setr_ps(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]));
3183
+ }
3184
+ inline v_float32x4 v_lut_pairs(const float *tab, const int *idx) {
3185
+ return v_reinterpret_as_f32(v_lut_pairs((const int *)tab, idx));
3186
+ }
3187
+ inline v_float32x4 v_lut_quads(const float *tab, const int *idx) {
3188
+ return v_reinterpret_as_f32(v_lut_quads((const int *)tab, idx));
3189
+ }
3190
+
3191
+ inline v_float64x2 v_lut(const double *tab, const int *idx) {
3192
+ return v_float64x2(_mm_setr_pd(tab[idx[0]], tab[idx[1]]));
3193
+ }
3194
+ inline v_float64x2 v_lut_pairs(const double *tab, const int *idx) {
3195
+ return v_float64x2(
3196
+ _mm_castsi128_pd(_mm_loadu_si128((const __m128i *)(tab + idx[0]))));
3197
+ }
3198
+
3199
+ inline v_int32x4 v_lut(const int *tab, const v_int32x4 &idxvec) {
3200
+ int CV_DECL_ALIGNED(32) idx[4];
3201
+ v_store_aligned(idx, idxvec);
3202
+ return v_int32x4(
3203
+ _mm_setr_epi32(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]));
3204
+ }
3205
+
3206
+ inline v_uint32x4 v_lut(const unsigned *tab, const v_int32x4 &idxvec) {
3207
+ return v_reinterpret_as_u32(v_lut((const int *)tab, idxvec));
3208
+ }
3209
+
3210
+ inline v_float32x4 v_lut(const float *tab, const v_int32x4 &idxvec) {
3211
+ int CV_DECL_ALIGNED(32) idx[4];
3212
+ v_store_aligned(idx, idxvec);
3213
+ return v_float32x4(
3214
+ _mm_setr_ps(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]));
3215
+ }
3216
+
3217
+ inline v_float64x2 v_lut(const double *tab, const v_int32x4 &idxvec) {
3218
+ int idx[2];
3219
+ v_store_low(idx, idxvec);
3220
+ return v_float64x2(_mm_setr_pd(tab[idx[0]], tab[idx[1]]));
3221
+ }
3222
+
3223
+ // loads pairs from the table and deinterleaves them, e.g. returns:
3224
+ // x = (tab[idxvec[0], tab[idxvec[1]], tab[idxvec[2]], tab[idxvec[3]]),
3225
+ // y = (tab[idxvec[0]+1], tab[idxvec[1]+1], tab[idxvec[2]+1],
3226
+ // tab[idxvec[3]+1])
3227
+ // note that the indices are float's indices, not the float-pair indices.
3228
+ // in theory, this function can be used to implement bilinear interpolation,
3229
+ // when idxvec are the offsets within the image.
3230
+ inline void v_lut_deinterleave(const float *tab, const v_int32x4 &idxvec,
3231
+ v_float32x4 &x, v_float32x4 &y) {
3232
+ int CV_DECL_ALIGNED(32) idx[4];
3233
+ v_store_aligned(idx, idxvec);
3234
+ __m128 z = _mm_setzero_ps();
3235
+ __m128 xy01 = _mm_loadl_pi(z, (__m64 *)(tab + idx[0]));
3236
+ __m128 xy23 = _mm_loadl_pi(z, (__m64 *)(tab + idx[2]));
3237
+ xy01 = _mm_loadh_pi(xy01, (__m64 *)(tab + idx[1]));
3238
+ xy23 = _mm_loadh_pi(xy23, (__m64 *)(tab + idx[3]));
3239
+ __m128 xxyy02 = _mm_unpacklo_ps(xy01, xy23);
3240
+ __m128 xxyy13 = _mm_unpackhi_ps(xy01, xy23);
3241
+ x = v_float32x4(_mm_unpacklo_ps(xxyy02, xxyy13));
3242
+ y = v_float32x4(_mm_unpackhi_ps(xxyy02, xxyy13));
3243
+ }
3244
+
3245
+ inline void v_lut_deinterleave(const double *tab, const v_int32x4 &idxvec,
3246
+ v_float64x2 &x, v_float64x2 &y) {
3247
+ int idx[2];
3248
+ v_store_low(idx, idxvec);
3249
+ __m128d xy0 = _mm_loadu_pd(tab + idx[0]);
3250
+ __m128d xy1 = _mm_loadu_pd(tab + idx[1]);
3251
+ x = v_float64x2(_mm_unpacklo_pd(xy0, xy1));
3252
+ y = v_float64x2(_mm_unpackhi_pd(xy0, xy1));
3253
+ }
3254
+
3255
+ inline v_int8x16 v_interleave_pairs(const v_int8x16 &vec) {
3256
+ #if CV_SSSE3
3257
+ return v_int8x16(_mm_shuffle_epi8(
3258
+ vec.val, _mm_set_epi64x(0x0f0d0e0c0b090a08, 0x0705060403010200)));
3259
+ #else
3260
+ __m128i a = _mm_shufflelo_epi16(vec.val, _MM_SHUFFLE(3, 1, 2, 0));
3261
+ a = _mm_shufflehi_epi16(a, _MM_SHUFFLE(3, 1, 2, 0));
3262
+ a = _mm_shuffle_epi32(a, _MM_SHUFFLE(3, 1, 2, 0));
3263
+ return v_int8x16(_mm_unpacklo_epi8(a, _mm_unpackhi_epi64(a, a)));
3264
+ #endif
3265
+ }
3266
+ inline v_uint8x16 v_interleave_pairs(const v_uint8x16 &vec) {
3267
+ return v_reinterpret_as_u8(v_interleave_pairs(v_reinterpret_as_s8(vec)));
3268
+ }
3269
+ inline v_int8x16 v_interleave_quads(const v_int8x16 &vec) {
3270
+ #if CV_SSSE3
3271
+ return v_int8x16(_mm_shuffle_epi8(
3272
+ vec.val, _mm_set_epi64x(0x0f0b0e0a0d090c08, 0x0703060205010400)));
3273
+ #else
3274
+ __m128i a = _mm_shuffle_epi32(vec.val, _MM_SHUFFLE(3, 1, 2, 0));
3275
+ return v_int8x16(_mm_unpacklo_epi8(a, _mm_unpackhi_epi64(a, a)));
3276
+ #endif
3277
+ }
3278
+ inline v_uint8x16 v_interleave_quads(const v_uint8x16 &vec) {
3279
+ return v_reinterpret_as_u8(v_interleave_quads(v_reinterpret_as_s8(vec)));
3280
+ }
3281
+
3282
+ inline v_int16x8 v_interleave_pairs(const v_int16x8 &vec) {
3283
+ #if CV_SSSE3
3284
+ return v_int16x8(_mm_shuffle_epi8(
3285
+ vec.val, _mm_set_epi64x(0x0f0e0b0a0d0c0908, 0x0706030205040100)));
3286
+ #else
3287
+ __m128i a = _mm_shufflelo_epi16(vec.val, _MM_SHUFFLE(3, 1, 2, 0));
3288
+ return v_int16x8(_mm_shufflehi_epi16(a, _MM_SHUFFLE(3, 1, 2, 0)));
3289
+ #endif
3290
+ }
3291
+ inline v_uint16x8 v_interleave_pairs(const v_uint16x8 &vec) {
3292
+ return v_reinterpret_as_u16(v_interleave_pairs(v_reinterpret_as_s16(vec)));
3293
+ }
3294
+ inline v_int16x8 v_interleave_quads(const v_int16x8 &vec) {
3295
+ #if CV_SSSE3
3296
+ return v_int16x8(_mm_shuffle_epi8(
3297
+ vec.val, _mm_set_epi64x(0x0f0e07060d0c0504, 0x0b0a030209080100)));
3298
+ #else
3299
+ return v_int16x8(
3300
+ _mm_unpacklo_epi16(vec.val, _mm_unpackhi_epi64(vec.val, vec.val)));
3301
+ #endif
3302
+ }
3303
+ inline v_uint16x8 v_interleave_quads(const v_uint16x8 &vec) {
3304
+ return v_reinterpret_as_u16(v_interleave_quads(v_reinterpret_as_s16(vec)));
3305
+ }
3306
+
3307
+ inline v_int32x4 v_interleave_pairs(const v_int32x4 &vec) {
3308
+ return v_int32x4(_mm_shuffle_epi32(vec.val, _MM_SHUFFLE(3, 1, 2, 0)));
3309
+ }
3310
+ inline v_uint32x4 v_interleave_pairs(const v_uint32x4 &vec) {
3311
+ return v_reinterpret_as_u32(v_interleave_pairs(v_reinterpret_as_s32(vec)));
3312
+ }
3313
+ inline v_float32x4 v_interleave_pairs(const v_float32x4 &vec) {
3314
+ return v_reinterpret_as_f32(v_interleave_pairs(v_reinterpret_as_s32(vec)));
3315
+ }
3316
+
3317
+ inline v_int8x16 v_pack_triplets(const v_int8x16 &vec) {
3318
+ #if CV_SSSE3
3319
+ return v_int8x16(_mm_shuffle_epi8(
3320
+ vec.val, _mm_set_epi64x(0xffffff0f0e0d0c0a, 0x0908060504020100)));
3321
+ #else
3322
+ __m128i mask = _mm_set1_epi64x(0x00000000FFFFFFFF);
3323
+ __m128i a = _mm_srli_si128(
3324
+ _mm_or_si128(
3325
+ _mm_andnot_si128(mask, vec.val),
3326
+ _mm_and_si128(mask, _mm_sll_epi32(vec.val, _mm_set_epi64x(0, 8)))),
3327
+ 1);
3328
+ return v_int8x16(
3329
+ _mm_srli_si128(_mm_shufflelo_epi16(a, _MM_SHUFFLE(2, 1, 0, 3)), 2));
3330
+ #endif
3331
+ }
3332
+ inline v_uint8x16 v_pack_triplets(const v_uint8x16 &vec) {
3333
+ return v_reinterpret_as_u8(v_pack_triplets(v_reinterpret_as_s8(vec)));
3334
+ }
3335
+
3336
+ inline v_int16x8 v_pack_triplets(const v_int16x8 &vec) {
3337
+ #if CV_SSSE3
3338
+ return v_int16x8(_mm_shuffle_epi8(
3339
+ vec.val, _mm_set_epi64x(0xffff0f0e0d0c0b0a, 0x0908050403020100)));
3340
+ #else
3341
+ return v_int16x8(
3342
+ _mm_srli_si128(_mm_shufflelo_epi16(vec.val, _MM_SHUFFLE(2, 1, 0, 3)), 2));
3343
+ #endif
3344
+ }
3345
+ inline v_uint16x8 v_pack_triplets(const v_uint16x8 &vec) {
3346
+ return v_reinterpret_as_u16(v_pack_triplets(v_reinterpret_as_s16(vec)));
3347
+ }
3348
+
3349
+ inline v_int32x4 v_pack_triplets(const v_int32x4 &vec) { return vec; }
3350
+ inline v_uint32x4 v_pack_triplets(const v_uint32x4 &vec) { return vec; }
3351
+ inline v_float32x4 v_pack_triplets(const v_float32x4 &vec) { return vec; }
3352
+
3353
+ template <int i> inline uchar v_extract_n(const v_uint8x16 &v) {
3354
+ #if CV_SSE4_1
3355
+ return (uchar)_mm_extract_epi8(v.val, i);
3356
+ #else
3357
+ return v_rotate_right<i>(v).get0();
3358
+ #endif
3359
+ }
3360
+
3361
+ template <int i> inline schar v_extract_n(const v_int8x16 &v) {
3362
+ return (schar)v_extract_n<i>(v_reinterpret_as_u8(v));
3363
+ }
3364
+
3365
+ template <int i> inline ushort v_extract_n(const v_uint16x8 &v) {
3366
+ return (ushort)_mm_extract_epi16(v.val, i);
3367
+ }
3368
+
3369
+ template <int i> inline short v_extract_n(const v_int16x8 &v) {
3370
+ return (short)v_extract_n<i>(v_reinterpret_as_u16(v));
3371
+ }
3372
+
3373
+ template <int i> inline uint v_extract_n(const v_uint32x4 &v) {
3374
+ #if CV_SSE4_1
3375
+ return (uint)_mm_extract_epi32(v.val, i);
3376
+ #else
3377
+ return v_rotate_right<i>(v).get0();
3378
+ #endif
3379
+ }
3380
+
3381
+ template <int i> inline int v_extract_n(const v_int32x4 &v) {
3382
+ return (int)v_extract_n<i>(v_reinterpret_as_u32(v));
3383
+ }
3384
+
3385
+ template <int i> inline uint64 v_extract_n(const v_uint64x2 &v) {
3386
+ #ifdef CV__SIMD_NATIVE_mm_extract_epi64
3387
+ return (uint64)_v128_extract_epi64<i>(v.val);
3388
+ #else
3389
+ return v_rotate_right<i>(v).get0();
3390
+ #endif
3391
+ }
3392
+
3393
+ template <int i> inline int64 v_extract_n(const v_int64x2 &v) {
3394
+ return (int64)v_extract_n<i>(v_reinterpret_as_u64(v));
3395
+ }
3396
+
3397
+ template <int i> inline float v_extract_n(const v_float32x4 &v) {
3398
+ union {
3399
+ uint iv;
3400
+ float fv;
3401
+ } d;
3402
+ d.iv = v_extract_n<i>(v_reinterpret_as_u32(v));
3403
+ return d.fv;
3404
+ }
3405
+
3406
+ template <int i> inline double v_extract_n(const v_float64x2 &v) {
3407
+ union {
3408
+ uint64 iv;
3409
+ double dv;
3410
+ } d;
3411
+ d.iv = v_extract_n<i>(v_reinterpret_as_u64(v));
3412
+ return d.dv;
3413
+ }
3414
+
3415
+ template <int i> inline v_int32x4 v_broadcast_element(const v_int32x4 &v) {
3416
+ return v_int32x4(_mm_shuffle_epi32(v.val, _MM_SHUFFLE(i, i, i, i)));
3417
+ }
3418
+
3419
+ template <int i> inline v_uint32x4 v_broadcast_element(const v_uint32x4 &v) {
3420
+ return v_uint32x4(_mm_shuffle_epi32(v.val, _MM_SHUFFLE(i, i, i, i)));
3421
+ }
3422
+
3423
+ template <int i> inline v_float32x4 v_broadcast_element(const v_float32x4 &v) {
3424
+ return v_float32x4(_mm_shuffle_ps(
3425
+ v.val, v.val, _MM_SHUFFLE((char)i, (char)i, (char)i, (char)i)));
3426
+ }
3427
+
3428
+ ////////////// FP16 support ///////////////////////////
3429
+
3430
+ inline v_float32x4 v_load_expand(const hfloat *ptr) {
3431
+ #if CV_FP16
3432
+ return v_float32x4(_mm_cvtph_ps(_mm_loadu_si128((const __m128i *)ptr)));
3433
+ #else
3434
+ const __m128i z = _mm_setzero_si128(), delta = _mm_set1_epi32(0x38000000);
3435
+ const __m128i signmask = _mm_set1_epi32(0x80000000),
3436
+ maxexp = _mm_set1_epi32(0x7c000000);
3437
+ const __m128 deltaf = _mm_castsi128_ps(_mm_set1_epi32(0x38800000));
3438
+ __m128i bits =
3439
+ _mm_unpacklo_epi16(z, _mm_loadl_epi64((const __m128i *)ptr)); // h << 16
3440
+ __m128i e = _mm_and_si128(bits, maxexp), sign = _mm_and_si128(bits, signmask);
3441
+ __m128i t = _mm_add_epi32(_mm_srli_epi32(_mm_xor_si128(bits, sign), 3),
3442
+ delta); // ((h & 0x7fff) << 13) + delta
3443
+ __m128i zt = _mm_castps_si128(_mm_sub_ps(
3444
+ _mm_castsi128_ps(_mm_add_epi32(t, _mm_set1_epi32(1 << 23))), deltaf));
3445
+
3446
+ t = _mm_add_epi32(t, _mm_and_si128(delta, _mm_cmpeq_epi32(maxexp, e)));
3447
+ __m128i zmask = _mm_cmpeq_epi32(e, z);
3448
+ __m128i ft = v_select_si128(zmask, zt, t);
3449
+ return v_float32x4(_mm_castsi128_ps(_mm_or_si128(ft, sign)));
3450
+ #endif
3451
+ }
3452
+
3453
+ inline void v_pack_store(hfloat *ptr, const v_float32x4 &v) {
3454
+ #if CV_FP16
3455
+ __m128i fp16_value = _mm_cvtps_ph(v.val, 0);
3456
+ _mm_storel_epi64((__m128i *)ptr, fp16_value);
3457
+ #else
3458
+ const __m128i signmask = _mm_set1_epi32(0x80000000);
3459
+ const __m128i rval = _mm_set1_epi32(0x3f000000);
3460
+
3461
+ __m128i t = _mm_castps_si128(v.val);
3462
+ __m128i sign = _mm_srai_epi32(_mm_and_si128(t, signmask), 16);
3463
+ t = _mm_andnot_si128(signmask, t);
3464
+
3465
+ __m128i finitemask = _mm_cmpgt_epi32(_mm_set1_epi32(0x47800000), t);
3466
+ __m128i isnan = _mm_cmpgt_epi32(t, _mm_set1_epi32(0x7f800000));
3467
+ __m128i naninf =
3468
+ v_select_si128(isnan, _mm_set1_epi32(0x7e00), _mm_set1_epi32(0x7c00));
3469
+ __m128i tinymask = _mm_cmpgt_epi32(_mm_set1_epi32(0x38800000), t);
3470
+ __m128i tt =
3471
+ _mm_castps_si128(_mm_add_ps(_mm_castsi128_ps(t), _mm_castsi128_ps(rval)));
3472
+ tt = _mm_sub_epi32(tt, rval);
3473
+ __m128i odd = _mm_and_si128(_mm_srli_epi32(t, 13), _mm_set1_epi32(1));
3474
+ __m128i nt = _mm_add_epi32(t, _mm_set1_epi32(0xc8000fff));
3475
+ nt = _mm_srli_epi32(_mm_add_epi32(nt, odd), 13);
3476
+ t = v_select_si128(tinymask, tt, nt);
3477
+ t = v_select_si128(finitemask, t, naninf);
3478
+ t = _mm_or_si128(t, sign);
3479
+ t = _mm_packs_epi32(t, t);
3480
+ _mm_storel_epi64((__m128i *)ptr, t);
3481
+ #endif
3482
+ }
3483
+
3484
+ inline void v_cleanup() {}
3485
+
3486
+ #include "intrin_math.hpp"
3487
+ inline v_float32x4 v_exp(const v_float32x4 &x) {
3488
+ return v_exp_default_32f<v_float32x4, v_int32x4>(x);
3489
+ }
3490
+ inline v_float32x4 v_log(const v_float32x4 &x) {
3491
+ return v_log_default_32f<v_float32x4, v_int32x4>(x);
3492
+ }
3493
+ inline void v_sincos(const v_float32x4 &x, v_float32x4 &s, v_float32x4 &c) {
3494
+ v_sincos_default_32f<v_float32x4, v_int32x4>(x, s, c);
3495
+ }
3496
+ inline v_float32x4 v_sin(const v_float32x4 &x) {
3497
+ return v_sin_default_32f<v_float32x4, v_int32x4>(x);
3498
+ }
3499
+ inline v_float32x4 v_cos(const v_float32x4 &x) {
3500
+ return v_cos_default_32f<v_float32x4, v_int32x4>(x);
3501
+ }
3502
+ inline v_float32x4 v_erf(const v_float32x4 &x) {
3503
+ return v_erf_default_32f<v_float32x4, v_int32x4>(x);
3504
+ }
3505
+
3506
+ inline v_float64x2 v_exp(const v_float64x2 &x) {
3507
+ return v_exp_default_64f<v_float64x2, v_int64x2>(x);
3508
+ }
3509
+ inline v_float64x2 v_log(const v_float64x2 &x) {
3510
+ return v_log_default_64f<v_float64x2, v_int64x2>(x);
3511
+ }
3512
+ inline void v_sincos(const v_float64x2 &x, v_float64x2 &s, v_float64x2 &c) {
3513
+ v_sincos_default_64f<v_float64x2, v_int64x2>(x, s, c);
3514
+ }
3515
+ inline v_float64x2 v_sin(const v_float64x2 &x) {
3516
+ return v_sin_default_64f<v_float64x2, v_int64x2>(x);
3517
+ }
3518
+ inline v_float64x2 v_cos(const v_float64x2 &x) {
3519
+ return v_cos_default_64f<v_float64x2, v_int64x2>(x);
3520
+ }
3521
+
3522
+ CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END
3523
+
3524
+ //! @endcond
3525
+
3526
+ } // namespace cv
3527
+
3528
+ #endif