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.

2100 lines
101KB

  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 : Immediate number of columns to slide with zero
  700. Arguments : Inputs - in0, in1, slide_val
  701. Outputs - out0, out1
  702. Return Type - as per RTYPE
  703. Details : Byte elements from 'zero_m' vector are slide into 'in0' by
  704. number of elements specified by 'slide_val'
  705. */
  706. #define SLDI_B2_0(RTYPE, in0, in1, out0, out1, slide_val) \
  707. { \
  708. v16i8 zero_m = { 0 }; \
  709. out0 = (RTYPE) __msa_sldi_b((v16i8) zero_m, (v16i8) in0, slide_val); \
  710. out1 = (RTYPE) __msa_sldi_b((v16i8) zero_m, (v16i8) in1, slide_val); \
  711. }
  712. #define SLDI_B2_0_UB(...) SLDI_B2_0(v16u8, __VA_ARGS__)
  713. #define SLDI_B4_0(RTYPE, in0, in1, in2, in3, \
  714. out0, out1, out2, out3, slide_val) \
  715. { \
  716. SLDI_B2_0(RTYPE, in0, in1, out0, out1, slide_val); \
  717. SLDI_B2_0(RTYPE, in2, in3, out2, out3, slide_val); \
  718. }
  719. #define SLDI_B4_0_SB(...) SLDI_B4_0(v16i8, __VA_ARGS__)
  720. /* Description : Immediate number of columns to slide
  721. Arguments : Inputs - in0_0, in0_1, in1_0, in1_1, slide_val
  722. Outputs - out0, out1
  723. Return Type - as per RTYPE
  724. Details : Byte elements from 'in0_0' vector are slide into 'in1_0' by
  725. number of elements specified by 'slide_val'
  726. */
  727. #define SLDI_B2(RTYPE, in0_0, in0_1, in1_0, in1_1, out0, out1, slide_val) \
  728. { \
  729. out0 = (RTYPE) __msa_sldi_b((v16i8) in0_0, (v16i8) in1_0, slide_val); \
  730. out1 = (RTYPE) __msa_sldi_b((v16i8) in0_1, (v16i8) in1_1, slide_val); \
  731. }
  732. #define SLDI_B2_UB(...) SLDI_B2(v16u8, __VA_ARGS__)
  733. #define SLDI_B2_SB(...) SLDI_B2(v16i8, __VA_ARGS__)
  734. #define SLDI_B2_SH(...) SLDI_B2(v8i16, __VA_ARGS__)
  735. /* Description : Shuffle byte vector elements as per mask vector
  736. Arguments : Inputs - in0, in1, in2, in3, mask0, mask1
  737. Outputs - out0, out1
  738. Return Type - as per RTYPE
  739. Details : Selective byte elements from in0 & in1 are copied to out0 as
  740. per control vector mask0
  741. Selective byte elements from in2 & in3 are copied to out1 as
  742. per control vector mask1
  743. */
  744. #define VSHF_B2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1) \
  745. { \
  746. out0 = (RTYPE) __msa_vshf_b((v16i8) mask0, (v16i8) in1, (v16i8) in0); \
  747. out1 = (RTYPE) __msa_vshf_b((v16i8) mask1, (v16i8) in3, (v16i8) in2); \
  748. }
  749. #define VSHF_B2_UB(...) VSHF_B2(v16u8, __VA_ARGS__)
  750. #define VSHF_B2_SB(...) VSHF_B2(v16i8, __VA_ARGS__)
  751. #define VSHF_B2_UH(...) VSHF_B2(v8u16, __VA_ARGS__)
  752. #define VSHF_B2_SH(...) VSHF_B2(v8i16, __VA_ARGS__)
  753. #define VSHF_B3(RTYPE, in0, in1, in2, in3, in4, in5, mask0, mask1, mask2, \
  754. out0, out1, out2) \
  755. { \
  756. VSHF_B2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1); \
  757. out2 = (RTYPE) __msa_vshf_b((v16i8) mask2, (v16i8) in5, (v16i8) in4); \
  758. }
  759. #define VSHF_B3_SB(...) VSHF_B3(v16i8, __VA_ARGS__)
  760. #define VSHF_B4(RTYPE, in0, in1, mask0, mask1, mask2, mask3, \
  761. out0, out1, out2, out3) \
  762. { \
  763. VSHF_B2(RTYPE, in0, in1, in0, in1, mask0, mask1, out0, out1); \
  764. VSHF_B2(RTYPE, in0, in1, in0, in1, mask2, mask3, out2, out3); \
  765. }
  766. #define VSHF_B4_SB(...) VSHF_B4(v16i8, __VA_ARGS__)
  767. /* Description : Shuffle byte vector elements as per mask vector
  768. Arguments : Inputs - in0, in1, in2, in3, mask0, mask1
  769. Outputs - out0, out1
  770. Return Type - as per RTYPE
  771. Details : Selective byte elements from in0 & in1 are copied to out0 as
  772. per control vector mask0
  773. Selective byte elements from in2 & in3 are copied to out1 as
  774. per control vector mask1
  775. */
  776. #define VSHF_W2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1) \
  777. { \
  778. out0 = (RTYPE) __msa_vshf_w((v4i32) mask0, (v4i32) in1, (v4i32) in0); \
  779. out1 = (RTYPE) __msa_vshf_w((v4i32) mask1, (v4i32) in3, (v4i32) in2); \
  780. }
  781. #define VSHF_W2_SB(...) VSHF_W2(v16i8, __VA_ARGS__)
  782. /* Description : Dot product of byte vector elements
  783. Arguments : Inputs - mult0, mult1
  784. cnst0, cnst1
  785. Outputs - out0, out1
  786. Return Type - signed halfword
  787. Details : Signed byte elements from mult0 are multiplied with
  788. signed byte elements from cnst0 producing a result
  789. twice the size of input i.e. signed halfword.
  790. Then this multiplication results of adjacent odd-even elements
  791. are added together and stored to the out vector
  792. (2 signed halfword results)
  793. */
  794. #define DOTP_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  795. { \
  796. out0 = (RTYPE) __msa_dotp_s_h((v16i8) mult0, (v16i8) cnst0); \
  797. out1 = (RTYPE) __msa_dotp_s_h((v16i8) mult1, (v16i8) cnst1); \
  798. }
  799. #define DOTP_SB2_SH(...) DOTP_SB2(v8i16, __VA_ARGS__)
  800. #define DOTP_SB3(RTYPE, mult0, mult1, mult2, cnst0, cnst1, cnst2, \
  801. out0, out1, out2) \
  802. { \
  803. DOTP_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  804. out2 = (RTYPE) __msa_dotp_s_h((v16i8) mult2, (v16i8) cnst2); \
  805. }
  806. #define DOTP_SB3_SH(...) DOTP_SB3(v8i16, __VA_ARGS__)
  807. #define DOTP_SB4(RTYPE, mult0, mult1, mult2, mult3, \
  808. cnst0, cnst1, cnst2, cnst3, out0, out1, out2, out3) \
  809. { \
  810. DOTP_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  811. DOTP_SB2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  812. }
  813. #define DOTP_SB4_SH(...) DOTP_SB4(v8i16, __VA_ARGS__)
  814. /* Description : Dot product of halfword vector elements
  815. Arguments : Inputs - mult0, mult1
  816. cnst0, cnst1
  817. Outputs - out0, out1
  818. Return Type - signed word
  819. Details : Signed halfword elements from mult0 are multiplied with
  820. signed halfword elements from cnst0 producing a result
  821. twice the size of input i.e. signed word.
  822. Then this multiplication results of adjacent odd-even elements
  823. are added together and stored to the out vector
  824. (2 signed word results)
  825. */
  826. #define DOTP_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  827. { \
  828. out0 = (RTYPE) __msa_dotp_s_w((v8i16) mult0, (v8i16) cnst0); \
  829. out1 = (RTYPE) __msa_dotp_s_w((v8i16) mult1, (v8i16) cnst1); \
  830. }
  831. #define DOTP_SH2_SW(...) DOTP_SH2(v4i32, __VA_ARGS__)
  832. #define DOTP_SH4(RTYPE, mult0, mult1, mult2, mult3, \
  833. cnst0, cnst1, cnst2, cnst3, \
  834. out0, out1, out2, out3) \
  835. { \
  836. DOTP_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  837. DOTP_SH2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  838. }
  839. #define DOTP_SH4_SW(...) DOTP_SH4(v4i32, __VA_ARGS__)
  840. /* Description : Dot product & addition of byte vector elements
  841. Arguments : Inputs - mult0, mult1
  842. cnst0, cnst1
  843. Outputs - out0, out1
  844. Return Type - signed halfword
  845. Details : Signed byte elements from mult0 are multiplied with
  846. signed byte elements from cnst0 producing a result
  847. twice the size of input i.e. signed halfword.
  848. Then this multiplication results of adjacent odd-even elements
  849. are added to the out vector
  850. (2 signed halfword results)
  851. */
  852. #define DPADD_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  853. { \
  854. out0 = (RTYPE) __msa_dpadd_s_h((v8i16) out0, \
  855. (v16i8) mult0, (v16i8) cnst0); \
  856. out1 = (RTYPE) __msa_dpadd_s_h((v8i16) out1, \
  857. (v16i8) mult1, (v16i8) cnst1); \
  858. }
  859. #define DPADD_SB2_SH(...) DPADD_SB2(v8i16, __VA_ARGS__)
  860. #define DPADD_SB4(RTYPE, mult0, mult1, mult2, mult3, \
  861. cnst0, cnst1, cnst2, cnst3, out0, out1, out2, out3) \
  862. { \
  863. DPADD_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  864. DPADD_SB2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  865. }
  866. #define DPADD_SB4_SH(...) DPADD_SB4(v8i16, __VA_ARGS__)
  867. /* Description : Dot product & addition of halfword vector elements
  868. Arguments : Inputs - mult0, mult1
  869. cnst0, cnst1
  870. Outputs - out0, out1
  871. Return Type - signed word
  872. Details : Signed halfword elements from mult0 are multiplied with
  873. signed halfword elements from cnst0 producing a result
  874. twice the size of input i.e. signed word.
  875. Then this multiplication results of adjacent odd-even elements
  876. are added to the out vector
  877. (2 signed word results)
  878. */
  879. #define DPADD_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  880. { \
  881. out0 = (RTYPE) __msa_dpadd_s_w((v4i32) out0, \
  882. (v8i16) mult0, (v8i16) cnst0); \
  883. out1 = (RTYPE) __msa_dpadd_s_w((v4i32) out1, \
  884. (v8i16) mult1, (v8i16) cnst1); \
  885. }
  886. #define DPADD_SH2_SW(...) DPADD_SH2(v4i32, __VA_ARGS__)
  887. #define DPADD_SH4(RTYPE, mult0, mult1, mult2, mult3, \
  888. cnst0, cnst1, cnst2, cnst3, out0, out1, out2, out3) \
  889. { \
  890. DPADD_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  891. DPADD_SH2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  892. }
  893. #define DPADD_SH4_SW(...) DPADD_SH4(v4i32, __VA_ARGS__)
  894. /* Description : Clips all halfword elements of input vector between min & max
  895. out = ((in) < (min)) ? (min) : (((in) > (max)) ? (max) : (in))
  896. Arguments : Inputs - in (input vector)
  897. - min (min threshold)
  898. - max (max threshold)
  899. Outputs - out_m (output vector with clipped elements)
  900. Return Type - signed halfword
  901. */
  902. #define CLIP_SH(in, min, max) \
  903. ( { \
  904. v8i16 out_m; \
  905. \
  906. out_m = __msa_max_s_h((v8i16) min, (v8i16) in); \
  907. out_m = __msa_min_s_h((v8i16) max, (v8i16) out_m); \
  908. out_m; \
  909. } )
  910. /* Description : Clips all signed halfword elements of input vector
  911. between 0 & 255
  912. Arguments : Inputs - in (input vector)
  913. Outputs - out_m (output vector with clipped elements)
  914. Return Type - signed halfword
  915. */
  916. #define CLIP_SH_0_255(in) \
  917. ( { \
  918. v8i16 max_m = __msa_ldi_h(255); \
  919. v8i16 out_m; \
  920. \
  921. out_m = __msa_maxi_s_h((v8i16) in, 0); \
  922. out_m = __msa_min_s_h((v8i16) max_m, (v8i16) out_m); \
  923. out_m; \
  924. } )
  925. #define CLIP_SH2_0_255(in0, in1) \
  926. { \
  927. in0 = CLIP_SH_0_255(in0); \
  928. in1 = CLIP_SH_0_255(in1); \
  929. }
  930. #define CLIP_SH4_0_255(in0, in1, in2, in3) \
  931. { \
  932. CLIP_SH2_0_255(in0, in1); \
  933. CLIP_SH2_0_255(in2, in3); \
  934. }
  935. /* Description : Clips all signed word elements of input vector
  936. between 0 & 255
  937. Arguments : Inputs - in (input vector)
  938. Outputs - out_m (output vector with clipped elements)
  939. Return Type - signed word
  940. */
  941. #define CLIP_SW_0_255(in) \
  942. ( { \
  943. v4i32 max_m = __msa_ldi_w(255); \
  944. v4i32 out_m; \
  945. \
  946. out_m = __msa_maxi_s_w((v4i32) in, 0); \
  947. out_m = __msa_min_s_w((v4i32) max_m, (v4i32) out_m); \
  948. out_m; \
  949. } )
  950. /* Description : Horizontal subtraction of unsigned byte vector elements
  951. Arguments : Inputs - in0, in1
  952. Outputs - out0, out1
  953. Return Type - as per RTYPE
  954. Details : Each unsigned odd byte element from 'in0' is subtracted from
  955. even unsigned byte element from 'in0' (pairwise) and the
  956. halfword result is stored in 'out0'
  957. */
  958. #define HSUB_UB2(RTYPE, in0, in1, out0, out1) \
  959. { \
  960. out0 = (RTYPE) __msa_hsub_u_h((v16u8) in0, (v16u8) in0); \
  961. out1 = (RTYPE) __msa_hsub_u_h((v16u8) in1, (v16u8) in1); \
  962. }
  963. #define HSUB_UB2_UH(...) HSUB_UB2(v8u16, __VA_ARGS__)
  964. #define HSUB_UB2_SH(...) HSUB_UB2(v8i16, __VA_ARGS__)
  965. #define INSERT_W4(RTYPE, in0, in1, in2, in3, out) \
  966. { \
  967. out = (RTYPE) __msa_insert_w((v4i32) out, 0, in0); \
  968. out = (RTYPE) __msa_insert_w((v4i32) out, 1, in1); \
  969. out = (RTYPE) __msa_insert_w((v4i32) out, 2, in2); \
  970. out = (RTYPE) __msa_insert_w((v4i32) out, 3, in3); \
  971. }
  972. #define INSERT_W4_UB(...) INSERT_W4(v16u8, __VA_ARGS__)
  973. #define INSERT_W4_SB(...) INSERT_W4(v16i8, __VA_ARGS__)
  974. #define INSERT_W4_SW(...) INSERT_W4(v4i32, __VA_ARGS__)
  975. /* Description : Insert specified double word elements from input vectors to 1
  976. destination vector
  977. Arguments : Inputs - in0, in1 (2 input vectors)
  978. Outputs - out (output vector)
  979. Return Type - as per RTYPE
  980. */
  981. #define INSERT_D2(RTYPE, in0, in1, out) \
  982. { \
  983. out = (RTYPE) __msa_insert_d((v2i64) out, 0, in0); \
  984. out = (RTYPE) __msa_insert_d((v2i64) out, 1, in1); \
  985. }
  986. #define INSERT_D2_UB(...) INSERT_D2(v16u8, __VA_ARGS__)
  987. #define INSERT_D2_SB(...) INSERT_D2(v16i8, __VA_ARGS__)
  988. #define INSERT_D2_SD(...) INSERT_D2(v2i64, __VA_ARGS__)
  989. /* Description : Interleave even halfword elements from vectors
  990. Arguments : Inputs - in0, in1, in2, in3
  991. Outputs - out0, out1
  992. Return Type - as per RTYPE
  993. Details : Even halfword elements of 'in0' and even halfword
  994. elements of 'in1' are interleaved and copied to 'out0'
  995. Even halfword elements of 'in2' and even halfword
  996. elements of 'in3' are interleaved and copied to 'out1'
  997. */
  998. #define ILVEV_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  999. { \
  1000. out0 = (RTYPE) __msa_ilvev_h((v8i16) in1, (v8i16) in0); \
  1001. out1 = (RTYPE) __msa_ilvev_h((v8i16) in3, (v8i16) in2); \
  1002. }
  1003. #define ILVEV_H2_UB(...) ILVEV_H2(v16u8, __VA_ARGS__)
  1004. /* Description : Interleave even word elements from vectors
  1005. Arguments : Inputs - in0, in1, in2, in3
  1006. Outputs - out0, out1
  1007. Return Type - as per RTYPE
  1008. Details : Even word elements of 'in0' and even word
  1009. elements of 'in1' are interleaved and copied to 'out0'
  1010. Even word elements of 'in2' and even word
  1011. elements of 'in3' are interleaved and copied to 'out1'
  1012. */
  1013. #define ILVEV_W2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1014. { \
  1015. out0 = (RTYPE) __msa_ilvev_w((v4i32) in1, (v4i32) in0); \
  1016. out1 = (RTYPE) __msa_ilvev_w((v4i32) in3, (v4i32) in2); \
  1017. }
  1018. #define ILVEV_W2_SB(...) ILVEV_W2(v16i8, __VA_ARGS__)
  1019. /* Description : Interleave even double word elements from vectors
  1020. Arguments : Inputs - in0, in1, in2, in3
  1021. Outputs - out0, out1
  1022. Return Type - as per RTYPE
  1023. Details : Even double word elements of 'in0' and even double word
  1024. elements of 'in1' are interleaved and copied to 'out0'
  1025. Even double word elements of 'in2' and even double word
  1026. elements of 'in3' are interleaved and copied to 'out1'
  1027. */
  1028. #define ILVEV_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1029. { \
  1030. out0 = (RTYPE) __msa_ilvev_d((v2i64) in1, (v2i64) in0); \
  1031. out1 = (RTYPE) __msa_ilvev_d((v2i64) in3, (v2i64) in2); \
  1032. }
  1033. #define ILVEV_D2_UB(...) ILVEV_D2(v16u8, __VA_ARGS__)
  1034. /* Description : Interleave left half of byte elements from vectors
  1035. Arguments : Inputs - in0, in1, in2, in3
  1036. Outputs - out0, out1
  1037. Return Type - as per RTYPE
  1038. Details : Left half of byte elements of in0 and left half of byte
  1039. elements of in1 are interleaved and copied to out0.
  1040. Left half of byte elements of in2 and left half of byte
  1041. elements of in3 are interleaved and copied to out1.
  1042. */
  1043. #define ILVL_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1044. { \
  1045. out0 = (RTYPE) __msa_ilvl_b((v16i8) in0, (v16i8) in1); \
  1046. out1 = (RTYPE) __msa_ilvl_b((v16i8) in2, (v16i8) in3); \
  1047. }
  1048. #define ILVL_B2_SB(...) ILVL_B2(v16i8, __VA_ARGS__)
  1049. #define ILVL_B2_SH(...) ILVL_B2(v8i16, __VA_ARGS__)
  1050. #define ILVL_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1051. out0, out1, out2, out3) \
  1052. { \
  1053. ILVL_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1054. ILVL_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1055. }
  1056. #define ILVL_B4_SB(...) ILVL_B4(v16i8, __VA_ARGS__)
  1057. #define ILVL_B4_UH(...) ILVL_B4(v8u16, __VA_ARGS__)
  1058. #define ILVL_B4_SH(...) ILVL_B4(v8i16, __VA_ARGS__)
  1059. /* Description : Interleave left half of halfword elements from vectors
  1060. Arguments : Inputs - in0, in1, in2, in3
  1061. Outputs - out0, out1
  1062. Return Type - as per RTYPE
  1063. Details : Left half of halfword elements of in0 and left half of halfword
  1064. elements of in1 are interleaved and copied to out0.
  1065. Left half of halfword elements of in2 and left half of halfword
  1066. elements of in3 are interleaved and copied to out1.
  1067. */
  1068. #define ILVL_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1069. { \
  1070. out0 = (RTYPE) __msa_ilvl_h((v8i16) in0, (v8i16) in1); \
  1071. out1 = (RTYPE) __msa_ilvl_h((v8i16) in2, (v8i16) in3); \
  1072. }
  1073. #define ILVL_H2_SH(...) ILVL_H2(v8i16, __VA_ARGS__)
  1074. #define ILVL_H2_SW(...) ILVL_H2(v4i32, __VA_ARGS__)
  1075. #define ILVL_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1076. out0, out1, out2, out3) \
  1077. { \
  1078. ILVL_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1079. ILVL_H2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1080. }
  1081. #define ILVL_H4_SH(...) ILVL_H4(v8i16, __VA_ARGS__)
  1082. /* Description : Interleave left half of word elements from vectors
  1083. Arguments : Inputs - in0, in1, in2, in3
  1084. Outputs - out0, out1
  1085. Return Type - as per RTYPE
  1086. Details : Left half of word elements of in0 and left half of word
  1087. elements of in1 are interleaved and copied to out0.
  1088. Left half of word elements of in2 and left half of word
  1089. elements of in3 are interleaved and copied to out1.
  1090. */
  1091. #define ILVL_W2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1092. { \
  1093. out0 = (RTYPE) __msa_ilvl_w((v4i32) in0, (v4i32) in1); \
  1094. out1 = (RTYPE) __msa_ilvl_w((v4i32) in2, (v4i32) in3); \
  1095. }
  1096. #define ILVL_W2_SB(...) ILVL_W2(v16i8, __VA_ARGS__)
  1097. /* Description : Interleave right half of byte elements from vectors
  1098. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1099. Outputs - out0, out1, out2, out3
  1100. Return Type - as per RTYPE
  1101. Details : Right half of byte elements of in0 and right half of byte
  1102. elements of in1 are interleaved and copied to out0.
  1103. Right half of byte elements of in2 and right half of byte
  1104. elements of in3 are interleaved and copied to out1.
  1105. Similar for other pairs
  1106. */
  1107. #define ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1108. { \
  1109. out0 = (RTYPE) __msa_ilvr_b((v16i8) in0, (v16i8) in1); \
  1110. out1 = (RTYPE) __msa_ilvr_b((v16i8) in2, (v16i8) in3); \
  1111. }
  1112. #define ILVR_B2_UB(...) ILVR_B2(v16u8, __VA_ARGS__)
  1113. #define ILVR_B2_SB(...) ILVR_B2(v16i8, __VA_ARGS__)
  1114. #define ILVR_B2_UH(...) ILVR_B2(v8u16, __VA_ARGS__)
  1115. #define ILVR_B2_SH(...) ILVR_B2(v8i16, __VA_ARGS__)
  1116. #define ILVR_B2_SW(...) ILVR_B2(v4i32, __VA_ARGS__)
  1117. #define ILVR_B3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1118. { \
  1119. ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1120. out2 = (RTYPE) __msa_ilvr_b((v16i8) in4, (v16i8) in5); \
  1121. }
  1122. #define ILVR_B3_UB(...) ILVR_B3(v16u8, __VA_ARGS__)
  1123. #define ILVR_B3_UH(...) ILVR_B3(v8u16, __VA_ARGS__)
  1124. #define ILVR_B3_SH(...) ILVR_B3(v8i16, __VA_ARGS__)
  1125. #define ILVR_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1126. out0, out1, out2, out3) \
  1127. { \
  1128. ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1129. ILVR_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1130. }
  1131. #define ILVR_B4_SB(...) ILVR_B4(v16i8, __VA_ARGS__)
  1132. #define ILVR_B4_UH(...) ILVR_B4(v8u16, __VA_ARGS__)
  1133. #define ILVR_B4_SH(...) ILVR_B4(v8i16, __VA_ARGS__)
  1134. /* Description : Interleave right half of halfword elements from vectors
  1135. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1136. Outputs - out0, out1, out2, out3
  1137. Return Type - signed halfword
  1138. Details : Right half of halfword elements of in0 and right half of
  1139. halfword elements of in1 are interleaved and copied to out0.
  1140. Right half of halfword elements of in2 and right half of
  1141. halfword elements of in3 are interleaved and copied to out1.
  1142. Similar for other pairs
  1143. */
  1144. #define ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1145. { \
  1146. out0 = (RTYPE) __msa_ilvr_h((v8i16) in0, (v8i16) in1); \
  1147. out1 = (RTYPE) __msa_ilvr_h((v8i16) in2, (v8i16) in3); \
  1148. }
  1149. #define ILVR_H2_SH(...) ILVR_H2(v8i16, __VA_ARGS__)
  1150. #define ILVR_H2_SW(...) ILVR_H2(v4i32, __VA_ARGS__)
  1151. #define ILVR_H3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1152. { \
  1153. ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1154. out2 = (RTYPE) __msa_ilvr_h((v8i16) in4, (v8i16) in5); \
  1155. }
  1156. #define ILVR_H3_SH(...) ILVR_H3(v8i16, __VA_ARGS__)
  1157. #define ILVR_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1158. out0, out1, out2, out3) \
  1159. { \
  1160. ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1161. ILVR_H2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1162. }
  1163. #define ILVR_H4_SH(...) ILVR_H4(v8i16, __VA_ARGS__)
  1164. #define ILVR_W2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1165. { \
  1166. out0 = (RTYPE) __msa_ilvr_w((v4i32) in0, (v4i32) in1); \
  1167. out1 = (RTYPE) __msa_ilvr_w((v4i32) in2, (v4i32) in3); \
  1168. }
  1169. #define ILVR_W2_UB(...) ILVR_W2(v16u8, __VA_ARGS__)
  1170. #define ILVR_W2_SB(...) ILVR_W2(v16i8, __VA_ARGS__)
  1171. #define ILVR_W4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1172. out0, out1, out2, out3) \
  1173. { \
  1174. ILVR_W2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1175. ILVR_W2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1176. }
  1177. #define ILVR_W4_SB(...) ILVR_W4(v16i8, __VA_ARGS__)
  1178. /* Description : Interleave right half of double word elements from vectors
  1179. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1180. Outputs - out0, out1, out2, out3
  1181. Return Type - unsigned double word
  1182. Details : Right half of double word elements of in0 and right half of
  1183. double word elements of in1 are interleaved and copied to out0.
  1184. Right half of double word elements of in2 and right half of
  1185. double word elements of in3 are interleaved and copied to out1.
  1186. */
  1187. #define ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1188. { \
  1189. out0 = (RTYPE) __msa_ilvr_d((v2i64) (in0), (v2i64) (in1)); \
  1190. out1 = (RTYPE) __msa_ilvr_d((v2i64) (in2), (v2i64) (in3)); \
  1191. }
  1192. #define ILVR_D2_SB(...) ILVR_D2(v16i8, __VA_ARGS__)
  1193. #define ILVR_D2_SH(...) ILVR_D2(v8i16, __VA_ARGS__)
  1194. #define ILVR_D3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1195. { \
  1196. ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1197. out2 = (RTYPE) __msa_ilvr_d((v2i64) (in4), (v2i64) (in5)); \
  1198. }
  1199. #define ILVR_D3_SB(...) ILVR_D3(v16i8, __VA_ARGS__)
  1200. #define ILVR_D4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1201. out0, out1, out2, out3) \
  1202. { \
  1203. ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1204. ILVR_D2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1205. }
  1206. #define ILVR_D4_SB(...) ILVR_D4(v16i8, __VA_ARGS__)
  1207. /* Description : Interleave both left and right half of input vectors
  1208. Arguments : Inputs - in0, in1
  1209. Outputs - out0, out1
  1210. Return Type - as per RTYPE
  1211. Details : Right half of byte elements from 'in0' and 'in1' are
  1212. interleaved and stored to 'out0'
  1213. Left half of byte elements from 'in0' and 'in1' are
  1214. interleaved and stored to 'out1'
  1215. */
  1216. #define ILVRL_B2(RTYPE, in0, in1, out0, out1) \
  1217. { \
  1218. out0 = (RTYPE) __msa_ilvr_b((v16i8) in0, (v16i8) in1); \
  1219. out1 = (RTYPE) __msa_ilvl_b((v16i8) in0, (v16i8) in1); \
  1220. }
  1221. #define ILVRL_B2_SB(...) ILVRL_B2(v16i8, __VA_ARGS__)
  1222. #define ILVRL_B2_SH(...) ILVRL_B2(v8i16, __VA_ARGS__)
  1223. #define ILVRL_H2(RTYPE, in0, in1, out0, out1) \
  1224. { \
  1225. out0 = (RTYPE) __msa_ilvr_h((v8i16) in0, (v8i16) in1); \
  1226. out1 = (RTYPE) __msa_ilvl_h((v8i16) in0, (v8i16) in1); \
  1227. }
  1228. #define ILVRL_H2_SB(...) ILVRL_H2(v16i8, __VA_ARGS__)
  1229. #define ILVRL_H2_SH(...) ILVRL_H2(v8i16, __VA_ARGS__)
  1230. #define ILVRL_H2_SW(...) ILVRL_H2(v4i32, __VA_ARGS__)
  1231. #define ILVRL_W2(RTYPE, in0, in1, out0, out1) \
  1232. { \
  1233. out0 = (RTYPE) __msa_ilvr_w((v4i32) in0, (v4i32) in1); \
  1234. out1 = (RTYPE) __msa_ilvl_w((v4i32) in0, (v4i32) in1); \
  1235. }
  1236. #define ILVRL_W2_UB(...) ILVRL_W2(v16u8, __VA_ARGS__)
  1237. #define ILVRL_W2_SH(...) ILVRL_W2(v8i16, __VA_ARGS__)
  1238. #define ILVRL_W2_SW(...) ILVRL_W2(v4i32, __VA_ARGS__)
  1239. /* Description : Maximum values between signed elements of vector and
  1240. 5-bit signed immediate value are copied to the output vector
  1241. Arguments : Inputs - in0, in1, in2, in3, max_val
  1242. Outputs - in0, in1, in2, in3 (in place)
  1243. Return Type - unsigned halfword
  1244. Details : Maximum of signed halfword element values from 'in0' and
  1245. 'max_val' are written to output vector 'in0'
  1246. */
  1247. #define MAXI_SH2(RTYPE, in0, in1, max_val) \
  1248. { \
  1249. in0 = (RTYPE) __msa_maxi_s_h((v8i16) in0, (max_val)); \
  1250. in1 = (RTYPE) __msa_maxi_s_h((v8i16) in1, (max_val)); \
  1251. }
  1252. #define MAXI_SH2_SH(...) MAXI_SH2(v8i16, __VA_ARGS__)
  1253. #define MAXI_SH4(RTYPE, in0, in1, in2, in3, max_val) \
  1254. { \
  1255. MAXI_SH2(RTYPE, in0, in1, max_val); \
  1256. MAXI_SH2(RTYPE, in2, in3, max_val); \
  1257. }
  1258. #define MAXI_SH4_UH(...) MAXI_SH4(v8u16, __VA_ARGS__)
  1259. /* Description : Saturate the halfword element values to the max
  1260. unsigned value of (sat_val+1 bits)
  1261. The element data width remains unchanged
  1262. Arguments : Inputs - in0, in1, in2, in3, sat_val
  1263. Outputs - in0, in1, in2, in3 (in place)
  1264. Return Type - unsigned halfword
  1265. Details : Each unsigned halfword element from 'in0' is saturated to the
  1266. value generated with (sat_val+1) bit range
  1267. Results are in placed to original vectors
  1268. */
  1269. #define SAT_UH2(RTYPE, in0, in1, sat_val) \
  1270. { \
  1271. in0 = (RTYPE) __msa_sat_u_h((v8u16) in0, sat_val); \
  1272. in1 = (RTYPE) __msa_sat_u_h((v8u16) in1, sat_val); \
  1273. }
  1274. #define SAT_UH2_UH(...) SAT_UH2(v8u16, __VA_ARGS__)
  1275. #define SAT_UH4(RTYPE, in0, in1, in2, in3, sat_val) \
  1276. { \
  1277. SAT_UH2(RTYPE, in0, in1, sat_val); \
  1278. SAT_UH2(RTYPE, in2, in3, sat_val) \
  1279. }
  1280. #define SAT_UH4_UH(...) SAT_UH4(v8u16, __VA_ARGS__)
  1281. /* Description : Saturate the halfword element values to the max
  1282. unsigned value of (sat_val+1 bits)
  1283. The element data width remains unchanged
  1284. Arguments : Inputs - in0, in1, in2, in3, sat_val
  1285. Outputs - in0, in1, in2, in3 (in place)
  1286. Return Type - unsigned halfword
  1287. Details : Each unsigned halfword element from 'in0' is saturated to the
  1288. value generated with (sat_val+1) bit range
  1289. Results are in placed to original vectors
  1290. */
  1291. #define SAT_SH2(RTYPE, in0, in1, sat_val) \
  1292. { \
  1293. in0 = (RTYPE) __msa_sat_s_h((v8i16) in0, sat_val); \
  1294. in1 = (RTYPE) __msa_sat_s_h((v8i16) in1, sat_val); \
  1295. }
  1296. #define SAT_SH2_SH(...) SAT_SH2(v8i16, __VA_ARGS__)
  1297. #define SAT_SH3(RTYPE, in0, in1, in2, sat_val) \
  1298. { \
  1299. SAT_SH2(RTYPE, in0, in1, sat_val) \
  1300. in2 = (RTYPE) __msa_sat_s_h((v8i16) in2, sat_val); \
  1301. }
  1302. #define SAT_SH3_SH(...) SAT_SH3(v8i16, __VA_ARGS__)
  1303. #define SAT_SH4(RTYPE, in0, in1, in2, in3, sat_val) \
  1304. { \
  1305. SAT_SH2(RTYPE, in0, in1, sat_val); \
  1306. SAT_SH2(RTYPE, in2, in3, sat_val); \
  1307. }
  1308. #define SAT_SH4_SH(...) SAT_SH4(v8i16, __VA_ARGS__)
  1309. /* Description : Saturate the word element values to the max
  1310. unsigned value of (sat_val+1 bits)
  1311. The element data width remains unchanged
  1312. Arguments : Inputs - in0, in1, in2, in3, sat_val
  1313. Outputs - in0, in1, in2, in3 (in place)
  1314. Return Type - unsigned word
  1315. Details : Each unsigned word element from 'in0' is saturated to the
  1316. value generated with (sat_val+1) bit range
  1317. Results are in placed to original vectors
  1318. */
  1319. #define SAT_SW2(RTYPE, in0, in1, sat_val) \
  1320. { \
  1321. in0 = (RTYPE) __msa_sat_s_w((v4i32) in0, sat_val); \
  1322. in1 = (RTYPE) __msa_sat_s_w((v4i32) in1, sat_val); \
  1323. }
  1324. #define SAT_SW2_SW(...) SAT_SW2(v4i32, __VA_ARGS__)
  1325. #define SAT_SW4(RTYPE, in0, in1, in2, in3, sat_val) \
  1326. { \
  1327. SAT_SW2(RTYPE, in0, in1, sat_val); \
  1328. SAT_SW2(RTYPE, in2, in3, sat_val); \
  1329. }
  1330. #define SAT_SW4_SW(...) SAT_SW4(v4i32, __VA_ARGS__)
  1331. /* Description : Indexed halfword element values are replicated to all
  1332. elements in output vector
  1333. Arguments : Inputs - in, idx0, idx1
  1334. Outputs - out0, out1
  1335. Return Type - as per RTYPE
  1336. Details : 'idx0' element value from 'in' vector is replicated to all
  1337. elements in 'out0' vector
  1338. Valid index range for halfword operation is 0-7
  1339. */
  1340. #define SPLATI_H2(RTYPE, in, idx0, idx1, out0, out1) \
  1341. { \
  1342. out0 = (RTYPE) __msa_splati_h((v8i16) in, idx0); \
  1343. out1 = (RTYPE) __msa_splati_h((v8i16) in, idx1); \
  1344. }
  1345. #define SPLATI_H2_SB(...) SPLATI_H2(v16i8, __VA_ARGS__)
  1346. #define SPLATI_H2_SH(...) SPLATI_H2(v8i16, __VA_ARGS__)
  1347. #define SPLATI_H4(RTYPE, in, idx0, idx1, idx2, idx3, \
  1348. out0, out1, out2, out3) \
  1349. { \
  1350. SPLATI_H2(RTYPE, in, idx0, idx1, out0, out1); \
  1351. SPLATI_H2(RTYPE, in, idx2, idx3, out2, out3); \
  1352. }
  1353. #define SPLATI_H4_SB(...) SPLATI_H4(v16i8, __VA_ARGS__)
  1354. #define SPLATI_H4_SH(...) SPLATI_H4(v8i16, __VA_ARGS__)
  1355. /* Description : Indexed word element values are replicated to all
  1356. elements in output vector
  1357. Arguments : Inputs - in, stidx
  1358. Outputs - out0, out1
  1359. Return Type - as per RTYPE
  1360. Details : 'stidx' element value from 'in' vector is replicated to all
  1361. elements in 'out0' vector
  1362. 'stidx + 1' element value from 'in' vector is replicated to all
  1363. elements in 'out1' vector
  1364. Valid index range for halfword operation is 0-3
  1365. */
  1366. #define SPLATI_W2(RTYPE, in, stidx, out0, out1) \
  1367. { \
  1368. out0 = (RTYPE) __msa_splati_w((v4i32) in, stidx); \
  1369. out1 = (RTYPE) __msa_splati_w((v4i32) in, (stidx+1)); \
  1370. }
  1371. #define SPLATI_W2_SH(...) SPLATI_W2(v8i16, __VA_ARGS__)
  1372. #define SPLATI_W2_SW(...) SPLATI_W2(v4i32, __VA_ARGS__)
  1373. #define SPLATI_W4(RTYPE, in, out0, out1, out2, out3) \
  1374. { \
  1375. SPLATI_W2(RTYPE, in, 0, out0, out1); \
  1376. SPLATI_W2(RTYPE, in, 2, out2, out3); \
  1377. }
  1378. #define SPLATI_W4_SH(...) SPLATI_W4(v8i16, __VA_ARGS__)
  1379. #define SPLATI_W4_SW(...) SPLATI_W4(v4i32, __VA_ARGS__)
  1380. /* Description : Pack even byte elements of vector pairs
  1381. Arguments : Inputs - in0, in1, in2, in3
  1382. Outputs - out0, out1
  1383. Return Type - as per RTYPE
  1384. Details : Even byte elements of in0 are copied to the left half of
  1385. out0 & even byte elements of in1 are copied to the right
  1386. half of out0.
  1387. Even byte elements of in2 are copied to the left half of
  1388. out1 & even byte elements of in3 are copied to the right
  1389. half of out1.
  1390. */
  1391. #define PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1392. { \
  1393. out0 = (RTYPE) __msa_pckev_b((v16i8) in0, (v16i8) in1); \
  1394. out1 = (RTYPE) __msa_pckev_b((v16i8) in2, (v16i8) in3); \
  1395. }
  1396. #define PCKEV_B2_SB(...) PCKEV_B2(v16i8, __VA_ARGS__)
  1397. #define PCKEV_B2_UB(...) PCKEV_B2(v16u8, __VA_ARGS__)
  1398. #define PCKEV_B2_SH(...) PCKEV_B2(v8i16, __VA_ARGS__)
  1399. #define PCKEV_B2_SW(...) PCKEV_B2(v4i32, __VA_ARGS__)
  1400. #define PCKEV_B3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1401. { \
  1402. PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1403. out2 = (RTYPE) __msa_pckev_b((v16i8) in4, (v16i8) in5); \
  1404. }
  1405. #define PCKEV_B3_UB(...) PCKEV_B3(v16u8, __VA_ARGS__)
  1406. #define PCKEV_B3_SB(...) PCKEV_B3(v16i8, __VA_ARGS__)
  1407. #define PCKEV_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1408. out0, out1, out2, out3) \
  1409. { \
  1410. PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1411. PCKEV_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1412. }
  1413. #define PCKEV_B4_SB(...) PCKEV_B4(v16i8, __VA_ARGS__)
  1414. #define PCKEV_B4_UB(...) PCKEV_B4(v16u8, __VA_ARGS__)
  1415. #define PCKEV_B4_SH(...) PCKEV_B4(v8i16, __VA_ARGS__)
  1416. #define PCKEV_B4_SW(...) PCKEV_B4(v4i32, __VA_ARGS__)
  1417. /* Description : Pack even halfword elements of vector pairs
  1418. Arguments : Inputs - in0, in1, in2, in3
  1419. Outputs - out0, out1
  1420. Return Type - as per RTYPE
  1421. Details : Even halfword elements of in0 are copied to the left half of
  1422. out0 & even halfword elements of in1 are copied to the right
  1423. half of out0.
  1424. Even halfword elements of in2 are copied to the left half of
  1425. out1 & even halfword elements of in3 are copied to the right
  1426. half of out1.
  1427. */
  1428. #define PCKEV_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1429. { \
  1430. out0 = (RTYPE) __msa_pckev_h((v8i16) in0, (v8i16) in1); \
  1431. out1 = (RTYPE) __msa_pckev_h((v8i16) in2, (v8i16) in3); \
  1432. }
  1433. #define PCKEV_H2_SH(...) PCKEV_H2(v8i16, __VA_ARGS__)
  1434. #define PCKEV_H2_SW(...) PCKEV_H2(v4i32, __VA_ARGS__)
  1435. #define PCKEV_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1436. out0, out1, out2, out3) \
  1437. { \
  1438. PCKEV_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1439. PCKEV_H2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1440. }
  1441. #define PCKEV_H4_SH(...) PCKEV_H4(v8i16, __VA_ARGS__)
  1442. #define PCKEV_H4_SW(...) PCKEV_H4(v4i32, __VA_ARGS__)
  1443. /* Description : Pack even double word elements of vector pairs
  1444. Arguments : Inputs - in0, in1, in2, in3
  1445. Outputs - out0, out1
  1446. Return Type - unsigned byte
  1447. Details : Even double elements of in0 are copied to the left half of
  1448. out0 & even double elements of in1 are copied to the right
  1449. half of out0.
  1450. Even double elements of in2 are copied to the left half of
  1451. out1 & even double elements of in3 are copied to the right
  1452. half of out1.
  1453. */
  1454. #define PCKEV_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1455. { \
  1456. out0 = (RTYPE) __msa_pckev_d((v2i64) in0, (v2i64) in1); \
  1457. out1 = (RTYPE) __msa_pckev_d((v2i64) in2, (v2i64) in3); \
  1458. }
  1459. #define PCKEV_D2_UB(...) PCKEV_D2(v16u8, __VA_ARGS__)
  1460. #define PCKEV_D2_SB(...) PCKEV_D2(v16i8, __VA_ARGS__)
  1461. #define PCKEV_D2_SH(...) PCKEV_D2(v8i16, __VA_ARGS__)
  1462. #define PCKEV_D4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1463. out0, out1, out2, out3) \
  1464. { \
  1465. PCKEV_D2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1466. PCKEV_D2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1467. }
  1468. #define PCKEV_D4_UB(...) PCKEV_D4(v16u8, __VA_ARGS__)
  1469. /* Description : Each byte element is logically xor'ed with immediate 128
  1470. Arguments : Inputs - in0, in1
  1471. Outputs - in0, in1 (in-place)
  1472. Return Type - as per RTYPE
  1473. Details : Each unsigned byte element from input vector 'in0' is
  1474. logically xor'ed with 128 and result is in-place stored in
  1475. 'in0' vector
  1476. Each unsigned byte element from input vector 'in1' is
  1477. logically xor'ed with 128 and result is in-place stored in
  1478. 'in1' vector
  1479. Similar for other pairs
  1480. */
  1481. #define XORI_B2_128(RTYPE, in0, in1) \
  1482. { \
  1483. in0 = (RTYPE) __msa_xori_b((v16u8) in0, 128); \
  1484. in1 = (RTYPE) __msa_xori_b((v16u8) in1, 128); \
  1485. }
  1486. #define XORI_B2_128_UB(...) XORI_B2_128(v16u8, __VA_ARGS__)
  1487. #define XORI_B2_128_SB(...) XORI_B2_128(v16i8, __VA_ARGS__)
  1488. #define XORI_B2_128_SH(...) XORI_B2_128(v8i16, __VA_ARGS__)
  1489. #define XORI_B3_128(RTYPE, in0, in1, in2) \
  1490. { \
  1491. XORI_B2_128(RTYPE, in0, in1); \
  1492. in2 = (RTYPE) __msa_xori_b((v16u8) in2, 128); \
  1493. }
  1494. #define XORI_B3_128_SB(...) XORI_B3_128(v16i8, __VA_ARGS__)
  1495. #define XORI_B4_128(RTYPE, in0, in1, in2, in3) \
  1496. { \
  1497. XORI_B2_128(RTYPE, in0, in1); \
  1498. XORI_B2_128(RTYPE, in2, in3); \
  1499. }
  1500. #define XORI_B4_128_UB(...) XORI_B4_128(v16u8, __VA_ARGS__)
  1501. #define XORI_B4_128_SB(...) XORI_B4_128(v16i8, __VA_ARGS__)
  1502. #define XORI_B4_128_SH(...) XORI_B4_128(v8i16, __VA_ARGS__)
  1503. #define XORI_B5_128(RTYPE, in0, in1, in2, in3, in4) \
  1504. { \
  1505. XORI_B3_128(RTYPE, in0, in1, in2); \
  1506. XORI_B2_128(RTYPE, in3, in4); \
  1507. }
  1508. #define XORI_B5_128_SB(...) XORI_B5_128(v16i8, __VA_ARGS__)
  1509. #define XORI_B6_128(RTYPE, in0, in1, in2, in3, in4, in5) \
  1510. { \
  1511. XORI_B4_128(RTYPE, in0, in1, in2, in3); \
  1512. XORI_B2_128(RTYPE, in4, in5); \
  1513. }
  1514. #define XORI_B6_128_SB(...) XORI_B6_128(v16i8, __VA_ARGS__)
  1515. #define XORI_B7_128(RTYPE, in0, in1, in2, in3, in4, in5, in6) \
  1516. { \
  1517. XORI_B4_128(RTYPE, in0, in1, in2, in3); \
  1518. XORI_B3_128(RTYPE, in4, in5, in6); \
  1519. }
  1520. #define XORI_B7_128_SB(...) XORI_B7_128(v16i8, __VA_ARGS__)
  1521. #define XORI_B8_128(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7) \
  1522. { \
  1523. XORI_B4_128(RTYPE, in0, in1, in2, in3); \
  1524. XORI_B4_128(RTYPE, in4, in5, in6, in7); \
  1525. }
  1526. #define XORI_B8_128_SB(...) XORI_B8_128(v16i8, __VA_ARGS__)
  1527. /* Description : Addition of signed halfword elements and signed saturation
  1528. Arguments : Inputs - in0, in1, in2, in3
  1529. Outputs - out0, out1
  1530. Return Type - as per RTYPE
  1531. Details : Signed halfword elements from 'in0' are added to signed
  1532. halfword elements of 'in1'. The result is then signed saturated
  1533. between -32768 to +32767 (as per halfword data type)
  1534. Similar for other pairs
  1535. */
  1536. #define ADDS_SH2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1537. { \
  1538. out0 = (RTYPE) __msa_adds_s_h((v8i16) in0, (v8i16) in1); \
  1539. out1 = (RTYPE) __msa_adds_s_h((v8i16) in2, (v8i16) in3); \
  1540. }
  1541. #define ADDS_SH2_SH(...) ADDS_SH2(v8i16, __VA_ARGS__)
  1542. #define ADDS_SH4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1543. out0, out1, out2, out3) \
  1544. { \
  1545. ADDS_SH2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1546. ADDS_SH2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1547. }
  1548. #define ADDS_SH4_UH(...) ADDS_SH4(v8u16, __VA_ARGS__)
  1549. #define ADDS_SH4_SH(...) ADDS_SH4(v8i16, __VA_ARGS__)
  1550. /* Description : Shift left all elements of vector (generic for all data types)
  1551. Arguments : Inputs - in0, in1, in2, in3, shift
  1552. Outputs - in0, in1, in2, in3 (in place)
  1553. Return Type - as per input vector RTYPE
  1554. Details : Each element of vector 'in0' is left shifted by 'shift' and
  1555. result is in place written to 'in0'
  1556. Similar for other pairs
  1557. */
  1558. #define SLLI_4V(in0, in1, in2, in3, shift) \
  1559. { \
  1560. in0 = in0 << shift; \
  1561. in1 = in1 << shift; \
  1562. in2 = in2 << shift; \
  1563. in3 = in3 << shift; \
  1564. }
  1565. /* Description : Arithmetic shift right all elements of vector
  1566. (generic for all data types)
  1567. Arguments : Inputs - in0, in1, in2, in3, shift
  1568. Outputs - in0, in1, in2, in3 (in place)
  1569. Return Type - as per input vector RTYPE
  1570. Details : Each element of vector 'in0' is right shifted by 'shift' and
  1571. result is in place written to 'in0'
  1572. Here, 'shift' is GP variable passed in
  1573. Similar for other pairs
  1574. */
  1575. #define SRA_4V(in0, in1, in2, in3, shift) \
  1576. { \
  1577. in0 = in0 >> shift; \
  1578. in1 = in1 >> shift; \
  1579. in2 = in2 >> shift; \
  1580. in3 = in3 >> shift; \
  1581. }
  1582. /* Description : Shift right logical all halfword elements of vector
  1583. Arguments : Inputs - in0, in1, in2, in3, shift
  1584. Outputs - in0, in1, in2, in3 (in place)
  1585. Return Type - unsigned halfword
  1586. Details : Each element of vector 'in0' is shifted right logical by
  1587. number of bits respective element holds in vector 'shift' and
  1588. result is in place written to 'in0'
  1589. Here, 'shift' is a vector passed in
  1590. Similar for other pairs
  1591. */
  1592. #define SRL_H4(RTYPE, in0, in1, in2, in3, shift) \
  1593. { \
  1594. in0 = (RTYPE) __msa_srl_h((v8i16) in0, (v8i16) shift); \
  1595. in1 = (RTYPE) __msa_srl_h((v8i16) in1, (v8i16) shift); \
  1596. in2 = (RTYPE) __msa_srl_h((v8i16) in2, (v8i16) shift); \
  1597. in3 = (RTYPE) __msa_srl_h((v8i16) in3, (v8i16) shift); \
  1598. }
  1599. #define SRL_H4_UH(...) SRL_H4(v8u16, __VA_ARGS__)
  1600. /* Description : Shift right arithmetic rounded halfwords
  1601. Arguments : Inputs - in0, in1, shift
  1602. Outputs - in0, in1, (in place)
  1603. Return Type - unsigned halfword
  1604. Details : Each element of vector 'in0' is shifted right arithmetic by
  1605. number of bits respective element holds in vector 'shift'.
  1606. The last discarded bit is added to shifted value for rounding
  1607. and the result is in place written to 'in0'
  1608. Here, 'shift' is a vector passed in
  1609. Similar for other pairs
  1610. */
  1611. #define SRAR_H2(RTYPE, in0, in1, shift) \
  1612. { \
  1613. in0 = (RTYPE) __msa_srar_h((v8i16) in0, (v8i16) shift); \
  1614. in1 = (RTYPE) __msa_srar_h((v8i16) in1, (v8i16) shift); \
  1615. }
  1616. #define SRAR_H2_UH(...) SRAR_H2(v8u16, __VA_ARGS__)
  1617. #define SRAR_H2_SH(...) SRAR_H2(v8i16, __VA_ARGS__)
  1618. #define SRAR_H3(RTYPE, in0, in1, in2, shift) \
  1619. { \
  1620. SRAR_H2(RTYPE, in0, in1, shift) \
  1621. in2 = (RTYPE) __msa_srar_h((v8i16) in2, (v8i16) shift); \
  1622. }
  1623. #define SRAR_H3_SH(...) SRAR_H3(v8i16, __VA_ARGS__)
  1624. #define SRAR_H4(RTYPE, in0, in1, in2, in3, shift) \
  1625. { \
  1626. SRAR_H2(RTYPE, in0, in1, shift) \
  1627. SRAR_H2(RTYPE, in2, in3, shift) \
  1628. }
  1629. #define SRAR_H4_UH(...) SRAR_H4(v8u16, __VA_ARGS__)
  1630. #define SRAR_H4_SH(...) SRAR_H4(v8i16, __VA_ARGS__)
  1631. /* Description : Shift right arithmetic rounded words
  1632. Arguments : Inputs - in0, in1, shift
  1633. Outputs - in0, in1, (in place)
  1634. Return Type - as per RTYPE
  1635. Details : Each element of vector 'in0' is shifted right arithmetic by
  1636. number of bits respective element holds in vector 'shift'.
  1637. The last discarded bit is added to shifted value for rounding
  1638. and the result is in place written to 'in0'
  1639. Here, 'shift' is a vector passed in
  1640. Similar for other pairs
  1641. */
  1642. #define SRAR_W2(RTYPE, in0, in1, shift) \
  1643. { \
  1644. in0 = (RTYPE) __msa_srar_w((v4i32) in0, (v4i32) shift); \
  1645. in1 = (RTYPE) __msa_srar_w((v4i32) in1, (v4i32) shift); \
  1646. }
  1647. #define SRAR_W2_SW(...) SRAR_W2(v4i32, __VA_ARGS__)
  1648. #define SRAR_W4(RTYPE, in0, in1, in2, in3, shift) \
  1649. { \
  1650. SRAR_W2(RTYPE, in0, in1, shift) \
  1651. SRAR_W2(RTYPE, in2, in3, shift) \
  1652. }
  1653. #define SRAR_W4_SW(...) SRAR_W4(v4i32, __VA_ARGS__)
  1654. /* Description : Shift right arithmetic rounded (immediate)
  1655. Arguments : Inputs - in0, in1, in2, in3, shift
  1656. Outputs - in0, in1, in2, in3 (in place)
  1657. Return Type - as per RTYPE
  1658. Details : Each element of vector 'in0' is shifted right arithmetic by
  1659. value in 'shift'.
  1660. The last discarded bit is added to shifted value for rounding
  1661. and the result is in place written to 'in0'
  1662. Similar for other pairs
  1663. */
  1664. #define SRARI_H2(RTYPE, in0, in1, shift) \
  1665. { \
  1666. in0 = (RTYPE) __msa_srari_h((v8i16) in0, shift); \
  1667. in1 = (RTYPE) __msa_srari_h((v8i16) in1, shift); \
  1668. }
  1669. #define SRARI_H2_UH(...) SRARI_H2(v8u16, __VA_ARGS__)
  1670. #define SRARI_H2_SH(...) SRARI_H2(v8i16, __VA_ARGS__)
  1671. #define SRARI_H4(RTYPE, in0, in1, in2, in3, shift) \
  1672. { \
  1673. SRARI_H2(RTYPE, in0, in1, shift); \
  1674. SRARI_H2(RTYPE, in2, in3, shift); \
  1675. }
  1676. #define SRARI_H4_UH(...) SRARI_H4(v8u16, __VA_ARGS__)
  1677. #define SRARI_H4_SH(...) SRARI_H4(v8i16, __VA_ARGS__)
  1678. /* Description : Shift right arithmetic rounded (immediate)
  1679. Arguments : Inputs - in0, in1, shift
  1680. Outputs - in0, in1 (in place)
  1681. Return Type - as per RTYPE
  1682. Details : Each element of vector 'in0' is shifted right arithmetic by
  1683. value in 'shift'.
  1684. The last discarded bit is added to shifted value for rounding
  1685. and the result is in place written to 'in0'
  1686. Similar for other pairs
  1687. */
  1688. #define SRARI_W2(RTYPE, in0, in1, shift) \
  1689. { \
  1690. in0 = (RTYPE) __msa_srari_w((v4i32) in0, shift); \
  1691. in1 = (RTYPE) __msa_srari_w((v4i32) in1, shift); \
  1692. }
  1693. #define SRARI_W2_SW(...) SRARI_W2(v4i32, __VA_ARGS__)
  1694. #define SRARI_W4(RTYPE, in0, in1, in2, in3, shift) \
  1695. { \
  1696. SRARI_W2(RTYPE, in0, in1, shift); \
  1697. SRARI_W2(RTYPE, in2, in3, shift); \
  1698. }
  1699. #define SRARI_W4_SH(...) SRARI_W4(v8i16, __VA_ARGS__)
  1700. #define SRARI_W4_SW(...) SRARI_W4(v4i32, __VA_ARGS__)
  1701. /* Description : Multiplication of pairs of vectors
  1702. Arguments : Inputs - in0, in1, in2, in3
  1703. Outputs - out0, out1
  1704. Details : Each element from 'in0' is multiplied with elements from 'in1'
  1705. and result is written to 'out0'
  1706. Similar for other pairs
  1707. */
  1708. #define MUL2(in0, in1, in2, in3, out0, out1) \
  1709. { \
  1710. out0 = in0 * in1; \
  1711. out1 = in2 * in3; \
  1712. }
  1713. #define MUL4(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, out3) \
  1714. { \
  1715. MUL2(in0, in1, in2, in3, out0, out1); \
  1716. MUL2(in4, in5, in6, in7, out2, out3); \
  1717. }
  1718. /* Description : Addition of 2 pairs of vectors
  1719. Arguments : Inputs - in0, in1, in2, in3
  1720. Outputs - out0, out1
  1721. Details : Each element from 2 pairs vectors is added and 2 results are
  1722. produced
  1723. */
  1724. #define ADD2(in0, in1, in2, in3, out0, out1) \
  1725. { \
  1726. out0 = in0 + in1; \
  1727. out1 = in2 + in3; \
  1728. }
  1729. #define ADD4(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, out3) \
  1730. { \
  1731. ADD2(in0, in1, in2, in3, out0, out1); \
  1732. ADD2(in4, in5, in6, in7, out2, out3); \
  1733. }
  1734. /* Description : Zero extend unsigned byte elements to halfword elements
  1735. Arguments : Inputs - in (1 input unsigned byte vector)
  1736. Outputs - out0, out1 (unsigned 2 halfword vectors)
  1737. Return Type - signed halfword
  1738. Details : Zero extended right half of vector is returned in 'out0'
  1739. Zero extended left half of vector is returned in 'out1'
  1740. */
  1741. #define UNPCK_UB_SH(in, out0, out1) \
  1742. { \
  1743. v16i8 zero_m = { 0 }; \
  1744. \
  1745. ILVRL_B2_SH(zero_m, in, out0, out1); \
  1746. }
  1747. /* Description : Sign extend halfword elements from input vector and return
  1748. result in pair of vectors
  1749. Arguments : Inputs - in (1 input halfword vector)
  1750. Outputs - out0, out1 (sign extended 2 word vectors)
  1751. Return Type - signed word
  1752. Details : Sign bit of halfword elements from input vector 'in' is
  1753. extracted and interleaved right with same vector 'in0' to
  1754. generate 4 signed word elements in 'out0'
  1755. Then interleaved left with same vector 'in0' to
  1756. generate 4 signed word elements in 'out1'
  1757. */
  1758. #define UNPCK_SH_SW(in, out0, out1) \
  1759. { \
  1760. v8i16 tmp_m; \
  1761. \
  1762. tmp_m = __msa_clti_s_h((v8i16) in, 0); \
  1763. ILVRL_H2_SW(tmp_m, in, out0, out1); \
  1764. }
  1765. /* Description : Butterfly of 4 input vectors
  1766. Arguments : Inputs - in0, in1, in2, in3
  1767. Outputs - out0, out1, out2, out3
  1768. Details : Butterfly operation
  1769. */
  1770. #define BUTTERFLY_4(in0, in1, in2, in3, out0, out1, out2, out3) \
  1771. { \
  1772. out0 = in0 + in3; \
  1773. out1 = in1 + in2; \
  1774. \
  1775. out2 = in1 - in2; \
  1776. out3 = in0 - in3; \
  1777. }
  1778. /* Description : Transposes input 4x4 byte block
  1779. Arguments : Inputs - in0, in1, in2, in3 (input 4x4 byte block)
  1780. Outputs - out0, out1, out2, out3 (output 4x4 byte block)
  1781. Return Type - unsigned byte
  1782. Details :
  1783. */
  1784. #define TRANSPOSE4x4_UB_UB(in0, in1, in2, in3, out0, out1, out2, out3) \
  1785. { \
  1786. v16i8 zero_m = { 0 }; \
  1787. v16i8 s0_m, s1_m, s2_m, s3_m; \
  1788. \
  1789. ILVR_D2_SB(in1, in0, in3, in2, s0_m, s1_m); \
  1790. ILVRL_B2_SB(s1_m, s0_m, s2_m, s3_m); \
  1791. \
  1792. out0 = (v16u8) __msa_ilvr_b(s3_m, s2_m); \
  1793. out1 = (v16u8) __msa_sldi_b(zero_m, (v16i8) out0, 4); \
  1794. out2 = (v16u8) __msa_sldi_b(zero_m, (v16i8) out1, 4); \
  1795. out3 = (v16u8) __msa_sldi_b(zero_m, (v16i8) out2, 4); \
  1796. }
  1797. /* Description : Transposes input 8x4 byte block into 4x8
  1798. Arguments : Inputs - in0, in1, in2, in3 (input 8x4 byte block)
  1799. Outputs - out0, out1, out2, out3 (output 4x8 byte block)
  1800. Return Type - unsigned byte
  1801. Details :
  1802. */
  1803. #define TRANSPOSE8x4_UB(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1804. out0, out1, out2, out3) \
  1805. { \
  1806. v16i8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  1807. \
  1808. ILVEV_W2_SB(in0, in4, in1, in5, tmp0_m, tmp1_m); \
  1809. tmp2_m = __msa_ilvr_b(tmp1_m, tmp0_m); \
  1810. ILVEV_W2_SB(in2, in6, in3, in7, tmp0_m, tmp1_m); \
  1811. \
  1812. tmp3_m = __msa_ilvr_b(tmp1_m, tmp0_m); \
  1813. ILVRL_H2_SB(tmp3_m, tmp2_m, tmp0_m, tmp1_m); \
  1814. \
  1815. ILVRL_W2(RTYPE, tmp1_m, tmp0_m, out0, out2); \
  1816. out1 = (RTYPE) __msa_ilvl_d((v2i64) out2, (v2i64) out0); \
  1817. out3 = (RTYPE) __msa_ilvl_d((v2i64) out0, (v2i64) out2); \
  1818. }
  1819. #define TRANSPOSE8x4_UB_UB(...) TRANSPOSE8x4_UB(v16u8, __VA_ARGS__)
  1820. /* Description : Transposes 16x8 block into 8x16 with byte elements in vectors
  1821. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7,
  1822. in8, in9, in10, in11, in12, in13, in14, in15
  1823. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  1824. Return Type - unsigned byte
  1825. Details :
  1826. */
  1827. #define TRANSPOSE16x8_UB_UB(in0, in1, in2, in3, in4, in5, in6, in7, \
  1828. in8, in9, in10, in11, in12, in13, in14, in15, \
  1829. out0, out1, out2, out3, out4, out5, out6, out7) \
  1830. { \
  1831. v16u8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  1832. v16u8 tmp4_m, tmp5_m, tmp6_m, tmp7_m; \
  1833. \
  1834. ILVEV_D2_UB(in0, in8, in1, in9, out7, out6); \
  1835. ILVEV_D2_UB(in2, in10, in3, in11, out5, out4); \
  1836. ILVEV_D2_UB(in4, in12, in5, in13, out3, out2); \
  1837. ILVEV_D2_UB(in6, in14, in7, in15, out1, out0); \
  1838. \
  1839. tmp0_m = (v16u8) __msa_ilvev_b((v16i8) out6, (v16i8) out7); \
  1840. tmp4_m = (v16u8) __msa_ilvod_b((v16i8) out6, (v16i8) out7); \
  1841. tmp1_m = (v16u8) __msa_ilvev_b((v16i8) out4, (v16i8) out5); \
  1842. tmp5_m = (v16u8) __msa_ilvod_b((v16i8) out4, (v16i8) out5); \
  1843. out5 = (v16u8) __msa_ilvev_b((v16i8) out2, (v16i8) out3); \
  1844. tmp6_m = (v16u8) __msa_ilvod_b((v16i8) out2, (v16i8) out3); \
  1845. out7 = (v16u8) __msa_ilvev_b((v16i8) out0, (v16i8) out1); \
  1846. tmp7_m = (v16u8) __msa_ilvod_b((v16i8) out0, (v16i8) out1); \
  1847. \
  1848. ILVEV_H2_UB(tmp0_m, tmp1_m, out5, out7, tmp2_m, tmp3_m); \
  1849. out0 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  1850. out4 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  1851. \
  1852. tmp2_m = (v16u8) __msa_ilvod_h((v8i16) tmp1_m, (v8i16) tmp0_m); \
  1853. tmp3_m = (v16u8) __msa_ilvod_h((v8i16) out7, (v8i16) out5); \
  1854. out2 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  1855. out6 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  1856. \
  1857. ILVEV_H2_UB(tmp4_m, tmp5_m, tmp6_m, tmp7_m, tmp2_m, tmp3_m); \
  1858. out1 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  1859. out5 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  1860. \
  1861. tmp2_m = (v16u8) __msa_ilvod_h((v8i16) tmp5_m, (v8i16) tmp4_m); \
  1862. tmp2_m = (v16u8) __msa_ilvod_h((v8i16) tmp5_m, (v8i16) tmp4_m); \
  1863. tmp3_m = (v16u8) __msa_ilvod_h((v8i16) tmp7_m, (v8i16) tmp6_m); \
  1864. tmp3_m = (v16u8) __msa_ilvod_h((v8i16) tmp7_m, (v8i16) tmp6_m); \
  1865. out3 = (v16u8) __msa_ilvev_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  1866. out7 = (v16u8) __msa_ilvod_w((v4i32) tmp3_m, (v4i32) tmp2_m); \
  1867. }
  1868. /* Description : Transposes 8x8 block with half word elements in vectors
  1869. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1870. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  1871. Return Type - signed halfword
  1872. Details :
  1873. */
  1874. #define TRANSPOSE8x8_H(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
  1875. out0, out1, out2, out3, out4, out5, out6, out7) \
  1876. { \
  1877. v8i16 s0_m, s1_m; \
  1878. v8i16 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  1879. v8i16 tmp4_m, tmp5_m, tmp6_m, tmp7_m; \
  1880. \
  1881. ILVR_H2_SH(in6, in4, in7, in5, s0_m, s1_m); \
  1882. ILVRL_H2_SH(s1_m, s0_m, tmp0_m, tmp1_m); \
  1883. ILVL_H2_SH(in6, in4, in7, in5, s0_m, s1_m); \
  1884. ILVRL_H2_SH(s1_m, s0_m, tmp2_m, tmp3_m); \
  1885. ILVR_H2_SH(in2, in0, in3, in1, s0_m, s1_m); \
  1886. ILVRL_H2_SH(s1_m, s0_m, tmp4_m, tmp5_m); \
  1887. ILVL_H2_SH(in2, in0, in3, in1, s0_m, s1_m); \
  1888. ILVRL_H2_SH(s1_m, s0_m, tmp6_m, tmp7_m); \
  1889. PCKEV_D4(RTYPE, tmp0_m, tmp4_m, tmp1_m, tmp5_m, tmp2_m, tmp6_m, \
  1890. tmp3_m, tmp7_m, out0, out2, out4, out6); \
  1891. out1 = (RTYPE) __msa_pckod_d((v2i64) tmp0_m, (v2i64) tmp4_m); \
  1892. out3 = (RTYPE) __msa_pckod_d((v2i64) tmp1_m, (v2i64) tmp5_m); \
  1893. out5 = (RTYPE) __msa_pckod_d((v2i64) tmp2_m, (v2i64) tmp6_m); \
  1894. out7 = (RTYPE) __msa_pckod_d((v2i64) tmp3_m, (v2i64) tmp7_m); \
  1895. }
  1896. #define TRANSPOSE8x8_UH_UH(...) TRANSPOSE8x8_H(v8u16, __VA_ARGS__)
  1897. #define TRANSPOSE8x8_SH_SH(...) TRANSPOSE8x8_H(v8i16, __VA_ARGS__)
  1898. /* Description : Transposes 4x4 block with word elements in vectors
  1899. Arguments : Inputs - in0, in1, in2, in3
  1900. Outputs - out0, out1, out2, out3
  1901. Return Type - signed word
  1902. Details :
  1903. */
  1904. #define TRANSPOSE4x4_SW_SW(in0, in1, in2, in3, out0, out1, out2, out3) \
  1905. { \
  1906. v4i32 s0_m, s1_m, s2_m, s3_m; \
  1907. \
  1908. ILVRL_W2_SW(in1, in0, s0_m, s1_m); \
  1909. ILVRL_W2_SW(in3, in2, s2_m, s3_m); \
  1910. \
  1911. out0 = (v4i32) __msa_ilvr_d((v2i64) s2_m, (v2i64) s0_m); \
  1912. out1 = (v4i32) __msa_ilvl_d((v2i64) s2_m, (v2i64) s0_m); \
  1913. out2 = (v4i32) __msa_ilvr_d((v2i64) s3_m, (v2i64) s1_m); \
  1914. out3 = (v4i32) __msa_ilvl_d((v2i64) s3_m, (v2i64) s1_m); \
  1915. }
  1916. /* Description : Pack even elements of input vectors & xor with 128
  1917. Arguments : Inputs - in0, in1
  1918. Outputs - out_m
  1919. Return Type - unsigned byte
  1920. Details : Signed byte even elements from 'in0' and 'in1' are packed
  1921. together in one vector and the resulted vector is xor'ed with
  1922. 128 to shift the range from signed to unsigned byte
  1923. */
  1924. #define PCKEV_XORI128_UB(in0, in1) \
  1925. ( { \
  1926. v16u8 out_m; \
  1927. out_m = (v16u8) __msa_pckev_b((v16i8) in1, (v16i8) in0); \
  1928. out_m = (v16u8) __msa_xori_b((v16u8) out_m, 128); \
  1929. out_m; \
  1930. } )
  1931. /* Description : Pack even byte elements, extract 0 & 2 index words from pair
  1932. of results and store 4 words in destination memory as per
  1933. stride
  1934. Arguments : Inputs - in0, in1, in2, in3, pdst, stride
  1935. */
  1936. #define PCKEV_ST4x4_UB(in0, in1, in2, in3, pdst, stride) \
  1937. { \
  1938. uint32_t out0_m, out1_m, out2_m, out3_m; \
  1939. v16i8 tmp0_m, tmp1_m; \
  1940. \
  1941. PCKEV_B2_SB(in1, in0, in3, in2, tmp0_m, tmp1_m); \
  1942. \
  1943. out0_m = __msa_copy_u_w((v4i32) tmp0_m, 0); \
  1944. out1_m = __msa_copy_u_w((v4i32) tmp0_m, 2); \
  1945. out2_m = __msa_copy_u_w((v4i32) tmp1_m, 0); \
  1946. out3_m = __msa_copy_u_w((v4i32) tmp1_m, 2); \
  1947. \
  1948. SW4(out0_m, out1_m, out2_m, out3_m, pdst, stride); \
  1949. }
  1950. #endif /* AVUTIL_MIPS_GENERIC_MACROS_MSA_H */