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.

2821 lines
141KB

  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 both left and right half of input vectors
  1430. Arguments : Inputs - in0, in1
  1431. Outputs - out0, out1
  1432. Return Type - as per RTYPE
  1433. Details : Right half of byte elements from 'in0' and 'in1' are
  1434. interleaved and stored to 'out0'
  1435. Left half of byte elements from 'in0' and 'in1' are
  1436. interleaved and stored to 'out1'
  1437. */
  1438. #define ILVRL_B2(RTYPE, in0, in1, out0, out1) \
  1439. { \
  1440. out0 = (RTYPE) __msa_ilvr_b((v16i8) in0, (v16i8) in1); \
  1441. out1 = (RTYPE) __msa_ilvl_b((v16i8) in0, (v16i8) in1); \
  1442. }
  1443. #define ILVRL_B2_UB(...) ILVRL_B2(v16u8, __VA_ARGS__)
  1444. #define ILVRL_B2_SB(...) ILVRL_B2(v16i8, __VA_ARGS__)
  1445. #define ILVRL_B2_UH(...) ILVRL_B2(v8u16, __VA_ARGS__)
  1446. #define ILVRL_B2_SH(...) ILVRL_B2(v8i16, __VA_ARGS__)
  1447. #define ILVRL_B2_SW(...) ILVRL_B2(v4i32, __VA_ARGS__)
  1448. #define ILVRL_H2(RTYPE, in0, in1, out0, out1) \
  1449. { \
  1450. out0 = (RTYPE) __msa_ilvr_h((v8i16) in0, (v8i16) in1); \
  1451. out1 = (RTYPE) __msa_ilvl_h((v8i16) in0, (v8i16) in1); \
  1452. }
  1453. #define ILVRL_H2_SB(...) ILVRL_H2(v16i8, __VA_ARGS__)
  1454. #define ILVRL_H2_SH(...) ILVRL_H2(v8i16, __VA_ARGS__)
  1455. #define ILVRL_H2_SW(...) ILVRL_H2(v4i32, __VA_ARGS__)
  1456. #define ILVRL_W2(RTYPE, in0, in1, out0, out1) \
  1457. { \
  1458. out0 = (RTYPE) __msa_ilvr_w((v4i32) in0, (v4i32) in1); \
  1459. out1 = (RTYPE) __msa_ilvl_w((v4i32) in0, (v4i32) in1); \
  1460. }
  1461. #define ILVRL_W2_UB(...) ILVRL_W2(v16u8, __VA_ARGS__)
  1462. #define ILVRL_W2_SH(...) ILVRL_W2(v8i16, __VA_ARGS__)
  1463. #define ILVRL_W2_SW(...) ILVRL_W2(v4i32, __VA_ARGS__)
  1464. /* Description : Maximum values between signed elements of vector and
  1465. 5-bit signed immediate value are copied to the output vector
  1466. Arguments : Inputs - in0, in1, in2, in3, max_val
  1467. Outputs - in0, in1, in2, in3 (in place)
  1468. Return Type - as per RTYPE
  1469. Details : Maximum of signed halfword element values from 'in0' and
  1470. 'max_val' are written to output vector 'in0'
  1471. */
  1472. #define MAXI_SH2(RTYPE, in0, in1, max_val) \
  1473. { \
  1474. in0 = (RTYPE) __msa_maxi_s_h((v8i16) in0, max_val); \
  1475. in1 = (RTYPE) __msa_maxi_s_h((v8i16) in1, max_val); \
  1476. }
  1477. #define MAXI_SH2_UH(...) MAXI_SH2(v8u16, __VA_ARGS__)
  1478. #define MAXI_SH2_SH(...) MAXI_SH2(v8i16, __VA_ARGS__)
  1479. #define MAXI_SH4(RTYPE, in0, in1, in2, in3, max_val) \
  1480. { \
  1481. MAXI_SH2(RTYPE, in0, in1, max_val); \
  1482. MAXI_SH2(RTYPE, in2, in3, max_val); \
  1483. }
  1484. #define MAXI_SH4_UH(...) MAXI_SH4(v8u16, __VA_ARGS__)
  1485. /* Description : Saturate the halfword element values to the max
  1486. unsigned value of (sat_val+1 bits)
  1487. The element data width remains unchanged
  1488. Arguments : Inputs - in0, in1, in2, in3, sat_val
  1489. Outputs - in0, in1, in2, in3 (in place)
  1490. Return Type - as per RTYPE
  1491. Details : Each unsigned halfword element from 'in0' is saturated to the
  1492. value generated with (sat_val+1) bit range
  1493. Results are in placed to original vectors
  1494. */
  1495. #define SAT_UH2(RTYPE, in0, in1, sat_val) \
  1496. { \
  1497. in0 = (RTYPE) __msa_sat_u_h((v8u16) in0, sat_val); \
  1498. in1 = (RTYPE) __msa_sat_u_h((v8u16) in1, sat_val); \
  1499. }
  1500. #define SAT_UH2_UH(...) SAT_UH2(v8u16, __VA_ARGS__)
  1501. #define SAT_UH2_SH(...) SAT_UH2(v8i16, __VA_ARGS__)
  1502. #define SAT_UH4(RTYPE, in0, in1, in2, in3, sat_val) \
  1503. { \
  1504. SAT_UH2(RTYPE, in0, in1, sat_val); \
  1505. SAT_UH2(RTYPE, in2, in3, sat_val); \
  1506. }
  1507. #define SAT_UH4_UH(...) SAT_UH4(v8u16, __VA_ARGS__)
  1508. /* Description : Saturate the halfword element values to the max
  1509. unsigned value of (sat_val+1 bits)
  1510. The element data width remains unchanged
  1511. Arguments : Inputs - in0, in1, in2, in3, sat_val
  1512. Outputs - in0, in1, in2, in3 (in place)
  1513. Return Type - as per RTYPE
  1514. Details : Each unsigned halfword element from 'in0' is saturated to the
  1515. value generated with (sat_val+1) bit range
  1516. Results are in placed to original vectors
  1517. */
  1518. #define SAT_SH2(RTYPE, in0, in1, sat_val) \
  1519. { \
  1520. in0 = (RTYPE) __msa_sat_s_h((v8i16) in0, sat_val); \
  1521. in1 = (RTYPE) __msa_sat_s_h((v8i16) in1, sat_val); \
  1522. }
  1523. #define SAT_SH2_SH(...) SAT_SH2(v8i16, __VA_ARGS__)
  1524. #define SAT_SH3(RTYPE, in0, in1, in2, sat_val) \
  1525. { \
  1526. SAT_SH2(RTYPE, in0, in1, sat_val); \
  1527. in2 = (RTYPE) __msa_sat_s_h((v8i16) in2, sat_val); \
  1528. }
  1529. #define SAT_SH3_SH(...) SAT_SH3(v8i16, __VA_ARGS__)
  1530. #define SAT_SH4(RTYPE, in0, in1, in2, in3, sat_val) \
  1531. { \
  1532. SAT_SH2(RTYPE, in0, in1, sat_val); \
  1533. SAT_SH2(RTYPE, in2, in3, sat_val); \
  1534. }
  1535. #define SAT_SH4_SH(...) SAT_SH4(v8i16, __VA_ARGS__)
  1536. /* Description : Saturate the word element values to the max
  1537. unsigned value of (sat_val+1 bits)
  1538. The element data width remains unchanged
  1539. Arguments : Inputs - in0, in1, in2, in3, sat_val
  1540. Outputs - in0, in1, in2, in3 (in place)
  1541. Return Type - as per RTYPE
  1542. Details : Each unsigned word element from 'in0' is saturated to the
  1543. value generated with (sat_val+1) bit range
  1544. Results are in placed to original vectors
  1545. */
  1546. #define SAT_SW2(RTYPE, in0, in1, sat_val) \
  1547. { \
  1548. in0 = (RTYPE) __msa_sat_s_w((v4i32) in0, sat_val); \
  1549. in1 = (RTYPE) __msa_sat_s_w((v4i32) in1, sat_val); \
  1550. }
  1551. #define SAT_SW2_SW(...) SAT_SW2(v4i32, __VA_ARGS__)
  1552. #define SAT_SW4(RTYPE, in0, in1, in2, in3, sat_val) \
  1553. { \
  1554. SAT_SW2(RTYPE, in0, in1, sat_val); \
  1555. SAT_SW2(RTYPE, in2, in3, sat_val); \
  1556. }
  1557. #define SAT_SW4_SW(...) SAT_SW4(v4i32, __VA_ARGS__)
  1558. /* Description : Indexed halfword element values are replicated to all
  1559. elements in output vector
  1560. Arguments : Inputs - in, idx0, idx1
  1561. Outputs - out0, out1
  1562. Return Type - as per RTYPE
  1563. Details : 'idx0' element value from 'in' vector is replicated to all
  1564. elements in 'out0' vector
  1565. Valid index range for halfword operation is 0-7
  1566. */
  1567. #define SPLATI_H2(RTYPE, in, idx0, idx1, out0, out1) \
  1568. { \
  1569. out0 = (RTYPE) __msa_splati_h((v8i16) in, idx0); \
  1570. out1 = (RTYPE) __msa_splati_h((v8i16) in, idx1); \
  1571. }
  1572. #define SPLATI_H2_SB(...) SPLATI_H2(v16i8, __VA_ARGS__)
  1573. #define SPLATI_H2_SH(...) SPLATI_H2(v8i16, __VA_ARGS__)
  1574. #define SPLATI_H3(RTYPE, in, idx0, idx1, idx2, \
  1575. out0, out1, out2) \
  1576. { \
  1577. SPLATI_H2(RTYPE, in, idx0, idx1, out0, out1); \
  1578. out2 = (RTYPE) __msa_splati_h((v8i16) in, idx2); \
  1579. }
  1580. #define SPLATI_H3_SB(...) SPLATI_H3(v16i8, __VA_ARGS__)
  1581. #define SPLATI_H3_SH(...) SPLATI_H3(v8i16, __VA_ARGS__)
  1582. #define SPLATI_H4(RTYPE, in, idx0, idx1, idx2, idx3, \
  1583. out0, out1, out2, out3) \
  1584. { \
  1585. SPLATI_H2(RTYPE, in, idx0, idx1, out0, out1); \
  1586. SPLATI_H2(RTYPE, in, idx2, idx3, out2, out3); \
  1587. }
  1588. #define SPLATI_H4_SB(...) SPLATI_H4(v16i8, __VA_ARGS__)
  1589. #define SPLATI_H4_SH(...) SPLATI_H4(v8i16, __VA_ARGS__)
  1590. /* Description : Indexed word element values are replicated to all
  1591. elements in output vector
  1592. Arguments : Inputs - in, stidx
  1593. Outputs - out0, out1
  1594. Return Type - as per RTYPE
  1595. Details : 'stidx' element value from 'in' vector is replicated to all
  1596. elements in 'out0' vector
  1597. 'stidx + 1' element value from 'in' vector is replicated to all
  1598. elements in 'out1' vector
  1599. Valid index range for halfword operation is 0-3
  1600. */
  1601. #define SPLATI_W2(RTYPE, in, stidx, out0, out1) \
  1602. { \
  1603. out0 = (RTYPE) __msa_splati_w((v4i32) in, stidx); \
  1604. out1 = (RTYPE) __msa_splati_w((v4i32) in, (stidx+1)); \
  1605. }
  1606. #define SPLATI_W2_SH(...) SPLATI_W2(v8i16, __VA_ARGS__)
  1607. #define SPLATI_W2_SW(...) SPLATI_W2(v4i32, __VA_ARGS__)
  1608. #define SPLATI_W4(RTYPE, in, out0, out1, out2, out3) \
  1609. { \
  1610. SPLATI_W2(RTYPE, in, 0, out0, out1); \
  1611. SPLATI_W2(RTYPE, in, 2, out2, out3); \
  1612. }
  1613. #define SPLATI_W4_SH(...) SPLATI_W4(v8i16, __VA_ARGS__)
  1614. #define SPLATI_W4_SW(...) SPLATI_W4(v4i32, __VA_ARGS__)
  1615. /* Description : Pack even byte elements of vector pairs
  1616. Arguments : Inputs - in0, in1, in2, in3
  1617. Outputs - out0, out1
  1618. Return Type - as per RTYPE
  1619. Details : Even byte elements of in0 are copied to the left half of
  1620. out0 & even byte elements of in1 are copied to the right
  1621. half of out0.
  1622. Even byte elements of in2 are copied to the left half of
  1623. out1 & even byte elements of in3 are copied to the right
  1624. half of out1.
  1625. */
  1626. #define PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1627. { \
  1628. out0 = (RTYPE) __msa_pckev_b((v16i8) in0, (v16i8) in1); \
  1629. out1 = (RTYPE) __msa_pckev_b((v16i8) in2, (v16i8) in3); \
  1630. }
  1631. #define PCKEV_B2_SB(...) PCKEV_B2(v16i8, __VA_ARGS__)
  1632. #define PCKEV_B2_UB(...) PCKEV_B2(v16u8, __VA_ARGS__)
  1633. #define PCKEV_B2_SH(...) PCKEV_B2(v8i16, __VA_ARGS__)
  1634. #define PCKEV_B2_SW(...) PCKEV_B2(v4i32, __VA_ARGS__)
  1635. #define PCKEV_B3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1636. { \
  1637. PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1638. out2 = (RTYPE) __msa_pckev_b((v16i8) in4, (v16i8) in5); \
  1639. }
  1640. #define PCKEV_B3_UB(...) PCKEV_B3(v16u8, __VA_ARGS__)
  1641. #define PCKEV_B3_SB(...) PCKEV_B3(v16i8, __VA_ARGS__)
  1642. #define PCKEV_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1643. out0, out1, out2, out3) \
  1644. { \
  1645. PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1646. PCKEV_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1647. }
  1648. #define PCKEV_B4_SB(...) PCKEV_B4(v16i8, __VA_ARGS__)
  1649. #define PCKEV_B4_UB(...) PCKEV_B4(v16u8, __VA_ARGS__)
  1650. #define PCKEV_B4_SH(...) PCKEV_B4(v8i16, __VA_ARGS__)
  1651. #define PCKEV_B4_SW(...) PCKEV_B4(v4i32, __VA_ARGS__)
  1652. /* Description : Pack even halfword elements of vector pairs
  1653. Arguments : Inputs - in0, in1, in2, in3
  1654. Outputs - out0, out1
  1655. Return Type - as per RTYPE
  1656. Details : Even halfword elements of in0 are copied to the left half of
  1657. out0 & even halfword elements of in1 are copied to the right
  1658. half of out0.
  1659. Even halfword elements of in2 are copied to the left half of
  1660. out1 & even halfword elements of in3 are copied to the right
  1661. half of out1.
  1662. */
  1663. #define PCKEV_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1664. { \
  1665. out0 = (RTYPE) __msa_pckev_h((v8i16) in0, (v8i16) in1); \
  1666. out1 = (RTYPE) __msa_pckev_h((v8i16) in2, (v8i16) in3); \
  1667. }
  1668. #define PCKEV_H2_SH(...) PCKEV_H2(v8i16, __VA_ARGS__)
  1669. #define PCKEV_H2_SW(...) PCKEV_H2(v4i32, __VA_ARGS__)
  1670. #define PCKEV_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1671. out0, out1, out2, out3) \
  1672. { \
  1673. PCKEV_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1674. PCKEV_H2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1675. }
  1676. #define PCKEV_H4_SH(...) PCKEV_H4(v8i16, __VA_ARGS__)
  1677. #define PCKEV_H4_SW(...) PCKEV_H4(v4i32, __VA_ARGS__)
  1678. /* Description : Pack even double word elements of vector pairs
  1679. Arguments : Inputs - in0, in1, in2, in3
  1680. Outputs - out0, out1
  1681. Return Type - as per RTYPE
  1682. Details : Even double elements of in0 are copied to the left half of
  1683. out0 & even double elements of in1 are copied to the right
  1684. half of out0.
  1685. Even double elements of in2 are copied to the left half of
  1686. out1 & even double elements of in3 are copied to the right
  1687. half of out1.
  1688. */
  1689. #define PCKEV_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1690. { \
  1691. out0 = (RTYPE) __msa_pckev_d((v2i64) in0, (v2i64) in1); \
  1692. out1 = (RTYPE) __msa_pckev_d((v2i64) in2, (v2i64) in3); \
  1693. }
  1694. #define PCKEV_D2_UB(...) PCKEV_D2(v16u8, __VA_ARGS__)
  1695. #define PCKEV_D2_SB(...) PCKEV_D2(v16i8, __VA_ARGS__)
  1696. #define PCKEV_D2_SH(...) PCKEV_D2(v8i16, __VA_ARGS__)
  1697. #define PCKEV_D4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1698. out0, out1, out2, out3) \
  1699. { \
  1700. PCKEV_D2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1701. PCKEV_D2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1702. }
  1703. #define PCKEV_D4_UB(...) PCKEV_D4(v16u8, __VA_ARGS__)
  1704. /* Description : Pack odd double word elements of vector pairs
  1705. Arguments : Inputs - in0, in1
  1706. Outputs - out0, out1
  1707. Return Type - as per RTYPE
  1708. Details : As operation is on same input 'in0' vector, index 1 double word
  1709. element is overwritten to index 0 and result is written to out0
  1710. As operation is on same input 'in1' vector, index 1 double word
  1711. element is overwritten to index 0 and result is written to out1
  1712. */
  1713. #define PCKOD_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1714. { \
  1715. out0 = (RTYPE) __msa_pckod_d((v2i64) in0, (v2i64) in1); \
  1716. out1 = (RTYPE) __msa_pckod_d((v2i64) in2, (v2i64) in3); \
  1717. }
  1718. #define PCKOD_D2_UB(...) PCKOD_D2(v16u8, __VA_ARGS__)
  1719. #define PCKOD_D2_SH(...) PCKOD_D2(v8i16, __VA_ARGS__)
  1720. #define PCKOD_D2_SD(...) PCKOD_D2(v2i64, __VA_ARGS__)
  1721. /* Description : Each byte element is logically xor'ed with immediate 128
  1722. Arguments : Inputs - in0, in1
  1723. Outputs - in0, in1 (in-place)
  1724. Return Type - as per RTYPE
  1725. Details : Each unsigned byte element from input vector 'in0' is
  1726. logically xor'ed with 128 and result is in-place stored in
  1727. 'in0' vector
  1728. Each unsigned byte element from input vector 'in1' is
  1729. logically xor'ed with 128 and result is in-place stored in
  1730. 'in1' vector
  1731. Similar for other pairs
  1732. */
  1733. #define XORI_B2_128(RTYPE, in0, in1) \
  1734. { \
  1735. in0 = (RTYPE) __msa_xori_b((v16u8) in0, 128); \
  1736. in1 = (RTYPE) __msa_xori_b((v16u8) in1, 128); \
  1737. }
  1738. #define XORI_B2_128_UB(...) XORI_B2_128(v16u8, __VA_ARGS__)
  1739. #define XORI_B2_128_SB(...) XORI_B2_128(v16i8, __VA_ARGS__)
  1740. #define XORI_B2_128_SH(...) XORI_B2_128(v8i16, __VA_ARGS__)
  1741. #define XORI_B3_128(RTYPE, in0, in1, in2) \
  1742. { \
  1743. XORI_B2_128(RTYPE, in0, in1); \
  1744. in2 = (RTYPE) __msa_xori_b((v16u8) in2, 128); \
  1745. }
  1746. #define XORI_B3_128_SB(...) XORI_B3_128(v16i8, __VA_ARGS__)
  1747. #define XORI_B4_128(RTYPE, in0, in1, in2, in3) \
  1748. { \
  1749. XORI_B2_128(RTYPE, in0, in1); \
  1750. XORI_B2_128(RTYPE, in2, in3); \
  1751. }
  1752. #define XORI_B4_128_UB(...) XORI_B4_128(v16u8, __VA_ARGS__)
  1753. #define XORI_B4_128_SB(...) XORI_B4_128(v16i8, __VA_ARGS__)
  1754. #define XORI_B4_128_SH(...) XORI_B4_128(v8i16, __VA_ARGS__)
  1755. #define XORI_B5_128(RTYPE, in0, in1, in2, in3, in4) \
  1756. { \
  1757. XORI_B3_128(RTYPE, in0, in1, in2); \
  1758. XORI_B2_128(RTYPE, in3, in4); \
  1759. }
  1760. #define XORI_B5_128_SB(...) XORI_B5_128(v16i8, __VA_ARGS__)
  1761. #define XORI_B6_128(RTYPE, in0, in1, in2, in3, in4, in5) \
  1762. { \
  1763. XORI_B4_128(RTYPE, in0, in1, in2, in3); \
  1764. XORI_B2_128(RTYPE, in4, in5); \
  1765. }
  1766. #define XORI_B6_128_SB(...) XORI_B6_128(v16i8, __VA_ARGS__)
  1767. #define XORI_B7_128(RTYPE, in0, in1, in2, in3, in4, in5, in6) \
  1768. { \
  1769. XORI_B4_128(RTYPE, in0, in1, in2, in3); \
  1770. XORI_B3_128(RTYPE, in4, in5, in6); \
  1771. }
  1772. #define XORI_B7_128_SB(...) XORI_B7_128(v16i8, __VA_ARGS__)
  1773. #define XORI_B8_128(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7) \
  1774. { \
  1775. XORI_B4_128(RTYPE, in0, in1, in2, in3); \
  1776. XORI_B4_128(RTYPE, in4, in5, in6, in7); \
  1777. }
  1778. #define XORI_B8_128_SB(...) XORI_B8_128(v16i8, __VA_ARGS__)
  1779. /* Description : Addition of signed halfword elements and signed saturation
  1780. Arguments : Inputs - in0, in1, in2, in3
  1781. Outputs - out0, out1
  1782. Return Type - as per RTYPE
  1783. Details : Signed halfword elements from 'in0' are added to signed
  1784. halfword elements of 'in1'. The result is then signed saturated
  1785. between -32768 to +32767 (as per halfword data type)
  1786. Similar for other pairs
  1787. */
  1788. #define ADDS_SH2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1789. { \
  1790. out0 = (RTYPE) __msa_adds_s_h((v8i16) in0, (v8i16) in1); \
  1791. out1 = (RTYPE) __msa_adds_s_h((v8i16) in2, (v8i16) in3); \
  1792. }
  1793. #define ADDS_SH2_SH(...) ADDS_SH2(v8i16, __VA_ARGS__)
  1794. #define ADDS_SH4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1795. out0, out1, out2, out3) \
  1796. { \
  1797. ADDS_SH2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1798. ADDS_SH2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1799. }
  1800. #define ADDS_SH4_UH(...) ADDS_SH4(v8u16, __VA_ARGS__)
  1801. #define ADDS_SH4_SH(...) ADDS_SH4(v8i16, __VA_ARGS__)
  1802. /* Description : Shift left all elements of vector (generic for all data types)
  1803. Arguments : Inputs - in0, in1, in2, in3, shift
  1804. Outputs - in0, in1, in2, in3 (in place)
  1805. Return Type - as per input vector RTYPE
  1806. Details : Each element of vector 'in0' is left shifted by 'shift' and
  1807. result is in place written to 'in0'
  1808. Similar for other pairs
  1809. */
  1810. #define SLLI_4V(in0, in1, in2, in3, shift) \
  1811. { \
  1812. in0 = in0 << shift; \
  1813. in1 = in1 << shift; \
  1814. in2 = in2 << shift; \
  1815. in3 = in3 << shift; \
  1816. }
  1817. /* Description : Arithmetic shift right all elements of vector
  1818. (generic for all data types)
  1819. Arguments : Inputs - in0, in1, in2, in3, shift
  1820. Outputs - in0, in1, in2, in3 (in place)
  1821. Return Type - as per input vector RTYPE
  1822. Details : Each element of vector 'in0' is right shifted by 'shift' and
  1823. result is in place written to 'in0'
  1824. Here, 'shift' is GP variable passed in
  1825. Similar for other pairs
  1826. */
  1827. #define SRA_4V(in0, in1, in2, in3, shift) \
  1828. { \
  1829. in0 = in0 >> shift; \
  1830. in1 = in1 >> shift; \
  1831. in2 = in2 >> shift; \
  1832. in3 = in3 >> shift; \
  1833. }
  1834. /* Description : Shift right logical all halfword elements of vector
  1835. Arguments : Inputs - in0, in1, in2, in3, shift
  1836. Outputs - in0, in1, in2, in3 (in place)
  1837. Return Type - as per RTYPE
  1838. Details : Each element of vector 'in0' is shifted right logical by
  1839. number of bits respective element holds in vector 'shift' and
  1840. result is in place written to 'in0'
  1841. Here, 'shift' is a vector passed in
  1842. Similar for other pairs
  1843. */
  1844. #define SRL_H4(RTYPE, in0, in1, in2, in3, shift) \
  1845. { \
  1846. in0 = (RTYPE) __msa_srl_h((v8i16) in0, (v8i16) shift); \
  1847. in1 = (RTYPE) __msa_srl_h((v8i16) in1, (v8i16) shift); \
  1848. in2 = (RTYPE) __msa_srl_h((v8i16) in2, (v8i16) shift); \
  1849. in3 = (RTYPE) __msa_srl_h((v8i16) in3, (v8i16) shift); \
  1850. }
  1851. #define SRL_H4_UH(...) SRL_H4(v8u16, __VA_ARGS__)
  1852. /* Description : Shift right arithmetic rounded halfwords
  1853. Arguments : Inputs - in0, in1, shift
  1854. Outputs - in0, in1, (in place)
  1855. Return Type - as per RTYPE
  1856. Details : Each element of vector 'in0' is shifted right arithmetic by
  1857. number of bits respective element holds in vector 'shift'.
  1858. The last discarded bit is added to shifted value for rounding
  1859. and the result is in place written to 'in0'
  1860. Here, 'shift' is a vector passed in
  1861. Similar for other pairs
  1862. */
  1863. #define SRAR_H2(RTYPE, in0, in1, shift) \
  1864. { \
  1865. in0 = (RTYPE) __msa_srar_h((v8i16) in0, (v8i16) shift); \
  1866. in1 = (RTYPE) __msa_srar_h((v8i16) in1, (v8i16) shift); \
  1867. }
  1868. #define SRAR_H2_UH(...) SRAR_H2(v8u16, __VA_ARGS__)
  1869. #define SRAR_H2_SH(...) SRAR_H2(v8i16, __VA_ARGS__)
  1870. #define SRAR_H3(RTYPE, in0, in1, in2, shift) \
  1871. { \
  1872. SRAR_H2(RTYPE, in0, in1, shift) \
  1873. in2 = (RTYPE) __msa_srar_h((v8i16) in2, (v8i16) shift); \
  1874. }
  1875. #define SRAR_H3_SH(...) SRAR_H3(v8i16, __VA_ARGS__)
  1876. #define SRAR_H4(RTYPE, in0, in1, in2, in3, shift) \
  1877. { \
  1878. SRAR_H2(RTYPE, in0, in1, shift) \
  1879. SRAR_H2(RTYPE, in2, in3, shift) \
  1880. }
  1881. #define SRAR_H4_UH(...) SRAR_H4(v8u16, __VA_ARGS__)
  1882. #define SRAR_H4_SH(...) SRAR_H4(v8i16, __VA_ARGS__)
  1883. /* Description : Shift right arithmetic rounded words
  1884. Arguments : Inputs - in0, in1, shift
  1885. Outputs - in0, in1, (in place)
  1886. Return Type - as per RTYPE
  1887. Details : Each element of vector 'in0' is shifted right arithmetic by
  1888. number of bits respective element holds in vector 'shift'.
  1889. The last discarded bit is added to shifted value for rounding
  1890. and the result is in place written to 'in0'
  1891. Here, 'shift' is a vector passed in
  1892. Similar for other pairs
  1893. */
  1894. #define SRAR_W2(RTYPE, in0, in1, shift) \
  1895. { \
  1896. in0 = (RTYPE) __msa_srar_w((v4i32) in0, (v4i32) shift); \
  1897. in1 = (RTYPE) __msa_srar_w((v4i32) in1, (v4i32) shift); \
  1898. }
  1899. #define SRAR_W2_SW(...) SRAR_W2(v4i32, __VA_ARGS__)
  1900. #define SRAR_W4(RTYPE, in0, in1, in2, in3, shift) \
  1901. { \
  1902. SRAR_W2(RTYPE, in0, in1, shift) \
  1903. SRAR_W2(RTYPE, in2, in3, shift) \
  1904. }
  1905. #define SRAR_W4_SW(...) SRAR_W4(v4i32, __VA_ARGS__)
  1906. /* Description : Shift right arithmetic rounded (immediate)
  1907. Arguments : Inputs - in0, in1, in2, in3, shift
  1908. Outputs - in0, in1, in2, in3 (in place)
  1909. Return Type - as per RTYPE
  1910. Details : Each element of vector 'in0' is shifted right arithmetic by
  1911. value in 'shift'.
  1912. The last discarded bit is added to shifted value for rounding
  1913. and the result is in place written to 'in0'
  1914. Similar for other pairs
  1915. */
  1916. #define SRARI_H2(RTYPE, in0, in1, shift) \
  1917. { \
  1918. in0 = (RTYPE) __msa_srari_h((v8i16) in0, shift); \
  1919. in1 = (RTYPE) __msa_srari_h((v8i16) in1, shift); \
  1920. }
  1921. #define SRARI_H2_UH(...) SRARI_H2(v8u16, __VA_ARGS__)
  1922. #define SRARI_H2_SH(...) SRARI_H2(v8i16, __VA_ARGS__)
  1923. #define SRARI_H4(RTYPE, in0, in1, in2, in3, shift) \
  1924. { \
  1925. SRARI_H2(RTYPE, in0, in1, shift); \
  1926. SRARI_H2(RTYPE, in2, in3, shift); \
  1927. }
  1928. #define SRARI_H4_UH(...) SRARI_H4(v8u16, __VA_ARGS__)
  1929. #define SRARI_H4_SH(...) SRARI_H4(v8i16, __VA_ARGS__)
  1930. /* Description : Shift right arithmetic rounded (immediate)
  1931. Arguments : Inputs - in0, in1, shift
  1932. Outputs - in0, in1 (in place)
  1933. Return Type - as per RTYPE
  1934. Details : Each element of vector 'in0' is shifted right arithmetic by
  1935. value in 'shift'.
  1936. The last discarded bit is added to shifted value for rounding
  1937. and the result is in place written to 'in0'
  1938. Similar for other pairs
  1939. */
  1940. #define SRARI_W2(RTYPE, in0, in1, shift) \
  1941. { \
  1942. in0 = (RTYPE) __msa_srari_w((v4i32) in0, shift); \
  1943. in1 = (RTYPE) __msa_srari_w((v4i32) in1, shift); \
  1944. }
  1945. #define SRARI_W2_SW(...) SRARI_W2(v4i32, __VA_ARGS__)
  1946. #define SRARI_W4(RTYPE, in0, in1, in2, in3, shift) \
  1947. { \
  1948. SRARI_W2(RTYPE, in0, in1, shift); \
  1949. SRARI_W2(RTYPE, in2, in3, shift); \
  1950. }
  1951. #define SRARI_W4_SH(...) SRARI_W4(v8i16, __VA_ARGS__)
  1952. #define SRARI_W4_SW(...) SRARI_W4(v4i32, __VA_ARGS__)
  1953. /* Description : Multiplication of pairs of vectors
  1954. Arguments : Inputs - in0, in1, in2, in3
  1955. Outputs - out0, out1
  1956. Details : Each element from 'in0' is multiplied with elements from 'in1'
  1957. and result is written to 'out0'
  1958. Similar for other pairs
  1959. */
  1960. #define MUL2(in0, in1, in2, in3, out0, out1) \
  1961. { \
  1962. out0 = in0 * in1; \
  1963. out1 = in2 * in3; \
  1964. }
  1965. #define MUL4(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, out3) \
  1966. { \
  1967. MUL2(in0, in1, in2, in3, out0, out1); \
  1968. MUL2(in4, in5, in6, in7, out2, out3); \
  1969. }
  1970. /* Description : Addition of 2 pairs of vectors
  1971. Arguments : Inputs - in0, in1, in2, in3
  1972. Outputs - out0, out1
  1973. Details : Each element from 2 pairs vectors is added and 2 results are
  1974. produced
  1975. */
  1976. #define ADD2(in0, in1, in2, in3, out0, out1) \
  1977. { \
  1978. out0 = in0 + in1; \
  1979. out1 = in2 + in3; \
  1980. }
  1981. #define ADD4(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, out3) \
  1982. { \
  1983. ADD2(in0, in1, in2, in3, out0, out1); \
  1984. ADD2(in4, in5, in6, in7, out2, out3); \
  1985. }
  1986. /* Description : Subtraction of 2 pairs of vectors
  1987. Arguments : Inputs - in0, in1, in2, in3
  1988. Outputs - out0, out1
  1989. Details : Each element from 2 pairs vectors is subtracted and 2 results
  1990. are produced
  1991. */
  1992. #define SUB2(in0, in1, in2, in3, out0, out1) \
  1993. { \
  1994. out0 = in0 - in1; \
  1995. out1 = in2 - in3; \
  1996. }
  1997. #define SUB4(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, out3) \
  1998. { \
  1999. out0 = in0 - in1; \
  2000. out1 = in2 - in3; \
  2001. out2 = in4 - in5; \
  2002. out3 = in6 - in7; \
  2003. }
  2004. /* Description : Sign extend halfword elements from right half of the vector
  2005. Arguments : Inputs - in (input halfword vector)
  2006. Outputs - out (sign extended word vectors)
  2007. Return Type - signed word
  2008. Details : Sign bit of halfword elements from input vector 'in' is
  2009. extracted and interleaved with same vector 'in0' to generate
  2010. 4 word elements keeping sign intact
  2011. */
  2012. #define UNPCK_R_SH_SW(in, out) \
  2013. { \
  2014. v8i16 sign_m; \
  2015. \
  2016. sign_m = __msa_clti_s_h((v8i16) in, 0); \
  2017. out = (v4i32) __msa_ilvr_h(sign_m, (v8i16) in); \
  2018. }
  2019. /* Description : Sign extend byte elements from input vector and return
  2020. halfword results in pair of vectors
  2021. Arguments : Inputs - in (1 input byte vector)
  2022. Outputs - out0, out1 (sign extended 2 halfword vectors)
  2023. Return Type - signed halfword
  2024. Details : Sign bit of byte elements from input vector 'in' is
  2025. extracted and interleaved right with same vector 'in0' to
  2026. generate 8 signed halfword elements in 'out0'
  2027. Then interleaved left with same vector 'in0' to
  2028. generate 8 signed halfword elements in 'out1'
  2029. */
  2030. #define UNPCK_SB_SH(in, out0, out1) \
  2031. { \
  2032. v16i8 tmp_m; \
  2033. \
  2034. tmp_m = __msa_clti_s_b((v16i8) in, 0); \
  2035. ILVRL_B2_SH(tmp_m, in, out0, out1); \
  2036. }
  2037. /* Description : Zero extend unsigned byte elements to halfword elements
  2038. Arguments : Inputs - in (1 input unsigned byte vector)
  2039. Outputs - out0, out1 (unsigned 2 halfword vectors)
  2040. Return Type - signed halfword
  2041. Details : Zero extended right half of vector is returned in 'out0'
  2042. Zero extended left half of vector is returned in 'out1'
  2043. */
  2044. #define UNPCK_UB_SH(in, out0, out1) \
  2045. { \
  2046. v16i8 zero_m = { 0 }; \
  2047. \
  2048. ILVRL_B2_SH(zero_m, in, out0, out1); \
  2049. }
  2050. /* Description : Sign extend halfword elements from input vector and return
  2051. result in pair of vectors
  2052. Arguments : Inputs - in (1 input halfword vector)
  2053. Outputs - out0, out1 (sign extended 2 word vectors)
  2054. Return Type - signed word
  2055. Details : Sign bit of halfword elements from input vector 'in' is
  2056. extracted and interleaved right with same vector 'in0' to
  2057. generate 4 signed word elements in 'out0'
  2058. Then interleaved left with same vector 'in0' to
  2059. generate 4 signed word elements in 'out1'
  2060. */
  2061. #define UNPCK_SH_SW(in, out0, out1) \
  2062. { \
  2063. v8i16 tmp_m; \
  2064. \
  2065. tmp_m = __msa_clti_s_h((v8i16) in, 0); \
  2066. ILVRL_H2_SW(tmp_m, in, out0, out1); \
  2067. }
  2068. /* Description : Swap two variables
  2069. Arguments : Inputs - in0, in1
  2070. Outputs - in0, in1 (in-place)
  2071. Details : Swapping of two input variables using xor
  2072. */
  2073. #define SWAP(in0, in1) \
  2074. { \
  2075. in0 = in0 ^ in1; \
  2076. in1 = in0 ^ in1; \
  2077. in0 = in0 ^ in1; \
  2078. }
  2079. /* Description : Butterfly of 4 input vectors
  2080. Arguments : Inputs - in0, in1, in2, in3
  2081. Outputs - out0, out1, out2, out3
  2082. Details : Butterfly operation
  2083. */
  2084. #define BUTTERFLY_4(in0, in1, in2, in3, out0, out1, out2, out3) \
  2085. { \
  2086. out0 = in0 + in3; \
  2087. out1 = in1 + in2; \
  2088. \
  2089. out2 = in1 - in2; \
  2090. out3 = in0 - in3; \
  2091. }
  2092. /* Description : Butterfly of 8 input vectors
  2093. Arguments : Inputs - in0 ... in7
  2094. Outputs - out0 .. out7
  2095. Details : Butterfly operation
  2096. */
  2097. #define BUTTERFLY_8(in0, in1, in2, in3, in4, in5, in6, in7, \
  2098. out0, out1, out2, out3, out4, out5, out6, out7) \
  2099. { \
  2100. out0 = in0 + in7; \
  2101. out1 = in1 + in6; \
  2102. out2 = in2 + in5; \
  2103. out3 = in3 + in4; \
  2104. \
  2105. out4 = in3 - in4; \
  2106. out5 = in2 - in5; \
  2107. out6 = in1 - in6; \
  2108. out7 = in0 - in7; \
  2109. }
  2110. /* Description : Butterfly of 16 input vectors
  2111. Arguments : Inputs - in0 ... in15
  2112. Outputs - out0 .. out15
  2113. Details : Butterfly operation
  2114. */
  2115. #define BUTTERFLY_16(in0, in1, in2, in3, in4, in5, in6, in7, \
  2116. in8, in9, in10, in11, in12, in13, in14, in15, \
  2117. out0, out1, out2, out3, out4, out5, out6, out7, \
  2118. out8, out9, out10, out11, out12, out13, out14, out15) \
  2119. { \
  2120. out0 = in0 + in15; \
  2121. out1 = in1 + in14; \
  2122. out2 = in2 + in13; \
  2123. out3 = in3 + in12; \
  2124. out4 = in4 + in11; \
  2125. out5 = in5 + in10; \
  2126. out6 = in6 + in9; \
  2127. out7 = in7 + in8; \
  2128. \
  2129. out8 = in7 - in8; \
  2130. out9 = in6 - in9; \
  2131. out10 = in5 - in10; \
  2132. out11 = in4 - in11; \
  2133. out12 = in3 - in12; \
  2134. out13 = in2 - in13; \
  2135. out14 = in1 - in14; \
  2136. out15 = in0 - in15; \
  2137. }
  2138. /* Description : Transposes input 4x4 byte block
  2139. Arguments : Inputs - in0, in1, in2, in3 (input 4x4 byte block)
  2140. Outputs - out0, out1, out2, out3 (output 4x4 byte block)
  2141. Return Type - unsigned byte
  2142. Details :
  2143. */
  2144. #define TRANSPOSE4x4_UB_UB(in0, in1, in2, in3, out0, out1, out2, out3) \
  2145. { \
  2146. v16i8 zero_m = { 0 }; \
  2147. v16i8 s0_m, s1_m, s2_m, s3_m; \
  2148. \
  2149. ILVR_D2_SB(in1, in0, in3, in2, s0_m, s1_m); \
  2150. ILVRL_B2_SB(s1_m, s0_m, s2_m, s3_m); \
  2151. \
  2152. out0 = (v16u8) __msa_ilvr_b(s3_m, s2_m); \
  2153. out1 = (v16u8) __msa_sldi_b(zero_m, (v16i8) out0, 4); \
  2154. out2 = (v16u8) __msa_sldi_b(zero_m, (v16i8) out1, 4); \
  2155. out3 = (v16u8) __msa_sldi_b(zero_m, (v16i8) out2, 4); \
  2156. }
  2157. /* Description : Transposes input 8x4 byte block into 4x8
  2158. Arguments : Inputs - in0, in1, in2, in3 (input 8x4 byte block)
  2159. Outputs - out0, out1, out2, out3 (output 4x8 byte block)
  2160. Return Type - as per RTYPE
  2161. Details :
  2162. */
  2163. #define TRANSPOSE8x4_UB(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  2164. out0, out1, out2, out3) \
  2165. { \
  2166. v16i8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2167. \
  2168. ILVEV_W2_SB(in0, in4, in1, in5, tmp0_m, tmp1_m); \
  2169. tmp2_m = __msa_ilvr_b(tmp1_m, tmp0_m); \
  2170. ILVEV_W2_SB(in2, in6, in3, in7, tmp0_m, tmp1_m); \
  2171. \
  2172. tmp3_m = __msa_ilvr_b(tmp1_m, tmp0_m); \
  2173. ILVRL_H2_SB(tmp3_m, tmp2_m, tmp0_m, tmp1_m); \
  2174. \
  2175. ILVRL_W2(RTYPE, tmp1_m, tmp0_m, out0, out2); \
  2176. out1 = (RTYPE) __msa_ilvl_d((v2i64) out2, (v2i64) out0); \
  2177. out3 = (RTYPE) __msa_ilvl_d((v2i64) out0, (v2i64) out2); \
  2178. }
  2179. #define TRANSPOSE8x4_UB_UB(...) TRANSPOSE8x4_UB(v16u8, __VA_ARGS__)
  2180. #define TRANSPOSE8x4_UB_UH(...) TRANSPOSE8x4_UB(v8u16, __VA_ARGS__)
  2181. /* Description : Transposes input 8x8 byte block
  2182. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  2183. (input 8x8 byte block)
  2184. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  2185. (output 8x8 byte block)
  2186. Return Type - as per RTYPE
  2187. Details :
  2188. */
  2189. #define TRANSPOSE8x8_UB(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  2190. out0, out1, out2, out3, out4, out5, out6, out7) \
  2191. { \
  2192. v16i8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2193. v16i8 tmp4_m, tmp5_m, tmp6_m, tmp7_m; \
  2194. \
  2195. ILVR_B4_SB(in2, in0, in3, in1, in6, in4, in7, in5, \
  2196. tmp0_m, tmp1_m, tmp2_m, tmp3_m); \
  2197. ILVRL_B2_SB(tmp1_m, tmp0_m, tmp4_m, tmp5_m); \
  2198. ILVRL_B2_SB(tmp3_m, tmp2_m, tmp6_m, tmp7_m); \
  2199. ILVRL_W2(RTYPE, tmp6_m, tmp4_m, out0, out2); \
  2200. ILVRL_W2(RTYPE, tmp7_m, tmp5_m, out4, out6); \
  2201. SLDI_B2_0(RTYPE, out0, out2, out1, out3, 8); \
  2202. SLDI_B2_0(RTYPE, out4, out6, out5, out7, 8); \
  2203. }
  2204. #define TRANSPOSE8x8_UB_UB(...) TRANSPOSE8x8_UB(v16u8, __VA_ARGS__)
  2205. #define TRANSPOSE8x8_UB_UH(...) TRANSPOSE8x8_UB(v8u16, __VA_ARGS__)
  2206. /* Description : Transposes 16x4 block into 4x16 with byte elements in vectors
  2207. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7,
  2208. in8, in9, in10, in11, in12, in13, in14, in15
  2209. Outputs - out0, out1, out2, out3
  2210. Return Type - unsigned byte
  2211. Details :
  2212. */
  2213. #define TRANSPOSE16x4_UB_UB(in0, in1, in2, in3, in4, in5, in6, in7, \
  2214. in8, in9, in10, in11, in12, in13, in14, in15, \
  2215. out0, out1, out2, out3) \
  2216. { \
  2217. v2i64 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2218. \
  2219. ILVEV_W2_SD(in0, in4, in8, in12, tmp0_m, tmp1_m); \
  2220. out1 = (v16u8) __msa_ilvev_d(tmp1_m, tmp0_m); \
  2221. \
  2222. ILVEV_W2_SD(in1, in5, in9, in13, tmp0_m, tmp1_m); \
  2223. out3 = (v16u8) __msa_ilvev_d(tmp1_m, tmp0_m); \
  2224. \
  2225. ILVEV_W2_SD(in2, in6, in10, in14, tmp0_m, tmp1_m); \
  2226. \
  2227. tmp2_m = __msa_ilvev_d(tmp1_m, tmp0_m); \
  2228. ILVEV_W2_SD(in3, in7, in11, in15, tmp0_m, tmp1_m); \
  2229. \
  2230. tmp3_m = __msa_ilvev_d(tmp1_m, tmp0_m); \
  2231. ILVEV_B2_SD(out1, out3, tmp2_m, tmp3_m, tmp0_m, tmp1_m); \
  2232. out0 = (v16u8) __msa_ilvev_h((v8i16) tmp1_m, (v8i16) tmp0_m); \
  2233. out2 = (v16u8) __msa_ilvod_h((v8i16) tmp1_m, (v8i16) tmp0_m); \
  2234. \
  2235. tmp0_m = (v2i64) __msa_ilvod_b((v16i8) out3, (v16i8) out1); \
  2236. tmp1_m = (v2i64) __msa_ilvod_b((v16i8) tmp3_m, (v16i8) tmp2_m); \
  2237. out1 = (v16u8) __msa_ilvev_h((v8i16) tmp1_m, (v8i16) tmp0_m); \
  2238. out3 = (v16u8) __msa_ilvod_h((v8i16) tmp1_m, (v8i16) tmp0_m); \
  2239. }
  2240. /* Description : Transposes 16x8 block into 8x16 with byte elements in vectors
  2241. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7,
  2242. in8, in9, in10, in11, in12, in13, in14, in15
  2243. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  2244. Return Type - unsigned byte
  2245. Details :
  2246. */
  2247. #define TRANSPOSE16x8_UB_UB(in0, in1, in2, in3, in4, in5, in6, in7, \
  2248. in8, in9, in10, in11, in12, in13, in14, in15, \
  2249. out0, out1, out2, out3, out4, out5, out6, out7) \
  2250. { \
  2251. v16u8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2252. v16u8 tmp4_m, tmp5_m, tmp6_m, tmp7_m; \
  2253. \
  2254. ILVEV_D2_UB(in0, in8, in1, in9, out7, out6); \
  2255. ILVEV_D2_UB(in2, in10, in3, in11, out5, out4); \
  2256. ILVEV_D2_UB(in4, in12, in5, in13, out3, out2); \
  2257. ILVEV_D2_UB(in6, in14, in7, in15, out1, out0); \
  2258. \
  2259. tmp0_m = (v16u8) __msa_ilvev_b((v16i8) out6, (v16i8) out7); \
  2260. tmp4_m = (v16u8) __msa_ilvod_b((v16i8) out6, (v16i8) out7); \
  2261. tmp1_m = (v16u8) __msa_ilvev_b((v16i8) out4, (v16i8) out5); \
  2262. tmp5_m = (v16u8) __msa_ilvod_b((v16i8) out4, (v16i8) out5); \
  2263. out5 = (v16u8) __msa_ilvev_b((v16i8) out2, (v16i8) out3); \
  2264. tmp6_m = (v16u8) __msa_ilvod_b((v16i8) out2, (v16i8) out3); \
  2265. out7 = (v16u8) __msa_ilvev_b((v16i8) out0, (v16i8) out1); \
  2266. tmp7_m = (v16u8) __msa_ilvod_b((v16i8) out0, (v16i8) out1); \
  2267. \
  2268. ILVEV_H2_UB(tmp0_m, tmp1_m, out5, out7, tmp2_m, tmp3_m); \
  2269. out0 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2270. out4 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2271. \
  2272. tmp2_m = (v16u8) __msa_ilvod_h((v8i16) tmp1_m, (v8i16) tmp0_m); \
  2273. tmp3_m = (v16u8) __msa_ilvod_h((v8i16) out7, (v8i16) out5); \
  2274. out2 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2275. out6 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2276. \
  2277. ILVEV_H2_UB(tmp4_m, tmp5_m, tmp6_m, tmp7_m, tmp2_m, tmp3_m); \
  2278. out1 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2279. out5 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2280. \
  2281. tmp2_m = (v16u8) __msa_ilvod_h((v8i16) tmp5_m, (v8i16) tmp4_m); \
  2282. tmp2_m = (v16u8) __msa_ilvod_h((v8i16) tmp5_m, (v8i16) tmp4_m); \
  2283. tmp3_m = (v16u8) __msa_ilvod_h((v8i16) tmp7_m, (v8i16) tmp6_m); \
  2284. tmp3_m = (v16u8) __msa_ilvod_h((v8i16) tmp7_m, (v8i16) tmp6_m); \
  2285. out3 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2286. out7 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2287. }
  2288. /* Description : Transposes 4x4 block with half word elements in vectors
  2289. Arguments : Inputs - in0, in1, in2, in3
  2290. Outputs - out0, out1, out2, out3
  2291. Return Type - signed halfword
  2292. Details :
  2293. */
  2294. #define TRANSPOSE4x4_SH_SH(in0, in1, in2, in3, out0, out1, out2, out3) \
  2295. { \
  2296. v8i16 s0_m, s1_m; \
  2297. \
  2298. ILVR_H2_SH(in1, in0, in3, in2, s0_m, s1_m); \
  2299. ILVRL_W2_SH(s1_m, s0_m, out0, out2); \
  2300. out1 = (v8i16) __msa_ilvl_d((v2i64) out0, (v2i64) out0); \
  2301. out3 = (v8i16) __msa_ilvl_d((v2i64) out0, (v2i64) out2); \
  2302. }
  2303. /* Description : Transposes 8x8 block with half word elements in vectors
  2304. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  2305. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  2306. Return Type - as per RTYPE
  2307. Details :
  2308. */
  2309. #define TRANSPOSE8x8_H(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  2310. out0, out1, out2, out3, out4, out5, out6, out7) \
  2311. { \
  2312. v8i16 s0_m, s1_m; \
  2313. v8i16 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2314. v8i16 tmp4_m, tmp5_m, tmp6_m, tmp7_m; \
  2315. \
  2316. ILVR_H2_SH(in6, in4, in7, in5, s0_m, s1_m); \
  2317. ILVRL_H2_SH(s1_m, s0_m, tmp0_m, tmp1_m); \
  2318. ILVL_H2_SH(in6, in4, in7, in5, s0_m, s1_m); \
  2319. ILVRL_H2_SH(s1_m, s0_m, tmp2_m, tmp3_m); \
  2320. ILVR_H2_SH(in2, in0, in3, in1, s0_m, s1_m); \
  2321. ILVRL_H2_SH(s1_m, s0_m, tmp4_m, tmp5_m); \
  2322. ILVL_H2_SH(in2, in0, in3, in1, s0_m, s1_m); \
  2323. ILVRL_H2_SH(s1_m, s0_m, tmp6_m, tmp7_m); \
  2324. PCKEV_D4(RTYPE, tmp0_m, tmp4_m, tmp1_m, tmp5_m, tmp2_m, tmp6_m, \
  2325. tmp3_m, tmp7_m, out0, out2, out4, out6); \
  2326. out1 = (RTYPE) __msa_pckod_d((v2i64) tmp0_m, (v2i64) tmp4_m); \
  2327. out3 = (RTYPE) __msa_pckod_d((v2i64) tmp1_m, (v2i64) tmp5_m); \
  2328. out5 = (RTYPE) __msa_pckod_d((v2i64) tmp2_m, (v2i64) tmp6_m); \
  2329. out7 = (RTYPE) __msa_pckod_d((v2i64) tmp3_m, (v2i64) tmp7_m); \
  2330. }
  2331. #define TRANSPOSE8x8_UH_UH(...) TRANSPOSE8x8_H(v8u16, __VA_ARGS__)
  2332. #define TRANSPOSE8x8_SH_SH(...) TRANSPOSE8x8_H(v8i16, __VA_ARGS__)
  2333. /* Description : Transposes 4x4 block with word elements in vectors
  2334. Arguments : Inputs - in0, in1, in2, in3
  2335. Outputs - out0, out1, out2, out3
  2336. Return Type - signed word
  2337. Details :
  2338. */
  2339. #define TRANSPOSE4x4_SW_SW(in0, in1, in2, in3, out0, out1, out2, out3) \
  2340. { \
  2341. v4i32 s0_m, s1_m, s2_m, s3_m; \
  2342. \
  2343. ILVRL_W2_SW(in1, in0, s0_m, s1_m); \
  2344. ILVRL_W2_SW(in3, in2, s2_m, s3_m); \
  2345. \
  2346. out0 = (v4i32) __msa_ilvr_d((v2i64) s2_m, (v2i64) s0_m); \
  2347. out1 = (v4i32) __msa_ilvl_d((v2i64) s2_m, (v2i64) s0_m); \
  2348. out2 = (v4i32) __msa_ilvr_d((v2i64) s3_m, (v2i64) s1_m); \
  2349. out3 = (v4i32) __msa_ilvl_d((v2i64) s3_m, (v2i64) s1_m); \
  2350. }
  2351. /* Description : Average byte elements from pair of vectors and store 8x4 byte
  2352. block in destination memory
  2353. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride
  2354. Details : Each byte element from input vector pair 'in0' and 'in1' are
  2355. averaged (a + b)/2 and stored in 'tmp0_m'
  2356. Each byte element from input vector pair 'in2' and 'in3' are
  2357. averaged (a + b)/2 and stored in 'tmp1_m'
  2358. Each byte element from input vector pair 'in4' and 'in5' are
  2359. averaged (a + b)/2 and stored in 'tmp2_m'
  2360. Each byte element from input vector pair 'in6' and 'in7' are
  2361. averaged (a + b)/2 and stored in 'tmp3_m'
  2362. The half vector results from all 4 vectors are stored in
  2363. destination memory as 8x4 byte block
  2364. */
  2365. #define AVE_ST8x4_UB(in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride) \
  2366. { \
  2367. uint64_t out0_m, out1_m, out2_m, out3_m; \
  2368. v16u8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2369. \
  2370. tmp0_m = __msa_ave_u_b((v16u8) in0, (v16u8) in1); \
  2371. tmp1_m = __msa_ave_u_b((v16u8) in2, (v16u8) in3); \
  2372. tmp2_m = __msa_ave_u_b((v16u8) in4, (v16u8) in5); \
  2373. tmp3_m = __msa_ave_u_b((v16u8) in6, (v16u8) in7); \
  2374. \
  2375. out0_m = __msa_copy_u_d((v2i64) tmp0_m, 0); \
  2376. out1_m = __msa_copy_u_d((v2i64) tmp1_m, 0); \
  2377. out2_m = __msa_copy_u_d((v2i64) tmp2_m, 0); \
  2378. out3_m = __msa_copy_u_d((v2i64) tmp3_m, 0); \
  2379. SD4(out0_m, out1_m, out2_m, out3_m, pdst, stride); \
  2380. }
  2381. /* Description : Average byte elements from pair of vectors and store 16x4 byte
  2382. block in destination memory
  2383. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride
  2384. Details : Each byte element from input vector pair 'in0' and 'in1' are
  2385. averaged (a + b)/2 and stored in 'tmp0_m'
  2386. Each byte element from input vector pair 'in2' and 'in3' are
  2387. averaged (a + b)/2 and stored in 'tmp1_m'
  2388. Each byte element from input vector pair 'in4' and 'in5' are
  2389. averaged (a + b)/2 and stored in 'tmp2_m'
  2390. Each byte element from input vector pair 'in6' and 'in7' are
  2391. averaged (a + b)/2 and stored in 'tmp3_m'
  2392. The results from all 4 vectors are stored in destination
  2393. memory as 16x4 byte block
  2394. */
  2395. #define AVE_ST16x4_UB(in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride) \
  2396. { \
  2397. v16u8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2398. \
  2399. tmp0_m = __msa_ave_u_b((v16u8) in0, (v16u8) in1); \
  2400. tmp1_m = __msa_ave_u_b((v16u8) in2, (v16u8) in3); \
  2401. tmp2_m = __msa_ave_u_b((v16u8) in4, (v16u8) in5); \
  2402. tmp3_m = __msa_ave_u_b((v16u8) in6, (v16u8) in7); \
  2403. \
  2404. ST_UB4(tmp0_m, tmp1_m, tmp2_m, tmp3_m, pdst, stride); \
  2405. }
  2406. /* Description : Average rounded byte elements from pair of vectors and store
  2407. 8x4 byte block in destination memory
  2408. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride
  2409. Details : Each byte element from input vector pair 'in0' and 'in1' are
  2410. average rounded (a + b + 1)/2 and stored in 'tmp0_m'
  2411. Each byte element from input vector pair 'in2' and 'in3' are
  2412. average rounded (a + b + 1)/2 and stored in 'tmp1_m'
  2413. Each byte element from input vector pair 'in4' and 'in5' are
  2414. average rounded (a + b + 1)/2 and stored in 'tmp2_m'
  2415. Each byte element from input vector pair 'in6' and 'in7' are
  2416. average rounded (a + b + 1)/2 and stored in 'tmp3_m'
  2417. The half vector results from all 4 vectors are stored in
  2418. destination memory as 8x4 byte block
  2419. */
  2420. #define AVER_ST8x4_UB(in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride) \
  2421. { \
  2422. uint64_t out0_m, out1_m, out2_m, out3_m; \
  2423. v16u8 tp0_m, tp1_m, tp2_m, tp3_m; \
  2424. \
  2425. AVER_UB4_UB(in0, in1, in2, in3, in4, in5, in6, in7, \
  2426. tp0_m, tp1_m, tp2_m, tp3_m); \
  2427. \
  2428. out0_m = __msa_copy_u_d((v2i64) tp0_m, 0); \
  2429. out1_m = __msa_copy_u_d((v2i64) tp1_m, 0); \
  2430. out2_m = __msa_copy_u_d((v2i64) tp2_m, 0); \
  2431. out3_m = __msa_copy_u_d((v2i64) tp3_m, 0); \
  2432. SD4(out0_m, out1_m, out2_m, out3_m, pdst, stride); \
  2433. }
  2434. /* Description : Average rounded byte elements from pair of vectors and store
  2435. 16x4 byte block in destination memory
  2436. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride
  2437. Details : Each byte element from input vector pair 'in0' and 'in1' are
  2438. average rounded (a + b + 1)/2 and stored in 'tmp0_m'
  2439. Each byte element from input vector pair 'in2' and 'in3' are
  2440. average rounded (a + b + 1)/2 and stored in 'tmp1_m'
  2441. Each byte element from input vector pair 'in4' and 'in5' are
  2442. average rounded (a + b + 1)/2 and stored in 'tmp2_m'
  2443. Each byte element from input vector pair 'in6' and 'in7' are
  2444. average rounded (a + b + 1)/2 and stored in 'tmp3_m'
  2445. The vector results from all 4 vectors are stored in
  2446. destination memory as 16x4 byte block
  2447. */
  2448. #define AVER_ST16x4_UB(in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride) \
  2449. { \
  2450. v16u8 t0_m, t1_m, t2_m, t3_m; \
  2451. \
  2452. AVER_UB4_UB(in0, in1, in2, in3, in4, in5, in6, in7, \
  2453. t0_m, t1_m, t2_m, t3_m); \
  2454. ST_UB4(t0_m, t1_m, t2_m, t3_m, pdst, stride); \
  2455. }
  2456. /* Description : Average rounded byte elements from pair of vectors,
  2457. average rounded with destination and store 8x4 byte block
  2458. in destination memory
  2459. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride
  2460. Details : Each byte element from input vector pair 'in0' and 'in1' are
  2461. average rounded (a + b + 1)/2 and stored in 'tmp0_m'
  2462. Each byte element from input vector pair 'in2' and 'in3' are
  2463. average rounded (a + b + 1)/2 and stored in 'tmp1_m'
  2464. Each byte element from input vector pair 'in4' and 'in5' are
  2465. average rounded (a + b + 1)/2 and stored in 'tmp2_m'
  2466. Each byte element from input vector pair 'in6' and 'in7' are
  2467. average rounded (a + b + 1)/2 and stored in 'tmp3_m'
  2468. The half vector results from all 4 vectors are stored in
  2469. destination memory as 8x4 byte block
  2470. */
  2471. #define AVER_DST_ST8x4_UB(in0, in1, in2, in3, in4, in5, in6, in7, \
  2472. pdst, stride) \
  2473. { \
  2474. v16u8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2475. v16u8 dst0_m, dst1_m, dst2_m, dst3_m; \
  2476. \
  2477. LD_UB4(pdst, stride, dst0_m, dst1_m, dst2_m, dst3_m); \
  2478. AVER_UB4_UB(in0, in1, in2, in3, in4, in5, in6, in7, \
  2479. tmp0_m, tmp1_m, tmp2_m, tmp3_m); \
  2480. AVER_ST8x4_UB(dst0_m, tmp0_m, dst1_m, tmp1_m, \
  2481. dst2_m, tmp2_m, dst3_m, tmp3_m, pdst, stride); \
  2482. }
  2483. /* Description : Average rounded byte elements from pair of vectors,
  2484. average rounded with destination and store 16x4 byte block
  2485. in destination memory
  2486. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride
  2487. Details : Each byte element from input vector pair 'in0' and 'in1' are
  2488. average rounded (a + b + 1)/2 and stored in 'tmp0_m'
  2489. Each byte element from input vector pair 'in2' and 'in3' are
  2490. average rounded (a + b + 1)/2 and stored in 'tmp1_m'
  2491. Each byte element from input vector pair 'in4' and 'in5' are
  2492. average rounded (a + b + 1)/2 and stored in 'tmp2_m'
  2493. Each byte element from input vector pair 'in6' and 'in7' are
  2494. average rounded (a + b + 1)/2 and stored in 'tmp3_m'
  2495. The vector results from all 4 vectors are stored in
  2496. destination memory as 16x4 byte block
  2497. */
  2498. #define AVER_DST_ST16x4_UB(in0, in1, in2, in3, in4, in5, in6, in7, \
  2499. pdst, stride) \
  2500. { \
  2501. v16u8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2502. v16u8 dst0_m, dst1_m, dst2_m, dst3_m; \
  2503. \
  2504. LD_UB4(pdst, stride, dst0_m, dst1_m, dst2_m, dst3_m); \
  2505. AVER_UB4_UB(in0, in1, in2, in3, in4, in5, in6, in7, \
  2506. tmp0_m, tmp1_m, tmp2_m, tmp3_m); \
  2507. AVER_ST16x4_UB(dst0_m, tmp0_m, dst1_m, tmp1_m, \
  2508. dst2_m, tmp2_m, dst3_m, tmp3_m, pdst, stride); \
  2509. }
  2510. /* Description : Add block 4x4
  2511. Arguments : Inputs - in0, in1, in2, in3, pdst, stride
  2512. Details : Least significant 4 bytes from each input vector are added to
  2513. the destination bytes, clipped between 0-255 and then stored.
  2514. */
  2515. #define ADDBLK_ST4x4_UB(in0, in1, in2, in3, pdst, stride) \
  2516. { \
  2517. uint32_t src0_m, src1_m, src2_m, src3_m; \
  2518. uint32_t out0_m, out1_m, out2_m, out3_m; \
  2519. v8i16 inp0_m, inp1_m, res0_m, res1_m; \
  2520. v16i8 dst0_m = { 0 }; \
  2521. v16i8 dst1_m = { 0 }; \
  2522. v16i8 zero_m = { 0 }; \
  2523. \
  2524. ILVR_D2_SH(in1, in0, in3, in2, inp0_m, inp1_m) \
  2525. LW4(pdst, stride, src0_m, src1_m, src2_m, src3_m); \
  2526. INSERT_W2_SB(src0_m, src1_m, dst0_m); \
  2527. INSERT_W2_SB(src2_m, src3_m, dst1_m); \
  2528. ILVR_B2_SH(zero_m, dst0_m, zero_m, dst1_m, res0_m, res1_m); \
  2529. ADD2(res0_m, inp0_m, res1_m, inp1_m, res0_m, res1_m); \
  2530. CLIP_SH2_0_255(res0_m, res1_m); \
  2531. PCKEV_B2_SB(res0_m, res0_m, res1_m, res1_m, dst0_m, dst1_m); \
  2532. \
  2533. out0_m = __msa_copy_u_w((v4i32) dst0_m, 0); \
  2534. out1_m = __msa_copy_u_w((v4i32) dst0_m, 1); \
  2535. out2_m = __msa_copy_u_w((v4i32) dst1_m, 0); \
  2536. out3_m = __msa_copy_u_w((v4i32) dst1_m, 1); \
  2537. SW4(out0_m, out1_m, out2_m, out3_m, pdst, stride); \
  2538. }
  2539. /* Description : Dot product and addition of 3 signed halfword input vectors
  2540. Arguments : Inputs - in0, in1, in2, coeff0, coeff1, coeff2
  2541. Outputs - out0_m
  2542. Return Type - signed halfword
  2543. Details : Dot product of 'in0' with 'coeff0'
  2544. Dot product of 'in1' with 'coeff1'
  2545. Dot product of 'in2' with 'coeff2'
  2546. Addition of all the 3 vector results
  2547. out0_m = (in0 * coeff0) + (in1 * coeff1) + (in2 * coeff2)
  2548. */
  2549. #define DPADD_SH3_SH(in0, in1, in2, coeff0, coeff1, coeff2) \
  2550. ( { \
  2551. v8i16 tmp1_m; \
  2552. v8i16 out0_m; \
  2553. \
  2554. out0_m = __msa_dotp_s_h((v16i8) in0, (v16i8) coeff0); \
  2555. out0_m = __msa_dpadd_s_h(out0_m, (v16i8) in1, (v16i8) coeff1); \
  2556. tmp1_m = __msa_dotp_s_h((v16i8) in2, (v16i8) coeff2); \
  2557. out0_m = __msa_adds_s_h(out0_m, tmp1_m); \
  2558. \
  2559. out0_m; \
  2560. } )
  2561. /* Description : Pack even elements of input vectors & xor with 128
  2562. Arguments : Inputs - in0, in1
  2563. Outputs - out_m
  2564. Return Type - unsigned byte
  2565. Details : Signed byte even elements from 'in0' and 'in1' are packed
  2566. together in one vector and the resulted vector is xor'ed with
  2567. 128 to shift the range from signed to unsigned byte
  2568. */
  2569. #define PCKEV_XORI128_UB(in0, in1) \
  2570. ( { \
  2571. v16u8 out_m; \
  2572. out_m = (v16u8) __msa_pckev_b((v16i8) in1, (v16i8) in0); \
  2573. out_m = (v16u8) __msa_xori_b((v16u8) out_m, 128); \
  2574. out_m; \
  2575. } )
  2576. /* Description : Converts inputs to unsigned bytes, interleave, average & store
  2577. as 8x4 unsigned byte block
  2578. Arguments : Inputs - in0, in1, in2, in3, dst0, dst1, dst2, dst3,
  2579. pdst, stride
  2580. */
  2581. #define CONVERT_UB_AVG_ST8x4_UB(in0, in1, in2, in3, \
  2582. dst0, dst1, dst2, dst3, pdst, stride) \
  2583. { \
  2584. v16u8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2585. uint8_t *pdst_m = (uint8_t *) (pdst); \
  2586. \
  2587. tmp0_m = PCKEV_XORI128_UB(in0, in1); \
  2588. tmp1_m = PCKEV_XORI128_UB(in2, in3); \
  2589. ILVR_D2_UB(dst1, dst0, dst3, dst2, tmp2_m, tmp3_m); \
  2590. AVER_UB2_UB(tmp0_m, tmp2_m, tmp1_m, tmp3_m, tmp0_m, tmp1_m); \
  2591. ST8x4_UB(tmp0_m, tmp1_m, pdst_m, stride); \
  2592. }
  2593. /* Description : Pack even byte elements, extract 0 & 2 index words from pair
  2594. of results and store 4 words in destination memory as per
  2595. stride
  2596. Arguments : Inputs - in0, in1, in2, in3, pdst, stride
  2597. */
  2598. #define PCKEV_ST4x4_UB(in0, in1, in2, in3, pdst, stride) \
  2599. { \
  2600. uint32_t out0_m, out1_m, out2_m, out3_m; \
  2601. v16i8 tmp0_m, tmp1_m; \
  2602. \
  2603. PCKEV_B2_SB(in1, in0, in3, in2, tmp0_m, tmp1_m); \
  2604. \
  2605. out0_m = __msa_copy_u_w((v4i32) tmp0_m, 0); \
  2606. out1_m = __msa_copy_u_w((v4i32) tmp0_m, 2); \
  2607. out2_m = __msa_copy_u_w((v4i32) tmp1_m, 0); \
  2608. out3_m = __msa_copy_u_w((v4i32) tmp1_m, 2); \
  2609. \
  2610. SW4(out0_m, out1_m, out2_m, out3_m, pdst, stride); \
  2611. }
  2612. /* Description : Pack even byte elements and store byte vector in destination
  2613. memory
  2614. Arguments : Inputs - in0, in1, pdst
  2615. */
  2616. #define PCKEV_ST_SB(in0, in1, pdst) \
  2617. { \
  2618. v16i8 tmp_m; \
  2619. tmp_m = __msa_pckev_b((v16i8) in1, (v16i8) in0); \
  2620. ST_SB(tmp_m, (pdst)); \
  2621. }
  2622. /* Description : Horizontal 2 tap filter kernel code
  2623. Arguments : Inputs - in0, in1, mask, coeff, shift
  2624. */
  2625. #define HORIZ_2TAP_FILT_UH(in0, in1, mask, coeff, shift) \
  2626. ( { \
  2627. v16i8 tmp0_m; \
  2628. v8u16 tmp1_m; \
  2629. \
  2630. tmp0_m = __msa_vshf_b((v16i8) mask, (v16i8) in1, (v16i8) in0); \
  2631. tmp1_m = __msa_dotp_u_h((v16u8) tmp0_m, (v16u8) coeff); \
  2632. tmp1_m = (v8u16) __msa_srari_h((v8i16) tmp1_m, shift); \
  2633. tmp1_m = __msa_sat_u_h(tmp1_m, shift); \
  2634. \
  2635. tmp1_m; \
  2636. } )
  2637. #endif /* AVUTIL_MIPS_GENERIC_MACROS_MSA_H */