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.

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