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.

2960 lines
147KB

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