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.

2868 lines
143KB

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