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.

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