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.

2725 lines
134KB

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