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.

2322 lines
112KB

  1. /*
  2. * Copyright (c) 2015 Manojkumar Bhosale (Manojkumar.Bhosale@imgtec.com)
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVUTIL_MIPS_GENERIC_MACROS_MSA_H
  21. #define AVUTIL_MIPS_GENERIC_MACROS_MSA_H
  22. #include <stdint.h>
  23. #include <msa.h>
  24. #define LD_B(RTYPE, psrc) *((RTYPE *)(psrc))
  25. #define LD_UB(...) LD_B(v16u8, __VA_ARGS__)
  26. #define LD_SB(...) LD_B(v16i8, __VA_ARGS__)
  27. #define LD_H(RTYPE, psrc) *((RTYPE *)(psrc))
  28. #define LD_UH(...) LD_H(v8u16, __VA_ARGS__)
  29. #define LD_SH(...) LD_H(v8i16, __VA_ARGS__)
  30. #define LD_W(RTYPE, psrc) *((RTYPE *)(psrc))
  31. #define LD_UW(...) LD_W(v4u32, __VA_ARGS__)
  32. #define LD_SW(...) LD_W(v4i32, __VA_ARGS__)
  33. #define ST_B(RTYPE, in, pdst) *((RTYPE *)(pdst)) = (in)
  34. #define ST_UB(...) ST_B(v16u8, __VA_ARGS__)
  35. #define ST_SB(...) ST_B(v16i8, __VA_ARGS__)
  36. #define ST_H(RTYPE, in, pdst) *((RTYPE *)(pdst)) = (in)
  37. #define ST_UH(...) ST_H(v8u16, __VA_ARGS__)
  38. #define ST_SH(...) ST_H(v8i16, __VA_ARGS__)
  39. #define ST_W(RTYPE, in, pdst) *((RTYPE *)(pdst)) = (in)
  40. #define ST_UW(...) ST_W(v4u32, __VA_ARGS__)
  41. #define ST_SW(...) ST_W(v4i32, __VA_ARGS__)
  42. #if (__mips_isa_rev >= 6)
  43. #define LW(psrc) \
  44. ( { \
  45. uint8_t *psrc_m = (uint8_t *) (psrc); \
  46. uint32_t val_m; \
  47. \
  48. __asm__ volatile ( \
  49. "lw %[val_m], %[psrc_m] \n\t" \
  50. \
  51. : [val_m] "=r" (val_m) \
  52. : [psrc_m] "m" (*psrc_m) \
  53. ); \
  54. \
  55. val_m; \
  56. } )
  57. #if (__mips == 64)
  58. #define LD(psrc) \
  59. ( { \
  60. uint8_t *psrc_m = (uint8_t *) (psrc); \
  61. uint64_t val_m = 0; \
  62. \
  63. __asm__ volatile ( \
  64. "ld %[val_m], %[psrc_m] \n\t" \
  65. \
  66. : [val_m] "=r" (val_m) \
  67. : [psrc_m] "m" (*psrc_m) \
  68. ); \
  69. \
  70. val_m; \
  71. } )
  72. #else // !(__mips == 64)
  73. #define LD(psrc) \
  74. ( { \
  75. uint8_t *psrc_m = (uint8_t *) (psrc); \
  76. uint32_t val0_m, val1_m; \
  77. uint64_t val_m = 0; \
  78. \
  79. val0_m = LW(psrc_m); \
  80. val1_m = LW(psrc_m + 4); \
  81. \
  82. val_m = (uint64_t) (val1_m); \
  83. val_m = (uint64_t) ((val_m << 32) & 0xFFFFFFFF00000000); \
  84. val_m = (uint64_t) (val_m | (uint64_t) val0_m); \
  85. \
  86. val_m; \
  87. } )
  88. #endif // (__mips == 64)
  89. #define SH(val, pdst) \
  90. { \
  91. uint8_t *pdst_m = (uint8_t *) (pdst); \
  92. uint16_t val_m = (val); \
  93. \
  94. __asm__ volatile ( \
  95. "sh %[val_m], %[pdst_m] \n\t" \
  96. \
  97. : [pdst_m] "=m" (*pdst_m) \
  98. : [val_m] "r" (val_m) \
  99. ); \
  100. }
  101. #define SW(val, pdst) \
  102. { \
  103. uint8_t *pdst_m = (uint8_t *) (pdst); \
  104. uint32_t val_m = (val); \
  105. \
  106. __asm__ volatile ( \
  107. "sw %[val_m], %[pdst_m] \n\t" \
  108. \
  109. : [pdst_m] "=m" (*pdst_m) \
  110. : [val_m] "r" (val_m) \
  111. ); \
  112. }
  113. #define SD(val, pdst) \
  114. { \
  115. uint8_t *pdst_m = (uint8_t *) (pdst); \
  116. uint64_t val_m = (val); \
  117. \
  118. __asm__ volatile ( \
  119. "sd %[val_m], %[pdst_m] \n\t" \
  120. \
  121. : [pdst_m] "=m" (*pdst_m) \
  122. : [val_m] "r" (val_m) \
  123. ); \
  124. }
  125. #else // !(__mips_isa_rev >= 6)
  126. #define LW(psrc) \
  127. ( { \
  128. uint8_t *psrc_m = (uint8_t *) (psrc); \
  129. uint32_t val_m; \
  130. \
  131. __asm__ volatile ( \
  132. "ulw %[val_m], %[psrc_m] \n\t" \
  133. \
  134. : [val_m] "=r" (val_m) \
  135. : [psrc_m] "m" (*psrc_m) \
  136. ); \
  137. \
  138. val_m; \
  139. } )
  140. #if (__mips == 64)
  141. #define LD(psrc) \
  142. ( { \
  143. uint8_t *psrc_m = (uint8_t *) (psrc); \
  144. uint64_t val_m = 0; \
  145. \
  146. __asm__ volatile ( \
  147. "uld %[val_m], %[psrc_m] \n\t" \
  148. \
  149. : [val_m] "=r" (val_m) \
  150. : [psrc_m] "m" (*psrc_m) \
  151. ); \
  152. \
  153. val_m; \
  154. } )
  155. #else // !(__mips == 64)
  156. #define LD(psrc) \
  157. ( { \
  158. uint8_t *psrc_m1 = (uint8_t *) (psrc); \
  159. uint32_t val0_m, val1_m; \
  160. uint64_t val_m = 0; \
  161. \
  162. val0_m = LW(psrc_m1); \
  163. val1_m = LW(psrc_m1 + 4); \
  164. \
  165. val_m = (uint64_t) (val1_m); \
  166. val_m = (uint64_t) ((val_m << 32) & 0xFFFFFFFF00000000); \
  167. val_m = (uint64_t) (val_m | (uint64_t) val0_m); \
  168. \
  169. val_m; \
  170. } )
  171. #endif // (__mips == 64)
  172. #define SH(val, pdst) \
  173. { \
  174. uint8_t *pdst_m = (uint8_t *) (pdst); \
  175. uint16_t val_m = (val); \
  176. \
  177. __asm__ volatile ( \
  178. "ush %[val_m], %[pdst_m] \n\t" \
  179. \
  180. : [pdst_m] "=m" (*pdst_m) \
  181. : [val_m] "r" (val_m) \
  182. ); \
  183. }
  184. #define SW(val, pdst) \
  185. { \
  186. uint8_t *pdst_m = (uint8_t *) (pdst); \
  187. uint32_t val_m = (val); \
  188. \
  189. __asm__ volatile ( \
  190. "usw %[val_m], %[pdst_m] \n\t" \
  191. \
  192. : [pdst_m] "=m" (*pdst_m) \
  193. : [val_m] "r" (val_m) \
  194. ); \
  195. }
  196. #define SD(val, pdst) \
  197. { \
  198. uint8_t *pdst_m1 = (uint8_t *) (pdst); \
  199. uint32_t val0_m, val1_m; \
  200. \
  201. val0_m = (uint32_t) ((val) & 0x00000000FFFFFFFF); \
  202. val1_m = (uint32_t) (((val) >> 32) & 0x00000000FFFFFFFF); \
  203. \
  204. SW(val0_m, pdst_m1); \
  205. SW(val1_m, pdst_m1 + 4); \
  206. }
  207. #endif // (__mips_isa_rev >= 6)
  208. /* Description : Load 4 words with stride
  209. Arguments : Inputs - psrc (source pointer to load from)
  210. - stride
  211. Outputs - out0, out1, out2, out3
  212. Details : Loads word in 'out0' from (psrc)
  213. Loads word in 'out1' from (psrc + stride)
  214. Loads word in 'out2' from (psrc + 2 * stride)
  215. Loads word in 'out3' from (psrc + 3 * stride)
  216. */
  217. #define LW4(psrc, stride, out0, out1, out2, out3) \
  218. { \
  219. out0 = LW((psrc)); \
  220. out1 = LW((psrc) + stride); \
  221. out2 = LW((psrc) + 2 * stride); \
  222. out3 = LW((psrc) + 3 * stride); \
  223. }
  224. /* Description : Load double words with stride
  225. Arguments : Inputs - psrc (source pointer to load from)
  226. - stride
  227. Outputs - out0, out1
  228. Details : Loads double word in 'out0' from (psrc)
  229. Loads double word in 'out1' from (psrc + stride)
  230. */
  231. #define LD2(psrc, stride, out0, out1) \
  232. { \
  233. out0 = LD((psrc)); \
  234. out1 = LD((psrc) + stride); \
  235. }
  236. #define LD4(psrc, stride, out0, out1, out2, out3) \
  237. { \
  238. LD2((psrc), stride, out0, out1); \
  239. LD2((psrc) + 2 * stride, stride, out2, out3); \
  240. }
  241. /* Description : Store 4 words with stride
  242. Arguments : Inputs - in0, in1, in2, in3, pdst, stride
  243. Details : Stores word from 'in0' to (pdst)
  244. Stores word from 'in1' to (pdst + stride)
  245. Stores word from 'in2' to (pdst + 2 * stride)
  246. Stores word from 'in3' to (pdst + 3 * stride)
  247. */
  248. #define SW4(in0, in1, in2, in3, pdst, stride) \
  249. { \
  250. SW(in0, (pdst)) \
  251. SW(in1, (pdst) + stride); \
  252. SW(in2, (pdst) + 2 * stride); \
  253. SW(in3, (pdst) + 3 * stride); \
  254. }
  255. /* Description : Store 4 double words with stride
  256. Arguments : Inputs - in0, in1, in2, in3, pdst, stride
  257. Details : Stores double word from 'in0' to (pdst)
  258. Stores double word from 'in1' to (pdst + stride)
  259. Stores double word from 'in2' to (pdst + 2 * stride)
  260. Stores double word from 'in3' to (pdst + 3 * stride)
  261. */
  262. #define SD4(in0, in1, in2, in3, pdst, stride) \
  263. { \
  264. SD(in0, (pdst)) \
  265. SD(in1, (pdst) + stride); \
  266. SD(in2, (pdst) + 2 * stride); \
  267. SD(in3, (pdst) + 3 * stride); \
  268. }
  269. /* Description : Load vectors with 16 byte elements with stride
  270. Arguments : Inputs - psrc (source pointer to load from)
  271. - stride
  272. Outputs - out0, out1
  273. Return Type - as per RTYPE
  274. Details : Loads 16 byte elements in 'out0' from (psrc)
  275. Loads 16 byte elements in 'out1' from (psrc + stride)
  276. */
  277. #define LD_B2(RTYPE, psrc, stride, out0, out1) \
  278. { \
  279. out0 = LD_B(RTYPE, (psrc)); \
  280. out1 = LD_B(RTYPE, (psrc) + stride); \
  281. }
  282. #define LD_UB2(...) LD_B2(v16u8, __VA_ARGS__)
  283. #define LD_SB2(...) LD_B2(v16i8, __VA_ARGS__)
  284. #define LD_B3(RTYPE, psrc, stride, out0, out1, out2) \
  285. { \
  286. LD_B2(RTYPE, (psrc), stride, out0, out1); \
  287. out2 = LD_B(RTYPE, (psrc) + 2 * stride); \
  288. }
  289. #define LD_UB3(...) LD_B3(v16u8, __VA_ARGS__)
  290. #define LD_SB3(...) LD_B3(v16i8, __VA_ARGS__)
  291. #define LD_B4(RTYPE, psrc, stride, out0, out1, out2, out3) \
  292. { \
  293. LD_B2(RTYPE, (psrc), stride, out0, out1); \
  294. LD_B2(RTYPE, (psrc) + 2 * stride , stride, out2, out3); \
  295. }
  296. #define LD_UB4(...) LD_B4(v16u8, __VA_ARGS__)
  297. #define LD_SB4(...) LD_B4(v16i8, __VA_ARGS__)
  298. #define LD_B5(RTYPE, psrc, stride, out0, out1, out2, out3, out4) \
  299. { \
  300. LD_B4(RTYPE, (psrc), stride, out0, out1, out2, out3); \
  301. out4 = LD_B(RTYPE, (psrc) + 4 * stride); \
  302. }
  303. #define LD_UB5(...) LD_B5(v16u8, __VA_ARGS__)
  304. #define LD_SB5(...) LD_B5(v16i8, __VA_ARGS__)
  305. #define LD_B6(RTYPE, psrc, stride, out0, out1, out2, out3, out4, out5) \
  306. { \
  307. LD_B4(RTYPE, (psrc), stride, out0, out1, out2, out3); \
  308. LD_B2(RTYPE, (psrc) + 4 * stride, stride, out4, out5); \
  309. }
  310. #define LD_SB6(...) LD_B6(v16i8, __VA_ARGS__)
  311. #define LD_B7(RTYPE, psrc, stride, \
  312. out0, out1, out2, out3, out4, out5, out6) \
  313. { \
  314. LD_B5(RTYPE, (psrc), stride, out0, out1, out2, out3, out4); \
  315. LD_B2(RTYPE, (psrc) + 5 * stride, stride, out5, out6); \
  316. }
  317. #define LD_SB7(...) LD_B7(v16i8, __VA_ARGS__)
  318. #define LD_B8(RTYPE, psrc, stride, \
  319. out0, out1, out2, out3, out4, out5, out6, out7) \
  320. { \
  321. LD_B4(RTYPE, (psrc), stride, out0, out1, out2, out3); \
  322. LD_B4(RTYPE, (psrc) + 4 * stride, stride, out4, out5, out6, out7); \
  323. }
  324. #define LD_UB8(...) LD_B8(v16u8, __VA_ARGS__)
  325. #define LD_SB8(...) LD_B8(v16i8, __VA_ARGS__)
  326. /* Description : Load vectors with 8 halfword elements with stride
  327. Arguments : Inputs - psrc (source pointer to load from)
  328. - stride
  329. Outputs - out0, out1
  330. Details : Loads 8 halfword elements in 'out0' from (psrc)
  331. Loads 8 halfword elements in 'out1' from (psrc + stride)
  332. */
  333. #define LD_H2(RTYPE, psrc, stride, out0, out1) \
  334. { \
  335. out0 = LD_H(RTYPE, (psrc)); \
  336. out1 = LD_H(RTYPE, (psrc) + (stride)); \
  337. }
  338. #define LD_UH2(...) LD_H2(v8u16, __VA_ARGS__)
  339. #define LD_SH2(...) LD_H2(v8i16, __VA_ARGS__)
  340. #define LD_H4(RTYPE, psrc, stride, out0, out1, out2, out3) \
  341. { \
  342. LD_H2(RTYPE, (psrc), stride, out0, out1); \
  343. LD_H2(RTYPE, (psrc) + 2 * stride, stride, out2, out3); \
  344. }
  345. #define LD_UH4(...) LD_H4(v8u16, __VA_ARGS__)
  346. #define LD_SH4(...) LD_H4(v8i16, __VA_ARGS__)
  347. #define LD_H6(RTYPE, psrc, stride, out0, out1, out2, out3, out4, out5) \
  348. { \
  349. LD_H4(RTYPE, (psrc), stride, out0, out1, out2, out3); \
  350. LD_H2(RTYPE, (psrc) + 4 * stride, stride, out4, out5); \
  351. }
  352. #define LD_UH6(...) LD_H6(v8u16, __VA_ARGS__)
  353. #define LD_SH6(...) LD_H6(v8i16, __VA_ARGS__)
  354. #define LD_H8(RTYPE, psrc, stride, \
  355. out0, out1, out2, out3, out4, out5, out6, out7) \
  356. { \
  357. LD_H4(RTYPE, (psrc), stride, out0, out1, out2, out3); \
  358. LD_H4(RTYPE, (psrc) + 4 * stride, stride, out4, out5, out6, out7); \
  359. }
  360. #define LD_UH8(...) LD_H8(v8u16, __VA_ARGS__)
  361. #define LD_SH8(...) LD_H8(v8i16, __VA_ARGS__)
  362. #define LD_H16(RTYPE, psrc, stride, \
  363. out0, out1, out2, out3, out4, out5, out6, out7, \
  364. out8, out9, out10, out11, out12, out13, out14, out15) \
  365. { \
  366. LD_H8(RTYPE, (psrc), stride, \
  367. out0, out1, out2, out3, out4, out5, out6, out7); \
  368. LD_H8(RTYPE, (psrc) + 8 * stride, stride, \
  369. out8, out9, out10, out11, out12, out13, out14, out15); \
  370. }
  371. #define LD_SH16(...) LD_H16(v8i16, __VA_ARGS__)
  372. /* Description : Load 2 vectors of signed word elements with stride
  373. Arguments : Inputs - psrc (source pointer to load from)
  374. - stride
  375. Outputs - out0, out1
  376. Return Type - signed word
  377. */
  378. #define LD_SW2(psrc, stride, out0, out1) \
  379. { \
  380. out0 = LD_SW((psrc)); \
  381. out1 = LD_SW((psrc) + stride); \
  382. }
  383. /* Description : Store vectors of 16 byte elements with stride
  384. Arguments : Inputs - in0, in1, stride
  385. Outputs - pdst (destination pointer to store to)
  386. Details : Stores 16 byte elements from 'in0' to (pdst)
  387. Stores 16 byte elements from 'in1' to (pdst + stride)
  388. */
  389. #define ST_B2(RTYPE, in0, in1, pdst, stride) \
  390. { \
  391. ST_B(RTYPE, in0, (pdst)); \
  392. ST_B(RTYPE, in1, (pdst) + stride); \
  393. }
  394. #define ST_UB2(...) ST_B2(v16u8, __VA_ARGS__)
  395. #define ST_SB2(...) ST_B2(v16i8, __VA_ARGS__)
  396. #define ST_B4(RTYPE, in0, in1, in2, in3, pdst, stride) \
  397. { \
  398. ST_B2(RTYPE, in0, in1, (pdst), stride); \
  399. ST_B2(RTYPE, in2, in3, (pdst) + 2 * stride, stride); \
  400. }
  401. #define ST_UB4(...) ST_B4(v16u8, __VA_ARGS__)
  402. #define ST_SB4(...) ST_B4(v16i8, __VA_ARGS__)
  403. #define ST_B8(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  404. pdst, stride) \
  405. { \
  406. ST_B4(RTYPE, in0, in1, in2, in3, pdst, stride); \
  407. ST_B4(RTYPE, in4, in5, in6, in7, (pdst) + 4 * stride, stride); \
  408. }
  409. #define ST_UB8(...) ST_B8(v16u8, __VA_ARGS__)
  410. /* Description : Store vectors of 8 halfword elements with stride
  411. Arguments : Inputs - in0, in1, stride
  412. Outputs - pdst (destination pointer to store to)
  413. Details : Stores 8 halfword elements from 'in0' to (pdst)
  414. Stores 8 halfword elements from 'in1' to (pdst + stride)
  415. */
  416. #define ST_H2(RTYPE, in0, in1, pdst, stride) \
  417. { \
  418. ST_H(RTYPE, in0, (pdst)); \
  419. ST_H(RTYPE, in1, (pdst) + stride); \
  420. }
  421. #define ST_UH2(...) ST_H2(v8u16, __VA_ARGS__)
  422. #define ST_SH2(...) ST_H2(v8i16, __VA_ARGS__)
  423. #define ST_H4(RTYPE, in0, in1, in2, in3, pdst, stride) \
  424. { \
  425. ST_H2(RTYPE, in0, in1, (pdst), stride); \
  426. ST_H2(RTYPE, in2, in3, (pdst) + 2 * stride, stride); \
  427. }
  428. #define ST_SH4(...) ST_H4(v8i16, __VA_ARGS__)
  429. #define ST_H6(RTYPE, in0, in1, in2, in3, in4, in5, pdst, stride) \
  430. { \
  431. ST_H4(RTYPE, in0, in1, in2, in3, (pdst), stride); \
  432. ST_H2(RTYPE, in4, in5, (pdst) + 4 * stride, stride); \
  433. }
  434. #define ST_SH6(...) ST_H6(v8i16, __VA_ARGS__)
  435. #define ST_H8(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride) \
  436. { \
  437. ST_H4(RTYPE, in0, in1, in2, in3, (pdst), stride); \
  438. ST_H4(RTYPE, in4, in5, in6, in7, (pdst) + 4 * stride, stride); \
  439. }
  440. #define ST_SH8(...) ST_H8(v8i16, __VA_ARGS__)
  441. /* Description : Store vectors of word elements with stride
  442. Arguments : Inputs - in0, in1, stride
  443. Outputs - pdst (destination pointer to store to)
  444. Return Type - signed word
  445. Details : Stores 4 word elements from 'in0' to (pdst)
  446. Stores 4 word elements from 'in1' to (pdst + stride)
  447. */
  448. #define ST_SW2(in0, in1, pdst, stride) \
  449. { \
  450. ST_SW(in0, (pdst)); \
  451. ST_SW(in1, (pdst) + stride); \
  452. }
  453. /* Description : Store as 2x4 byte block to destination memory from input vector
  454. Arguments : Inputs - in, stidx, pdst, stride
  455. Return Type - unsigned byte
  456. Details : Index stidx halfword element from 'in' vector is copied and
  457. stored on first line
  458. Index stidx+1 halfword element from 'in' vector is copied and
  459. stored on second line
  460. Index stidx+2 halfword element from 'in' vector is copied and
  461. stored on third line
  462. Index stidx+3 halfword element from 'in' vector is copied and
  463. stored on fourth line
  464. */
  465. #define ST2x4_UB(in, stidx, pdst, stride) \
  466. { \
  467. uint16_t out0_m, out1_m, out2_m, out3_m; \
  468. uint8_t *pblk_2x4_m = (uint8_t *) (pdst); \
  469. \
  470. out0_m = __msa_copy_u_h((v8i16) in, (stidx)); \
  471. out1_m = __msa_copy_u_h((v8i16) in, (stidx + 1)); \
  472. out2_m = __msa_copy_u_h((v8i16) in, (stidx + 2)); \
  473. out3_m = __msa_copy_u_h((v8i16) in, (stidx + 3)); \
  474. \
  475. SH(out0_m, pblk_2x4_m); \
  476. SH(out1_m, pblk_2x4_m + stride); \
  477. SH(out2_m, pblk_2x4_m + 2 * stride); \
  478. SH(out3_m, pblk_2x4_m + 3 * stride); \
  479. }
  480. /* Description : Store as 4x2 byte block to destination memory from input vector
  481. Arguments : Inputs - in, pdst, stride
  482. Return Type - unsigned byte
  483. Details : Index 0 word element from input vector is copied and stored
  484. on first line
  485. Index 1 word element from input vector is copied and stored
  486. on second line
  487. */
  488. #define ST4x2_UB(in, pdst, stride) \
  489. { \
  490. uint32_t out0_m, out1_m; \
  491. uint8_t *pblk_4x2_m = (uint8_t *) (pdst); \
  492. \
  493. out0_m = __msa_copy_u_w((v4i32) in, 0); \
  494. out1_m = __msa_copy_u_w((v4i32) in, 1); \
  495. \
  496. SW(out0_m, pblk_4x2_m); \
  497. SW(out1_m, pblk_4x2_m + stride); \
  498. }
  499. /* Description : Store as 4x4 byte block to destination memory from input vector
  500. Arguments : Inputs - in0, in1, pdst, stride
  501. Return Type - unsigned byte
  502. Details : Idx0 word element from input vector 'in0' is copied and stored
  503. on first line
  504. Idx1 word element from input vector 'in0' is copied and stored
  505. on second line
  506. Idx2 word element from input vector 'in1' is copied and stored
  507. on third line
  508. Idx3 word element from input vector 'in1' is copied and stored
  509. on fourth line
  510. */
  511. #define ST4x4_UB(in0, in1, idx0, idx1, idx2, idx3, pdst, stride) \
  512. { \
  513. uint32_t out0_m, out1_m, out2_m, out3_m; \
  514. uint8_t *pblk_4x4_m = (uint8_t *) (pdst); \
  515. \
  516. out0_m = __msa_copy_u_w((v4i32) in0, idx0); \
  517. out1_m = __msa_copy_u_w((v4i32) in0, idx1); \
  518. out2_m = __msa_copy_u_w((v4i32) in1, idx2); \
  519. out3_m = __msa_copy_u_w((v4i32) in1, idx3); \
  520. \
  521. SW4(out0_m, out1_m, out2_m, out3_m, pblk_4x4_m, stride); \
  522. }
  523. #define ST4x8_UB(in0, in1, pdst, stride) \
  524. { \
  525. uint8_t *pblk_4x8 = (uint8_t *) (pdst); \
  526. \
  527. ST4x4_UB(in0, in0, 0, 1, 2, 3, pblk_4x8, stride); \
  528. ST4x4_UB(in1, in1, 0, 1, 2, 3, pblk_4x8 + 4 * stride, stride); \
  529. }
  530. /* Description : Store as 6x4 byte block to destination memory from input
  531. vectors
  532. Arguments : Inputs - in0, in1, pdst, stride
  533. Return Type - unsigned byte
  534. Details : Index 0 word element from input vector 'in0' is copied and
  535. stored on first line followed by index 2 halfword element
  536. Index 2 word element from input vector 'in0' is copied and
  537. stored on second line followed by index 2 halfword element
  538. Index 0 word element from input vector 'in1' is copied and
  539. stored on third line followed by index 2 halfword element
  540. Index 2 word element from input vector 'in1' is copied and
  541. stored on fourth line followed by index 2 halfword element
  542. */
  543. #define ST6x4_UB(in0, in1, pdst, stride) \
  544. { \
  545. uint32_t out0_m, out1_m, out2_m, out3_m; \
  546. uint16_t out4_m, out5_m, out6_m, out7_m; \
  547. uint8_t *pblk_6x4_m = (uint8_t *) (pdst); \
  548. \
  549. out0_m = __msa_copy_u_w((v4i32) in0, 0); \
  550. out1_m = __msa_copy_u_w((v4i32) in0, 2); \
  551. out2_m = __msa_copy_u_w((v4i32) in1, 0); \
  552. out3_m = __msa_copy_u_w((v4i32) in1, 2); \
  553. \
  554. out4_m = __msa_copy_u_h((v8i16) in0, 2); \
  555. out5_m = __msa_copy_u_h((v8i16) in0, 6); \
  556. out6_m = __msa_copy_u_h((v8i16) in1, 2); \
  557. out7_m = __msa_copy_u_h((v8i16) in1, 6); \
  558. \
  559. SW(out0_m, pblk_6x4_m); \
  560. SH(out4_m, (pblk_6x4_m + 4)); \
  561. pblk_6x4_m += stride; \
  562. SW(out1_m, pblk_6x4_m); \
  563. SH(out5_m, (pblk_6x4_m + 4)); \
  564. pblk_6x4_m += stride; \
  565. SW(out2_m, pblk_6x4_m); \
  566. SH(out6_m, (pblk_6x4_m + 4)); \
  567. pblk_6x4_m += stride; \
  568. SW(out3_m, pblk_6x4_m); \
  569. SH(out7_m, (pblk_6x4_m + 4)); \
  570. }
  571. /* Description : Store as 8x1 byte block to destination memory from input vector
  572. Arguments : Inputs - in, pdst
  573. Details : Index 0 double word element from input vector 'in' is copied
  574. and stored to destination memory at (pdst)
  575. */
  576. #define ST8x1_UB(in, pdst) \
  577. { \
  578. uint64_t out0_m; \
  579. out0_m = __msa_copy_u_d((v2i64) in, 0); \
  580. SD(out0_m, pdst); \
  581. }
  582. /* Description : Store as 8x2 byte block to destination memory from input vector
  583. Arguments : Inputs - in, pdst, stride
  584. Details : Index 0 double word element from input vector 'in' is copied
  585. and stored to destination memory at (pdst)
  586. Index 1 double word element from input vector 'in' is copied
  587. and stored to destination memory at (pdst + stride)
  588. */
  589. #define ST8x2_UB(in, pdst, stride) \
  590. { \
  591. uint64_t out0_m, out1_m; \
  592. uint8_t *pblk_8x2_m = (uint8_t *) (pdst); \
  593. \
  594. out0_m = __msa_copy_u_d((v2i64) in, 0); \
  595. out1_m = __msa_copy_u_d((v2i64) in, 1); \
  596. \
  597. SD(out0_m, pblk_8x2_m); \
  598. SD(out1_m, pblk_8x2_m + stride); \
  599. }
  600. /* Description : Store as 8x4 byte block to destination memory from input
  601. vectors
  602. Arguments : Inputs - in0, in1, pdst, stride
  603. Details : Index 0 double word element from input vector 'in0' is copied
  604. and stored to destination memory at (pblk_8x4_m)
  605. Index 1 double word element from input vector 'in0' is copied
  606. and stored to destination memory at (pblk_8x4_m + stride)
  607. Index 0 double word element from input vector 'in1' is copied
  608. and stored to destination memory at (pblk_8x4_m + 2 * stride)
  609. Index 1 double word element from input vector 'in1' is copied
  610. and stored to destination memory at (pblk_8x4_m + 3 * stride)
  611. */
  612. #define ST8x4_UB(in0, in1, pdst, stride) \
  613. { \
  614. uint64_t out0_m, out1_m, out2_m, out3_m; \
  615. uint8_t *pblk_8x4_m = (uint8_t *) (pdst); \
  616. \
  617. out0_m = __msa_copy_u_d((v2i64) in0, 0); \
  618. out1_m = __msa_copy_u_d((v2i64) in0, 1); \
  619. out2_m = __msa_copy_u_d((v2i64) in1, 0); \
  620. out3_m = __msa_copy_u_d((v2i64) in1, 1); \
  621. \
  622. SD4(out0_m, out1_m, out2_m, out3_m, pblk_8x4_m, stride); \
  623. }
  624. #define ST8x8_UB(in0, in1, in2, in3, pdst, stride) \
  625. { \
  626. uint8_t *pblk_8x8_m = (uint8_t *) (pdst); \
  627. \
  628. ST8x4_UB(in0, in1, pblk_8x8_m, stride); \
  629. ST8x4_UB(in2, in3, pblk_8x8_m + 4 * stride, stride); \
  630. }
  631. #define ST12x4_UB(in0, in1, in2, pdst, stride) \
  632. { \
  633. uint8_t *pblk_12x4_m = (uint8_t *) (pdst); \
  634. \
  635. /* left 8x4 */ \
  636. ST8x4_UB(in0, in1, pblk_12x4_m, stride); \
  637. /* right 4x4 */ \
  638. ST4x4_UB(in2, in2, 0, 1, 2, 3, pblk_12x4_m + 8, stride); \
  639. }
  640. /* Description : Store as 12x8 byte block to destination memory from
  641. input vectors
  642. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride
  643. Details : Index 0 double word element from input vector 'in0' is copied
  644. and stored to destination memory at (pblk_12x8_m) followed by
  645. index 2 word element from same input vector 'in0' at
  646. (pblk_12x8_m + 8)
  647. Similar to remaining lines
  648. */
  649. #define ST12x8_UB(in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride) \
  650. { \
  651. uint64_t out0_m, out1_m, out2_m, out3_m; \
  652. uint64_t out4_m, out5_m, out6_m, out7_m; \
  653. uint32_t out8_m, out9_m, out10_m, out11_m; \
  654. uint32_t out12_m, out13_m, out14_m, out15_m; \
  655. uint8_t *pblk_12x8_m = (uint8_t *) (pdst); \
  656. \
  657. out0_m = __msa_copy_u_d((v2i64) in0, 0); \
  658. out1_m = __msa_copy_u_d((v2i64) in1, 0); \
  659. out2_m = __msa_copy_u_d((v2i64) in2, 0); \
  660. out3_m = __msa_copy_u_d((v2i64) in3, 0); \
  661. out4_m = __msa_copy_u_d((v2i64) in4, 0); \
  662. out5_m = __msa_copy_u_d((v2i64) in5, 0); \
  663. out6_m = __msa_copy_u_d((v2i64) in6, 0); \
  664. out7_m = __msa_copy_u_d((v2i64) in7, 0); \
  665. \
  666. out8_m = __msa_copy_u_w((v4i32) in0, 2); \
  667. out9_m = __msa_copy_u_w((v4i32) in1, 2); \
  668. out10_m = __msa_copy_u_w((v4i32) in2, 2); \
  669. out11_m = __msa_copy_u_w((v4i32) in3, 2); \
  670. out12_m = __msa_copy_u_w((v4i32) in4, 2); \
  671. out13_m = __msa_copy_u_w((v4i32) in5, 2); \
  672. out14_m = __msa_copy_u_w((v4i32) in6, 2); \
  673. out15_m = __msa_copy_u_w((v4i32) in7, 2); \
  674. \
  675. SD(out0_m, pblk_12x8_m); \
  676. SW(out8_m, pblk_12x8_m + 8); \
  677. pblk_12x8_m += stride; \
  678. SD(out1_m, pblk_12x8_m); \
  679. SW(out9_m, pblk_12x8_m + 8); \
  680. pblk_12x8_m += stride; \
  681. SD(out2_m, pblk_12x8_m); \
  682. SW(out10_m, pblk_12x8_m + 8); \
  683. pblk_12x8_m += stride; \
  684. SD(out3_m, pblk_12x8_m); \
  685. SW(out11_m, pblk_12x8_m + 8); \
  686. pblk_12x8_m += stride; \
  687. SD(out4_m, pblk_12x8_m); \
  688. SW(out12_m, pblk_12x8_m + 8); \
  689. pblk_12x8_m += stride; \
  690. SD(out5_m, pblk_12x8_m); \
  691. SW(out13_m, pblk_12x8_m + 8); \
  692. pblk_12x8_m += stride; \
  693. SD(out6_m, pblk_12x8_m); \
  694. SW(out14_m, pblk_12x8_m + 8); \
  695. pblk_12x8_m += stride; \
  696. SD(out7_m, pblk_12x8_m); \
  697. SW(out15_m, pblk_12x8_m + 8); \
  698. }
  699. /* Description : average with rounding (in0 + in1 + 1) / 2.
  700. Arguments : Inputs - in0, in1, in2, in3,
  701. Outputs - out0, out1
  702. Return Type - signed byte
  703. Details : Each byte element from 'in0' vector is added with each byte
  704. element from 'in1' vector. The addition of the elements plus 1
  705. (for rounding) is done unsigned with full precision,
  706. i.e. the result has one extra bit. Unsigned division by 2
  707. (or logical shift right by one bit) is performed before writing
  708. the result to vector 'out0'
  709. Similar for the pair of 'in2' and 'in3'
  710. */
  711. #define AVER_UB2(RTYPE, in0, in1, in2, in3, out0, out1) \
  712. { \
  713. out0 = (RTYPE) __msa_aver_u_b((v16u8) in0, (v16u8) in1); \
  714. out1 = (RTYPE) __msa_aver_u_b((v16u8) in2, (v16u8) in3); \
  715. }
  716. #define AVER_UB2_UB(...) AVER_UB2(v16u8, __VA_ARGS__)
  717. #define AVER_UB4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  718. out0, out1, out2, out3) \
  719. { \
  720. AVER_UB2(RTYPE, in0, in1, in2, in3, out0, out1) \
  721. AVER_UB2(RTYPE, in4, in5, in6, in7, out2, out3) \
  722. }
  723. #define AVER_UB4_UB(...) AVER_UB4(v16u8, __VA_ARGS__)
  724. /* Description : Immediate number of columns to slide with zero
  725. Arguments : Inputs - in0, in1, slide_val
  726. Outputs - out0, out1
  727. Return Type - as per RTYPE
  728. Details : Byte elements from 'zero_m' vector are slide into 'in0' by
  729. number of elements specified by 'slide_val'
  730. */
  731. #define SLDI_B2_0(RTYPE, in0, in1, out0, out1, slide_val) \
  732. { \
  733. v16i8 zero_m = { 0 }; \
  734. out0 = (RTYPE) __msa_sldi_b((v16i8) zero_m, (v16i8) in0, slide_val); \
  735. out1 = (RTYPE) __msa_sldi_b((v16i8) zero_m, (v16i8) in1, slide_val); \
  736. }
  737. #define SLDI_B2_0_UB(...) SLDI_B2_0(v16u8, __VA_ARGS__)
  738. #define SLDI_B2_0_SB(...) SLDI_B2_0(v16i8, __VA_ARGS__)
  739. #define SLDI_B2_0_SW(...) SLDI_B2_0(v4i32, __VA_ARGS__)
  740. #define SLDI_B4_0(RTYPE, in0, in1, in2, in3, \
  741. out0, out1, out2, out3, slide_val) \
  742. { \
  743. SLDI_B2_0(RTYPE, in0, in1, out0, out1, slide_val); \
  744. SLDI_B2_0(RTYPE, in2, in3, out2, out3, slide_val); \
  745. }
  746. #define SLDI_B4_0_UB(...) SLDI_B4_0(v16u8, __VA_ARGS__)
  747. #define SLDI_B4_0_SB(...) SLDI_B4_0(v16i8, __VA_ARGS__)
  748. #define SLDI_B4_0_SH(...) SLDI_B4_0(v8i16, __VA_ARGS__)
  749. /* Description : Immediate number of columns to slide
  750. Arguments : Inputs - in0_0, in0_1, in1_0, in1_1, slide_val
  751. Outputs - out0, out1
  752. Return Type - as per RTYPE
  753. Details : Byte elements from 'in0_0' vector are slide into 'in1_0' by
  754. number of elements specified by 'slide_val'
  755. */
  756. #define SLDI_B2(RTYPE, in0_0, in0_1, in1_0, in1_1, out0, out1, slide_val) \
  757. { \
  758. out0 = (RTYPE) __msa_sldi_b((v16i8) in0_0, (v16i8) in1_0, slide_val); \
  759. out1 = (RTYPE) __msa_sldi_b((v16i8) in0_1, (v16i8) in1_1, slide_val); \
  760. }
  761. #define SLDI_B2_UB(...) SLDI_B2(v16u8, __VA_ARGS__)
  762. #define SLDI_B2_SB(...) SLDI_B2(v16i8, __VA_ARGS__)
  763. #define SLDI_B2_SH(...) SLDI_B2(v8i16, __VA_ARGS__)
  764. /* Description : Shuffle byte vector elements as per mask vector
  765. Arguments : Inputs - in0, in1, in2, in3, mask0, mask1
  766. Outputs - out0, out1
  767. Return Type - as per RTYPE
  768. Details : Selective byte elements from in0 & in1 are copied to out0 as
  769. per control vector mask0
  770. Selective byte elements from in2 & in3 are copied to out1 as
  771. per control vector mask1
  772. */
  773. #define VSHF_B2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1) \
  774. { \
  775. out0 = (RTYPE) __msa_vshf_b((v16i8) mask0, (v16i8) in1, (v16i8) in0); \
  776. out1 = (RTYPE) __msa_vshf_b((v16i8) mask1, (v16i8) in3, (v16i8) in2); \
  777. }
  778. #define VSHF_B2_UB(...) VSHF_B2(v16u8, __VA_ARGS__)
  779. #define VSHF_B2_SB(...) VSHF_B2(v16i8, __VA_ARGS__)
  780. #define VSHF_B2_UH(...) VSHF_B2(v8u16, __VA_ARGS__)
  781. #define VSHF_B2_SH(...) VSHF_B2(v8i16, __VA_ARGS__)
  782. #define VSHF_B3(RTYPE, in0, in1, in2, in3, in4, in5, mask0, mask1, mask2, \
  783. out0, out1, out2) \
  784. { \
  785. VSHF_B2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1); \
  786. out2 = (RTYPE) __msa_vshf_b((v16i8) mask2, (v16i8) in5, (v16i8) in4); \
  787. }
  788. #define VSHF_B3_SB(...) VSHF_B3(v16i8, __VA_ARGS__)
  789. #define VSHF_B4(RTYPE, in0, in1, mask0, mask1, mask2, mask3, \
  790. out0, out1, out2, out3) \
  791. { \
  792. VSHF_B2(RTYPE, in0, in1, in0, in1, mask0, mask1, out0, out1); \
  793. VSHF_B2(RTYPE, in0, in1, in0, in1, mask2, mask3, out2, out3); \
  794. }
  795. #define VSHF_B4_SB(...) VSHF_B4(v16i8, __VA_ARGS__)
  796. #define VSHF_B4_SH(...) VSHF_B4(v8i16, __VA_ARGS__)
  797. /* Description : Shuffle halfword vector elements as per mask vector
  798. Arguments : Inputs - in0, in1, in2, in3, mask0, mask1
  799. Outputs - out0, out1
  800. Return Type - as per RTYPE
  801. Details : Selective halfword elements from in0 & in1 are copied to out0
  802. as per control vector mask0
  803. Selective halfword elements from in2 & in3 are copied to out1
  804. as per control vector mask1
  805. */
  806. #define VSHF_H2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1) \
  807. { \
  808. out0 = (RTYPE) __msa_vshf_h((v8i16) mask0, (v8i16) in1, (v8i16) in0); \
  809. out1 = (RTYPE) __msa_vshf_h((v8i16) mask1, (v8i16) in3, (v8i16) in2); \
  810. }
  811. #define VSHF_H2_SH(...) VSHF_H2(v8i16, __VA_ARGS__)
  812. /* Description : Shuffle byte vector elements as per mask vector
  813. Arguments : Inputs - in0, in1, in2, in3, mask0, mask1
  814. Outputs - out0, out1
  815. Return Type - as per RTYPE
  816. Details : Selective byte elements from in0 & in1 are copied to out0 as
  817. per control vector mask0
  818. Selective byte elements from in2 & in3 are copied to out1 as
  819. per control vector mask1
  820. */
  821. #define VSHF_W2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1) \
  822. { \
  823. out0 = (RTYPE) __msa_vshf_w((v4i32) mask0, (v4i32) in1, (v4i32) in0); \
  824. out1 = (RTYPE) __msa_vshf_w((v4i32) mask1, (v4i32) in3, (v4i32) in2); \
  825. }
  826. #define VSHF_W2_SB(...) VSHF_W2(v16i8, __VA_ARGS__)
  827. /* Description : Dot product of byte vector elements
  828. Arguments : Inputs - mult0, mult1
  829. cnst0, cnst1
  830. Outputs - out0, out1
  831. Return Type - unsigned halfword
  832. Details : Unsigned byte elements from mult0 are multiplied with
  833. unsigned byte elements from cnst0 producing a result
  834. twice the size of input i.e. unsigned halfword.
  835. Then this multiplication results of adjacent odd-even elements
  836. are added together and stored to the out vector
  837. (2 unsigned halfword results)
  838. */
  839. #define DOTP_UB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  840. { \
  841. out0 = (RTYPE) __msa_dotp_u_h((v16u8) mult0, (v16u8) cnst0); \
  842. out1 = (RTYPE) __msa_dotp_u_h((v16u8) mult1, (v16u8) cnst1); \
  843. }
  844. #define DOTP_UB2_UH(...) DOTP_UB2(v8u16, __VA_ARGS__)
  845. #define DOTP_UB4(RTYPE, mult0, mult1, mult2, mult3, \
  846. cnst0, cnst1, cnst2, cnst3, \
  847. out0, out1, out2, out3) \
  848. { \
  849. DOTP_UB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  850. DOTP_UB2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  851. }
  852. #define DOTP_UB4_UH(...) DOTP_UB4(v8u16, __VA_ARGS__)
  853. /* Description : Dot product of byte vector elements
  854. Arguments : Inputs - mult0, mult1
  855. cnst0, cnst1
  856. Outputs - out0, out1
  857. Return Type - signed halfword
  858. Details : Signed byte elements from mult0 are multiplied with
  859. signed byte elements from cnst0 producing a result
  860. twice the size of input i.e. signed halfword.
  861. Then this multiplication results of adjacent odd-even elements
  862. are added together and stored to the out vector
  863. (2 signed halfword results)
  864. */
  865. #define DOTP_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  866. { \
  867. out0 = (RTYPE) __msa_dotp_s_h((v16i8) mult0, (v16i8) cnst0); \
  868. out1 = (RTYPE) __msa_dotp_s_h((v16i8) mult1, (v16i8) cnst1); \
  869. }
  870. #define DOTP_SB2_SH(...) DOTP_SB2(v8i16, __VA_ARGS__)
  871. #define DOTP_SB3(RTYPE, mult0, mult1, mult2, cnst0, cnst1, cnst2, \
  872. out0, out1, out2) \
  873. { \
  874. DOTP_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  875. out2 = (RTYPE) __msa_dotp_s_h((v16i8) mult2, (v16i8) cnst2); \
  876. }
  877. #define DOTP_SB3_SH(...) DOTP_SB3(v8i16, __VA_ARGS__)
  878. #define DOTP_SB4(RTYPE, mult0, mult1, mult2, mult3, \
  879. cnst0, cnst1, cnst2, cnst3, out0, out1, out2, out3) \
  880. { \
  881. DOTP_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  882. DOTP_SB2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  883. }
  884. #define DOTP_SB4_SH(...) DOTP_SB4(v8i16, __VA_ARGS__)
  885. /* Description : Dot product of halfword vector elements
  886. Arguments : Inputs - mult0, mult1
  887. cnst0, cnst1
  888. Outputs - out0, out1
  889. Return Type - signed word
  890. Details : Signed halfword elements from mult0 are multiplied with
  891. signed halfword elements from cnst0 producing a result
  892. twice the size of input i.e. signed word.
  893. Then this multiplication results of adjacent odd-even elements
  894. are added together and stored to the out vector
  895. (2 signed word results)
  896. */
  897. #define DOTP_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  898. { \
  899. out0 = (RTYPE) __msa_dotp_s_w((v8i16) mult0, (v8i16) cnst0); \
  900. out1 = (RTYPE) __msa_dotp_s_w((v8i16) mult1, (v8i16) cnst1); \
  901. }
  902. #define DOTP_SH2_SW(...) DOTP_SH2(v4i32, __VA_ARGS__)
  903. #define DOTP_SH4(RTYPE, mult0, mult1, mult2, mult3, \
  904. cnst0, cnst1, cnst2, cnst3, \
  905. out0, out1, out2, out3) \
  906. { \
  907. DOTP_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  908. DOTP_SH2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  909. }
  910. #define DOTP_SH4_SW(...) DOTP_SH4(v4i32, __VA_ARGS__)
  911. /* Description : Dot product & addition of byte vector elements
  912. Arguments : Inputs - mult0, mult1
  913. cnst0, cnst1
  914. Outputs - out0, out1
  915. Return Type - signed halfword
  916. Details : Signed byte elements from mult0 are multiplied with
  917. signed byte elements from cnst0 producing a result
  918. twice the size of input i.e. signed halfword.
  919. Then this multiplication results of adjacent odd-even elements
  920. are added to the out vector
  921. (2 signed halfword results)
  922. */
  923. #define DPADD_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  924. { \
  925. out0 = (RTYPE) __msa_dpadd_s_h((v8i16) out0, \
  926. (v16i8) mult0, (v16i8) cnst0); \
  927. out1 = (RTYPE) __msa_dpadd_s_h((v8i16) out1, \
  928. (v16i8) mult1, (v16i8) cnst1); \
  929. }
  930. #define DPADD_SB2_SH(...) DPADD_SB2(v8i16, __VA_ARGS__)
  931. #define DPADD_SB4(RTYPE, mult0, mult1, mult2, mult3, \
  932. cnst0, cnst1, cnst2, cnst3, out0, out1, out2, out3) \
  933. { \
  934. DPADD_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  935. DPADD_SB2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  936. }
  937. #define DPADD_SB4_SH(...) DPADD_SB4(v8i16, __VA_ARGS__)
  938. /* Description : Dot product & addition of halfword vector elements
  939. Arguments : Inputs - mult0, mult1
  940. cnst0, cnst1
  941. Outputs - out0, out1
  942. Return Type - signed word
  943. Details : Signed halfword elements from mult0 are multiplied with
  944. signed halfword elements from cnst0 producing a result
  945. twice the size of input i.e. signed word.
  946. Then this multiplication results of adjacent odd-even elements
  947. are added to the out vector
  948. (2 signed word results)
  949. */
  950. #define DPADD_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  951. { \
  952. out0 = (RTYPE) __msa_dpadd_s_w((v4i32) out0, \
  953. (v8i16) mult0, (v8i16) cnst0); \
  954. out1 = (RTYPE) __msa_dpadd_s_w((v4i32) out1, \
  955. (v8i16) mult1, (v8i16) cnst1); \
  956. }
  957. #define DPADD_SH2_SW(...) DPADD_SH2(v4i32, __VA_ARGS__)
  958. #define DPADD_SH4(RTYPE, mult0, mult1, mult2, mult3, \
  959. cnst0, cnst1, cnst2, cnst3, out0, out1, out2, out3) \
  960. { \
  961. DPADD_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  962. DPADD_SH2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  963. }
  964. #define DPADD_SH4_SW(...) DPADD_SH4(v4i32, __VA_ARGS__)
  965. /* Description : Clips all halfword elements of input vector between min & max
  966. out = ((in) < (min)) ? (min) : (((in) > (max)) ? (max) : (in))
  967. Arguments : Inputs - in (input vector)
  968. - min (min threshold)
  969. - max (max threshold)
  970. Outputs - out_m (output vector with clipped elements)
  971. Return Type - signed halfword
  972. */
  973. #define CLIP_SH(in, min, max) \
  974. ( { \
  975. v8i16 out_m; \
  976. \
  977. out_m = __msa_max_s_h((v8i16) min, (v8i16) in); \
  978. out_m = __msa_min_s_h((v8i16) max, (v8i16) out_m); \
  979. out_m; \
  980. } )
  981. /* Description : Clips all signed halfword elements of input vector
  982. between 0 & 255
  983. Arguments : Inputs - in (input vector)
  984. Outputs - out_m (output vector with clipped elements)
  985. Return Type - signed halfword
  986. */
  987. #define CLIP_SH_0_255(in) \
  988. ( { \
  989. v8i16 max_m = __msa_ldi_h(255); \
  990. v8i16 out_m; \
  991. \
  992. out_m = __msa_maxi_s_h((v8i16) in, 0); \
  993. out_m = __msa_min_s_h((v8i16) max_m, (v8i16) out_m); \
  994. out_m; \
  995. } )
  996. #define CLIP_SH2_0_255(in0, in1) \
  997. { \
  998. in0 = CLIP_SH_0_255(in0); \
  999. in1 = CLIP_SH_0_255(in1); \
  1000. }
  1001. #define CLIP_SH4_0_255(in0, in1, in2, in3) \
  1002. { \
  1003. CLIP_SH2_0_255(in0, in1); \
  1004. CLIP_SH2_0_255(in2, in3); \
  1005. }
  1006. /* Description : Clips all signed word elements of input vector
  1007. between 0 & 255
  1008. Arguments : Inputs - in (input vector)
  1009. Outputs - out_m (output vector with clipped elements)
  1010. Return Type - signed word
  1011. */
  1012. #define CLIP_SW_0_255(in) \
  1013. ( { \
  1014. v4i32 max_m = __msa_ldi_w(255); \
  1015. v4i32 out_m; \
  1016. \
  1017. out_m = __msa_maxi_s_w((v4i32) in, 0); \
  1018. out_m = __msa_min_s_w((v4i32) max_m, (v4i32) out_m); \
  1019. out_m; \
  1020. } )
  1021. /* Description : Horizontal addition of unsigned byte vector elements
  1022. Arguments : Inputs - in0, in1
  1023. Outputs - out0, out1
  1024. Return Type - as per RTYPE
  1025. Details : Each unsigned odd byte element from 'in0' is added to
  1026. even unsigned byte element from 'in0' (pairwise) and the
  1027. halfword result is stored in 'out0'
  1028. */
  1029. #define HADD_UB2(RTYPE, in0, in1, out0, out1) \
  1030. { \
  1031. out0 = (RTYPE) __msa_hadd_u_h((v16u8) in0, (v16u8) in0); \
  1032. out1 = (RTYPE) __msa_hadd_u_h((v16u8) in1, (v16u8) in1); \
  1033. }
  1034. #define HADD_UB2_UH(...) HADD_UB2(v8u16, __VA_ARGS__)
  1035. /* Description : Horizontal subtraction of unsigned byte vector elements
  1036. Arguments : Inputs - in0, in1
  1037. Outputs - out0, out1
  1038. Return Type - as per RTYPE
  1039. Details : Each unsigned odd byte element from 'in0' is subtracted from
  1040. even unsigned byte element from 'in0' (pairwise) and the
  1041. halfword result is stored in 'out0'
  1042. */
  1043. #define HSUB_UB2(RTYPE, in0, in1, out0, out1) \
  1044. { \
  1045. out0 = (RTYPE) __msa_hsub_u_h((v16u8) in0, (v16u8) in0); \
  1046. out1 = (RTYPE) __msa_hsub_u_h((v16u8) in1, (v16u8) in1); \
  1047. }
  1048. #define HSUB_UB2_UH(...) HSUB_UB2(v8u16, __VA_ARGS__)
  1049. #define HSUB_UB2_SH(...) HSUB_UB2(v8i16, __VA_ARGS__)
  1050. /* Description : Insert specified word elements from input vectors to 1
  1051. destination vector
  1052. Arguments : Inputs - in0, in1, in2, in3 (4 input vectors)
  1053. Outputs - out (output vector)
  1054. Return Type - as per RTYPE
  1055. */
  1056. #define INSERT_W2(RTYPE, in0, in1, out) \
  1057. { \
  1058. out = (RTYPE) __msa_insert_w((v4i32) out, 0, in0); \
  1059. out = (RTYPE) __msa_insert_w((v4i32) out, 1, in1); \
  1060. }
  1061. #define INSERT_W2_UB(...) INSERT_W2(v16u8, __VA_ARGS__)
  1062. #define INSERT_W2_SB(...) INSERT_W2(v16i8, __VA_ARGS__)
  1063. #define INSERT_W4(RTYPE, in0, in1, in2, in3, out) \
  1064. { \
  1065. out = (RTYPE) __msa_insert_w((v4i32) out, 0, in0); \
  1066. out = (RTYPE) __msa_insert_w((v4i32) out, 1, in1); \
  1067. out = (RTYPE) __msa_insert_w((v4i32) out, 2, in2); \
  1068. out = (RTYPE) __msa_insert_w((v4i32) out, 3, in3); \
  1069. }
  1070. #define INSERT_W4_UB(...) INSERT_W4(v16u8, __VA_ARGS__)
  1071. #define INSERT_W4_SB(...) INSERT_W4(v16i8, __VA_ARGS__)
  1072. #define INSERT_W4_SW(...) INSERT_W4(v4i32, __VA_ARGS__)
  1073. /* Description : Insert specified double word elements from input vectors to 1
  1074. destination vector
  1075. Arguments : Inputs - in0, in1 (2 input vectors)
  1076. Outputs - out (output vector)
  1077. Return Type - as per RTYPE
  1078. */
  1079. #define INSERT_D2(RTYPE, in0, in1, out) \
  1080. { \
  1081. out = (RTYPE) __msa_insert_d((v2i64) out, 0, in0); \
  1082. out = (RTYPE) __msa_insert_d((v2i64) out, 1, in1); \
  1083. }
  1084. #define INSERT_D2_UB(...) INSERT_D2(v16u8, __VA_ARGS__)
  1085. #define INSERT_D2_SB(...) INSERT_D2(v16i8, __VA_ARGS__)
  1086. #define INSERT_D2_SD(...) INSERT_D2(v2i64, __VA_ARGS__)
  1087. /* Description : Interleave even byte elements from vectors
  1088. Arguments : Inputs - in0, in1, in2, in3
  1089. Outputs - out0, out1
  1090. Return Type - as per RTYPE
  1091. Details : Even byte elements of 'in0' and even byte
  1092. elements of 'in1' are interleaved and copied to 'out0'
  1093. Even byte elements of 'in2' and even byte
  1094. elements of 'in3' are interleaved and copied to 'out1'
  1095. */
  1096. #define ILVEV_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1097. { \
  1098. out0 = (RTYPE) __msa_ilvev_b((v16i8) in1, (v16i8) in0); \
  1099. out1 = (RTYPE) __msa_ilvev_b((v16i8) in3, (v16i8) in2); \
  1100. }
  1101. #define ILVEV_B2_UB(...) ILVEV_B2(v16u8, __VA_ARGS__)
  1102. #define ILVEV_B2_SB(...) ILVEV_B2(v16i8, __VA_ARGS__)
  1103. #define ILVEV_B2_SH(...) ILVEV_B2(v8i16, __VA_ARGS__)
  1104. #define ILVEV_B2_SD(...) ILVEV_B2(v2i64, __VA_ARGS__)
  1105. /* Description : Interleave even halfword elements from vectors
  1106. Arguments : Inputs - in0, in1, in2, in3
  1107. Outputs - out0, out1
  1108. Return Type - as per RTYPE
  1109. Details : Even halfword elements of 'in0' and even halfword
  1110. elements of 'in1' are interleaved and copied to 'out0'
  1111. Even halfword elements of 'in2' and even halfword
  1112. elements of 'in3' are interleaved and copied to 'out1'
  1113. */
  1114. #define ILVEV_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1115. { \
  1116. out0 = (RTYPE) __msa_ilvev_h((v8i16) in1, (v8i16) in0); \
  1117. out1 = (RTYPE) __msa_ilvev_h((v8i16) in3, (v8i16) in2); \
  1118. }
  1119. #define ILVEV_H2_UB(...) ILVEV_H2(v16u8, __VA_ARGS__)
  1120. /* Description : Interleave even word elements from vectors
  1121. Arguments : Inputs - in0, in1, in2, in3
  1122. Outputs - out0, out1
  1123. Return Type - as per RTYPE
  1124. Details : Even word elements of 'in0' and even word
  1125. elements of 'in1' are interleaved and copied to 'out0'
  1126. Even word elements of 'in2' and even word
  1127. elements of 'in3' are interleaved and copied to 'out1'
  1128. */
  1129. #define ILVEV_W2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1130. { \
  1131. out0 = (RTYPE) __msa_ilvev_w((v4i32) in1, (v4i32) in0); \
  1132. out1 = (RTYPE) __msa_ilvev_w((v4i32) in3, (v4i32) in2); \
  1133. }
  1134. #define ILVEV_W2_SB(...) ILVEV_W2(v16i8, __VA_ARGS__)
  1135. /* Description : Interleave even double word elements from vectors
  1136. Arguments : Inputs - in0, in1, in2, in3
  1137. Outputs - out0, out1
  1138. Return Type - as per RTYPE
  1139. Details : Even double word elements of 'in0' and even double word
  1140. elements of 'in1' are interleaved and copied to 'out0'
  1141. Even double word elements of 'in2' and even double word
  1142. elements of 'in3' are interleaved and copied to 'out1'
  1143. */
  1144. #define ILVEV_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1145. { \
  1146. out0 = (RTYPE) __msa_ilvev_d((v2i64) in1, (v2i64) in0); \
  1147. out1 = (RTYPE) __msa_ilvev_d((v2i64) in3, (v2i64) in2); \
  1148. }
  1149. #define ILVEV_D2_UB(...) ILVEV_D2(v16u8, __VA_ARGS__)
  1150. #define ILVEV_D2_SB(...) ILVEV_D2(v16i8, __VA_ARGS__)
  1151. #define ILVEV_D2_SW(...) ILVEV_D2(v4i32, __VA_ARGS__)
  1152. /* Description : Interleave left half of byte elements from vectors
  1153. Arguments : Inputs - in0, in1, in2, in3
  1154. Outputs - out0, out1
  1155. Return Type - as per RTYPE
  1156. Details : Left half of byte elements of in0 and left half of byte
  1157. elements of in1 are interleaved and copied to out0.
  1158. Left half of byte elements of in2 and left half of byte
  1159. elements of in3 are interleaved and copied to out1.
  1160. */
  1161. #define ILVL_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1162. { \
  1163. out0 = (RTYPE) __msa_ilvl_b((v16i8) in0, (v16i8) in1); \
  1164. out1 = (RTYPE) __msa_ilvl_b((v16i8) in2, (v16i8) in3); \
  1165. }
  1166. #define ILVL_B2_SB(...) ILVL_B2(v16i8, __VA_ARGS__)
  1167. #define ILVL_B2_SH(...) ILVL_B2(v8i16, __VA_ARGS__)
  1168. #define ILVL_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1169. out0, out1, out2, out3) \
  1170. { \
  1171. ILVL_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1172. ILVL_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1173. }
  1174. #define ILVL_B4_SB(...) ILVL_B4(v16i8, __VA_ARGS__)
  1175. #define ILVL_B4_UH(...) ILVL_B4(v8u16, __VA_ARGS__)
  1176. #define ILVL_B4_SH(...) ILVL_B4(v8i16, __VA_ARGS__)
  1177. /* Description : Interleave left half of halfword elements from vectors
  1178. Arguments : Inputs - in0, in1, in2, in3
  1179. Outputs - out0, out1
  1180. Return Type - as per RTYPE
  1181. Details : Left half of halfword elements of in0 and left half of halfword
  1182. elements of in1 are interleaved and copied to out0.
  1183. Left half of halfword elements of in2 and left half of halfword
  1184. elements of in3 are interleaved and copied to out1.
  1185. */
  1186. #define ILVL_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1187. { \
  1188. out0 = (RTYPE) __msa_ilvl_h((v8i16) in0, (v8i16) in1); \
  1189. out1 = (RTYPE) __msa_ilvl_h((v8i16) in2, (v8i16) in3); \
  1190. }
  1191. #define ILVL_H2_SH(...) ILVL_H2(v8i16, __VA_ARGS__)
  1192. #define ILVL_H2_SW(...) ILVL_H2(v4i32, __VA_ARGS__)
  1193. #define ILVL_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1194. out0, out1, out2, out3) \
  1195. { \
  1196. ILVL_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1197. ILVL_H2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1198. }
  1199. #define ILVL_H4_SH(...) ILVL_H4(v8i16, __VA_ARGS__)
  1200. /* Description : Interleave left half of word elements from vectors
  1201. Arguments : Inputs - in0, in1, in2, in3
  1202. Outputs - out0, out1
  1203. Return Type - as per RTYPE
  1204. Details : Left half of word elements of in0 and left half of word
  1205. elements of in1 are interleaved and copied to out0.
  1206. Left half of word elements of in2 and left half of word
  1207. elements of in3 are interleaved and copied to out1.
  1208. */
  1209. #define ILVL_W2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1210. { \
  1211. out0 = (RTYPE) __msa_ilvl_w((v4i32) in0, (v4i32) in1); \
  1212. out1 = (RTYPE) __msa_ilvl_w((v4i32) in2, (v4i32) in3); \
  1213. }
  1214. #define ILVL_W2_SB(...) ILVL_W2(v16i8, __VA_ARGS__)
  1215. /* Description : Interleave right half of byte elements from vectors
  1216. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1217. Outputs - out0, out1, out2, out3
  1218. Return Type - as per RTYPE
  1219. Details : Right half of byte elements of in0 and right half of byte
  1220. elements of in1 are interleaved and copied to out0.
  1221. Right half of byte elements of in2 and right half of byte
  1222. elements of in3 are interleaved and copied to out1.
  1223. Similar for other pairs
  1224. */
  1225. #define ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1226. { \
  1227. out0 = (RTYPE) __msa_ilvr_b((v16i8) in0, (v16i8) in1); \
  1228. out1 = (RTYPE) __msa_ilvr_b((v16i8) in2, (v16i8) in3); \
  1229. }
  1230. #define ILVR_B2_UB(...) ILVR_B2(v16u8, __VA_ARGS__)
  1231. #define ILVR_B2_SB(...) ILVR_B2(v16i8, __VA_ARGS__)
  1232. #define ILVR_B2_UH(...) ILVR_B2(v8u16, __VA_ARGS__)
  1233. #define ILVR_B2_SH(...) ILVR_B2(v8i16, __VA_ARGS__)
  1234. #define ILVR_B2_SW(...) ILVR_B2(v4i32, __VA_ARGS__)
  1235. #define ILVR_B3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1236. { \
  1237. ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1238. out2 = (RTYPE) __msa_ilvr_b((v16i8) in4, (v16i8) in5); \
  1239. }
  1240. #define ILVR_B3_UB(...) ILVR_B3(v16u8, __VA_ARGS__)
  1241. #define ILVR_B3_UH(...) ILVR_B3(v8u16, __VA_ARGS__)
  1242. #define ILVR_B3_SH(...) ILVR_B3(v8i16, __VA_ARGS__)
  1243. #define ILVR_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1244. out0, out1, out2, out3) \
  1245. { \
  1246. ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1247. ILVR_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1248. }
  1249. #define ILVR_B4_UB(...) ILVR_B4(v16u8, __VA_ARGS__)
  1250. #define ILVR_B4_SB(...) ILVR_B4(v16i8, __VA_ARGS__)
  1251. #define ILVR_B4_UH(...) ILVR_B4(v8u16, __VA_ARGS__)
  1252. #define ILVR_B4_SH(...) ILVR_B4(v8i16, __VA_ARGS__)
  1253. #define ILVR_B4_SW(...) ILVR_B4(v4i32, __VA_ARGS__)
  1254. #define ILVR_B8(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1255. in8, in9, in10, in11, in12, in13, in14, in15, \
  1256. out0, out1, out2, out3, out4, out5, out6, out7) \
  1257. { \
  1258. ILVR_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1259. out0, out1, out2, out3); \
  1260. ILVR_B4(RTYPE, in8, in9, in10, in11, in12, in13, in14, in15, \
  1261. out4, out5, out6, out7); \
  1262. }
  1263. #define ILVR_B8_UH(...) ILVR_B8(v8u16, __VA_ARGS__)
  1264. /* Description : Interleave right half of halfword elements from vectors
  1265. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1266. Outputs - out0, out1, out2, out3
  1267. Return Type - signed halfword
  1268. Details : Right half of halfword elements of in0 and right half of
  1269. halfword elements of in1 are interleaved and copied to out0.
  1270. Right half of halfword elements of in2 and right half of
  1271. halfword elements of in3 are interleaved and copied to out1.
  1272. Similar for other pairs
  1273. */
  1274. #define ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1275. { \
  1276. out0 = (RTYPE) __msa_ilvr_h((v8i16) in0, (v8i16) in1); \
  1277. out1 = (RTYPE) __msa_ilvr_h((v8i16) in2, (v8i16) in3); \
  1278. }
  1279. #define ILVR_H2_SH(...) ILVR_H2(v8i16, __VA_ARGS__)
  1280. #define ILVR_H2_SW(...) ILVR_H2(v4i32, __VA_ARGS__)
  1281. #define ILVR_H3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1282. { \
  1283. ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1284. out2 = (RTYPE) __msa_ilvr_h((v8i16) in4, (v8i16) in5); \
  1285. }
  1286. #define ILVR_H3_SH(...) ILVR_H3(v8i16, __VA_ARGS__)
  1287. #define ILVR_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1288. out0, out1, out2, out3) \
  1289. { \
  1290. ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1291. ILVR_H2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1292. }
  1293. #define ILVR_H4_SH(...) ILVR_H4(v8i16, __VA_ARGS__)
  1294. #define ILVR_W2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1295. { \
  1296. out0 = (RTYPE) __msa_ilvr_w((v4i32) in0, (v4i32) in1); \
  1297. out1 = (RTYPE) __msa_ilvr_w((v4i32) in2, (v4i32) in3); \
  1298. }
  1299. #define ILVR_W2_UB(...) ILVR_W2(v16u8, __VA_ARGS__)
  1300. #define ILVR_W2_SB(...) ILVR_W2(v16i8, __VA_ARGS__)
  1301. #define ILVR_W4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1302. out0, out1, out2, out3) \
  1303. { \
  1304. ILVR_W2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1305. ILVR_W2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1306. }
  1307. #define ILVR_W4_SB(...) ILVR_W4(v16i8, __VA_ARGS__)
  1308. /* Description : Interleave right half of double word elements from vectors
  1309. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1310. Outputs - out0, out1, out2, out3
  1311. Return Type - unsigned double word
  1312. Details : Right half of double word elements of in0 and right half of
  1313. double word elements of in1 are interleaved and copied to out0.
  1314. Right half of double word elements of in2 and right half of
  1315. double word elements of in3 are interleaved and copied to out1.
  1316. */
  1317. #define ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1318. { \
  1319. out0 = (RTYPE) __msa_ilvr_d((v2i64) (in0), (v2i64) (in1)); \
  1320. out1 = (RTYPE) __msa_ilvr_d((v2i64) (in2), (v2i64) (in3)); \
  1321. }
  1322. #define ILVR_D2_UB(...) ILVR_D2(v16u8, __VA_ARGS__)
  1323. #define ILVR_D2_SB(...) ILVR_D2(v16i8, __VA_ARGS__)
  1324. #define ILVR_D2_SH(...) ILVR_D2(v8i16, __VA_ARGS__)
  1325. #define ILVR_D3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1326. { \
  1327. ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1328. out2 = (RTYPE) __msa_ilvr_d((v2i64) (in4), (v2i64) (in5)); \
  1329. }
  1330. #define ILVR_D3_SB(...) ILVR_D3(v16i8, __VA_ARGS__)
  1331. #define ILVR_D4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1332. out0, out1, out2, out3) \
  1333. { \
  1334. ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1335. ILVR_D2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1336. }
  1337. #define ILVR_D4_SB(...) ILVR_D4(v16i8, __VA_ARGS__)
  1338. /* Description : Interleave both left and right half of input vectors
  1339. Arguments : Inputs - in0, in1
  1340. Outputs - out0, out1
  1341. Return Type - as per RTYPE
  1342. Details : Right half of byte elements from 'in0' and 'in1' are
  1343. interleaved and stored to 'out0'
  1344. Left half of byte elements from 'in0' and 'in1' are
  1345. interleaved and stored to 'out1'
  1346. */
  1347. #define ILVRL_B2(RTYPE, in0, in1, out0, out1) \
  1348. { \
  1349. out0 = (RTYPE) __msa_ilvr_b((v16i8) in0, (v16i8) in1); \
  1350. out1 = (RTYPE) __msa_ilvl_b((v16i8) in0, (v16i8) in1); \
  1351. }
  1352. #define ILVRL_B2_UB(...) ILVRL_B2(v16u8, __VA_ARGS__)
  1353. #define ILVRL_B2_SB(...) ILVRL_B2(v16i8, __VA_ARGS__)
  1354. #define ILVRL_B2_UH(...) ILVRL_B2(v8u16, __VA_ARGS__)
  1355. #define ILVRL_B2_SH(...) ILVRL_B2(v8i16, __VA_ARGS__)
  1356. #define ILVRL_B2_SW(...) ILVRL_B2(v4i32, __VA_ARGS__)
  1357. #define ILVRL_H2(RTYPE, in0, in1, out0, out1) \
  1358. { \
  1359. out0 = (RTYPE) __msa_ilvr_h((v8i16) in0, (v8i16) in1); \
  1360. out1 = (RTYPE) __msa_ilvl_h((v8i16) in0, (v8i16) in1); \
  1361. }
  1362. #define ILVRL_H2_SB(...) ILVRL_H2(v16i8, __VA_ARGS__)
  1363. #define ILVRL_H2_SH(...) ILVRL_H2(v8i16, __VA_ARGS__)
  1364. #define ILVRL_H2_SW(...) ILVRL_H2(v4i32, __VA_ARGS__)
  1365. #define ILVRL_W2(RTYPE, in0, in1, out0, out1) \
  1366. { \
  1367. out0 = (RTYPE) __msa_ilvr_w((v4i32) in0, (v4i32) in1); \
  1368. out1 = (RTYPE) __msa_ilvl_w((v4i32) in0, (v4i32) in1); \
  1369. }
  1370. #define ILVRL_W2_UB(...) ILVRL_W2(v16u8, __VA_ARGS__)
  1371. #define ILVRL_W2_SH(...) ILVRL_W2(v8i16, __VA_ARGS__)
  1372. #define ILVRL_W2_SW(...) ILVRL_W2(v4i32, __VA_ARGS__)
  1373. /* Description : Maximum values between signed elements of vector and
  1374. 5-bit signed immediate value are copied to the output vector
  1375. Arguments : Inputs - in0, in1, in2, in3, max_val
  1376. Outputs - in0, in1, in2, in3 (in place)
  1377. Return Type - unsigned halfword
  1378. Details : Maximum of signed halfword element values from 'in0' and
  1379. 'max_val' are written to output vector 'in0'
  1380. */
  1381. #define MAXI_SH2(RTYPE, in0, in1, max_val) \
  1382. { \
  1383. in0 = (RTYPE) __msa_maxi_s_h((v8i16) in0, (max_val)); \
  1384. in1 = (RTYPE) __msa_maxi_s_h((v8i16) in1, (max_val)); \
  1385. }
  1386. #define MAXI_SH2_SH(...) MAXI_SH2(v8i16, __VA_ARGS__)
  1387. #define MAXI_SH4(RTYPE, in0, in1, in2, in3, max_val) \
  1388. { \
  1389. MAXI_SH2(RTYPE, in0, in1, max_val); \
  1390. MAXI_SH2(RTYPE, in2, in3, max_val); \
  1391. }
  1392. #define MAXI_SH4_UH(...) MAXI_SH4(v8u16, __VA_ARGS__)
  1393. /* Description : Saturate the halfword element values to the max
  1394. unsigned value of (sat_val+1 bits)
  1395. The element data width remains unchanged
  1396. Arguments : Inputs - in0, in1, in2, in3, sat_val
  1397. Outputs - in0, in1, in2, in3 (in place)
  1398. Return Type - unsigned halfword
  1399. Details : Each unsigned halfword element from 'in0' is saturated to the
  1400. value generated with (sat_val+1) bit range
  1401. Results are in placed to original vectors
  1402. */
  1403. #define SAT_UH2(RTYPE, in0, in1, sat_val) \
  1404. { \
  1405. in0 = (RTYPE) __msa_sat_u_h((v8u16) in0, sat_val); \
  1406. in1 = (RTYPE) __msa_sat_u_h((v8u16) in1, sat_val); \
  1407. }
  1408. #define SAT_UH2_UH(...) SAT_UH2(v8u16, __VA_ARGS__)
  1409. #define SAT_UH4(RTYPE, in0, in1, in2, in3, sat_val) \
  1410. { \
  1411. SAT_UH2(RTYPE, in0, in1, sat_val); \
  1412. SAT_UH2(RTYPE, in2, in3, sat_val) \
  1413. }
  1414. #define SAT_UH4_UH(...) SAT_UH4(v8u16, __VA_ARGS__)
  1415. /* Description : Saturate the halfword element values to the max
  1416. unsigned value of (sat_val+1 bits)
  1417. The element data width remains unchanged
  1418. Arguments : Inputs - in0, in1, in2, in3, sat_val
  1419. Outputs - in0, in1, in2, in3 (in place)
  1420. Return Type - unsigned halfword
  1421. Details : Each unsigned halfword element from 'in0' is saturated to the
  1422. value generated with (sat_val+1) bit range
  1423. Results are in placed to original vectors
  1424. */
  1425. #define SAT_SH2(RTYPE, in0, in1, sat_val) \
  1426. { \
  1427. in0 = (RTYPE) __msa_sat_s_h((v8i16) in0, sat_val); \
  1428. in1 = (RTYPE) __msa_sat_s_h((v8i16) in1, sat_val); \
  1429. }
  1430. #define SAT_SH2_SH(...) SAT_SH2(v8i16, __VA_ARGS__)
  1431. #define SAT_SH3(RTYPE, in0, in1, in2, sat_val) \
  1432. { \
  1433. SAT_SH2(RTYPE, in0, in1, sat_val) \
  1434. in2 = (RTYPE) __msa_sat_s_h((v8i16) in2, sat_val); \
  1435. }
  1436. #define SAT_SH3_SH(...) SAT_SH3(v8i16, __VA_ARGS__)
  1437. #define SAT_SH4(RTYPE, in0, in1, in2, in3, sat_val) \
  1438. { \
  1439. SAT_SH2(RTYPE, in0, in1, sat_val); \
  1440. SAT_SH2(RTYPE, in2, in3, sat_val); \
  1441. }
  1442. #define SAT_SH4_SH(...) SAT_SH4(v8i16, __VA_ARGS__)
  1443. /* Description : Saturate the word element values to the max
  1444. unsigned value of (sat_val+1 bits)
  1445. The element data width remains unchanged
  1446. Arguments : Inputs - in0, in1, in2, in3, sat_val
  1447. Outputs - in0, in1, in2, in3 (in place)
  1448. Return Type - unsigned word
  1449. Details : Each unsigned word element from 'in0' is saturated to the
  1450. value generated with (sat_val+1) bit range
  1451. Results are in placed to original vectors
  1452. */
  1453. #define SAT_SW2(RTYPE, in0, in1, sat_val) \
  1454. { \
  1455. in0 = (RTYPE) __msa_sat_s_w((v4i32) in0, sat_val); \
  1456. in1 = (RTYPE) __msa_sat_s_w((v4i32) in1, sat_val); \
  1457. }
  1458. #define SAT_SW2_SW(...) SAT_SW2(v4i32, __VA_ARGS__)
  1459. #define SAT_SW4(RTYPE, in0, in1, in2, in3, sat_val) \
  1460. { \
  1461. SAT_SW2(RTYPE, in0, in1, sat_val); \
  1462. SAT_SW2(RTYPE, in2, in3, sat_val); \
  1463. }
  1464. #define SAT_SW4_SW(...) SAT_SW4(v4i32, __VA_ARGS__)
  1465. /* Description : Indexed halfword element values are replicated to all
  1466. elements in output vector
  1467. Arguments : Inputs - in, idx0, idx1
  1468. Outputs - out0, out1
  1469. Return Type - as per RTYPE
  1470. Details : 'idx0' element value from 'in' vector is replicated to all
  1471. elements in 'out0' vector
  1472. Valid index range for halfword operation is 0-7
  1473. */
  1474. #define SPLATI_H2(RTYPE, in, idx0, idx1, out0, out1) \
  1475. { \
  1476. out0 = (RTYPE) __msa_splati_h((v8i16) in, idx0); \
  1477. out1 = (RTYPE) __msa_splati_h((v8i16) in, idx1); \
  1478. }
  1479. #define SPLATI_H2_SB(...) SPLATI_H2(v16i8, __VA_ARGS__)
  1480. #define SPLATI_H2_SH(...) SPLATI_H2(v8i16, __VA_ARGS__)
  1481. #define SPLATI_H4(RTYPE, in, idx0, idx1, idx2, idx3, \
  1482. out0, out1, out2, out3) \
  1483. { \
  1484. SPLATI_H2(RTYPE, in, idx0, idx1, out0, out1); \
  1485. SPLATI_H2(RTYPE, in, idx2, idx3, out2, out3); \
  1486. }
  1487. #define SPLATI_H4_SB(...) SPLATI_H4(v16i8, __VA_ARGS__)
  1488. #define SPLATI_H4_SH(...) SPLATI_H4(v8i16, __VA_ARGS__)
  1489. /* Description : Indexed word element values are replicated to all
  1490. elements in output vector
  1491. Arguments : Inputs - in, stidx
  1492. Outputs - out0, out1
  1493. Return Type - as per RTYPE
  1494. Details : 'stidx' element value from 'in' vector is replicated to all
  1495. elements in 'out0' vector
  1496. 'stidx + 1' element value from 'in' vector is replicated to all
  1497. elements in 'out1' vector
  1498. Valid index range for halfword operation is 0-3
  1499. */
  1500. #define SPLATI_W2(RTYPE, in, stidx, out0, out1) \
  1501. { \
  1502. out0 = (RTYPE) __msa_splati_w((v4i32) in, stidx); \
  1503. out1 = (RTYPE) __msa_splati_w((v4i32) in, (stidx+1)); \
  1504. }
  1505. #define SPLATI_W2_SH(...) SPLATI_W2(v8i16, __VA_ARGS__)
  1506. #define SPLATI_W2_SW(...) SPLATI_W2(v4i32, __VA_ARGS__)
  1507. #define SPLATI_W4(RTYPE, in, out0, out1, out2, out3) \
  1508. { \
  1509. SPLATI_W2(RTYPE, in, 0, out0, out1); \
  1510. SPLATI_W2(RTYPE, in, 2, out2, out3); \
  1511. }
  1512. #define SPLATI_W4_SH(...) SPLATI_W4(v8i16, __VA_ARGS__)
  1513. #define SPLATI_W4_SW(...) SPLATI_W4(v4i32, __VA_ARGS__)
  1514. /* Description : Pack even byte elements of vector pairs
  1515. Arguments : Inputs - in0, in1, in2, in3
  1516. Outputs - out0, out1
  1517. Return Type - as per RTYPE
  1518. Details : Even byte elements of in0 are copied to the left half of
  1519. out0 & even byte elements of in1 are copied to the right
  1520. half of out0.
  1521. Even byte elements of in2 are copied to the left half of
  1522. out1 & even byte elements of in3 are copied to the right
  1523. half of out1.
  1524. */
  1525. #define PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1526. { \
  1527. out0 = (RTYPE) __msa_pckev_b((v16i8) in0, (v16i8) in1); \
  1528. out1 = (RTYPE) __msa_pckev_b((v16i8) in2, (v16i8) in3); \
  1529. }
  1530. #define PCKEV_B2_SB(...) PCKEV_B2(v16i8, __VA_ARGS__)
  1531. #define PCKEV_B2_UB(...) PCKEV_B2(v16u8, __VA_ARGS__)
  1532. #define PCKEV_B2_SH(...) PCKEV_B2(v8i16, __VA_ARGS__)
  1533. #define PCKEV_B2_SW(...) PCKEV_B2(v4i32, __VA_ARGS__)
  1534. #define PCKEV_B3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1535. { \
  1536. PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1537. out2 = (RTYPE) __msa_pckev_b((v16i8) in4, (v16i8) in5); \
  1538. }
  1539. #define PCKEV_B3_UB(...) PCKEV_B3(v16u8, __VA_ARGS__)
  1540. #define PCKEV_B3_SB(...) PCKEV_B3(v16i8, __VA_ARGS__)
  1541. #define PCKEV_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1542. out0, out1, out2, out3) \
  1543. { \
  1544. PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1545. PCKEV_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1546. }
  1547. #define PCKEV_B4_SB(...) PCKEV_B4(v16i8, __VA_ARGS__)
  1548. #define PCKEV_B4_UB(...) PCKEV_B4(v16u8, __VA_ARGS__)
  1549. #define PCKEV_B4_SH(...) PCKEV_B4(v8i16, __VA_ARGS__)
  1550. #define PCKEV_B4_SW(...) PCKEV_B4(v4i32, __VA_ARGS__)
  1551. /* Description : Pack even halfword elements of vector pairs
  1552. Arguments : Inputs - in0, in1, in2, in3
  1553. Outputs - out0, out1
  1554. Return Type - as per RTYPE
  1555. Details : Even halfword elements of in0 are copied to the left half of
  1556. out0 & even halfword elements of in1 are copied to the right
  1557. half of out0.
  1558. Even halfword elements of in2 are copied to the left half of
  1559. out1 & even halfword elements of in3 are copied to the right
  1560. half of out1.
  1561. */
  1562. #define PCKEV_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1563. { \
  1564. out0 = (RTYPE) __msa_pckev_h((v8i16) in0, (v8i16) in1); \
  1565. out1 = (RTYPE) __msa_pckev_h((v8i16) in2, (v8i16) in3); \
  1566. }
  1567. #define PCKEV_H2_SH(...) PCKEV_H2(v8i16, __VA_ARGS__)
  1568. #define PCKEV_H2_SW(...) PCKEV_H2(v4i32, __VA_ARGS__)
  1569. #define PCKEV_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1570. out0, out1, out2, out3) \
  1571. { \
  1572. PCKEV_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1573. PCKEV_H2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1574. }
  1575. #define PCKEV_H4_SH(...) PCKEV_H4(v8i16, __VA_ARGS__)
  1576. #define PCKEV_H4_SW(...) PCKEV_H4(v4i32, __VA_ARGS__)
  1577. /* Description : Pack even double word elements of vector pairs
  1578. Arguments : Inputs - in0, in1, in2, in3
  1579. Outputs - out0, out1
  1580. Return Type - unsigned byte
  1581. Details : Even double elements of in0 are copied to the left half of
  1582. out0 & even double elements of in1 are copied to the right
  1583. half of out0.
  1584. Even double elements of in2 are copied to the left half of
  1585. out1 & even double elements of in3 are copied to the right
  1586. half of out1.
  1587. */
  1588. #define PCKEV_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1589. { \
  1590. out0 = (RTYPE) __msa_pckev_d((v2i64) in0, (v2i64) in1); \
  1591. out1 = (RTYPE) __msa_pckev_d((v2i64) in2, (v2i64) in3); \
  1592. }
  1593. #define PCKEV_D2_UB(...) PCKEV_D2(v16u8, __VA_ARGS__)
  1594. #define PCKEV_D2_SB(...) PCKEV_D2(v16i8, __VA_ARGS__)
  1595. #define PCKEV_D2_SH(...) PCKEV_D2(v8i16, __VA_ARGS__)
  1596. #define PCKEV_D4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1597. out0, out1, out2, out3) \
  1598. { \
  1599. PCKEV_D2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1600. PCKEV_D2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1601. }
  1602. #define PCKEV_D4_UB(...) PCKEV_D4(v16u8, __VA_ARGS__)
  1603. /* Description : Each byte element is logically xor'ed with immediate 128
  1604. Arguments : Inputs - in0, in1
  1605. Outputs - in0, in1 (in-place)
  1606. Return Type - as per RTYPE
  1607. Details : Each unsigned byte element from input vector 'in0' is
  1608. logically xor'ed with 128 and result is in-place stored in
  1609. 'in0' vector
  1610. Each unsigned byte element from input vector 'in1' is
  1611. logically xor'ed with 128 and result is in-place stored in
  1612. 'in1' vector
  1613. Similar for other pairs
  1614. */
  1615. #define XORI_B2_128(RTYPE, in0, in1) \
  1616. { \
  1617. in0 = (RTYPE) __msa_xori_b((v16u8) in0, 128); \
  1618. in1 = (RTYPE) __msa_xori_b((v16u8) in1, 128); \
  1619. }
  1620. #define XORI_B2_128_UB(...) XORI_B2_128(v16u8, __VA_ARGS__)
  1621. #define XORI_B2_128_SB(...) XORI_B2_128(v16i8, __VA_ARGS__)
  1622. #define XORI_B2_128_SH(...) XORI_B2_128(v8i16, __VA_ARGS__)
  1623. #define XORI_B3_128(RTYPE, in0, in1, in2) \
  1624. { \
  1625. XORI_B2_128(RTYPE, in0, in1); \
  1626. in2 = (RTYPE) __msa_xori_b((v16u8) in2, 128); \
  1627. }
  1628. #define XORI_B3_128_SB(...) XORI_B3_128(v16i8, __VA_ARGS__)
  1629. #define XORI_B4_128(RTYPE, in0, in1, in2, in3) \
  1630. { \
  1631. XORI_B2_128(RTYPE, in0, in1); \
  1632. XORI_B2_128(RTYPE, in2, in3); \
  1633. }
  1634. #define XORI_B4_128_UB(...) XORI_B4_128(v16u8, __VA_ARGS__)
  1635. #define XORI_B4_128_SB(...) XORI_B4_128(v16i8, __VA_ARGS__)
  1636. #define XORI_B4_128_SH(...) XORI_B4_128(v8i16, __VA_ARGS__)
  1637. #define XORI_B5_128(RTYPE, in0, in1, in2, in3, in4) \
  1638. { \
  1639. XORI_B3_128(RTYPE, in0, in1, in2); \
  1640. XORI_B2_128(RTYPE, in3, in4); \
  1641. }
  1642. #define XORI_B5_128_SB(...) XORI_B5_128(v16i8, __VA_ARGS__)
  1643. #define XORI_B6_128(RTYPE, in0, in1, in2, in3, in4, in5) \
  1644. { \
  1645. XORI_B4_128(RTYPE, in0, in1, in2, in3); \
  1646. XORI_B2_128(RTYPE, in4, in5); \
  1647. }
  1648. #define XORI_B6_128_SB(...) XORI_B6_128(v16i8, __VA_ARGS__)
  1649. #define XORI_B7_128(RTYPE, in0, in1, in2, in3, in4, in5, in6) \
  1650. { \
  1651. XORI_B4_128(RTYPE, in0, in1, in2, in3); \
  1652. XORI_B3_128(RTYPE, in4, in5, in6); \
  1653. }
  1654. #define XORI_B7_128_SB(...) XORI_B7_128(v16i8, __VA_ARGS__)
  1655. #define XORI_B8_128(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7) \
  1656. { \
  1657. XORI_B4_128(RTYPE, in0, in1, in2, in3); \
  1658. XORI_B4_128(RTYPE, in4, in5, in6, in7); \
  1659. }
  1660. #define XORI_B8_128_SB(...) XORI_B8_128(v16i8, __VA_ARGS__)
  1661. /* Description : Addition of signed halfword elements and signed saturation
  1662. Arguments : Inputs - in0, in1, in2, in3
  1663. Outputs - out0, out1
  1664. Return Type - as per RTYPE
  1665. Details : Signed halfword elements from 'in0' are added to signed
  1666. halfword elements of 'in1'. The result is then signed saturated
  1667. between -32768 to +32767 (as per halfword data type)
  1668. Similar for other pairs
  1669. */
  1670. #define ADDS_SH2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1671. { \
  1672. out0 = (RTYPE) __msa_adds_s_h((v8i16) in0, (v8i16) in1); \
  1673. out1 = (RTYPE) __msa_adds_s_h((v8i16) in2, (v8i16) in3); \
  1674. }
  1675. #define ADDS_SH2_SH(...) ADDS_SH2(v8i16, __VA_ARGS__)
  1676. #define ADDS_SH4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1677. out0, out1, out2, out3) \
  1678. { \
  1679. ADDS_SH2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1680. ADDS_SH2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1681. }
  1682. #define ADDS_SH4_UH(...) ADDS_SH4(v8u16, __VA_ARGS__)
  1683. #define ADDS_SH4_SH(...) ADDS_SH4(v8i16, __VA_ARGS__)
  1684. /* Description : Shift left all elements of vector (generic for all data types)
  1685. Arguments : Inputs - in0, in1, in2, in3, shift
  1686. Outputs - in0, in1, in2, in3 (in place)
  1687. Return Type - as per input vector RTYPE
  1688. Details : Each element of vector 'in0' is left shifted by 'shift' and
  1689. result is in place written to 'in0'
  1690. Similar for other pairs
  1691. */
  1692. #define SLLI_4V(in0, in1, in2, in3, shift) \
  1693. { \
  1694. in0 = in0 << shift; \
  1695. in1 = in1 << shift; \
  1696. in2 = in2 << shift; \
  1697. in3 = in3 << shift; \
  1698. }
  1699. /* Description : Arithmetic shift right all elements of vector
  1700. (generic for all data types)
  1701. Arguments : Inputs - in0, in1, in2, in3, shift
  1702. Outputs - in0, in1, in2, in3 (in place)
  1703. Return Type - as per input vector RTYPE
  1704. Details : Each element of vector 'in0' is right shifted by 'shift' and
  1705. result is in place written to 'in0'
  1706. Here, 'shift' is GP variable passed in
  1707. Similar for other pairs
  1708. */
  1709. #define SRA_4V(in0, in1, in2, in3, shift) \
  1710. { \
  1711. in0 = in0 >> shift; \
  1712. in1 = in1 >> shift; \
  1713. in2 = in2 >> shift; \
  1714. in3 = in3 >> shift; \
  1715. }
  1716. /* Description : Shift right logical all halfword elements of vector
  1717. Arguments : Inputs - in0, in1, in2, in3, shift
  1718. Outputs - in0, in1, in2, in3 (in place)
  1719. Return Type - unsigned halfword
  1720. Details : Each element of vector 'in0' is shifted right logical by
  1721. number of bits respective element holds in vector 'shift' and
  1722. result is in place written to 'in0'
  1723. Here, 'shift' is a vector passed in
  1724. Similar for other pairs
  1725. */
  1726. #define SRL_H4(RTYPE, in0, in1, in2, in3, shift) \
  1727. { \
  1728. in0 = (RTYPE) __msa_srl_h((v8i16) in0, (v8i16) shift); \
  1729. in1 = (RTYPE) __msa_srl_h((v8i16) in1, (v8i16) shift); \
  1730. in2 = (RTYPE) __msa_srl_h((v8i16) in2, (v8i16) shift); \
  1731. in3 = (RTYPE) __msa_srl_h((v8i16) in3, (v8i16) shift); \
  1732. }
  1733. #define SRL_H4_UH(...) SRL_H4(v8u16, __VA_ARGS__)
  1734. /* Description : Shift right arithmetic rounded halfwords
  1735. Arguments : Inputs - in0, in1, shift
  1736. Outputs - in0, in1, (in place)
  1737. Return Type - unsigned halfword
  1738. Details : Each element of vector 'in0' is shifted right arithmetic by
  1739. number of bits respective element holds in vector 'shift'.
  1740. The last discarded bit is added to shifted value for rounding
  1741. and the result is in place written to 'in0'
  1742. Here, 'shift' is a vector passed in
  1743. Similar for other pairs
  1744. */
  1745. #define SRAR_H2(RTYPE, in0, in1, shift) \
  1746. { \
  1747. in0 = (RTYPE) __msa_srar_h((v8i16) in0, (v8i16) shift); \
  1748. in1 = (RTYPE) __msa_srar_h((v8i16) in1, (v8i16) shift); \
  1749. }
  1750. #define SRAR_H2_UH(...) SRAR_H2(v8u16, __VA_ARGS__)
  1751. #define SRAR_H2_SH(...) SRAR_H2(v8i16, __VA_ARGS__)
  1752. #define SRAR_H3(RTYPE, in0, in1, in2, shift) \
  1753. { \
  1754. SRAR_H2(RTYPE, in0, in1, shift) \
  1755. in2 = (RTYPE) __msa_srar_h((v8i16) in2, (v8i16) shift); \
  1756. }
  1757. #define SRAR_H3_SH(...) SRAR_H3(v8i16, __VA_ARGS__)
  1758. #define SRAR_H4(RTYPE, in0, in1, in2, in3, shift) \
  1759. { \
  1760. SRAR_H2(RTYPE, in0, in1, shift) \
  1761. SRAR_H2(RTYPE, in2, in3, shift) \
  1762. }
  1763. #define SRAR_H4_UH(...) SRAR_H4(v8u16, __VA_ARGS__)
  1764. #define SRAR_H4_SH(...) SRAR_H4(v8i16, __VA_ARGS__)
  1765. /* Description : Shift right arithmetic rounded words
  1766. Arguments : Inputs - in0, in1, shift
  1767. Outputs - in0, in1, (in place)
  1768. Return Type - as per RTYPE
  1769. Details : Each element of vector 'in0' is shifted right arithmetic by
  1770. number of bits respective element holds in vector 'shift'.
  1771. The last discarded bit is added to shifted value for rounding
  1772. and the result is in place written to 'in0'
  1773. Here, 'shift' is a vector passed in
  1774. Similar for other pairs
  1775. */
  1776. #define SRAR_W2(RTYPE, in0, in1, shift) \
  1777. { \
  1778. in0 = (RTYPE) __msa_srar_w((v4i32) in0, (v4i32) shift); \
  1779. in1 = (RTYPE) __msa_srar_w((v4i32) in1, (v4i32) shift); \
  1780. }
  1781. #define SRAR_W2_SW(...) SRAR_W2(v4i32, __VA_ARGS__)
  1782. #define SRAR_W4(RTYPE, in0, in1, in2, in3, shift) \
  1783. { \
  1784. SRAR_W2(RTYPE, in0, in1, shift) \
  1785. SRAR_W2(RTYPE, in2, in3, shift) \
  1786. }
  1787. #define SRAR_W4_SW(...) SRAR_W4(v4i32, __VA_ARGS__)
  1788. /* Description : Shift right arithmetic rounded (immediate)
  1789. Arguments : Inputs - in0, in1, in2, in3, shift
  1790. Outputs - in0, in1, in2, in3 (in place)
  1791. Return Type - as per RTYPE
  1792. Details : Each element of vector 'in0' is shifted right arithmetic by
  1793. value in 'shift'.
  1794. The last discarded bit is added to shifted value for rounding
  1795. and the result is in place written to 'in0'
  1796. Similar for other pairs
  1797. */
  1798. #define SRARI_H2(RTYPE, in0, in1, shift) \
  1799. { \
  1800. in0 = (RTYPE) __msa_srari_h((v8i16) in0, shift); \
  1801. in1 = (RTYPE) __msa_srari_h((v8i16) in1, shift); \
  1802. }
  1803. #define SRARI_H2_UH(...) SRARI_H2(v8u16, __VA_ARGS__)
  1804. #define SRARI_H2_SH(...) SRARI_H2(v8i16, __VA_ARGS__)
  1805. #define SRARI_H4(RTYPE, in0, in1, in2, in3, shift) \
  1806. { \
  1807. SRARI_H2(RTYPE, in0, in1, shift); \
  1808. SRARI_H2(RTYPE, in2, in3, shift); \
  1809. }
  1810. #define SRARI_H4_UH(...) SRARI_H4(v8u16, __VA_ARGS__)
  1811. #define SRARI_H4_SH(...) SRARI_H4(v8i16, __VA_ARGS__)
  1812. /* Description : Shift right arithmetic rounded (immediate)
  1813. Arguments : Inputs - in0, in1, shift
  1814. Outputs - in0, in1 (in place)
  1815. Return Type - as per RTYPE
  1816. Details : Each element of vector 'in0' is shifted right arithmetic by
  1817. value in 'shift'.
  1818. The last discarded bit is added to shifted value for rounding
  1819. and the result is in place written to 'in0'
  1820. Similar for other pairs
  1821. */
  1822. #define SRARI_W2(RTYPE, in0, in1, shift) \
  1823. { \
  1824. in0 = (RTYPE) __msa_srari_w((v4i32) in0, shift); \
  1825. in1 = (RTYPE) __msa_srari_w((v4i32) in1, shift); \
  1826. }
  1827. #define SRARI_W2_SW(...) SRARI_W2(v4i32, __VA_ARGS__)
  1828. #define SRARI_W4(RTYPE, in0, in1, in2, in3, shift) \
  1829. { \
  1830. SRARI_W2(RTYPE, in0, in1, shift); \
  1831. SRARI_W2(RTYPE, in2, in3, shift); \
  1832. }
  1833. #define SRARI_W4_SH(...) SRARI_W4(v8i16, __VA_ARGS__)
  1834. #define SRARI_W4_SW(...) SRARI_W4(v4i32, __VA_ARGS__)
  1835. /* Description : Multiplication of pairs of vectors
  1836. Arguments : Inputs - in0, in1, in2, in3
  1837. Outputs - out0, out1
  1838. Details : Each element from 'in0' is multiplied with elements from 'in1'
  1839. and result is written to 'out0'
  1840. Similar for other pairs
  1841. */
  1842. #define MUL2(in0, in1, in2, in3, out0, out1) \
  1843. { \
  1844. out0 = in0 * in1; \
  1845. out1 = in2 * in3; \
  1846. }
  1847. #define MUL4(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, out3) \
  1848. { \
  1849. MUL2(in0, in1, in2, in3, out0, out1); \
  1850. MUL2(in4, in5, in6, in7, out2, out3); \
  1851. }
  1852. /* Description : Addition of 2 pairs of vectors
  1853. Arguments : Inputs - in0, in1, in2, in3
  1854. Outputs - out0, out1
  1855. Details : Each element from 2 pairs vectors is added and 2 results are
  1856. produced
  1857. */
  1858. #define ADD2(in0, in1, in2, in3, out0, out1) \
  1859. { \
  1860. out0 = in0 + in1; \
  1861. out1 = in2 + in3; \
  1862. }
  1863. #define ADD4(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, out3) \
  1864. { \
  1865. ADD2(in0, in1, in2, in3, out0, out1); \
  1866. ADD2(in4, in5, in6, in7, out2, out3); \
  1867. }
  1868. /* Description : Subtraction of 2 pairs of vectors
  1869. Arguments : Inputs - in0, in1, in2, in3
  1870. Outputs - out0, out1
  1871. Details : Each element from 2 pairs vectors is subtracted and 2 results
  1872. are produced
  1873. */
  1874. #define SUB2(in0, in1, in2, in3, out0, out1) \
  1875. { \
  1876. out0 = in0 - in1; \
  1877. out1 = in2 - in3; \
  1878. }
  1879. /* Description : Sign extend byte elements from input vector and return
  1880. halfword results in pair of vectors
  1881. Arguments : Inputs - in (1 input byte vector)
  1882. Outputs - out0, out1 (sign extended 2 halfword vectors)
  1883. Return Type - signed halfword
  1884. Details : Sign bit of byte elements from input vector 'in' is
  1885. extracted and interleaved right with same vector 'in0' to
  1886. generate 8 signed halfword elements in 'out0'
  1887. Then interleaved left with same vector 'in0' to
  1888. generate 8 signed halfword elements in 'out1'
  1889. */
  1890. #define UNPCK_SB_SH(in, out0, out1) \
  1891. { \
  1892. v16i8 tmp_m; \
  1893. \
  1894. tmp_m = __msa_clti_s_b((v16i8) in, 0); \
  1895. ILVRL_B2_SH(tmp_m, in, out0, out1); \
  1896. }
  1897. /* Description : Zero extend unsigned byte elements to halfword elements
  1898. Arguments : Inputs - in (1 input unsigned byte vector)
  1899. Outputs - out0, out1 (unsigned 2 halfword vectors)
  1900. Return Type - signed halfword
  1901. Details : Zero extended right half of vector is returned in 'out0'
  1902. Zero extended left half of vector is returned in 'out1'
  1903. */
  1904. #define UNPCK_UB_SH(in, out0, out1) \
  1905. { \
  1906. v16i8 zero_m = { 0 }; \
  1907. \
  1908. ILVRL_B2_SH(zero_m, in, out0, out1); \
  1909. }
  1910. /* Description : Sign extend halfword elements from input vector and return
  1911. result in pair of vectors
  1912. Arguments : Inputs - in (1 input halfword vector)
  1913. Outputs - out0, out1 (sign extended 2 word vectors)
  1914. Return Type - signed word
  1915. Details : Sign bit of halfword elements from input vector 'in' is
  1916. extracted and interleaved right with same vector 'in0' to
  1917. generate 4 signed word elements in 'out0'
  1918. Then interleaved left with same vector 'in0' to
  1919. generate 4 signed word elements in 'out1'
  1920. */
  1921. #define UNPCK_SH_SW(in, out0, out1) \
  1922. { \
  1923. v8i16 tmp_m; \
  1924. \
  1925. tmp_m = __msa_clti_s_h((v8i16) in, 0); \
  1926. ILVRL_H2_SW(tmp_m, in, out0, out1); \
  1927. }
  1928. /* Description : Swap two variables
  1929. Arguments : Inputs - in0, in1
  1930. Outputs - in0, in1 (in-place)
  1931. Details : Swapping of two input variables using xor
  1932. */
  1933. #define SWAP(in0, in1) \
  1934. { \
  1935. in0 = in0 ^ in1; \
  1936. in1 = in0 ^ in1; \
  1937. in0 = in0 ^ in1; \
  1938. }
  1939. /* Description : Butterfly of 4 input vectors
  1940. Arguments : Inputs - in0, in1, in2, in3
  1941. Outputs - out0, out1, out2, out3
  1942. Details : Butterfly operation
  1943. */
  1944. #define BUTTERFLY_4(in0, in1, in2, in3, out0, out1, out2, out3) \
  1945. { \
  1946. out0 = in0 + in3; \
  1947. out1 = in1 + in2; \
  1948. \
  1949. out2 = in1 - in2; \
  1950. out3 = in0 - in3; \
  1951. }
  1952. /* Description : Transposes input 4x4 byte block
  1953. Arguments : Inputs - in0, in1, in2, in3 (input 4x4 byte block)
  1954. Outputs - out0, out1, out2, out3 (output 4x4 byte block)
  1955. Return Type - unsigned byte
  1956. Details :
  1957. */
  1958. #define TRANSPOSE4x4_UB_UB(in0, in1, in2, in3, out0, out1, out2, out3) \
  1959. { \
  1960. v16i8 zero_m = { 0 }; \
  1961. v16i8 s0_m, s1_m, s2_m, s3_m; \
  1962. \
  1963. ILVR_D2_SB(in1, in0, in3, in2, s0_m, s1_m); \
  1964. ILVRL_B2_SB(s1_m, s0_m, s2_m, s3_m); \
  1965. \
  1966. out0 = (v16u8) __msa_ilvr_b(s3_m, s2_m); \
  1967. out1 = (v16u8) __msa_sldi_b(zero_m, (v16i8) out0, 4); \
  1968. out2 = (v16u8) __msa_sldi_b(zero_m, (v16i8) out1, 4); \
  1969. out3 = (v16u8) __msa_sldi_b(zero_m, (v16i8) out2, 4); \
  1970. }
  1971. /* Description : Transposes input 8x4 byte block into 4x8
  1972. Arguments : Inputs - in0, in1, in2, in3 (input 8x4 byte block)
  1973. Outputs - out0, out1, out2, out3 (output 4x8 byte block)
  1974. Return Type - unsigned byte
  1975. Details :
  1976. */
  1977. #define TRANSPOSE8x4_UB(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1978. out0, out1, out2, out3) \
  1979. { \
  1980. v16i8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  1981. \
  1982. ILVEV_W2_SB(in0, in4, in1, in5, tmp0_m, tmp1_m); \
  1983. tmp2_m = __msa_ilvr_b(tmp1_m, tmp0_m); \
  1984. ILVEV_W2_SB(in2, in6, in3, in7, tmp0_m, tmp1_m); \
  1985. \
  1986. tmp3_m = __msa_ilvr_b(tmp1_m, tmp0_m); \
  1987. ILVRL_H2_SB(tmp3_m, tmp2_m, tmp0_m, tmp1_m); \
  1988. \
  1989. ILVRL_W2(RTYPE, tmp1_m, tmp0_m, out0, out2); \
  1990. out1 = (RTYPE) __msa_ilvl_d((v2i64) out2, (v2i64) out0); \
  1991. out3 = (RTYPE) __msa_ilvl_d((v2i64) out0, (v2i64) out2); \
  1992. }
  1993. #define TRANSPOSE8x4_UB_UB(...) TRANSPOSE8x4_UB(v16u8, __VA_ARGS__)
  1994. #define TRANSPOSE8x4_UB_UH(...) TRANSPOSE8x4_UB(v8u16, __VA_ARGS__)
  1995. /* Description : Transposes input 8x8 byte block
  1996. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1997. (input 8x8 byte block)
  1998. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  1999. (output 8x8 byte block)
  2000. Return Type - unsigned byte
  2001. Details :
  2002. */
  2003. #define TRANSPOSE8x8_UB(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  2004. out0, out1, out2, out3, out4, out5, out6, out7) \
  2005. { \
  2006. v16i8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2007. v16i8 tmp4_m, tmp5_m, tmp6_m, tmp7_m; \
  2008. \
  2009. ILVR_B4_SB(in2, in0, in3, in1, in6, in4, in7, in5, \
  2010. tmp0_m, tmp1_m, tmp2_m, tmp3_m); \
  2011. ILVRL_B2_SB(tmp1_m, tmp0_m, tmp4_m, tmp5_m); \
  2012. ILVRL_B2_SB(tmp3_m, tmp2_m, tmp6_m, tmp7_m); \
  2013. ILVRL_W2(RTYPE, tmp6_m, tmp4_m, out0, out2); \
  2014. ILVRL_W2(RTYPE, tmp7_m, tmp5_m, out4, out6); \
  2015. SLDI_B2_0(RTYPE, out0, out2, out1, out3, 8); \
  2016. SLDI_B2_0(RTYPE, out4, out6, out5, out7, 8); \
  2017. }
  2018. #define TRANSPOSE8x8_UB_UB(...) TRANSPOSE8x8_UB(v16u8, __VA_ARGS__)
  2019. #define TRANSPOSE8x8_UB_UH(...) TRANSPOSE8x8_UB(v8u16, __VA_ARGS__)
  2020. /* Description : Transposes 16x8 block into 8x16 with byte elements in vectors
  2021. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7,
  2022. in8, in9, in10, in11, in12, in13, in14, in15
  2023. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  2024. Return Type - unsigned byte
  2025. Details :
  2026. */
  2027. #define TRANSPOSE16x8_UB_UB(in0, in1, in2, in3, in4, in5, in6, in7, \
  2028. in8, in9, in10, in11, in12, in13, in14, in15, \
  2029. out0, out1, out2, out3, out4, out5, out6, out7) \
  2030. { \
  2031. v16u8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2032. v16u8 tmp4_m, tmp5_m, tmp6_m, tmp7_m; \
  2033. \
  2034. ILVEV_D2_UB(in0, in8, in1, in9, out7, out6); \
  2035. ILVEV_D2_UB(in2, in10, in3, in11, out5, out4); \
  2036. ILVEV_D2_UB(in4, in12, in5, in13, out3, out2); \
  2037. ILVEV_D2_UB(in6, in14, in7, in15, out1, out0); \
  2038. \
  2039. tmp0_m = (v16u8) __msa_ilvev_b((v16i8) out6, (v16i8) out7); \
  2040. tmp4_m = (v16u8) __msa_ilvod_b((v16i8) out6, (v16i8) out7); \
  2041. tmp1_m = (v16u8) __msa_ilvev_b((v16i8) out4, (v16i8) out5); \
  2042. tmp5_m = (v16u8) __msa_ilvod_b((v16i8) out4, (v16i8) out5); \
  2043. out5 = (v16u8) __msa_ilvev_b((v16i8) out2, (v16i8) out3); \
  2044. tmp6_m = (v16u8) __msa_ilvod_b((v16i8) out2, (v16i8) out3); \
  2045. out7 = (v16u8) __msa_ilvev_b((v16i8) out0, (v16i8) out1); \
  2046. tmp7_m = (v16u8) __msa_ilvod_b((v16i8) out0, (v16i8) out1); \
  2047. \
  2048. ILVEV_H2_UB(tmp0_m, tmp1_m, out5, out7, tmp2_m, tmp3_m); \
  2049. out0 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2050. out4 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2051. \
  2052. tmp2_m = (v16u8) __msa_ilvod_h((v8i16) tmp1_m, (v8i16) tmp0_m); \
  2053. tmp3_m = (v16u8) __msa_ilvod_h((v8i16) out7, (v8i16) out5); \
  2054. out2 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2055. out6 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2056. \
  2057. ILVEV_H2_UB(tmp4_m, tmp5_m, tmp6_m, tmp7_m, tmp2_m, tmp3_m); \
  2058. out1 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2059. out5 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2060. \
  2061. tmp2_m = (v16u8) __msa_ilvod_h((v8i16) tmp5_m, (v8i16) tmp4_m); \
  2062. tmp2_m = (v16u8) __msa_ilvod_h((v8i16) tmp5_m, (v8i16) tmp4_m); \
  2063. tmp3_m = (v16u8) __msa_ilvod_h((v8i16) tmp7_m, (v8i16) tmp6_m); \
  2064. tmp3_m = (v16u8) __msa_ilvod_h((v8i16) tmp7_m, (v8i16) tmp6_m); \
  2065. out3 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2066. out7 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  2067. }
  2068. /* Description : Transposes 8x8 block with half word elements in vectors
  2069. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  2070. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  2071. Return Type - signed halfword
  2072. Details :
  2073. */
  2074. #define TRANSPOSE8x8_H(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  2075. out0, out1, out2, out3, out4, out5, out6, out7) \
  2076. { \
  2077. v8i16 s0_m, s1_m; \
  2078. v8i16 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  2079. v8i16 tmp4_m, tmp5_m, tmp6_m, tmp7_m; \
  2080. \
  2081. ILVR_H2_SH(in6, in4, in7, in5, s0_m, s1_m); \
  2082. ILVRL_H2_SH(s1_m, s0_m, tmp0_m, tmp1_m); \
  2083. ILVL_H2_SH(in6, in4, in7, in5, s0_m, s1_m); \
  2084. ILVRL_H2_SH(s1_m, s0_m, tmp2_m, tmp3_m); \
  2085. ILVR_H2_SH(in2, in0, in3, in1, s0_m, s1_m); \
  2086. ILVRL_H2_SH(s1_m, s0_m, tmp4_m, tmp5_m); \
  2087. ILVL_H2_SH(in2, in0, in3, in1, s0_m, s1_m); \
  2088. ILVRL_H2_SH(s1_m, s0_m, tmp6_m, tmp7_m); \
  2089. PCKEV_D4(RTYPE, tmp0_m, tmp4_m, tmp1_m, tmp5_m, tmp2_m, tmp6_m, \
  2090. tmp3_m, tmp7_m, out0, out2, out4, out6); \
  2091. out1 = (RTYPE) __msa_pckod_d((v2i64) tmp0_m, (v2i64) tmp4_m); \
  2092. out3 = (RTYPE) __msa_pckod_d((v2i64) tmp1_m, (v2i64) tmp5_m); \
  2093. out5 = (RTYPE) __msa_pckod_d((v2i64) tmp2_m, (v2i64) tmp6_m); \
  2094. out7 = (RTYPE) __msa_pckod_d((v2i64) tmp3_m, (v2i64) tmp7_m); \
  2095. }
  2096. #define TRANSPOSE8x8_UH_UH(...) TRANSPOSE8x8_H(v8u16, __VA_ARGS__)
  2097. #define TRANSPOSE8x8_SH_SH(...) TRANSPOSE8x8_H(v8i16, __VA_ARGS__)
  2098. /* Description : Transposes 4x4 block with word elements in vectors
  2099. Arguments : Inputs - in0, in1, in2, in3
  2100. Outputs - out0, out1, out2, out3
  2101. Return Type - signed word
  2102. Details :
  2103. */
  2104. #define TRANSPOSE4x4_SW_SW(in0, in1, in2, in3, out0, out1, out2, out3) \
  2105. { \
  2106. v4i32 s0_m, s1_m, s2_m, s3_m; \
  2107. \
  2108. ILVRL_W2_SW(in1, in0, s0_m, s1_m); \
  2109. ILVRL_W2_SW(in3, in2, s2_m, s3_m); \
  2110. \
  2111. out0 = (v4i32) __msa_ilvr_d((v2i64) s2_m, (v2i64) s0_m); \
  2112. out1 = (v4i32) __msa_ilvl_d((v2i64) s2_m, (v2i64) s0_m); \
  2113. out2 = (v4i32) __msa_ilvr_d((v2i64) s3_m, (v2i64) s1_m); \
  2114. out3 = (v4i32) __msa_ilvl_d((v2i64) s3_m, (v2i64) s1_m); \
  2115. }
  2116. /* Description : Pack even elements of input vectors & xor with 128
  2117. Arguments : Inputs - in0, in1
  2118. Outputs - out_m
  2119. Return Type - unsigned byte
  2120. Details : Signed byte even elements from 'in0' and 'in1' are packed
  2121. together in one vector and the resulted vector is xor'ed with
  2122. 128 to shift the range from signed to unsigned byte
  2123. */
  2124. #define PCKEV_XORI128_UB(in0, in1) \
  2125. ( { \
  2126. v16u8 out_m; \
  2127. out_m = (v16u8) __msa_pckev_b((v16i8) in1, (v16i8) in0); \
  2128. out_m = (v16u8) __msa_xori_b((v16u8) out_m, 128); \
  2129. out_m; \
  2130. } )
  2131. /* Description : Pack even byte elements, extract 0 & 2 index words from pair
  2132. of results and store 4 words in destination memory as per
  2133. stride
  2134. Arguments : Inputs - in0, in1, in2, in3, pdst, stride
  2135. */
  2136. #define PCKEV_ST4x4_UB(in0, in1, in2, in3, pdst, stride) \
  2137. { \
  2138. uint32_t out0_m, out1_m, out2_m, out3_m; \
  2139. v16i8 tmp0_m, tmp1_m; \
  2140. \
  2141. PCKEV_B2_SB(in1, in0, in3, in2, tmp0_m, tmp1_m); \
  2142. \
  2143. out0_m = __msa_copy_u_w((v4i32) tmp0_m, 0); \
  2144. out1_m = __msa_copy_u_w((v4i32) tmp0_m, 2); \
  2145. out2_m = __msa_copy_u_w((v4i32) tmp1_m, 0); \
  2146. out3_m = __msa_copy_u_w((v4i32) tmp1_m, 2); \
  2147. \
  2148. SW4(out0_m, out1_m, out2_m, out3_m, pdst, stride); \
  2149. }
  2150. /* Description : Pack even byte elements and store byte vector in destination
  2151. memory
  2152. Arguments : Inputs - in0, in1, pdst
  2153. */
  2154. #define PCKEV_ST_SB(in0, in1, pdst) \
  2155. { \
  2156. v16i8 tmp_m; \
  2157. tmp_m = __msa_pckev_b((v16i8) in1, (v16i8) in0); \
  2158. ST_SB(tmp_m, (pdst)); \
  2159. }
  2160. #endif /* AVUTIL_MIPS_GENERIC_MACROS_MSA_H */