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.

2418 lines
117KB

  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_B4_0(RTYPE, in0, in1, in2, in3, \
  753. out0, out1, out2, out3, slide_val) \
  754. { \
  755. SLDI_B2_0(RTYPE, in0, in1, out0, out1, slide_val); \
  756. SLDI_B2_0(RTYPE, in2, in3, out2, out3, slide_val); \
  757. }
  758. #define SLDI_B4_0_UB(...) SLDI_B4_0(v16u8, __VA_ARGS__)
  759. #define SLDI_B4_0_SB(...) SLDI_B4_0(v16i8, __VA_ARGS__)
  760. #define SLDI_B4_0_SH(...) SLDI_B4_0(v8i16, __VA_ARGS__)
  761. /* Description : Immediate number of columns to slide
  762. Arguments : Inputs - in0_0, in0_1, in1_0, in1_1, slide_val
  763. Outputs - out0, out1
  764. Return Type - as per RTYPE
  765. Details : Byte elements from 'in0_0' vector are slide into 'in1_0' by
  766. number of elements specified by 'slide_val'
  767. */
  768. #define SLDI_B2(RTYPE, in0_0, in0_1, in1_0, in1_1, out0, out1, slide_val) \
  769. { \
  770. out0 = (RTYPE) __msa_sldi_b((v16i8) in0_0, (v16i8) in1_0, slide_val); \
  771. out1 = (RTYPE) __msa_sldi_b((v16i8) in0_1, (v16i8) in1_1, slide_val); \
  772. }
  773. #define SLDI_B2_UB(...) SLDI_B2(v16u8, __VA_ARGS__)
  774. #define SLDI_B2_SB(...) SLDI_B2(v16i8, __VA_ARGS__)
  775. #define SLDI_B2_SH(...) SLDI_B2(v8i16, __VA_ARGS__)
  776. /* Description : Shuffle byte vector elements as per mask vector
  777. Arguments : Inputs - in0, in1, in2, in3, mask0, mask1
  778. Outputs - out0, out1
  779. Return Type - as per RTYPE
  780. Details : Selective byte elements from in0 & in1 are copied to out0 as
  781. per control vector mask0
  782. Selective byte elements from in2 & in3 are copied to out1 as
  783. per control vector mask1
  784. */
  785. #define VSHF_B2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1) \
  786. { \
  787. out0 = (RTYPE) __msa_vshf_b((v16i8) mask0, (v16i8) in1, (v16i8) in0); \
  788. out1 = (RTYPE) __msa_vshf_b((v16i8) mask1, (v16i8) in3, (v16i8) in2); \
  789. }
  790. #define VSHF_B2_UB(...) VSHF_B2(v16u8, __VA_ARGS__)
  791. #define VSHF_B2_SB(...) VSHF_B2(v16i8, __VA_ARGS__)
  792. #define VSHF_B2_UH(...) VSHF_B2(v8u16, __VA_ARGS__)
  793. #define VSHF_B2_SH(...) VSHF_B2(v8i16, __VA_ARGS__)
  794. #define VSHF_B3(RTYPE, in0, in1, in2, in3, in4, in5, mask0, mask1, mask2, \
  795. out0, out1, out2) \
  796. { \
  797. VSHF_B2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1); \
  798. out2 = (RTYPE) __msa_vshf_b((v16i8) mask2, (v16i8) in5, (v16i8) in4); \
  799. }
  800. #define VSHF_B3_SB(...) VSHF_B3(v16i8, __VA_ARGS__)
  801. #define VSHF_B4(RTYPE, in0, in1, mask0, mask1, mask2, mask3, \
  802. out0, out1, out2, out3) \
  803. { \
  804. VSHF_B2(RTYPE, in0, in1, in0, in1, mask0, mask1, out0, out1); \
  805. VSHF_B2(RTYPE, in0, in1, in0, in1, mask2, mask3, out2, out3); \
  806. }
  807. #define VSHF_B4_SB(...) VSHF_B4(v16i8, __VA_ARGS__)
  808. #define VSHF_B4_SH(...) VSHF_B4(v8i16, __VA_ARGS__)
  809. /* Description : Shuffle halfword vector elements as per mask vector
  810. Arguments : Inputs - in0, in1, in2, in3, mask0, mask1
  811. Outputs - out0, out1
  812. Return Type - as per RTYPE
  813. Details : Selective halfword elements from in0 & in1 are copied to out0
  814. as per control vector mask0
  815. Selective halfword elements from in2 & in3 are copied to out1
  816. as per control vector mask1
  817. */
  818. #define VSHF_H2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1) \
  819. { \
  820. out0 = (RTYPE) __msa_vshf_h((v8i16) mask0, (v8i16) in1, (v8i16) in0); \
  821. out1 = (RTYPE) __msa_vshf_h((v8i16) mask1, (v8i16) in3, (v8i16) in2); \
  822. }
  823. #define VSHF_H2_SH(...) VSHF_H2(v8i16, __VA_ARGS__)
  824. /* Description : Shuffle byte vector elements as per mask vector
  825. Arguments : Inputs - in0, in1, in2, in3, mask0, mask1
  826. Outputs - out0, out1
  827. Return Type - as per RTYPE
  828. Details : Selective byte elements from in0 & in1 are copied to out0 as
  829. per control vector mask0
  830. Selective byte elements from in2 & in3 are copied to out1 as
  831. per control vector mask1
  832. */
  833. #define VSHF_W2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1) \
  834. { \
  835. out0 = (RTYPE) __msa_vshf_w((v4i32) mask0, (v4i32) in1, (v4i32) in0); \
  836. out1 = (RTYPE) __msa_vshf_w((v4i32) mask1, (v4i32) in3, (v4i32) in2); \
  837. }
  838. #define VSHF_W2_SB(...) VSHF_W2(v16i8, __VA_ARGS__)
  839. /* Description : Dot product of byte vector elements
  840. Arguments : Inputs - mult0, mult1
  841. cnst0, cnst1
  842. Outputs - out0, out1
  843. Return Type - unsigned halfword
  844. Details : Unsigned byte elements from mult0 are multiplied with
  845. unsigned byte elements from cnst0 producing a result
  846. twice the size of input i.e. unsigned halfword.
  847. Then this multiplication results of adjacent odd-even elements
  848. are added together and stored to the out vector
  849. (2 unsigned halfword results)
  850. */
  851. #define DOTP_UB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  852. { \
  853. out0 = (RTYPE) __msa_dotp_u_h((v16u8) mult0, (v16u8) cnst0); \
  854. out1 = (RTYPE) __msa_dotp_u_h((v16u8) mult1, (v16u8) cnst1); \
  855. }
  856. #define DOTP_UB2_UH(...) DOTP_UB2(v8u16, __VA_ARGS__)
  857. #define DOTP_UB4(RTYPE, mult0, mult1, mult2, mult3, \
  858. cnst0, cnst1, cnst2, cnst3, \
  859. out0, out1, out2, out3) \
  860. { \
  861. DOTP_UB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  862. DOTP_UB2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  863. }
  864. #define DOTP_UB4_UH(...) DOTP_UB4(v8u16, __VA_ARGS__)
  865. /* Description : Dot product of byte vector elements
  866. Arguments : Inputs - mult0, mult1
  867. cnst0, cnst1
  868. Outputs - out0, out1
  869. Return Type - signed halfword
  870. Details : Signed byte elements from mult0 are multiplied with
  871. signed byte elements from cnst0 producing a result
  872. twice the size of input i.e. signed halfword.
  873. Then this multiplication results of adjacent odd-even elements
  874. are added together and stored to the out vector
  875. (2 signed halfword results)
  876. */
  877. #define DOTP_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  878. { \
  879. out0 = (RTYPE) __msa_dotp_s_h((v16i8) mult0, (v16i8) cnst0); \
  880. out1 = (RTYPE) __msa_dotp_s_h((v16i8) mult1, (v16i8) cnst1); \
  881. }
  882. #define DOTP_SB2_SH(...) DOTP_SB2(v8i16, __VA_ARGS__)
  883. #define DOTP_SB3(RTYPE, mult0, mult1, mult2, cnst0, cnst1, cnst2, \
  884. out0, out1, out2) \
  885. { \
  886. DOTP_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  887. out2 = (RTYPE) __msa_dotp_s_h((v16i8) mult2, (v16i8) cnst2); \
  888. }
  889. #define DOTP_SB3_SH(...) DOTP_SB3(v8i16, __VA_ARGS__)
  890. #define DOTP_SB4(RTYPE, mult0, mult1, mult2, mult3, \
  891. cnst0, cnst1, cnst2, cnst3, out0, out1, out2, out3) \
  892. { \
  893. DOTP_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  894. DOTP_SB2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  895. }
  896. #define DOTP_SB4_SH(...) DOTP_SB4(v8i16, __VA_ARGS__)
  897. /* Description : Dot product of halfword vector elements
  898. Arguments : Inputs - mult0, mult1
  899. cnst0, cnst1
  900. Outputs - out0, out1
  901. Return Type - signed word
  902. Details : Signed halfword elements from mult0 are multiplied with
  903. signed halfword elements from cnst0 producing a result
  904. twice the size of input i.e. signed word.
  905. Then this multiplication results of adjacent odd-even elements
  906. are added together and stored to the out vector
  907. (2 signed word results)
  908. */
  909. #define DOTP_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  910. { \
  911. out0 = (RTYPE) __msa_dotp_s_w((v8i16) mult0, (v8i16) cnst0); \
  912. out1 = (RTYPE) __msa_dotp_s_w((v8i16) mult1, (v8i16) cnst1); \
  913. }
  914. #define DOTP_SH2_SW(...) DOTP_SH2(v4i32, __VA_ARGS__)
  915. #define DOTP_SH4(RTYPE, mult0, mult1, mult2, mult3, \
  916. cnst0, cnst1, cnst2, cnst3, \
  917. out0, out1, out2, out3) \
  918. { \
  919. DOTP_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  920. DOTP_SH2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  921. }
  922. #define DOTP_SH4_SW(...) DOTP_SH4(v4i32, __VA_ARGS__)
  923. /* Description : Dot product & addition of byte vector elements
  924. Arguments : Inputs - mult0, mult1
  925. cnst0, cnst1
  926. Outputs - out0, out1
  927. Return Type - signed halfword
  928. Details : Signed byte elements from mult0 are multiplied with
  929. signed byte elements from cnst0 producing a result
  930. twice the size of input i.e. signed halfword.
  931. Then this multiplication results of adjacent odd-even elements
  932. are added to the out vector
  933. (2 signed halfword results)
  934. */
  935. #define DPADD_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  936. { \
  937. out0 = (RTYPE) __msa_dpadd_s_h((v8i16) out0, \
  938. (v16i8) mult0, (v16i8) cnst0); \
  939. out1 = (RTYPE) __msa_dpadd_s_h((v8i16) out1, \
  940. (v16i8) mult1, (v16i8) cnst1); \
  941. }
  942. #define DPADD_SB2_SH(...) DPADD_SB2(v8i16, __VA_ARGS__)
  943. #define DPADD_SB4(RTYPE, mult0, mult1, mult2, mult3, \
  944. cnst0, cnst1, cnst2, cnst3, out0, out1, out2, out3) \
  945. { \
  946. DPADD_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  947. DPADD_SB2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  948. }
  949. #define DPADD_SB4_SH(...) DPADD_SB4(v8i16, __VA_ARGS__)
  950. /* Description : Dot product & addition of halfword vector elements
  951. Arguments : Inputs - mult0, mult1
  952. cnst0, cnst1
  953. Outputs - out0, out1
  954. Return Type - signed word
  955. Details : Signed halfword elements from mult0 are multiplied with
  956. signed halfword elements from cnst0 producing a result
  957. twice the size of input i.e. signed word.
  958. Then this multiplication results of adjacent odd-even elements
  959. are added to the out vector
  960. (2 signed word results)
  961. */
  962. #define DPADD_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  963. { \
  964. out0 = (RTYPE) __msa_dpadd_s_w((v4i32) out0, \
  965. (v8i16) mult0, (v8i16) cnst0); \
  966. out1 = (RTYPE) __msa_dpadd_s_w((v4i32) out1, \
  967. (v8i16) mult1, (v8i16) cnst1); \
  968. }
  969. #define DPADD_SH2_SW(...) DPADD_SH2(v4i32, __VA_ARGS__)
  970. #define DPADD_SH4(RTYPE, mult0, mult1, mult2, mult3, \
  971. cnst0, cnst1, cnst2, cnst3, out0, out1, out2, out3) \
  972. { \
  973. DPADD_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  974. DPADD_SH2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  975. }
  976. #define DPADD_SH4_SW(...) DPADD_SH4(v4i32, __VA_ARGS__)
  977. /* Description : Clips all halfword elements of input vector between min & max
  978. out = ((in) < (min)) ? (min) : (((in) > (max)) ? (max) : (in))
  979. Arguments : Inputs - in (input vector)
  980. - min (min threshold)
  981. - max (max threshold)
  982. Outputs - out_m (output vector with clipped elements)
  983. Return Type - signed halfword
  984. */
  985. #define CLIP_SH(in, min, max) \
  986. ( { \
  987. v8i16 out_m; \
  988. \
  989. out_m = __msa_max_s_h((v8i16) min, (v8i16) in); \
  990. out_m = __msa_min_s_h((v8i16) max, (v8i16) out_m); \
  991. out_m; \
  992. } )
  993. /* Description : Clips all signed halfword elements of input vector
  994. between 0 & 255
  995. Arguments : Inputs - in (input vector)
  996. Outputs - out_m (output vector with clipped elements)
  997. Return Type - signed halfword
  998. */
  999. #define CLIP_SH_0_255(in) \
  1000. ( { \
  1001. v8i16 max_m = __msa_ldi_h(255); \
  1002. v8i16 out_m; \
  1003. \
  1004. out_m = __msa_maxi_s_h((v8i16) in, 0); \
  1005. out_m = __msa_min_s_h((v8i16) max_m, (v8i16) out_m); \
  1006. out_m; \
  1007. } )
  1008. #define CLIP_SH2_0_255(in0, in1) \
  1009. { \
  1010. in0 = CLIP_SH_0_255(in0); \
  1011. in1 = CLIP_SH_0_255(in1); \
  1012. }
  1013. #define CLIP_SH4_0_255(in0, in1, in2, in3) \
  1014. { \
  1015. CLIP_SH2_0_255(in0, in1); \
  1016. CLIP_SH2_0_255(in2, in3); \
  1017. }
  1018. /* Description : Clips all signed word elements of input vector
  1019. between 0 & 255
  1020. Arguments : Inputs - in (input vector)
  1021. Outputs - out_m (output vector with clipped elements)
  1022. Return Type - signed word
  1023. */
  1024. #define CLIP_SW_0_255(in) \
  1025. ( { \
  1026. v4i32 max_m = __msa_ldi_w(255); \
  1027. v4i32 out_m; \
  1028. \
  1029. out_m = __msa_maxi_s_w((v4i32) in, 0); \
  1030. out_m = __msa_min_s_w((v4i32) max_m, (v4i32) out_m); \
  1031. out_m; \
  1032. } )
  1033. /* Description : Horizontal addition of unsigned byte vector elements
  1034. Arguments : Inputs - in0, in1
  1035. Outputs - out0, out1
  1036. Return Type - as per RTYPE
  1037. Details : Each unsigned odd byte element from 'in0' is added to
  1038. even unsigned byte element from 'in0' (pairwise) and the
  1039. halfword result is stored in 'out0'
  1040. */
  1041. #define HADD_UB2(RTYPE, in0, in1, out0, out1) \
  1042. { \
  1043. out0 = (RTYPE) __msa_hadd_u_h((v16u8) in0, (v16u8) in0); \
  1044. out1 = (RTYPE) __msa_hadd_u_h((v16u8) in1, (v16u8) in1); \
  1045. }
  1046. #define HADD_UB2_UH(...) HADD_UB2(v8u16, __VA_ARGS__)
  1047. /* Description : Horizontal subtraction of unsigned byte vector elements
  1048. Arguments : Inputs - in0, in1
  1049. Outputs - out0, out1
  1050. Return Type - as per RTYPE
  1051. Details : Each unsigned odd byte element from 'in0' is subtracted from
  1052. even unsigned byte element from 'in0' (pairwise) and the
  1053. halfword result is stored in 'out0'
  1054. */
  1055. #define HSUB_UB2(RTYPE, in0, in1, out0, out1) \
  1056. { \
  1057. out0 = (RTYPE) __msa_hsub_u_h((v16u8) in0, (v16u8) in0); \
  1058. out1 = (RTYPE) __msa_hsub_u_h((v16u8) in1, (v16u8) in1); \
  1059. }
  1060. #define HSUB_UB2_UH(...) HSUB_UB2(v8u16, __VA_ARGS__)
  1061. #define HSUB_UB2_SH(...) HSUB_UB2(v8i16, __VA_ARGS__)
  1062. /* Description : Insert specified word elements from input vectors to 1
  1063. destination vector
  1064. Arguments : Inputs - in0, in1, in2, in3 (4 input vectors)
  1065. Outputs - out (output vector)
  1066. Return Type - as per RTYPE
  1067. */
  1068. #define INSERT_W2(RTYPE, in0, in1, out) \
  1069. { \
  1070. out = (RTYPE) __msa_insert_w((v4i32) out, 0, in0); \
  1071. out = (RTYPE) __msa_insert_w((v4i32) out, 1, in1); \
  1072. }
  1073. #define INSERT_W2_UB(...) INSERT_W2(v16u8, __VA_ARGS__)
  1074. #define INSERT_W2_SB(...) INSERT_W2(v16i8, __VA_ARGS__)
  1075. #define INSERT_W4(RTYPE, in0, in1, in2, in3, out) \
  1076. { \
  1077. out = (RTYPE) __msa_insert_w((v4i32) out, 0, in0); \
  1078. out = (RTYPE) __msa_insert_w((v4i32) out, 1, in1); \
  1079. out = (RTYPE) __msa_insert_w((v4i32) out, 2, in2); \
  1080. out = (RTYPE) __msa_insert_w((v4i32) out, 3, in3); \
  1081. }
  1082. #define INSERT_W4_UB(...) INSERT_W4(v16u8, __VA_ARGS__)
  1083. #define INSERT_W4_SB(...) INSERT_W4(v16i8, __VA_ARGS__)
  1084. #define INSERT_W4_SW(...) INSERT_W4(v4i32, __VA_ARGS__)
  1085. /* Description : Insert specified double word elements from input vectors to 1
  1086. destination vector
  1087. Arguments : Inputs - in0, in1 (2 input vectors)
  1088. Outputs - out (output vector)
  1089. Return Type - as per RTYPE
  1090. */
  1091. #define INSERT_D2(RTYPE, in0, in1, out) \
  1092. { \
  1093. out = (RTYPE) __msa_insert_d((v2i64) out, 0, in0); \
  1094. out = (RTYPE) __msa_insert_d((v2i64) out, 1, in1); \
  1095. }
  1096. #define INSERT_D2_UB(...) INSERT_D2(v16u8, __VA_ARGS__)
  1097. #define INSERT_D2_SB(...) INSERT_D2(v16i8, __VA_ARGS__)
  1098. #define INSERT_D2_SD(...) INSERT_D2(v2i64, __VA_ARGS__)
  1099. /* Description : Interleave even byte elements from vectors
  1100. Arguments : Inputs - in0, in1, in2, in3
  1101. Outputs - out0, out1
  1102. Return Type - as per RTYPE
  1103. Details : Even byte elements of 'in0' and even byte
  1104. elements of 'in1' are interleaved and copied to 'out0'
  1105. Even byte elements of 'in2' and even byte
  1106. elements of 'in3' are interleaved and copied to 'out1'
  1107. */
  1108. #define ILVEV_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1109. { \
  1110. out0 = (RTYPE) __msa_ilvev_b((v16i8) in1, (v16i8) in0); \
  1111. out1 = (RTYPE) __msa_ilvev_b((v16i8) in3, (v16i8) in2); \
  1112. }
  1113. #define ILVEV_B2_UB(...) ILVEV_B2(v16u8, __VA_ARGS__)
  1114. #define ILVEV_B2_SB(...) ILVEV_B2(v16i8, __VA_ARGS__)
  1115. #define ILVEV_B2_SH(...) ILVEV_B2(v8i16, __VA_ARGS__)
  1116. #define ILVEV_B2_SD(...) ILVEV_B2(v2i64, __VA_ARGS__)
  1117. /* Description : Interleave even halfword elements from vectors
  1118. Arguments : Inputs - in0, in1, in2, in3
  1119. Outputs - out0, out1
  1120. Return Type - as per RTYPE
  1121. Details : Even halfword elements of 'in0' and even halfword
  1122. elements of 'in1' are interleaved and copied to 'out0'
  1123. Even halfword elements of 'in2' and even halfword
  1124. elements of 'in3' are interleaved and copied to 'out1'
  1125. */
  1126. #define ILVEV_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1127. { \
  1128. out0 = (RTYPE) __msa_ilvev_h((v8i16) in1, (v8i16) in0); \
  1129. out1 = (RTYPE) __msa_ilvev_h((v8i16) in3, (v8i16) in2); \
  1130. }
  1131. #define ILVEV_H2_UB(...) ILVEV_H2(v16u8, __VA_ARGS__)
  1132. /* Description : Interleave even word elements from vectors
  1133. Arguments : Inputs - in0, in1, in2, in3
  1134. Outputs - out0, out1
  1135. Return Type - as per RTYPE
  1136. Details : Even word elements of 'in0' and even word
  1137. elements of 'in1' are interleaved and copied to 'out0'
  1138. Even word elements of 'in2' and even word
  1139. elements of 'in3' are interleaved and copied to 'out1'
  1140. */
  1141. #define ILVEV_W2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1142. { \
  1143. out0 = (RTYPE) __msa_ilvev_w((v4i32) in1, (v4i32) in0); \
  1144. out1 = (RTYPE) __msa_ilvev_w((v4i32) in3, (v4i32) in2); \
  1145. }
  1146. #define ILVEV_W2_SB(...) ILVEV_W2(v16i8, __VA_ARGS__)
  1147. /* Description : Interleave even double word elements from vectors
  1148. Arguments : Inputs - in0, in1, in2, in3
  1149. Outputs - out0, out1
  1150. Return Type - as per RTYPE
  1151. Details : Even double word elements of 'in0' and even double word
  1152. elements of 'in1' are interleaved and copied to 'out0'
  1153. Even double word elements of 'in2' and even double word
  1154. elements of 'in3' are interleaved and copied to 'out1'
  1155. */
  1156. #define ILVEV_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1157. { \
  1158. out0 = (RTYPE) __msa_ilvev_d((v2i64) in1, (v2i64) in0); \
  1159. out1 = (RTYPE) __msa_ilvev_d((v2i64) in3, (v2i64) in2); \
  1160. }
  1161. #define ILVEV_D2_UB(...) ILVEV_D2(v16u8, __VA_ARGS__)
  1162. #define ILVEV_D2_SB(...) ILVEV_D2(v16i8, __VA_ARGS__)
  1163. #define ILVEV_D2_SW(...) ILVEV_D2(v4i32, __VA_ARGS__)
  1164. /* Description : Interleave left half of byte elements from vectors
  1165. Arguments : Inputs - in0, in1, in2, in3
  1166. Outputs - out0, out1
  1167. Return Type - as per RTYPE
  1168. Details : Left half of byte elements of in0 and left half of byte
  1169. elements of in1 are interleaved and copied to out0.
  1170. Left half of byte elements of in2 and left half of byte
  1171. elements of in3 are interleaved and copied to out1.
  1172. */
  1173. #define ILVL_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1174. { \
  1175. out0 = (RTYPE) __msa_ilvl_b((v16i8) in0, (v16i8) in1); \
  1176. out1 = (RTYPE) __msa_ilvl_b((v16i8) in2, (v16i8) in3); \
  1177. }
  1178. #define ILVL_B2_SB(...) ILVL_B2(v16i8, __VA_ARGS__)
  1179. #define ILVL_B2_SH(...) ILVL_B2(v8i16, __VA_ARGS__)
  1180. #define ILVL_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1181. out0, out1, out2, out3) \
  1182. { \
  1183. ILVL_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1184. ILVL_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1185. }
  1186. #define ILVL_B4_SB(...) ILVL_B4(v16i8, __VA_ARGS__)
  1187. #define ILVL_B4_UH(...) ILVL_B4(v8u16, __VA_ARGS__)
  1188. #define ILVL_B4_SH(...) ILVL_B4(v8i16, __VA_ARGS__)
  1189. /* Description : Interleave left half of halfword elements from vectors
  1190. Arguments : Inputs - in0, in1, in2, in3
  1191. Outputs - out0, out1
  1192. Return Type - as per RTYPE
  1193. Details : Left half of halfword elements of in0 and left half of halfword
  1194. elements of in1 are interleaved and copied to out0.
  1195. Left half of halfword elements of in2 and left half of halfword
  1196. elements of in3 are interleaved and copied to out1.
  1197. */
  1198. #define ILVL_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1199. { \
  1200. out0 = (RTYPE) __msa_ilvl_h((v8i16) in0, (v8i16) in1); \
  1201. out1 = (RTYPE) __msa_ilvl_h((v8i16) in2, (v8i16) in3); \
  1202. }
  1203. #define ILVL_H2_SH(...) ILVL_H2(v8i16, __VA_ARGS__)
  1204. #define ILVL_H2_SW(...) ILVL_H2(v4i32, __VA_ARGS__)
  1205. #define ILVL_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1206. out0, out1, out2, out3) \
  1207. { \
  1208. ILVL_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1209. ILVL_H2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1210. }
  1211. #define ILVL_H4_SH(...) ILVL_H4(v8i16, __VA_ARGS__)
  1212. /* Description : Interleave left half of word elements from vectors
  1213. Arguments : Inputs - in0, in1, in2, in3
  1214. Outputs - out0, out1
  1215. Return Type - as per RTYPE
  1216. Details : Left half of word elements of in0 and left half of word
  1217. elements of in1 are interleaved and copied to out0.
  1218. Left half of word elements of in2 and left half of word
  1219. elements of in3 are interleaved and copied to out1.
  1220. */
  1221. #define ILVL_W2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1222. { \
  1223. out0 = (RTYPE) __msa_ilvl_w((v4i32) in0, (v4i32) in1); \
  1224. out1 = (RTYPE) __msa_ilvl_w((v4i32) in2, (v4i32) in3); \
  1225. }
  1226. #define ILVL_W2_SB(...) ILVL_W2(v16i8, __VA_ARGS__)
  1227. /* Description : Interleave right half of byte elements from vectors
  1228. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1229. Outputs - out0, out1, out2, out3
  1230. Return Type - as per RTYPE
  1231. Details : Right half of byte elements of in0 and right half of byte
  1232. elements of in1 are interleaved and copied to out0.
  1233. Right half of byte elements of in2 and right half of byte
  1234. elements of in3 are interleaved and copied to out1.
  1235. Similar for other pairs
  1236. */
  1237. #define ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1238. { \
  1239. out0 = (RTYPE) __msa_ilvr_b((v16i8) in0, (v16i8) in1); \
  1240. out1 = (RTYPE) __msa_ilvr_b((v16i8) in2, (v16i8) in3); \
  1241. }
  1242. #define ILVR_B2_UB(...) ILVR_B2(v16u8, __VA_ARGS__)
  1243. #define ILVR_B2_SB(...) ILVR_B2(v16i8, __VA_ARGS__)
  1244. #define ILVR_B2_UH(...) ILVR_B2(v8u16, __VA_ARGS__)
  1245. #define ILVR_B2_SH(...) ILVR_B2(v8i16, __VA_ARGS__)
  1246. #define ILVR_B2_SW(...) ILVR_B2(v4i32, __VA_ARGS__)
  1247. #define ILVR_B3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1248. { \
  1249. ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1250. out2 = (RTYPE) __msa_ilvr_b((v16i8) in4, (v16i8) in5); \
  1251. }
  1252. #define ILVR_B3_UB(...) ILVR_B3(v16u8, __VA_ARGS__)
  1253. #define ILVR_B3_UH(...) ILVR_B3(v8u16, __VA_ARGS__)
  1254. #define ILVR_B3_SH(...) ILVR_B3(v8i16, __VA_ARGS__)
  1255. #define ILVR_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1256. out0, out1, out2, out3) \
  1257. { \
  1258. ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1259. ILVR_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1260. }
  1261. #define ILVR_B4_UB(...) ILVR_B4(v16u8, __VA_ARGS__)
  1262. #define ILVR_B4_SB(...) ILVR_B4(v16i8, __VA_ARGS__)
  1263. #define ILVR_B4_UH(...) ILVR_B4(v8u16, __VA_ARGS__)
  1264. #define ILVR_B4_SH(...) ILVR_B4(v8i16, __VA_ARGS__)
  1265. #define ILVR_B4_SW(...) ILVR_B4(v4i32, __VA_ARGS__)
  1266. #define ILVR_B8(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1267. in8, in9, in10, in11, in12, in13, in14, in15, \
  1268. out0, out1, out2, out3, out4, out5, out6, out7) \
  1269. { \
  1270. ILVR_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1271. out0, out1, out2, out3); \
  1272. ILVR_B4(RTYPE, in8, in9, in10, in11, in12, in13, in14, in15, \
  1273. out4, out5, out6, out7); \
  1274. }
  1275. #define ILVR_B8_UH(...) ILVR_B8(v8u16, __VA_ARGS__)
  1276. /* Description : Interleave right half of halfword elements from vectors
  1277. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1278. Outputs - out0, out1, out2, out3
  1279. Return Type - signed halfword
  1280. Details : Right half of halfword elements of in0 and right half of
  1281. halfword elements of in1 are interleaved and copied to out0.
  1282. Right half of halfword elements of in2 and right half of
  1283. halfword elements of in3 are interleaved and copied to out1.
  1284. Similar for other pairs
  1285. */
  1286. #define ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1287. { \
  1288. out0 = (RTYPE) __msa_ilvr_h((v8i16) in0, (v8i16) in1); \
  1289. out1 = (RTYPE) __msa_ilvr_h((v8i16) in2, (v8i16) in3); \
  1290. }
  1291. #define ILVR_H2_SH(...) ILVR_H2(v8i16, __VA_ARGS__)
  1292. #define ILVR_H2_SW(...) ILVR_H2(v4i32, __VA_ARGS__)
  1293. #define ILVR_H3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1294. { \
  1295. ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1296. out2 = (RTYPE) __msa_ilvr_h((v8i16) in4, (v8i16) in5); \
  1297. }
  1298. #define ILVR_H3_SH(...) ILVR_H3(v8i16, __VA_ARGS__)
  1299. #define ILVR_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1300. out0, out1, out2, out3) \
  1301. { \
  1302. ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1303. ILVR_H2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1304. }
  1305. #define ILVR_H4_SH(...) ILVR_H4(v8i16, __VA_ARGS__)
  1306. #define ILVR_W2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1307. { \
  1308. out0 = (RTYPE) __msa_ilvr_w((v4i32) in0, (v4i32) in1); \
  1309. out1 = (RTYPE) __msa_ilvr_w((v4i32) in2, (v4i32) in3); \
  1310. }
  1311. #define ILVR_W2_UB(...) ILVR_W2(v16u8, __VA_ARGS__)
  1312. #define ILVR_W2_SB(...) ILVR_W2(v16i8, __VA_ARGS__)
  1313. #define ILVR_W4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1314. out0, out1, out2, out3) \
  1315. { \
  1316. ILVR_W2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1317. ILVR_W2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1318. }
  1319. #define ILVR_W4_SB(...) ILVR_W4(v16i8, __VA_ARGS__)
  1320. /* Description : Interleave right half of double word elements from vectors
  1321. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1322. Outputs - out0, out1, out2, out3
  1323. Return Type - unsigned double word
  1324. Details : Right half of double word elements of in0 and right half of
  1325. double word elements of in1 are interleaved and copied to out0.
  1326. Right half of double word elements of in2 and right half of
  1327. double word elements of in3 are interleaved and copied to out1.
  1328. */
  1329. #define ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1330. { \
  1331. out0 = (RTYPE) __msa_ilvr_d((v2i64) (in0), (v2i64) (in1)); \
  1332. out1 = (RTYPE) __msa_ilvr_d((v2i64) (in2), (v2i64) (in3)); \
  1333. }
  1334. #define ILVR_D2_UB(...) ILVR_D2(v16u8, __VA_ARGS__)
  1335. #define ILVR_D2_SB(...) ILVR_D2(v16i8, __VA_ARGS__)
  1336. #define ILVR_D2_SH(...) ILVR_D2(v8i16, __VA_ARGS__)
  1337. #define ILVR_D3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1338. { \
  1339. ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1340. out2 = (RTYPE) __msa_ilvr_d((v2i64) (in4), (v2i64) (in5)); \
  1341. }
  1342. #define ILVR_D3_SB(...) ILVR_D3(v16i8, __VA_ARGS__)
  1343. #define ILVR_D4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1344. out0, out1, out2, out3) \
  1345. { \
  1346. ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1347. ILVR_D2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1348. }
  1349. #define ILVR_D4_SB(...) ILVR_D4(v16i8, __VA_ARGS__)
  1350. /* Description : Interleave both left and right half of input vectors
  1351. Arguments : Inputs - in0, in1
  1352. Outputs - out0, out1
  1353. Return Type - as per RTYPE
  1354. Details : Right half of byte elements from 'in0' and 'in1' are
  1355. interleaved and stored to 'out0'
  1356. Left half of byte elements from 'in0' and 'in1' are
  1357. interleaved and stored to 'out1'
  1358. */
  1359. #define ILVRL_B2(RTYPE, in0, in1, out0, out1) \
  1360. { \
  1361. out0 = (RTYPE) __msa_ilvr_b((v16i8) in0, (v16i8) in1); \
  1362. out1 = (RTYPE) __msa_ilvl_b((v16i8) in0, (v16i8) in1); \
  1363. }
  1364. #define ILVRL_B2_UB(...) ILVRL_B2(v16u8, __VA_ARGS__)
  1365. #define ILVRL_B2_SB(...) ILVRL_B2(v16i8, __VA_ARGS__)
  1366. #define ILVRL_B2_UH(...) ILVRL_B2(v8u16, __VA_ARGS__)
  1367. #define ILVRL_B2_SH(...) ILVRL_B2(v8i16, __VA_ARGS__)
  1368. #define ILVRL_B2_SW(...) ILVRL_B2(v4i32, __VA_ARGS__)
  1369. #define ILVRL_H2(RTYPE, in0, in1, out0, out1) \
  1370. { \
  1371. out0 = (RTYPE) __msa_ilvr_h((v8i16) in0, (v8i16) in1); \
  1372. out1 = (RTYPE) __msa_ilvl_h((v8i16) in0, (v8i16) in1); \
  1373. }
  1374. #define ILVRL_H2_SB(...) ILVRL_H2(v16i8, __VA_ARGS__)
  1375. #define ILVRL_H2_SH(...) ILVRL_H2(v8i16, __VA_ARGS__)
  1376. #define ILVRL_H2_SW(...) ILVRL_H2(v4i32, __VA_ARGS__)
  1377. #define ILVRL_W2(RTYPE, in0, in1, out0, out1) \
  1378. { \
  1379. out0 = (RTYPE) __msa_ilvr_w((v4i32) in0, (v4i32) in1); \
  1380. out1 = (RTYPE) __msa_ilvl_w((v4i32) in0, (v4i32) in1); \
  1381. }
  1382. #define ILVRL_W2_UB(...) ILVRL_W2(v16u8, __VA_ARGS__)
  1383. #define ILVRL_W2_SH(...) ILVRL_W2(v8i16, __VA_ARGS__)
  1384. #define ILVRL_W2_SW(...) ILVRL_W2(v4i32, __VA_ARGS__)
  1385. /* Description : Maximum values between signed elements of vector and
  1386. 5-bit signed immediate value are copied to the output vector
  1387. Arguments : Inputs - in0, in1, in2, in3, max_val
  1388. Outputs - in0, in1, in2, in3 (in place)
  1389. Return Type - unsigned halfword
  1390. Details : Maximum of signed halfword element values from 'in0' and
  1391. 'max_val' are written to output vector 'in0'
  1392. */
  1393. #define MAXI_SH2(RTYPE, in0, in1, max_val) \
  1394. { \
  1395. in0 = (RTYPE) __msa_maxi_s_h((v8i16) in0, (max_val)); \
  1396. in1 = (RTYPE) __msa_maxi_s_h((v8i16) in1, (max_val)); \
  1397. }
  1398. #define MAXI_SH2_SH(...) MAXI_SH2(v8i16, __VA_ARGS__)
  1399. #define MAXI_SH4(RTYPE, in0, in1, in2, in3, max_val) \
  1400. { \
  1401. MAXI_SH2(RTYPE, in0, in1, max_val); \
  1402. MAXI_SH2(RTYPE, in2, in3, max_val); \
  1403. }
  1404. #define MAXI_SH4_UH(...) MAXI_SH4(v8u16, __VA_ARGS__)
  1405. /* Description : Saturate the halfword element values to the max
  1406. unsigned value of (sat_val+1 bits)
  1407. The element data width remains unchanged
  1408. Arguments : Inputs - in0, in1, in2, in3, sat_val
  1409. Outputs - in0, in1, in2, in3 (in place)
  1410. Return Type - unsigned halfword
  1411. Details : Each unsigned halfword element from 'in0' is saturated to the
  1412. value generated with (sat_val+1) bit range
  1413. Results are in placed to original vectors
  1414. */
  1415. #define SAT_UH2(RTYPE, in0, in1, sat_val) \
  1416. { \
  1417. in0 = (RTYPE) __msa_sat_u_h((v8u16) in0, sat_val); \
  1418. in1 = (RTYPE) __msa_sat_u_h((v8u16) in1, sat_val); \
  1419. }
  1420. #define SAT_UH2_UH(...) SAT_UH2(v8u16, __VA_ARGS__)
  1421. #define SAT_UH4(RTYPE, in0, in1, in2, in3, sat_val) \
  1422. { \
  1423. SAT_UH2(RTYPE, in0, in1, sat_val); \
  1424. SAT_UH2(RTYPE, in2, in3, sat_val) \
  1425. }
  1426. #define SAT_UH4_UH(...) SAT_UH4(v8u16, __VA_ARGS__)
  1427. /* Description : Saturate the halfword element values to the max
  1428. unsigned value of (sat_val+1 bits)
  1429. The element data width remains unchanged
  1430. Arguments : Inputs - in0, in1, in2, in3, sat_val
  1431. Outputs - in0, in1, in2, in3 (in place)
  1432. Return Type - unsigned halfword
  1433. Details : Each unsigned halfword element from 'in0' is saturated to the
  1434. value generated with (sat_val+1) bit range
  1435. Results are in placed to original vectors
  1436. */
  1437. #define SAT_SH2(RTYPE, in0, in1, sat_val) \
  1438. { \
  1439. in0 = (RTYPE) __msa_sat_s_h((v8i16) in0, sat_val); \
  1440. in1 = (RTYPE) __msa_sat_s_h((v8i16) in1, sat_val); \
  1441. }
  1442. #define SAT_SH2_SH(...) SAT_SH2(v8i16, __VA_ARGS__)
  1443. #define SAT_SH3(RTYPE, in0, in1, in2, sat_val) \
  1444. { \
  1445. SAT_SH2(RTYPE, in0, in1, sat_val) \
  1446. in2 = (RTYPE) __msa_sat_s_h((v8i16) in2, sat_val); \
  1447. }
  1448. #define SAT_SH3_SH(...) SAT_SH3(v8i16, __VA_ARGS__)
  1449. #define SAT_SH4(RTYPE, in0, in1, in2, in3, sat_val) \
  1450. { \
  1451. SAT_SH2(RTYPE, in0, in1, sat_val); \
  1452. SAT_SH2(RTYPE, in2, in3, sat_val); \
  1453. }
  1454. #define SAT_SH4_SH(...) SAT_SH4(v8i16, __VA_ARGS__)
  1455. /* Description : Saturate the word element values to the max
  1456. unsigned value of (sat_val+1 bits)
  1457. The element data width remains unchanged
  1458. Arguments : Inputs - in0, in1, in2, in3, sat_val
  1459. Outputs - in0, in1, in2, in3 (in place)
  1460. Return Type - unsigned word
  1461. Details : Each unsigned word element from 'in0' is saturated to the
  1462. value generated with (sat_val+1) bit range
  1463. Results are in placed to original vectors
  1464. */
  1465. #define SAT_SW2(RTYPE, in0, in1, sat_val) \
  1466. { \
  1467. in0 = (RTYPE) __msa_sat_s_w((v4i32) in0, sat_val); \
  1468. in1 = (RTYPE) __msa_sat_s_w((v4i32) in1, sat_val); \
  1469. }
  1470. #define SAT_SW2_SW(...) SAT_SW2(v4i32, __VA_ARGS__)
  1471. #define SAT_SW4(RTYPE, in0, in1, in2, in3, sat_val) \
  1472. { \
  1473. SAT_SW2(RTYPE, in0, in1, sat_val); \
  1474. SAT_SW2(RTYPE, in2, in3, sat_val); \
  1475. }
  1476. #define SAT_SW4_SW(...) SAT_SW4(v4i32, __VA_ARGS__)
  1477. /* Description : Indexed halfword element values are replicated to all
  1478. elements in output vector
  1479. Arguments : Inputs - in, idx0, idx1
  1480. Outputs - out0, out1
  1481. Return Type - as per RTYPE
  1482. Details : 'idx0' element value from 'in' vector is replicated to all
  1483. elements in 'out0' vector
  1484. Valid index range for halfword operation is 0-7
  1485. */
  1486. #define SPLATI_H2(RTYPE, in, idx0, idx1, out0, out1) \
  1487. { \
  1488. out0 = (RTYPE) __msa_splati_h((v8i16) in, idx0); \
  1489. out1 = (RTYPE) __msa_splati_h((v8i16) in, idx1); \
  1490. }
  1491. #define SPLATI_H2_SB(...) SPLATI_H2(v16i8, __VA_ARGS__)
  1492. #define SPLATI_H2_SH(...) SPLATI_H2(v8i16, __VA_ARGS__)
  1493. #define SPLATI_H4(RTYPE, in, idx0, idx1, idx2, idx3, \
  1494. out0, out1, out2, out3) \
  1495. { \
  1496. SPLATI_H2(RTYPE, in, idx0, idx1, out0, out1); \
  1497. SPLATI_H2(RTYPE, in, idx2, idx3, out2, out3); \
  1498. }
  1499. #define SPLATI_H4_SB(...) SPLATI_H4(v16i8, __VA_ARGS__)
  1500. #define SPLATI_H4_SH(...) SPLATI_H4(v8i16, __VA_ARGS__)
  1501. /* Description : Indexed word element values are replicated to all
  1502. elements in output vector
  1503. Arguments : Inputs - in, stidx
  1504. Outputs - out0, out1
  1505. Return Type - as per RTYPE
  1506. Details : 'stidx' element value from 'in' vector is replicated to all
  1507. elements in 'out0' vector
  1508. 'stidx + 1' element value from 'in' vector is replicated to all
  1509. elements in 'out1' vector
  1510. Valid index range for halfword operation is 0-3
  1511. */
  1512. #define SPLATI_W2(RTYPE, in, stidx, out0, out1) \
  1513. { \
  1514. out0 = (RTYPE) __msa_splati_w((v4i32) in, stidx); \
  1515. out1 = (RTYPE) __msa_splati_w((v4i32) in, (stidx+1)); \
  1516. }
  1517. #define SPLATI_W2_SH(...) SPLATI_W2(v8i16, __VA_ARGS__)
  1518. #define SPLATI_W2_SW(...) SPLATI_W2(v4i32, __VA_ARGS__)
  1519. #define SPLATI_W4(RTYPE, in, out0, out1, out2, out3) \
  1520. { \
  1521. SPLATI_W2(RTYPE, in, 0, out0, out1); \
  1522. SPLATI_W2(RTYPE, in, 2, out2, out3); \
  1523. }
  1524. #define SPLATI_W4_SH(...) SPLATI_W4(v8i16, __VA_ARGS__)
  1525. #define SPLATI_W4_SW(...) SPLATI_W4(v4i32, __VA_ARGS__)
  1526. /* Description : Pack even byte elements of vector pairs
  1527. Arguments : Inputs - in0, in1, in2, in3
  1528. Outputs - out0, out1
  1529. Return Type - as per RTYPE
  1530. Details : Even byte elements of in0 are copied to the left half of
  1531. out0 & even byte elements of in1 are copied to the right
  1532. half of out0.
  1533. Even byte elements of in2 are copied to the left half of
  1534. out1 & even byte elements of in3 are copied to the right
  1535. half of out1.
  1536. */
  1537. #define PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1538. { \
  1539. out0 = (RTYPE) __msa_pckev_b((v16i8) in0, (v16i8) in1); \
  1540. out1 = (RTYPE) __msa_pckev_b((v16i8) in2, (v16i8) in3); \
  1541. }
  1542. #define PCKEV_B2_SB(...) PCKEV_B2(v16i8, __VA_ARGS__)
  1543. #define PCKEV_B2_UB(...) PCKEV_B2(v16u8, __VA_ARGS__)
  1544. #define PCKEV_B2_SH(...) PCKEV_B2(v8i16, __VA_ARGS__)
  1545. #define PCKEV_B2_SW(...) PCKEV_B2(v4i32, __VA_ARGS__)
  1546. #define PCKEV_B3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1547. { \
  1548. PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1549. out2 = (RTYPE) __msa_pckev_b((v16i8) in4, (v16i8) in5); \
  1550. }
  1551. #define PCKEV_B3_UB(...) PCKEV_B3(v16u8, __VA_ARGS__)
  1552. #define PCKEV_B3_SB(...) PCKEV_B3(v16i8, __VA_ARGS__)
  1553. #define PCKEV_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1554. out0, out1, out2, out3) \
  1555. { \
  1556. PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1557. PCKEV_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1558. }
  1559. #define PCKEV_B4_SB(...) PCKEV_B4(v16i8, __VA_ARGS__)
  1560. #define PCKEV_B4_UB(...) PCKEV_B4(v16u8, __VA_ARGS__)
  1561. #define PCKEV_B4_SH(...) PCKEV_B4(v8i16, __VA_ARGS__)
  1562. #define PCKEV_B4_SW(...) PCKEV_B4(v4i32, __VA_ARGS__)
  1563. /* Description : Pack even halfword elements of vector pairs
  1564. Arguments : Inputs - in0, in1, in2, in3
  1565. Outputs - out0, out1
  1566. Return Type - as per RTYPE
  1567. Details : Even halfword elements of in0 are copied to the left half of
  1568. out0 & even halfword elements of in1 are copied to the right
  1569. half of out0.
  1570. Even halfword elements of in2 are copied to the left half of
  1571. out1 & even halfword elements of in3 are copied to the right
  1572. half of out1.
  1573. */
  1574. #define PCKEV_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1575. { \
  1576. out0 = (RTYPE) __msa_pckev_h((v8i16) in0, (v8i16) in1); \
  1577. out1 = (RTYPE) __msa_pckev_h((v8i16) in2, (v8i16) in3); \
  1578. }
  1579. #define PCKEV_H2_SH(...) PCKEV_H2(v8i16, __VA_ARGS__)
  1580. #define PCKEV_H2_SW(...) PCKEV_H2(v4i32, __VA_ARGS__)
  1581. #define PCKEV_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1582. out0, out1, out2, out3) \
  1583. { \
  1584. PCKEV_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1585. PCKEV_H2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1586. }
  1587. #define PCKEV_H4_SH(...) PCKEV_H4(v8i16, __VA_ARGS__)
  1588. #define PCKEV_H4_SW(...) PCKEV_H4(v4i32, __VA_ARGS__)
  1589. /* Description : Pack even double word elements of vector pairs
  1590. Arguments : Inputs - in0, in1, in2, in3
  1591. Outputs - out0, out1
  1592. Return Type - unsigned byte
  1593. Details : Even double elements of in0 are copied to the left half of
  1594. out0 & even double elements of in1 are copied to the right
  1595. half of out0.
  1596. Even double elements of in2 are copied to the left half of
  1597. out1 & even double elements of in3 are copied to the right
  1598. half of out1.
  1599. */
  1600. #define PCKEV_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1601. { \
  1602. out0 = (RTYPE) __msa_pckev_d((v2i64) in0, (v2i64) in1); \
  1603. out1 = (RTYPE) __msa_pckev_d((v2i64) in2, (v2i64) in3); \
  1604. }
  1605. #define PCKEV_D2_UB(...) PCKEV_D2(v16u8, __VA_ARGS__)
  1606. #define PCKEV_D2_SB(...) PCKEV_D2(v16i8, __VA_ARGS__)
  1607. #define PCKEV_D2_SH(...) PCKEV_D2(v8i16, __VA_ARGS__)
  1608. #define PCKEV_D4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1609. out0, out1, out2, out3) \
  1610. { \
  1611. PCKEV_D2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1612. PCKEV_D2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1613. }
  1614. #define PCKEV_D4_UB(...) PCKEV_D4(v16u8, __VA_ARGS__)
  1615. /* Description : Each byte element is logically xor'ed with immediate 128
  1616. Arguments : Inputs - in0, in1
  1617. Outputs - in0, in1 (in-place)
  1618. Return Type - as per RTYPE
  1619. Details : Each unsigned byte element from input vector 'in0' is
  1620. logically xor'ed with 128 and result is in-place stored in
  1621. 'in0' vector
  1622. Each unsigned byte element from input vector 'in1' is
  1623. logically xor'ed with 128 and result is in-place stored in
  1624. 'in1' vector
  1625. Similar for other pairs
  1626. */
  1627. #define XORI_B2_128(RTYPE, in0, in1) \
  1628. { \
  1629. in0 = (RTYPE) __msa_xori_b((v16u8) in0, 128); \
  1630. in1 = (RTYPE) __msa_xori_b((v16u8) in1, 128); \
  1631. }
  1632. #define XORI_B2_128_UB(...) XORI_B2_128(v16u8, __VA_ARGS__)
  1633. #define XORI_B2_128_SB(...) XORI_B2_128(v16i8, __VA_ARGS__)
  1634. #define XORI_B2_128_SH(...) XORI_B2_128(v8i16, __VA_ARGS__)
  1635. #define XORI_B3_128(RTYPE, in0, in1, in2) \
  1636. { \
  1637. XORI_B2_128(RTYPE, in0, in1); \
  1638. in2 = (RTYPE) __msa_xori_b((v16u8) in2, 128); \
  1639. }
  1640. #define XORI_B3_128_SB(...) XORI_B3_128(v16i8, __VA_ARGS__)
  1641. #define XORI_B4_128(RTYPE, in0, in1, in2, in3) \
  1642. { \
  1643. XORI_B2_128(RTYPE, in0, in1); \
  1644. XORI_B2_128(RTYPE, in2, in3); \
  1645. }
  1646. #define XORI_B4_128_UB(...) XORI_B4_128(v16u8, __VA_ARGS__)
  1647. #define XORI_B4_128_SB(...) XORI_B4_128(v16i8, __VA_ARGS__)
  1648. #define XORI_B4_128_SH(...) XORI_B4_128(v8i16, __VA_ARGS__)
  1649. #define XORI_B5_128(RTYPE, in0, in1, in2, in3, in4) \
  1650. { \
  1651. XORI_B3_128(RTYPE, in0, in1, in2); \
  1652. XORI_B2_128(RTYPE, in3, in4); \
  1653. }
  1654. #define XORI_B5_128_SB(...) XORI_B5_128(v16i8, __VA_ARGS__)
  1655. #define XORI_B6_128(RTYPE, in0, in1, in2, in3, in4, in5) \
  1656. { \
  1657. XORI_B4_128(RTYPE, in0, in1, in2, in3); \
  1658. XORI_B2_128(RTYPE, in4, in5); \
  1659. }
  1660. #define XORI_B6_128_SB(...) XORI_B6_128(v16i8, __VA_ARGS__)
  1661. #define XORI_B7_128(RTYPE, in0, in1, in2, in3, in4, in5, in6) \
  1662. { \
  1663. XORI_B4_128(RTYPE, in0, in1, in2, in3); \
  1664. XORI_B3_128(RTYPE, in4, in5, in6); \
  1665. }
  1666. #define XORI_B7_128_SB(...) XORI_B7_128(v16i8, __VA_ARGS__)
  1667. #define XORI_B8_128(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7) \
  1668. { \
  1669. XORI_B4_128(RTYPE, in0, in1, in2, in3); \
  1670. XORI_B4_128(RTYPE, in4, in5, in6, in7); \
  1671. }
  1672. #define XORI_B8_128_SB(...) XORI_B8_128(v16i8, __VA_ARGS__)
  1673. /* Description : Addition of signed halfword elements and signed saturation
  1674. Arguments : Inputs - in0, in1, in2, in3
  1675. Outputs - out0, out1
  1676. Return Type - as per RTYPE
  1677. Details : Signed halfword elements from 'in0' are added to signed
  1678. halfword elements of 'in1'. The result is then signed saturated
  1679. between -32768 to +32767 (as per halfword data type)
  1680. Similar for other pairs
  1681. */
  1682. #define ADDS_SH2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1683. { \
  1684. out0 = (RTYPE) __msa_adds_s_h((v8i16) in0, (v8i16) in1); \
  1685. out1 = (RTYPE) __msa_adds_s_h((v8i16) in2, (v8i16) in3); \
  1686. }
  1687. #define ADDS_SH2_SH(...) ADDS_SH2(v8i16, __VA_ARGS__)
  1688. #define ADDS_SH4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1689. out0, out1, out2, out3) \
  1690. { \
  1691. ADDS_SH2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1692. ADDS_SH2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1693. }
  1694. #define ADDS_SH4_UH(...) ADDS_SH4(v8u16, __VA_ARGS__)
  1695. #define ADDS_SH4_SH(...) ADDS_SH4(v8i16, __VA_ARGS__)
  1696. /* Description : Shift left all elements of vector (generic for all data types)
  1697. Arguments : Inputs - in0, in1, in2, in3, shift
  1698. Outputs - in0, in1, in2, in3 (in place)
  1699. Return Type - as per input vector RTYPE
  1700. Details : Each element of vector 'in0' is left shifted by 'shift' and
  1701. result is in place written to 'in0'
  1702. Similar for other pairs
  1703. */
  1704. #define SLLI_4V(in0, in1, in2, in3, shift) \
  1705. { \
  1706. in0 = in0 << shift; \
  1707. in1 = in1 << shift; \
  1708. in2 = in2 << shift; \
  1709. in3 = in3 << shift; \
  1710. }
  1711. /* Description : Arithmetic shift right all elements of vector
  1712. (generic for all data types)
  1713. Arguments : Inputs - in0, in1, in2, in3, shift
  1714. Outputs - in0, in1, in2, in3 (in place)
  1715. Return Type - as per input vector RTYPE
  1716. Details : Each element of vector 'in0' is right shifted by 'shift' and
  1717. result is in place written to 'in0'
  1718. Here, 'shift' is GP variable passed in
  1719. Similar for other pairs
  1720. */
  1721. #define SRA_4V(in0, in1, in2, in3, shift) \
  1722. { \
  1723. in0 = in0 >> shift; \
  1724. in1 = in1 >> shift; \
  1725. in2 = in2 >> shift; \
  1726. in3 = in3 >> shift; \
  1727. }
  1728. /* Description : Shift right logical all halfword elements of vector
  1729. Arguments : Inputs - in0, in1, in2, in3, shift
  1730. Outputs - in0, in1, in2, in3 (in place)
  1731. Return Type - unsigned halfword
  1732. Details : Each element of vector 'in0' is shifted right logical by
  1733. number of bits respective element holds in vector 'shift' and
  1734. result is in place written to 'in0'
  1735. Here, 'shift' is a vector passed in
  1736. Similar for other pairs
  1737. */
  1738. #define SRL_H4(RTYPE, in0, in1, in2, in3, shift) \
  1739. { \
  1740. in0 = (RTYPE) __msa_srl_h((v8i16) in0, (v8i16) shift); \
  1741. in1 = (RTYPE) __msa_srl_h((v8i16) in1, (v8i16) shift); \
  1742. in2 = (RTYPE) __msa_srl_h((v8i16) in2, (v8i16) shift); \
  1743. in3 = (RTYPE) __msa_srl_h((v8i16) in3, (v8i16) shift); \
  1744. }
  1745. #define SRL_H4_UH(...) SRL_H4(v8u16, __VA_ARGS__)
  1746. /* Description : Shift right arithmetic rounded halfwords
  1747. Arguments : Inputs - in0, in1, shift
  1748. Outputs - in0, in1, (in place)
  1749. Return Type - unsigned halfword
  1750. Details : Each element of vector 'in0' is shifted right arithmetic by
  1751. number of bits respective element holds in vector 'shift'.
  1752. The last discarded bit is added to shifted value for rounding
  1753. and the result is in place written to 'in0'
  1754. Here, 'shift' is a vector passed in
  1755. Similar for other pairs
  1756. */
  1757. #define SRAR_H2(RTYPE, in0, in1, shift) \
  1758. { \
  1759. in0 = (RTYPE) __msa_srar_h((v8i16) in0, (v8i16) shift); \
  1760. in1 = (RTYPE) __msa_srar_h((v8i16) in1, (v8i16) shift); \
  1761. }
  1762. #define SRAR_H2_UH(...) SRAR_H2(v8u16, __VA_ARGS__)
  1763. #define SRAR_H2_SH(...) SRAR_H2(v8i16, __VA_ARGS__)
  1764. #define SRAR_H3(RTYPE, in0, in1, in2, shift) \
  1765. { \
  1766. SRAR_H2(RTYPE, in0, in1, shift) \
  1767. in2 = (RTYPE) __msa_srar_h((v8i16) in2, (v8i16) shift); \
  1768. }
  1769. #define SRAR_H3_SH(...) SRAR_H3(v8i16, __VA_ARGS__)
  1770. #define SRAR_H4(RTYPE, in0, in1, in2, in3, shift) \
  1771. { \
  1772. SRAR_H2(RTYPE, in0, in1, shift) \
  1773. SRAR_H2(RTYPE, in2, in3, shift) \
  1774. }
  1775. #define SRAR_H4_UH(...) SRAR_H4(v8u16, __VA_ARGS__)
  1776. #define SRAR_H4_SH(...) SRAR_H4(v8i16, __VA_ARGS__)
  1777. /* Description : Shift right arithmetic rounded words
  1778. Arguments : Inputs - in0, in1, shift
  1779. Outputs - in0, in1, (in place)
  1780. Return Type - as per RTYPE
  1781. Details : Each element of vector 'in0' is shifted right arithmetic by
  1782. number of bits respective element holds in vector 'shift'.
  1783. The last discarded bit is added to shifted value for rounding
  1784. and the result is in place written to 'in0'
  1785. Here, 'shift' is a vector passed in
  1786. Similar for other pairs
  1787. */
  1788. #define SRAR_W2(RTYPE, in0, in1, shift) \
  1789. { \
  1790. in0 = (RTYPE) __msa_srar_w((v4i32) in0, (v4i32) shift); \
  1791. in1 = (RTYPE) __msa_srar_w((v4i32) in1, (v4i32) shift); \
  1792. }
  1793. #define SRAR_W2_SW(...) SRAR_W2(v4i32, __VA_ARGS__)
  1794. #define SRAR_W4(RTYPE, in0, in1, in2, in3, shift) \
  1795. { \
  1796. SRAR_W2(RTYPE, in0, in1, shift) \
  1797. SRAR_W2(RTYPE, in2, in3, shift) \
  1798. }
  1799. #define SRAR_W4_SW(...) SRAR_W4(v4i32, __VA_ARGS__)
  1800. /* Description : Shift right arithmetic rounded (immediate)
  1801. Arguments : Inputs - in0, in1, in2, in3, shift
  1802. Outputs - in0, in1, in2, in3 (in place)
  1803. Return Type - as per RTYPE
  1804. Details : Each element of vector 'in0' is shifted right arithmetic by
  1805. value in 'shift'.
  1806. The last discarded bit is added to shifted value for rounding
  1807. and the result is in place written to 'in0'
  1808. Similar for other pairs
  1809. */
  1810. #define SRARI_H2(RTYPE, in0, in1, shift) \
  1811. { \
  1812. in0 = (RTYPE) __msa_srari_h((v8i16) in0, shift); \
  1813. in1 = (RTYPE) __msa_srari_h((v8i16) in1, shift); \
  1814. }
  1815. #define SRARI_H2_UH(...) SRARI_H2(v8u16, __VA_ARGS__)
  1816. #define SRARI_H2_SH(...) SRARI_H2(v8i16, __VA_ARGS__)
  1817. #define SRARI_H4(RTYPE, in0, in1, in2, in3, shift) \
  1818. { \
  1819. SRARI_H2(RTYPE, in0, in1, shift); \
  1820. SRARI_H2(RTYPE, in2, in3, shift); \
  1821. }
  1822. #define SRARI_H4_UH(...) SRARI_H4(v8u16, __VA_ARGS__)
  1823. #define SRARI_H4_SH(...) SRARI_H4(v8i16, __VA_ARGS__)
  1824. /* Description : Shift right arithmetic rounded (immediate)
  1825. Arguments : Inputs - in0, in1, shift
  1826. Outputs - in0, in1 (in place)
  1827. Return Type - as per RTYPE
  1828. Details : Each element of vector 'in0' is shifted right arithmetic by
  1829. value in 'shift'.
  1830. The last discarded bit is added to shifted value for rounding
  1831. and the result is in place written to 'in0'
  1832. Similar for other pairs
  1833. */
  1834. #define SRARI_W2(RTYPE, in0, in1, shift) \
  1835. { \
  1836. in0 = (RTYPE) __msa_srari_w((v4i32) in0, shift); \
  1837. in1 = (RTYPE) __msa_srari_w((v4i32) in1, shift); \
  1838. }
  1839. #define SRARI_W2_SW(...) SRARI_W2(v4i32, __VA_ARGS__)
  1840. #define SRARI_W4(RTYPE, in0, in1, in2, in3, shift) \
  1841. { \
  1842. SRARI_W2(RTYPE, in0, in1, shift); \
  1843. SRARI_W2(RTYPE, in2, in3, shift); \
  1844. }
  1845. #define SRARI_W4_SH(...) SRARI_W4(v8i16, __VA_ARGS__)
  1846. #define SRARI_W4_SW(...) SRARI_W4(v4i32, __VA_ARGS__)
  1847. /* Description : Multiplication of pairs of vectors
  1848. Arguments : Inputs - in0, in1, in2, in3
  1849. Outputs - out0, out1
  1850. Details : Each element from 'in0' is multiplied with elements from 'in1'
  1851. and result is written to 'out0'
  1852. Similar for other pairs
  1853. */
  1854. #define MUL2(in0, in1, in2, in3, out0, out1) \
  1855. { \
  1856. out0 = in0 * in1; \
  1857. out1 = in2 * in3; \
  1858. }
  1859. #define MUL4(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, out3) \
  1860. { \
  1861. MUL2(in0, in1, in2, in3, out0, out1); \
  1862. MUL2(in4, in5, in6, in7, out2, out3); \
  1863. }
  1864. /* Description : Addition of 2 pairs of vectors
  1865. Arguments : Inputs - in0, in1, in2, in3
  1866. Outputs - out0, out1
  1867. Details : Each element from 2 pairs vectors is added and 2 results are
  1868. produced
  1869. */
  1870. #define ADD2(in0, in1, in2, in3, out0, out1) \
  1871. { \
  1872. out0 = in0 + in1; \
  1873. out1 = in2 + in3; \
  1874. }
  1875. #define ADD4(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, out3) \
  1876. { \
  1877. ADD2(in0, in1, in2, in3, out0, out1); \
  1878. ADD2(in4, in5, in6, in7, out2, out3); \
  1879. }
  1880. /* Description : Subtraction of 2 pairs of vectors
  1881. Arguments : Inputs - in0, in1, in2, in3
  1882. Outputs - out0, out1
  1883. Details : Each element from 2 pairs vectors is subtracted and 2 results
  1884. are produced
  1885. */
  1886. #define SUB2(in0, in1, in2, in3, out0, out1) \
  1887. { \
  1888. out0 = in0 - in1; \
  1889. out1 = in2 - in3; \
  1890. }
  1891. /* Description : Sign extend halfword elements from right half of the vector
  1892. Arguments : Inputs - in (input halfword vector)
  1893. Outputs - out (sign extended word vectors)
  1894. Return Type - signed word
  1895. Details : Sign bit of halfword elements from input vector 'in' is
  1896. extracted and interleaved with same vector 'in0' to generate
  1897. 4 word elements keeping sign intact
  1898. */
  1899. #define UNPCK_R_SH_SW(in, out) \
  1900. { \
  1901. v8i16 sign_m; \
  1902. \
  1903. sign_m = __msa_clti_s_h((v8i16) in, 0); \
  1904. out = (v4i32) __msa_ilvr_h(sign_m, (v8i16) in); \
  1905. }
  1906. /* Description : Sign extend byte elements from input vector and return
  1907. halfword results in pair of vectors
  1908. Arguments : Inputs - in (1 input byte vector)
  1909. Outputs - out0, out1 (sign extended 2 halfword vectors)
  1910. Return Type - signed halfword
  1911. Details : Sign bit of byte elements from input vector 'in' is
  1912. extracted and interleaved right with same vector 'in0' to
  1913. generate 8 signed halfword elements in 'out0'
  1914. Then interleaved left with same vector 'in0' to
  1915. generate 8 signed halfword elements in 'out1'
  1916. */
  1917. #define UNPCK_SB_SH(in, out0, out1) \
  1918. { \
  1919. v16i8 tmp_m; \
  1920. \
  1921. tmp_m = __msa_clti_s_b((v16i8) in, 0); \
  1922. ILVRL_B2_SH(tmp_m, in, out0, out1); \
  1923. }
  1924. /* Description : Zero extend unsigned byte elements to halfword elements
  1925. Arguments : Inputs - in (1 input unsigned byte vector)
  1926. Outputs - out0, out1 (unsigned 2 halfword vectors)
  1927. Return Type - signed halfword
  1928. Details : Zero extended right half of vector is returned in 'out0'
  1929. Zero extended left half of vector is returned in 'out1'
  1930. */
  1931. #define UNPCK_UB_SH(in, out0, out1) \
  1932. { \
  1933. v16i8 zero_m = { 0 }; \
  1934. \
  1935. ILVRL_B2_SH(zero_m, in, out0, out1); \
  1936. }
  1937. /* Description : Sign extend halfword elements from input vector and return
  1938. result in pair of vectors
  1939. Arguments : Inputs - in (1 input halfword vector)
  1940. Outputs - out0, out1 (sign extended 2 word vectors)
  1941. Return Type - signed word
  1942. Details : Sign bit of halfword elements from input vector 'in' is
  1943. extracted and interleaved right with same vector 'in0' to
  1944. generate 4 signed word elements in 'out0'
  1945. Then interleaved left with same vector 'in0' to
  1946. generate 4 signed word elements in 'out1'
  1947. */
  1948. #define UNPCK_SH_SW(in, out0, out1) \
  1949. { \
  1950. v8i16 tmp_m; \
  1951. \
  1952. tmp_m = __msa_clti_s_h((v8i16) in, 0); \
  1953. ILVRL_H2_SW(tmp_m, in, out0, out1); \
  1954. }
  1955. /* Description : Swap two variables
  1956. Arguments : Inputs - in0, in1
  1957. Outputs - in0, in1 (in-place)
  1958. Details : Swapping of two input variables using xor
  1959. */
  1960. #define SWAP(in0, in1) \
  1961. { \
  1962. in0 = in0 ^ in1; \
  1963. in1 = in0 ^ in1; \
  1964. in0 = in0 ^ in1; \
  1965. }
  1966. /* Description : Butterfly of 4 input vectors
  1967. Arguments : Inputs - in0, in1, in2, in3
  1968. Outputs - out0, out1, out2, out3
  1969. Details : Butterfly operation
  1970. */
  1971. #define BUTTERFLY_4(in0, in1, in2, in3, out0, out1, out2, out3) \
  1972. { \
  1973. out0 = in0 + in3; \
  1974. out1 = in1 + in2; \
  1975. \
  1976. out2 = in1 - in2; \
  1977. out3 = in0 - in3; \
  1978. }
  1979. /* Description : Butterfly of 8 input vectors
  1980. Arguments : Inputs - in0 ... in7
  1981. Outputs - out0 .. out7
  1982. Details : Butterfly operation
  1983. */
  1984. #define BUTTERFLY_8(in0, in1, in2, in3, in4, in5, in6, in7, \
  1985. out0, out1, out2, out3, out4, out5, out6, out7) \
  1986. { \
  1987. out0 = in0 + in7; \
  1988. out1 = in1 + in6; \
  1989. out2 = in2 + in5; \
  1990. out3 = in3 + in4; \
  1991. \
  1992. out4 = in3 - in4; \
  1993. out5 = in2 - in5; \
  1994. out6 = in1 - in6; \
  1995. out7 = in0 - in7; \
  1996. }
  1997. /* Description : Transposes input 4x4 byte block
  1998. Arguments : Inputs - in0, in1, in2, in3 (input 4x4 byte block)
  1999. Outputs - out0, out1, out2, out3 (output 4x4 byte block)
  2000. Return Type - unsigned byte
  2001. Details :
  2002. */
  2003. #define TRANSPOSE4x4_UB_UB(in0, in1, in2, in3, out0, out1, out2, out3) \
  2004. { \
  2005. v16i8 zero_m = { 0 }; \
  2006. v16i8 s0_m, s1_m, s2_m, s3_m; \
  2007. \
  2008. ILVR_D2_SB(in1, in0, in3, in2, s0_m, s1_m); \
  2009. ILVRL_B2_SB(s1_m, s0_m, s2_m, s3_m); \
  2010. \
  2011. out0 = (v16u8) __msa_ilvr_b(s3_m, s2_m); \
  2012. out1 = (v16u8) __msa_sldi_b(zero_m, (v16i8) out0, 4); \
  2013. out2 = (v16u8) __msa_sldi_b(zero_m, (v16i8) out1, 4); \
  2014. out3 = (v16u8) __msa_sldi_b(zero_m, (v16i8) out2, 4); \
  2015. }
  2016. /* Description : Transposes input 8x4 byte block into 4x8
  2017. Arguments : Inputs - in0, in1, in2, in3 (input 8x4 byte block)
  2018. Outputs - out0, out1, out2, out3 (output 4x8 byte block)
  2019. Return Type - unsigned byte
  2020. Details :
  2021. */
  2022. #define TRANSPOSE8x4_UB(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  2023. out0, out1, out2, out3) \
  2024. { \
  2025. v16i8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2026. \
  2027. ILVEV_W2_SB(in0, in4, in1, in5, tmp0_m, tmp1_m); \
  2028. tmp2_m = __msa_ilvr_b(tmp1_m, tmp0_m); \
  2029. ILVEV_W2_SB(in2, in6, in3, in7, tmp0_m, tmp1_m); \
  2030. \
  2031. tmp3_m = __msa_ilvr_b(tmp1_m, tmp0_m); \
  2032. ILVRL_H2_SB(tmp3_m, tmp2_m, tmp0_m, tmp1_m); \
  2033. \
  2034. ILVRL_W2(RTYPE, tmp1_m, tmp0_m, out0, out2); \
  2035. out1 = (RTYPE) __msa_ilvl_d((v2i64) out2, (v2i64) out0); \
  2036. out3 = (RTYPE) __msa_ilvl_d((v2i64) out0, (v2i64) out2); \
  2037. }
  2038. #define TRANSPOSE8x4_UB_UB(...) TRANSPOSE8x4_UB(v16u8, __VA_ARGS__)
  2039. #define TRANSPOSE8x4_UB_UH(...) TRANSPOSE8x4_UB(v8u16, __VA_ARGS__)
  2040. /* Description : Transposes input 8x8 byte block
  2041. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  2042. (input 8x8 byte block)
  2043. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  2044. (output 8x8 byte block)
  2045. Return Type - unsigned byte
  2046. Details :
  2047. */
  2048. #define TRANSPOSE8x8_UB(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  2049. out0, out1, out2, out3, out4, out5, out6, out7) \
  2050. { \
  2051. v16i8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2052. v16i8 tmp4_m, tmp5_m, tmp6_m, tmp7_m; \
  2053. \
  2054. ILVR_B4_SB(in2, in0, in3, in1, in6, in4, in7, in5, \
  2055. tmp0_m, tmp1_m, tmp2_m, tmp3_m); \
  2056. ILVRL_B2_SB(tmp1_m, tmp0_m, tmp4_m, tmp5_m); \
  2057. ILVRL_B2_SB(tmp3_m, tmp2_m, tmp6_m, tmp7_m); \
  2058. ILVRL_W2(RTYPE, tmp6_m, tmp4_m, out0, out2); \
  2059. ILVRL_W2(RTYPE, tmp7_m, tmp5_m, out4, out6); \
  2060. SLDI_B2_0(RTYPE, out0, out2, out1, out3, 8); \
  2061. SLDI_B2_0(RTYPE, out4, out6, out5, out7, 8); \
  2062. }
  2063. #define TRANSPOSE8x8_UB_UB(...) TRANSPOSE8x8_UB(v16u8, __VA_ARGS__)
  2064. #define TRANSPOSE8x8_UB_UH(...) TRANSPOSE8x8_UB(v8u16, __VA_ARGS__)
  2065. /* Description : Transposes 16x8 block into 8x16 with byte elements in vectors
  2066. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7,
  2067. in8, in9, in10, in11, in12, in13, in14, in15
  2068. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  2069. Return Type - unsigned byte
  2070. Details :
  2071. */
  2072. #define TRANSPOSE16x8_UB_UB(in0, in1, in2, in3, in4, in5, in6, in7, \
  2073. in8, in9, in10, in11, in12, in13, in14, in15, \
  2074. out0, out1, out2, out3, out4, out5, out6, out7) \
  2075. { \
  2076. v16u8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2077. v16u8 tmp4_m, tmp5_m, tmp6_m, tmp7_m; \
  2078. \
  2079. ILVEV_D2_UB(in0, in8, in1, in9, out7, out6); \
  2080. ILVEV_D2_UB(in2, in10, in3, in11, out5, out4); \
  2081. ILVEV_D2_UB(in4, in12, in5, in13, out3, out2); \
  2082. ILVEV_D2_UB(in6, in14, in7, in15, out1, out0); \
  2083. \
  2084. tmp0_m = (v16u8) __msa_ilvev_b((v16i8) out6, (v16i8) out7); \
  2085. tmp4_m = (v16u8) __msa_ilvod_b((v16i8) out6, (v16i8) out7); \
  2086. tmp1_m = (v16u8) __msa_ilvev_b((v16i8) out4, (v16i8) out5); \
  2087. tmp5_m = (v16u8) __msa_ilvod_b((v16i8) out4, (v16i8) out5); \
  2088. out5 = (v16u8) __msa_ilvev_b((v16i8) out2, (v16i8) out3); \
  2089. tmp6_m = (v16u8) __msa_ilvod_b((v16i8) out2, (v16i8) out3); \
  2090. out7 = (v16u8) __msa_ilvev_b((v16i8) out0, (v16i8) out1); \
  2091. tmp7_m = (v16u8) __msa_ilvod_b((v16i8) out0, (v16i8) out1); \
  2092. \
  2093. ILVEV_H2_UB(tmp0_m, tmp1_m, out5, out7, tmp2_m, tmp3_m); \
  2094. out0 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2095. out4 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2096. \
  2097. tmp2_m = (v16u8) __msa_ilvod_h((v8i16) tmp1_m, (v8i16) tmp0_m); \
  2098. tmp3_m = (v16u8) __msa_ilvod_h((v8i16) out7, (v8i16) out5); \
  2099. out2 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2100. out6 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2101. \
  2102. ILVEV_H2_UB(tmp4_m, tmp5_m, tmp6_m, tmp7_m, tmp2_m, tmp3_m); \
  2103. out1 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2104. out5 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2105. \
  2106. tmp2_m = (v16u8) __msa_ilvod_h((v8i16) tmp5_m, (v8i16) tmp4_m); \
  2107. tmp2_m = (v16u8) __msa_ilvod_h((v8i16) tmp5_m, (v8i16) tmp4_m); \
  2108. tmp3_m = (v16u8) __msa_ilvod_h((v8i16) tmp7_m, (v8i16) tmp6_m); \
  2109. tmp3_m = (v16u8) __msa_ilvod_h((v8i16) tmp7_m, (v8i16) tmp6_m); \
  2110. out3 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2111. out7 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2112. }
  2113. /* Description : Transposes 4x4 block with half word elements in vectors
  2114. Arguments : Inputs - in0, in1, in2, in3
  2115. Outputs - out0, out1, out2, out3
  2116. Return Type - signed halfword
  2117. Details :
  2118. */
  2119. #define TRANSPOSE4x4_SH_SH(in0, in1, in2, in3, out0, out1, out2, out3) \
  2120. { \
  2121. v8i16 s0_m, s1_m; \
  2122. \
  2123. ILVR_H2_SH(in1, in0, in3, in2, s0_m, s1_m); \
  2124. ILVRL_W2_SH(s1_m, s0_m, out0, out2); \
  2125. out1 = (v8i16) __msa_ilvl_d((v2i64) out0, (v2i64) out0); \
  2126. out3 = (v8i16) __msa_ilvl_d((v2i64) out0, (v2i64) out2); \
  2127. }
  2128. /* Description : Transposes 8x8 block with half word elements in vectors
  2129. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  2130. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  2131. Return Type - signed halfword
  2132. Details :
  2133. */
  2134. #define TRANSPOSE8x8_H(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  2135. out0, out1, out2, out3, out4, out5, out6, out7) \
  2136. { \
  2137. v8i16 s0_m, s1_m; \
  2138. v8i16 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2139. v8i16 tmp4_m, tmp5_m, tmp6_m, tmp7_m; \
  2140. \
  2141. ILVR_H2_SH(in6, in4, in7, in5, s0_m, s1_m); \
  2142. ILVRL_H2_SH(s1_m, s0_m, tmp0_m, tmp1_m); \
  2143. ILVL_H2_SH(in6, in4, in7, in5, s0_m, s1_m); \
  2144. ILVRL_H2_SH(s1_m, s0_m, tmp2_m, tmp3_m); \
  2145. ILVR_H2_SH(in2, in0, in3, in1, s0_m, s1_m); \
  2146. ILVRL_H2_SH(s1_m, s0_m, tmp4_m, tmp5_m); \
  2147. ILVL_H2_SH(in2, in0, in3, in1, s0_m, s1_m); \
  2148. ILVRL_H2_SH(s1_m, s0_m, tmp6_m, tmp7_m); \
  2149. PCKEV_D4(RTYPE, tmp0_m, tmp4_m, tmp1_m, tmp5_m, tmp2_m, tmp6_m, \
  2150. tmp3_m, tmp7_m, out0, out2, out4, out6); \
  2151. out1 = (RTYPE) __msa_pckod_d((v2i64) tmp0_m, (v2i64) tmp4_m); \
  2152. out3 = (RTYPE) __msa_pckod_d((v2i64) tmp1_m, (v2i64) tmp5_m); \
  2153. out5 = (RTYPE) __msa_pckod_d((v2i64) tmp2_m, (v2i64) tmp6_m); \
  2154. out7 = (RTYPE) __msa_pckod_d((v2i64) tmp3_m, (v2i64) tmp7_m); \
  2155. }
  2156. #define TRANSPOSE8x8_UH_UH(...) TRANSPOSE8x8_H(v8u16, __VA_ARGS__)
  2157. #define TRANSPOSE8x8_SH_SH(...) TRANSPOSE8x8_H(v8i16, __VA_ARGS__)
  2158. /* Description : Transposes 4x4 block with word elements in vectors
  2159. Arguments : Inputs - in0, in1, in2, in3
  2160. Outputs - out0, out1, out2, out3
  2161. Return Type - signed word
  2162. Details :
  2163. */
  2164. #define TRANSPOSE4x4_SW_SW(in0, in1, in2, in3, out0, out1, out2, out3) \
  2165. { \
  2166. v4i32 s0_m, s1_m, s2_m, s3_m; \
  2167. \
  2168. ILVRL_W2_SW(in1, in0, s0_m, s1_m); \
  2169. ILVRL_W2_SW(in3, in2, s2_m, s3_m); \
  2170. \
  2171. out0 = (v4i32) __msa_ilvr_d((v2i64) s2_m, (v2i64) s0_m); \
  2172. out1 = (v4i32) __msa_ilvl_d((v2i64) s2_m, (v2i64) s0_m); \
  2173. out2 = (v4i32) __msa_ilvr_d((v2i64) s3_m, (v2i64) s1_m); \
  2174. out3 = (v4i32) __msa_ilvl_d((v2i64) s3_m, (v2i64) s1_m); \
  2175. }
  2176. /* Description : Add block 4x4
  2177. Arguments : Inputs - in0, in1, in2, in3, pdst, stride
  2178. Outputs -
  2179. Return Type - unsigned bytes
  2180. Details : Least significant 4 bytes from each input vector are added to
  2181. the destination bytes, clipped between 0-255 and then stored.
  2182. */
  2183. #define ADDBLK_ST4x4_UB(in0, in1, in2, in3, pdst, stride) \
  2184. { \
  2185. uint32_t src0_m, src1_m, src2_m, src3_m; \
  2186. uint32_t out0_m, out1_m, out2_m, out3_m; \
  2187. v8i16 inp0_m, inp1_m, res0_m, res1_m; \
  2188. v16i8 dst0_m = { 0 }; \
  2189. v16i8 dst1_m = { 0 }; \
  2190. v16i8 zero_m = { 0 }; \
  2191. \
  2192. ILVR_D2_SH(in1, in0, in3, in2, inp0_m, inp1_m) \
  2193. LW4(pdst, stride, src0_m, src1_m, src2_m, src3_m); \
  2194. INSERT_W2_SB(src0_m, src1_m, dst0_m); \
  2195. INSERT_W2_SB(src2_m, src3_m, dst1_m); \
  2196. ILVR_B2_SH(zero_m, dst0_m, zero_m, dst1_m, res0_m, res1_m); \
  2197. ADD2(res0_m, inp0_m, res1_m, inp1_m, res0_m, res1_m); \
  2198. CLIP_SH2_0_255(res0_m, res1_m); \
  2199. PCKEV_B2_SB(res0_m, res0_m, res1_m, res1_m, dst0_m, dst1_m); \
  2200. \
  2201. out0_m = __msa_copy_u_w((v4i32) dst0_m, 0); \
  2202. out1_m = __msa_copy_u_w((v4i32) dst0_m, 1); \
  2203. out2_m = __msa_copy_u_w((v4i32) dst1_m, 0); \
  2204. out3_m = __msa_copy_u_w((v4i32) dst1_m, 1); \
  2205. SW4(out0_m, out1_m, out2_m, out3_m, pdst, stride); \
  2206. }
  2207. /* Description : Pack even elements of input vectors & xor with 128
  2208. Arguments : Inputs - in0, in1
  2209. Outputs - out_m
  2210. Return Type - unsigned byte
  2211. Details : Signed byte even elements from 'in0' and 'in1' are packed
  2212. together in one vector and the resulted vector is xor'ed with
  2213. 128 to shift the range from signed to unsigned byte
  2214. */
  2215. #define PCKEV_XORI128_UB(in0, in1) \
  2216. ( { \
  2217. v16u8 out_m; \
  2218. out_m = (v16u8) __msa_pckev_b((v16i8) in1, (v16i8) in0); \
  2219. out_m = (v16u8) __msa_xori_b((v16u8) out_m, 128); \
  2220. out_m; \
  2221. } )
  2222. /* Description : Pack even byte elements, extract 0 & 2 index words from pair
  2223. of results and store 4 words in destination memory as per
  2224. stride
  2225. Arguments : Inputs - in0, in1, in2, in3, pdst, stride
  2226. */
  2227. #define PCKEV_ST4x4_UB(in0, in1, in2, in3, pdst, stride) \
  2228. { \
  2229. uint32_t out0_m, out1_m, out2_m, out3_m; \
  2230. v16i8 tmp0_m, tmp1_m; \
  2231. \
  2232. PCKEV_B2_SB(in1, in0, in3, in2, tmp0_m, tmp1_m); \
  2233. \
  2234. out0_m = __msa_copy_u_w((v4i32) tmp0_m, 0); \
  2235. out1_m = __msa_copy_u_w((v4i32) tmp0_m, 2); \
  2236. out2_m = __msa_copy_u_w((v4i32) tmp1_m, 0); \
  2237. out3_m = __msa_copy_u_w((v4i32) tmp1_m, 2); \
  2238. \
  2239. SW4(out0_m, out1_m, out2_m, out3_m, pdst, stride); \
  2240. }
  2241. /* Description : Pack even byte elements and store byte vector in destination
  2242. memory
  2243. Arguments : Inputs - in0, in1, pdst
  2244. */
  2245. #define PCKEV_ST_SB(in0, in1, pdst) \
  2246. { \
  2247. v16i8 tmp_m; \
  2248. tmp_m = __msa_pckev_b((v16i8) in1, (v16i8) in0); \
  2249. ST_SB(tmp_m, (pdst)); \
  2250. }
  2251. #endif /* AVUTIL_MIPS_GENERIC_MACROS_MSA_H */