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.

1905 lines
91KB

  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 LD_B(RTYPE, psrc) *((RTYPE *)(psrc))
  25. #define LD_UB(...) LD_B(v16u8, __VA_ARGS__)
  26. #define LD_SB(...) LD_B(v16i8, __VA_ARGS__)
  27. #define LD_H(RTYPE, psrc) *((RTYPE *)(psrc))
  28. #define LD_UH(...) LD_H(v8u16, __VA_ARGS__)
  29. #define LD_SH(...) LD_H(v8i16, __VA_ARGS__)
  30. #define LD_W(RTYPE, psrc) *((RTYPE *)(psrc))
  31. #define LD_UW(...) LD_W(v4u32, __VA_ARGS__)
  32. #define LD_SW(...) LD_W(v4i32, __VA_ARGS__)
  33. #define ST_B(RTYPE, in, pdst) *((RTYPE *)(pdst)) = (in)
  34. #define ST_UB(...) ST_B(v16u8, __VA_ARGS__)
  35. #define ST_SB(...) ST_B(v16i8, __VA_ARGS__)
  36. #define ST_H(RTYPE, in, pdst) *((RTYPE *)(pdst)) = (in)
  37. #define ST_UH(...) ST_H(v8u16, __VA_ARGS__)
  38. #define ST_SH(...) ST_H(v8i16, __VA_ARGS__)
  39. #define ST_W(RTYPE, in, pdst) *((RTYPE *)(pdst)) = (in)
  40. #define ST_UW(...) ST_W(v4u32, __VA_ARGS__)
  41. #define ST_SW(...) ST_W(v4i32, __VA_ARGS__)
  42. #if (__mips_isa_rev >= 6)
  43. #define LW(psrc) \
  44. ( { \
  45. uint8_t *psrc_m = (uint8_t *) (psrc); \
  46. uint32_t val_m; \
  47. \
  48. __asm__ volatile ( \
  49. "lw %[val_m], %[psrc_m] \n\t" \
  50. \
  51. : [val_m] "=r" (val_m) \
  52. : [psrc_m] "m" (*psrc_m) \
  53. ); \
  54. \
  55. val_m; \
  56. } )
  57. #if (__mips == 64)
  58. #define LD(psrc) \
  59. ( { \
  60. uint8_t *psrc_m = (uint8_t *) (psrc); \
  61. uint64_t val_m = 0; \
  62. \
  63. __asm__ volatile ( \
  64. "ld %[val_m], %[psrc_m] \n\t" \
  65. \
  66. : [val_m] "=r" (val_m) \
  67. : [psrc_m] "m" (*psrc_m) \
  68. ); \
  69. \
  70. val_m; \
  71. } )
  72. #else // !(__mips == 64)
  73. #define LD(psrc) \
  74. ( { \
  75. uint8_t *psrc_m = (uint8_t *) (psrc); \
  76. uint32_t val0_m, val1_m; \
  77. uint64_t val_m = 0; \
  78. \
  79. val0_m = LW(psrc_m); \
  80. val1_m = LW(psrc_m + 4); \
  81. \
  82. val_m = (uint64_t) (val1_m); \
  83. val_m = (uint64_t) ((val_m << 32) & 0xFFFFFFFF00000000); \
  84. val_m = (uint64_t) (val_m | (uint64_t) val0_m); \
  85. \
  86. val_m; \
  87. } )
  88. #endif // (__mips == 64)
  89. #define SH(val, pdst) \
  90. { \
  91. uint8_t *pdst_m = (uint8_t *) (pdst); \
  92. uint16_t val_m = (val); \
  93. \
  94. __asm__ volatile ( \
  95. "sh %[val_m], %[pdst_m] \n\t" \
  96. \
  97. : [pdst_m] "=m" (*pdst_m) \
  98. : [val_m] "r" (val_m) \
  99. ); \
  100. }
  101. #define SW(val, pdst) \
  102. { \
  103. uint8_t *pdst_m = (uint8_t *) (pdst); \
  104. uint32_t val_m = (val); \
  105. \
  106. __asm__ volatile ( \
  107. "sw %[val_m], %[pdst_m] \n\t" \
  108. \
  109. : [pdst_m] "=m" (*pdst_m) \
  110. : [val_m] "r" (val_m) \
  111. ); \
  112. }
  113. #define SD(val, pdst) \
  114. { \
  115. uint8_t *pdst_m = (uint8_t *) (pdst); \
  116. uint64_t val_m = (val); \
  117. \
  118. __asm__ volatile ( \
  119. "sd %[val_m], %[pdst_m] \n\t" \
  120. \
  121. : [pdst_m] "=m" (*pdst_m) \
  122. : [val_m] "r" (val_m) \
  123. ); \
  124. }
  125. #else // !(__mips_isa_rev >= 6)
  126. #define LW(psrc) \
  127. ( { \
  128. uint8_t *psrc_m = (uint8_t *) (psrc); \
  129. uint32_t val_m; \
  130. \
  131. __asm__ volatile ( \
  132. "ulw %[val_m], %[psrc_m] \n\t" \
  133. \
  134. : [val_m] "=r" (val_m) \
  135. : [psrc_m] "m" (*psrc_m) \
  136. ); \
  137. \
  138. val_m; \
  139. } )
  140. #if (__mips == 64)
  141. #define LD(psrc) \
  142. ( { \
  143. uint8_t *psrc_m = (uint8_t *) (psrc); \
  144. uint64_t val_m = 0; \
  145. \
  146. __asm__ volatile ( \
  147. "uld %[val_m], %[psrc_m] \n\t" \
  148. \
  149. : [val_m] "=r" (val_m) \
  150. : [psrc_m] "m" (*psrc_m) \
  151. ); \
  152. \
  153. val_m; \
  154. } )
  155. #else // !(__mips == 64)
  156. #define LD(psrc) \
  157. ( { \
  158. uint8_t *psrc_m1 = (uint8_t *) (psrc); \
  159. uint32_t val0_m, val1_m; \
  160. uint64_t val_m = 0; \
  161. \
  162. val0_m = LW(psrc_m1); \
  163. val1_m = LW(psrc_m1 + 4); \
  164. \
  165. val_m = (uint64_t) (val1_m); \
  166. val_m = (uint64_t) ((val_m << 32) & 0xFFFFFFFF00000000); \
  167. val_m = (uint64_t) (val_m | (uint64_t) val0_m); \
  168. \
  169. val_m; \
  170. } )
  171. #endif // (__mips == 64)
  172. #define SH(val, pdst) \
  173. { \
  174. uint8_t *pdst_m = (uint8_t *) (pdst); \
  175. uint16_t val_m = (val); \
  176. \
  177. __asm__ volatile ( \
  178. "ush %[val_m], %[pdst_m] \n\t" \
  179. \
  180. : [pdst_m] "=m" (*pdst_m) \
  181. : [val_m] "r" (val_m) \
  182. ); \
  183. }
  184. #define SW(val, pdst) \
  185. { \
  186. uint8_t *pdst_m = (uint8_t *) (pdst); \
  187. uint32_t val_m = (val); \
  188. \
  189. __asm__ volatile ( \
  190. "usw %[val_m], %[pdst_m] \n\t" \
  191. \
  192. : [pdst_m] "=m" (*pdst_m) \
  193. : [val_m] "r" (val_m) \
  194. ); \
  195. }
  196. #define SD(val, pdst) \
  197. { \
  198. uint8_t *pdst_m1 = (uint8_t *) (pdst); \
  199. uint32_t val0_m, val1_m; \
  200. \
  201. val0_m = (uint32_t) ((val) & 0x00000000FFFFFFFF); \
  202. val1_m = (uint32_t) (((val) >> 32) & 0x00000000FFFFFFFF); \
  203. \
  204. SW(val0_m, pdst_m1); \
  205. SW(val1_m, pdst_m1 + 4); \
  206. }
  207. #endif // (__mips_isa_rev >= 6)
  208. /* Description : Load 4 words with stride
  209. Arguments : Inputs - psrc (source pointer to load from)
  210. - stride
  211. Outputs - out0, out1, out2, out3
  212. Details : Loads word in 'out0' from (psrc)
  213. Loads word in 'out1' from (psrc + stride)
  214. Loads word in 'out2' from (psrc + 2 * stride)
  215. Loads word in 'out3' from (psrc + 3 * stride)
  216. */
  217. #define LW4(psrc, stride, out0, out1, out2, out3) \
  218. { \
  219. out0 = LW((psrc)); \
  220. out1 = LW((psrc) + stride); \
  221. out2 = LW((psrc) + 2 * stride); \
  222. out3 = LW((psrc) + 3 * stride); \
  223. }
  224. /* Description : Store 4 words with stride
  225. Arguments : Inputs - in0, in1, in2, in3, pdst, stride
  226. Details : Stores word from 'in0' to (pdst)
  227. Stores word from 'in1' to (pdst + stride)
  228. Stores word from 'in2' to (pdst + 2 * stride)
  229. Stores word from 'in3' to (pdst + 3 * stride)
  230. */
  231. #define SW4(in0, in1, in2, in3, pdst, stride) \
  232. { \
  233. SW(in0, (pdst)) \
  234. SW(in1, (pdst) + stride); \
  235. SW(in2, (pdst) + 2 * stride); \
  236. SW(in3, (pdst) + 3 * stride); \
  237. }
  238. /* Description : Store 4 double words with stride
  239. Arguments : Inputs - in0, in1, in2, in3, pdst, stride
  240. Details : Stores double word from 'in0' to (pdst)
  241. Stores double word from 'in1' to (pdst + stride)
  242. Stores double word from 'in2' to (pdst + 2 * stride)
  243. Stores double word from 'in3' to (pdst + 3 * stride)
  244. */
  245. #define SD4(in0, in1, in2, in3, pdst, stride) \
  246. { \
  247. SD(in0, (pdst)) \
  248. SD(in1, (pdst) + stride); \
  249. SD(in2, (pdst) + 2 * stride); \
  250. SD(in3, (pdst) + 3 * stride); \
  251. }
  252. /* Description : Load vectors with 16 byte elements with stride
  253. Arguments : Inputs - psrc (source pointer to load from)
  254. - stride
  255. Outputs - out0, out1
  256. Return Type - as per RTYPE
  257. Details : Loads 16 byte elements in 'out0' from (psrc)
  258. Loads 16 byte elements in 'out1' from (psrc + stride)
  259. */
  260. #define LD_B2(RTYPE, psrc, stride, out0, out1) \
  261. { \
  262. out0 = LD_B(RTYPE, (psrc)); \
  263. out1 = LD_B(RTYPE, (psrc) + stride); \
  264. }
  265. #define LD_UB2(...) LD_B2(v16u8, __VA_ARGS__)
  266. #define LD_SB2(...) LD_B2(v16i8, __VA_ARGS__)
  267. #define LD_B3(RTYPE, psrc, stride, out0, out1, out2) \
  268. { \
  269. LD_B2(RTYPE, (psrc), stride, out0, out1); \
  270. out2 = LD_B(RTYPE, (psrc) + 2 * stride); \
  271. }
  272. #define LD_UB3(...) LD_B3(v16u8, __VA_ARGS__)
  273. #define LD_SB3(...) LD_B3(v16i8, __VA_ARGS__)
  274. #define LD_B4(RTYPE, psrc, stride, out0, out1, out2, out3) \
  275. { \
  276. LD_B2(RTYPE, (psrc), stride, out0, out1); \
  277. LD_B2(RTYPE, (psrc) + 2 * stride , stride, out2, out3); \
  278. }
  279. #define LD_UB4(...) LD_B4(v16u8, __VA_ARGS__)
  280. #define LD_SB4(...) LD_B4(v16i8, __VA_ARGS__)
  281. #define LD_B5(RTYPE, psrc, stride, out0, out1, out2, out3, out4) \
  282. { \
  283. LD_B4(RTYPE, (psrc), stride, out0, out1, out2, out3); \
  284. out4 = LD_B(RTYPE, (psrc) + 4 * stride); \
  285. }
  286. #define LD_UB5(...) LD_B5(v16u8, __VA_ARGS__)
  287. #define LD_SB5(...) LD_B5(v16i8, __VA_ARGS__)
  288. #define LD_B6(RTYPE, psrc, stride, out0, out1, out2, out3, out4, out5) \
  289. { \
  290. LD_B4(RTYPE, (psrc), stride, out0, out1, out2, out3); \
  291. LD_B2(RTYPE, (psrc) + 4 * stride, stride, out4, out5); \
  292. }
  293. #define LD_SB6(...) LD_B6(v16i8, __VA_ARGS__)
  294. #define LD_B7(RTYPE, psrc, stride, \
  295. out0, out1, out2, out3, out4, out5, out6) \
  296. { \
  297. LD_B5(RTYPE, (psrc), stride, out0, out1, out2, out3, out4); \
  298. LD_B2(RTYPE, (psrc) + 5 * stride, stride, out5, out6); \
  299. }
  300. #define LD_SB7(...) LD_B7(v16i8, __VA_ARGS__)
  301. #define LD_B8(RTYPE, psrc, stride, \
  302. out0, out1, out2, out3, out4, out5, out6, out7) \
  303. { \
  304. LD_B4(RTYPE, (psrc), stride, out0, out1, out2, out3); \
  305. LD_B4(RTYPE, (psrc) + 4 * stride, stride, out4, out5, out6, out7); \
  306. }
  307. #define LD_UB8(...) LD_B8(v16u8, __VA_ARGS__)
  308. #define LD_SB8(...) LD_B8(v16i8, __VA_ARGS__)
  309. /* Description : Load vectors with 8 halfword elements with stride
  310. Arguments : Inputs - psrc (source pointer to load from)
  311. - stride
  312. Outputs - out0, out1
  313. Details : Loads 8 halfword elements in 'out0' from (psrc)
  314. Loads 8 halfword elements in 'out1' from (psrc + stride)
  315. */
  316. #define LD_H2(RTYPE, psrc, stride, out0, out1) \
  317. { \
  318. out0 = LD_H(RTYPE, (psrc)); \
  319. out1 = LD_H(RTYPE, (psrc) + (stride)); \
  320. }
  321. #define LD_UH2(...) LD_H2(v8u16, __VA_ARGS__)
  322. #define LD_SH2(...) LD_H2(v8i16, __VA_ARGS__)
  323. #define LD_H4(RTYPE, psrc, stride, out0, out1, out2, out3) \
  324. { \
  325. LD_H2(RTYPE, (psrc), stride, out0, out1); \
  326. LD_H2(RTYPE, (psrc) + 2 * stride, stride, out2, out3); \
  327. }
  328. #define LD_UH4(...) LD_H4(v8u16, __VA_ARGS__)
  329. #define LD_SH4(...) LD_H4(v8i16, __VA_ARGS__)
  330. #define LD_H6(RTYPE, psrc, stride, out0, out1, out2, out3, out4, out5) \
  331. { \
  332. LD_H4(RTYPE, (psrc), stride, out0, out1, out2, out3); \
  333. LD_H2(RTYPE, (psrc) + 4 * stride, stride, out4, out5); \
  334. }
  335. #define LD_UH6(...) LD_H6(v8u16, __VA_ARGS__)
  336. #define LD_SH6(...) LD_H6(v8i16, __VA_ARGS__)
  337. #define LD_H8(RTYPE, psrc, stride, \
  338. out0, out1, out2, out3, out4, out5, out6, out7) \
  339. { \
  340. LD_H4(RTYPE, (psrc), stride, out0, out1, out2, out3); \
  341. LD_H4(RTYPE, (psrc) + 4 * stride, stride, out4, out5, out6, out7); \
  342. }
  343. #define LD_UH8(...) LD_H8(v8u16, __VA_ARGS__)
  344. #define LD_SH8(...) LD_H8(v8i16, __VA_ARGS__)
  345. /* Description : Store vectors of 16 byte elements with stride
  346. Arguments : Inputs - in0, in1, stride
  347. Outputs - pdst (destination pointer to store to)
  348. Details : Stores 16 byte elements from 'in0' to (pdst)
  349. Stores 16 byte elements from 'in1' to (pdst + stride)
  350. */
  351. #define ST_B2(RTYPE, in0, in1, pdst, stride) \
  352. { \
  353. ST_B(RTYPE, in0, (pdst)); \
  354. ST_B(RTYPE, in1, (pdst) + stride); \
  355. }
  356. #define ST_UB2(...) ST_B2(v16u8, __VA_ARGS__)
  357. #define ST_SB2(...) ST_B2(v16i8, __VA_ARGS__)
  358. #define ST_B4(RTYPE, in0, in1, in2, in3, pdst, stride) \
  359. { \
  360. ST_B2(RTYPE, in0, in1, (pdst), stride); \
  361. ST_B2(RTYPE, in2, in3, (pdst) + 2 * stride, stride); \
  362. }
  363. #define ST_UB4(...) ST_B4(v16u8, __VA_ARGS__)
  364. #define ST_SB4(...) ST_B4(v16i8, __VA_ARGS__)
  365. #define ST_B8(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  366. pdst, stride) \
  367. { \
  368. ST_B4(RTYPE, in0, in1, in2, in3, pdst, stride); \
  369. ST_B4(RTYPE, in4, in5, in6, in7, (pdst) + 4 * stride, stride); \
  370. }
  371. #define ST_UB8(...) ST_B8(v16u8, __VA_ARGS__)
  372. /* Description : Store vectors of 8 halfword elements with stride
  373. Arguments : Inputs - in0, in1, stride
  374. Outputs - pdst (destination pointer to store to)
  375. Details : Stores 8 halfword elements from 'in0' to (pdst)
  376. Stores 8 halfword elements from 'in1' to (pdst + stride)
  377. */
  378. #define ST_H2(RTYPE, in0, in1, pdst, stride) \
  379. { \
  380. ST_H(RTYPE, in0, (pdst)); \
  381. ST_H(RTYPE, in1, (pdst) + stride); \
  382. }
  383. #define ST_UH2(...) ST_H2(v8u16, __VA_ARGS__)
  384. #define ST_SH2(...) ST_H2(v8i16, __VA_ARGS__)
  385. #define ST_H4(RTYPE, in0, in1, in2, in3, pdst, stride) \
  386. { \
  387. ST_H2(RTYPE, in0, in1, (pdst), stride); \
  388. ST_H2(RTYPE, in2, in3, (pdst) + 2 * stride, stride); \
  389. }
  390. #define ST_SH4(...) ST_H4(v8i16, __VA_ARGS__)
  391. #define ST_H6(RTYPE, in0, in1, in2, in3, in4, in5, pdst, stride) \
  392. { \
  393. ST_H4(RTYPE, in0, in1, in2, in3, (pdst), stride); \
  394. ST_H2(RTYPE, in4, in5, (pdst) + 4 * stride, stride); \
  395. }
  396. #define ST_SH6(...) ST_H6(v8i16, __VA_ARGS__)
  397. #define ST_H8(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride) \
  398. { \
  399. ST_H4(RTYPE, in0, in1, in2, in3, (pdst), stride); \
  400. ST_H4(RTYPE, in4, in5, in6, in7, (pdst) + 4 * stride, stride); \
  401. }
  402. #define ST_SH8(...) ST_H8(v8i16, __VA_ARGS__)
  403. /* Description : Store vectors of word elements with stride
  404. Arguments : Inputs - in0, in1, stride
  405. Outputs - pdst (destination pointer to store to)
  406. Return Type - signed word
  407. Details : Stores 4 word elements from 'in0' to (pdst)
  408. Stores 4 word elements from 'in1' to (pdst + stride)
  409. */
  410. #define ST_SW2(in0, in1, pdst, stride) \
  411. { \
  412. ST_SW(in0, (pdst)); \
  413. ST_SW(in1, (pdst) + stride); \
  414. }
  415. /* Description : Store as 2x4 byte block to destination memory from input vector
  416. Arguments : Inputs - in, stidx, pdst, stride
  417. Return Type - unsigned byte
  418. Details : Index stidx halfword element from 'in' vector is copied and
  419. stored on first line
  420. Index stidx+1 halfword element from 'in' vector is copied and
  421. stored on second line
  422. Index stidx+2 halfword element from 'in' vector is copied and
  423. stored on third line
  424. Index stidx+3 halfword element from 'in' vector is copied and
  425. stored on fourth line
  426. */
  427. #define ST2x4_UB(in, stidx, pdst, stride) \
  428. { \
  429. uint16_t out0_m, out1_m, out2_m, out3_m; \
  430. uint8_t *pblk_2x4_m = (uint8_t *) (pdst); \
  431. \
  432. out0_m = __msa_copy_u_h((v8i16) in, (stidx)); \
  433. out1_m = __msa_copy_u_h((v8i16) in, (stidx + 1)); \
  434. out2_m = __msa_copy_u_h((v8i16) in, (stidx + 2)); \
  435. out3_m = __msa_copy_u_h((v8i16) in, (stidx + 3)); \
  436. \
  437. SH(out0_m, pblk_2x4_m); \
  438. SH(out1_m, pblk_2x4_m + stride); \
  439. SH(out2_m, pblk_2x4_m + 2 * stride); \
  440. SH(out3_m, pblk_2x4_m + 3 * stride); \
  441. }
  442. /* Description : Store as 4x2 byte block to destination memory from input vector
  443. Arguments : Inputs - in, pdst, stride
  444. Return Type - unsigned byte
  445. Details : Index 0 word element from input vector is copied and stored
  446. on first line
  447. Index 1 word element from input vector is copied and stored
  448. on second line
  449. */
  450. #define ST4x2_UB(in, pdst, stride) \
  451. { \
  452. uint32_t out0_m, out1_m; \
  453. uint8_t *pblk_4x2_m = (uint8_t *) (pdst); \
  454. \
  455. out0_m = __msa_copy_u_w((v4i32) in, 0); \
  456. out1_m = __msa_copy_u_w((v4i32) in, 1); \
  457. \
  458. SW(out0_m, pblk_4x2_m); \
  459. SW(out1_m, pblk_4x2_m + stride); \
  460. }
  461. /* Description : Store as 4x4 byte block to destination memory from input vector
  462. Arguments : Inputs - in0, in1, pdst, stride
  463. Return Type - unsigned byte
  464. Details : Idx0 word element from input vector 'in0' is copied and stored
  465. on first line
  466. Idx1 word element from input vector 'in0' is copied and stored
  467. on second line
  468. Idx2 word element from input vector 'in1' is copied and stored
  469. on third line
  470. Idx3 word element from input vector 'in1' is copied and stored
  471. on fourth line
  472. */
  473. #define ST4x4_UB(in0, in1, idx0, idx1, idx2, idx3, pdst, stride) \
  474. { \
  475. uint32_t out0_m, out1_m, out2_m, out3_m; \
  476. uint8_t *pblk_4x4_m = (uint8_t *) (pdst); \
  477. \
  478. out0_m = __msa_copy_u_w((v4i32) in0, idx0); \
  479. out1_m = __msa_copy_u_w((v4i32) in0, idx1); \
  480. out2_m = __msa_copy_u_w((v4i32) in1, idx2); \
  481. out3_m = __msa_copy_u_w((v4i32) in1, idx3); \
  482. \
  483. SW4(out0_m, out1_m, out2_m, out3_m, pblk_4x4_m, stride); \
  484. }
  485. #define ST4x8_UB(in0, in1, pdst, stride) \
  486. { \
  487. uint8_t *pblk_4x8 = (uint8_t *) (pdst); \
  488. \
  489. ST4x4_UB(in0, in0, 0, 1, 2, 3, pblk_4x8, stride); \
  490. ST4x4_UB(in1, in1, 0, 1, 2, 3, pblk_4x8 + 4 * stride, stride); \
  491. }
  492. /* Description : Store as 6x4 byte block to destination memory from input
  493. vectors
  494. Arguments : Inputs - in0, in1, pdst, stride
  495. Return Type - unsigned byte
  496. Details : Index 0 word element from input vector 'in0' is copied and
  497. stored on first line followed by index 2 halfword element
  498. Index 2 word element from input vector 'in0' is copied and
  499. stored on second line followed by index 2 halfword element
  500. Index 0 word element from input vector 'in1' is copied and
  501. stored on third line followed by index 2 halfword element
  502. Index 2 word element from input vector 'in1' is copied and
  503. stored on fourth line followed by index 2 halfword element
  504. */
  505. #define ST6x4_UB(in0, in1, pdst, stride) \
  506. { \
  507. uint32_t out0_m, out1_m, out2_m, out3_m; \
  508. uint16_t out4_m, out5_m, out6_m, out7_m; \
  509. uint8_t *pblk_6x4_m = (uint8_t *) (pdst); \
  510. \
  511. out0_m = __msa_copy_u_w((v4i32) in0, 0); \
  512. out1_m = __msa_copy_u_w((v4i32) in0, 2); \
  513. out2_m = __msa_copy_u_w((v4i32) in1, 0); \
  514. out3_m = __msa_copy_u_w((v4i32) in1, 2); \
  515. \
  516. out4_m = __msa_copy_u_h((v8i16) in0, 2); \
  517. out5_m = __msa_copy_u_h((v8i16) in0, 6); \
  518. out6_m = __msa_copy_u_h((v8i16) in1, 2); \
  519. out7_m = __msa_copy_u_h((v8i16) in1, 6); \
  520. \
  521. SW(out0_m, pblk_6x4_m); \
  522. SH(out4_m, (pblk_6x4_m + 4)); \
  523. pblk_6x4_m += stride; \
  524. SW(out1_m, pblk_6x4_m); \
  525. SH(out5_m, (pblk_6x4_m + 4)); \
  526. pblk_6x4_m += stride; \
  527. SW(out2_m, pblk_6x4_m); \
  528. SH(out6_m, (pblk_6x4_m + 4)); \
  529. pblk_6x4_m += stride; \
  530. SW(out3_m, pblk_6x4_m); \
  531. SH(out7_m, (pblk_6x4_m + 4)); \
  532. }
  533. /* Description : Store as 8x1 byte block to destination memory from input vector
  534. Arguments : Inputs - in, pdst
  535. Details : Index 0 double word element from input vector 'in' is copied
  536. and stored to destination memory at (pdst)
  537. */
  538. #define ST8x1_UB(in, pdst) \
  539. { \
  540. uint64_t out0_m; \
  541. out0_m = __msa_copy_u_d((v2i64) in, 0); \
  542. SD(out0_m, pdst); \
  543. }
  544. /* Description : Store as 8x2 byte block to destination memory from input vector
  545. Arguments : Inputs - in, pdst, stride
  546. Details : Index 0 double word element from input vector 'in' is copied
  547. and stored to destination memory at (pdst)
  548. Index 1 double word element from input vector 'in' is copied
  549. and stored to destination memory at (pdst + stride)
  550. */
  551. #define ST8x2_UB(in, pdst, stride) \
  552. { \
  553. uint64_t out0_m, out1_m; \
  554. uint8_t *pblk_8x2_m = (uint8_t *) (pdst); \
  555. \
  556. out0_m = __msa_copy_u_d((v2i64) in, 0); \
  557. out1_m = __msa_copy_u_d((v2i64) in, 1); \
  558. \
  559. SD(out0_m, pblk_8x2_m); \
  560. SD(out1_m, pblk_8x2_m + stride); \
  561. }
  562. /* Description : Store as 8x4 byte block to destination memory from input
  563. vectors
  564. Arguments : Inputs - in0, in1, pdst, stride
  565. Details : Index 0 double word element from input vector 'in0' is copied
  566. and stored to destination memory at (pblk_8x4_m)
  567. Index 1 double word element from input vector 'in0' is copied
  568. and stored to destination memory at (pblk_8x4_m + stride)
  569. Index 0 double word element from input vector 'in1' is copied
  570. and stored to destination memory at (pblk_8x4_m + 2 * stride)
  571. Index 1 double word element from input vector 'in1' is copied
  572. and stored to destination memory at (pblk_8x4_m + 3 * stride)
  573. */
  574. #define ST8x4_UB(in0, in1, pdst, stride) \
  575. { \
  576. uint64_t out0_m, out1_m, out2_m, out3_m; \
  577. uint8_t *pblk_8x4_m = (uint8_t *) (pdst); \
  578. \
  579. out0_m = __msa_copy_u_d((v2i64) in0, 0); \
  580. out1_m = __msa_copy_u_d((v2i64) in0, 1); \
  581. out2_m = __msa_copy_u_d((v2i64) in1, 0); \
  582. out3_m = __msa_copy_u_d((v2i64) in1, 1); \
  583. \
  584. SD4(out0_m, out1_m, out2_m, out3_m, pblk_8x4_m, stride); \
  585. }
  586. #define ST8x8_UB(in0, in1, in2, in3, pdst, stride) \
  587. { \
  588. uint8_t *pblk_8x8_m = (uint8_t *) (pdst); \
  589. \
  590. ST8x4_UB(in0, in1, pblk_8x8_m, stride); \
  591. ST8x4_UB(in2, in3, pblk_8x8_m + 4 * stride, stride); \
  592. }
  593. #define ST12x4_UB(in0, in1, in2, pdst, stride) \
  594. { \
  595. uint8_t *pblk_12x4_m = (uint8_t *) (pdst); \
  596. \
  597. /* left 8x4 */ \
  598. ST8x4_UB(in0, in1, pblk_12x4_m, stride); \
  599. /* right 4x4 */ \
  600. ST4x4_UB(in2, in2, 0, 1, 2, 3, pblk_12x4_m + 8, stride); \
  601. }
  602. /* Description : Store as 12x8 byte block to destination memory from
  603. input vectors
  604. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride
  605. Details : Index 0 double word element from input vector 'in0' is copied
  606. and stored to destination memory at (pblk_12x8_m) followed by
  607. index 2 word element from same input vector 'in0' at
  608. (pblk_12x8_m + 8)
  609. Similar to remaining lines
  610. */
  611. #define ST12x8_UB(in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride) \
  612. { \
  613. uint64_t out0_m, out1_m, out2_m, out3_m; \
  614. uint64_t out4_m, out5_m, out6_m, out7_m; \
  615. uint32_t out8_m, out9_m, out10_m, out11_m; \
  616. uint32_t out12_m, out13_m, out14_m, out15_m; \
  617. uint8_t *pblk_12x8_m = (uint8_t *) (pdst); \
  618. \
  619. out0_m = __msa_copy_u_d((v2i64) in0, 0); \
  620. out1_m = __msa_copy_u_d((v2i64) in1, 0); \
  621. out2_m = __msa_copy_u_d((v2i64) in2, 0); \
  622. out3_m = __msa_copy_u_d((v2i64) in3, 0); \
  623. out4_m = __msa_copy_u_d((v2i64) in4, 0); \
  624. out5_m = __msa_copy_u_d((v2i64) in5, 0); \
  625. out6_m = __msa_copy_u_d((v2i64) in6, 0); \
  626. out7_m = __msa_copy_u_d((v2i64) in7, 0); \
  627. \
  628. out8_m = __msa_copy_u_w((v4i32) in0, 2); \
  629. out9_m = __msa_copy_u_w((v4i32) in1, 2); \
  630. out10_m = __msa_copy_u_w((v4i32) in2, 2); \
  631. out11_m = __msa_copy_u_w((v4i32) in3, 2); \
  632. out12_m = __msa_copy_u_w((v4i32) in4, 2); \
  633. out13_m = __msa_copy_u_w((v4i32) in5, 2); \
  634. out14_m = __msa_copy_u_w((v4i32) in6, 2); \
  635. out15_m = __msa_copy_u_w((v4i32) in7, 2); \
  636. \
  637. SD(out0_m, pblk_12x8_m); \
  638. SW(out8_m, pblk_12x8_m + 8); \
  639. pblk_12x8_m += stride; \
  640. SD(out1_m, pblk_12x8_m); \
  641. SW(out9_m, pblk_12x8_m + 8); \
  642. pblk_12x8_m += stride; \
  643. SD(out2_m, pblk_12x8_m); \
  644. SW(out10_m, pblk_12x8_m + 8); \
  645. pblk_12x8_m += stride; \
  646. SD(out3_m, pblk_12x8_m); \
  647. SW(out11_m, pblk_12x8_m + 8); \
  648. pblk_12x8_m += stride; \
  649. SD(out4_m, pblk_12x8_m); \
  650. SW(out12_m, pblk_12x8_m + 8); \
  651. pblk_12x8_m += stride; \
  652. SD(out5_m, pblk_12x8_m); \
  653. SW(out13_m, pblk_12x8_m + 8); \
  654. pblk_12x8_m += stride; \
  655. SD(out6_m, pblk_12x8_m); \
  656. SW(out14_m, pblk_12x8_m + 8); \
  657. pblk_12x8_m += stride; \
  658. SD(out7_m, pblk_12x8_m); \
  659. SW(out15_m, pblk_12x8_m + 8); \
  660. }
  661. /* Description : Immediate number of columns to slide with zero
  662. Arguments : Inputs - in0, in1, slide_val
  663. Outputs - out0, out1
  664. Return Type - as per RTYPE
  665. Details : Byte elements from 'zero_m' vector are slide into 'in0' by
  666. number of elements specified by 'slide_val'
  667. */
  668. #define SLDI_B2_0(RTYPE, in0, in1, out0, out1, slide_val) \
  669. { \
  670. v16i8 zero_m = { 0 }; \
  671. out0 = (RTYPE) __msa_sldi_b((v16i8) zero_m, (v16i8) in0, slide_val); \
  672. out1 = (RTYPE) __msa_sldi_b((v16i8) zero_m, (v16i8) in1, slide_val); \
  673. }
  674. #define SLDI_B2_0_UB(...) SLDI_B2_0(v16u8, __VA_ARGS__)
  675. #define SLDI_B4_0(RTYPE, in0, in1, in2, in3, \
  676. out0, out1, out2, out3, slide_val) \
  677. { \
  678. SLDI_B2_0(RTYPE, in0, in1, out0, out1, slide_val); \
  679. SLDI_B2_0(RTYPE, in2, in3, out2, out3, slide_val); \
  680. }
  681. #define SLDI_B4_0_SB(...) SLDI_B4_0(v16i8, __VA_ARGS__)
  682. /* Description : Immediate number of columns to slide
  683. Arguments : Inputs - in0_0, in0_1, in1_0, in1_1, slide_val
  684. Outputs - out0, out1
  685. Return Type - as per RTYPE
  686. Details : Byte elements from 'in0_0' vector are slide into 'in1_0' by
  687. number of elements specified by 'slide_val'
  688. */
  689. #define SLDI_B2(RTYPE, in0_0, in0_1, in1_0, in1_1, out0, out1, slide_val) \
  690. { \
  691. out0 = (RTYPE) __msa_sldi_b((v16i8) in0_0, (v16i8) in1_0, slide_val); \
  692. out1 = (RTYPE) __msa_sldi_b((v16i8) in0_1, (v16i8) in1_1, slide_val); \
  693. }
  694. #define SLDI_B2_UB(...) SLDI_B2(v16u8, __VA_ARGS__)
  695. #define SLDI_B2_SB(...) SLDI_B2(v16i8, __VA_ARGS__)
  696. #define SLDI_B2_SH(...) SLDI_B2(v8i16, __VA_ARGS__)
  697. /* Description : Shuffle byte vector elements as per mask vector
  698. Arguments : Inputs - in0, in1, in2, in3, mask0, mask1
  699. Outputs - out0, out1
  700. Return Type - as per RTYPE
  701. Details : Selective byte elements from in0 & in1 are copied to out0 as
  702. per control vector mask0
  703. Selective byte elements from in2 & in3 are copied to out1 as
  704. per control vector mask1
  705. */
  706. #define VSHF_B2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1) \
  707. { \
  708. out0 = (RTYPE) __msa_vshf_b((v16i8) mask0, (v16i8) in1, (v16i8) in0); \
  709. out1 = (RTYPE) __msa_vshf_b((v16i8) mask1, (v16i8) in3, (v16i8) in2); \
  710. }
  711. #define VSHF_B2_UB(...) VSHF_B2(v16u8, __VA_ARGS__)
  712. #define VSHF_B2_SB(...) VSHF_B2(v16i8, __VA_ARGS__)
  713. #define VSHF_B2_UH(...) VSHF_B2(v8u16, __VA_ARGS__)
  714. #define VSHF_B2_SH(...) VSHF_B2(v8i16, __VA_ARGS__)
  715. #define VSHF_B3(RTYPE, in0, in1, in2, in3, in4, in5, mask0, mask1, mask2, \
  716. out0, out1, out2) \
  717. { \
  718. VSHF_B2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1); \
  719. out2 = (RTYPE) __msa_vshf_b((v16i8) mask2, (v16i8) in5, (v16i8) in4); \
  720. }
  721. #define VSHF_B3_SB(...) VSHF_B3(v16i8, __VA_ARGS__)
  722. #define VSHF_B4(RTYPE, in0, in1, mask0, mask1, mask2, mask3, \
  723. out0, out1, out2, out3) \
  724. { \
  725. VSHF_B2(RTYPE, in0, in1, in0, in1, mask0, mask1, out0, out1); \
  726. VSHF_B2(RTYPE, in0, in1, in0, in1, mask2, mask3, out2, out3); \
  727. }
  728. #define VSHF_B4_SB(...) VSHF_B4(v16i8, __VA_ARGS__)
  729. /* Description : Shuffle byte vector elements as per mask vector
  730. Arguments : Inputs - in0, in1, in2, in3, mask0, mask1
  731. Outputs - out0, out1
  732. Return Type - as per RTYPE
  733. Details : Selective byte elements from in0 & in1 are copied to out0 as
  734. per control vector mask0
  735. Selective byte elements from in2 & in3 are copied to out1 as
  736. per control vector mask1
  737. */
  738. #define VSHF_W2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1) \
  739. { \
  740. out0 = (RTYPE) __msa_vshf_w((v4i32) mask0, (v4i32) in1, (v4i32) in0); \
  741. out1 = (RTYPE) __msa_vshf_w((v4i32) mask1, (v4i32) in3, (v4i32) in2); \
  742. }
  743. #define VSHF_W2_SB(...) VSHF_W2(v16i8, __VA_ARGS__)
  744. /* Description : Dot product of byte vector elements
  745. Arguments : Inputs - mult0, mult1
  746. cnst0, cnst1
  747. Outputs - out0, out1
  748. Return Type - signed halfword
  749. Details : Signed byte elements from mult0 are multiplied with
  750. signed byte elements from cnst0 producing a result
  751. twice the size of input i.e. signed halfword.
  752. Then this multiplication results of adjacent odd-even elements
  753. are added together and stored to the out vector
  754. (2 signed halfword results)
  755. */
  756. #define DOTP_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  757. { \
  758. out0 = (RTYPE) __msa_dotp_s_h((v16i8) mult0, (v16i8) cnst0); \
  759. out1 = (RTYPE) __msa_dotp_s_h((v16i8) mult1, (v16i8) cnst1); \
  760. }
  761. #define DOTP_SB2_SH(...) DOTP_SB2(v8i16, __VA_ARGS__)
  762. #define DOTP_SB3(RTYPE, mult0, mult1, mult2, cnst0, cnst1, cnst2, \
  763. out0, out1, out2) \
  764. { \
  765. DOTP_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  766. out2 = (RTYPE) __msa_dotp_s_h((v16i8) mult2, (v16i8) cnst2); \
  767. }
  768. #define DOTP_SB3_SH(...) DOTP_SB3(v8i16, __VA_ARGS__)
  769. #define DOTP_SB4(RTYPE, mult0, mult1, mult2, mult3, \
  770. cnst0, cnst1, cnst2, cnst3, out0, out1, out2, out3) \
  771. { \
  772. DOTP_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  773. DOTP_SB2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  774. }
  775. #define DOTP_SB4_SH(...) DOTP_SB4(v8i16, __VA_ARGS__)
  776. /* Description : Dot product of halfword vector elements
  777. Arguments : Inputs - mult0, mult1
  778. cnst0, cnst1
  779. Outputs - out0, out1
  780. Return Type - signed word
  781. Details : Signed halfword elements from mult0 are multiplied with
  782. signed halfword elements from cnst0 producing a result
  783. twice the size of input i.e. signed word.
  784. Then this multiplication results of adjacent odd-even elements
  785. are added together and stored to the out vector
  786. (2 signed word results)
  787. */
  788. #define DOTP_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  789. { \
  790. out0 = (RTYPE) __msa_dotp_s_w((v8i16) mult0, (v8i16) cnst0); \
  791. out1 = (RTYPE) __msa_dotp_s_w((v8i16) mult1, (v8i16) cnst1); \
  792. }
  793. #define DOTP_SH2_SW(...) DOTP_SH2(v4i32, __VA_ARGS__)
  794. #define DOTP_SH4(RTYPE, mult0, mult1, mult2, mult3, \
  795. cnst0, cnst1, cnst2, cnst3, \
  796. out0, out1, out2, out3) \
  797. { \
  798. DOTP_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  799. DOTP_SH2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  800. }
  801. #define DOTP_SH4_SW(...) DOTP_SH4(v4i32, __VA_ARGS__)
  802. /* Description : Dot product & addition of byte vector elements
  803. Arguments : Inputs - mult0, mult1
  804. cnst0, cnst1
  805. Outputs - out0, out1
  806. Return Type - signed halfword
  807. Details : Signed byte elements from mult0 are multiplied with
  808. signed byte elements from cnst0 producing a result
  809. twice the size of input i.e. signed halfword.
  810. Then this multiplication results of adjacent odd-even elements
  811. are added to the out vector
  812. (2 signed halfword results)
  813. */
  814. #define DPADD_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  815. { \
  816. out0 = (RTYPE) __msa_dpadd_s_h((v8i16) out0, \
  817. (v16i8) mult0, (v16i8) cnst0); \
  818. out1 = (RTYPE) __msa_dpadd_s_h((v8i16) out1, \
  819. (v16i8) mult1, (v16i8) cnst1); \
  820. }
  821. #define DPADD_SB2_SH(...) DPADD_SB2(v8i16, __VA_ARGS__)
  822. #define DPADD_SB4(RTYPE, mult0, mult1, mult2, mult3, \
  823. cnst0, cnst1, cnst2, cnst3, out0, out1, out2, out3) \
  824. { \
  825. DPADD_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  826. DPADD_SB2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  827. }
  828. #define DPADD_SB4_SH(...) DPADD_SB4(v8i16, __VA_ARGS__)
  829. /* Description : Dot product & addition of halfword vector elements
  830. Arguments : Inputs - mult0, mult1
  831. cnst0, cnst1
  832. Outputs - out0, out1
  833. Return Type - signed word
  834. Details : Signed halfword elements from mult0 are multiplied with
  835. signed halfword elements from cnst0 producing a result
  836. twice the size of input i.e. signed word.
  837. Then this multiplication results of adjacent odd-even elements
  838. are added to the out vector
  839. (2 signed word results)
  840. */
  841. #define DPADD_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  842. { \
  843. out0 = (RTYPE) __msa_dpadd_s_w((v4i32) out0, \
  844. (v8i16) mult0, (v8i16) cnst0); \
  845. out1 = (RTYPE) __msa_dpadd_s_w((v4i32) out1, \
  846. (v8i16) mult1, (v8i16) cnst1); \
  847. }
  848. #define DPADD_SH2_SW(...) DPADD_SH2(v4i32, __VA_ARGS__)
  849. /* Description : Clips all halfword elements of input vector between min & max
  850. out = ((in) < (min)) ? (min) : (((in) > (max)) ? (max) : (in))
  851. Arguments : Inputs - in (input vector)
  852. - min (min threshold)
  853. - max (max threshold)
  854. Outputs - out_m (output vector with clipped elements)
  855. Return Type - signed halfword
  856. */
  857. #define CLIP_SH(in, min, max) \
  858. ( { \
  859. v8i16 out_m; \
  860. \
  861. out_m = __msa_max_s_h((v8i16) min, (v8i16) in); \
  862. out_m = __msa_min_s_h((v8i16) max, (v8i16) out_m); \
  863. out_m; \
  864. } )
  865. /* Description : Clips all signed halfword elements of input vector
  866. between 0 & 255
  867. Arguments : Inputs - in (input vector)
  868. Outputs - out_m (output vector with clipped elements)
  869. Return Type - signed halfword
  870. */
  871. #define CLIP_SH_0_255(in) \
  872. ( { \
  873. v8i16 max_m = __msa_ldi_h(255); \
  874. v8i16 out_m; \
  875. \
  876. out_m = __msa_maxi_s_h((v8i16) in, 0); \
  877. out_m = __msa_min_s_h((v8i16) max_m, (v8i16) out_m); \
  878. out_m; \
  879. } )
  880. #define CLIP_SH2_0_255(in0, in1) \
  881. { \
  882. in0 = CLIP_SH_0_255(in0); \
  883. in1 = CLIP_SH_0_255(in1); \
  884. }
  885. #define CLIP_SH4_0_255(in0, in1, in2, in3) \
  886. { \
  887. CLIP_SH2_0_255(in0, in1); \
  888. CLIP_SH2_0_255(in2, in3); \
  889. }
  890. /* Description : Clips all signed word elements of input vector
  891. between 0 & 255
  892. Arguments : Inputs - in (input vector)
  893. Outputs - out_m (output vector with clipped elements)
  894. Return Type - signed word
  895. */
  896. #define CLIP_SW_0_255(in) \
  897. ( { \
  898. v4i32 max_m = __msa_ldi_w(255); \
  899. v4i32 out_m; \
  900. \
  901. out_m = __msa_maxi_s_w((v4i32) in, 0); \
  902. out_m = __msa_min_s_w((v4i32) max_m, (v4i32) out_m); \
  903. out_m; \
  904. } )
  905. /* Description : Horizontal subtraction of unsigned byte vector elements
  906. Arguments : Inputs - in0, in1
  907. Outputs - out0, out1
  908. Return Type - as per RTYPE
  909. Details : Each unsigned odd byte element from 'in0' is subtracted from
  910. even unsigned byte element from 'in0' (pairwise) and the
  911. halfword result is stored in 'out0'
  912. */
  913. #define HSUB_UB2(RTYPE, in0, in1, out0, out1) \
  914. { \
  915. out0 = (RTYPE) __msa_hsub_u_h((v16u8) in0, (v16u8) in0); \
  916. out1 = (RTYPE) __msa_hsub_u_h((v16u8) in1, (v16u8) in1); \
  917. }
  918. #define HSUB_UB2_UH(...) HSUB_UB2(v8u16, __VA_ARGS__)
  919. #define HSUB_UB2_SH(...) HSUB_UB2(v8i16, __VA_ARGS__)
  920. /* Description : Interleave even halfword elements from vectors
  921. Arguments : Inputs - in0, in1, in2, in3
  922. Outputs - out0, out1
  923. Return Type - as per RTYPE
  924. Details : Even halfword elements of 'in0' and even halfword
  925. elements of 'in1' are interleaved and copied to 'out0'
  926. Even halfword elements of 'in2' and even halfword
  927. elements of 'in3' are interleaved and copied to 'out1'
  928. */
  929. #define ILVEV_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  930. { \
  931. out0 = (RTYPE) __msa_ilvev_h((v8i16) in1, (v8i16) in0); \
  932. out1 = (RTYPE) __msa_ilvev_h((v8i16) in3, (v8i16) in2); \
  933. }
  934. #define ILVEV_H2_UB(...) ILVEV_H2(v16u8, __VA_ARGS__)
  935. /* Description : Interleave even word elements from vectors
  936. Arguments : Inputs - in0, in1, in2, in3
  937. Outputs - out0, out1
  938. Return Type - as per RTYPE
  939. Details : Even word elements of 'in0' and even word
  940. elements of 'in1' are interleaved and copied to 'out0'
  941. Even word elements of 'in2' and even word
  942. elements of 'in3' are interleaved and copied to 'out1'
  943. */
  944. #define ILVEV_W2(RTYPE, in0, in1, in2, in3, out0, out1) \
  945. { \
  946. out0 = (RTYPE) __msa_ilvev_w((v4i32) in1, (v4i32) in0); \
  947. out1 = (RTYPE) __msa_ilvev_w((v4i32) in3, (v4i32) in2); \
  948. }
  949. #define ILVEV_W2_SB(...) ILVEV_W2(v16i8, __VA_ARGS__)
  950. /* Description : Interleave even double word elements from vectors
  951. Arguments : Inputs - in0, in1, in2, in3
  952. Outputs - out0, out1
  953. Return Type - as per RTYPE
  954. Details : Even double word elements of 'in0' and even double word
  955. elements of 'in1' are interleaved and copied to 'out0'
  956. Even double word elements of 'in2' and even double word
  957. elements of 'in3' are interleaved and copied to 'out1'
  958. */
  959. #define ILVEV_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  960. { \
  961. out0 = (RTYPE) __msa_ilvev_d((v2i64) in1, (v2i64) in0); \
  962. out1 = (RTYPE) __msa_ilvev_d((v2i64) in3, (v2i64) in2); \
  963. }
  964. #define ILVEV_D2_UB(...) ILVEV_D2(v16u8, __VA_ARGS__)
  965. /* Description : Interleave left half of byte elements from vectors
  966. Arguments : Inputs - in0, in1, in2, in3
  967. Outputs - out0, out1
  968. Return Type - as per RTYPE
  969. Details : Left half of byte elements of in0 and left half of byte
  970. elements of in1 are interleaved and copied to out0.
  971. Left half of byte elements of in2 and left half of byte
  972. elements of in3 are interleaved and copied to out1.
  973. */
  974. #define ILVL_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  975. { \
  976. out0 = (RTYPE) __msa_ilvl_b((v16i8) in0, (v16i8) in1); \
  977. out1 = (RTYPE) __msa_ilvl_b((v16i8) in2, (v16i8) in3); \
  978. }
  979. #define ILVL_B2_SB(...) ILVL_B2(v16i8, __VA_ARGS__)
  980. #define ILVL_B2_SH(...) ILVL_B2(v8i16, __VA_ARGS__)
  981. #define ILVL_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  982. out0, out1, out2, out3) \
  983. { \
  984. ILVL_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  985. ILVL_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
  986. }
  987. #define ILVL_B4_SB(...) ILVL_B4(v16i8, __VA_ARGS__)
  988. #define ILVL_B4_UH(...) ILVL_B4(v8u16, __VA_ARGS__)
  989. #define ILVL_B4_SH(...) ILVL_B4(v8i16, __VA_ARGS__)
  990. /* Description : Interleave left half of halfword elements from vectors
  991. Arguments : Inputs - in0, in1, in2, in3
  992. Outputs - out0, out1
  993. Return Type - as per RTYPE
  994. Details : Left half of halfword elements of in0 and left half of halfword
  995. elements of in1 are interleaved and copied to out0.
  996. Left half of halfword elements of in2 and left half of halfword
  997. elements of in3 are interleaved and copied to out1.
  998. */
  999. #define ILVL_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1000. { \
  1001. out0 = (RTYPE) __msa_ilvl_h((v8i16) in0, (v8i16) in1); \
  1002. out1 = (RTYPE) __msa_ilvl_h((v8i16) in2, (v8i16) in3); \
  1003. }
  1004. #define ILVL_H2_SH(...) ILVL_H2(v8i16, __VA_ARGS__)
  1005. #define ILVL_H2_SW(...) ILVL_H2(v4i32, __VA_ARGS__)
  1006. #define ILVL_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1007. out0, out1, out2, out3) \
  1008. { \
  1009. ILVL_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1010. ILVL_H2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1011. }
  1012. #define ILVL_H4_SH(...) ILVL_H4(v8i16, __VA_ARGS__)
  1013. /* Description : Interleave left half of word elements from vectors
  1014. Arguments : Inputs - in0, in1, in2, in3
  1015. Outputs - out0, out1
  1016. Return Type - as per RTYPE
  1017. Details : Left half of word elements of in0 and left half of word
  1018. elements of in1 are interleaved and copied to out0.
  1019. Left half of word elements of in2 and left half of word
  1020. elements of in3 are interleaved and copied to out1.
  1021. */
  1022. #define ILVL_W2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1023. { \
  1024. out0 = (RTYPE) __msa_ilvl_w((v4i32) in0, (v4i32) in1); \
  1025. out1 = (RTYPE) __msa_ilvl_w((v4i32) in2, (v4i32) in3); \
  1026. }
  1027. #define ILVL_W2_SB(...) ILVL_W2(v16i8, __VA_ARGS__)
  1028. /* Description : Interleave right half of byte elements from vectors
  1029. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1030. Outputs - out0, out1, out2, out3
  1031. Return Type - as per RTYPE
  1032. Details : Right half of byte elements of in0 and right half of byte
  1033. elements of in1 are interleaved and copied to out0.
  1034. Right half of byte elements of in2 and right half of byte
  1035. elements of in3 are interleaved and copied to out1.
  1036. Similar for other pairs
  1037. */
  1038. #define ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1039. { \
  1040. out0 = (RTYPE) __msa_ilvr_b((v16i8) in0, (v16i8) in1); \
  1041. out1 = (RTYPE) __msa_ilvr_b((v16i8) in2, (v16i8) in3); \
  1042. }
  1043. #define ILVR_B2_UB(...) ILVR_B2(v16u8, __VA_ARGS__)
  1044. #define ILVR_B2_SB(...) ILVR_B2(v16i8, __VA_ARGS__)
  1045. #define ILVR_B2_UH(...) ILVR_B2(v8u16, __VA_ARGS__)
  1046. #define ILVR_B2_SH(...) ILVR_B2(v8i16, __VA_ARGS__)
  1047. #define ILVR_B2_SW(...) ILVR_B2(v4i32, __VA_ARGS__)
  1048. #define ILVR_B3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1049. { \
  1050. ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1051. out2 = (RTYPE) __msa_ilvr_b((v16i8) in4, (v16i8) in5); \
  1052. }
  1053. #define ILVR_B3_UB(...) ILVR_B3(v16u8, __VA_ARGS__)
  1054. #define ILVR_B3_UH(...) ILVR_B3(v8u16, __VA_ARGS__)
  1055. #define ILVR_B3_SH(...) ILVR_B3(v8i16, __VA_ARGS__)
  1056. #define ILVR_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1057. out0, out1, out2, out3) \
  1058. { \
  1059. ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1060. ILVR_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1061. }
  1062. #define ILVR_B4_SB(...) ILVR_B4(v16i8, __VA_ARGS__)
  1063. #define ILVR_B4_UH(...) ILVR_B4(v8u16, __VA_ARGS__)
  1064. #define ILVR_B4_SH(...) ILVR_B4(v8i16, __VA_ARGS__)
  1065. /* Description : Interleave right half of halfword elements from vectors
  1066. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1067. Outputs - out0, out1, out2, out3
  1068. Return Type - signed halfword
  1069. Details : Right half of halfword elements of in0 and right half of
  1070. halfword elements of in1 are interleaved and copied to out0.
  1071. Right half of halfword elements of in2 and right half of
  1072. halfword elements of in3 are interleaved and copied to out1.
  1073. Similar for other pairs
  1074. */
  1075. #define ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1076. { \
  1077. out0 = (RTYPE) __msa_ilvr_h((v8i16) in0, (v8i16) in1); \
  1078. out1 = (RTYPE) __msa_ilvr_h((v8i16) in2, (v8i16) in3); \
  1079. }
  1080. #define ILVR_H2_SH(...) ILVR_H2(v8i16, __VA_ARGS__)
  1081. #define ILVR_H2_SW(...) ILVR_H2(v4i32, __VA_ARGS__)
  1082. #define ILVR_H3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1083. { \
  1084. ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1085. out2 = (RTYPE) __msa_ilvr_h((v8i16) in4, (v8i16) in5); \
  1086. }
  1087. #define ILVR_H3_SH(...) ILVR_H3(v8i16, __VA_ARGS__)
  1088. #define ILVR_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1089. out0, out1, out2, out3) \
  1090. { \
  1091. ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1092. ILVR_H2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1093. }
  1094. #define ILVR_H4_SH(...) ILVR_H4(v8i16, __VA_ARGS__)
  1095. #define ILVR_W2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1096. { \
  1097. out0 = (RTYPE) __msa_ilvr_w((v4i32) in0, (v4i32) in1); \
  1098. out1 = (RTYPE) __msa_ilvr_w((v4i32) in2, (v4i32) in3); \
  1099. }
  1100. #define ILVR_W2_UB(...) ILVR_W2(v16u8, __VA_ARGS__)
  1101. #define ILVR_W2_SB(...) ILVR_W2(v16i8, __VA_ARGS__)
  1102. #define ILVR_W4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1103. out0, out1, out2, out3) \
  1104. { \
  1105. ILVR_W2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1106. ILVR_W2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1107. }
  1108. #define ILVR_W4_SB(...) ILVR_W4(v16i8, __VA_ARGS__)
  1109. /* Description : Interleave right half of double word elements from vectors
  1110. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1111. Outputs - out0, out1, out2, out3
  1112. Return Type - unsigned double word
  1113. Details : Right half of double word elements of in0 and right half of
  1114. double word elements of in1 are interleaved and copied to out0.
  1115. Right half of double word elements of in2 and right half of
  1116. double word elements of in3 are interleaved and copied to out1.
  1117. */
  1118. #define ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1119. { \
  1120. out0 = (RTYPE) __msa_ilvr_d((v2i64) (in0), (v2i64) (in1)); \
  1121. out1 = (RTYPE) __msa_ilvr_d((v2i64) (in2), (v2i64) (in3)); \
  1122. }
  1123. #define ILVR_D2_SB(...) ILVR_D2(v16i8, __VA_ARGS__)
  1124. #define ILVR_D2_SH(...) ILVR_D2(v8i16, __VA_ARGS__)
  1125. #define ILVR_D3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1126. { \
  1127. ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1128. out2 = (RTYPE) __msa_ilvr_d((v2i64) (in4), (v2i64) (in5)); \
  1129. }
  1130. #define ILVR_D3_SB(...) ILVR_D3(v16i8, __VA_ARGS__)
  1131. #define ILVR_D4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1132. out0, out1, out2, out3) \
  1133. { \
  1134. ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1135. ILVR_D2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1136. }
  1137. #define ILVR_D4_SB(...) ILVR_D4(v16i8, __VA_ARGS__)
  1138. /* Description : Interleave both left and right half of input vectors
  1139. Arguments : Inputs - in0, in1
  1140. Outputs - out0, out1
  1141. Return Type - as per RTYPE
  1142. Details : Right half of byte elements from 'in0' and 'in1' are
  1143. interleaved and stored to 'out0'
  1144. Left half of byte elements from 'in0' and 'in1' are
  1145. interleaved and stored to 'out1'
  1146. */
  1147. #define ILVRL_B2(RTYPE, in0, in1, out0, out1) \
  1148. { \
  1149. out0 = (RTYPE) __msa_ilvr_b((v16i8) in0, (v16i8) in1); \
  1150. out1 = (RTYPE) __msa_ilvl_b((v16i8) in0, (v16i8) in1); \
  1151. }
  1152. #define ILVRL_B2_SB(...) ILVRL_B2(v16i8, __VA_ARGS__)
  1153. #define ILVRL_B2_SH(...) ILVRL_B2(v8i16, __VA_ARGS__)
  1154. #define ILVRL_H2(RTYPE, in0, in1, out0, out1) \
  1155. { \
  1156. out0 = (RTYPE) __msa_ilvr_h((v8i16) in0, (v8i16) in1); \
  1157. out1 = (RTYPE) __msa_ilvl_h((v8i16) in0, (v8i16) in1); \
  1158. }
  1159. #define ILVRL_H2_SB(...) ILVRL_H2(v16i8, __VA_ARGS__)
  1160. #define ILVRL_H2_SH(...) ILVRL_H2(v8i16, __VA_ARGS__)
  1161. #define ILVRL_H2_SW(...) ILVRL_H2(v4i32, __VA_ARGS__)
  1162. #define ILVRL_W2(RTYPE, in0, in1, out0, out1) \
  1163. { \
  1164. out0 = (RTYPE) __msa_ilvr_w((v4i32) in0, (v4i32) in1); \
  1165. out1 = (RTYPE) __msa_ilvl_w((v4i32) in0, (v4i32) in1); \
  1166. }
  1167. #define ILVRL_W2_SH(...) ILVRL_W2(v8i16, __VA_ARGS__)
  1168. /* Description : Maximum values between signed elements of vector and
  1169. 5-bit signed immediate value are copied to the output vector
  1170. Arguments : Inputs - in0, in1, in2, in3, max_val
  1171. Outputs - in0, in1, in2, in3 (in place)
  1172. Return Type - unsigned halfword
  1173. Details : Maximum of signed halfword element values from 'in0' and
  1174. 'max_val' are written to output vector 'in0'
  1175. */
  1176. #define MAXI_SH2(RTYPE, in0, in1, max_val) \
  1177. { \
  1178. in0 = (RTYPE) __msa_maxi_s_h((v8i16) in0, (max_val)); \
  1179. in1 = (RTYPE) __msa_maxi_s_h((v8i16) in1, (max_val)); \
  1180. }
  1181. #define MAXI_SH2_SH(...) MAXI_SH2(v8i16, __VA_ARGS__)
  1182. #define MAXI_SH4(RTYPE, in0, in1, in2, in3, max_val) \
  1183. { \
  1184. MAXI_SH2(RTYPE, in0, in1, max_val); \
  1185. MAXI_SH2(RTYPE, in2, in3, max_val); \
  1186. }
  1187. #define MAXI_SH4_UH(...) MAXI_SH4(v8u16, __VA_ARGS__)
  1188. /* Description : Saturate the halfword element values to the max
  1189. unsigned value of (sat_val+1 bits)
  1190. The element data width remains unchanged
  1191. Arguments : Inputs - in0, in1, in2, in3, sat_val
  1192. Outputs - in0, in1, in2, in3 (in place)
  1193. Return Type - unsigned halfword
  1194. Details : Each unsigned halfword element from 'in0' is saturated to the
  1195. value generated with (sat_val+1) bit range
  1196. Results are in placed to original vectors
  1197. */
  1198. #define SAT_UH2(RTYPE, in0, in1, sat_val) \
  1199. { \
  1200. in0 = (RTYPE) __msa_sat_u_h((v8u16) in0, sat_val); \
  1201. in1 = (RTYPE) __msa_sat_u_h((v8u16) in1, sat_val); \
  1202. }
  1203. #define SAT_UH2_UH(...) SAT_UH2(v8u16, __VA_ARGS__)
  1204. #define SAT_UH4(RTYPE, in0, in1, in2, in3, sat_val) \
  1205. { \
  1206. SAT_UH2(RTYPE, in0, in1, sat_val); \
  1207. SAT_UH2(RTYPE, in2, in3, sat_val) \
  1208. }
  1209. #define SAT_UH4_UH(...) SAT_UH4(v8u16, __VA_ARGS__)
  1210. /* Description : Saturate the halfword element values to the max
  1211. unsigned value of (sat_val+1 bits)
  1212. The element data width remains unchanged
  1213. Arguments : Inputs - in0, in1, in2, in3, sat_val
  1214. Outputs - in0, in1, in2, in3 (in place)
  1215. Return Type - unsigned halfword
  1216. Details : Each unsigned halfword element from 'in0' is saturated to the
  1217. value generated with (sat_val+1) bit range
  1218. Results are in placed to original vectors
  1219. */
  1220. #define SAT_SH2(RTYPE, in0, in1, sat_val) \
  1221. { \
  1222. in0 = (RTYPE) __msa_sat_s_h((v8i16) in0, sat_val); \
  1223. in1 = (RTYPE) __msa_sat_s_h((v8i16) in1, sat_val); \
  1224. }
  1225. #define SAT_SH2_SH(...) SAT_SH2(v8i16, __VA_ARGS__)
  1226. #define SAT_SH3(RTYPE, in0, in1, in2, sat_val) \
  1227. { \
  1228. SAT_SH2(RTYPE, in0, in1, sat_val) \
  1229. in2 = (RTYPE) __msa_sat_s_h((v8i16) in2, sat_val); \
  1230. }
  1231. #define SAT_SH3_SH(...) SAT_SH3(v8i16, __VA_ARGS__)
  1232. #define SAT_SH4(RTYPE, in0, in1, in2, in3, sat_val) \
  1233. { \
  1234. SAT_SH2(RTYPE, in0, in1, sat_val); \
  1235. SAT_SH2(RTYPE, in2, in3, sat_val); \
  1236. }
  1237. #define SAT_SH4_SH(...) SAT_SH4(v8i16, __VA_ARGS__)
  1238. /* Description : Indexed halfword element values are replicated to all
  1239. elements in output vector
  1240. Arguments : Inputs - in, idx0, idx1
  1241. Outputs - out0, out1
  1242. Return Type - as per RTYPE
  1243. Details : 'idx0' element value from 'in' vector is replicated to all
  1244. elements in 'out0' vector
  1245. Valid index range for halfword operation is 0-7
  1246. */
  1247. #define SPLATI_H2(RTYPE, in, idx0, idx1, out0, out1) \
  1248. { \
  1249. out0 = (RTYPE) __msa_splati_h((v8i16) in, idx0); \
  1250. out1 = (RTYPE) __msa_splati_h((v8i16) in, idx1); \
  1251. }
  1252. #define SPLATI_H2_SB(...) SPLATI_H2(v16i8, __VA_ARGS__)
  1253. #define SPLATI_H2_SH(...) SPLATI_H2(v8i16, __VA_ARGS__)
  1254. #define SPLATI_H4(RTYPE, in, idx0, idx1, idx2, idx3, \
  1255. out0, out1, out2, out3) \
  1256. { \
  1257. SPLATI_H2(RTYPE, in, idx0, idx1, out0, out1); \
  1258. SPLATI_H2(RTYPE, in, idx2, idx3, out2, out3); \
  1259. }
  1260. #define SPLATI_H4_SB(...) SPLATI_H4(v16i8, __VA_ARGS__)
  1261. #define SPLATI_H4_SH(...) SPLATI_H4(v8i16, __VA_ARGS__)
  1262. /* Description : Indexed word element values are replicated to all
  1263. elements in output vector
  1264. Arguments : Inputs - in, stidx
  1265. Outputs - out0, out1
  1266. Return Type - as per RTYPE
  1267. Details : 'stidx' element value from 'in' vector is replicated to all
  1268. elements in 'out0' vector
  1269. 'stidx + 1' element value from 'in' vector is replicated to all
  1270. elements in 'out1' vector
  1271. Valid index range for halfword operation is 0-3
  1272. */
  1273. #define SPLATI_W2(RTYPE, in, stidx, out0, out1) \
  1274. { \
  1275. out0 = (RTYPE) __msa_splati_w((v4i32) in, stidx); \
  1276. out1 = (RTYPE) __msa_splati_w((v4i32) in, (stidx+1)); \
  1277. }
  1278. #define SPLATI_W2_SW(...) SPLATI_W2(v4i32, __VA_ARGS__)
  1279. #define SPLATI_W4(RTYPE, in, out0, out1, out2, out3) \
  1280. { \
  1281. SPLATI_W2(RTYPE, in, 0, out0, out1); \
  1282. SPLATI_W2(RTYPE, in, 2, out2, out3); \
  1283. }
  1284. #define SPLATI_W4_SW(...) SPLATI_W4(v4i32, __VA_ARGS__)
  1285. /* Description : Pack even byte elements of vector pairs
  1286. Arguments : Inputs - in0, in1, in2, in3
  1287. Outputs - out0, out1
  1288. Return Type - as per RTYPE
  1289. Details : Even byte elements of in0 are copied to the left half of
  1290. out0 & even byte elements of in1 are copied to the right
  1291. half of out0.
  1292. Even byte elements of in2 are copied to the left half of
  1293. out1 & even byte elements of in3 are copied to the right
  1294. half of out1.
  1295. */
  1296. #define PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1297. { \
  1298. out0 = (RTYPE) __msa_pckev_b((v16i8) in0, (v16i8) in1); \
  1299. out1 = (RTYPE) __msa_pckev_b((v16i8) in2, (v16i8) in3); \
  1300. }
  1301. #define PCKEV_B2_SB(...) PCKEV_B2(v16i8, __VA_ARGS__)
  1302. #define PCKEV_B2_UB(...) PCKEV_B2(v16u8, __VA_ARGS__)
  1303. #define PCKEV_B2_SH(...) PCKEV_B2(v8i16, __VA_ARGS__)
  1304. #define PCKEV_B2_SW(...) PCKEV_B2(v4i32, __VA_ARGS__)
  1305. #define PCKEV_B3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1306. { \
  1307. PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1308. out2 = (RTYPE) __msa_pckev_b((v16i8) in4, (v16i8) in5); \
  1309. }
  1310. #define PCKEV_B3_UB(...) PCKEV_B3(v16u8, __VA_ARGS__)
  1311. #define PCKEV_B3_SB(...) PCKEV_B3(v16i8, __VA_ARGS__)
  1312. #define PCKEV_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1313. out0, out1, out2, out3) \
  1314. { \
  1315. PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1316. PCKEV_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1317. }
  1318. #define PCKEV_B4_SB(...) PCKEV_B4(v16i8, __VA_ARGS__)
  1319. #define PCKEV_B4_UB(...) PCKEV_B4(v16u8, __VA_ARGS__)
  1320. #define PCKEV_B4_SH(...) PCKEV_B4(v8i16, __VA_ARGS__)
  1321. #define PCKEV_B4_SW(...) PCKEV_B4(v4i32, __VA_ARGS__)
  1322. /* Description : Pack even halfword elements of vector pairs
  1323. Arguments : Inputs - in0, in1, in2, in3
  1324. Outputs - out0, out1
  1325. Return Type - as per RTYPE
  1326. Details : Even halfword elements of in0 are copied to the left half of
  1327. out0 & even halfword elements of in1 are copied to the right
  1328. half of out0.
  1329. Even halfword elements of in2 are copied to the left half of
  1330. out1 & even halfword elements of in3 are copied to the right
  1331. half of out1.
  1332. */
  1333. #define PCKEV_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1334. { \
  1335. out0 = (RTYPE) __msa_pckev_h((v8i16) in0, (v8i16) in1); \
  1336. out1 = (RTYPE) __msa_pckev_h((v8i16) in2, (v8i16) in3); \
  1337. }
  1338. #define PCKEV_H2_SH(...) PCKEV_H2(v8i16, __VA_ARGS__)
  1339. #define PCKEV_H2_SW(...) PCKEV_H2(v4i32, __VA_ARGS__)
  1340. #define PCKEV_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1341. out0, out1, out2, out3) \
  1342. { \
  1343. PCKEV_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1344. PCKEV_H2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1345. }
  1346. #define PCKEV_H4_SH(...) PCKEV_H4(v8i16, __VA_ARGS__)
  1347. #define PCKEV_H4_SW(...) PCKEV_H4(v4i32, __VA_ARGS__)
  1348. /* Description : Each byte element is logically xor'ed with immediate 128
  1349. Arguments : Inputs - in0, in1
  1350. Outputs - in0, in1 (in-place)
  1351. Return Type - as per RTYPE
  1352. Details : Each unsigned byte element from input vector 'in0' is
  1353. logically xor'ed with 128 and result is in-place stored in
  1354. 'in0' vector
  1355. Each unsigned byte element from input vector 'in1' is
  1356. logically xor'ed with 128 and result is in-place stored in
  1357. 'in1' vector
  1358. Similar for other pairs
  1359. */
  1360. #define XORI_B2_128(RTYPE, in0, in1) \
  1361. { \
  1362. in0 = (RTYPE) __msa_xori_b((v16u8) in0, 128); \
  1363. in1 = (RTYPE) __msa_xori_b((v16u8) in1, 128); \
  1364. }
  1365. #define XORI_B2_128_UB(...) XORI_B2_128(v16u8, __VA_ARGS__)
  1366. #define XORI_B2_128_SB(...) XORI_B2_128(v16i8, __VA_ARGS__)
  1367. #define XORI_B2_128_SH(...) XORI_B2_128(v8i16, __VA_ARGS__)
  1368. #define XORI_B3_128(RTYPE, in0, in1, in2) \
  1369. { \
  1370. XORI_B2_128(RTYPE, in0, in1); \
  1371. in2 = (RTYPE) __msa_xori_b((v16u8) in2, 128); \
  1372. }
  1373. #define XORI_B3_128_SB(...) XORI_B3_128(v16i8, __VA_ARGS__)
  1374. #define XORI_B4_128(RTYPE, in0, in1, in2, in3) \
  1375. { \
  1376. XORI_B2_128(RTYPE, in0, in1); \
  1377. XORI_B2_128(RTYPE, in2, in3); \
  1378. }
  1379. #define XORI_B4_128_UB(...) XORI_B4_128(v16u8, __VA_ARGS__)
  1380. #define XORI_B4_128_SB(...) XORI_B4_128(v16i8, __VA_ARGS__)
  1381. #define XORI_B4_128_SH(...) XORI_B4_128(v8i16, __VA_ARGS__)
  1382. #define XORI_B5_128(RTYPE, in0, in1, in2, in3, in4) \
  1383. { \
  1384. XORI_B3_128(RTYPE, in0, in1, in2); \
  1385. XORI_B2_128(RTYPE, in3, in4); \
  1386. }
  1387. #define XORI_B5_128_SB(...) XORI_B5_128(v16i8, __VA_ARGS__)
  1388. #define XORI_B6_128(RTYPE, in0, in1, in2, in3, in4, in5) \
  1389. { \
  1390. XORI_B4_128(RTYPE, in0, in1, in2, in3); \
  1391. XORI_B2_128(RTYPE, in4, in5); \
  1392. }
  1393. #define XORI_B6_128_SB(...) XORI_B6_128(v16i8, __VA_ARGS__)
  1394. #define XORI_B7_128(RTYPE, in0, in1, in2, in3, in4, in5, in6) \
  1395. { \
  1396. XORI_B4_128(RTYPE, in0, in1, in2, in3); \
  1397. XORI_B3_128(RTYPE, in4, in5, in6); \
  1398. }
  1399. #define XORI_B7_128_SB(...) XORI_B7_128(v16i8, __VA_ARGS__)
  1400. #define XORI_B8_128(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7) \
  1401. { \
  1402. XORI_B4_128(RTYPE, in0, in1, in2, in3); \
  1403. XORI_B4_128(RTYPE, in4, in5, in6, in7); \
  1404. }
  1405. #define XORI_B8_128_SB(...) XORI_B8_128(v16i8, __VA_ARGS__)
  1406. /* Description : Addition of signed halfword elements and signed saturation
  1407. Arguments : Inputs - in0, in1, in2, in3
  1408. Outputs - out0, out1
  1409. Return Type - as per RTYPE
  1410. Details : Signed halfword elements from 'in0' are added to signed
  1411. halfword elements of 'in1'. The result is then signed saturated
  1412. between -32768 to +32767 (as per halfword data type)
  1413. Similar for other pairs
  1414. */
  1415. #define ADDS_SH2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1416. { \
  1417. out0 = (RTYPE) __msa_adds_s_h((v8i16) in0, (v8i16) in1); \
  1418. out1 = (RTYPE) __msa_adds_s_h((v8i16) in2, (v8i16) in3); \
  1419. }
  1420. #define ADDS_SH2_SH(...) ADDS_SH2(v8i16, __VA_ARGS__)
  1421. #define ADDS_SH4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1422. out0, out1, out2, out3) \
  1423. { \
  1424. ADDS_SH2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1425. ADDS_SH2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1426. }
  1427. #define ADDS_SH4_UH(...) ADDS_SH4(v8u16, __VA_ARGS__)
  1428. #define ADDS_SH4_SH(...) ADDS_SH4(v8i16, __VA_ARGS__)
  1429. /* Description : Shift left all elements of vector (generic for all data types)
  1430. Arguments : Inputs - in0, in1, in2, in3, shift
  1431. Outputs - in0, in1, in2, in3 (in place)
  1432. Return Type - as per input vector RTYPE
  1433. Details : Each element of vector 'in0' is left shifted by 'shift' and
  1434. result is in place written to 'in0'
  1435. Similar for other pairs
  1436. */
  1437. #define SLLI_4V(in0, in1, in2, in3, shift) \
  1438. { \
  1439. in0 = in0 << shift; \
  1440. in1 = in1 << shift; \
  1441. in2 = in2 << shift; \
  1442. in3 = in3 << shift; \
  1443. }
  1444. /* Description : Arithmetic shift right all elements of vector
  1445. (generic for all data types)
  1446. Arguments : Inputs - in0, in1, in2, in3, shift
  1447. Outputs - in0, in1, in2, in3 (in place)
  1448. Return Type - as per input vector RTYPE
  1449. Details : Each element of vector 'in0' is right shifted by 'shift' and
  1450. result is in place written to 'in0'
  1451. Here, 'shift' is GP variable passed in
  1452. Similar for other pairs
  1453. */
  1454. #define SRA_4V(in0, in1, in2, in3, shift) \
  1455. { \
  1456. in0 = in0 >> shift; \
  1457. in1 = in1 >> shift; \
  1458. in2 = in2 >> shift; \
  1459. in3 = in3 >> shift; \
  1460. }
  1461. /* Description : Shift right logical all halfword elements of vector
  1462. Arguments : Inputs - in0, in1, in2, in3, shift
  1463. Outputs - in0, in1, in2, in3 (in place)
  1464. Return Type - unsigned halfword
  1465. Details : Each element of vector 'in0' is shifted right logical by
  1466. number of bits respective element holds in vector 'shift' and
  1467. result is in place written to 'in0'
  1468. Here, 'shift' is a vector passed in
  1469. Similar for other pairs
  1470. */
  1471. #define SRL_H4(RTYPE, in0, in1, in2, in3, shift) \
  1472. { \
  1473. in0 = (RTYPE) __msa_srl_h((v8i16) in0, (v8i16) shift); \
  1474. in1 = (RTYPE) __msa_srl_h((v8i16) in1, (v8i16) shift); \
  1475. in2 = (RTYPE) __msa_srl_h((v8i16) in2, (v8i16) shift); \
  1476. in3 = (RTYPE) __msa_srl_h((v8i16) in3, (v8i16) shift); \
  1477. }
  1478. #define SRL_H4_UH(...) SRL_H4(v8u16, __VA_ARGS__)
  1479. /* Description : Shift right arithmetic rounded halfwords
  1480. Arguments : Inputs - in0, in1, shift
  1481. Outputs - in0, in1, (in place)
  1482. Return Type - unsigned halfword
  1483. Details : Each element of vector 'in0' is shifted right arithmetic by
  1484. number of bits respective element holds in vector 'shift'.
  1485. The last discarded bit is added to shifted value for rounding
  1486. and the result is in place written to 'in0'
  1487. Here, 'shift' is a vector passed in
  1488. Similar for other pairs
  1489. */
  1490. #define SRAR_H2(RTYPE, in0, in1, shift) \
  1491. { \
  1492. in0 = (RTYPE) __msa_srar_h((v8i16) in0, (v8i16) shift); \
  1493. in1 = (RTYPE) __msa_srar_h((v8i16) in1, (v8i16) shift); \
  1494. }
  1495. #define SRAR_H2_UH(...) SRAR_H2(v8u16, __VA_ARGS__)
  1496. #define SRAR_H2_SH(...) SRAR_H2(v8i16, __VA_ARGS__)
  1497. #define SRAR_H3(RTYPE, in0, in1, in2, shift) \
  1498. { \
  1499. SRAR_H2(RTYPE, in0, in1, shift) \
  1500. in2 = (RTYPE) __msa_srar_h((v8i16) in2, (v8i16) shift); \
  1501. }
  1502. #define SRAR_H3_SH(...) SRAR_H3(v8i16, __VA_ARGS__)
  1503. #define SRAR_H4(RTYPE, in0, in1, in2, in3, shift) \
  1504. { \
  1505. SRAR_H2(RTYPE, in0, in1, shift) \
  1506. SRAR_H2(RTYPE, in2, in3, shift) \
  1507. }
  1508. #define SRAR_H4_UH(...) SRAR_H4(v8u16, __VA_ARGS__)
  1509. #define SRAR_H4_SH(...) SRAR_H4(v8i16, __VA_ARGS__)
  1510. /* Description : Shift right arithmetic rounded words
  1511. Arguments : Inputs - in0, in1, shift
  1512. Outputs - in0, in1, (in place)
  1513. Return Type - as per RTYPE
  1514. Details : Each element of vector 'in0' is shifted right arithmetic by
  1515. number of bits respective element holds in vector 'shift'.
  1516. The last discarded bit is added to shifted value for rounding
  1517. and the result is in place written to 'in0'
  1518. Here, 'shift' is a vector passed in
  1519. Similar for other pairs
  1520. */
  1521. #define SRAR_W2(RTYPE, in0, in1, shift) \
  1522. { \
  1523. in0 = (RTYPE) __msa_srar_w((v4i32) in0, (v4i32) shift); \
  1524. in1 = (RTYPE) __msa_srar_w((v4i32) in1, (v4i32) shift); \
  1525. }
  1526. #define SRAR_W2_SW(...) SRAR_W2(v4i32, __VA_ARGS__)
  1527. #define SRAR_W4(RTYPE, in0, in1, in2, in3, shift) \
  1528. { \
  1529. SRAR_W2(RTYPE, in0, in1, shift) \
  1530. SRAR_W2(RTYPE, in2, in3, shift) \
  1531. }
  1532. #define SRAR_W4_SW(...) SRAR_W4(v4i32, __VA_ARGS__)
  1533. /* Description : Shift right arithmetic rounded (immediate)
  1534. Arguments : Inputs - in0, in1, in2, in3, shift
  1535. Outputs - in0, in1, in2, in3 (in place)
  1536. Return Type - as per RTYPE
  1537. Details : Each element of vector 'in0' is shifted right arithmetic by
  1538. value in 'shift'.
  1539. The last discarded bit is added to shifted value for rounding
  1540. and the result is in place written to 'in0'
  1541. Similar for other pairs
  1542. */
  1543. #define SRARI_H2(RTYPE, in0, in1, shift) \
  1544. { \
  1545. in0 = (RTYPE) __msa_srari_h((v8i16) in0, shift); \
  1546. in1 = (RTYPE) __msa_srari_h((v8i16) in1, shift); \
  1547. }
  1548. #define SRARI_H2_UH(...) SRARI_H2(v8u16, __VA_ARGS__)
  1549. #define SRARI_H2_SH(...) SRARI_H2(v8i16, __VA_ARGS__)
  1550. #define SRARI_H4(RTYPE, in0, in1, in2, in3, shift) \
  1551. { \
  1552. SRARI_H2(RTYPE, in0, in1, shift); \
  1553. SRARI_H2(RTYPE, in2, in3, shift); \
  1554. }
  1555. #define SRARI_H4_UH(...) SRARI_H4(v8u16, __VA_ARGS__)
  1556. #define SRARI_H4_SH(...) SRARI_H4(v8i16, __VA_ARGS__)
  1557. /* Description : Shift right arithmetic rounded (immediate)
  1558. Arguments : Inputs - in0, in1, shift
  1559. Outputs - in0, in1 (in place)
  1560. Return Type - as per RTYPE
  1561. Details : Each element of vector 'in0' is shifted right arithmetic by
  1562. value in 'shift'.
  1563. The last discarded bit is added to shifted value for rounding
  1564. and the result is in place written to 'in0'
  1565. Similar for other pairs
  1566. */
  1567. #define SRARI_W2(RTYPE, in0, in1, shift) \
  1568. { \
  1569. in0 = (RTYPE) __msa_srari_w((v4i32) in0, shift); \
  1570. in1 = (RTYPE) __msa_srari_w((v4i32) in1, shift); \
  1571. }
  1572. #define SRARI_W2_SW(...) SRARI_W2(v4i32, __VA_ARGS__)
  1573. #define SRARI_W4(RTYPE, in0, in1, in2, in3, shift) \
  1574. { \
  1575. SRARI_W2(RTYPE, in0, in1, shift); \
  1576. SRARI_W2(RTYPE, in2, in3, shift); \
  1577. }
  1578. #define SRARI_W4_SH(...) SRARI_W4(v8i16, __VA_ARGS__)
  1579. #define SRARI_W4_SW(...) SRARI_W4(v4i32, __VA_ARGS__)
  1580. /* Description : Multiplication of pairs of vectors
  1581. Arguments : Inputs - in0, in1, in2, in3
  1582. Outputs - out0, out1
  1583. Details : Each element from 'in0' is multiplied with elements from 'in1'
  1584. and result is written to 'out0'
  1585. Similar for other pairs
  1586. */
  1587. #define MUL2(in0, in1, in2, in3, out0, out1) \
  1588. { \
  1589. out0 = in0 * in1; \
  1590. out1 = in2 * in3; \
  1591. }
  1592. #define MUL4(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, out3) \
  1593. { \
  1594. MUL2(in0, in1, in2, in3, out0, out1); \
  1595. MUL2(in4, in5, in6, in7, out2, out3); \
  1596. }
  1597. /* Description : Addition of 2 pairs of vectors
  1598. Arguments : Inputs - in0, in1, in2, in3
  1599. Outputs - out0, out1
  1600. Details : Each element from 2 pairs vectors is added and 2 results are
  1601. produced
  1602. */
  1603. #define ADD2(in0, in1, in2, in3, out0, out1) \
  1604. { \
  1605. out0 = in0 + in1; \
  1606. out1 = in2 + in3; \
  1607. }
  1608. #define ADD4(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, out3) \
  1609. { \
  1610. ADD2(in0, in1, in2, in3, out0, out1); \
  1611. ADD2(in4, in5, in6, in7, out2, out3); \
  1612. }
  1613. /* Description : Zero extend unsigned byte elements to halfword elements
  1614. Arguments : Inputs - in (1 input unsigned byte vector)
  1615. Outputs - out0, out1 (unsigned 2 halfword vectors)
  1616. Return Type - signed halfword
  1617. Details : Zero extended right half of vector is returned in 'out0'
  1618. Zero extended left half of vector is returned in 'out1'
  1619. */
  1620. #define UNPCK_UB_SH(in, out0, out1) \
  1621. { \
  1622. v16i8 zero_m = { 0 }; \
  1623. \
  1624. ILVRL_B2_SH(zero_m, in, out0, out1); \
  1625. }
  1626. /* Description : Sign extend halfword elements from input vector and return
  1627. result in pair of vectors
  1628. Arguments : Inputs - in (1 input halfword vector)
  1629. Outputs - out0, out1 (sign extended 2 word vectors)
  1630. Return Type - signed word
  1631. Details : Sign bit of halfword elements from input vector 'in' is
  1632. extracted and interleaved right with same vector 'in0' to
  1633. generate 4 signed word elements in 'out0'
  1634. Then interleaved left with same vector 'in0' to
  1635. generate 4 signed word elements in 'out1'
  1636. */
  1637. #define UNPCK_SH_SW(in, out0, out1) \
  1638. { \
  1639. v8i16 tmp_m; \
  1640. \
  1641. tmp_m = __msa_clti_s_h((v8i16) in, 0); \
  1642. ILVRL_H2_SW(tmp_m, in, out0, out1); \
  1643. }
  1644. /* Description : Transposes input 4x4 byte block
  1645. Arguments : Inputs - in0, in1, in2, in3 (input 4x4 byte block)
  1646. Outputs - out0, out1, out2, out3 (output 4x4 byte block)
  1647. Return Type - unsigned byte
  1648. Details :
  1649. */
  1650. #define TRANSPOSE4x4_UB_UB(in0, in1, in2, in3, out0, out1, out2, out3) \
  1651. { \
  1652. v16i8 zero_m = { 0 }; \
  1653. v16i8 s0_m, s1_m, s2_m, s3_m; \
  1654. \
  1655. ILVR_D2_SB(in1, in0, in3, in2, s0_m, s1_m); \
  1656. ILVRL_B2_SB(s1_m, s0_m, s2_m, s3_m); \
  1657. \
  1658. out0 = (v16u8) __msa_ilvr_b(s3_m, s2_m); \
  1659. out1 = (v16u8) __msa_sldi_b(zero_m, (v16i8) out0, 4); \
  1660. out2 = (v16u8) __msa_sldi_b(zero_m, (v16i8) out1, 4); \
  1661. out3 = (v16u8) __msa_sldi_b(zero_m, (v16i8) out2, 4); \
  1662. }
  1663. /* Description : Transposes input 8x4 byte block into 4x8
  1664. Arguments : Inputs - in0, in1, in2, in3 (input 8x4 byte block)
  1665. Outputs - out0, out1, out2, out3 (output 4x8 byte block)
  1666. Return Type - unsigned byte
  1667. Details :
  1668. */
  1669. #define TRANSPOSE8x4_UB(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1670. out0, out1, out2, out3) \
  1671. { \
  1672. v16i8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  1673. \
  1674. ILVEV_W2_SB(in0, in4, in1, in5, tmp0_m, tmp1_m); \
  1675. tmp2_m = __msa_ilvr_b(tmp1_m, tmp0_m); \
  1676. ILVEV_W2_SB(in2, in6, in3, in7, tmp0_m, tmp1_m); \
  1677. \
  1678. tmp3_m = __msa_ilvr_b(tmp1_m, tmp0_m); \
  1679. ILVRL_H2_SB(tmp3_m, tmp2_m, tmp0_m, tmp1_m); \
  1680. \
  1681. ILVRL_W2(RTYPE, tmp1_m, tmp0_m, out0, out2); \
  1682. out1 = (RTYPE) __msa_ilvl_d((v2i64) out2, (v2i64) out0); \
  1683. out3 = (RTYPE) __msa_ilvl_d((v2i64) out0, (v2i64) out2); \
  1684. }
  1685. #define TRANSPOSE8x4_UB_UB(...) TRANSPOSE8x4_UB(v16u8, __VA_ARGS__)
  1686. /* Description : Transposes 16x8 block into 8x16 with byte elements in vectors
  1687. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7,
  1688. in8, in9, in10, in11, in12, in13, in14, in15
  1689. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  1690. Return Type - unsigned byte
  1691. Details :
  1692. */
  1693. #define TRANSPOSE16x8_UB_UB(in0, in1, in2, in3, in4, in5, in6, in7, \
  1694. in8, in9, in10, in11, in12, in13, in14, in15, \
  1695. out0, out1, out2, out3, out4, out5, out6, out7) \
  1696. { \
  1697. v16u8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  1698. v16u8 tmp4_m, tmp5_m, tmp6_m, tmp7_m; \
  1699. \
  1700. ILVEV_D2_UB(in0, in8, in1, in9, out7, out6); \
  1701. ILVEV_D2_UB(in2, in10, in3, in11, out5, out4); \
  1702. ILVEV_D2_UB(in4, in12, in5, in13, out3, out2); \
  1703. ILVEV_D2_UB(in6, in14, in7, in15, out1, out0); \
  1704. \
  1705. tmp0_m = (v16u8) __msa_ilvev_b((v16i8) out6, (v16i8) out7); \
  1706. tmp4_m = (v16u8) __msa_ilvod_b((v16i8) out6, (v16i8) out7); \
  1707. tmp1_m = (v16u8) __msa_ilvev_b((v16i8) out4, (v16i8) out5); \
  1708. tmp5_m = (v16u8) __msa_ilvod_b((v16i8) out4, (v16i8) out5); \
  1709. out5 = (v16u8) __msa_ilvev_b((v16i8) out2, (v16i8) out3); \
  1710. tmp6_m = (v16u8) __msa_ilvod_b((v16i8) out2, (v16i8) out3); \
  1711. out7 = (v16u8) __msa_ilvev_b((v16i8) out0, (v16i8) out1); \
  1712. tmp7_m = (v16u8) __msa_ilvod_b((v16i8) out0, (v16i8) out1); \
  1713. \
  1714. ILVEV_H2_UB(tmp0_m, tmp1_m, out5, out7, tmp2_m, tmp3_m); \
  1715. out0 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  1716. out4 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  1717. \
  1718. tmp2_m = (v16u8) __msa_ilvod_h((v8i16) tmp1_m, (v8i16) tmp0_m); \
  1719. tmp3_m = (v16u8) __msa_ilvod_h((v8i16) out7, (v8i16) out5); \
  1720. out2 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  1721. out6 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  1722. \
  1723. ILVEV_H2_UB(tmp4_m, tmp5_m, tmp6_m, tmp7_m, tmp2_m, tmp3_m); \
  1724. out1 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  1725. out5 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  1726. \
  1727. tmp2_m = (v16u8) __msa_ilvod_h((v8i16) tmp5_m, (v8i16) tmp4_m); \
  1728. tmp2_m = (v16u8) __msa_ilvod_h((v8i16) tmp5_m, (v8i16) tmp4_m); \
  1729. tmp3_m = (v16u8) __msa_ilvod_h((v8i16) tmp7_m, (v8i16) tmp6_m); \
  1730. tmp3_m = (v16u8) __msa_ilvod_h((v8i16) tmp7_m, (v8i16) tmp6_m); \
  1731. out3 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  1732. out7 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  1733. }
  1734. /* Description : Pack even elements of input vectors & xor with 128
  1735. Arguments : Inputs - in0, in1
  1736. Outputs - out_m
  1737. Return Type - unsigned byte
  1738. Details : Signed byte even elements from 'in0' and 'in1' are packed
  1739. together in one vector and the resulted vector is xor'ed with
  1740. 128 to shift the range from signed to unsigned byte
  1741. */
  1742. #define PCKEV_XORI128_UB(in0, in1) \
  1743. ( { \
  1744. v16u8 out_m; \
  1745. out_m = (v16u8) __msa_pckev_b((v16i8) in1, (v16i8) in0); \
  1746. out_m = (v16u8) __msa_xori_b((v16u8) out_m, 128); \
  1747. out_m; \
  1748. } )
  1749. /* Description : Pack even byte elements, extract 0 & 2 index words from pair
  1750. of results and store 4 words in destination memory as per
  1751. stride
  1752. Arguments : Inputs - in0, in1, in2, in3, pdst, stride
  1753. */
  1754. #define PCKEV_ST4x4_UB(in0, in1, in2, in3, pdst, stride) \
  1755. { \
  1756. uint32_t out0_m, out1_m, out2_m, out3_m; \
  1757. v16i8 tmp0_m, tmp1_m; \
  1758. \
  1759. PCKEV_B2_SB(in1, in0, in3, in2, tmp0_m, tmp1_m); \
  1760. \
  1761. out0_m = __msa_copy_u_w((v4i32) tmp0_m, 0); \
  1762. out1_m = __msa_copy_u_w((v4i32) tmp0_m, 2); \
  1763. out2_m = __msa_copy_u_w((v4i32) tmp1_m, 0); \
  1764. out3_m = __msa_copy_u_w((v4i32) tmp1_m, 2); \
  1765. \
  1766. SW4(out0_m, out1_m, out2_m, out3_m, pdst, stride); \
  1767. }
  1768. #endif /* AVUTIL_MIPS_GENERIC_MACROS_MSA_H */