core.hpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. #ifndef OPENCV_NDSRVP_CORE_HPP
  5. #define OPENCV_NDSRVP_CORE_HPP
  6. namespace cv {
  7. namespace ndsrvp {
  8. template <typename srctype, typename dsttype,
  9. typename vsrctype, typename vdsttype, int nlane,
  10. template <typename src, typename dst> typename operators_t,
  11. typename... params_t>
  12. int elemwise_binop(const srctype* src1_data, size_t src1_step,
  13. const srctype* src2_data, size_t src2_step,
  14. dsttype* dst_data, size_t dst_step,
  15. int width, int height, params_t... params)
  16. {
  17. src1_step /= sizeof(srctype);
  18. src2_step /= sizeof(srctype);
  19. dst_step /= sizeof(dsttype);
  20. operators_t<srctype, dsttype> operators;
  21. int i, j;
  22. for (i = 0; i < height; ++i) {
  23. const srctype* src1_row = src1_data + (src1_step * i);
  24. const srctype* src2_row = src2_data + (src2_step * i);
  25. dsttype* dst_row = dst_data + (dst_step * i);
  26. j = 0;
  27. for (; j + nlane <= width; j += nlane) {
  28. register vsrctype vs1 = *(vsrctype*)(src1_row + j);
  29. register vsrctype vs2 = *(vsrctype*)(src2_row + j);
  30. *(vdsttype*)(dst_row + j) = operators.vector(vs1, vs2, params...);
  31. }
  32. for (; j < width; j++)
  33. dst_row[j] = operators.scalar(src1_row[j], src2_row[j], params...);
  34. }
  35. return CV_HAL_ERROR_OK;
  36. }
  37. template <typename srctype, typename dsttype,
  38. typename vsrctype, typename vdsttype, int nlane,
  39. template <typename src, typename dst> typename operators_t,
  40. typename... params_t>
  41. int elemwise_unop(const srctype* src_data, size_t src_step,
  42. dsttype* dst_data, size_t dst_step,
  43. int width, int height, params_t... params)
  44. {
  45. src_step /= sizeof(srctype);
  46. dst_step /= sizeof(dsttype);
  47. operators_t<srctype, dsttype> operators;
  48. int i, j;
  49. for (i = 0; i < height; ++i) {
  50. const srctype* src_row = src_data + (src_step * i);
  51. dsttype* dst_row = dst_data + (dst_step * i);
  52. j = 0;
  53. for (; j + nlane <= width; j += nlane) {
  54. register vsrctype vs = *(vsrctype*)(src_row + j);
  55. *(vdsttype*)(dst_row + j) = operators.vector(vs, params...);
  56. }
  57. for (; j < width; j++)
  58. dst_row[j] = operators.scalar(src_row[j], params...);
  59. }
  60. return CV_HAL_ERROR_OK;
  61. }
  62. // ################ add ################
  63. template <typename src, typename dst>
  64. struct operators_add_t {
  65. inline uint8x8_t vector(uint8x8_t a, uint8x8_t b) { return __nds__v_ukadd8(a, b); }
  66. inline uchar scalar(uchar a, uchar b) { return __nds__ukadd8(a, b); }
  67. inline int8x8_t vector(int8x8_t a, int8x8_t b) { return __nds__v_kadd8(a, b); }
  68. inline schar scalar(schar a, schar b) { return __nds__kadd8(a, b); }
  69. inline uint16x4_t vector(uint16x4_t a, uint16x4_t b) { return __nds__v_ukadd16(a, b); }
  70. inline ushort scalar(ushort a, ushort b) { return __nds__ukadd16(a, b); }
  71. inline int16x4_t vector(int16x4_t a, int16x4_t b) { return __nds__v_kadd16(a, b); }
  72. inline short scalar(short a, short b) { return __nds__kadd16(a, b); }
  73. inline int32x2_t vector(int32x2_t a, int32x2_t b) { return __nds__v_kadd32(a, b); }
  74. inline int scalar(int a, int b) { return __nds__kadd32(a, b); }
  75. };
  76. #undef cv_hal_add8u
  77. #define cv_hal_add8u (cv::ndsrvp::elemwise_binop<uchar, uchar, uint8x8_t, uint8x8_t, 8, cv::ndsrvp::operators_add_t>)
  78. #undef cv_hal_add8s
  79. #define cv_hal_add8s (cv::ndsrvp::elemwise_binop<schar, schar, int8x8_t, int8x8_t, 8, cv::ndsrvp::operators_add_t>)
  80. #undef cv_hal_add16u
  81. #define cv_hal_add16u (cv::ndsrvp::elemwise_binop<ushort, ushort, uint16x4_t, uint16x4_t, 4, cv::ndsrvp::operators_add_t>)
  82. #undef cv_hal_add16s
  83. #define cv_hal_add16s (cv::ndsrvp::elemwise_binop<short, short, int16x4_t, int16x4_t, 4, cv::ndsrvp::operators_add_t>)
  84. #undef cv_hal_add32s
  85. #define cv_hal_add32s (cv::ndsrvp::elemwise_binop<int, int, int32x2_t, int32x2_t, 2, cv::ndsrvp::operators_add_t>)
  86. // ################ sub ################
  87. template <typename src, typename dst>
  88. struct operators_sub_t {
  89. inline uint8x8_t vector(uint8x8_t a, uint8x8_t b) { return __nds__v_uksub8(a, b); }
  90. inline uchar scalar(uchar a, uchar b) { return __nds__uksub8(a, b); }
  91. inline int8x8_t vector(int8x8_t a, int8x8_t b) { return __nds__v_ksub8(a, b); }
  92. inline schar scalar(schar a, schar b) { return __nds__ksub8(a, b); }
  93. inline uint16x4_t vector(uint16x4_t a, uint16x4_t b) { return __nds__v_uksub16(a, b); }
  94. inline ushort scalar(ushort a, ushort b) { return __nds__uksub16(a, b); }
  95. inline int16x4_t vector(int16x4_t a, int16x4_t b) { return __nds__v_ksub16(a, b); }
  96. inline short scalar(short a, short b) { return __nds__ksub16(a, b); }
  97. inline int32x2_t vector(int32x2_t a, int32x2_t b) { return __nds__v_ksub32(a, b); }
  98. inline int scalar(int a, int b) { return __nds__ksub32(a, b); }
  99. };
  100. #undef cv_hal_sub8u
  101. #define cv_hal_sub8u (cv::ndsrvp::elemwise_binop<uchar, uchar, uint8x8_t, uint8x8_t, 8, cv::ndsrvp::operators_sub_t>)
  102. #undef cv_hal_sub8s
  103. #define cv_hal_sub8s (cv::ndsrvp::elemwise_binop<schar, schar, int8x8_t, int8x8_t, 8, cv::ndsrvp::operators_sub_t>)
  104. #undef cv_hal_sub16u
  105. #define cv_hal_sub16u (cv::ndsrvp::elemwise_binop<ushort, ushort, uint16x4_t, uint16x4_t, 4, cv::ndsrvp::operators_sub_t>)
  106. #undef cv_hal_sub16s
  107. #define cv_hal_sub16s (cv::ndsrvp::elemwise_binop<short, short, int16x4_t, int16x4_t, 4, cv::ndsrvp::operators_sub_t>)
  108. #undef cv_hal_sub32s
  109. #define cv_hal_sub32s (cv::ndsrvp::elemwise_binop<int, int, int32x2_t, int32x2_t, 2, cv::ndsrvp::operators_sub_t>)
  110. // ################ max ################
  111. template <typename src, typename dst>
  112. struct operators_max_t {
  113. inline uint8x8_t vector(uint8x8_t a, uint8x8_t b) { return __nds__v_umax8(a, b); }
  114. inline uchar scalar(uchar a, uchar b) { return __nds__umax8(a, b); }
  115. inline int8x8_t vector(int8x8_t a, int8x8_t b) { return __nds__v_smax8(a, b); }
  116. inline schar scalar(schar a, schar b) { return __nds__smax8(a, b); }
  117. inline uint16x4_t vector(uint16x4_t a, uint16x4_t b) { return __nds__v_umax16(a, b); }
  118. inline ushort scalar(ushort a, ushort b) { return __nds__umax16(a, b); }
  119. inline int16x4_t vector(int16x4_t a, int16x4_t b) { return __nds__v_smax16(a, b); }
  120. inline short scalar(short a, short b) { return __nds__smax16(a, b); }
  121. inline int32x2_t vector(int32x2_t a, int32x2_t b) { return __nds__v_smax32(a, b); }
  122. inline int scalar(int a, int b) { return __nds__smax32(a, b); }
  123. };
  124. #undef cv_hal_max8u
  125. #define cv_hal_max8u (cv::ndsrvp::elemwise_binop<uchar, uchar, uint8x8_t, uint8x8_t, 8, cv::ndsrvp::operators_max_t>)
  126. #undef cv_hal_max8s
  127. #define cv_hal_max8s (cv::ndsrvp::elemwise_binop<schar, schar, int8x8_t, int8x8_t, 8, cv::ndsrvp::operators_max_t>)
  128. #undef cv_hal_max16u
  129. #define cv_hal_max16u (cv::ndsrvp::elemwise_binop<ushort, ushort, uint16x4_t, uint16x4_t, 4, cv::ndsrvp::operators_max_t>)
  130. #undef cv_hal_max16s
  131. #define cv_hal_max16s (cv::ndsrvp::elemwise_binop<short, short, int16x4_t, int16x4_t, 4, cv::ndsrvp::operators_max_t>)
  132. #undef cv_hal_max32s
  133. #define cv_hal_max32s (cv::ndsrvp::elemwise_binop<int, int, int32x2_t, int32x2_t, 2, cv::ndsrvp::operators_max_t>)
  134. // ################ min ################
  135. template <typename src, typename dst>
  136. struct operators_min_t {
  137. inline uint8x8_t vector(uint8x8_t a, uint8x8_t b) { return __nds__v_umin8(a, b); }
  138. inline uchar scalar(uchar a, uchar b) { return __nds__umin8(a, b); }
  139. inline int8x8_t vector(int8x8_t a, int8x8_t b) { return __nds__v_smin8(a, b); }
  140. inline schar scalar(schar a, schar b) { return __nds__smin8(a, b); }
  141. inline uint16x4_t vector(uint16x4_t a, uint16x4_t b) { return __nds__v_umin16(a, b); }
  142. inline ushort scalar(ushort a, ushort b) { return __nds__umin16(a, b); }
  143. inline int16x4_t vector(int16x4_t a, int16x4_t b) { return __nds__v_smin16(a, b); }
  144. inline short scalar(short a, short b) { return __nds__smin16(a, b); }
  145. inline int32x2_t vector(int32x2_t a, int32x2_t b) { return __nds__v_smin32(a, b); }
  146. inline int scalar(int a, int b) { return __nds__smin32(a, b); }
  147. };
  148. #undef cv_hal_min8u
  149. #define cv_hal_min8u (cv::ndsrvp::elemwise_binop<uchar, uchar, uint8x8_t, uint8x8_t, 8, cv::ndsrvp::operators_min_t>)
  150. #undef cv_hal_min8s
  151. #define cv_hal_min8s (cv::ndsrvp::elemwise_binop<schar, schar, int8x8_t, int8x8_t, 8, cv::ndsrvp::operators_min_t>)
  152. #undef cv_hal_min16u
  153. #define cv_hal_min16u (cv::ndsrvp::elemwise_binop<ushort, ushort, uint16x4_t, uint16x4_t, 4, cv::ndsrvp::operators_min_t>)
  154. #undef cv_hal_min16s
  155. #define cv_hal_min16s (cv::ndsrvp::elemwise_binop<short, short, int16x4_t, int16x4_t, 4, cv::ndsrvp::operators_min_t>)
  156. #undef cv_hal_min32s
  157. #define cv_hal_min32s (cv::ndsrvp::elemwise_binop<int, int, int32x2_t, int32x2_t, 2, cv::ndsrvp::operators_min_t>)
  158. // ################ absdiff ################
  159. template <typename src, typename dst>
  160. struct operators_absdiff_t {
  161. inline uint8x8_t vector(uint8x8_t a, uint8x8_t b) { return __nds__v_uksub8(__nds__v_umax8(a, b), __nds__v_umin8(a, b)); }
  162. inline uchar scalar(uchar a, uchar b) { return __nds__uksub8(__nds__umax8(a, b), __nds__umin8(a, b)); }
  163. inline int8x8_t vector(int8x8_t a, int8x8_t b) { return __nds__v_ksub8(__nds__v_smax8(a, b), __nds__v_smin8(a, b)); }
  164. inline schar scalar(schar a, schar b) { return __nds__ksub8(__nds__smax8(a, b), __nds__smin8(a, b)); }
  165. inline uint16x4_t vector(uint16x4_t a, uint16x4_t b) { return __nds__v_uksub16(__nds__v_umax16(a, b), __nds__v_umin16(a, b)); }
  166. inline ushort scalar(ushort a, ushort b) { return __nds__uksub16(__nds__umax16(a, b), __nds__umin16(a, b)); }
  167. inline int16x4_t vector(int16x4_t a, int16x4_t b) { return __nds__v_ksub16(__nds__v_smax16(a, b), __nds__v_smin16(a, b)); }
  168. inline short scalar(short a, short b) { return __nds__ksub16(__nds__smax16(a, b), __nds__smin16(a, b)); }
  169. inline int32x2_t vector(int32x2_t a, int32x2_t b) { return __nds__v_ksub32(__nds__v_smax32(a, b), __nds__v_smin32(a, b)); }
  170. inline int scalar(int a, int b) { return __nds__ksub32(__nds__smax32(a, b), __nds__smin32(a, b)); }
  171. };
  172. #undef cv_hal_absdiff8u
  173. #define cv_hal_absdiff8u (cv::ndsrvp::elemwise_binop<uchar, uchar, uint8x8_t, uint8x8_t, 8, cv::ndsrvp::operators_absdiff_t>)
  174. #undef cv_hal_absdiff8s
  175. #define cv_hal_absdiff8s (cv::ndsrvp::elemwise_binop<schar, schar, int8x8_t, int8x8_t, 8, cv::ndsrvp::operators_absdiff_t>)
  176. #undef cv_hal_absdiff16u
  177. #define cv_hal_absdiff16u (cv::ndsrvp::elemwise_binop<ushort, ushort, uint16x4_t, uint16x4_t, 4, cv::ndsrvp::operators_absdiff_t>)
  178. #undef cv_hal_absdiff16s
  179. #define cv_hal_absdiff16s (cv::ndsrvp::elemwise_binop<short, short, int16x4_t, int16x4_t, 4, cv::ndsrvp::operators_absdiff_t>)
  180. #undef cv_hal_absdiff32s
  181. #define cv_hal_absdiff32s (cv::ndsrvp::elemwise_binop<int, int, int32x2_t, int32x2_t, 2, cv::ndsrvp::operators_absdiff_t>)
  182. // ################ bitwise ################
  183. template <typename src, typename dst>
  184. struct operators_and_t {
  185. inline uint8x8_t vector(uint8x8_t a, uint8x8_t b) { return a & b; }
  186. inline uchar scalar(uchar a, uchar b) { return a & b; }
  187. };
  188. #undef cv_hal_and8u
  189. #define cv_hal_and8u (cv::ndsrvp::elemwise_binop<uchar, uchar, uint8x8_t, uint8x8_t, 8, cv::ndsrvp::operators_and_t>)
  190. template <typename src, typename dst>
  191. struct operators_or_t {
  192. inline uint8x8_t vector(uint8x8_t a, uint8x8_t b) { return a | b; }
  193. inline uchar scalar(uchar a, uchar b) { return a | b; }
  194. };
  195. #undef cv_hal_or8u
  196. #define cv_hal_or8u (cv::ndsrvp::elemwise_binop<uchar, uchar, uint8x8_t, uint8x8_t, 8, cv::ndsrvp::operators_or_t>)
  197. template <typename src, typename dst>
  198. struct operators_xor_t {
  199. inline uint8x8_t vector(uint8x8_t a, uint8x8_t b) { return a ^ b; }
  200. inline uchar scalar(uchar a, uchar b) { return a ^ b; }
  201. };
  202. #undef cv_hal_xor8u
  203. #define cv_hal_xor8u (cv::ndsrvp::elemwise_binop<uchar, uchar, uint8x8_t, uint8x8_t, 8, cv::ndsrvp::operators_xor_t>)
  204. template <typename src, typename dst>
  205. struct operators_not_t {
  206. inline uint8x8_t vector(uint8x8_t a) { return ~a; }
  207. inline uchar scalar(uchar a) { return ~a; }
  208. };
  209. #undef cv_hal_not8u
  210. #define cv_hal_not8u (cv::ndsrvp::elemwise_unop<uchar, uchar, uint8x8_t, uint8x8_t, 8, cv::ndsrvp::operators_not_t>)
  211. // ################ cmp ################
  212. template <typename src, typename dst>
  213. struct operators_cmp_t {
  214. inline uint8x8_t vector(uint8x8_t a, uint8x8_t b, int operation)
  215. {
  216. switch (operation) {
  217. case CV_HAL_CMP_EQ:
  218. return __nds__v_ucmpeq8(a, b);
  219. case CV_HAL_CMP_GT:
  220. return __nds__v_ucmplt8(b, a);
  221. case CV_HAL_CMP_GE:
  222. return __nds__v_ucmple8(b, a);
  223. case CV_HAL_CMP_LT:
  224. return __nds__v_ucmplt8(a, b);
  225. case CV_HAL_CMP_LE:
  226. return __nds__v_ucmple8(a, b);
  227. case CV_HAL_CMP_NE:
  228. return ~__nds__v_ucmpeq8(a, b);
  229. default:
  230. return uint8x8_t();
  231. }
  232. }
  233. inline uchar scalar(uchar a, uchar b, int operation)
  234. {
  235. switch (operation) {
  236. case CV_HAL_CMP_EQ:
  237. return __nds__cmpeq8(a, b);
  238. case CV_HAL_CMP_GT:
  239. return __nds__ucmplt8(b, a);
  240. case CV_HAL_CMP_GE:
  241. return __nds__ucmple8(b, a);
  242. case CV_HAL_CMP_LT:
  243. return __nds__ucmplt8(a, b);
  244. case CV_HAL_CMP_LE:
  245. return __nds__ucmple8(a, b);
  246. case CV_HAL_CMP_NE:
  247. return ~__nds__cmpeq8(a, b);
  248. default:
  249. return 0;
  250. }
  251. }
  252. inline uint8x8_t vector(int8x8_t a, int8x8_t b, int operation)
  253. {
  254. switch (operation) {
  255. case CV_HAL_CMP_EQ:
  256. return __nds__v_scmpeq8(a, b);
  257. case CV_HAL_CMP_GT:
  258. return __nds__v_scmplt8(b, a);
  259. case CV_HAL_CMP_GE:
  260. return __nds__v_scmple8(b, a);
  261. case CV_HAL_CMP_LT:
  262. return __nds__v_scmplt8(a, b);
  263. case CV_HAL_CMP_LE:
  264. return __nds__v_scmple8(a, b);
  265. case CV_HAL_CMP_NE:
  266. return ~__nds__v_scmpeq8(a, b);
  267. default:
  268. return uint8x8_t();
  269. }
  270. }
  271. inline uchar scalar(schar a, schar b, int operation)
  272. {
  273. switch (operation) {
  274. case CV_HAL_CMP_EQ:
  275. return __nds__cmpeq8(a, b);
  276. case CV_HAL_CMP_GT:
  277. return __nds__scmplt8(b, a);
  278. case CV_HAL_CMP_GE:
  279. return __nds__scmple8(b, a);
  280. case CV_HAL_CMP_LT:
  281. return __nds__scmplt8(a, b);
  282. case CV_HAL_CMP_LE:
  283. return __nds__scmple8(a, b);
  284. case CV_HAL_CMP_NE:
  285. return ~__nds__cmpeq8(a, b);
  286. default:
  287. return 0;
  288. }
  289. }
  290. inline uint8x4_t vector(uint16x4_t a, uint16x4_t b, int operation)
  291. {
  292. register unsigned long cmp;
  293. switch (operation) {
  294. case CV_HAL_CMP_EQ:
  295. cmp = (unsigned long)__nds__v_ucmpeq16(a, b) >> 8;
  296. break;
  297. case CV_HAL_CMP_GT:
  298. cmp = (unsigned long)__nds__v_ucmplt16(b, a) >> 8;
  299. break;
  300. case CV_HAL_CMP_GE:
  301. cmp = (unsigned long)__nds__v_ucmple16(b, a) >> 8;
  302. break;
  303. case CV_HAL_CMP_LT:
  304. cmp = (unsigned long)__nds__v_ucmplt16(a, b) >> 8;
  305. break;
  306. case CV_HAL_CMP_LE:
  307. cmp = (unsigned long)__nds__v_ucmple16(a, b) >> 8;
  308. break;
  309. case CV_HAL_CMP_NE:
  310. cmp = ~(unsigned long)__nds__v_ucmpeq16(a, b) >> 8;
  311. break;
  312. default:
  313. return uint8x4_t();
  314. }
  315. return (uint8x4_t)(unsigned int)__nds__pkbb16(cmp >> 32, cmp);
  316. }
  317. inline uchar scalar(ushort a, ushort b, int operation)
  318. {
  319. switch (operation) {
  320. case CV_HAL_CMP_EQ:
  321. return __nds__cmpeq16(a, b);
  322. case CV_HAL_CMP_GT:
  323. return __nds__ucmplt16(b, a);
  324. case CV_HAL_CMP_GE:
  325. return __nds__ucmple16(b, a);
  326. case CV_HAL_CMP_LT:
  327. return __nds__ucmplt16(a, b);
  328. case CV_HAL_CMP_LE:
  329. return __nds__ucmple16(a, b);
  330. case CV_HAL_CMP_NE:
  331. return ~__nds__cmpeq16(a, b);
  332. default:
  333. return 0;
  334. }
  335. }
  336. inline uint8x4_t vector(int16x4_t a, int16x4_t b, int operation)
  337. {
  338. register unsigned long cmp;
  339. switch (operation) {
  340. case CV_HAL_CMP_EQ:
  341. cmp = (unsigned long)__nds__v_scmpeq16(a, b) >> 8;
  342. break;
  343. case CV_HAL_CMP_GT:
  344. cmp = (unsigned long)__nds__v_scmplt16(b, a) >> 8;
  345. break;
  346. case CV_HAL_CMP_GE:
  347. cmp = (unsigned long)__nds__v_scmple16(b, a) >> 8;
  348. break;
  349. case CV_HAL_CMP_LT:
  350. cmp = (unsigned long)__nds__v_scmplt16(a, b) >> 8;
  351. break;
  352. case CV_HAL_CMP_LE:
  353. cmp = (unsigned long)__nds__v_scmple16(a, b) >> 8;
  354. break;
  355. case CV_HAL_CMP_NE:
  356. cmp = ~(unsigned long)__nds__v_scmpeq16(a, b) >> 8;
  357. break;
  358. default:
  359. return uint8x4_t();
  360. }
  361. return (uint8x4_t)(unsigned int)__nds__pkbb16(cmp >> 32, cmp);
  362. }
  363. inline uchar scalar(short a, short b, int operation)
  364. {
  365. switch (operation) {
  366. case CV_HAL_CMP_EQ:
  367. return __nds__cmpeq16(a, b);
  368. case CV_HAL_CMP_GT:
  369. return __nds__scmplt16(b, a);
  370. case CV_HAL_CMP_GE:
  371. return __nds__scmple16(b, a);
  372. case CV_HAL_CMP_LT:
  373. return __nds__scmplt16(a, b);
  374. case CV_HAL_CMP_LE:
  375. return __nds__scmple16(a, b);
  376. case CV_HAL_CMP_NE:
  377. return ~__nds__cmpeq16(a, b);
  378. default:
  379. return 0;
  380. }
  381. }
  382. };
  383. #undef cv_hal_cmp8u
  384. #define cv_hal_cmp8u (cv::ndsrvp::elemwise_binop<uchar, uchar, uint8x8_t, uint8x8_t, 8, cv::ndsrvp::operators_cmp_t>)
  385. #undef cv_hal_cmp8s
  386. #define cv_hal_cmp8s (cv::ndsrvp::elemwise_binop<schar, uchar, int8x8_t, uint8x8_t, 8, cv::ndsrvp::operators_cmp_t>)
  387. #undef cv_hal_cmp16u
  388. #define cv_hal_cmp16u (cv::ndsrvp::elemwise_binop<ushort, uchar, uint16x4_t, uint8x4_t, 4, cv::ndsrvp::operators_cmp_t>)
  389. #undef cv_hal_cmp16s
  390. #define cv_hal_cmp16s (cv::ndsrvp::elemwise_binop<short, uchar, int16x4_t, uint8x4_t, 4, cv::ndsrvp::operators_cmp_t>)
  391. // ################ split ################
  392. /*template <typename srctype, typename vsrctype, int nlane>
  393. int split(const srctype* src_data, srctype** dst_data, int len, int cn)
  394. {
  395. int i, j;
  396. for (i = 0; i < len; i++) {
  397. for (j = 0; j < cn; j++) {
  398. dst_data[j][i] = src_data[i * cn + j];
  399. }
  400. }
  401. return CV_HAL_ERROR_OK;
  402. }
  403. #undef cv_hal_split8u
  404. #define cv_hal_split8u (cv::ndsrvp::split<uchar, uint8x8_t, 8>)
  405. #undef cv_hal_split16u
  406. #define cv_hal_split16u (cv::ndsrvp::split<ushort, uint16x4_t, 4>)
  407. #undef cv_hal_split32s
  408. #define cv_hal_split32s (cv::ndsrvp::split<int, int32x2_t, 2>)*/
  409. // ################ merge ################
  410. /*template <typename srctype, typename vsrctype, int nlane>
  411. int merge(const srctype** src_data, srctype* dst_data, int len, int cn)
  412. {
  413. int i, j;
  414. for (i = 0; i < len; i++) {
  415. for (j = 0; j < cn; j++) {
  416. dst_data[i * cn + j] = src_data[j][i];
  417. }
  418. }
  419. return CV_HAL_ERROR_OK;
  420. }
  421. #undef cv_hal_merge8u
  422. #define cv_hal_merge8u (cv::ndsrvp::merge<uchar, uint8x8_t, 8>)
  423. #undef cv_hal_merge16u
  424. #define cv_hal_merge16u (cv::ndsrvp::merge<ushort, uint16x4_t, 4>)
  425. #undef cv_hal_merge32s
  426. #define cv_hal_merge32s (cv::ndsrvp::merge<int, int32x2_t, 2>)*/
  427. } // namespace ndsrvp
  428. } // namespace cv
  429. #endif