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.

2838 lines
142KB

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