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.

1782 lines
86KB

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