You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2872 lines
142KB

  1. /*
  2. * Copyright (c) 2015 Manojkumar Bhosale (Manojkumar.Bhosale@imgtec.com)
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVUTIL_MIPS_GENERIC_MACROS_MSA_H
  21. #define AVUTIL_MIPS_GENERIC_MACROS_MSA_H
  22. #include <stdint.h>
  23. #include <msa.h>
  24. #include <config.h>
  25. #if HAVE_MSA2
  26. #include <msa2.h>
  27. #endif
  28. #define ALIGNMENT 16
  29. #define ALLOC_ALIGNED(align) __attribute__ ((aligned((align) << 1)))
  30. #define LD_V(RTYPE, psrc) *((RTYPE *)(psrc))
  31. #define LD_UB(...) LD_V(v16u8, __VA_ARGS__)
  32. #define LD_SB(...) LD_V(v16i8, __VA_ARGS__)
  33. #define LD_UH(...) LD_V(v8u16, __VA_ARGS__)
  34. #define LD_SH(...) LD_V(v8i16, __VA_ARGS__)
  35. #define LD_UW(...) LD_V(v4u32, __VA_ARGS__)
  36. #define LD_SW(...) LD_V(v4i32, __VA_ARGS__)
  37. #define ST_V(RTYPE, in, pdst) *((RTYPE *)(pdst)) = (in)
  38. #define ST_UB(...) ST_V(v16u8, __VA_ARGS__)
  39. #define ST_SB(...) ST_V(v16i8, __VA_ARGS__)
  40. #define ST_UH(...) ST_V(v8u16, __VA_ARGS__)
  41. #define ST_SH(...) ST_V(v8i16, __VA_ARGS__)
  42. #define ST_UW(...) ST_V(v4u32, __VA_ARGS__)
  43. #define ST_SW(...) ST_V(v4i32, __VA_ARGS__)
  44. #if (__mips_isa_rev >= 6)
  45. #define LH(psrc) \
  46. ( { \
  47. uint16_t val_lh_m = *(uint16_t *)(psrc); \
  48. val_lh_m; \
  49. } )
  50. #define LW(psrc) \
  51. ( { \
  52. uint32_t val_lw_m = *(uint32_t *)(psrc); \
  53. val_lw_m; \
  54. } )
  55. #if (__mips == 64)
  56. #define LD(psrc) \
  57. ( { \
  58. uint64_t val_ld_m = *(uint64_t *)(psrc); \
  59. val_ld_m; \
  60. } )
  61. #else // !(__mips == 64)
  62. #define LD(psrc) \
  63. ( { \
  64. uint8_t *psrc_ld_m = (uint8_t *) (psrc); \
  65. uint32_t val0_ld_m, val1_ld_m; \
  66. uint64_t val_ld_m = 0; \
  67. \
  68. val0_ld_m = LW(psrc_ld_m); \
  69. val1_ld_m = LW(psrc_ld_m + 4); \
  70. \
  71. val_ld_m = (uint64_t) (val1_ld_m); \
  72. val_ld_m = (uint64_t) ((val_ld_m << 32) & 0xFFFFFFFF00000000); \
  73. val_ld_m = (uint64_t) (val_ld_m | (uint64_t) val0_ld_m); \
  74. \
  75. val_ld_m; \
  76. } )
  77. #endif // (__mips == 64)
  78. #define SH(val, pdst) *(uint16_t *)(pdst) = (val);
  79. #define SW(val, pdst) *(uint32_t *)(pdst) = (val);
  80. #define SD(val, pdst) *(uint64_t *)(pdst) = (val);
  81. #else // !(__mips_isa_rev >= 6)
  82. #define LH(psrc) \
  83. ( { \
  84. uint8_t *psrc_lh_m = (uint8_t *) (psrc); \
  85. uint16_t val_lh_m; \
  86. \
  87. __asm__ volatile ( \
  88. "ulh %[val_lh_m], %[psrc_lh_m] \n\t" \
  89. \
  90. : [val_lh_m] "=r" (val_lh_m) \
  91. : [psrc_lh_m] "m" (*psrc_lh_m) \
  92. ); \
  93. \
  94. val_lh_m; \
  95. } )
  96. #define LW(psrc) \
  97. ( { \
  98. uint8_t *psrc_lw_m = (uint8_t *) (psrc); \
  99. uint32_t val_lw_m; \
  100. \
  101. __asm__ volatile ( \
  102. "ulw %[val_lw_m], %[psrc_lw_m] \n\t" \
  103. \
  104. : [val_lw_m] "=r" (val_lw_m) \
  105. : [psrc_lw_m] "m" (*psrc_lw_m) \
  106. ); \
  107. \
  108. val_lw_m; \
  109. } )
  110. #if (__mips == 64)
  111. #define LD(psrc) \
  112. ( { \
  113. uint8_t *psrc_ld_m = (uint8_t *) (psrc); \
  114. uint64_t val_ld_m = 0; \
  115. \
  116. __asm__ volatile ( \
  117. "uld %[val_ld_m], %[psrc_ld_m] \n\t" \
  118. \
  119. : [val_ld_m] "=r" (val_ld_m) \
  120. : [psrc_ld_m] "m" (*psrc_ld_m) \
  121. ); \
  122. \
  123. val_ld_m; \
  124. } )
  125. #else // !(__mips == 64)
  126. #define LD(psrc) \
  127. ( { \
  128. uint8_t *psrc_ld_m = (uint8_t *) (psrc); \
  129. uint32_t val0_ld_m, val1_ld_m; \
  130. uint64_t val_ld_m = 0; \
  131. \
  132. val0_ld_m = LW(psrc_ld_m); \
  133. val1_ld_m = LW(psrc_ld_m + 4); \
  134. \
  135. val_ld_m = (uint64_t) (val1_ld_m); \
  136. val_ld_m = (uint64_t) ((val_ld_m << 32) & 0xFFFFFFFF00000000); \
  137. val_ld_m = (uint64_t) (val_ld_m | (uint64_t) val0_ld_m); \
  138. \
  139. val_ld_m; \
  140. } )
  141. #endif // (__mips == 64)
  142. #define SH(val, pdst) \
  143. { \
  144. uint8_t *pdst_sh_m = (uint8_t *) (pdst); \
  145. uint16_t val_sh_m = (val); \
  146. \
  147. __asm__ volatile ( \
  148. "ush %[val_sh_m], %[pdst_sh_m] \n\t" \
  149. \
  150. : [pdst_sh_m] "=m" (*pdst_sh_m) \
  151. : [val_sh_m] "r" (val_sh_m) \
  152. ); \
  153. }
  154. #define SW(val, pdst) \
  155. { \
  156. uint8_t *pdst_sw_m = (uint8_t *) (pdst); \
  157. uint32_t val_sw_m = (val); \
  158. \
  159. __asm__ volatile ( \
  160. "usw %[val_sw_m], %[pdst_sw_m] \n\t" \
  161. \
  162. : [pdst_sw_m] "=m" (*pdst_sw_m) \
  163. : [val_sw_m] "r" (val_sw_m) \
  164. ); \
  165. }
  166. #define SD(val, pdst) \
  167. { \
  168. uint8_t *pdst_sd_m = (uint8_t *) (pdst); \
  169. uint32_t val0_sd_m, val1_sd_m; \
  170. \
  171. val0_sd_m = (uint32_t) ((val) & 0x00000000FFFFFFFF); \
  172. val1_sd_m = (uint32_t) (((val) >> 32) & 0x00000000FFFFFFFF); \
  173. \
  174. SW(val0_sd_m, pdst_sd_m); \
  175. SW(val1_sd_m, pdst_sd_m + 4); \
  176. }
  177. #endif // (__mips_isa_rev >= 6)
  178. /* Description : Load 4 words with stride
  179. Arguments : Inputs - psrc (source pointer to load from)
  180. - stride
  181. Outputs - out0, out1, out2, out3
  182. Details : Loads word in 'out0' from (psrc)
  183. Loads word in 'out1' from (psrc + stride)
  184. Loads word in 'out2' from (psrc + 2 * stride)
  185. Loads word in 'out3' from (psrc + 3 * stride)
  186. */
  187. #define LW4(psrc, stride, out0, out1, out2, out3) \
  188. { \
  189. out0 = LW((psrc)); \
  190. out1 = LW((psrc) + stride); \
  191. out2 = LW((psrc) + 2 * stride); \
  192. out3 = LW((psrc) + 3 * stride); \
  193. }
  194. #define LW2(psrc, stride, out0, out1) \
  195. { \
  196. out0 = LW((psrc)); \
  197. out1 = LW((psrc) + stride); \
  198. }
  199. /* Description : Load double words with stride
  200. Arguments : Inputs - psrc (source pointer to load from)
  201. - stride
  202. Outputs - out0, out1
  203. Details : Loads double word in 'out0' from (psrc)
  204. Loads double word in 'out1' from (psrc + stride)
  205. */
  206. #define LD2(psrc, stride, out0, out1) \
  207. { \
  208. out0 = LD((psrc)); \
  209. out1 = LD((psrc) + stride); \
  210. }
  211. #define LD4(psrc, stride, out0, out1, out2, out3) \
  212. { \
  213. LD2((psrc), stride, out0, out1); \
  214. LD2((psrc) + 2 * stride, stride, out2, out3); \
  215. }
  216. /* Description : Store 4 words with stride
  217. Arguments : Inputs - in0, in1, in2, in3, pdst, stride
  218. Details : Stores word from 'in0' to (pdst)
  219. Stores word from 'in1' to (pdst + stride)
  220. Stores word from 'in2' to (pdst + 2 * stride)
  221. Stores word from 'in3' to (pdst + 3 * stride)
  222. */
  223. #define SW4(in0, in1, in2, in3, pdst, stride) \
  224. { \
  225. SW(in0, (pdst)) \
  226. SW(in1, (pdst) + stride); \
  227. SW(in2, (pdst) + 2 * stride); \
  228. SW(in3, (pdst) + 3 * stride); \
  229. }
  230. /* Description : Store 4 double words with stride
  231. Arguments : Inputs - in0, in1, in2, in3, pdst, stride
  232. Details : Stores double word from 'in0' to (pdst)
  233. Stores double word from 'in1' to (pdst + stride)
  234. Stores double word from 'in2' to (pdst + 2 * stride)
  235. Stores double word from 'in3' to (pdst + 3 * stride)
  236. */
  237. #define SD4(in0, in1, in2, in3, pdst, stride) \
  238. { \
  239. SD(in0, (pdst)) \
  240. SD(in1, (pdst) + stride); \
  241. SD(in2, (pdst) + 2 * stride); \
  242. SD(in3, (pdst) + 3 * stride); \
  243. }
  244. /* Description : Load vector elements with stride
  245. Arguments : Inputs - psrc (source pointer to load from)
  246. - stride
  247. Outputs - out0, out1
  248. Return Type - as per RTYPE
  249. Details : Loads elements in 'out0' from (psrc)
  250. Loads elements in 'out1' from (psrc + stride)
  251. */
  252. #define LD_V2(RTYPE, psrc, stride, out0, out1) \
  253. { \
  254. out0 = LD_V(RTYPE, (psrc)); \
  255. out1 = LD_V(RTYPE, (psrc) + stride); \
  256. }
  257. #define LD_UB2(...) LD_V2(v16u8, __VA_ARGS__)
  258. #define LD_SB2(...) LD_V2(v16i8, __VA_ARGS__)
  259. #define LD_UH2(...) LD_V2(v8u16, __VA_ARGS__)
  260. #define LD_SH2(...) LD_V2(v8i16, __VA_ARGS__)
  261. #define LD_SW2(...) LD_V2(v4i32, __VA_ARGS__)
  262. #define LD_V3(RTYPE, psrc, stride, out0, out1, out2) \
  263. { \
  264. LD_V2(RTYPE, (psrc), stride, out0, out1); \
  265. out2 = LD_V(RTYPE, (psrc) + 2 * stride); \
  266. }
  267. #define LD_UB3(...) LD_V3(v16u8, __VA_ARGS__)
  268. #define LD_SB3(...) LD_V3(v16i8, __VA_ARGS__)
  269. #define LD_V4(RTYPE, psrc, stride, out0, out1, out2, out3) \
  270. { \
  271. LD_V2(RTYPE, (psrc), stride, out0, out1); \
  272. LD_V2(RTYPE, (psrc) + 2 * stride , stride, out2, out3); \
  273. }
  274. #define LD_UB4(...) LD_V4(v16u8, __VA_ARGS__)
  275. #define LD_SB4(...) LD_V4(v16i8, __VA_ARGS__)
  276. #define LD_UH4(...) LD_V4(v8u16, __VA_ARGS__)
  277. #define LD_SH4(...) LD_V4(v8i16, __VA_ARGS__)
  278. #define LD_V5(RTYPE, psrc, stride, out0, out1, out2, out3, out4) \
  279. { \
  280. LD_V4(RTYPE, (psrc), stride, out0, out1, out2, out3); \
  281. out4 = LD_V(RTYPE, (psrc) + 4 * stride); \
  282. }
  283. #define LD_UB5(...) LD_V5(v16u8, __VA_ARGS__)
  284. #define LD_SB5(...) LD_V5(v16i8, __VA_ARGS__)
  285. #define LD_V6(RTYPE, psrc, stride, out0, out1, out2, out3, out4, out5) \
  286. { \
  287. LD_V4(RTYPE, (psrc), stride, out0, out1, out2, out3); \
  288. LD_V2(RTYPE, (psrc) + 4 * stride, stride, out4, out5); \
  289. }
  290. #define LD_UB6(...) LD_V6(v16u8, __VA_ARGS__)
  291. #define LD_SB6(...) LD_V6(v16i8, __VA_ARGS__)
  292. #define LD_UH6(...) LD_V6(v8u16, __VA_ARGS__)
  293. #define LD_SH6(...) LD_V6(v8i16, __VA_ARGS__)
  294. #define LD_V7(RTYPE, psrc, stride, \
  295. out0, out1, out2, out3, out4, out5, out6) \
  296. { \
  297. LD_V5(RTYPE, (psrc), stride, out0, out1, out2, out3, out4); \
  298. LD_V2(RTYPE, (psrc) + 5 * stride, stride, out5, out6); \
  299. }
  300. #define LD_UB7(...) LD_V7(v16u8, __VA_ARGS__)
  301. #define LD_SB7(...) LD_V7(v16i8, __VA_ARGS__)
  302. #define LD_V8(RTYPE, psrc, stride, \
  303. out0, out1, out2, out3, out4, out5, out6, out7) \
  304. { \
  305. LD_V4(RTYPE, (psrc), stride, out0, out1, out2, out3); \
  306. LD_V4(RTYPE, (psrc) + 4 * stride, stride, out4, out5, out6, out7); \
  307. }
  308. #define LD_UB8(...) LD_V8(v16u8, __VA_ARGS__)
  309. #define LD_SB8(...) LD_V8(v16i8, __VA_ARGS__)
  310. #define LD_UH8(...) LD_V8(v8u16, __VA_ARGS__)
  311. #define LD_SH8(...) LD_V8(v8i16, __VA_ARGS__)
  312. #define LD_V16(RTYPE, psrc, stride, \
  313. out0, out1, out2, out3, out4, out5, out6, out7, \
  314. out8, out9, out10, out11, out12, out13, out14, out15) \
  315. { \
  316. LD_V8(RTYPE, (psrc), stride, \
  317. out0, out1, out2, out3, out4, out5, out6, out7); \
  318. LD_V8(RTYPE, (psrc) + 8 * stride, stride, \
  319. out8, out9, out10, out11, out12, out13, out14, out15); \
  320. }
  321. #define LD_SH16(...) LD_V16(v8i16, __VA_ARGS__)
  322. /* Description : Store vectors with stride
  323. Arguments : Inputs - in0, in1, stride
  324. Outputs - pdst (destination pointer to store to)
  325. Details : Stores elements from 'in0' to (pdst)
  326. Stores elements from 'in1' to (pdst + stride)
  327. */
  328. #define ST_V2(RTYPE, in0, in1, pdst, stride) \
  329. { \
  330. ST_V(RTYPE, in0, (pdst)); \
  331. ST_V(RTYPE, in1, (pdst) + stride); \
  332. }
  333. #define ST_UB2(...) ST_V2(v16u8, __VA_ARGS__)
  334. #define ST_SB2(...) ST_V2(v16i8, __VA_ARGS__)
  335. #define ST_UH2(...) ST_V2(v8u16, __VA_ARGS__)
  336. #define ST_SH2(...) ST_V2(v8i16, __VA_ARGS__)
  337. #define ST_SW2(...) ST_V2(v4i32, __VA_ARGS__)
  338. #define ST_V4(RTYPE, in0, in1, in2, in3, pdst, stride) \
  339. { \
  340. ST_V2(RTYPE, in0, in1, (pdst), stride); \
  341. ST_V2(RTYPE, in2, in3, (pdst) + 2 * stride, stride); \
  342. }
  343. #define ST_UB4(...) ST_V4(v16u8, __VA_ARGS__)
  344. #define ST_SB4(...) ST_V4(v16i8, __VA_ARGS__)
  345. #define ST_SH4(...) ST_V4(v8i16, __VA_ARGS__)
  346. #define ST_SW4(...) ST_V4(v4i32, __VA_ARGS__)
  347. #define ST_V6(RTYPE, in0, in1, in2, in3, in4, in5, pdst, stride) \
  348. { \
  349. ST_V4(RTYPE, in0, in1, in2, in3, (pdst), stride); \
  350. ST_V2(RTYPE, in4, in5, (pdst) + 4 * stride, stride); \
  351. }
  352. #define ST_SH6(...) ST_V6(v8i16, __VA_ARGS__)
  353. #define ST_V8(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride) \
  354. { \
  355. ST_V4(RTYPE, in0, in1, in2, in3, (pdst), stride); \
  356. ST_V4(RTYPE, in4, in5, in6, in7, (pdst) + 4 * stride, stride); \
  357. }
  358. #define ST_UB8(...) ST_V8(v16u8, __VA_ARGS__)
  359. #define ST_SH8(...) ST_V8(v8i16, __VA_ARGS__)
  360. #define ST_SW8(...) ST_V8(v4i32, __VA_ARGS__)
  361. /* Description : Store half word elements of vector with stride
  362. * Arguments : Inputs - in source vector
  363. * - pdst (destination pointer to store to)
  364. * - stride
  365. * Details : Stores half word 'idx0' from 'in' to (pdst)
  366. * Stores half word 'idx1' from 'in' to (pdst + stride)
  367. * Similar for other elements
  368. */
  369. #define ST_H1(in, idx, pdst) \
  370. { \
  371. uint16_t out0_m; \
  372. out0_m = __msa_copy_u_h((v8i16) in, idx); \
  373. SH(out0_m, (pdst)); \
  374. }
  375. #define ST_H2(in, idx0, idx1, pdst, stride) \
  376. { \
  377. uint16_t out0_m, out1_m; \
  378. out0_m = __msa_copy_u_h((v8i16) in, idx0); \
  379. out1_m = __msa_copy_u_h((v8i16) in, idx1); \
  380. SH(out0_m, (pdst)); \
  381. SH(out1_m, (pdst) + stride); \
  382. }
  383. #define ST_H4(in, idx0, idx1, idx2, idx3, pdst, stride) \
  384. { \
  385. uint16_t out0_m, out1_m, out2_m, out3_m; \
  386. out0_m = __msa_copy_u_h((v8i16) in, idx0); \
  387. out1_m = __msa_copy_u_h((v8i16) in, idx1); \
  388. out2_m = __msa_copy_u_h((v8i16) in, idx2); \
  389. out3_m = __msa_copy_u_h((v8i16) in, idx3); \
  390. SH(out0_m, (pdst)); \
  391. SH(out1_m, (pdst) + stride); \
  392. SH(out2_m, (pdst) + 2 * stride); \
  393. SH(out3_m, (pdst) + 3 * stride); \
  394. }
  395. #define ST_H8(in, idx0, idx1, idx2, idx3, idx4, idx5, \
  396. idx6, idx7, pdst, stride) \
  397. { \
  398. ST_H4(in, idx0, idx1, idx2, idx3, pdst, stride) \
  399. ST_H4(in, idx4, idx5, idx6, idx7, (pdst) + 4*stride, stride) \
  400. }
  401. /* Description : Store word elements of vector with stride
  402. * Arguments : Inputs - in source vector
  403. * - pdst (destination pointer to store to)
  404. * - stride
  405. * Details : Stores word 'idx0' from 'in' to (pdst)
  406. * Stores word 'idx1' from 'in' to (pdst + stride)
  407. * Similar for other elements
  408. */
  409. #define ST_W1(in, idx, pdst) \
  410. { \
  411. uint32_t out0_m; \
  412. out0_m = __msa_copy_u_w((v4i32) in, idx); \
  413. SW(out0_m, (pdst)); \
  414. }
  415. #define ST_W2(in, idx0, idx1, pdst, stride) \
  416. { \
  417. uint32_t out0_m, out1_m; \
  418. out0_m = __msa_copy_u_w((v4i32) in, idx0); \
  419. out1_m = __msa_copy_u_w((v4i32) in, idx1); \
  420. SW(out0_m, (pdst)); \
  421. SW(out1_m, (pdst) + stride); \
  422. }
  423. #define ST_W4(in, idx0, idx1, idx2, idx3, pdst, stride) \
  424. { \
  425. uint32_t out0_m, out1_m, out2_m, out3_m; \
  426. out0_m = __msa_copy_u_w((v4i32) in, idx0); \
  427. out1_m = __msa_copy_u_w((v4i32) in, idx1); \
  428. out2_m = __msa_copy_u_w((v4i32) in, idx2); \
  429. out3_m = __msa_copy_u_w((v4i32) in, idx3); \
  430. SW(out0_m, (pdst)); \
  431. SW(out1_m, (pdst) + stride); \
  432. SW(out2_m, (pdst) + 2*stride); \
  433. SW(out3_m, (pdst) + 3*stride); \
  434. }
  435. #define ST_W8(in0, in1, idx0, idx1, idx2, idx3, \
  436. idx4, idx5, idx6, idx7, pdst, stride) \
  437. { \
  438. ST_W4(in0, idx0, idx1, idx2, idx3, pdst, stride) \
  439. ST_W4(in1, idx4, idx5, idx6, idx7, pdst + 4*stride, stride) \
  440. }
  441. /* Description : Store double word elements of vector with stride
  442. * Arguments : Inputs - in source vector
  443. * - pdst (destination pointer to store to)
  444. * - stride
  445. * Details : Stores double word 'idx0' from 'in' to (pdst)
  446. * Stores double word 'idx1' from 'in' to (pdst + stride)
  447. * Similar for other elements
  448. */
  449. #define ST_D1(in, idx, pdst) \
  450. { \
  451. uint64_t out0_m; \
  452. out0_m = __msa_copy_u_d((v2i64) in, idx); \
  453. SD(out0_m, (pdst)); \
  454. }
  455. #define ST_D2(in, idx0, idx1, pdst, stride) \
  456. { \
  457. uint64_t out0_m, out1_m; \
  458. out0_m = __msa_copy_u_d((v2i64) in, idx0); \
  459. out1_m = __msa_copy_u_d((v2i64) in, idx1); \
  460. SD(out0_m, (pdst)); \
  461. SD(out1_m, (pdst) + stride); \
  462. }
  463. #define ST_D4(in0, in1, idx0, idx1, idx2, idx3, pdst, stride) \
  464. { \
  465. uint64_t out0_m, out1_m, out2_m, out3_m; \
  466. out0_m = __msa_copy_u_d((v2i64) in0, idx0); \
  467. out1_m = __msa_copy_u_d((v2i64) in0, idx1); \
  468. out2_m = __msa_copy_u_d((v2i64) in1, idx2); \
  469. out3_m = __msa_copy_u_d((v2i64) in1, idx3); \
  470. SD(out0_m, (pdst)); \
  471. SD(out1_m, (pdst) + stride); \
  472. SD(out2_m, (pdst) + 2 * stride); \
  473. SD(out3_m, (pdst) + 3 * stride); \
  474. }
  475. #define ST_D8(in0, in1, in2, in3, idx0, idx1, idx2, idx3, \
  476. idx4, idx5, idx6, idx7, pdst, stride) \
  477. { \
  478. ST_D4(in0, in1, idx0, idx1, idx2, idx3, pdst, stride) \
  479. ST_D4(in2, in3, idx4, idx5, idx6, idx7, pdst + 4 * stride, stride) \
  480. }
  481. /* Description : Store as 12x8 byte block to destination memory from
  482. input vectors
  483. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride
  484. Details : Index 0 double word element from input vector 'in0' is copied
  485. and stored to destination memory at (pblk_12x8_m) followed by
  486. index 2 word element from same input vector 'in0' at
  487. (pblk_12x8_m + 8)
  488. Similar to remaining lines
  489. */
  490. #define ST12x8_UB(in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride) \
  491. { \
  492. uint64_t out0_m, out1_m, out2_m, out3_m; \
  493. uint64_t out4_m, out5_m, out6_m, out7_m; \
  494. uint32_t out8_m, out9_m, out10_m, out11_m; \
  495. uint32_t out12_m, out13_m, out14_m, out15_m; \
  496. uint8_t *pblk_12x8_m = (uint8_t *) (pdst); \
  497. \
  498. out0_m = __msa_copy_u_d((v2i64) in0, 0); \
  499. out1_m = __msa_copy_u_d((v2i64) in1, 0); \
  500. out2_m = __msa_copy_u_d((v2i64) in2, 0); \
  501. out3_m = __msa_copy_u_d((v2i64) in3, 0); \
  502. out4_m = __msa_copy_u_d((v2i64) in4, 0); \
  503. out5_m = __msa_copy_u_d((v2i64) in5, 0); \
  504. out6_m = __msa_copy_u_d((v2i64) in6, 0); \
  505. out7_m = __msa_copy_u_d((v2i64) in7, 0); \
  506. \
  507. out8_m = __msa_copy_u_w((v4i32) in0, 2); \
  508. out9_m = __msa_copy_u_w((v4i32) in1, 2); \
  509. out10_m = __msa_copy_u_w((v4i32) in2, 2); \
  510. out11_m = __msa_copy_u_w((v4i32) in3, 2); \
  511. out12_m = __msa_copy_u_w((v4i32) in4, 2); \
  512. out13_m = __msa_copy_u_w((v4i32) in5, 2); \
  513. out14_m = __msa_copy_u_w((v4i32) in6, 2); \
  514. out15_m = __msa_copy_u_w((v4i32) in7, 2); \
  515. \
  516. SD(out0_m, pblk_12x8_m); \
  517. SW(out8_m, pblk_12x8_m + 8); \
  518. pblk_12x8_m += stride; \
  519. SD(out1_m, pblk_12x8_m); \
  520. SW(out9_m, pblk_12x8_m + 8); \
  521. pblk_12x8_m += stride; \
  522. SD(out2_m, pblk_12x8_m); \
  523. SW(out10_m, pblk_12x8_m + 8); \
  524. pblk_12x8_m += stride; \
  525. SD(out3_m, pblk_12x8_m); \
  526. SW(out11_m, pblk_12x8_m + 8); \
  527. pblk_12x8_m += stride; \
  528. SD(out4_m, pblk_12x8_m); \
  529. SW(out12_m, pblk_12x8_m + 8); \
  530. pblk_12x8_m += stride; \
  531. SD(out5_m, pblk_12x8_m); \
  532. SW(out13_m, pblk_12x8_m + 8); \
  533. pblk_12x8_m += stride; \
  534. SD(out6_m, pblk_12x8_m); \
  535. SW(out14_m, pblk_12x8_m + 8); \
  536. pblk_12x8_m += stride; \
  537. SD(out7_m, pblk_12x8_m); \
  538. SW(out15_m, pblk_12x8_m + 8); \
  539. }
  540. /* Description : average with rounding (in0 + in1 + 1) / 2.
  541. Arguments : Inputs - in0, in1, in2, in3,
  542. Outputs - out0, out1
  543. Return Type - as per RTYPE
  544. Details : Each byte element from 'in0' vector is added with each byte
  545. element from 'in1' vector. The addition of the elements plus 1
  546. (for rounding) is done unsigned with full precision,
  547. i.e. the result has one extra bit. Unsigned division by 2
  548. (or logical shift right by one bit) is performed before writing
  549. the result to vector 'out0'
  550. Similar for the pair of 'in2' and 'in3'
  551. */
  552. #define AVER_UB2(RTYPE, in0, in1, in2, in3, out0, out1) \
  553. { \
  554. out0 = (RTYPE) __msa_aver_u_b((v16u8) in0, (v16u8) in1); \
  555. out1 = (RTYPE) __msa_aver_u_b((v16u8) in2, (v16u8) in3); \
  556. }
  557. #define AVER_UB2_UB(...) AVER_UB2(v16u8, __VA_ARGS__)
  558. #define AVER_UB4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  559. out0, out1, out2, out3) \
  560. { \
  561. AVER_UB2(RTYPE, in0, in1, in2, in3, out0, out1) \
  562. AVER_UB2(RTYPE, in4, in5, in6, in7, out2, out3) \
  563. }
  564. #define AVER_UB4_UB(...) AVER_UB4(v16u8, __VA_ARGS__)
  565. /* Description : Immediate number of columns to slide with zero
  566. Arguments : Inputs - in0, in1, slide_val
  567. Outputs - out0, out1
  568. Return Type - as per RTYPE
  569. Details : Byte elements from 'zero_m' vector are slide into 'in0' by
  570. number of elements specified by 'slide_val'
  571. */
  572. #define SLDI_B2_0(RTYPE, in0, in1, out0, out1, slide_val) \
  573. { \
  574. v16i8 zero_m = { 0 }; \
  575. out0 = (RTYPE) __msa_sldi_b((v16i8) zero_m, (v16i8) in0, slide_val); \
  576. out1 = (RTYPE) __msa_sldi_b((v16i8) zero_m, (v16i8) in1, slide_val); \
  577. }
  578. #define SLDI_B2_0_UB(...) SLDI_B2_0(v16u8, __VA_ARGS__)
  579. #define SLDI_B2_0_SB(...) SLDI_B2_0(v16i8, __VA_ARGS__)
  580. #define SLDI_B2_0_SW(...) SLDI_B2_0(v4i32, __VA_ARGS__)
  581. #define SLDI_B3_0(RTYPE, in0, in1, in2, out0, out1, out2, slide_val) \
  582. { \
  583. v16i8 zero_m = { 0 }; \
  584. SLDI_B2_0(RTYPE, in0, in1, out0, out1, slide_val); \
  585. out2 = (RTYPE) __msa_sldi_b((v16i8) zero_m, (v16i8) in2, slide_val); \
  586. }
  587. #define SLDI_B3_0_UB(...) SLDI_B3_0(v16u8, __VA_ARGS__)
  588. #define SLDI_B3_0_SB(...) SLDI_B3_0(v16i8, __VA_ARGS__)
  589. #define SLDI_B4_0(RTYPE, in0, in1, in2, in3, \
  590. out0, out1, out2, out3, slide_val) \
  591. { \
  592. SLDI_B2_0(RTYPE, in0, in1, out0, out1, slide_val); \
  593. SLDI_B2_0(RTYPE, in2, in3, out2, out3, slide_val); \
  594. }
  595. #define SLDI_B4_0_UB(...) SLDI_B4_0(v16u8, __VA_ARGS__)
  596. #define SLDI_B4_0_SB(...) SLDI_B4_0(v16i8, __VA_ARGS__)
  597. #define SLDI_B4_0_SH(...) SLDI_B4_0(v8i16, __VA_ARGS__)
  598. /* Description : Immediate number of columns to slide
  599. Arguments : Inputs - in0_0, in0_1, in1_0, in1_1, slide_val
  600. Outputs - out0, out1
  601. Return Type - as per RTYPE
  602. Details : Byte elements from 'in0_0' vector are slide into 'in1_0' by
  603. number of elements specified by 'slide_val'
  604. */
  605. #define SLDI_B2(RTYPE, in0_0, in0_1, in1_0, in1_1, out0, out1, slide_val) \
  606. { \
  607. out0 = (RTYPE) __msa_sldi_b((v16i8) in0_0, (v16i8) in1_0, slide_val); \
  608. out1 = (RTYPE) __msa_sldi_b((v16i8) in0_1, (v16i8) in1_1, slide_val); \
  609. }
  610. #define SLDI_B2_UB(...) SLDI_B2(v16u8, __VA_ARGS__)
  611. #define SLDI_B2_SB(...) SLDI_B2(v16i8, __VA_ARGS__)
  612. #define SLDI_B2_SH(...) SLDI_B2(v8i16, __VA_ARGS__)
  613. #define SLDI_B3(RTYPE, in0_0, in0_1, in0_2, in1_0, in1_1, in1_2, \
  614. out0, out1, out2, slide_val) \
  615. { \
  616. SLDI_B2(RTYPE, in0_0, in0_1, in1_0, in1_1, out0, out1, slide_val) \
  617. out2 = (RTYPE) __msa_sldi_b((v16i8) in0_2, (v16i8) in1_2, slide_val); \
  618. }
  619. #define SLDI_B3_SB(...) SLDI_B3(v16i8, __VA_ARGS__)
  620. #define SLDI_B3_UH(...) SLDI_B3(v8u16, __VA_ARGS__)
  621. /* Description : Shuffle byte vector elements as per mask vector
  622. Arguments : Inputs - in0, in1, in2, in3, mask0, mask1
  623. Outputs - out0, out1
  624. Return Type - as per RTYPE
  625. Details : Selective byte elements from in0 & in1 are copied to out0 as
  626. per control vector mask0
  627. Selective byte elements from in2 & in3 are copied to out1 as
  628. per control vector mask1
  629. */
  630. #define VSHF_B2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1) \
  631. { \
  632. out0 = (RTYPE) __msa_vshf_b((v16i8) mask0, (v16i8) in1, (v16i8) in0); \
  633. out1 = (RTYPE) __msa_vshf_b((v16i8) mask1, (v16i8) in3, (v16i8) in2); \
  634. }
  635. #define VSHF_B2_UB(...) VSHF_B2(v16u8, __VA_ARGS__)
  636. #define VSHF_B2_SB(...) VSHF_B2(v16i8, __VA_ARGS__)
  637. #define VSHF_B2_UH(...) VSHF_B2(v8u16, __VA_ARGS__)
  638. #define VSHF_B2_SH(...) VSHF_B2(v8i16, __VA_ARGS__)
  639. #define VSHF_B3(RTYPE, in0, in1, in2, in3, in4, in5, mask0, mask1, mask2, \
  640. out0, out1, out2) \
  641. { \
  642. VSHF_B2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1); \
  643. out2 = (RTYPE) __msa_vshf_b((v16i8) mask2, (v16i8) in5, (v16i8) in4); \
  644. }
  645. #define VSHF_B3_SB(...) VSHF_B3(v16i8, __VA_ARGS__)
  646. #define VSHF_B4(RTYPE, in0, in1, mask0, mask1, mask2, mask3, \
  647. out0, out1, out2, out3) \
  648. { \
  649. VSHF_B2(RTYPE, in0, in1, in0, in1, mask0, mask1, out0, out1); \
  650. VSHF_B2(RTYPE, in0, in1, in0, in1, mask2, mask3, out2, out3); \
  651. }
  652. #define VSHF_B4_SB(...) VSHF_B4(v16i8, __VA_ARGS__)
  653. #define VSHF_B4_SH(...) VSHF_B4(v8i16, __VA_ARGS__)
  654. /* Description : Shuffle halfword vector elements as per mask vector
  655. Arguments : Inputs - in0, in1, in2, in3, mask0, mask1
  656. Outputs - out0, out1
  657. Return Type - as per RTYPE
  658. Details : Selective halfword elements from in0 & in1 are copied to out0
  659. as per control vector mask0
  660. Selective halfword elements from in2 & in3 are copied to out1
  661. as per control vector mask1
  662. */
  663. #define VSHF_H2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1) \
  664. { \
  665. out0 = (RTYPE) __msa_vshf_h((v8i16) mask0, (v8i16) in1, (v8i16) in0); \
  666. out1 = (RTYPE) __msa_vshf_h((v8i16) mask1, (v8i16) in3, (v8i16) in2); \
  667. }
  668. #define VSHF_H2_SH(...) VSHF_H2(v8i16, __VA_ARGS__)
  669. #define VSHF_H3(RTYPE, in0, in1, in2, in3, in4, in5, mask0, mask1, mask2, \
  670. out0, out1, out2) \
  671. { \
  672. VSHF_H2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1); \
  673. out2 = (RTYPE) __msa_vshf_h((v8i16) mask2, (v8i16) in5, (v8i16) in4); \
  674. }
  675. #define VSHF_H3_SH(...) VSHF_H3(v8i16, __VA_ARGS__)
  676. /* Description : Shuffle byte vector elements as per mask vector
  677. Arguments : Inputs - in0, in1, in2, in3, mask0, mask1
  678. Outputs - out0, out1
  679. Return Type - as per RTYPE
  680. Details : Selective byte elements from in0 & in1 are copied to out0 as
  681. per control vector mask0
  682. Selective byte elements from in2 & in3 are copied to out1 as
  683. per control vector mask1
  684. */
  685. #define VSHF_W2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1) \
  686. { \
  687. out0 = (RTYPE) __msa_vshf_w((v4i32) mask0, (v4i32) in1, (v4i32) in0); \
  688. out1 = (RTYPE) __msa_vshf_w((v4i32) mask1, (v4i32) in3, (v4i32) in2); \
  689. }
  690. #define VSHF_W2_SB(...) VSHF_W2(v16i8, __VA_ARGS__)
  691. /* Description : Dot product of byte vector elements
  692. Arguments : Inputs - mult0, mult1
  693. cnst0, cnst1
  694. Outputs - out0, out1
  695. Return Type - as per RTYPE
  696. Details : Unsigned byte elements from mult0 are multiplied with
  697. unsigned byte elements from cnst0 producing a result
  698. twice the size of input i.e. unsigned halfword.
  699. Then this multiplication results of adjacent odd-even elements
  700. are added together and stored to the out vector
  701. (2 unsigned halfword results)
  702. */
  703. #define DOTP_UB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  704. { \
  705. out0 = (RTYPE) __msa_dotp_u_h((v16u8) mult0, (v16u8) cnst0); \
  706. out1 = (RTYPE) __msa_dotp_u_h((v16u8) mult1, (v16u8) cnst1); \
  707. }
  708. #define DOTP_UB2_UH(...) DOTP_UB2(v8u16, __VA_ARGS__)
  709. #define DOTP_UB4(RTYPE, mult0, mult1, mult2, mult3, \
  710. cnst0, cnst1, cnst2, cnst3, \
  711. out0, out1, out2, out3) \
  712. { \
  713. DOTP_UB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  714. DOTP_UB2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  715. }
  716. #define DOTP_UB4_UH(...) DOTP_UB4(v8u16, __VA_ARGS__)
  717. /* Description : Dot product of byte vector elements
  718. Arguments : Inputs - mult0, mult1
  719. cnst0, cnst1
  720. Outputs - out0, out1
  721. Return Type - as per RTYPE
  722. Details : Signed byte elements from mult0 are multiplied with
  723. signed byte elements from cnst0 producing a result
  724. twice the size of input i.e. signed halfword.
  725. Then this multiplication results of adjacent odd-even elements
  726. are added together and stored to the out vector
  727. (2 signed halfword results)
  728. */
  729. #define DOTP_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  730. { \
  731. out0 = (RTYPE) __msa_dotp_s_h((v16i8) mult0, (v16i8) cnst0); \
  732. out1 = (RTYPE) __msa_dotp_s_h((v16i8) mult1, (v16i8) cnst1); \
  733. }
  734. #define DOTP_SB2_SH(...) DOTP_SB2(v8i16, __VA_ARGS__)
  735. #define DOTP_SB3(RTYPE, mult0, mult1, mult2, cnst0, cnst1, cnst2, \
  736. out0, out1, out2) \
  737. { \
  738. DOTP_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  739. out2 = (RTYPE) __msa_dotp_s_h((v16i8) mult2, (v16i8) cnst2); \
  740. }
  741. #define DOTP_SB3_SH(...) DOTP_SB3(v8i16, __VA_ARGS__)
  742. #define DOTP_SB4(RTYPE, mult0, mult1, mult2, mult3, \
  743. cnst0, cnst1, cnst2, cnst3, out0, out1, out2, out3) \
  744. { \
  745. DOTP_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  746. DOTP_SB2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  747. }
  748. #define DOTP_SB4_SH(...) DOTP_SB4(v8i16, __VA_ARGS__)
  749. /* Description : Dot product of halfword vector elements
  750. Arguments : Inputs - mult0, mult1
  751. cnst0, cnst1
  752. Outputs - out0, out1
  753. Return Type - as per RTYPE
  754. Details : Signed halfword elements from mult0 are multiplied with
  755. signed halfword elements from cnst0 producing a result
  756. twice the size of input i.e. signed word.
  757. Then this multiplication results of adjacent odd-even elements
  758. are added together and stored to the out vector
  759. (2 signed word results)
  760. */
  761. #define DOTP_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  762. { \
  763. out0 = (RTYPE) __msa_dotp_s_w((v8i16) mult0, (v8i16) cnst0); \
  764. out1 = (RTYPE) __msa_dotp_s_w((v8i16) mult1, (v8i16) cnst1); \
  765. }
  766. #define DOTP_SH2_SW(...) DOTP_SH2(v4i32, __VA_ARGS__)
  767. #define DOTP_SH4(RTYPE, mult0, mult1, mult2, mult3, \
  768. cnst0, cnst1, cnst2, cnst3, \
  769. out0, out1, out2, out3) \
  770. { \
  771. DOTP_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  772. DOTP_SH2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  773. }
  774. #define DOTP_SH4_SW(...) DOTP_SH4(v4i32, __VA_ARGS__)
  775. /* Description : Dot product & addition of byte vector elements
  776. Arguments : Inputs - mult0, mult1
  777. cnst0, cnst1
  778. Outputs - out0, out1
  779. Return Type - as per RTYPE
  780. Details : Signed byte elements from mult0 are multiplied with
  781. signed byte elements from cnst0 producing a result
  782. twice the size of input i.e. signed halfword.
  783. Then this multiplication results of adjacent odd-even elements
  784. are added to the out vector
  785. (2 signed halfword results)
  786. */
  787. #define DPADD_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  788. { \
  789. out0 = (RTYPE) __msa_dpadd_s_h((v8i16) out0, \
  790. (v16i8) mult0, (v16i8) cnst0); \
  791. out1 = (RTYPE) __msa_dpadd_s_h((v8i16) out1, \
  792. (v16i8) mult1, (v16i8) cnst1); \
  793. }
  794. #define DPADD_SB2_SH(...) DPADD_SB2(v8i16, __VA_ARGS__)
  795. #define DPADD_SB4(RTYPE, mult0, mult1, mult2, mult3, \
  796. cnst0, cnst1, cnst2, cnst3, out0, out1, out2, out3) \
  797. { \
  798. DPADD_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  799. DPADD_SB2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  800. }
  801. #define DPADD_SB4_SH(...) DPADD_SB4(v8i16, __VA_ARGS__)
  802. /* Description : Dot product & addition of byte vector elements
  803. Arguments : Inputs - mult0, mult1
  804. cnst0, cnst1
  805. Outputs - out0, out1
  806. Return Type - as per RTYPE
  807. Details : Unsigned byte elements from mult0 are multiplied with
  808. unsigned byte elements from cnst0 producing a result
  809. twice the size of input i.e. unsigned halfword.
  810. Then this multiplication results of adjacent odd-even elements
  811. are added to the out vector
  812. (2 unsigned halfword results)
  813. */
  814. #define DPADD_UB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  815. { \
  816. out0 = (RTYPE) __msa_dpadd_u_h((v8u16) out0, \
  817. (v16u8) mult0, (v16u8) cnst0); \
  818. out1 = (RTYPE) __msa_dpadd_u_h((v8u16) out1, \
  819. (v16u8) mult1, (v16u8) cnst1); \
  820. }
  821. #define DPADD_UB2_UH(...) DPADD_UB2(v8u16, __VA_ARGS__)
  822. /* Description : Dot product & addition of halfword vector elements
  823. Arguments : Inputs - mult0, mult1
  824. cnst0, cnst1
  825. Outputs - out0, out1
  826. Return Type - as per RTYPE
  827. Details : Signed halfword elements from mult0 are multiplied with
  828. signed halfword elements from cnst0 producing a result
  829. twice the size of input i.e. signed word.
  830. Then this multiplication results of adjacent odd-even elements
  831. are added to the out vector
  832. (2 signed word results)
  833. */
  834. #define DPADD_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  835. { \
  836. out0 = (RTYPE) __msa_dpadd_s_w((v4i32) out0, \
  837. (v8i16) mult0, (v8i16) cnst0); \
  838. out1 = (RTYPE) __msa_dpadd_s_w((v4i32) out1, \
  839. (v8i16) mult1, (v8i16) cnst1); \
  840. }
  841. #define DPADD_SH2_SW(...) DPADD_SH2(v4i32, __VA_ARGS__)
  842. #define DPADD_SH4(RTYPE, mult0, mult1, mult2, mult3, \
  843. cnst0, cnst1, cnst2, cnst3, out0, out1, out2, out3) \
  844. { \
  845. DPADD_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  846. DPADD_SH2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  847. }
  848. #define DPADD_SH4_SW(...) DPADD_SH4(v4i32, __VA_ARGS__)
  849. /* Description : Minimum values between unsigned elements of
  850. either vector are copied to the output vector
  851. Arguments : Inputs - in0, in1, min_vec
  852. Outputs - in0, in1, (in place)
  853. Return Type - as per RTYPE
  854. Details : Minimum of unsigned halfword element values from 'in0' and
  855. 'min_value' are written to output vector 'in0'
  856. */
  857. #define MIN_UH2(RTYPE, in0, in1, min_vec) \
  858. { \
  859. in0 = (RTYPE) __msa_min_u_h((v8u16) in0, min_vec); \
  860. in1 = (RTYPE) __msa_min_u_h((v8u16) in1, min_vec); \
  861. }
  862. #define MIN_UH2_UH(...) MIN_UH2(v8u16, __VA_ARGS__)
  863. #define MIN_UH4(RTYPE, in0, in1, in2, in3, min_vec) \
  864. { \
  865. MIN_UH2(RTYPE, in0, in1, min_vec); \
  866. MIN_UH2(RTYPE, in2, in3, min_vec); \
  867. }
  868. #define MIN_UH4_UH(...) MIN_UH4(v8u16, __VA_ARGS__)
  869. /* Description : Clips all halfword elements of input vector between min & max
  870. out = ((in) < (min)) ? (min) : (((in) > (max)) ? (max) : (in))
  871. Arguments : Inputs - in (input vector)
  872. - min (min threshold)
  873. - max (max threshold)
  874. Outputs - in (output vector with clipped elements)
  875. Return Type - signed halfword
  876. */
  877. #define CLIP_SH(in, min, max) \
  878. { \
  879. in = __msa_max_s_h((v8i16) min, (v8i16) in); \
  880. in = __msa_min_s_h((v8i16) max, (v8i16) in); \
  881. }
  882. /* Description : Clips all signed halfword elements of input vector
  883. between 0 & 255
  884. Arguments : Inputs - in (input vector)
  885. Outputs - in (output vector with clipped elements)
  886. Return Type - signed halfwords
  887. */
  888. #define CLIP_SH_0_255(in) \
  889. { \
  890. in = __msa_maxi_s_h((v8i16) in, 0); \
  891. in = (v8i16) __msa_sat_u_h((v8u16) in, 7); \
  892. }
  893. #define CLIP_SH2_0_255(in0, in1) \
  894. { \
  895. CLIP_SH_0_255(in0); \
  896. CLIP_SH_0_255(in1); \
  897. }
  898. #define CLIP_SH4_0_255(in0, in1, in2, in3) \
  899. { \
  900. CLIP_SH2_0_255(in0, in1); \
  901. CLIP_SH2_0_255(in2, in3); \
  902. }
  903. #define CLIP_SH8_0_255(in0, in1, in2, in3, \
  904. in4, in5, in6, in7) \
  905. { \
  906. CLIP_SH4_0_255(in0, in1, in2, in3); \
  907. CLIP_SH4_0_255(in4, in5, in6, in7); \
  908. }
  909. /* Description : Clips all signed word elements of input vector
  910. between 0 & 255
  911. Arguments : Inputs - in (input vector)
  912. Outputs - in (output vector with clipped elements)
  913. Return Type - signed word
  914. */
  915. #define CLIP_SW_0_255(in) \
  916. { \
  917. in = __msa_maxi_s_w((v4i32) in, 0); \
  918. in = (v4i32) __msa_sat_u_w((v4u32) in, 7); \
  919. }
  920. #define CLIP_SW2_0_255(in0, in1) \
  921. { \
  922. CLIP_SW_0_255(in0); \
  923. CLIP_SW_0_255(in1); \
  924. }
  925. #define CLIP_SW4_0_255(in0, in1, in2, in3) \
  926. { \
  927. CLIP_SW2_0_255(in0, in1); \
  928. CLIP_SW2_0_255(in2, in3); \
  929. }
  930. #define CLIP_SW8_0_255(in0, in1, in2, in3, \
  931. in4, in5, in6, in7) \
  932. { \
  933. CLIP_SW4_0_255(in0, in1, in2, in3); \
  934. CLIP_SW4_0_255(in4, in5, in6, in7); \
  935. }
  936. /* Description : Addition of 4 signed word elements
  937. 4 signed word elements of input vector are added together and
  938. resulted integer sum is returned
  939. Arguments : Inputs - in (signed word vector)
  940. Outputs - sum_m (i32 sum)
  941. Return Type - signed word
  942. */
  943. #define HADD_SW_S32(in) \
  944. ( { \
  945. v2i64 res0_m, res1_m; \
  946. int32_t sum_m; \
  947. \
  948. res0_m = __msa_hadd_s_d((v4i32) in, (v4i32) in); \
  949. res1_m = __msa_splati_d(res0_m, 1); \
  950. res0_m += res1_m; \
  951. sum_m = __msa_copy_s_w((v4i32) res0_m, 0); \
  952. sum_m; \
  953. } )
  954. /* Description : Addition of 8 unsigned halfword elements
  955. 8 unsigned halfword elements of input vector are added
  956. together and resulted integer sum is returned
  957. Arguments : Inputs - in (unsigned halfword vector)
  958. Outputs - sum_m (u32 sum)
  959. Return Type - unsigned word
  960. */
  961. #define HADD_UH_U32(in) \
  962. ( { \
  963. v4u32 res_m; \
  964. v2u64 res0_m, res1_m; \
  965. uint32_t sum_m; \
  966. \
  967. res_m = __msa_hadd_u_w((v8u16) in, (v8u16) in); \
  968. res0_m = __msa_hadd_u_d(res_m, res_m); \
  969. res1_m = (v2u64) __msa_splati_d((v2i64) res0_m, 1); \
  970. res0_m += res1_m; \
  971. sum_m = __msa_copy_u_w((v4i32) res0_m, 0); \
  972. sum_m; \
  973. } )
  974. /* Description : Horizontal addition of signed byte vector elements
  975. Arguments : Inputs - in0, in1
  976. Outputs - out0, out1
  977. Return Type - as per RTYPE
  978. Details : Each signed odd byte element from 'in0' is added to
  979. even signed byte element from 'in0' (pairwise) and the
  980. halfword result is stored in 'out0'
  981. */
  982. #define HADD_SB2(RTYPE, in0, in1, out0, out1) \
  983. { \
  984. out0 = (RTYPE) __msa_hadd_s_h((v16i8) in0, (v16i8) in0); \
  985. out1 = (RTYPE) __msa_hadd_s_h((v16i8) in1, (v16i8) in1); \
  986. }
  987. #define HADD_SB2_SH(...) HADD_SB2(v8i16, __VA_ARGS__)
  988. #define HADD_SB4(RTYPE, in0, in1, in2, in3, out0, out1, out2, out3) \
  989. { \
  990. HADD_SB2(RTYPE, in0, in1, out0, out1); \
  991. HADD_SB2(RTYPE, in2, in3, out2, out3); \
  992. }
  993. #define HADD_SB4_UH(...) HADD_SB4(v8u16, __VA_ARGS__)
  994. #define HADD_SB4_SH(...) HADD_SB4(v8i16, __VA_ARGS__)
  995. /* Description : Horizontal addition of unsigned byte vector elements
  996. Arguments : Inputs - in0, in1
  997. Outputs - out0, out1
  998. Return Type - as per RTYPE
  999. Details : Each unsigned odd byte element from 'in0' is added to
  1000. even unsigned byte element from 'in0' (pairwise) and the
  1001. halfword result is stored in 'out0'
  1002. */
  1003. #define HADD_UB2(RTYPE, in0, in1, out0, out1) \
  1004. { \
  1005. out0 = (RTYPE) __msa_hadd_u_h((v16u8) in0, (v16u8) in0); \
  1006. out1 = (RTYPE) __msa_hadd_u_h((v16u8) in1, (v16u8) in1); \
  1007. }
  1008. #define HADD_UB2_UH(...) HADD_UB2(v8u16, __VA_ARGS__)
  1009. #define HADD_UB3(RTYPE, in0, in1, in2, out0, out1, out2) \
  1010. { \
  1011. HADD_UB2(RTYPE, in0, in1, out0, out1); \
  1012. out2 = (RTYPE) __msa_hadd_u_h((v16u8) in2, (v16u8) in2); \
  1013. }
  1014. #define HADD_UB3_UH(...) HADD_UB3(v8u16, __VA_ARGS__)
  1015. #define HADD_UB4(RTYPE, in0, in1, in2, in3, out0, out1, out2, out3) \
  1016. { \
  1017. HADD_UB2(RTYPE, in0, in1, out0, out1); \
  1018. HADD_UB2(RTYPE, in2, in3, out2, out3); \
  1019. }
  1020. #define HADD_UB4_UB(...) HADD_UB4(v16u8, __VA_ARGS__)
  1021. #define HADD_UB4_UH(...) HADD_UB4(v8u16, __VA_ARGS__)
  1022. #define HADD_UB4_SH(...) HADD_UB4(v8i16, __VA_ARGS__)
  1023. /* Description : Horizontal subtraction of unsigned byte vector elements
  1024. Arguments : Inputs - in0, in1
  1025. Outputs - out0, out1
  1026. Return Type - as per RTYPE
  1027. Details : Each unsigned odd byte element from 'in0' is subtracted from
  1028. even unsigned byte element from 'in0' (pairwise) and the
  1029. halfword result is stored in 'out0'
  1030. */
  1031. #define HSUB_UB2(RTYPE, in0, in1, out0, out1) \
  1032. { \
  1033. out0 = (RTYPE) __msa_hsub_u_h((v16u8) in0, (v16u8) in0); \
  1034. out1 = (RTYPE) __msa_hsub_u_h((v16u8) in1, (v16u8) in1); \
  1035. }
  1036. #define HSUB_UB2_UH(...) HSUB_UB2(v8u16, __VA_ARGS__)
  1037. #define HSUB_UB2_SH(...) HSUB_UB2(v8i16, __VA_ARGS__)
  1038. #define HSUB_UB4(RTYPE, in0, in1, in2, in3, out0, out1, out2, out3) \
  1039. { \
  1040. HSUB_UB2(RTYPE, in0, in1, out0, out1); \
  1041. HSUB_UB2(RTYPE, in2, in3, out2, out3); \
  1042. }
  1043. #define HSUB_UB4_UH(...) HSUB_UB4(v8u16, __VA_ARGS__)
  1044. #define HSUB_UB4_SH(...) HSUB_UB4(v8i16, __VA_ARGS__)
  1045. /* Description : SAD (Sum of Absolute Difference)
  1046. Arguments : Inputs - in0, in1, ref0, ref1 (unsigned byte src & ref)
  1047. Outputs - sad_m (halfword vector with sad)
  1048. Return Type - unsigned halfword
  1049. Details : Absolute difference of all the byte elements from 'in0' with
  1050. 'ref0' is calculated and preserved in 'diff0'. From the 16
  1051. unsigned absolute diff values, even-odd pairs are added
  1052. together to generate 8 halfword results.
  1053. */
  1054. #if HAVE_MSA2
  1055. #define SAD_UB2_UH(in0, in1, ref0, ref1) \
  1056. ( { \
  1057. v8u16 sad_m = { 0 }; \
  1058. sad_m += __builtin_msa2_sad_adj2_u_w2x_b((v16u8) in0, (v16u8) ref0); \
  1059. sad_m += __builtin_msa2_sad_adj2_u_w2x_b((v16u8) in1, (v16u8) ref1); \
  1060. sad_m; \
  1061. } )
  1062. #else
  1063. #define SAD_UB2_UH(in0, in1, ref0, ref1) \
  1064. ( { \
  1065. v16u8 diff0_m, diff1_m; \
  1066. v8u16 sad_m = { 0 }; \
  1067. \
  1068. diff0_m = __msa_asub_u_b((v16u8) in0, (v16u8) ref0); \
  1069. diff1_m = __msa_asub_u_b((v16u8) in1, (v16u8) ref1); \
  1070. \
  1071. sad_m += __msa_hadd_u_h((v16u8) diff0_m, (v16u8) diff0_m); \
  1072. sad_m += __msa_hadd_u_h((v16u8) diff1_m, (v16u8) diff1_m); \
  1073. \
  1074. sad_m; \
  1075. } )
  1076. #endif // #if HAVE_MSA2
  1077. /* Description : Insert specified word elements from input vectors to 1
  1078. destination vector
  1079. Arguments : Inputs - in0, in1, in2, in3 (4 input vectors)
  1080. Outputs - out (output vector)
  1081. Return Type - as per RTYPE
  1082. */
  1083. #define INSERT_W2(RTYPE, in0, in1, out) \
  1084. { \
  1085. out = (RTYPE) __msa_insert_w((v4i32) out, 0, in0); \
  1086. out = (RTYPE) __msa_insert_w((v4i32) out, 1, in1); \
  1087. }
  1088. #define INSERT_W2_UB(...) INSERT_W2(v16u8, __VA_ARGS__)
  1089. #define INSERT_W2_SB(...) INSERT_W2(v16i8, __VA_ARGS__)
  1090. #define INSERT_W4(RTYPE, in0, in1, in2, in3, out) \
  1091. { \
  1092. out = (RTYPE) __msa_insert_w((v4i32) out, 0, in0); \
  1093. out = (RTYPE) __msa_insert_w((v4i32) out, 1, in1); \
  1094. out = (RTYPE) __msa_insert_w((v4i32) out, 2, in2); \
  1095. out = (RTYPE) __msa_insert_w((v4i32) out, 3, in3); \
  1096. }
  1097. #define INSERT_W4_UB(...) INSERT_W4(v16u8, __VA_ARGS__)
  1098. #define INSERT_W4_SB(...) INSERT_W4(v16i8, __VA_ARGS__)
  1099. #define INSERT_W4_SH(...) INSERT_W4(v8i16, __VA_ARGS__)
  1100. #define INSERT_W4_SW(...) INSERT_W4(v4i32, __VA_ARGS__)
  1101. /* Description : Insert specified double word elements from input vectors to 1
  1102. destination vector
  1103. Arguments : Inputs - in0, in1 (2 input vectors)
  1104. Outputs - out (output vector)
  1105. Return Type - as per RTYPE
  1106. */
  1107. #define INSERT_D2(RTYPE, in0, in1, out) \
  1108. { \
  1109. out = (RTYPE) __msa_insert_d((v2i64) out, 0, in0); \
  1110. out = (RTYPE) __msa_insert_d((v2i64) out, 1, in1); \
  1111. }
  1112. #define INSERT_D2_UB(...) INSERT_D2(v16u8, __VA_ARGS__)
  1113. #define INSERT_D2_SB(...) INSERT_D2(v16i8, __VA_ARGS__)
  1114. #define INSERT_D2_SH(...) INSERT_D2(v8i16, __VA_ARGS__)
  1115. #define INSERT_D2_SD(...) INSERT_D2(v2i64, __VA_ARGS__)
  1116. /* Description : Interleave even byte elements from vectors
  1117. Arguments : Inputs - in0, in1, in2, in3
  1118. Outputs - out0, out1
  1119. Return Type - as per RTYPE
  1120. Details : Even byte elements of 'in0' and even byte
  1121. elements of 'in1' are interleaved and copied to 'out0'
  1122. Even byte elements of 'in2' and even byte
  1123. elements of 'in3' are interleaved and copied to 'out1'
  1124. */
  1125. #define ILVEV_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1126. { \
  1127. out0 = (RTYPE) __msa_ilvev_b((v16i8) in1, (v16i8) in0); \
  1128. out1 = (RTYPE) __msa_ilvev_b((v16i8) in3, (v16i8) in2); \
  1129. }
  1130. #define ILVEV_B2_UB(...) ILVEV_B2(v16u8, __VA_ARGS__)
  1131. #define ILVEV_B2_SB(...) ILVEV_B2(v16i8, __VA_ARGS__)
  1132. #define ILVEV_B2_SH(...) ILVEV_B2(v8i16, __VA_ARGS__)
  1133. #define ILVEV_B2_SD(...) ILVEV_B2(v2i64, __VA_ARGS__)
  1134. /* Description : Interleave even halfword elements from vectors
  1135. Arguments : Inputs - in0, in1, in2, in3
  1136. Outputs - out0, out1
  1137. Return Type - as per RTYPE
  1138. Details : Even halfword elements of 'in0' and even halfword
  1139. elements of 'in1' are interleaved and copied to 'out0'
  1140. Even halfword elements of 'in2' and even halfword
  1141. elements of 'in3' are interleaved and copied to 'out1'
  1142. */
  1143. #define ILVEV_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1144. { \
  1145. out0 = (RTYPE) __msa_ilvev_h((v8i16) in1, (v8i16) in0); \
  1146. out1 = (RTYPE) __msa_ilvev_h((v8i16) in3, (v8i16) in2); \
  1147. }
  1148. #define ILVEV_H2_UB(...) ILVEV_H2(v16u8, __VA_ARGS__)
  1149. #define ILVEV_H2_SH(...) ILVEV_H2(v8i16, __VA_ARGS__)
  1150. #define ILVEV_H2_SW(...) ILVEV_H2(v4i32, __VA_ARGS__)
  1151. /* Description : Interleave even word elements from vectors
  1152. Arguments : Inputs - in0, in1, in2, in3
  1153. Outputs - out0, out1
  1154. Return Type - as per RTYPE
  1155. Details : Even word elements of 'in0' and even word
  1156. elements of 'in1' are interleaved and copied to 'out0'
  1157. Even word elements of 'in2' and even word
  1158. elements of 'in3' are interleaved and copied to 'out1'
  1159. */
  1160. #define ILVEV_W2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1161. { \
  1162. out0 = (RTYPE) __msa_ilvev_w((v4i32) in1, (v4i32) in0); \
  1163. out1 = (RTYPE) __msa_ilvev_w((v4i32) in3, (v4i32) in2); \
  1164. }
  1165. #define ILVEV_W2_UB(...) ILVEV_W2(v16u8, __VA_ARGS__)
  1166. #define ILVEV_W2_SB(...) ILVEV_W2(v16i8, __VA_ARGS__)
  1167. #define ILVEV_W2_UH(...) ILVEV_W2(v8u16, __VA_ARGS__)
  1168. #define ILVEV_W2_SD(...) ILVEV_W2(v2i64, __VA_ARGS__)
  1169. /* Description : Interleave even double word elements from vectors
  1170. Arguments : Inputs - in0, in1, in2, in3
  1171. Outputs - out0, out1
  1172. Return Type - as per RTYPE
  1173. Details : Even double word elements of 'in0' and even double word
  1174. elements of 'in1' are interleaved and copied to 'out0'
  1175. Even double word elements of 'in2' and even double word
  1176. elements of 'in3' are interleaved and copied to 'out1'
  1177. */
  1178. #define ILVEV_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1179. { \
  1180. out0 = (RTYPE) __msa_ilvev_d((v2i64) in1, (v2i64) in0); \
  1181. out1 = (RTYPE) __msa_ilvev_d((v2i64) in3, (v2i64) in2); \
  1182. }
  1183. #define ILVEV_D2_UB(...) ILVEV_D2(v16u8, __VA_ARGS__)
  1184. #define ILVEV_D2_SB(...) ILVEV_D2(v16i8, __VA_ARGS__)
  1185. #define ILVEV_D2_SW(...) ILVEV_D2(v4i32, __VA_ARGS__)
  1186. /* Description : Interleave left half of byte elements from vectors
  1187. Arguments : Inputs - in0, in1, in2, in3
  1188. Outputs - out0, out1
  1189. Return Type - as per RTYPE
  1190. Details : Left half of byte elements of in0 and left half of byte
  1191. elements of in1 are interleaved and copied to out0.
  1192. Left half of byte elements of in2 and left half of byte
  1193. elements of in3 are interleaved and copied to out1.
  1194. */
  1195. #define ILVL_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1196. { \
  1197. out0 = (RTYPE) __msa_ilvl_b((v16i8) in0, (v16i8) in1); \
  1198. out1 = (RTYPE) __msa_ilvl_b((v16i8) in2, (v16i8) in3); \
  1199. }
  1200. #define ILVL_B2_UB(...) ILVL_B2(v16u8, __VA_ARGS__)
  1201. #define ILVL_B2_SB(...) ILVL_B2(v16i8, __VA_ARGS__)
  1202. #define ILVL_B2_UH(...) ILVL_B2(v8u16, __VA_ARGS__)
  1203. #define ILVL_B2_SH(...) ILVL_B2(v8i16, __VA_ARGS__)
  1204. #define ILVL_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1205. out0, out1, out2, out3) \
  1206. { \
  1207. ILVL_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1208. ILVL_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1209. }
  1210. #define ILVL_B4_UB(...) ILVL_B4(v16u8, __VA_ARGS__)
  1211. #define ILVL_B4_SB(...) ILVL_B4(v16i8, __VA_ARGS__)
  1212. #define ILVL_B4_UH(...) ILVL_B4(v8u16, __VA_ARGS__)
  1213. #define ILVL_B4_SH(...) ILVL_B4(v8i16, __VA_ARGS__)
  1214. /* Description : Interleave left half of halfword elements from vectors
  1215. Arguments : Inputs - in0, in1, in2, in3
  1216. Outputs - out0, out1
  1217. Return Type - as per RTYPE
  1218. Details : Left half of halfword elements of in0 and left half of halfword
  1219. elements of in1 are interleaved and copied to out0.
  1220. Left half of halfword elements of in2 and left half of halfword
  1221. elements of in3 are interleaved and copied to out1.
  1222. */
  1223. #define ILVL_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1224. { \
  1225. out0 = (RTYPE) __msa_ilvl_h((v8i16) in0, (v8i16) in1); \
  1226. out1 = (RTYPE) __msa_ilvl_h((v8i16) in2, (v8i16) in3); \
  1227. }
  1228. #define ILVL_H2_SH(...) ILVL_H2(v8i16, __VA_ARGS__)
  1229. #define ILVL_H2_SW(...) ILVL_H2(v4i32, __VA_ARGS__)
  1230. #define ILVL_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1231. out0, out1, out2, out3) \
  1232. { \
  1233. ILVL_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1234. ILVL_H2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1235. }
  1236. #define ILVL_H4_SH(...) ILVL_H4(v8i16, __VA_ARGS__)
  1237. #define ILVL_H4_SW(...) ILVL_H4(v4i32, __VA_ARGS__)
  1238. /* Description : Interleave left half of word elements from vectors
  1239. Arguments : Inputs - in0, in1, in2, in3
  1240. Outputs - out0, out1
  1241. Return Type - as per RTYPE
  1242. Details : Left half of word elements of in0 and left half of word
  1243. elements of in1 are interleaved and copied to out0.
  1244. Left half of word elements of in2 and left half of word
  1245. elements of in3 are interleaved and copied to out1.
  1246. */
  1247. #define ILVL_W2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1248. { \
  1249. out0 = (RTYPE) __msa_ilvl_w((v4i32) in0, (v4i32) in1); \
  1250. out1 = (RTYPE) __msa_ilvl_w((v4i32) in2, (v4i32) in3); \
  1251. }
  1252. #define ILVL_W2_UB(...) ILVL_W2(v16u8, __VA_ARGS__)
  1253. #define ILVL_W2_SB(...) ILVL_W2(v16i8, __VA_ARGS__)
  1254. #define ILVL_W2_SH(...) ILVL_W2(v8i16, __VA_ARGS__)
  1255. /* Description : Interleave right half of byte elements from vectors
  1256. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1257. Outputs - out0, out1, out2, out3
  1258. Return Type - as per RTYPE
  1259. Details : Right half of byte elements of in0 and right half of byte
  1260. elements of in1 are interleaved and copied to out0.
  1261. Right half of byte elements of in2 and right half of byte
  1262. elements of in3 are interleaved and copied to out1.
  1263. Similar for other pairs
  1264. */
  1265. #define ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1266. { \
  1267. out0 = (RTYPE) __msa_ilvr_b((v16i8) in0, (v16i8) in1); \
  1268. out1 = (RTYPE) __msa_ilvr_b((v16i8) in2, (v16i8) in3); \
  1269. }
  1270. #define ILVR_B2_UB(...) ILVR_B2(v16u8, __VA_ARGS__)
  1271. #define ILVR_B2_SB(...) ILVR_B2(v16i8, __VA_ARGS__)
  1272. #define ILVR_B2_UH(...) ILVR_B2(v8u16, __VA_ARGS__)
  1273. #define ILVR_B2_SH(...) ILVR_B2(v8i16, __VA_ARGS__)
  1274. #define ILVR_B2_SW(...) ILVR_B2(v4i32, __VA_ARGS__)
  1275. #define ILVR_B3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1276. { \
  1277. ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1278. out2 = (RTYPE) __msa_ilvr_b((v16i8) in4, (v16i8) in5); \
  1279. }
  1280. #define ILVR_B3_UB(...) ILVR_B3(v16u8, __VA_ARGS__)
  1281. #define ILVR_B3_SB(...) ILVR_B3(v16i8, __VA_ARGS__)
  1282. #define ILVR_B3_UH(...) ILVR_B3(v8u16, __VA_ARGS__)
  1283. #define ILVR_B3_SH(...) ILVR_B3(v8i16, __VA_ARGS__)
  1284. #define ILVR_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1285. out0, out1, out2, out3) \
  1286. { \
  1287. ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1288. ILVR_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1289. }
  1290. #define ILVR_B4_UB(...) ILVR_B4(v16u8, __VA_ARGS__)
  1291. #define ILVR_B4_SB(...) ILVR_B4(v16i8, __VA_ARGS__)
  1292. #define ILVR_B4_UH(...) ILVR_B4(v8u16, __VA_ARGS__)
  1293. #define ILVR_B4_SH(...) ILVR_B4(v8i16, __VA_ARGS__)
  1294. #define ILVR_B4_SW(...) ILVR_B4(v4i32, __VA_ARGS__)
  1295. #define ILVR_B8(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1296. in8, in9, in10, in11, in12, in13, in14, in15, \
  1297. out0, out1, out2, out3, out4, out5, out6, out7) \
  1298. { \
  1299. ILVR_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1300. out0, out1, out2, out3); \
  1301. ILVR_B4(RTYPE, in8, in9, in10, in11, in12, in13, in14, in15, \
  1302. out4, out5, out6, out7); \
  1303. }
  1304. #define ILVR_B8_UH(...) ILVR_B8(v8u16, __VA_ARGS__)
  1305. /* Description : Interleave right half of halfword elements from vectors
  1306. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1307. Outputs - out0, out1, out2, out3
  1308. Return Type - as per RTYPE
  1309. Details : Right half of halfword elements of in0 and right half of
  1310. halfword elements of in1 are interleaved and copied to out0.
  1311. Right half of halfword elements of in2 and right half of
  1312. halfword elements of in3 are interleaved and copied to out1.
  1313. Similar for other pairs
  1314. */
  1315. #define ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1316. { \
  1317. out0 = (RTYPE) __msa_ilvr_h((v8i16) in0, (v8i16) in1); \
  1318. out1 = (RTYPE) __msa_ilvr_h((v8i16) in2, (v8i16) in3); \
  1319. }
  1320. #define ILVR_H2_SH(...) ILVR_H2(v8i16, __VA_ARGS__)
  1321. #define ILVR_H2_SW(...) ILVR_H2(v4i32, __VA_ARGS__)
  1322. #define ILVR_H3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1323. { \
  1324. ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1325. out2 = (RTYPE) __msa_ilvr_h((v8i16) in4, (v8i16) in5); \
  1326. }
  1327. #define ILVR_H3_SH(...) ILVR_H3(v8i16, __VA_ARGS__)
  1328. #define ILVR_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1329. out0, out1, out2, out3) \
  1330. { \
  1331. ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1332. ILVR_H2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1333. }
  1334. #define ILVR_H4_SH(...) ILVR_H4(v8i16, __VA_ARGS__)
  1335. #define ILVR_H4_SW(...) ILVR_H4(v4i32, __VA_ARGS__)
  1336. #define ILVR_W2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1337. { \
  1338. out0 = (RTYPE) __msa_ilvr_w((v4i32) in0, (v4i32) in1); \
  1339. out1 = (RTYPE) __msa_ilvr_w((v4i32) in2, (v4i32) in3); \
  1340. }
  1341. #define ILVR_W2_UB(...) ILVR_W2(v16u8, __VA_ARGS__)
  1342. #define ILVR_W2_SB(...) ILVR_W2(v16i8, __VA_ARGS__)
  1343. #define ILVR_W2_SH(...) ILVR_W2(v8i16, __VA_ARGS__)
  1344. #define ILVR_W4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1345. out0, out1, out2, out3) \
  1346. { \
  1347. ILVR_W2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1348. ILVR_W2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1349. }
  1350. #define ILVR_W4_SB(...) ILVR_W4(v16i8, __VA_ARGS__)
  1351. #define ILVR_W4_UB(...) ILVR_W4(v16u8, __VA_ARGS__)
  1352. /* Description : Interleave right half of double word elements from vectors
  1353. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1354. Outputs - out0, out1, out2, out3
  1355. Return Type - as per RTYPE
  1356. Details : Right half of double word elements of in0 and right half of
  1357. double word elements of in1 are interleaved and copied to out0.
  1358. Right half of double word elements of in2 and right half of
  1359. double word elements of in3 are interleaved and copied to out1.
  1360. */
  1361. #define ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1362. { \
  1363. out0 = (RTYPE) __msa_ilvr_d((v2i64) in0, (v2i64) in1); \
  1364. out1 = (RTYPE) __msa_ilvr_d((v2i64) in2, (v2i64) in3); \
  1365. }
  1366. #define ILVR_D2_UB(...) ILVR_D2(v16u8, __VA_ARGS__)
  1367. #define ILVR_D2_SB(...) ILVR_D2(v16i8, __VA_ARGS__)
  1368. #define ILVR_D2_SH(...) ILVR_D2(v8i16, __VA_ARGS__)
  1369. #define ILVR_D3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1370. { \
  1371. ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1372. out2 = (RTYPE) __msa_ilvr_d((v2i64) in4, (v2i64) in5); \
  1373. }
  1374. #define ILVR_D3_SB(...) ILVR_D3(v16i8, __VA_ARGS__)
  1375. #define ILVR_D4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1376. out0, out1, out2, out3) \
  1377. { \
  1378. ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1379. ILVR_D2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1380. }
  1381. #define ILVR_D4_SB(...) ILVR_D4(v16i8, __VA_ARGS__)
  1382. #define ILVR_D4_UB(...) ILVR_D4(v16u8, __VA_ARGS__)
  1383. /* Description : Interleave left half of double word elements from vectors
  1384. Arguments : Inputs - in0, in1, in2, in3
  1385. Outputs - out0, out1
  1386. Return Type - as per RTYPE
  1387. Details : Left half of double word elements of in0 and left half of
  1388. double word elements of in1 are interleaved and copied to out0.
  1389. Left half of double word elements of in2 and left half of
  1390. double word elements of in3 are interleaved and copied to out1.
  1391. */
  1392. #define ILVL_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1393. { \
  1394. out0 = (RTYPE) __msa_ilvl_d((v2i64) in0, (v2i64) in1); \
  1395. out1 = (RTYPE) __msa_ilvl_d((v2i64) in2, (v2i64) in3); \
  1396. }
  1397. #define ILVL_D2_UB(...) ILVL_D2(v16u8, __VA_ARGS__)
  1398. #define ILVL_D2_SB(...) ILVL_D2(v16i8, __VA_ARGS__)
  1399. #define ILVL_D2_SH(...) ILVL_D2(v8i16, __VA_ARGS__)
  1400. /* Description : Interleave both left and right half of input vectors
  1401. Arguments : Inputs - in0, in1
  1402. Outputs - out0, out1
  1403. Return Type - as per RTYPE
  1404. Details : Right half of byte elements from 'in0' and 'in1' are
  1405. interleaved and stored to 'out0'
  1406. Left half of byte elements from 'in0' and 'in1' are
  1407. interleaved and stored to 'out1'
  1408. */
  1409. #define ILVRL_B2(RTYPE, in0, in1, out0, out1) \
  1410. { \
  1411. out0 = (RTYPE) __msa_ilvr_b((v16i8) in0, (v16i8) in1); \
  1412. out1 = (RTYPE) __msa_ilvl_b((v16i8) in0, (v16i8) in1); \
  1413. }
  1414. #define ILVRL_B2_UB(...) ILVRL_B2(v16u8, __VA_ARGS__)
  1415. #define ILVRL_B2_SB(...) ILVRL_B2(v16i8, __VA_ARGS__)
  1416. #define ILVRL_B2_UH(...) ILVRL_B2(v8u16, __VA_ARGS__)
  1417. #define ILVRL_B2_SH(...) ILVRL_B2(v8i16, __VA_ARGS__)
  1418. #define ILVRL_B2_SW(...) ILVRL_B2(v4i32, __VA_ARGS__)
  1419. #define ILVRL_H2(RTYPE, in0, in1, out0, out1) \
  1420. { \
  1421. out0 = (RTYPE) __msa_ilvr_h((v8i16) in0, (v8i16) in1); \
  1422. out1 = (RTYPE) __msa_ilvl_h((v8i16) in0, (v8i16) in1); \
  1423. }
  1424. #define ILVRL_H2_UB(...) ILVRL_H2(v16u8, __VA_ARGS__)
  1425. #define ILVRL_H2_SB(...) ILVRL_H2(v16i8, __VA_ARGS__)
  1426. #define ILVRL_H2_SH(...) ILVRL_H2(v8i16, __VA_ARGS__)
  1427. #define ILVRL_H2_SW(...) ILVRL_H2(v4i32, __VA_ARGS__)
  1428. #define ILVRL_W2(RTYPE, in0, in1, out0, out1) \
  1429. { \
  1430. out0 = (RTYPE) __msa_ilvr_w((v4i32) in0, (v4i32) in1); \
  1431. out1 = (RTYPE) __msa_ilvl_w((v4i32) in0, (v4i32) in1); \
  1432. }
  1433. #define ILVRL_W2_UB(...) ILVRL_W2(v16u8, __VA_ARGS__)
  1434. #define ILVRL_W2_SH(...) ILVRL_W2(v8i16, __VA_ARGS__)
  1435. #define ILVRL_W2_SW(...) ILVRL_W2(v4i32, __VA_ARGS__)
  1436. /* Description : Maximum values between signed elements of vector and
  1437. 5-bit signed immediate value are copied to the output vector
  1438. Arguments : Inputs - in0, in1, in2, in3, max_val
  1439. Outputs - in0, in1, in2, in3 (in place)
  1440. Return Type - as per RTYPE
  1441. Details : Maximum of signed halfword element values from 'in0' and
  1442. 'max_val' are written to output vector 'in0'
  1443. */
  1444. #define MAXI_SH2(RTYPE, in0, in1, max_val) \
  1445. { \
  1446. in0 = (RTYPE) __msa_maxi_s_h((v8i16) in0, max_val); \
  1447. in1 = (RTYPE) __msa_maxi_s_h((v8i16) in1, max_val); \
  1448. }
  1449. #define MAXI_SH2_UH(...) MAXI_SH2(v8u16, __VA_ARGS__)
  1450. #define MAXI_SH2_SH(...) MAXI_SH2(v8i16, __VA_ARGS__)
  1451. #define MAXI_SH4(RTYPE, in0, in1, in2, in3, max_val) \
  1452. { \
  1453. MAXI_SH2(RTYPE, in0, in1, max_val); \
  1454. MAXI_SH2(RTYPE, in2, in3, max_val); \
  1455. }
  1456. #define MAXI_SH4_UH(...) MAXI_SH4(v8u16, __VA_ARGS__)
  1457. #define MAXI_SH4_SH(...) MAXI_SH4(v8i16, __VA_ARGS__)
  1458. #define MAXI_SH8(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, max_val) \
  1459. { \
  1460. MAXI_SH4(RTYPE, in0, in1, in2, in3, max_val); \
  1461. MAXI_SH4(RTYPE, in4, in5, in6, in7, max_val); \
  1462. }
  1463. #define MAXI_SH8_UH(...) MAXI_SH8(v8u16, __VA_ARGS__)
  1464. #define MAXI_SH8_SH(...) MAXI_SH8(v8i16, __VA_ARGS__)
  1465. /* Description : Saturate the halfword element values to the max
  1466. unsigned value of (sat_val+1 bits)
  1467. The element data width remains unchanged
  1468. Arguments : Inputs - in0, in1, in2, in3, sat_val
  1469. Outputs - in0, in1, in2, in3 (in place)
  1470. Return Type - as per RTYPE
  1471. Details : Each unsigned halfword element from 'in0' is saturated to the
  1472. value generated with (sat_val+1) bit range
  1473. Results are in placed to original vectors
  1474. */
  1475. #define SAT_UH2(RTYPE, in0, in1, sat_val) \
  1476. { \
  1477. in0 = (RTYPE) __msa_sat_u_h((v8u16) in0, sat_val); \
  1478. in1 = (RTYPE) __msa_sat_u_h((v8u16) in1, sat_val); \
  1479. }
  1480. #define SAT_UH2_UH(...) SAT_UH2(v8u16, __VA_ARGS__)
  1481. #define SAT_UH2_SH(...) SAT_UH2(v8i16, __VA_ARGS__)
  1482. #define SAT_UH4(RTYPE, in0, in1, in2, in3, sat_val) \
  1483. { \
  1484. SAT_UH2(RTYPE, in0, in1, sat_val); \
  1485. SAT_UH2(RTYPE, in2, in3, sat_val); \
  1486. }
  1487. #define SAT_UH4_UH(...) SAT_UH4(v8u16, __VA_ARGS__)
  1488. #define SAT_UH4_SH(...) SAT_UH4(v8i16, __VA_ARGS__)
  1489. #define SAT_UH8(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, sat_val) \
  1490. { \
  1491. SAT_UH4(RTYPE, in0, in1, in2, in3, sat_val); \
  1492. SAT_UH4(RTYPE, in4, in5, in6, in7, sat_val); \
  1493. }
  1494. #define SAT_UH8_UH(...) SAT_UH8(v8u16, __VA_ARGS__)
  1495. #define SAT_UH8_SH(...) SAT_UH8(v8i16, __VA_ARGS__)
  1496. /* Description : Saturate the halfword element values to the max
  1497. unsigned value of (sat_val+1 bits)
  1498. The element data width remains unchanged
  1499. Arguments : Inputs - in0, in1, in2, in3, sat_val
  1500. Outputs - in0, in1, in2, in3 (in place)
  1501. Return Type - as per RTYPE
  1502. Details : Each unsigned halfword element from 'in0' is saturated to the
  1503. value generated with (sat_val+1) bit range
  1504. Results are in placed to original vectors
  1505. */
  1506. #define SAT_SH2(RTYPE, in0, in1, sat_val) \
  1507. { \
  1508. in0 = (RTYPE) __msa_sat_s_h((v8i16) in0, sat_val); \
  1509. in1 = (RTYPE) __msa_sat_s_h((v8i16) in1, sat_val); \
  1510. }
  1511. #define SAT_SH2_SH(...) SAT_SH2(v8i16, __VA_ARGS__)
  1512. #define SAT_SH3(RTYPE, in0, in1, in2, sat_val) \
  1513. { \
  1514. SAT_SH2(RTYPE, in0, in1, sat_val); \
  1515. in2 = (RTYPE) __msa_sat_s_h((v8i16) in2, sat_val); \
  1516. }
  1517. #define SAT_SH3_SH(...) SAT_SH3(v8i16, __VA_ARGS__)
  1518. #define SAT_SH4(RTYPE, in0, in1, in2, in3, sat_val) \
  1519. { \
  1520. SAT_SH2(RTYPE, in0, in1, sat_val); \
  1521. SAT_SH2(RTYPE, in2, in3, sat_val); \
  1522. }
  1523. #define SAT_SH4_SH(...) SAT_SH4(v8i16, __VA_ARGS__)
  1524. /* Description : Saturate the word element values to the max
  1525. unsigned value of (sat_val+1 bits)
  1526. The element data width remains unchanged
  1527. Arguments : Inputs - in0, in1, in2, in3, sat_val
  1528. Outputs - in0, in1, in2, in3 (in place)
  1529. Return Type - as per RTYPE
  1530. Details : Each unsigned word element from 'in0' is saturated to the
  1531. value generated with (sat_val+1) bit range
  1532. Results are in placed to original vectors
  1533. */
  1534. #define SAT_SW2(RTYPE, in0, in1, sat_val) \
  1535. { \
  1536. in0 = (RTYPE) __msa_sat_s_w((v4i32) in0, sat_val); \
  1537. in1 = (RTYPE) __msa_sat_s_w((v4i32) in1, sat_val); \
  1538. }
  1539. #define SAT_SW2_SW(...) SAT_SW2(v4i32, __VA_ARGS__)
  1540. #define SAT_SW4(RTYPE, in0, in1, in2, in3, sat_val) \
  1541. { \
  1542. SAT_SW2(RTYPE, in0, in1, sat_val); \
  1543. SAT_SW2(RTYPE, in2, in3, sat_val); \
  1544. }
  1545. #define SAT_SW4_SW(...) SAT_SW4(v4i32, __VA_ARGS__)
  1546. /* Description : Indexed halfword element values are replicated to all
  1547. elements in output vector
  1548. Arguments : Inputs - in, idx0, idx1
  1549. Outputs - out0, out1
  1550. Return Type - as per RTYPE
  1551. Details : 'idx0' element value from 'in' vector is replicated to all
  1552. elements in 'out0' vector
  1553. Valid index range for halfword operation is 0-7
  1554. */
  1555. #define SPLATI_H2(RTYPE, in, idx0, idx1, out0, out1) \
  1556. { \
  1557. out0 = (RTYPE) __msa_splati_h((v8i16) in, idx0); \
  1558. out1 = (RTYPE) __msa_splati_h((v8i16) in, idx1); \
  1559. }
  1560. #define SPLATI_H2_SB(...) SPLATI_H2(v16i8, __VA_ARGS__)
  1561. #define SPLATI_H2_SH(...) SPLATI_H2(v8i16, __VA_ARGS__)
  1562. #define SPLATI_H3(RTYPE, in, idx0, idx1, idx2, \
  1563. out0, out1, out2) \
  1564. { \
  1565. SPLATI_H2(RTYPE, in, idx0, idx1, out0, out1); \
  1566. out2 = (RTYPE) __msa_splati_h((v8i16) in, idx2); \
  1567. }
  1568. #define SPLATI_H3_SB(...) SPLATI_H3(v16i8, __VA_ARGS__)
  1569. #define SPLATI_H3_SH(...) SPLATI_H3(v8i16, __VA_ARGS__)
  1570. #define SPLATI_H4(RTYPE, in, idx0, idx1, idx2, idx3, \
  1571. out0, out1, out2, out3) \
  1572. { \
  1573. SPLATI_H2(RTYPE, in, idx0, idx1, out0, out1); \
  1574. SPLATI_H2(RTYPE, in, idx2, idx3, out2, out3); \
  1575. }
  1576. #define SPLATI_H4_SB(...) SPLATI_H4(v16i8, __VA_ARGS__)
  1577. #define SPLATI_H4_SH(...) SPLATI_H4(v8i16, __VA_ARGS__)
  1578. /* Description : Indexed word element values are replicated to all
  1579. elements in output vector
  1580. Arguments : Inputs - in, stidx
  1581. Outputs - out0, out1
  1582. Return Type - as per RTYPE
  1583. Details : 'stidx' element value from 'in' vector is replicated to all
  1584. elements in 'out0' vector
  1585. 'stidx + 1' element value from 'in' vector is replicated to all
  1586. elements in 'out1' vector
  1587. Valid index range for halfword operation is 0-3
  1588. */
  1589. #define SPLATI_W2(RTYPE, in, stidx, out0, out1) \
  1590. { \
  1591. out0 = (RTYPE) __msa_splati_w((v4i32) in, stidx); \
  1592. out1 = (RTYPE) __msa_splati_w((v4i32) in, (stidx+1)); \
  1593. }
  1594. #define SPLATI_W2_SH(...) SPLATI_W2(v8i16, __VA_ARGS__)
  1595. #define SPLATI_W2_SW(...) SPLATI_W2(v4i32, __VA_ARGS__)
  1596. #define SPLATI_W4(RTYPE, in, out0, out1, out2, out3) \
  1597. { \
  1598. SPLATI_W2(RTYPE, in, 0, out0, out1); \
  1599. SPLATI_W2(RTYPE, in, 2, out2, out3); \
  1600. }
  1601. #define SPLATI_W4_SH(...) SPLATI_W4(v8i16, __VA_ARGS__)
  1602. #define SPLATI_W4_SW(...) SPLATI_W4(v4i32, __VA_ARGS__)
  1603. /* Description : Pack even byte elements of vector pairs
  1604. Arguments : Inputs - in0, in1, in2, in3
  1605. Outputs - out0, out1
  1606. Return Type - as per RTYPE
  1607. Details : Even byte elements of in0 are copied to the left half of
  1608. out0 & even byte elements of in1 are copied to the right
  1609. half of out0.
  1610. Even byte elements of in2 are copied to the left half of
  1611. out1 & even byte elements of in3 are copied to the right
  1612. half of out1.
  1613. */
  1614. #define PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1615. { \
  1616. out0 = (RTYPE) __msa_pckev_b((v16i8) in0, (v16i8) in1); \
  1617. out1 = (RTYPE) __msa_pckev_b((v16i8) in2, (v16i8) in3); \
  1618. }
  1619. #define PCKEV_B2_SB(...) PCKEV_B2(v16i8, __VA_ARGS__)
  1620. #define PCKEV_B2_UB(...) PCKEV_B2(v16u8, __VA_ARGS__)
  1621. #define PCKEV_B2_SH(...) PCKEV_B2(v8i16, __VA_ARGS__)
  1622. #define PCKEV_B2_SW(...) PCKEV_B2(v4i32, __VA_ARGS__)
  1623. #define PCKEV_B3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1624. { \
  1625. PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1626. out2 = (RTYPE) __msa_pckev_b((v16i8) in4, (v16i8) in5); \
  1627. }
  1628. #define PCKEV_B3_UB(...) PCKEV_B3(v16u8, __VA_ARGS__)
  1629. #define PCKEV_B3_SB(...) PCKEV_B3(v16i8, __VA_ARGS__)
  1630. #define PCKEV_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1631. out0, out1, out2, out3) \
  1632. { \
  1633. PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1634. PCKEV_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1635. }
  1636. #define PCKEV_B4_SB(...) PCKEV_B4(v16i8, __VA_ARGS__)
  1637. #define PCKEV_B4_UB(...) PCKEV_B4(v16u8, __VA_ARGS__)
  1638. #define PCKEV_B4_SH(...) PCKEV_B4(v8i16, __VA_ARGS__)
  1639. #define PCKEV_B4_SW(...) PCKEV_B4(v4i32, __VA_ARGS__)
  1640. /* Description : Pack even halfword elements of vector pairs
  1641. Arguments : Inputs - in0, in1, in2, in3
  1642. Outputs - out0, out1
  1643. Return Type - as per RTYPE
  1644. Details : Even halfword elements of in0 are copied to the left half of
  1645. out0 & even halfword elements of in1 are copied to the right
  1646. half of out0.
  1647. Even halfword elements of in2 are copied to the left half of
  1648. out1 & even halfword elements of in3 are copied to the right
  1649. half of out1.
  1650. */
  1651. #define PCKEV_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1652. { \
  1653. out0 = (RTYPE) __msa_pckev_h((v8i16) in0, (v8i16) in1); \
  1654. out1 = (RTYPE) __msa_pckev_h((v8i16) in2, (v8i16) in3); \
  1655. }
  1656. #define PCKEV_H2_SH(...) PCKEV_H2(v8i16, __VA_ARGS__)
  1657. #define PCKEV_H2_SW(...) PCKEV_H2(v4i32, __VA_ARGS__)
  1658. #define PCKEV_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1659. out0, out1, out2, out3) \
  1660. { \
  1661. PCKEV_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1662. PCKEV_H2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1663. }
  1664. #define PCKEV_H4_SH(...) PCKEV_H4(v8i16, __VA_ARGS__)
  1665. #define PCKEV_H4_SW(...) PCKEV_H4(v4i32, __VA_ARGS__)
  1666. /* Description : Pack even double word elements of vector pairs
  1667. Arguments : Inputs - in0, in1, in2, in3
  1668. Outputs - out0, out1
  1669. Return Type - as per RTYPE
  1670. Details : Even double elements of in0 are copied to the left half of
  1671. out0 & even double elements of in1 are copied to the right
  1672. half of out0.
  1673. Even double elements of in2 are copied to the left half of
  1674. out1 & even double elements of in3 are copied to the right
  1675. half of out1.
  1676. */
  1677. #define PCKEV_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1678. { \
  1679. out0 = (RTYPE) __msa_pckev_d((v2i64) in0, (v2i64) in1); \
  1680. out1 = (RTYPE) __msa_pckev_d((v2i64) in2, (v2i64) in3); \
  1681. }
  1682. #define PCKEV_D2_UB(...) PCKEV_D2(v16u8, __VA_ARGS__)
  1683. #define PCKEV_D2_SB(...) PCKEV_D2(v16i8, __VA_ARGS__)
  1684. #define PCKEV_D2_SH(...) PCKEV_D2(v8i16, __VA_ARGS__)
  1685. #define PCKEV_D4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1686. out0, out1, out2, out3) \
  1687. { \
  1688. PCKEV_D2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1689. PCKEV_D2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1690. }
  1691. #define PCKEV_D4_UB(...) PCKEV_D4(v16u8, __VA_ARGS__)
  1692. /* Description : Pack odd double word elements of vector pairs
  1693. Arguments : Inputs - in0, in1
  1694. Outputs - out0, out1
  1695. Return Type - as per RTYPE
  1696. Details : As operation is on same input 'in0' vector, index 1 double word
  1697. element is overwritten to index 0 and result is written to out0
  1698. As operation is on same input 'in1' vector, index 1 double word
  1699. element is overwritten to index 0 and result is written to out1
  1700. */
  1701. #define PCKOD_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1702. { \
  1703. out0 = (RTYPE) __msa_pckod_d((v2i64) in0, (v2i64) in1); \
  1704. out1 = (RTYPE) __msa_pckod_d((v2i64) in2, (v2i64) in3); \
  1705. }
  1706. #define PCKOD_D2_UB(...) PCKOD_D2(v16u8, __VA_ARGS__)
  1707. #define PCKOD_D2_SH(...) PCKOD_D2(v8i16, __VA_ARGS__)
  1708. #define PCKOD_D2_SD(...) PCKOD_D2(v2i64, __VA_ARGS__)
  1709. /* Description : Each byte element is logically xor'ed with immediate 128
  1710. Arguments : Inputs - in0, in1
  1711. Outputs - in0, in1 (in-place)
  1712. Return Type - as per RTYPE
  1713. Details : Each unsigned byte element from input vector 'in0' is
  1714. logically xor'ed with 128 and result is in-place stored in
  1715. 'in0' vector
  1716. Each unsigned byte element from input vector 'in1' is
  1717. logically xor'ed with 128 and result is in-place stored in
  1718. 'in1' vector
  1719. Similar for other pairs
  1720. */
  1721. #define XORI_B2_128(RTYPE, in0, in1) \
  1722. { \
  1723. in0 = (RTYPE) __msa_xori_b((v16u8) in0, 128); \
  1724. in1 = (RTYPE) __msa_xori_b((v16u8) in1, 128); \
  1725. }
  1726. #define XORI_B2_128_UB(...) XORI_B2_128(v16u8, __VA_ARGS__)
  1727. #define XORI_B2_128_SB(...) XORI_B2_128(v16i8, __VA_ARGS__)
  1728. #define XORI_B2_128_SH(...) XORI_B2_128(v8i16, __VA_ARGS__)
  1729. #define XORI_B3_128(RTYPE, in0, in1, in2) \
  1730. { \
  1731. XORI_B2_128(RTYPE, in0, in1); \
  1732. in2 = (RTYPE) __msa_xori_b((v16u8) in2, 128); \
  1733. }
  1734. #define XORI_B3_128_SB(...) XORI_B3_128(v16i8, __VA_ARGS__)
  1735. #define XORI_B4_128(RTYPE, in0, in1, in2, in3) \
  1736. { \
  1737. XORI_B2_128(RTYPE, in0, in1); \
  1738. XORI_B2_128(RTYPE, in2, in3); \
  1739. }
  1740. #define XORI_B4_128_UB(...) XORI_B4_128(v16u8, __VA_ARGS__)
  1741. #define XORI_B4_128_SB(...) XORI_B4_128(v16i8, __VA_ARGS__)
  1742. #define XORI_B4_128_SH(...) XORI_B4_128(v8i16, __VA_ARGS__)
  1743. #define XORI_B5_128(RTYPE, in0, in1, in2, in3, in4) \
  1744. { \
  1745. XORI_B3_128(RTYPE, in0, in1, in2); \
  1746. XORI_B2_128(RTYPE, in3, in4); \
  1747. }
  1748. #define XORI_B5_128_SB(...) XORI_B5_128(v16i8, __VA_ARGS__)
  1749. #define XORI_B6_128(RTYPE, in0, in1, in2, in3, in4, in5) \
  1750. { \
  1751. XORI_B4_128(RTYPE, in0, in1, in2, in3); \
  1752. XORI_B2_128(RTYPE, in4, in5); \
  1753. }
  1754. #define XORI_B6_128_SB(...) XORI_B6_128(v16i8, __VA_ARGS__)
  1755. #define XORI_B7_128(RTYPE, in0, in1, in2, in3, in4, in5, in6) \
  1756. { \
  1757. XORI_B4_128(RTYPE, in0, in1, in2, in3); \
  1758. XORI_B3_128(RTYPE, in4, in5, in6); \
  1759. }
  1760. #define XORI_B7_128_SB(...) XORI_B7_128(v16i8, __VA_ARGS__)
  1761. #define XORI_B8_128(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7) \
  1762. { \
  1763. XORI_B4_128(RTYPE, in0, in1, in2, in3); \
  1764. XORI_B4_128(RTYPE, in4, in5, in6, in7); \
  1765. }
  1766. #define XORI_B8_128_SB(...) XORI_B8_128(v16i8, __VA_ARGS__)
  1767. #define XORI_B8_128_UB(...) XORI_B8_128(v16u8, __VA_ARGS__)
  1768. /* Description : Addition of signed halfword elements and signed saturation
  1769. Arguments : Inputs - in0, in1, in2, in3
  1770. Outputs - out0, out1
  1771. Return Type - as per RTYPE
  1772. Details : Signed halfword elements from 'in0' are added to signed
  1773. halfword elements of 'in1'. The result is then signed saturated
  1774. between -32768 to +32767 (as per halfword data type)
  1775. Similar for other pairs
  1776. */
  1777. #define ADDS_SH2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1778. { \
  1779. out0 = (RTYPE) __msa_adds_s_h((v8i16) in0, (v8i16) in1); \
  1780. out1 = (RTYPE) __msa_adds_s_h((v8i16) in2, (v8i16) in3); \
  1781. }
  1782. #define ADDS_SH2_SH(...) ADDS_SH2(v8i16, __VA_ARGS__)
  1783. #define ADDS_SH4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1784. out0, out1, out2, out3) \
  1785. { \
  1786. ADDS_SH2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1787. ADDS_SH2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1788. }
  1789. #define ADDS_SH4_UH(...) ADDS_SH4(v8u16, __VA_ARGS__)
  1790. #define ADDS_SH4_SH(...) ADDS_SH4(v8i16, __VA_ARGS__)
  1791. /* Description : Shift left all elements of vector (generic for all data types)
  1792. Arguments : Inputs - in0, in1, in2, in3, shift
  1793. Outputs - in0, in1, in2, in3 (in place)
  1794. Return Type - as per input vector RTYPE
  1795. Details : Each element of vector 'in0' is left shifted by 'shift' and
  1796. result is in place written to 'in0'
  1797. Similar for other pairs
  1798. */
  1799. #define SLLI_2V(in0, in1, shift) \
  1800. { \
  1801. in0 = in0 << shift; \
  1802. in1 = in1 << shift; \
  1803. }
  1804. #define SLLI_4V(in0, in1, in2, in3, shift) \
  1805. { \
  1806. in0 = in0 << shift; \
  1807. in1 = in1 << shift; \
  1808. in2 = in2 << shift; \
  1809. in3 = in3 << shift; \
  1810. }
  1811. /* Description : Arithmetic shift right all elements of vector
  1812. (generic for all data types)
  1813. Arguments : Inputs - in0, in1, in2, in3, shift
  1814. Outputs - in0, in1, in2, in3 (in place)
  1815. Return Type - as per input vector RTYPE
  1816. Details : Each element of vector 'in0' is right shifted by 'shift' and
  1817. result is in place written to 'in0'
  1818. Here, 'shift' is GP variable passed in
  1819. Similar for other pairs
  1820. */
  1821. #define SRA_4V(in0, in1, in2, in3, shift) \
  1822. { \
  1823. in0 = in0 >> shift; \
  1824. in1 = in1 >> shift; \
  1825. in2 = in2 >> shift; \
  1826. in3 = in3 >> shift; \
  1827. }
  1828. /* Description : Shift right logical all halfword elements of vector
  1829. Arguments : Inputs - in0, in1, in2, in3, shift
  1830. Outputs - in0, in1, in2, in3 (in place)
  1831. Return Type - as per RTYPE
  1832. Details : Each element of vector 'in0' is shifted right logical by
  1833. number of bits respective element holds in vector 'shift' and
  1834. result is in place written to 'in0'
  1835. Here, 'shift' is a vector passed in
  1836. Similar for other pairs
  1837. */
  1838. #define SRL_H4(RTYPE, in0, in1, in2, in3, shift) \
  1839. { \
  1840. in0 = (RTYPE) __msa_srl_h((v8i16) in0, (v8i16) shift); \
  1841. in1 = (RTYPE) __msa_srl_h((v8i16) in1, (v8i16) shift); \
  1842. in2 = (RTYPE) __msa_srl_h((v8i16) in2, (v8i16) shift); \
  1843. in3 = (RTYPE) __msa_srl_h((v8i16) in3, (v8i16) shift); \
  1844. }
  1845. #define SRL_H4_UH(...) SRL_H4(v8u16, __VA_ARGS__)
  1846. #define SRLR_H4(RTYPE, in0, in1, in2, in3, shift) \
  1847. { \
  1848. in0 = (RTYPE) __msa_srlr_h((v8i16) in0, (v8i16) shift); \
  1849. in1 = (RTYPE) __msa_srlr_h((v8i16) in1, (v8i16) shift); \
  1850. in2 = (RTYPE) __msa_srlr_h((v8i16) in2, (v8i16) shift); \
  1851. in3 = (RTYPE) __msa_srlr_h((v8i16) in3, (v8i16) shift); \
  1852. }
  1853. #define SRLR_H4_UH(...) SRLR_H4(v8u16, __VA_ARGS__)
  1854. #define SRLR_H4_SH(...) SRLR_H4(v8i16, __VA_ARGS__)
  1855. #define SRLR_H8(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, shift) \
  1856. { \
  1857. SRLR_H4(RTYPE, in0, in1, in2, in3, shift); \
  1858. SRLR_H4(RTYPE, in4, in5, in6, in7, shift); \
  1859. }
  1860. #define SRLR_H8_UH(...) SRLR_H8(v8u16, __VA_ARGS__)
  1861. #define SRLR_H8_SH(...) SRLR_H8(v8i16, __VA_ARGS__)
  1862. /* Description : Shift right arithmetic rounded halfwords
  1863. Arguments : Inputs - in0, in1, shift
  1864. Outputs - in0, in1, (in place)
  1865. Return Type - as per RTYPE
  1866. Details : Each element of vector 'in0' is shifted right arithmetic by
  1867. number of bits respective element holds in vector 'shift'.
  1868. The last discarded bit is added to shifted value for rounding
  1869. and the result is in place written to 'in0'
  1870. Here, 'shift' is a vector passed in
  1871. Similar for other pairs
  1872. */
  1873. #define SRAR_H2(RTYPE, in0, in1, shift) \
  1874. { \
  1875. in0 = (RTYPE) __msa_srar_h((v8i16) in0, (v8i16) shift); \
  1876. in1 = (RTYPE) __msa_srar_h((v8i16) in1, (v8i16) shift); \
  1877. }
  1878. #define SRAR_H2_UH(...) SRAR_H2(v8u16, __VA_ARGS__)
  1879. #define SRAR_H2_SH(...) SRAR_H2(v8i16, __VA_ARGS__)
  1880. #define SRAR_H3(RTYPE, in0, in1, in2, shift) \
  1881. { \
  1882. SRAR_H2(RTYPE, in0, in1, shift) \
  1883. in2 = (RTYPE) __msa_srar_h((v8i16) in2, (v8i16) shift); \
  1884. }
  1885. #define SRAR_H3_SH(...) SRAR_H3(v8i16, __VA_ARGS__)
  1886. #define SRAR_H4(RTYPE, in0, in1, in2, in3, shift) \
  1887. { \
  1888. SRAR_H2(RTYPE, in0, in1, shift) \
  1889. SRAR_H2(RTYPE, in2, in3, shift) \
  1890. }
  1891. #define SRAR_H4_UH(...) SRAR_H4(v8u16, __VA_ARGS__)
  1892. #define SRAR_H4_SH(...) SRAR_H4(v8i16, __VA_ARGS__)
  1893. /* Description : Shift right arithmetic rounded words
  1894. Arguments : Inputs - in0, in1, shift
  1895. Outputs - in0, in1, (in place)
  1896. Return Type - as per RTYPE
  1897. Details : Each element of vector 'in0' is shifted right arithmetic by
  1898. number of bits respective element holds in vector 'shift'.
  1899. The last discarded bit is added to shifted value for rounding
  1900. and the result is in place written to 'in0'
  1901. Here, 'shift' is a vector passed in
  1902. Similar for other pairs
  1903. */
  1904. #define SRAR_W2(RTYPE, in0, in1, shift) \
  1905. { \
  1906. in0 = (RTYPE) __msa_srar_w((v4i32) in0, (v4i32) shift); \
  1907. in1 = (RTYPE) __msa_srar_w((v4i32) in1, (v4i32) shift); \
  1908. }
  1909. #define SRAR_W2_SW(...) SRAR_W2(v4i32, __VA_ARGS__)
  1910. #define SRAR_W4(RTYPE, in0, in1, in2, in3, shift) \
  1911. { \
  1912. SRAR_W2(RTYPE, in0, in1, shift) \
  1913. SRAR_W2(RTYPE, in2, in3, shift) \
  1914. }
  1915. #define SRAR_W4_SW(...) SRAR_W4(v4i32, __VA_ARGS__)
  1916. /* Description : Shift right arithmetic rounded (immediate)
  1917. Arguments : Inputs - in0, in1, in2, in3, shift
  1918. Outputs - in0, in1, in2, in3 (in place)
  1919. Return Type - as per RTYPE
  1920. Details : Each element of vector 'in0' is shifted right arithmetic by
  1921. value in 'shift'.
  1922. The last discarded bit is added to shifted value for rounding
  1923. and the result is in place written to 'in0'
  1924. Similar for other pairs
  1925. */
  1926. #define SRARI_H2(RTYPE, in0, in1, shift) \
  1927. { \
  1928. in0 = (RTYPE) __msa_srari_h((v8i16) in0, shift); \
  1929. in1 = (RTYPE) __msa_srari_h((v8i16) in1, shift); \
  1930. }
  1931. #define SRARI_H2_UH(...) SRARI_H2(v8u16, __VA_ARGS__)
  1932. #define SRARI_H2_SH(...) SRARI_H2(v8i16, __VA_ARGS__)
  1933. #define SRARI_H4(RTYPE, in0, in1, in2, in3, shift) \
  1934. { \
  1935. SRARI_H2(RTYPE, in0, in1, shift); \
  1936. SRARI_H2(RTYPE, in2, in3, shift); \
  1937. }
  1938. #define SRARI_H4_UH(...) SRARI_H4(v8u16, __VA_ARGS__)
  1939. #define SRARI_H4_SH(...) SRARI_H4(v8i16, __VA_ARGS__)
  1940. /* Description : Shift right arithmetic rounded (immediate)
  1941. Arguments : Inputs - in0, in1, shift
  1942. Outputs - in0, in1 (in place)
  1943. Return Type - as per RTYPE
  1944. Details : Each element of vector 'in0' is shifted right arithmetic by
  1945. value in 'shift'.
  1946. The last discarded bit is added to shifted value for rounding
  1947. and the result is in place written to 'in0'
  1948. Similar for other pairs
  1949. */
  1950. #define SRARI_W2(RTYPE, in0, in1, shift) \
  1951. { \
  1952. in0 = (RTYPE) __msa_srari_w((v4i32) in0, shift); \
  1953. in1 = (RTYPE) __msa_srari_w((v4i32) in1, shift); \
  1954. }
  1955. #define SRARI_W2_SW(...) SRARI_W2(v4i32, __VA_ARGS__)
  1956. #define SRARI_W4(RTYPE, in0, in1, in2, in3, shift) \
  1957. { \
  1958. SRARI_W2(RTYPE, in0, in1, shift); \
  1959. SRARI_W2(RTYPE, in2, in3, shift); \
  1960. }
  1961. #define SRARI_W4_SH(...) SRARI_W4(v8i16, __VA_ARGS__)
  1962. #define SRARI_W4_SW(...) SRARI_W4(v4i32, __VA_ARGS__)
  1963. /* Description : Multiplication of pairs of vectors
  1964. Arguments : Inputs - in0, in1, in2, in3
  1965. Outputs - out0, out1
  1966. Details : Each element from 'in0' is multiplied with elements from 'in1'
  1967. and result is written to 'out0'
  1968. Similar for other pairs
  1969. */
  1970. #define MUL2(in0, in1, in2, in3, out0, out1) \
  1971. { \
  1972. out0 = in0 * in1; \
  1973. out1 = in2 * in3; \
  1974. }
  1975. #define MUL4(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, out3) \
  1976. { \
  1977. MUL2(in0, in1, in2, in3, out0, out1); \
  1978. MUL2(in4, in5, in6, in7, out2, out3); \
  1979. }
  1980. /* Description : Addition of 2 pairs of vectors
  1981. Arguments : Inputs - in0, in1, in2, in3
  1982. Outputs - out0, out1
  1983. Details : Each element from 2 pairs vectors is added and 2 results are
  1984. produced
  1985. */
  1986. #define ADD2(in0, in1, in2, in3, out0, out1) \
  1987. { \
  1988. out0 = in0 + in1; \
  1989. out1 = in2 + in3; \
  1990. }
  1991. #define ADD4(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, out3) \
  1992. { \
  1993. ADD2(in0, in1, in2, in3, out0, out1); \
  1994. ADD2(in4, in5, in6, in7, out2, out3); \
  1995. }
  1996. /* Description : Subtraction of 2 pairs of vectors
  1997. Arguments : Inputs - in0, in1, in2, in3
  1998. Outputs - out0, out1
  1999. Details : Each element from 2 pairs vectors is subtracted and 2 results
  2000. are produced
  2001. */
  2002. #define SUB2(in0, in1, in2, in3, out0, out1) \
  2003. { \
  2004. out0 = in0 - in1; \
  2005. out1 = in2 - in3; \
  2006. }
  2007. #define SUB4(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, out3) \
  2008. { \
  2009. out0 = in0 - in1; \
  2010. out1 = in2 - in3; \
  2011. out2 = in4 - in5; \
  2012. out3 = in6 - in7; \
  2013. }
  2014. /* Description : Sign extend byte elements from right half of the vector
  2015. Arguments : Input - in (byte vector)
  2016. Output - out (sign extended halfword vector)
  2017. Return Type - signed halfword
  2018. Details : Sign bit of byte elements from input vector 'in' is
  2019. extracted and interleaved with same vector 'in' to generate
  2020. 8 halfword elements keeping sign intact
  2021. */
  2022. #define UNPCK_R_SB_SH(in, out) \
  2023. { \
  2024. v16i8 sign_m; \
  2025. \
  2026. sign_m = __msa_clti_s_b((v16i8) in, 0); \
  2027. out = (v8i16) __msa_ilvr_b(sign_m, (v16i8) in); \
  2028. }
  2029. /* Description : Sign extend halfword elements from right half of the vector
  2030. Arguments : Inputs - in (input halfword vector)
  2031. Outputs - out (sign extended word vectors)
  2032. Return Type - signed word
  2033. Details : Sign bit of halfword elements from input vector 'in' is
  2034. extracted and interleaved with same vector 'in0' to generate
  2035. 4 word elements keeping sign intact
  2036. */
  2037. #if HAVE_MSA2
  2038. #define UNPCK_R_SH_SW(in, out) \
  2039. { \
  2040. out = (v4i32) __builtin_msa2_w2x_lo_s_h((v8i16) in); \
  2041. }
  2042. #else
  2043. #define UNPCK_R_SH_SW(in, out) \
  2044. { \
  2045. v8i16 sign_m; \
  2046. \
  2047. sign_m = __msa_clti_s_h((v8i16) in, 0); \
  2048. out = (v4i32) __msa_ilvr_h(sign_m, (v8i16) in); \
  2049. }
  2050. #endif // #if HAVE_MSA2
  2051. /* Description : Sign extend byte elements from input vector and return
  2052. halfword results in pair of vectors
  2053. Arguments : Inputs - in (1 input byte vector)
  2054. Outputs - out0, out1 (sign extended 2 halfword vectors)
  2055. Return Type - signed halfword
  2056. Details : Sign bit of byte elements from input vector 'in' is
  2057. extracted and interleaved right with same vector 'in0' to
  2058. generate 8 signed halfword elements in 'out0'
  2059. Then interleaved left with same vector 'in0' to
  2060. generate 8 signed halfword elements in 'out1'
  2061. */
  2062. #if HAVE_MSA2
  2063. #define UNPCK_SB_SH(in, out0, out1) \
  2064. { \
  2065. out0 = (v4i32) __builtin_msa2_w2x_lo_s_b((v16i8) in); \
  2066. out1 = (v4i32) __builtin_msa2_w2x_hi_s_b((v16i8) in); \
  2067. }
  2068. #else
  2069. #define UNPCK_SB_SH(in, out0, out1) \
  2070. { \
  2071. v16i8 tmp_m; \
  2072. \
  2073. tmp_m = __msa_clti_s_b((v16i8) in, 0); \
  2074. ILVRL_B2_SH(tmp_m, in, out0, out1); \
  2075. }
  2076. #endif // #if HAVE_MSA2
  2077. /* Description : Zero extend unsigned byte elements to halfword elements
  2078. Arguments : Inputs - in (1 input unsigned byte vector)
  2079. Outputs - out0, out1 (unsigned 2 halfword vectors)
  2080. Return Type - signed halfword
  2081. Details : Zero extended right half of vector is returned in 'out0'
  2082. Zero extended left half of vector is returned in 'out1'
  2083. */
  2084. #define UNPCK_UB_SH(in, out0, out1) \
  2085. { \
  2086. v16i8 zero_m = { 0 }; \
  2087. \
  2088. ILVRL_B2_SH(zero_m, in, out0, out1); \
  2089. }
  2090. /* Description : Sign extend halfword elements from input vector and return
  2091. result in pair of vectors
  2092. Arguments : Inputs - in (1 input halfword vector)
  2093. Outputs - out0, out1 (sign extended 2 word vectors)
  2094. Return Type - signed word
  2095. Details : Sign bit of halfword elements from input vector 'in' is
  2096. extracted and interleaved right with same vector 'in0' to
  2097. generate 4 signed word elements in 'out0'
  2098. Then interleaved left with same vector 'in0' to
  2099. generate 4 signed word elements in 'out1'
  2100. */
  2101. #if HAVE_MSA2
  2102. #define UNPCK_SH_SW(in, out0, out1) \
  2103. { \
  2104. out0 = (v4i32) __builtin_msa2_w2x_lo_s_h((v8i16) in); \
  2105. out1 = (v4i32) __builtin_msa2_w2x_hi_s_h((v8i16) in); \
  2106. }
  2107. #else
  2108. #define UNPCK_SH_SW(in, out0, out1) \
  2109. { \
  2110. v8i16 tmp_m; \
  2111. \
  2112. tmp_m = __msa_clti_s_h((v8i16) in, 0); \
  2113. ILVRL_H2_SW(tmp_m, in, out0, out1); \
  2114. }
  2115. #endif // #if HAVE_MSA2
  2116. /* Description : Swap two variables
  2117. Arguments : Inputs - in0, in1
  2118. Outputs - in0, in1 (in-place)
  2119. Details : Swapping of two input variables using xor
  2120. */
  2121. #define SWAP(in0, in1) \
  2122. { \
  2123. in0 = in0 ^ in1; \
  2124. in1 = in0 ^ in1; \
  2125. in0 = in0 ^ in1; \
  2126. }
  2127. /* Description : Butterfly of 4 input vectors
  2128. Arguments : Inputs - in0, in1, in2, in3
  2129. Outputs - out0, out1, out2, out3
  2130. Details : Butterfly operation
  2131. */
  2132. #define BUTTERFLY_4(in0, in1, in2, in3, out0, out1, out2, out3) \
  2133. { \
  2134. out0 = in0 + in3; \
  2135. out1 = in1 + in2; \
  2136. \
  2137. out2 = in1 - in2; \
  2138. out3 = in0 - in3; \
  2139. }
  2140. /* Description : Butterfly of 8 input vectors
  2141. Arguments : Inputs - in0 ... in7
  2142. Outputs - out0 .. out7
  2143. Details : Butterfly operation
  2144. */
  2145. #define BUTTERFLY_8(in0, in1, in2, in3, in4, in5, in6, in7, \
  2146. out0, out1, out2, out3, out4, out5, out6, out7) \
  2147. { \
  2148. out0 = in0 + in7; \
  2149. out1 = in1 + in6; \
  2150. out2 = in2 + in5; \
  2151. out3 = in3 + in4; \
  2152. \
  2153. out4 = in3 - in4; \
  2154. out5 = in2 - in5; \
  2155. out6 = in1 - in6; \
  2156. out7 = in0 - in7; \
  2157. }
  2158. /* Description : Butterfly of 16 input vectors
  2159. Arguments : Inputs - in0 ... in15
  2160. Outputs - out0 .. out15
  2161. Details : Butterfly operation
  2162. */
  2163. #define BUTTERFLY_16(in0, in1, in2, in3, in4, in5, in6, in7, \
  2164. in8, in9, in10, in11, in12, in13, in14, in15, \
  2165. out0, out1, out2, out3, out4, out5, out6, out7, \
  2166. out8, out9, out10, out11, out12, out13, out14, out15) \
  2167. { \
  2168. out0 = in0 + in15; \
  2169. out1 = in1 + in14; \
  2170. out2 = in2 + in13; \
  2171. out3 = in3 + in12; \
  2172. out4 = in4 + in11; \
  2173. out5 = in5 + in10; \
  2174. out6 = in6 + in9; \
  2175. out7 = in7 + in8; \
  2176. \
  2177. out8 = in7 - in8; \
  2178. out9 = in6 - in9; \
  2179. out10 = in5 - in10; \
  2180. out11 = in4 - in11; \
  2181. out12 = in3 - in12; \
  2182. out13 = in2 - in13; \
  2183. out14 = in1 - in14; \
  2184. out15 = in0 - in15; \
  2185. }
  2186. /* Description : Transposes input 4x4 byte block
  2187. Arguments : Inputs - in0, in1, in2, in3 (input 4x4 byte block)
  2188. Outputs - out0, out1, out2, out3 (output 4x4 byte block)
  2189. Return Type - unsigned byte
  2190. Details :
  2191. */
  2192. #define TRANSPOSE4x4_UB_UB(in0, in1, in2, in3, out0, out1, out2, out3) \
  2193. { \
  2194. v16i8 zero_m = { 0 }; \
  2195. v16i8 s0_m, s1_m, s2_m, s3_m; \
  2196. \
  2197. ILVR_D2_SB(in1, in0, in3, in2, s0_m, s1_m); \
  2198. ILVRL_B2_SB(s1_m, s0_m, s2_m, s3_m); \
  2199. \
  2200. out0 = (v16u8) __msa_ilvr_b(s3_m, s2_m); \
  2201. out1 = (v16u8) __msa_sldi_b(zero_m, (v16i8) out0, 4); \
  2202. out2 = (v16u8) __msa_sldi_b(zero_m, (v16i8) out1, 4); \
  2203. out3 = (v16u8) __msa_sldi_b(zero_m, (v16i8) out2, 4); \
  2204. }
  2205. /* Description : Transposes input 8x4 byte block into 4x8
  2206. Arguments : Inputs - in0, in1, in2, in3 (input 8x4 byte block)
  2207. Outputs - out0, out1, out2, out3 (output 4x8 byte block)
  2208. Return Type - as per RTYPE
  2209. Details :
  2210. */
  2211. #define TRANSPOSE8x4_UB(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  2212. out0, out1, out2, out3) \
  2213. { \
  2214. v16i8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2215. \
  2216. ILVEV_W2_SB(in0, in4, in1, in5, tmp0_m, tmp1_m); \
  2217. tmp2_m = __msa_ilvr_b(tmp1_m, tmp0_m); \
  2218. ILVEV_W2_SB(in2, in6, in3, in7, tmp0_m, tmp1_m); \
  2219. \
  2220. tmp3_m = __msa_ilvr_b(tmp1_m, tmp0_m); \
  2221. ILVRL_H2_SB(tmp3_m, tmp2_m, tmp0_m, tmp1_m); \
  2222. \
  2223. ILVRL_W2(RTYPE, tmp1_m, tmp0_m, out0, out2); \
  2224. out1 = (RTYPE) __msa_ilvl_d((v2i64) out2, (v2i64) out0); \
  2225. out3 = (RTYPE) __msa_ilvl_d((v2i64) out0, (v2i64) out2); \
  2226. }
  2227. #define TRANSPOSE8x4_UB_UB(...) TRANSPOSE8x4_UB(v16u8, __VA_ARGS__)
  2228. #define TRANSPOSE8x4_UB_UH(...) TRANSPOSE8x4_UB(v8u16, __VA_ARGS__)
  2229. /* Description : Transposes input 8x8 byte block
  2230. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  2231. (input 8x8 byte block)
  2232. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  2233. (output 8x8 byte block)
  2234. Return Type - as per RTYPE
  2235. Details :
  2236. */
  2237. #define TRANSPOSE8x8_UB(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  2238. out0, out1, out2, out3, out4, out5, out6, out7) \
  2239. { \
  2240. v16i8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2241. v16i8 tmp4_m, tmp5_m, tmp6_m, tmp7_m; \
  2242. \
  2243. ILVR_B4_SB(in2, in0, in3, in1, in6, in4, in7, in5, \
  2244. tmp0_m, tmp1_m, tmp2_m, tmp3_m); \
  2245. ILVRL_B2_SB(tmp1_m, tmp0_m, tmp4_m, tmp5_m); \
  2246. ILVRL_B2_SB(tmp3_m, tmp2_m, tmp6_m, tmp7_m); \
  2247. ILVRL_W2(RTYPE, tmp6_m, tmp4_m, out0, out2); \
  2248. ILVRL_W2(RTYPE, tmp7_m, tmp5_m, out4, out6); \
  2249. SLDI_B2_0(RTYPE, out0, out2, out1, out3, 8); \
  2250. SLDI_B2_0(RTYPE, out4, out6, out5, out7, 8); \
  2251. }
  2252. #define TRANSPOSE8x8_UB_UB(...) TRANSPOSE8x8_UB(v16u8, __VA_ARGS__)
  2253. #define TRANSPOSE8x8_UB_UH(...) TRANSPOSE8x8_UB(v8u16, __VA_ARGS__)
  2254. /* Description : Transposes 16x4 block into 4x16 with byte elements in vectors
  2255. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7,
  2256. in8, in9, in10, in11, in12, in13, in14, in15
  2257. Outputs - out0, out1, out2, out3
  2258. Return Type - unsigned byte
  2259. Details :
  2260. */
  2261. #define TRANSPOSE16x4_UB_UB(in0, in1, in2, in3, in4, in5, in6, in7, \
  2262. in8, in9, in10, in11, in12, in13, in14, in15, \
  2263. out0, out1, out2, out3) \
  2264. { \
  2265. v2i64 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2266. \
  2267. ILVEV_W2_SD(in0, in4, in8, in12, tmp0_m, tmp1_m); \
  2268. out1 = (v16u8) __msa_ilvev_d(tmp1_m, tmp0_m); \
  2269. \
  2270. ILVEV_W2_SD(in1, in5, in9, in13, tmp0_m, tmp1_m); \
  2271. out3 = (v16u8) __msa_ilvev_d(tmp1_m, tmp0_m); \
  2272. \
  2273. ILVEV_W2_SD(in2, in6, in10, in14, tmp0_m, tmp1_m); \
  2274. \
  2275. tmp2_m = __msa_ilvev_d(tmp1_m, tmp0_m); \
  2276. ILVEV_W2_SD(in3, in7, in11, in15, tmp0_m, tmp1_m); \
  2277. \
  2278. tmp3_m = __msa_ilvev_d(tmp1_m, tmp0_m); \
  2279. ILVEV_B2_SD(out1, out3, tmp2_m, tmp3_m, tmp0_m, tmp1_m); \
  2280. out0 = (v16u8) __msa_ilvev_h((v8i16) tmp1_m, (v8i16) tmp0_m); \
  2281. out2 = (v16u8) __msa_ilvod_h((v8i16) tmp1_m, (v8i16) tmp0_m); \
  2282. \
  2283. tmp0_m = (v2i64) __msa_ilvod_b((v16i8) out3, (v16i8) out1); \
  2284. tmp1_m = (v2i64) __msa_ilvod_b((v16i8) tmp3_m, (v16i8) tmp2_m); \
  2285. out1 = (v16u8) __msa_ilvev_h((v8i16) tmp1_m, (v8i16) tmp0_m); \
  2286. out3 = (v16u8) __msa_ilvod_h((v8i16) tmp1_m, (v8i16) tmp0_m); \
  2287. }
  2288. /* Description : Transposes 16x8 block into 8x16 with byte elements in vectors
  2289. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7,
  2290. in8, in9, in10, in11, in12, in13, in14, in15
  2291. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  2292. Return Type - unsigned byte
  2293. Details :
  2294. */
  2295. #define TRANSPOSE16x8_UB_UB(in0, in1, in2, in3, in4, in5, in6, in7, \
  2296. in8, in9, in10, in11, in12, in13, in14, in15, \
  2297. out0, out1, out2, out3, out4, out5, out6, out7) \
  2298. { \
  2299. v16u8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2300. v16u8 tmp4_m, tmp5_m, tmp6_m, tmp7_m; \
  2301. \
  2302. ILVEV_D2_UB(in0, in8, in1, in9, out7, out6); \
  2303. ILVEV_D2_UB(in2, in10, in3, in11, out5, out4); \
  2304. ILVEV_D2_UB(in4, in12, in5, in13, out3, out2); \
  2305. ILVEV_D2_UB(in6, in14, in7, in15, out1, out0); \
  2306. \
  2307. tmp0_m = (v16u8) __msa_ilvev_b((v16i8) out6, (v16i8) out7); \
  2308. tmp4_m = (v16u8) __msa_ilvod_b((v16i8) out6, (v16i8) out7); \
  2309. tmp1_m = (v16u8) __msa_ilvev_b((v16i8) out4, (v16i8) out5); \
  2310. tmp5_m = (v16u8) __msa_ilvod_b((v16i8) out4, (v16i8) out5); \
  2311. out5 = (v16u8) __msa_ilvev_b((v16i8) out2, (v16i8) out3); \
  2312. tmp6_m = (v16u8) __msa_ilvod_b((v16i8) out2, (v16i8) out3); \
  2313. out7 = (v16u8) __msa_ilvev_b((v16i8) out0, (v16i8) out1); \
  2314. tmp7_m = (v16u8) __msa_ilvod_b((v16i8) out0, (v16i8) out1); \
  2315. \
  2316. ILVEV_H2_UB(tmp0_m, tmp1_m, out5, out7, tmp2_m, tmp3_m); \
  2317. out0 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2318. out4 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2319. \
  2320. tmp2_m = (v16u8) __msa_ilvod_h((v8i16) tmp1_m, (v8i16) tmp0_m); \
  2321. tmp3_m = (v16u8) __msa_ilvod_h((v8i16) out7, (v8i16) out5); \
  2322. out2 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2323. out6 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2324. \
  2325. ILVEV_H2_UB(tmp4_m, tmp5_m, tmp6_m, tmp7_m, tmp2_m, tmp3_m); \
  2326. out1 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2327. out5 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2328. \
  2329. tmp2_m = (v16u8) __msa_ilvod_h((v8i16) tmp5_m, (v8i16) tmp4_m); \
  2330. tmp3_m = (v16u8) __msa_ilvod_h((v8i16) tmp7_m, (v8i16) tmp6_m); \
  2331. out3 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2332. out7 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2333. }
  2334. /* Description : Transposes 4x4 block with half word elements in vectors
  2335. Arguments : Inputs - in0, in1, in2, in3
  2336. Outputs - out0, out1, out2, out3
  2337. Return Type - signed halfword
  2338. Details :
  2339. */
  2340. #define TRANSPOSE4x4_SH_SH(in0, in1, in2, in3, out0, out1, out2, out3) \
  2341. { \
  2342. v8i16 s0_m, s1_m; \
  2343. \
  2344. ILVR_H2_SH(in1, in0, in3, in2, s0_m, s1_m); \
  2345. ILVRL_W2_SH(s1_m, s0_m, out0, out2); \
  2346. out1 = (v8i16) __msa_ilvl_d((v2i64) out0, (v2i64) out0); \
  2347. out3 = (v8i16) __msa_ilvl_d((v2i64) out0, (v2i64) out2); \
  2348. }
  2349. /* Description : Transposes 8x8 block with half word elements in vectors
  2350. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  2351. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  2352. Return Type - as per RTYPE
  2353. Details :
  2354. */
  2355. #define TRANSPOSE8x8_H(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  2356. out0, out1, out2, out3, out4, out5, out6, out7) \
  2357. { \
  2358. v8i16 s0_m, s1_m; \
  2359. v8i16 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2360. v8i16 tmp4_m, tmp5_m, tmp6_m, tmp7_m; \
  2361. \
  2362. ILVR_H2_SH(in6, in4, in7, in5, s0_m, s1_m); \
  2363. ILVRL_H2_SH(s1_m, s0_m, tmp0_m, tmp1_m); \
  2364. ILVL_H2_SH(in6, in4, in7, in5, s0_m, s1_m); \
  2365. ILVRL_H2_SH(s1_m, s0_m, tmp2_m, tmp3_m); \
  2366. ILVR_H2_SH(in2, in0, in3, in1, s0_m, s1_m); \
  2367. ILVRL_H2_SH(s1_m, s0_m, tmp4_m, tmp5_m); \
  2368. ILVL_H2_SH(in2, in0, in3, in1, s0_m, s1_m); \
  2369. ILVRL_H2_SH(s1_m, s0_m, tmp6_m, tmp7_m); \
  2370. PCKEV_D4(RTYPE, tmp0_m, tmp4_m, tmp1_m, tmp5_m, tmp2_m, tmp6_m, \
  2371. tmp3_m, tmp7_m, out0, out2, out4, out6); \
  2372. out1 = (RTYPE) __msa_pckod_d((v2i64) tmp0_m, (v2i64) tmp4_m); \
  2373. out3 = (RTYPE) __msa_pckod_d((v2i64) tmp1_m, (v2i64) tmp5_m); \
  2374. out5 = (RTYPE) __msa_pckod_d((v2i64) tmp2_m, (v2i64) tmp6_m); \
  2375. out7 = (RTYPE) __msa_pckod_d((v2i64) tmp3_m, (v2i64) tmp7_m); \
  2376. }
  2377. #define TRANSPOSE8x8_UH_UH(...) TRANSPOSE8x8_H(v8u16, __VA_ARGS__)
  2378. #define TRANSPOSE8x8_SH_SH(...) TRANSPOSE8x8_H(v8i16, __VA_ARGS__)
  2379. /* Description : Transposes 4x4 block with word elements in vectors
  2380. Arguments : Inputs - in0, in1, in2, in3
  2381. Outputs - out0, out1, out2, out3
  2382. Return Type - signed word
  2383. Details :
  2384. */
  2385. #define TRANSPOSE4x4_SW_SW(in0, in1, in2, in3, out0, out1, out2, out3) \
  2386. { \
  2387. v4i32 s0_m, s1_m, s2_m, s3_m; \
  2388. \
  2389. ILVRL_W2_SW(in1, in0, s0_m, s1_m); \
  2390. ILVRL_W2_SW(in3, in2, s2_m, s3_m); \
  2391. \
  2392. out0 = (v4i32) __msa_ilvr_d((v2i64) s2_m, (v2i64) s0_m); \
  2393. out1 = (v4i32) __msa_ilvl_d((v2i64) s2_m, (v2i64) s0_m); \
  2394. out2 = (v4i32) __msa_ilvr_d((v2i64) s3_m, (v2i64) s1_m); \
  2395. out3 = (v4i32) __msa_ilvl_d((v2i64) s3_m, (v2i64) s1_m); \
  2396. }
  2397. /* Description : Average byte elements from pair of vectors and store 8x4 byte
  2398. block in destination memory
  2399. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride
  2400. Details : Each byte element from input vector pair 'in0' and 'in1' are
  2401. averaged (a + b)/2 and stored in 'tmp0_m'
  2402. Each byte element from input vector pair 'in2' and 'in3' are
  2403. averaged (a + b)/2 and stored in 'tmp1_m'
  2404. Each byte element from input vector pair 'in4' and 'in5' are
  2405. averaged (a + b)/2 and stored in 'tmp2_m'
  2406. Each byte element from input vector pair 'in6' and 'in7' are
  2407. averaged (a + b)/2 and stored in 'tmp3_m'
  2408. The half vector results from all 4 vectors are stored in
  2409. destination memory as 8x4 byte block
  2410. */
  2411. #define AVE_ST8x4_UB(in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride) \
  2412. { \
  2413. uint64_t out0_m, out1_m, out2_m, out3_m; \
  2414. v16u8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2415. \
  2416. tmp0_m = __msa_ave_u_b((v16u8) in0, (v16u8) in1); \
  2417. tmp1_m = __msa_ave_u_b((v16u8) in2, (v16u8) in3); \
  2418. tmp2_m = __msa_ave_u_b((v16u8) in4, (v16u8) in5); \
  2419. tmp3_m = __msa_ave_u_b((v16u8) in6, (v16u8) in7); \
  2420. \
  2421. out0_m = __msa_copy_u_d((v2i64) tmp0_m, 0); \
  2422. out1_m = __msa_copy_u_d((v2i64) tmp1_m, 0); \
  2423. out2_m = __msa_copy_u_d((v2i64) tmp2_m, 0); \
  2424. out3_m = __msa_copy_u_d((v2i64) tmp3_m, 0); \
  2425. SD4(out0_m, out1_m, out2_m, out3_m, pdst, stride); \
  2426. }
  2427. /* Description : Average byte elements from pair of vectors and store 16x4 byte
  2428. block in destination memory
  2429. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride
  2430. Details : Each byte element from input vector pair 'in0' and 'in1' are
  2431. averaged (a + b)/2 and stored in 'tmp0_m'
  2432. Each byte element from input vector pair 'in2' and 'in3' are
  2433. averaged (a + b)/2 and stored in 'tmp1_m'
  2434. Each byte element from input vector pair 'in4' and 'in5' are
  2435. averaged (a + b)/2 and stored in 'tmp2_m'
  2436. Each byte element from input vector pair 'in6' and 'in7' are
  2437. averaged (a + b)/2 and stored in 'tmp3_m'
  2438. The results from all 4 vectors are stored in destination
  2439. memory as 16x4 byte block
  2440. */
  2441. #define AVE_ST16x4_UB(in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride) \
  2442. { \
  2443. v16u8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2444. \
  2445. tmp0_m = __msa_ave_u_b((v16u8) in0, (v16u8) in1); \
  2446. tmp1_m = __msa_ave_u_b((v16u8) in2, (v16u8) in3); \
  2447. tmp2_m = __msa_ave_u_b((v16u8) in4, (v16u8) in5); \
  2448. tmp3_m = __msa_ave_u_b((v16u8) in6, (v16u8) in7); \
  2449. \
  2450. ST_UB4(tmp0_m, tmp1_m, tmp2_m, tmp3_m, pdst, stride); \
  2451. }
  2452. /* Description : Average rounded byte elements from pair of vectors and store
  2453. 8x4 byte block in destination memory
  2454. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride
  2455. Details : Each byte element from input vector pair 'in0' and 'in1' are
  2456. average rounded (a + b + 1)/2 and stored in 'tmp0_m'
  2457. Each byte element from input vector pair 'in2' and 'in3' are
  2458. average rounded (a + b + 1)/2 and stored in 'tmp1_m'
  2459. Each byte element from input vector pair 'in4' and 'in5' are
  2460. average rounded (a + b + 1)/2 and stored in 'tmp2_m'
  2461. Each byte element from input vector pair 'in6' and 'in7' are
  2462. average rounded (a + b + 1)/2 and stored in 'tmp3_m'
  2463. The half vector results from all 4 vectors are stored in
  2464. destination memory as 8x4 byte block
  2465. */
  2466. #define AVER_ST8x4_UB(in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride) \
  2467. { \
  2468. uint64_t out0_m, out1_m, out2_m, out3_m; \
  2469. v16u8 tp0_m, tp1_m, tp2_m, tp3_m; \
  2470. \
  2471. AVER_UB4_UB(in0, in1, in2, in3, in4, in5, in6, in7, \
  2472. tp0_m, tp1_m, tp2_m, tp3_m); \
  2473. \
  2474. out0_m = __msa_copy_u_d((v2i64) tp0_m, 0); \
  2475. out1_m = __msa_copy_u_d((v2i64) tp1_m, 0); \
  2476. out2_m = __msa_copy_u_d((v2i64) tp2_m, 0); \
  2477. out3_m = __msa_copy_u_d((v2i64) tp3_m, 0); \
  2478. SD4(out0_m, out1_m, out2_m, out3_m, pdst, stride); \
  2479. }
  2480. /* Description : Average rounded byte elements from pair of vectors and store
  2481. 16x4 byte block in destination memory
  2482. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride
  2483. Details : Each byte element from input vector pair 'in0' and 'in1' are
  2484. average rounded (a + b + 1)/2 and stored in 'tmp0_m'
  2485. Each byte element from input vector pair 'in2' and 'in3' are
  2486. average rounded (a + b + 1)/2 and stored in 'tmp1_m'
  2487. Each byte element from input vector pair 'in4' and 'in5' are
  2488. average rounded (a + b + 1)/2 and stored in 'tmp2_m'
  2489. Each byte element from input vector pair 'in6' and 'in7' are
  2490. average rounded (a + b + 1)/2 and stored in 'tmp3_m'
  2491. The vector results from all 4 vectors are stored in
  2492. destination memory as 16x4 byte block
  2493. */
  2494. #define AVER_ST16x4_UB(in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride) \
  2495. { \
  2496. v16u8 t0_m, t1_m, t2_m, t3_m; \
  2497. \
  2498. AVER_UB4_UB(in0, in1, in2, in3, in4, in5, in6, in7, \
  2499. t0_m, t1_m, t2_m, t3_m); \
  2500. ST_UB4(t0_m, t1_m, t2_m, t3_m, pdst, stride); \
  2501. }
  2502. /* Description : Average rounded byte elements from pair of vectors,
  2503. average rounded with destination and store 8x4 byte block
  2504. in destination memory
  2505. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride
  2506. Details : Each byte element from input vector pair 'in0' and 'in1' are
  2507. average rounded (a + b + 1)/2 and stored in 'tmp0_m'
  2508. Each byte element from input vector pair 'in2' and 'in3' are
  2509. average rounded (a + b + 1)/2 and stored in 'tmp1_m'
  2510. Each byte element from input vector pair 'in4' and 'in5' are
  2511. average rounded (a + b + 1)/2 and stored in 'tmp2_m'
  2512. Each byte element from input vector pair 'in6' and 'in7' are
  2513. average rounded (a + b + 1)/2 and stored in 'tmp3_m'
  2514. The half vector results from all 4 vectors are stored in
  2515. destination memory as 8x4 byte block
  2516. */
  2517. #define AVER_DST_ST8x4_UB(in0, in1, in2, in3, in4, in5, in6, in7, \
  2518. pdst, stride) \
  2519. { \
  2520. v16u8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2521. v16u8 dst0_m, dst1_m, dst2_m, dst3_m; \
  2522. \
  2523. LD_UB4(pdst, stride, dst0_m, dst1_m, dst2_m, dst3_m); \
  2524. AVER_UB4_UB(in0, in1, in2, in3, in4, in5, in6, in7, \
  2525. tmp0_m, tmp1_m, tmp2_m, tmp3_m); \
  2526. AVER_ST8x4_UB(dst0_m, tmp0_m, dst1_m, tmp1_m, \
  2527. dst2_m, tmp2_m, dst3_m, tmp3_m, pdst, stride); \
  2528. }
  2529. /* Description : Average rounded byte elements from pair of vectors,
  2530. average rounded with destination and store 16x4 byte block
  2531. in destination memory
  2532. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride
  2533. Details : Each byte element from input vector pair 'in0' and 'in1' are
  2534. average rounded (a + b + 1)/2 and stored in 'tmp0_m'
  2535. Each byte element from input vector pair 'in2' and 'in3' are
  2536. average rounded (a + b + 1)/2 and stored in 'tmp1_m'
  2537. Each byte element from input vector pair 'in4' and 'in5' are
  2538. average rounded (a + b + 1)/2 and stored in 'tmp2_m'
  2539. Each byte element from input vector pair 'in6' and 'in7' are
  2540. average rounded (a + b + 1)/2 and stored in 'tmp3_m'
  2541. The vector results from all 4 vectors are stored in
  2542. destination memory as 16x4 byte block
  2543. */
  2544. #define AVER_DST_ST16x4_UB(in0, in1, in2, in3, in4, in5, in6, in7, \
  2545. pdst, stride) \
  2546. { \
  2547. v16u8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2548. v16u8 dst0_m, dst1_m, dst2_m, dst3_m; \
  2549. \
  2550. LD_UB4(pdst, stride, dst0_m, dst1_m, dst2_m, dst3_m); \
  2551. AVER_UB4_UB(in0, in1, in2, in3, in4, in5, in6, in7, \
  2552. tmp0_m, tmp1_m, tmp2_m, tmp3_m); \
  2553. AVER_ST16x4_UB(dst0_m, tmp0_m, dst1_m, tmp1_m, \
  2554. dst2_m, tmp2_m, dst3_m, tmp3_m, pdst, stride); \
  2555. }
  2556. /* Description : Add block 4x4
  2557. Arguments : Inputs - in0, in1, in2, in3, pdst, stride
  2558. Details : Least significant 4 bytes from each input vector are added to
  2559. the destination bytes, clipped between 0-255 and then stored.
  2560. */
  2561. #define ADDBLK_ST4x4_UB(in0, in1, in2, in3, pdst, stride) \
  2562. { \
  2563. uint32_t src0_m, src1_m, src2_m, src3_m; \
  2564. uint32_t out0_m, out1_m, out2_m, out3_m; \
  2565. v8i16 inp0_m, inp1_m, res0_m, res1_m; \
  2566. v16i8 dst0_m = { 0 }; \
  2567. v16i8 dst1_m = { 0 }; \
  2568. v16i8 zero_m = { 0 }; \
  2569. \
  2570. ILVR_D2_SH(in1, in0, in3, in2, inp0_m, inp1_m) \
  2571. LW4(pdst, stride, src0_m, src1_m, src2_m, src3_m); \
  2572. INSERT_W2_SB(src0_m, src1_m, dst0_m); \
  2573. INSERT_W2_SB(src2_m, src3_m, dst1_m); \
  2574. ILVR_B2_SH(zero_m, dst0_m, zero_m, dst1_m, res0_m, res1_m); \
  2575. ADD2(res0_m, inp0_m, res1_m, inp1_m, res0_m, res1_m); \
  2576. CLIP_SH2_0_255(res0_m, res1_m); \
  2577. PCKEV_B2_SB(res0_m, res0_m, res1_m, res1_m, dst0_m, dst1_m); \
  2578. \
  2579. out0_m = __msa_copy_u_w((v4i32) dst0_m, 0); \
  2580. out1_m = __msa_copy_u_w((v4i32) dst0_m, 1); \
  2581. out2_m = __msa_copy_u_w((v4i32) dst1_m, 0); \
  2582. out3_m = __msa_copy_u_w((v4i32) dst1_m, 1); \
  2583. SW4(out0_m, out1_m, out2_m, out3_m, pdst, stride); \
  2584. }
  2585. /* Description : Dot product and addition of 3 signed halfword input vectors
  2586. Arguments : Inputs - in0, in1, in2, coeff0, coeff1, coeff2
  2587. Outputs - out0_m
  2588. Return Type - signed halfword
  2589. Details : Dot product of 'in0' with 'coeff0'
  2590. Dot product of 'in1' with 'coeff1'
  2591. Dot product of 'in2' with 'coeff2'
  2592. Addition of all the 3 vector results
  2593. out0_m = (in0 * coeff0) + (in1 * coeff1) + (in2 * coeff2)
  2594. */
  2595. #define DPADD_SH3_SH(in0, in1, in2, coeff0, coeff1, coeff2) \
  2596. ( { \
  2597. v8i16 out0_m; \
  2598. \
  2599. out0_m = __msa_dotp_s_h((v16i8) in0, (v16i8) coeff0); \
  2600. out0_m = __msa_dpadd_s_h(out0_m, (v16i8) in1, (v16i8) coeff1); \
  2601. out0_m = __msa_dpadd_s_h(out0_m, (v16i8) in2, (v16i8) coeff2); \
  2602. \
  2603. out0_m; \
  2604. } )
  2605. /* Description : Pack even elements of input vectors & xor with 128
  2606. Arguments : Inputs - in0, in1
  2607. Outputs - out_m
  2608. Return Type - unsigned byte
  2609. Details : Signed byte even elements from 'in0' and 'in1' are packed
  2610. together in one vector and the resulted vector is xor'ed with
  2611. 128 to shift the range from signed to unsigned byte
  2612. */
  2613. #define PCKEV_XORI128_UB(in0, in1) \
  2614. ( { \
  2615. v16u8 out_m; \
  2616. out_m = (v16u8) __msa_pckev_b((v16i8) in1, (v16i8) in0); \
  2617. out_m = (v16u8) __msa_xori_b((v16u8) out_m, 128); \
  2618. out_m; \
  2619. } )
  2620. /* Description : Converts inputs to unsigned bytes, interleave, average & store
  2621. as 8x4 unsigned byte block
  2622. Arguments : Inputs - in0, in1, in2, in3, dst0, dst1, pdst, stride
  2623. */
  2624. #define CONVERT_UB_AVG_ST8x4_UB(in0, in1, in2, in3, \
  2625. dst0, dst1, pdst, stride) \
  2626. { \
  2627. v16u8 tmp0_m, tmp1_m; \
  2628. uint8_t *pdst_m = (uint8_t *) (pdst); \
  2629. \
  2630. tmp0_m = PCKEV_XORI128_UB(in0, in1); \
  2631. tmp1_m = PCKEV_XORI128_UB(in2, in3); \
  2632. AVER_UB2_UB(tmp0_m, dst0, tmp1_m, dst1, tmp0_m, tmp1_m); \
  2633. ST_D4(tmp0_m, tmp1_m, 0, 1, 0, 1, pdst_m, stride); \
  2634. }
  2635. /* Description : Pack even byte elements, extract 0 & 2 index words from pair
  2636. of results and store 4 words in destination memory as per
  2637. stride
  2638. Arguments : Inputs - in0, in1, in2, in3, pdst, stride
  2639. */
  2640. #define PCKEV_ST4x4_UB(in0, in1, in2, in3, pdst, stride) \
  2641. { \
  2642. uint32_t out0_m, out1_m, out2_m, out3_m; \
  2643. v16i8 tmp0_m, tmp1_m; \
  2644. \
  2645. PCKEV_B2_SB(in1, in0, in3, in2, tmp0_m, tmp1_m); \
  2646. \
  2647. out0_m = __msa_copy_u_w((v4i32) tmp0_m, 0); \
  2648. out1_m = __msa_copy_u_w((v4i32) tmp0_m, 2); \
  2649. out2_m = __msa_copy_u_w((v4i32) tmp1_m, 0); \
  2650. out3_m = __msa_copy_u_w((v4i32) tmp1_m, 2); \
  2651. \
  2652. SW4(out0_m, out1_m, out2_m, out3_m, pdst, stride); \
  2653. }
  2654. /* Description : Pack even byte elements and store byte vector in destination
  2655. memory
  2656. Arguments : Inputs - in0, in1, pdst
  2657. */
  2658. #define PCKEV_ST_SB(in0, in1, pdst) \
  2659. { \
  2660. v16i8 tmp_m; \
  2661. tmp_m = __msa_pckev_b((v16i8) in1, (v16i8) in0); \
  2662. ST_SB(tmp_m, (pdst)); \
  2663. }
  2664. /* Description : Horizontal 2 tap filter kernel code
  2665. Arguments : Inputs - in0, in1, mask, coeff, shift
  2666. */
  2667. #define HORIZ_2TAP_FILT_UH(in0, in1, mask, coeff, shift) \
  2668. ( { \
  2669. v16i8 tmp0_m; \
  2670. v8u16 tmp1_m; \
  2671. \
  2672. tmp0_m = __msa_vshf_b((v16i8) mask, (v16i8) in1, (v16i8) in0); \
  2673. tmp1_m = __msa_dotp_u_h((v16u8) tmp0_m, (v16u8) coeff); \
  2674. tmp1_m = (v8u16) __msa_srari_h((v8i16) tmp1_m, shift); \
  2675. tmp1_m = __msa_sat_u_h(tmp1_m, shift); \
  2676. \
  2677. tmp1_m; \
  2678. } )
  2679. #endif /* AVUTIL_MIPS_GENERIC_MACROS_MSA_H */