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.

2542 lines
123KB

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