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.

2859 lines
141KB

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