macros_msa.h 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948
  1. /*
  2. * Copyright (c) 2015 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef VPX_DSP_MIPS_MACROS_MSA_H_
  11. #define VPX_DSP_MIPS_MACROS_MSA_H_
  12. #include <msa.h>
  13. #include "./vpx_config.h"
  14. #include "vpx/vpx_integer.h"
  15. #define LD_V(RTYPE, psrc) *((const RTYPE *)(psrc))
  16. #define LD_UB(...) LD_V(v16u8, __VA_ARGS__)
  17. #define LD_SB(...) LD_V(v16i8, __VA_ARGS__)
  18. #define LD_UH(...) LD_V(v8u16, __VA_ARGS__)
  19. #define LD_SH(...) LD_V(v8i16, __VA_ARGS__)
  20. #define LD_SW(...) LD_V(v4i32, __VA_ARGS__)
  21. #define ST_V(RTYPE, in, pdst) *((RTYPE *)(pdst)) = (in)
  22. #define ST_UB(...) ST_V(v16u8, __VA_ARGS__)
  23. #define ST_SB(...) ST_V(v16i8, __VA_ARGS__)
  24. #define ST_SH(...) ST_V(v8i16, __VA_ARGS__)
  25. #define ST_SW(...) ST_V(v4i32, __VA_ARGS__)
  26. #if (__mips_isa_rev >= 6)
  27. #define LH(psrc) \
  28. ({ \
  29. uint16_t val_lh_m = *(const uint16_t *)(psrc); \
  30. val_lh_m; \
  31. })
  32. #define LW(psrc) \
  33. ({ \
  34. uint32_t val_lw_m = *(const uint32_t *)(psrc); \
  35. val_lw_m; \
  36. })
  37. #if (__mips == 64)
  38. #define LD(psrc) \
  39. ({ \
  40. uint64_t val_ld_m = *(const uint64_t *)(psrc); \
  41. val_ld_m; \
  42. })
  43. #else // !(__mips == 64)
  44. #define LD(psrc) \
  45. ({ \
  46. const uint8_t *psrc_ld_m = (const uint8_t *)(psrc); \
  47. uint32_t val0_ld_m, val1_ld_m; \
  48. uint64_t val_ld_m = 0; \
  49. \
  50. val0_ld_m = LW(psrc_ld_m); \
  51. val1_ld_m = LW(psrc_ld_m + 4); \
  52. \
  53. val_ld_m = (uint64_t)(val1_ld_m); \
  54. val_ld_m = (uint64_t)((val_ld_m << 32) & 0xFFFFFFFF00000000); \
  55. val_ld_m = (uint64_t)(val_ld_m | (uint64_t)val0_ld_m); \
  56. \
  57. val_ld_m; \
  58. })
  59. #endif // (__mips == 64)
  60. #define SH(val, pdst) *(uint16_t *)(pdst) = (val);
  61. #define SW(val, pdst) *(uint32_t *)(pdst) = (val);
  62. #define SD(val, pdst) *(uint64_t *)(pdst) = (val);
  63. #else // !(__mips_isa_rev >= 6)
  64. #define LH(psrc) \
  65. ({ \
  66. const uint8_t *psrc_lh_m = (const uint8_t *)(psrc); \
  67. uint16_t val_lh_m; \
  68. \
  69. __asm__ __volatile__("ulh %[val_lh_m], %[psrc_lh_m] \n\t" \
  70. \
  71. : [val_lh_m] "=r"(val_lh_m) \
  72. : [psrc_lh_m] "m"(*psrc_lh_m)); \
  73. \
  74. val_lh_m; \
  75. })
  76. #define LW(psrc) \
  77. ({ \
  78. const uint8_t *psrc_lw_m = (const uint8_t *)(psrc); \
  79. uint32_t val_lw_m; \
  80. \
  81. __asm__ __volatile__("ulw %[val_lw_m], %[psrc_lw_m] \n\t" \
  82. \
  83. : [val_lw_m] "=r"(val_lw_m) \
  84. : [psrc_lw_m] "m"(*psrc_lw_m)); \
  85. \
  86. val_lw_m; \
  87. })
  88. #if (__mips == 64)
  89. #define LD(psrc) \
  90. ({ \
  91. const uint8_t *psrc_ld_m = (const uint8_t *)(psrc); \
  92. uint64_t val_ld_m = 0; \
  93. \
  94. __asm__ __volatile__("uld %[val_ld_m], %[psrc_ld_m] \n\t" \
  95. \
  96. : [val_ld_m] "=r"(val_ld_m) \
  97. : [psrc_ld_m] "m"(*psrc_ld_m)); \
  98. \
  99. val_ld_m; \
  100. })
  101. #else // !(__mips == 64)
  102. #define LD(psrc) \
  103. ({ \
  104. const uint8_t *psrc_ld_m = (const uint8_t *)(psrc); \
  105. uint32_t val0_ld_m, val1_ld_m; \
  106. uint64_t val_ld_m = 0; \
  107. \
  108. val0_ld_m = LW(psrc_ld_m); \
  109. val1_ld_m = LW(psrc_ld_m + 4); \
  110. \
  111. val_ld_m = (uint64_t)(val1_ld_m); \
  112. val_ld_m = (uint64_t)((val_ld_m << 32) & 0xFFFFFFFF00000000); \
  113. val_ld_m = (uint64_t)(val_ld_m | (uint64_t)val0_ld_m); \
  114. \
  115. val_ld_m; \
  116. })
  117. #endif // (__mips == 64)
  118. #define SH(val, pdst) \
  119. { \
  120. uint8_t *pdst_sh_m = (uint8_t *)(pdst); \
  121. const uint16_t val_sh_m = (val); \
  122. \
  123. __asm__ __volatile__("ush %[val_sh_m], %[pdst_sh_m] \n\t" \
  124. \
  125. : [pdst_sh_m] "=m"(*pdst_sh_m) \
  126. : [val_sh_m] "r"(val_sh_m)); \
  127. }
  128. #define SW(val, pdst) \
  129. { \
  130. uint8_t *pdst_sw_m = (uint8_t *)(pdst); \
  131. const uint32_t val_sw_m = (val); \
  132. \
  133. __asm__ __volatile__("usw %[val_sw_m], %[pdst_sw_m] \n\t" \
  134. \
  135. : [pdst_sw_m] "=m"(*pdst_sw_m) \
  136. : [val_sw_m] "r"(val_sw_m)); \
  137. }
  138. #define SD(val, pdst) \
  139. { \
  140. uint8_t *pdst_sd_m = (uint8_t *)(pdst); \
  141. uint32_t val0_sd_m, val1_sd_m; \
  142. \
  143. val0_sd_m = (uint32_t)((val)&0x00000000FFFFFFFF); \
  144. val1_sd_m = (uint32_t)(((val) >> 32) & 0x00000000FFFFFFFF); \
  145. \
  146. SW(val0_sd_m, pdst_sd_m); \
  147. SW(val1_sd_m, pdst_sd_m + 4); \
  148. }
  149. #endif // (__mips_isa_rev >= 6)
  150. /* Description : Load 4 words with stride
  151. Arguments : Inputs - psrc, stride
  152. Outputs - out0, out1, out2, out3
  153. Details : Load word in 'out0' from (psrc)
  154. Load word in 'out1' from (psrc + stride)
  155. Load word in 'out2' from (psrc + 2 * stride)
  156. Load word in 'out3' from (psrc + 3 * stride)
  157. */
  158. #define LW4(psrc, stride, out0, out1, out2, out3) \
  159. { \
  160. out0 = LW((psrc)); \
  161. out1 = LW((psrc) + stride); \
  162. out2 = LW((psrc) + 2 * stride); \
  163. out3 = LW((psrc) + 3 * stride); \
  164. }
  165. /* Description : Load double words with stride
  166. Arguments : Inputs - psrc, stride
  167. Outputs - out0, out1
  168. Details : Load double word in 'out0' from (psrc)
  169. Load double word in 'out1' from (psrc + stride)
  170. */
  171. #define LD2(psrc, stride, out0, out1) \
  172. { \
  173. out0 = LD((psrc)); \
  174. out1 = LD((psrc) + stride); \
  175. }
  176. #define LD4(psrc, stride, out0, out1, out2, out3) \
  177. { \
  178. LD2((psrc), stride, out0, out1); \
  179. LD2((psrc) + 2 * stride, stride, out2, out3); \
  180. }
  181. /* Description : Store 4 words with stride
  182. Arguments : Inputs - in0, in1, in2, in3, pdst, stride
  183. Details : Store word from 'in0' to (pdst)
  184. Store word from 'in1' to (pdst + stride)
  185. Store word from 'in2' to (pdst + 2 * stride)
  186. Store word from 'in3' to (pdst + 3 * stride)
  187. */
  188. #define SW4(in0, in1, in2, in3, pdst, stride) \
  189. { \
  190. SW(in0, (pdst)) \
  191. SW(in1, (pdst) + stride); \
  192. SW(in2, (pdst) + 2 * stride); \
  193. SW(in3, (pdst) + 3 * stride); \
  194. }
  195. /* Description : Store 4 double words with stride
  196. Arguments : Inputs - in0, in1, in2, in3, pdst, stride
  197. Details : Store double word from 'in0' to (pdst)
  198. Store double word from 'in1' to (pdst + stride)
  199. Store double word from 'in2' to (pdst + 2 * stride)
  200. Store double word from 'in3' to (pdst + 3 * stride)
  201. */
  202. #define SD4(in0, in1, in2, in3, pdst, stride) \
  203. { \
  204. SD(in0, (pdst)) \
  205. SD(in1, (pdst) + stride); \
  206. SD(in2, (pdst) + 2 * stride); \
  207. SD(in3, (pdst) + 3 * stride); \
  208. }
  209. /* Description : Load vector elements with stride
  210. Arguments : Inputs - psrc, stride
  211. Outputs - out0, out1
  212. Return Type - as per RTYPE
  213. Details : Load 16 byte elements in 'out0' from (psrc)
  214. Load 16 byte elements in 'out1' from (psrc + stride)
  215. */
  216. #define LD_V2(RTYPE, psrc, stride, out0, out1) \
  217. { \
  218. out0 = LD_V(RTYPE, (psrc)); \
  219. out1 = LD_V(RTYPE, (psrc) + stride); \
  220. }
  221. #define LD_UB2(...) LD_V2(v16u8, __VA_ARGS__)
  222. #define LD_SB2(...) LD_V2(v16i8, __VA_ARGS__)
  223. #define LD_SH2(...) LD_V2(v8i16, __VA_ARGS__)
  224. #define LD_SW2(...) LD_V2(v4i32, __VA_ARGS__)
  225. #define LD_V3(RTYPE, psrc, stride, out0, out1, out2) \
  226. { \
  227. LD_V2(RTYPE, (psrc), stride, out0, out1); \
  228. out2 = LD_V(RTYPE, (psrc) + 2 * stride); \
  229. }
  230. #define LD_UB3(...) LD_V3(v16u8, __VA_ARGS__)
  231. #define LD_V4(RTYPE, psrc, stride, out0, out1, out2, out3) \
  232. { \
  233. LD_V2(RTYPE, (psrc), stride, out0, out1); \
  234. LD_V2(RTYPE, (psrc) + 2 * stride, stride, out2, out3); \
  235. }
  236. #define LD_UB4(...) LD_V4(v16u8, __VA_ARGS__)
  237. #define LD_SB4(...) LD_V4(v16i8, __VA_ARGS__)
  238. #define LD_SH4(...) LD_V4(v8i16, __VA_ARGS__)
  239. #define LD_V5(RTYPE, psrc, stride, out0, out1, out2, out3, out4) \
  240. { \
  241. LD_V4(RTYPE, (psrc), stride, out0, out1, out2, out3); \
  242. out4 = LD_V(RTYPE, (psrc) + 4 * stride); \
  243. }
  244. #define LD_UB5(...) LD_V5(v16u8, __VA_ARGS__)
  245. #define LD_SB5(...) LD_V5(v16i8, __VA_ARGS__)
  246. #define LD_V7(RTYPE, psrc, stride, out0, out1, out2, out3, out4, out5, out6) \
  247. { \
  248. LD_V5(RTYPE, (psrc), stride, out0, out1, out2, out3, out4); \
  249. LD_V2(RTYPE, (psrc) + 5 * stride, stride, out5, out6); \
  250. }
  251. #define LD_SB7(...) LD_V7(v16i8, __VA_ARGS__)
  252. #define LD_V8(RTYPE, psrc, stride, out0, out1, out2, out3, out4, out5, out6, \
  253. out7) \
  254. { \
  255. LD_V4(RTYPE, (psrc), stride, out0, out1, out2, out3); \
  256. LD_V4(RTYPE, (psrc) + 4 * stride, stride, out4, out5, out6, out7); \
  257. }
  258. #define LD_UB8(...) LD_V8(v16u8, __VA_ARGS__)
  259. #define LD_SB8(...) LD_V8(v16i8, __VA_ARGS__)
  260. #define LD_SH8(...) LD_V8(v8i16, __VA_ARGS__)
  261. #define LD_V16(RTYPE, psrc, stride, out0, out1, out2, out3, out4, out5, out6, \
  262. out7, out8, out9, out10, out11, out12, out13, out14, out15) \
  263. { \
  264. LD_V8(RTYPE, (psrc), stride, out0, out1, out2, out3, out4, out5, out6, \
  265. out7); \
  266. LD_V8(RTYPE, (psrc) + 8 * stride, stride, out8, out9, out10, out11, out12, \
  267. out13, out14, out15); \
  268. }
  269. #define LD_SH16(...) LD_V16(v8i16, __VA_ARGS__)
  270. /* Description : Load 4x4 block of signed halfword elements from 1D source
  271. data into 4 vectors (Each vector with 4 signed halfwords)
  272. Arguments : Input - psrc
  273. Outputs - out0, out1, out2, out3
  274. */
  275. #define LD4x4_SH(psrc, out0, out1, out2, out3) \
  276. { \
  277. out0 = LD_SH(psrc); \
  278. out2 = LD_SH(psrc + 8); \
  279. out1 = (v8i16)__msa_ilvl_d((v2i64)out0, (v2i64)out0); \
  280. out3 = (v8i16)__msa_ilvl_d((v2i64)out2, (v2i64)out2); \
  281. }
  282. /* Description : Store vectors with stride
  283. Arguments : Inputs - in0, in1, pdst, stride
  284. Details : Store 16 byte elements from 'in0' to (pdst)
  285. Store 16 byte elements from 'in1' to (pdst + stride)
  286. */
  287. #define ST_V2(RTYPE, in0, in1, pdst, stride) \
  288. { \
  289. ST_V(RTYPE, in0, (pdst)); \
  290. ST_V(RTYPE, in1, (pdst) + stride); \
  291. }
  292. #define ST_UB2(...) ST_V2(v16u8, __VA_ARGS__)
  293. #define ST_SH2(...) ST_V2(v8i16, __VA_ARGS__)
  294. #define ST_SW2(...) ST_V2(v4i32, __VA_ARGS__)
  295. #define ST_V4(RTYPE, in0, in1, in2, in3, pdst, stride) \
  296. { \
  297. ST_V2(RTYPE, in0, in1, (pdst), stride); \
  298. ST_V2(RTYPE, in2, in3, (pdst) + 2 * stride, stride); \
  299. }
  300. #define ST_UB4(...) ST_V4(v16u8, __VA_ARGS__)
  301. #define ST_SH4(...) ST_V4(v8i16, __VA_ARGS__)
  302. #define ST_V8(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, pdst, stride) \
  303. { \
  304. ST_V4(RTYPE, in0, in1, in2, in3, pdst, stride); \
  305. ST_V4(RTYPE, in4, in5, in6, in7, (pdst) + 4 * stride, stride); \
  306. }
  307. #define ST_UB8(...) ST_V8(v16u8, __VA_ARGS__)
  308. #define ST_SH8(...) ST_V8(v8i16, __VA_ARGS__)
  309. /* Description : Store 2x4 byte block to destination memory from input vector
  310. Arguments : Inputs - in, stidx, pdst, stride
  311. Details : Index 'stidx' halfword element from 'in' vector is copied to
  312. the GP register and stored to (pdst)
  313. Index 'stidx+1' halfword element from 'in' vector is copied to
  314. the GP register and stored to (pdst + stride)
  315. Index 'stidx+2' halfword element from 'in' vector is copied to
  316. the GP register and stored to (pdst + 2 * stride)
  317. Index 'stidx+3' halfword element from 'in' vector is copied to
  318. the GP register and stored to (pdst + 3 * stride)
  319. */
  320. #define ST2x4_UB(in, stidx, pdst, stride) \
  321. { \
  322. uint16_t out0_m, out1_m, out2_m, out3_m; \
  323. uint8_t *pblk_2x4_m = (uint8_t *)(pdst); \
  324. \
  325. out0_m = __msa_copy_u_h((v8i16)in, (stidx)); \
  326. out1_m = __msa_copy_u_h((v8i16)in, (stidx + 1)); \
  327. out2_m = __msa_copy_u_h((v8i16)in, (stidx + 2)); \
  328. out3_m = __msa_copy_u_h((v8i16)in, (stidx + 3)); \
  329. \
  330. SH(out0_m, pblk_2x4_m); \
  331. SH(out1_m, pblk_2x4_m + stride); \
  332. SH(out2_m, pblk_2x4_m + 2 * stride); \
  333. SH(out3_m, pblk_2x4_m + 3 * stride); \
  334. }
  335. /* Description : Store 4x2 byte block to destination memory from input vector
  336. Arguments : Inputs - in, pdst, stride
  337. Details : Index 0 word element from 'in' vector is copied to the GP
  338. register and stored to (pdst)
  339. Index 1 word element from 'in' vector is copied to the GP
  340. register and stored to (pdst + stride)
  341. */
  342. #define ST4x2_UB(in, pdst, stride) \
  343. { \
  344. uint32_t out0_m, out1_m; \
  345. uint8_t *pblk_4x2_m = (uint8_t *)(pdst); \
  346. \
  347. out0_m = __msa_copy_u_w((v4i32)in, 0); \
  348. out1_m = __msa_copy_u_w((v4i32)in, 1); \
  349. \
  350. SW(out0_m, pblk_4x2_m); \
  351. SW(out1_m, pblk_4x2_m + stride); \
  352. }
  353. /* Description : Store 4x4 byte block to destination memory from input vector
  354. Arguments : Inputs - in0, in1, pdst, stride
  355. Details : 'Idx0' word element from input vector 'in0' is copied to the
  356. GP register and stored to (pdst)
  357. 'Idx1' word element from input vector 'in0' is copied to the
  358. GP register and stored to (pdst + stride)
  359. 'Idx2' word element from input vector 'in0' is copied to the
  360. GP register and stored to (pdst + 2 * stride)
  361. 'Idx3' word element from input vector 'in0' is copied to the
  362. GP register and stored to (pdst + 3 * stride)
  363. */
  364. #define ST4x4_UB(in0, in1, idx0, idx1, idx2, idx3, pdst, stride) \
  365. { \
  366. uint32_t out0_m, out1_m, out2_m, out3_m; \
  367. uint8_t *pblk_4x4_m = (uint8_t *)(pdst); \
  368. \
  369. out0_m = __msa_copy_u_w((v4i32)in0, idx0); \
  370. out1_m = __msa_copy_u_w((v4i32)in0, idx1); \
  371. out2_m = __msa_copy_u_w((v4i32)in1, idx2); \
  372. out3_m = __msa_copy_u_w((v4i32)in1, idx3); \
  373. \
  374. SW4(out0_m, out1_m, out2_m, out3_m, pblk_4x4_m, stride); \
  375. }
  376. #define ST4x8_UB(in0, in1, pdst, stride) \
  377. { \
  378. uint8_t *pblk_4x8 = (uint8_t *)(pdst); \
  379. \
  380. ST4x4_UB(in0, in0, 0, 1, 2, 3, pblk_4x8, stride); \
  381. ST4x4_UB(in1, in1, 0, 1, 2, 3, pblk_4x8 + 4 * stride, stride); \
  382. }
  383. /* Description : Store 8x1 byte block to destination memory from input vector
  384. Arguments : Inputs - in, pdst
  385. Details : Index 0 double word element from 'in' vector is copied to the
  386. GP register and stored to (pdst)
  387. */
  388. #define ST8x1_UB(in, pdst) \
  389. { \
  390. uint64_t out0_m; \
  391. \
  392. out0_m = __msa_copy_u_d((v2i64)in, 0); \
  393. SD(out0_m, pdst); \
  394. }
  395. /* Description : Store 8x2 byte block to destination memory from input vector
  396. Arguments : Inputs - in, pdst, stride
  397. Details : Index 0 double word element from 'in' vector is copied to the
  398. GP register and stored to (pdst)
  399. Index 1 double word element from 'in' vector is copied to the
  400. GP register and stored to (pdst + stride)
  401. */
  402. #define ST8x2_UB(in, pdst, stride) \
  403. { \
  404. uint64_t out0_m, out1_m; \
  405. uint8_t *pblk_8x2_m = (uint8_t *)(pdst); \
  406. \
  407. out0_m = __msa_copy_u_d((v2i64)in, 0); \
  408. out1_m = __msa_copy_u_d((v2i64)in, 1); \
  409. \
  410. SD(out0_m, pblk_8x2_m); \
  411. SD(out1_m, pblk_8x2_m + stride); \
  412. }
  413. /* Description : Store 8x4 byte block to destination memory from input
  414. vectors
  415. Arguments : Inputs - in0, in1, pdst, stride
  416. Details : Index 0 double word element from 'in0' vector is copied to the
  417. GP register and stored to (pdst)
  418. Index 1 double word element from 'in0' vector is copied to the
  419. GP register and stored to (pdst + stride)
  420. Index 0 double word element from 'in1' vector is copied to the
  421. GP register and stored to (pdst + 2 * stride)
  422. Index 1 double word element from 'in1' vector is copied to the
  423. GP register and stored to (pdst + 3 * stride)
  424. */
  425. #define ST8x4_UB(in0, in1, pdst, stride) \
  426. { \
  427. uint64_t out0_m, out1_m, out2_m, out3_m; \
  428. uint8_t *pblk_8x4_m = (uint8_t *)(pdst); \
  429. \
  430. out0_m = __msa_copy_u_d((v2i64)in0, 0); \
  431. out1_m = __msa_copy_u_d((v2i64)in0, 1); \
  432. out2_m = __msa_copy_u_d((v2i64)in1, 0); \
  433. out3_m = __msa_copy_u_d((v2i64)in1, 1); \
  434. \
  435. SD4(out0_m, out1_m, out2_m, out3_m, pblk_8x4_m, stride); \
  436. }
  437. /* Description : average with rounding (in0 + in1 + 1) / 2.
  438. Arguments : Inputs - in0, in1, in2, in3,
  439. Outputs - out0, out1
  440. Return Type - as per RTYPE
  441. Details : Each unsigned byte element from 'in0' vector is added with
  442. each unsigned byte element from 'in1' vector. Then the average
  443. with rounding is calculated and written to 'out0'
  444. */
  445. #define AVER_UB2(RTYPE, in0, in1, in2, in3, out0, out1) \
  446. { \
  447. out0 = (RTYPE)__msa_aver_u_b((v16u8)in0, (v16u8)in1); \
  448. out1 = (RTYPE)__msa_aver_u_b((v16u8)in2, (v16u8)in3); \
  449. }
  450. #define AVER_UB2_UB(...) AVER_UB2(v16u8, __VA_ARGS__)
  451. #define AVER_UB4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  452. out2, out3) \
  453. { \
  454. AVER_UB2(RTYPE, in0, in1, in2, in3, out0, out1) \
  455. AVER_UB2(RTYPE, in4, in5, in6, in7, out2, out3) \
  456. }
  457. #define AVER_UB4_UB(...) AVER_UB4(v16u8, __VA_ARGS__)
  458. /* Description : Immediate number of elements to slide with zero
  459. Arguments : Inputs - in0, in1, slide_val
  460. Outputs - out0, out1
  461. Return Type - as per RTYPE
  462. Details : Byte elements from 'zero_m' vector are slid into 'in0' by
  463. value specified in the 'slide_val'
  464. */
  465. #define SLDI_B2_0(RTYPE, in0, in1, out0, out1, slide_val) \
  466. { \
  467. v16i8 zero_m = { 0 }; \
  468. out0 = (RTYPE)__msa_sldi_b((v16i8)zero_m, (v16i8)in0, slide_val); \
  469. out1 = (RTYPE)__msa_sldi_b((v16i8)zero_m, (v16i8)in1, slide_val); \
  470. }
  471. #define SLDI_B2_0_SW(...) SLDI_B2_0(v4i32, __VA_ARGS__)
  472. #define SLDI_B4_0(RTYPE, in0, in1, in2, in3, out0, out1, out2, out3, \
  473. slide_val) \
  474. { \
  475. SLDI_B2_0(RTYPE, in0, in1, out0, out1, slide_val); \
  476. SLDI_B2_0(RTYPE, in2, in3, out2, out3, slide_val); \
  477. }
  478. #define SLDI_B4_0_UB(...) SLDI_B4_0(v16u8, __VA_ARGS__)
  479. /* Description : Immediate number of elements to slide
  480. Arguments : Inputs - in0_0, in0_1, in1_0, in1_1, slide_val
  481. Outputs - out0, out1
  482. Return Type - as per RTYPE
  483. Details : Byte elements from 'in0_0' vector are slid into 'in1_0' by
  484. value specified in the 'slide_val'
  485. */
  486. #define SLDI_B2(RTYPE, in0_0, in0_1, in1_0, in1_1, out0, out1, slide_val) \
  487. { \
  488. out0 = (RTYPE)__msa_sldi_b((v16i8)in0_0, (v16i8)in1_0, slide_val); \
  489. out1 = (RTYPE)__msa_sldi_b((v16i8)in0_1, (v16i8)in1_1, slide_val); \
  490. }
  491. #define SLDI_B2_UB(...) SLDI_B2(v16u8, __VA_ARGS__)
  492. #define SLDI_B2_SH(...) SLDI_B2(v8i16, __VA_ARGS__)
  493. #define SLDI_B3(RTYPE, in0_0, in0_1, in0_2, in1_0, in1_1, in1_2, out0, out1, \
  494. out2, slide_val) \
  495. { \
  496. SLDI_B2(RTYPE, in0_0, in0_1, in1_0, in1_1, out0, out1, slide_val) \
  497. out2 = (RTYPE)__msa_sldi_b((v16i8)in0_2, (v16i8)in1_2, slide_val); \
  498. }
  499. #define SLDI_B3_SB(...) SLDI_B3(v16i8, __VA_ARGS__)
  500. #define SLDI_B3_UH(...) SLDI_B3(v8u16, __VA_ARGS__)
  501. /* Description : Shuffle byte vector elements as per mask vector
  502. Arguments : Inputs - in0, in1, in2, in3, mask0, mask1
  503. Outputs - out0, out1
  504. Return Type - as per RTYPE
  505. Details : Byte elements from 'in0' & 'in1' are copied selectively to
  506. 'out0' as per control vector 'mask0'
  507. */
  508. #define VSHF_B2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1) \
  509. { \
  510. out0 = (RTYPE)__msa_vshf_b((v16i8)mask0, (v16i8)in1, (v16i8)in0); \
  511. out1 = (RTYPE)__msa_vshf_b((v16i8)mask1, (v16i8)in3, (v16i8)in2); \
  512. }
  513. #define VSHF_B2_UB(...) VSHF_B2(v16u8, __VA_ARGS__)
  514. #define VSHF_B2_SB(...) VSHF_B2(v16i8, __VA_ARGS__)
  515. #define VSHF_B2_UH(...) VSHF_B2(v8u16, __VA_ARGS__)
  516. #define VSHF_B4(RTYPE, in0, in1, mask0, mask1, mask2, mask3, out0, out1, out2, \
  517. out3) \
  518. { \
  519. VSHF_B2(RTYPE, in0, in1, in0, in1, mask0, mask1, out0, out1); \
  520. VSHF_B2(RTYPE, in0, in1, in0, in1, mask2, mask3, out2, out3); \
  521. }
  522. #define VSHF_B4_SB(...) VSHF_B4(v16i8, __VA_ARGS__)
  523. #define VSHF_B4_SH(...) VSHF_B4(v8i16, __VA_ARGS__)
  524. /* Description : Dot product of byte vector elements
  525. Arguments : Inputs - mult0, mult1, cnst0, cnst1
  526. Outputs - out0, out1
  527. Return Type - as per RTYPE
  528. Details : Unsigned byte elements from 'mult0' are multiplied with
  529. unsigned byte elements from 'cnst0' producing a result
  530. twice the size of input i.e. unsigned halfword.
  531. The multiplication result of adjacent odd-even elements
  532. are added together and written to the 'out0' vector
  533. */
  534. #define DOTP_UB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  535. { \
  536. out0 = (RTYPE)__msa_dotp_u_h((v16u8)mult0, (v16u8)cnst0); \
  537. out1 = (RTYPE)__msa_dotp_u_h((v16u8)mult1, (v16u8)cnst1); \
  538. }
  539. #define DOTP_UB2_UH(...) DOTP_UB2(v8u16, __VA_ARGS__)
  540. #define DOTP_UB4(RTYPE, mult0, mult1, mult2, mult3, cnst0, cnst1, cnst2, \
  541. cnst3, out0, out1, out2, out3) \
  542. { \
  543. DOTP_UB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  544. DOTP_UB2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  545. }
  546. #define DOTP_UB4_UH(...) DOTP_UB4(v8u16, __VA_ARGS__)
  547. /* Description : Dot product of byte vector elements
  548. Arguments : Inputs - mult0, mult1, cnst0, cnst1
  549. Outputs - out0, out1
  550. Return Type - as per RTYPE
  551. Details : Signed byte elements from 'mult0' are multiplied with
  552. signed byte elements from 'cnst0' producing a result
  553. twice the size of input i.e. signed halfword.
  554. The multiplication result of adjacent odd-even elements
  555. are added together and written to the 'out0' vector
  556. */
  557. #define DOTP_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  558. { \
  559. out0 = (RTYPE)__msa_dotp_s_h((v16i8)mult0, (v16i8)cnst0); \
  560. out1 = (RTYPE)__msa_dotp_s_h((v16i8)mult1, (v16i8)cnst1); \
  561. }
  562. #define DOTP_SB2_SH(...) DOTP_SB2(v8i16, __VA_ARGS__)
  563. #define DOTP_SB4(RTYPE, mult0, mult1, mult2, mult3, cnst0, cnst1, cnst2, \
  564. cnst3, out0, out1, out2, out3) \
  565. { \
  566. DOTP_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  567. DOTP_SB2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  568. }
  569. #define DOTP_SB4_SH(...) DOTP_SB4(v8i16, __VA_ARGS__)
  570. /* Description : Dot product of halfword vector elements
  571. Arguments : Inputs - mult0, mult1, cnst0, cnst1
  572. Outputs - out0, out1
  573. Return Type - as per RTYPE
  574. Details : Signed halfword elements from 'mult0' are multiplied with
  575. signed halfword elements from 'cnst0' producing a result
  576. twice the size of input i.e. signed word.
  577. The multiplication result of adjacent odd-even elements
  578. are added together and written to the 'out0' vector
  579. */
  580. #define DOTP_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  581. { \
  582. out0 = (RTYPE)__msa_dotp_s_w((v8i16)mult0, (v8i16)cnst0); \
  583. out1 = (RTYPE)__msa_dotp_s_w((v8i16)mult1, (v8i16)cnst1); \
  584. }
  585. #define DOTP_SH2_SW(...) DOTP_SH2(v4i32, __VA_ARGS__)
  586. #define DOTP_SH4(RTYPE, mult0, mult1, mult2, mult3, cnst0, cnst1, cnst2, \
  587. cnst3, out0, out1, out2, out3) \
  588. { \
  589. DOTP_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  590. DOTP_SH2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  591. }
  592. #define DOTP_SH4_SW(...) DOTP_SH4(v4i32, __VA_ARGS__)
  593. /* Description : Dot product of word vector elements
  594. Arguments : Inputs - mult0, mult1, cnst0, cnst1
  595. Outputs - out0, out1
  596. Return Type - as per RTYPE
  597. Details : Signed word elements from 'mult0' are multiplied with
  598. signed word elements from 'cnst0' producing a result
  599. twice the size of input i.e. signed double word.
  600. The multiplication result of adjacent odd-even elements
  601. are added together and written to the 'out0' vector
  602. */
  603. #define DOTP_SW2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  604. { \
  605. out0 = (RTYPE)__msa_dotp_s_d((v4i32)mult0, (v4i32)cnst0); \
  606. out1 = (RTYPE)__msa_dotp_s_d((v4i32)mult1, (v4i32)cnst1); \
  607. }
  608. #define DOTP_SW2_SD(...) DOTP_SW2(v2i64, __VA_ARGS__)
  609. /* Description : Dot product & addition of byte vector elements
  610. Arguments : Inputs - mult0, mult1, cnst0, cnst1
  611. Outputs - out0, out1
  612. Return Type - as per RTYPE
  613. Details : Signed byte elements from 'mult0' are multiplied with
  614. signed byte elements from 'cnst0' producing a result
  615. twice the size of input i.e. signed halfword.
  616. The multiplication result of adjacent odd-even elements
  617. are added to the 'out0' vector
  618. */
  619. #define DPADD_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  620. { \
  621. out0 = (RTYPE)__msa_dpadd_s_h((v8i16)out0, (v16i8)mult0, (v16i8)cnst0); \
  622. out1 = (RTYPE)__msa_dpadd_s_h((v8i16)out1, (v16i8)mult1, (v16i8)cnst1); \
  623. }
  624. #define DPADD_SB2_SH(...) DPADD_SB2(v8i16, __VA_ARGS__)
  625. #define DPADD_SB4(RTYPE, mult0, mult1, mult2, mult3, cnst0, cnst1, cnst2, \
  626. cnst3, out0, out1, out2, out3) \
  627. { \
  628. DPADD_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  629. DPADD_SB2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  630. }
  631. #define DPADD_SB4_SH(...) DPADD_SB4(v8i16, __VA_ARGS__)
  632. /* Description : Dot product & addition of halfword vector elements
  633. Arguments : Inputs - mult0, mult1, cnst0, cnst1
  634. Outputs - out0, out1
  635. Return Type - as per RTYPE
  636. Details : Signed halfword elements from 'mult0' are multiplied with
  637. signed halfword elements from 'cnst0' producing a result
  638. twice the size of input i.e. signed word.
  639. The multiplication result of adjacent odd-even elements
  640. are added to the 'out0' vector
  641. */
  642. #define DPADD_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  643. { \
  644. out0 = (RTYPE)__msa_dpadd_s_w((v4i32)out0, (v8i16)mult0, (v8i16)cnst0); \
  645. out1 = (RTYPE)__msa_dpadd_s_w((v4i32)out1, (v8i16)mult1, (v8i16)cnst1); \
  646. }
  647. #define DPADD_SH2_SW(...) DPADD_SH2(v4i32, __VA_ARGS__)
  648. /* Description : Dot product & addition of double word vector elements
  649. Arguments : Inputs - mult0, mult1
  650. Outputs - out0, out1
  651. Return Type - as per RTYPE
  652. Details : Each signed word element from 'mult0' is multiplied with itself
  653. producing an intermediate result twice the size of input
  654. i.e. signed double word
  655. The multiplication result of adjacent odd-even elements
  656. are added to the 'out0' vector
  657. */
  658. #define DPADD_SD2(RTYPE, mult0, mult1, out0, out1) \
  659. { \
  660. out0 = (RTYPE)__msa_dpadd_s_d((v2i64)out0, (v4i32)mult0, (v4i32)mult0); \
  661. out1 = (RTYPE)__msa_dpadd_s_d((v2i64)out1, (v4i32)mult1, (v4i32)mult1); \
  662. }
  663. #define DPADD_SD2_SD(...) DPADD_SD2(v2i64, __VA_ARGS__)
  664. /* Description : Minimum values between unsigned elements of
  665. either vector are copied to the output vector
  666. Arguments : Inputs - in0, in1, min_vec
  667. Outputs - in place operation
  668. Return Type - as per RTYPE
  669. Details : Minimum of unsigned halfword element values from 'in0' and
  670. 'min_vec' are written to output vector 'in0'
  671. */
  672. #define MIN_UH2(RTYPE, in0, in1, min_vec) \
  673. { \
  674. in0 = (RTYPE)__msa_min_u_h((v8u16)in0, min_vec); \
  675. in1 = (RTYPE)__msa_min_u_h((v8u16)in1, min_vec); \
  676. }
  677. #define MIN_UH2_UH(...) MIN_UH2(v8u16, __VA_ARGS__)
  678. #define MIN_UH4(RTYPE, in0, in1, in2, in3, min_vec) \
  679. { \
  680. MIN_UH2(RTYPE, in0, in1, min_vec); \
  681. MIN_UH2(RTYPE, in2, in3, min_vec); \
  682. }
  683. #define MIN_UH4_UH(...) MIN_UH4(v8u16, __VA_ARGS__)
  684. /* Description : Clips all signed halfword elements of input vector
  685. between 0 & 255
  686. Arguments : Input - in
  687. Output - out_m
  688. Return Type - signed halfword
  689. */
  690. #define CLIP_SH_0_255(in) \
  691. ({ \
  692. v8i16 max_m = __msa_ldi_h(255); \
  693. v8i16 out_m; \
  694. \
  695. out_m = __msa_maxi_s_h((v8i16)in, 0); \
  696. out_m = __msa_min_s_h((v8i16)max_m, (v8i16)out_m); \
  697. out_m; \
  698. })
  699. #define CLIP_SH2_0_255(in0, in1) \
  700. { \
  701. in0 = CLIP_SH_0_255(in0); \
  702. in1 = CLIP_SH_0_255(in1); \
  703. }
  704. #define CLIP_SH4_0_255(in0, in1, in2, in3) \
  705. { \
  706. CLIP_SH2_0_255(in0, in1); \
  707. CLIP_SH2_0_255(in2, in3); \
  708. }
  709. /* Description : Horizontal addition of 4 signed word elements of input vector
  710. Arguments : Input - in (signed word vector)
  711. Output - sum_m (i32 sum)
  712. Return Type - signed word (GP)
  713. Details : 4 signed word elements of 'in' vector are added together and
  714. the resulting integer sum is returned
  715. */
  716. #define HADD_SW_S32(in) \
  717. ({ \
  718. v2i64 res0_m, res1_m; \
  719. int32_t sum_m; \
  720. \
  721. res0_m = __msa_hadd_s_d((v4i32)in, (v4i32)in); \
  722. res1_m = __msa_splati_d(res0_m, 1); \
  723. res0_m = res0_m + res1_m; \
  724. sum_m = __msa_copy_s_w((v4i32)res0_m, 0); \
  725. sum_m; \
  726. })
  727. /* Description : Horizontal addition of 4 unsigned word elements
  728. Arguments : Input - in (unsigned word vector)
  729. Output - sum_m (u32 sum)
  730. Return Type - unsigned word (GP)
  731. Details : 4 unsigned word elements of 'in' vector are added together and
  732. the resulting integer sum is returned
  733. */
  734. #define HADD_UW_U32(in) \
  735. ({ \
  736. v2u64 res0_m, res1_m; \
  737. uint32_t sum_m; \
  738. \
  739. res0_m = __msa_hadd_u_d((v4u32)in, (v4u32)in); \
  740. res1_m = (v2u64)__msa_splati_d((v2i64)res0_m, 1); \
  741. res0_m += res1_m; \
  742. sum_m = __msa_copy_u_w((v4i32)res0_m, 0); \
  743. sum_m; \
  744. })
  745. /* Description : Horizontal addition of 8 unsigned halfword elements
  746. Arguments : Input - in (unsigned halfword vector)
  747. Output - sum_m (u32 sum)
  748. Return Type - unsigned word
  749. Details : 8 unsigned halfword elements of 'in' vector are added
  750. together and the resulting integer sum is returned
  751. */
  752. #define HADD_UH_U32(in) \
  753. ({ \
  754. v4u32 res_m; \
  755. uint32_t sum_m; \
  756. \
  757. res_m = __msa_hadd_u_w((v8u16)in, (v8u16)in); \
  758. sum_m = HADD_UW_U32(res_m); \
  759. sum_m; \
  760. })
  761. /* Description : Horizontal addition of unsigned byte vector elements
  762. Arguments : Inputs - in0, in1
  763. Outputs - out0, out1
  764. Return Type - as per RTYPE
  765. Details : Each unsigned odd byte element from 'in0' is added to
  766. even unsigned byte element from 'in0' (pairwise) and the
  767. halfword result is written to 'out0'
  768. */
  769. #define HADD_UB2(RTYPE, in0, in1, out0, out1) \
  770. { \
  771. out0 = (RTYPE)__msa_hadd_u_h((v16u8)in0, (v16u8)in0); \
  772. out1 = (RTYPE)__msa_hadd_u_h((v16u8)in1, (v16u8)in1); \
  773. }
  774. #define HADD_UB2_UH(...) HADD_UB2(v8u16, __VA_ARGS__)
  775. #define HADD_UB4(RTYPE, in0, in1, in2, in3, out0, out1, out2, out3) \
  776. { \
  777. HADD_UB2(RTYPE, in0, in1, out0, out1); \
  778. HADD_UB2(RTYPE, in2, in3, out2, out3); \
  779. }
  780. #define HADD_UB4_UH(...) HADD_UB4(v8u16, __VA_ARGS__)
  781. /* Description : Horizontal subtraction of unsigned byte vector elements
  782. Arguments : Inputs - in0, in1
  783. Outputs - out0, out1
  784. Return Type - as per RTYPE
  785. Details : Each unsigned odd byte element from 'in0' is subtracted from
  786. even unsigned byte element from 'in0' (pairwise) and the
  787. halfword result is written to 'out0'
  788. */
  789. #define HSUB_UB2(RTYPE, in0, in1, out0, out1) \
  790. { \
  791. out0 = (RTYPE)__msa_hsub_u_h((v16u8)in0, (v16u8)in0); \
  792. out1 = (RTYPE)__msa_hsub_u_h((v16u8)in1, (v16u8)in1); \
  793. }
  794. #define HSUB_UB2_SH(...) HSUB_UB2(v8i16, __VA_ARGS__)
  795. /* Description : SAD (Sum of Absolute Difference)
  796. Arguments : Inputs - in0, in1, ref0, ref1
  797. Outputs - sad_m (halfword vector)
  798. Return Type - unsigned halfword
  799. Details : Absolute difference of all the byte elements from 'in0' with
  800. 'ref0' is calculated and preserved in 'diff0'. Then even-odd
  801. pairs are added together to generate 8 halfword results.
  802. */
  803. #define SAD_UB2_UH(in0, in1, ref0, ref1) \
  804. ({ \
  805. v16u8 diff0_m, diff1_m; \
  806. v8u16 sad_m = { 0 }; \
  807. \
  808. diff0_m = __msa_asub_u_b((v16u8)in0, (v16u8)ref0); \
  809. diff1_m = __msa_asub_u_b((v16u8)in1, (v16u8)ref1); \
  810. \
  811. sad_m += __msa_hadd_u_h((v16u8)diff0_m, (v16u8)diff0_m); \
  812. sad_m += __msa_hadd_u_h((v16u8)diff1_m, (v16u8)diff1_m); \
  813. \
  814. sad_m; \
  815. })
  816. /* Description : Horizontal subtraction of signed halfword vector elements
  817. Arguments : Inputs - in0, in1
  818. Outputs - out0, out1
  819. Return Type - as per RTYPE
  820. Details : Each signed odd halfword element from 'in0' is subtracted from
  821. even signed halfword element from 'in0' (pairwise) and the
  822. word result is written to 'out0'
  823. */
  824. #define HSUB_UH2(RTYPE, in0, in1, out0, out1) \
  825. { \
  826. out0 = (RTYPE)__msa_hsub_s_w((v8i16)in0, (v8i16)in0); \
  827. out1 = (RTYPE)__msa_hsub_s_w((v8i16)in1, (v8i16)in1); \
  828. }
  829. #define HSUB_UH2_SW(...) HSUB_UH2(v4i32, __VA_ARGS__)
  830. /* Description : Set element n input vector to GPR value
  831. Arguments : Inputs - in0, in1, in2, in3
  832. Output - out
  833. Return Type - as per RTYPE
  834. Details : Set element 0 in vector 'out' to value specified in 'in0'
  835. */
  836. #define INSERT_W2(RTYPE, in0, in1, out) \
  837. { \
  838. out = (RTYPE)__msa_insert_w((v4i32)out, 0, in0); \
  839. out = (RTYPE)__msa_insert_w((v4i32)out, 1, in1); \
  840. }
  841. #define INSERT_W2_SB(...) INSERT_W2(v16i8, __VA_ARGS__)
  842. #define INSERT_W4(RTYPE, in0, in1, in2, in3, out) \
  843. { \
  844. out = (RTYPE)__msa_insert_w((v4i32)out, 0, in0); \
  845. out = (RTYPE)__msa_insert_w((v4i32)out, 1, in1); \
  846. out = (RTYPE)__msa_insert_w((v4i32)out, 2, in2); \
  847. out = (RTYPE)__msa_insert_w((v4i32)out, 3, in3); \
  848. }
  849. #define INSERT_W4_UB(...) INSERT_W4(v16u8, __VA_ARGS__)
  850. #define INSERT_W4_SB(...) INSERT_W4(v16i8, __VA_ARGS__)
  851. #define INSERT_D2(RTYPE, in0, in1, out) \
  852. { \
  853. out = (RTYPE)__msa_insert_d((v2i64)out, 0, in0); \
  854. out = (RTYPE)__msa_insert_d((v2i64)out, 1, in1); \
  855. }
  856. #define INSERT_D2_UB(...) INSERT_D2(v16u8, __VA_ARGS__)
  857. #define INSERT_D2_SB(...) INSERT_D2(v16i8, __VA_ARGS__)
  858. #define INSERT_D2_SH(...) INSERT_D2(v8i16, __VA_ARGS__)
  859. /* Description : Interleave even byte elements from vectors
  860. Arguments : Inputs - in0, in1, in2, in3
  861. Outputs - out0, out1
  862. Return Type - as per RTYPE
  863. Details : Even byte elements of 'in0' and 'in1' are interleaved
  864. and written to 'out0'
  865. */
  866. #define ILVEV_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  867. { \
  868. out0 = (RTYPE)__msa_ilvev_b((v16i8)in1, (v16i8)in0); \
  869. out1 = (RTYPE)__msa_ilvev_b((v16i8)in3, (v16i8)in2); \
  870. }
  871. #define ILVEV_B2_UB(...) ILVEV_B2(v16u8, __VA_ARGS__)
  872. #define ILVEV_B2_SH(...) ILVEV_B2(v8i16, __VA_ARGS__)
  873. /* Description : Interleave even halfword elements from vectors
  874. Arguments : Inputs - in0, in1, in2, in3
  875. Outputs - out0, out1
  876. Return Type - as per RTYPE
  877. Details : Even halfword elements of 'in0' and 'in1' are interleaved
  878. and written to 'out0'
  879. */
  880. #define ILVEV_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  881. { \
  882. out0 = (RTYPE)__msa_ilvev_h((v8i16)in1, (v8i16)in0); \
  883. out1 = (RTYPE)__msa_ilvev_h((v8i16)in3, (v8i16)in2); \
  884. }
  885. #define ILVEV_H2_UB(...) ILVEV_H2(v16u8, __VA_ARGS__)
  886. #define ILVEV_H2_SH(...) ILVEV_H2(v8i16, __VA_ARGS__)
  887. #define ILVEV_H2_SW(...) ILVEV_H2(v4i32, __VA_ARGS__)
  888. /* Description : Interleave even word elements from vectors
  889. Arguments : Inputs - in0, in1, in2, in3
  890. Outputs - out0, out1
  891. Return Type - as per RTYPE
  892. Details : Even word elements of 'in0' and 'in1' are interleaved
  893. and written to 'out0'
  894. */
  895. #define ILVEV_W2(RTYPE, in0, in1, in2, in3, out0, out1) \
  896. { \
  897. out0 = (RTYPE)__msa_ilvev_w((v4i32)in1, (v4i32)in0); \
  898. out1 = (RTYPE)__msa_ilvev_w((v4i32)in3, (v4i32)in2); \
  899. }
  900. #define ILVEV_W2_SB(...) ILVEV_W2(v16i8, __VA_ARGS__)
  901. /* Description : Interleave even double word elements from vectors
  902. Arguments : Inputs - in0, in1, in2, in3
  903. Outputs - out0, out1
  904. Return Type - as per RTYPE
  905. Details : Even double word elements of 'in0' and 'in1' are interleaved
  906. and written to 'out0'
  907. */
  908. #define ILVEV_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  909. { \
  910. out0 = (RTYPE)__msa_ilvev_d((v2i64)in1, (v2i64)in0); \
  911. out1 = (RTYPE)__msa_ilvev_d((v2i64)in3, (v2i64)in2); \
  912. }
  913. #define ILVEV_D2_UB(...) ILVEV_D2(v16u8, __VA_ARGS__)
  914. /* Description : Interleave left half of byte elements from vectors
  915. Arguments : Inputs - in0, in1, in2, in3
  916. Outputs - out0, out1
  917. Return Type - as per RTYPE
  918. Details : Left half of byte elements of 'in0' and 'in1' are interleaved
  919. and written to 'out0'.
  920. */
  921. #define ILVL_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  922. { \
  923. out0 = (RTYPE)__msa_ilvl_b((v16i8)in0, (v16i8)in1); \
  924. out1 = (RTYPE)__msa_ilvl_b((v16i8)in2, (v16i8)in3); \
  925. }
  926. #define ILVL_B2_UB(...) ILVL_B2(v16u8, __VA_ARGS__)
  927. #define ILVL_B2_SB(...) ILVL_B2(v16i8, __VA_ARGS__)
  928. #define ILVL_B2_UH(...) ILVL_B2(v8u16, __VA_ARGS__)
  929. #define ILVL_B2_SH(...) ILVL_B2(v8i16, __VA_ARGS__)
  930. #define ILVL_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  931. out2, out3) \
  932. { \
  933. ILVL_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  934. ILVL_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
  935. }
  936. #define ILVL_B4_SB(...) ILVL_B4(v16i8, __VA_ARGS__)
  937. #define ILVL_B4_SH(...) ILVL_B4(v8i16, __VA_ARGS__)
  938. #define ILVL_B4_UH(...) ILVL_B4(v8u16, __VA_ARGS__)
  939. /* Description : Interleave left half of halfword elements from vectors
  940. Arguments : Inputs - in0, in1, in2, in3
  941. Outputs - out0, out1
  942. Return Type - as per RTYPE
  943. Details : Left half of halfword elements of 'in0' and 'in1' are
  944. interleaved and written to 'out0'.
  945. */
  946. #define ILVL_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  947. { \
  948. out0 = (RTYPE)__msa_ilvl_h((v8i16)in0, (v8i16)in1); \
  949. out1 = (RTYPE)__msa_ilvl_h((v8i16)in2, (v8i16)in3); \
  950. }
  951. #define ILVL_H2_SH(...) ILVL_H2(v8i16, __VA_ARGS__)
  952. #define ILVL_H2_SW(...) ILVL_H2(v4i32, __VA_ARGS__)
  953. /* Description : Interleave left half of word elements from vectors
  954. Arguments : Inputs - in0, in1, in2, in3
  955. Outputs - out0, out1
  956. Return Type - as per RTYPE
  957. Details : Left half of word elements of 'in0' and 'in1' are interleaved
  958. and written to 'out0'.
  959. */
  960. #define ILVL_W2(RTYPE, in0, in1, in2, in3, out0, out1) \
  961. { \
  962. out0 = (RTYPE)__msa_ilvl_w((v4i32)in0, (v4i32)in1); \
  963. out1 = (RTYPE)__msa_ilvl_w((v4i32)in2, (v4i32)in3); \
  964. }
  965. #define ILVL_W2_UB(...) ILVL_W2(v16u8, __VA_ARGS__)
  966. #define ILVL_W2_SH(...) ILVL_W2(v8i16, __VA_ARGS__)
  967. /* Description : Interleave right half of byte elements from vectors
  968. Arguments : Inputs - in0, in1, in2, in3
  969. Outputs - out0, out1
  970. Return Type - as per RTYPE
  971. Details : Right half of byte elements of 'in0' and 'in1' are interleaved
  972. and written to out0.
  973. */
  974. #define ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  975. { \
  976. out0 = (RTYPE)__msa_ilvr_b((v16i8)in0, (v16i8)in1); \
  977. out1 = (RTYPE)__msa_ilvr_b((v16i8)in2, (v16i8)in3); \
  978. }
  979. #define ILVR_B2_UB(...) ILVR_B2(v16u8, __VA_ARGS__)
  980. #define ILVR_B2_SB(...) ILVR_B2(v16i8, __VA_ARGS__)
  981. #define ILVR_B2_UH(...) ILVR_B2(v8u16, __VA_ARGS__)
  982. #define ILVR_B2_SH(...) ILVR_B2(v8i16, __VA_ARGS__)
  983. #define ILVR_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  984. out2, out3) \
  985. { \
  986. ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  987. ILVR_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
  988. }
  989. #define ILVR_B4_UB(...) ILVR_B4(v16u8, __VA_ARGS__)
  990. #define ILVR_B4_SB(...) ILVR_B4(v16i8, __VA_ARGS__)
  991. #define ILVR_B4_UH(...) ILVR_B4(v8u16, __VA_ARGS__)
  992. #define ILVR_B4_SH(...) ILVR_B4(v8i16, __VA_ARGS__)
  993. #define ILVR_B8(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, in8, in9, in10, \
  994. in11, in12, in13, in14, in15, out0, out1, out2, out3, out4, \
  995. out5, out6, out7) \
  996. { \
  997. ILVR_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, \
  998. out3); \
  999. ILVR_B4(RTYPE, in8, in9, in10, in11, in12, in13, in14, in15, out4, out5, \
  1000. out6, out7); \
  1001. }
  1002. #define ILVR_B8_UH(...) ILVR_B8(v8u16, __VA_ARGS__)
  1003. /* Description : Interleave right half of halfword elements from vectors
  1004. Arguments : Inputs - in0, in1, in2, in3
  1005. Outputs - out0, out1
  1006. Return Type - as per RTYPE
  1007. Details : Right half of halfword elements of 'in0' and 'in1' are
  1008. interleaved and written to 'out0'.
  1009. */
  1010. #define ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1011. { \
  1012. out0 = (RTYPE)__msa_ilvr_h((v8i16)in0, (v8i16)in1); \
  1013. out1 = (RTYPE)__msa_ilvr_h((v8i16)in2, (v8i16)in3); \
  1014. }
  1015. #define ILVR_H2_SH(...) ILVR_H2(v8i16, __VA_ARGS__)
  1016. #define ILVR_H2_SW(...) ILVR_H2(v4i32, __VA_ARGS__)
  1017. #define ILVR_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  1018. out2, out3) \
  1019. { \
  1020. ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1021. ILVR_H2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1022. }
  1023. #define ILVR_H4_SH(...) ILVR_H4(v8i16, __VA_ARGS__)
  1024. #define ILVR_W2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1025. { \
  1026. out0 = (RTYPE)__msa_ilvr_w((v4i32)in0, (v4i32)in1); \
  1027. out1 = (RTYPE)__msa_ilvr_w((v4i32)in2, (v4i32)in3); \
  1028. }
  1029. #define ILVR_W2_UB(...) ILVR_W2(v16u8, __VA_ARGS__)
  1030. #define ILVR_W2_SH(...) ILVR_W2(v8i16, __VA_ARGS__)
  1031. #define ILVR_W4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  1032. out2, out3) \
  1033. { \
  1034. ILVR_W2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1035. ILVR_W2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1036. }
  1037. #define ILVR_W4_UB(...) ILVR_W4(v16u8, __VA_ARGS__)
  1038. /* Description : Interleave right half of double word elements from vectors
  1039. Arguments : Inputs - in0, in1, in2, in3
  1040. Outputs - out0, out1
  1041. Return Type - as per RTYPE
  1042. Details : Right half of double word elements of 'in0' and 'in1' are
  1043. interleaved and written to 'out0'.
  1044. */
  1045. #define ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1046. { \
  1047. out0 = (RTYPE)__msa_ilvr_d((v2i64)(in0), (v2i64)(in1)); \
  1048. out1 = (RTYPE)__msa_ilvr_d((v2i64)(in2), (v2i64)(in3)); \
  1049. }
  1050. #define ILVR_D2_UB(...) ILVR_D2(v16u8, __VA_ARGS__)
  1051. #define ILVR_D2_SB(...) ILVR_D2(v16i8, __VA_ARGS__)
  1052. #define ILVR_D2_SH(...) ILVR_D2(v8i16, __VA_ARGS__)
  1053. #define ILVR_D3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1054. { \
  1055. ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1056. out2 = (RTYPE)__msa_ilvr_d((v2i64)(in4), (v2i64)(in5)); \
  1057. }
  1058. #define ILVR_D3_SB(...) ILVR_D3(v16i8, __VA_ARGS__)
  1059. #define ILVR_D4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  1060. out2, out3) \
  1061. { \
  1062. ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1063. ILVR_D2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1064. }
  1065. #define ILVR_D4_SB(...) ILVR_D4(v16i8, __VA_ARGS__)
  1066. #define ILVR_D4_UB(...) ILVR_D4(v16u8, __VA_ARGS__)
  1067. /* Description : Interleave both left and right half of input vectors
  1068. Arguments : Inputs - in0, in1
  1069. Outputs - out0, out1
  1070. Return Type - as per RTYPE
  1071. Details : Right half of byte elements from 'in0' and 'in1' are
  1072. interleaved and written to 'out0'
  1073. */
  1074. #define ILVRL_B2(RTYPE, in0, in1, out0, out1) \
  1075. { \
  1076. out0 = (RTYPE)__msa_ilvr_b((v16i8)in0, (v16i8)in1); \
  1077. out1 = (RTYPE)__msa_ilvl_b((v16i8)in0, (v16i8)in1); \
  1078. }
  1079. #define ILVRL_B2_UB(...) ILVRL_B2(v16u8, __VA_ARGS__)
  1080. #define ILVRL_B2_SB(...) ILVRL_B2(v16i8, __VA_ARGS__)
  1081. #define ILVRL_B2_UH(...) ILVRL_B2(v8u16, __VA_ARGS__)
  1082. #define ILVRL_B2_SH(...) ILVRL_B2(v8i16, __VA_ARGS__)
  1083. #define ILVRL_H2(RTYPE, in0, in1, out0, out1) \
  1084. { \
  1085. out0 = (RTYPE)__msa_ilvr_h((v8i16)in0, (v8i16)in1); \
  1086. out1 = (RTYPE)__msa_ilvl_h((v8i16)in0, (v8i16)in1); \
  1087. }
  1088. #define ILVRL_H2_SH(...) ILVRL_H2(v8i16, __VA_ARGS__)
  1089. #define ILVRL_H2_SW(...) ILVRL_H2(v4i32, __VA_ARGS__)
  1090. #define ILVRL_W2(RTYPE, in0, in1, out0, out1) \
  1091. { \
  1092. out0 = (RTYPE)__msa_ilvr_w((v4i32)in0, (v4i32)in1); \
  1093. out1 = (RTYPE)__msa_ilvl_w((v4i32)in0, (v4i32)in1); \
  1094. }
  1095. #define ILVRL_W2_UB(...) ILVRL_W2(v16u8, __VA_ARGS__)
  1096. #define ILVRL_W2_SH(...) ILVRL_W2(v8i16, __VA_ARGS__)
  1097. #define ILVRL_W2_SW(...) ILVRL_W2(v4i32, __VA_ARGS__)
  1098. /* Description : Saturate the halfword element values to the max
  1099. unsigned value of (sat_val + 1) bits
  1100. The element data width remains unchanged
  1101. Arguments : Inputs - in0, in1, sat_val
  1102. Outputs - in place operation
  1103. Return Type - as per RTYPE
  1104. Details : Each unsigned halfword element from 'in0' is saturated to the
  1105. value generated with (sat_val + 1) bit range.
  1106. The results are written in place
  1107. */
  1108. #define SAT_UH2(RTYPE, in0, in1, sat_val) \
  1109. { \
  1110. in0 = (RTYPE)__msa_sat_u_h((v8u16)in0, sat_val); \
  1111. in1 = (RTYPE)__msa_sat_u_h((v8u16)in1, sat_val); \
  1112. }
  1113. #define SAT_UH2_UH(...) SAT_UH2(v8u16, __VA_ARGS__)
  1114. #define SAT_UH4(RTYPE, in0, in1, in2, in3, sat_val) \
  1115. { \
  1116. SAT_UH2(RTYPE, in0, in1, sat_val); \
  1117. SAT_UH2(RTYPE, in2, in3, sat_val) \
  1118. }
  1119. #define SAT_UH4_UH(...) SAT_UH4(v8u16, __VA_ARGS__)
  1120. /* Description : Saturate the halfword element values to the max
  1121. unsigned value of (sat_val + 1) bits
  1122. The element data width remains unchanged
  1123. Arguments : Inputs - in0, in1, sat_val
  1124. Outputs - in place operation
  1125. Return Type - as per RTYPE
  1126. Details : Each unsigned halfword element from 'in0' is saturated to the
  1127. value generated with (sat_val + 1) bit range
  1128. The results are written in place
  1129. */
  1130. #define SAT_SH2(RTYPE, in0, in1, sat_val) \
  1131. { \
  1132. in0 = (RTYPE)__msa_sat_s_h((v8i16)in0, sat_val); \
  1133. in1 = (RTYPE)__msa_sat_s_h((v8i16)in1, sat_val); \
  1134. }
  1135. #define SAT_SH2_SH(...) SAT_SH2(v8i16, __VA_ARGS__)
  1136. #define SAT_SH4(RTYPE, in0, in1, in2, in3, sat_val) \
  1137. { \
  1138. SAT_SH2(RTYPE, in0, in1, sat_val); \
  1139. SAT_SH2(RTYPE, in2, in3, sat_val); \
  1140. }
  1141. #define SAT_SH4_SH(...) SAT_SH4(v8i16, __VA_ARGS__)
  1142. /* Description : Indexed halfword element values are replicated to all
  1143. elements in output vector
  1144. Arguments : Inputs - in, idx0, idx1
  1145. Outputs - out0, out1
  1146. Return Type - as per RTYPE
  1147. Details : 'idx0' element value from 'in' vector is replicated to all
  1148. elements in 'out0' vector
  1149. Valid index range for halfword operation is 0-7
  1150. */
  1151. #define SPLATI_H2(RTYPE, in, idx0, idx1, out0, out1) \
  1152. { \
  1153. out0 = (RTYPE)__msa_splati_h((v8i16)in, idx0); \
  1154. out1 = (RTYPE)__msa_splati_h((v8i16)in, idx1); \
  1155. }
  1156. #define SPLATI_H2_SH(...) SPLATI_H2(v8i16, __VA_ARGS__)
  1157. #define SPLATI_H4(RTYPE, in, idx0, idx1, idx2, idx3, out0, out1, out2, out3) \
  1158. { \
  1159. SPLATI_H2(RTYPE, in, idx0, idx1, out0, out1); \
  1160. SPLATI_H2(RTYPE, in, idx2, idx3, out2, out3); \
  1161. }
  1162. #define SPLATI_H4_SB(...) SPLATI_H4(v16i8, __VA_ARGS__)
  1163. #define SPLATI_H4_SH(...) SPLATI_H4(v8i16, __VA_ARGS__)
  1164. /* Description : Pack even byte elements of vector pairs
  1165. Arguments : Inputs - in0, in1, in2, in3
  1166. Outputs - out0, out1
  1167. Return Type - as per RTYPE
  1168. Details : Even byte elements of 'in0' are copied to the left half of
  1169. 'out0' & even byte elements of 'in1' are copied to the right
  1170. half of 'out0'.
  1171. */
  1172. #define PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1173. { \
  1174. out0 = (RTYPE)__msa_pckev_b((v16i8)in0, (v16i8)in1); \
  1175. out1 = (RTYPE)__msa_pckev_b((v16i8)in2, (v16i8)in3); \
  1176. }
  1177. #define PCKEV_B2_SB(...) PCKEV_B2(v16i8, __VA_ARGS__)
  1178. #define PCKEV_B2_UB(...) PCKEV_B2(v16u8, __VA_ARGS__)
  1179. #define PCKEV_B2_SH(...) PCKEV_B2(v8i16, __VA_ARGS__)
  1180. #define PCKEV_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  1181. out2, out3) \
  1182. { \
  1183. PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1184. PCKEV_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1185. }
  1186. #define PCKEV_B4_SB(...) PCKEV_B4(v16i8, __VA_ARGS__)
  1187. #define PCKEV_B4_UB(...) PCKEV_B4(v16u8, __VA_ARGS__)
  1188. #define PCKEV_B4_SH(...) PCKEV_B4(v8i16, __VA_ARGS__)
  1189. /* Description : Pack even halfword elements of vector pairs
  1190. Arguments : Inputs - in0, in1, in2, in3
  1191. Outputs - out0, out1
  1192. Return Type - as per RTYPE
  1193. Details : Even halfword elements of 'in0' are copied to the left half of
  1194. 'out0' & even halfword elements of 'in1' are copied to the
  1195. right half of 'out0'.
  1196. */
  1197. #define PCKEV_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1198. { \
  1199. out0 = (RTYPE)__msa_pckev_h((v8i16)in0, (v8i16)in1); \
  1200. out1 = (RTYPE)__msa_pckev_h((v8i16)in2, (v8i16)in3); \
  1201. }
  1202. #define PCKEV_H2_SH(...) PCKEV_H2(v8i16, __VA_ARGS__)
  1203. #define PCKEV_H2_SW(...) PCKEV_H2(v4i32, __VA_ARGS__)
  1204. #define PCKEV_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  1205. out2, out3) \
  1206. { \
  1207. PCKEV_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1208. PCKEV_H2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1209. }
  1210. #define PCKEV_H4_SH(...) PCKEV_H4(v8i16, __VA_ARGS__)
  1211. /* Description : Pack even double word elements of vector pairs
  1212. Arguments : Inputs - in0, in1, in2, in3
  1213. Outputs - out0, out1
  1214. Return Type - as per RTYPE
  1215. Details : Even double elements of 'in0' are copied to the left half of
  1216. 'out0' & even double elements of 'in1' are copied to the right
  1217. half of 'out0'.
  1218. */
  1219. #define PCKEV_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1220. { \
  1221. out0 = (RTYPE)__msa_pckev_d((v2i64)in0, (v2i64)in1); \
  1222. out1 = (RTYPE)__msa_pckev_d((v2i64)in2, (v2i64)in3); \
  1223. }
  1224. #define PCKEV_D2_UB(...) PCKEV_D2(v16u8, __VA_ARGS__)
  1225. #define PCKEV_D2_SH(...) PCKEV_D2(v8i16, __VA_ARGS__)
  1226. #define PCKEV_D4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  1227. out2, out3) \
  1228. { \
  1229. PCKEV_D2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1230. PCKEV_D2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1231. }
  1232. #define PCKEV_D4_UB(...) PCKEV_D4(v16u8, __VA_ARGS__)
  1233. /* Description : Each byte element is logically xor'ed with immediate 128
  1234. Arguments : Inputs - in0, in1
  1235. Outputs - in place operation
  1236. Return Type - as per RTYPE
  1237. Details : Each unsigned byte element from input vector 'in0' is
  1238. logically xor'ed with 128 and the result is stored in-place.
  1239. */
  1240. #define XORI_B2_128(RTYPE, in0, in1) \
  1241. { \
  1242. in0 = (RTYPE)__msa_xori_b((v16u8)in0, 128); \
  1243. in1 = (RTYPE)__msa_xori_b((v16u8)in1, 128); \
  1244. }
  1245. #define XORI_B2_128_UB(...) XORI_B2_128(v16u8, __VA_ARGS__)
  1246. #define XORI_B2_128_SB(...) XORI_B2_128(v16i8, __VA_ARGS__)
  1247. #define XORI_B3_128(RTYPE, in0, in1, in2) \
  1248. { \
  1249. XORI_B2_128(RTYPE, in0, in1); \
  1250. in2 = (RTYPE)__msa_xori_b((v16u8)in2, 128); \
  1251. }
  1252. #define XORI_B3_128_SB(...) XORI_B3_128(v16i8, __VA_ARGS__)
  1253. #define XORI_B4_128(RTYPE, in0, in1, in2, in3) \
  1254. { \
  1255. XORI_B2_128(RTYPE, in0, in1); \
  1256. XORI_B2_128(RTYPE, in2, in3); \
  1257. }
  1258. #define XORI_B4_128_UB(...) XORI_B4_128(v16u8, __VA_ARGS__)
  1259. #define XORI_B4_128_SB(...) XORI_B4_128(v16i8, __VA_ARGS__)
  1260. #define XORI_B7_128(RTYPE, in0, in1, in2, in3, in4, in5, in6) \
  1261. { \
  1262. XORI_B4_128(RTYPE, in0, in1, in2, in3); \
  1263. XORI_B3_128(RTYPE, in4, in5, in6); \
  1264. }
  1265. #define XORI_B7_128_SB(...) XORI_B7_128(v16i8, __VA_ARGS__)
  1266. /* Description : Average of signed halfword elements -> (a + b) / 2
  1267. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1268. Outputs - out0, out1, out2, out3
  1269. Return Type - as per RTYPE
  1270. Details : Each signed halfword element from 'in0' is added to each
  1271. signed halfword element of 'in1' with full precision resulting
  1272. in one extra bit in the result. The result is then divided by
  1273. 2 and written to 'out0'
  1274. */
  1275. #define AVE_SH4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  1276. out2, out3) \
  1277. { \
  1278. out0 = (RTYPE)__msa_ave_s_h((v8i16)in0, (v8i16)in1); \
  1279. out1 = (RTYPE)__msa_ave_s_h((v8i16)in2, (v8i16)in3); \
  1280. out2 = (RTYPE)__msa_ave_s_h((v8i16)in4, (v8i16)in5); \
  1281. out3 = (RTYPE)__msa_ave_s_h((v8i16)in6, (v8i16)in7); \
  1282. }
  1283. #define AVE_SH4_SH(...) AVE_SH4(v8i16, __VA_ARGS__)
  1284. /* Description : Addition of signed halfword elements and signed saturation
  1285. Arguments : Inputs - in0, in1, in2, in3
  1286. Outputs - out0, out1
  1287. Return Type - as per RTYPE
  1288. Details : Signed halfword elements from 'in0' are added to signed
  1289. halfword elements of 'in1'. The result is then signed saturated
  1290. between halfword data type range
  1291. */
  1292. #define ADDS_SH2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1293. { \
  1294. out0 = (RTYPE)__msa_adds_s_h((v8i16)in0, (v8i16)in1); \
  1295. out1 = (RTYPE)__msa_adds_s_h((v8i16)in2, (v8i16)in3); \
  1296. }
  1297. #define ADDS_SH2_SH(...) ADDS_SH2(v8i16, __VA_ARGS__)
  1298. #define ADDS_SH4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  1299. out2, out3) \
  1300. { \
  1301. ADDS_SH2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1302. ADDS_SH2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1303. }
  1304. #define ADDS_SH4_SH(...) ADDS_SH4(v8i16, __VA_ARGS__)
  1305. /* Description : Shift left all elements of vector (generic for all data types)
  1306. Arguments : Inputs - in0, in1, in2, in3, shift
  1307. Outputs - in place operation
  1308. Return Type - as per input vector RTYPE
  1309. Details : Each element of vector 'in0' is left shifted by 'shift' and
  1310. the result is written in-place.
  1311. */
  1312. #define SLLI_4V(in0, in1, in2, in3, shift) \
  1313. { \
  1314. in0 = in0 << shift; \
  1315. in1 = in1 << shift; \
  1316. in2 = in2 << shift; \
  1317. in3 = in3 << shift; \
  1318. }
  1319. /* Description : Arithmetic shift right all elements of vector
  1320. (generic for all data types)
  1321. Arguments : Inputs - in0, in1, in2, in3, shift
  1322. Outputs - in place operation
  1323. Return Type - as per input vector RTYPE
  1324. Details : Each element of vector 'in0' is right shifted by 'shift' and
  1325. the result is written in-place. 'shift' is a GP variable.
  1326. */
  1327. #define SRA_2V(in0, in1, shift) \
  1328. { \
  1329. in0 = in0 >> shift; \
  1330. in1 = in1 >> shift; \
  1331. }
  1332. #define SRA_4V(in0, in1, in2, in3, shift) \
  1333. { \
  1334. in0 = in0 >> shift; \
  1335. in1 = in1 >> shift; \
  1336. in2 = in2 >> shift; \
  1337. in3 = in3 >> shift; \
  1338. }
  1339. /* Description : Shift right arithmetic rounded words
  1340. Arguments : Inputs - in0, in1, shift
  1341. Outputs - in place operation
  1342. Return Type - as per RTYPE
  1343. Details : Each element of vector 'in0' is shifted right arithmetically by
  1344. the number of bits in the corresponding element in the vector
  1345. 'shift'. The last discarded bit is added to shifted value for
  1346. rounding and the result is written in-place.
  1347. 'shift' is a vector.
  1348. */
  1349. #define SRAR_W2(RTYPE, in0, in1, shift) \
  1350. { \
  1351. in0 = (RTYPE)__msa_srar_w((v4i32)in0, (v4i32)shift); \
  1352. in1 = (RTYPE)__msa_srar_w((v4i32)in1, (v4i32)shift); \
  1353. }
  1354. #define SRAR_W4(RTYPE, in0, in1, in2, in3, shift) \
  1355. { \
  1356. SRAR_W2(RTYPE, in0, in1, shift) \
  1357. SRAR_W2(RTYPE, in2, in3, shift) \
  1358. }
  1359. #define SRAR_W4_SW(...) SRAR_W4(v4i32, __VA_ARGS__)
  1360. /* Description : Shift right arithmetic rounded (immediate)
  1361. Arguments : Inputs - in0, in1, shift
  1362. Outputs - in place operation
  1363. Return Type - as per RTYPE
  1364. Details : Each element of vector 'in0' is shifted right arithmetically by
  1365. the value in 'shift'. The last discarded bit is added to the
  1366. shifted value for rounding and the result is written in-place.
  1367. 'shift' is an immediate value.
  1368. */
  1369. #define SRARI_H2(RTYPE, in0, in1, shift) \
  1370. { \
  1371. in0 = (RTYPE)__msa_srari_h((v8i16)in0, shift); \
  1372. in1 = (RTYPE)__msa_srari_h((v8i16)in1, shift); \
  1373. }
  1374. #define SRARI_H2_UH(...) SRARI_H2(v8u16, __VA_ARGS__)
  1375. #define SRARI_H2_SH(...) SRARI_H2(v8i16, __VA_ARGS__)
  1376. #define SRARI_H4(RTYPE, in0, in1, in2, in3, shift) \
  1377. { \
  1378. SRARI_H2(RTYPE, in0, in1, shift); \
  1379. SRARI_H2(RTYPE, in2, in3, shift); \
  1380. }
  1381. #define SRARI_H4_UH(...) SRARI_H4(v8u16, __VA_ARGS__)
  1382. #define SRARI_H4_SH(...) SRARI_H4(v8i16, __VA_ARGS__)
  1383. #define SRARI_W2(RTYPE, in0, in1, shift) \
  1384. { \
  1385. in0 = (RTYPE)__msa_srari_w((v4i32)in0, shift); \
  1386. in1 = (RTYPE)__msa_srari_w((v4i32)in1, shift); \
  1387. }
  1388. #define SRARI_W2_SW(...) SRARI_W2(v4i32, __VA_ARGS__)
  1389. #define SRARI_W4(RTYPE, in0, in1, in2, in3, shift) \
  1390. { \
  1391. SRARI_W2(RTYPE, in0, in1, shift); \
  1392. SRARI_W2(RTYPE, in2, in3, shift); \
  1393. }
  1394. #define SRARI_W4_SW(...) SRARI_W4(v4i32, __VA_ARGS__)
  1395. /* Description : Logical shift right all elements of vector (immediate)
  1396. Arguments : Inputs - in0, in1, in2, in3, shift
  1397. Outputs - out0, out1, out2, out3
  1398. Return Type - as per RTYPE
  1399. Details : Each element of vector 'in0' is right shifted by 'shift' and
  1400. the result is written in-place. 'shift' is an immediate value.
  1401. */
  1402. #define SRLI_H4(RTYPE, in0, in1, in2, in3, out0, out1, out2, out3, shift) \
  1403. { \
  1404. out0 = (RTYPE)__msa_srli_h((v8i16)in0, shift); \
  1405. out1 = (RTYPE)__msa_srli_h((v8i16)in1, shift); \
  1406. out2 = (RTYPE)__msa_srli_h((v8i16)in2, shift); \
  1407. out3 = (RTYPE)__msa_srli_h((v8i16)in3, shift); \
  1408. }
  1409. #define SRLI_H4_SH(...) SRLI_H4(v8i16, __VA_ARGS__)
  1410. /* Description : Multiplication of pairs of vectors
  1411. Arguments : Inputs - in0, in1, in2, in3
  1412. Outputs - out0, out1
  1413. Details : Each element from 'in0' is multiplied with elements from 'in1'
  1414. and the result is written to 'out0'
  1415. */
  1416. #define MUL2(in0, in1, in2, in3, out0, out1) \
  1417. { \
  1418. out0 = in0 * in1; \
  1419. out1 = in2 * in3; \
  1420. }
  1421. #define MUL4(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, out3) \
  1422. { \
  1423. MUL2(in0, in1, in2, in3, out0, out1); \
  1424. MUL2(in4, in5, in6, in7, out2, out3); \
  1425. }
  1426. /* Description : Addition of 2 pairs of vectors
  1427. Arguments : Inputs - in0, in1, in2, in3
  1428. Outputs - out0, out1
  1429. Details : Each element in 'in0' is added to 'in1' and result is written
  1430. to 'out0'.
  1431. */
  1432. #define ADD2(in0, in1, in2, in3, out0, out1) \
  1433. { \
  1434. out0 = in0 + in1; \
  1435. out1 = in2 + in3; \
  1436. }
  1437. #define ADD4(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, out3) \
  1438. { \
  1439. ADD2(in0, in1, in2, in3, out0, out1); \
  1440. ADD2(in4, in5, in6, in7, out2, out3); \
  1441. }
  1442. /* Description : Subtraction of 2 pairs of vectors
  1443. Arguments : Inputs - in0, in1, in2, in3
  1444. Outputs - out0, out1
  1445. Details : Each element in 'in1' is subtracted from 'in0' and result is
  1446. written to 'out0'.
  1447. */
  1448. #define SUB2(in0, in1, in2, in3, out0, out1) \
  1449. { \
  1450. out0 = in0 - in1; \
  1451. out1 = in2 - in3; \
  1452. }
  1453. #define SUB4(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, out3) \
  1454. { \
  1455. out0 = in0 - in1; \
  1456. out1 = in2 - in3; \
  1457. out2 = in4 - in5; \
  1458. out3 = in6 - in7; \
  1459. }
  1460. /* Description : Sign extend halfword elements from right half of the vector
  1461. Arguments : Input - in (halfword vector)
  1462. Output - out (sign extended word vector)
  1463. Return Type - signed word
  1464. Details : Sign bit of halfword elements from input vector 'in' is
  1465. extracted and interleaved with same vector 'in0' to generate
  1466. 4 word elements keeping sign intact
  1467. */
  1468. #define UNPCK_R_SH_SW(in, out) \
  1469. { \
  1470. v8i16 sign_m; \
  1471. \
  1472. sign_m = __msa_clti_s_h((v8i16)in, 0); \
  1473. out = (v4i32)__msa_ilvr_h(sign_m, (v8i16)in); \
  1474. }
  1475. /* Description : Zero extend unsigned byte elements to halfword elements
  1476. Arguments : Input - in (unsigned byte vector)
  1477. Outputs - out0, out1 (unsigned halfword vectors)
  1478. Return Type - signed halfword
  1479. Details : Zero extended right half of vector is returned in 'out0'
  1480. Zero extended left half of vector is returned in 'out1'
  1481. */
  1482. #define UNPCK_UB_SH(in, out0, out1) \
  1483. { \
  1484. v16i8 zero_m = { 0 }; \
  1485. \
  1486. ILVRL_B2_SH(zero_m, in, out0, out1); \
  1487. }
  1488. /* Description : Sign extend halfword elements from input vector and return
  1489. the result in pair of vectors
  1490. Arguments : Input - in (halfword vector)
  1491. Outputs - out0, out1 (sign extended word vectors)
  1492. Return Type - signed word
  1493. Details : Sign bit of halfword elements from input vector 'in' is
  1494. extracted and interleaved right with same vector 'in0' to
  1495. generate 4 signed word elements in 'out0'
  1496. Then interleaved left with same vector 'in0' to
  1497. generate 4 signed word elements in 'out1'
  1498. */
  1499. #define UNPCK_SH_SW(in, out0, out1) \
  1500. { \
  1501. v8i16 tmp_m; \
  1502. \
  1503. tmp_m = __msa_clti_s_h((v8i16)in, 0); \
  1504. ILVRL_H2_SW(tmp_m, in, out0, out1); \
  1505. }
  1506. /* Description : Butterfly of 4 input vectors
  1507. Arguments : Inputs - in0, in1, in2, in3
  1508. Outputs - out0, out1, out2, out3
  1509. Details : Butterfly operation
  1510. */
  1511. #define BUTTERFLY_4(in0, in1, in2, in3, out0, out1, out2, out3) \
  1512. { \
  1513. out0 = in0 + in3; \
  1514. out1 = in1 + in2; \
  1515. \
  1516. out2 = in1 - in2; \
  1517. out3 = in0 - in3; \
  1518. }
  1519. /* Description : Butterfly of 8 input vectors
  1520. Arguments : Inputs - in0 ... in7
  1521. Outputs - out0 .. out7
  1522. Details : Butterfly operation
  1523. */
  1524. #define BUTTERFLY_8(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, \
  1525. out3, out4, out5, out6, out7) \
  1526. { \
  1527. out0 = in0 + in7; \
  1528. out1 = in1 + in6; \
  1529. out2 = in2 + in5; \
  1530. out3 = in3 + in4; \
  1531. \
  1532. out4 = in3 - in4; \
  1533. out5 = in2 - in5; \
  1534. out6 = in1 - in6; \
  1535. out7 = in0 - in7; \
  1536. }
  1537. /* Description : Butterfly of 16 input vectors
  1538. Arguments : Inputs - in0 ... in15
  1539. Outputs - out0 .. out15
  1540. Details : Butterfly operation
  1541. */
  1542. #define BUTTERFLY_16(in0, in1, in2, in3, in4, in5, in6, in7, in8, in9, in10, \
  1543. in11, in12, in13, in14, in15, out0, out1, out2, out3, \
  1544. out4, out5, out6, out7, out8, out9, out10, out11, out12, \
  1545. out13, out14, out15) \
  1546. { \
  1547. out0 = in0 + in15; \
  1548. out1 = in1 + in14; \
  1549. out2 = in2 + in13; \
  1550. out3 = in3 + in12; \
  1551. out4 = in4 + in11; \
  1552. out5 = in5 + in10; \
  1553. out6 = in6 + in9; \
  1554. out7 = in7 + in8; \
  1555. \
  1556. out8 = in7 - in8; \
  1557. out9 = in6 - in9; \
  1558. out10 = in5 - in10; \
  1559. out11 = in4 - in11; \
  1560. out12 = in3 - in12; \
  1561. out13 = in2 - in13; \
  1562. out14 = in1 - in14; \
  1563. out15 = in0 - in15; \
  1564. }
  1565. /* Description : Transpose input 8x8 byte block
  1566. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1567. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  1568. Return Type - as per RTYPE
  1569. */
  1570. #define TRANSPOSE8x8_UB(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, \
  1571. out1, out2, out3, out4, out5, out6, out7) \
  1572. { \
  1573. v16i8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  1574. v16i8 tmp4_m, tmp5_m, tmp6_m, tmp7_m; \
  1575. \
  1576. ILVR_B4_SB(in2, in0, in3, in1, in6, in4, in7, in5, tmp0_m, tmp1_m, tmp2_m, \
  1577. tmp3_m); \
  1578. ILVRL_B2_SB(tmp1_m, tmp0_m, tmp4_m, tmp5_m); \
  1579. ILVRL_B2_SB(tmp3_m, tmp2_m, tmp6_m, tmp7_m); \
  1580. ILVRL_W2(RTYPE, tmp6_m, tmp4_m, out0, out2); \
  1581. ILVRL_W2(RTYPE, tmp7_m, tmp5_m, out4, out6); \
  1582. SLDI_B2_0(RTYPE, out0, out2, out1, out3, 8); \
  1583. SLDI_B2_0(RTYPE, out4, out6, out5, out7, 8); \
  1584. }
  1585. #define TRANSPOSE8x8_UB_UB(...) TRANSPOSE8x8_UB(v16u8, __VA_ARGS__)
  1586. /* Description : Transpose 16x8 block into 8x16 with byte elements in vectors
  1587. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7,
  1588. in8, in9, in10, in11, in12, in13, in14, in15
  1589. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  1590. Return Type - unsigned byte
  1591. */
  1592. #define TRANSPOSE16x8_UB_UB(in0, in1, in2, in3, in4, in5, in6, in7, in8, in9, \
  1593. in10, in11, in12, in13, in14, in15, out0, out1, \
  1594. out2, out3, out4, out5, out6, out7) \
  1595. { \
  1596. v16u8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  1597. v16u8 tmp4_m, tmp5_m, tmp6_m, tmp7_m; \
  1598. \
  1599. ILVEV_D2_UB(in0, in8, in1, in9, out7, out6); \
  1600. ILVEV_D2_UB(in2, in10, in3, in11, out5, out4); \
  1601. ILVEV_D2_UB(in4, in12, in5, in13, out3, out2); \
  1602. ILVEV_D2_UB(in6, in14, in7, in15, out1, out0); \
  1603. \
  1604. tmp0_m = (v16u8)__msa_ilvev_b((v16i8)out6, (v16i8)out7); \
  1605. tmp4_m = (v16u8)__msa_ilvod_b((v16i8)out6, (v16i8)out7); \
  1606. tmp1_m = (v16u8)__msa_ilvev_b((v16i8)out4, (v16i8)out5); \
  1607. tmp5_m = (v16u8)__msa_ilvod_b((v16i8)out4, (v16i8)out5); \
  1608. out5 = (v16u8)__msa_ilvev_b((v16i8)out2, (v16i8)out3); \
  1609. tmp6_m = (v16u8)__msa_ilvod_b((v16i8)out2, (v16i8)out3); \
  1610. out7 = (v16u8)__msa_ilvev_b((v16i8)out0, (v16i8)out1); \
  1611. tmp7_m = (v16u8)__msa_ilvod_b((v16i8)out0, (v16i8)out1); \
  1612. \
  1613. ILVEV_H2_UB(tmp0_m, tmp1_m, out5, out7, tmp2_m, tmp3_m); \
  1614. out0 = (v16u8)__msa_ilvev_w((v4i32)tmp3_m, (v4i32)tmp2_m); \
  1615. out4 = (v16u8)__msa_ilvod_w((v4i32)tmp3_m, (v4i32)tmp2_m); \
  1616. \
  1617. tmp2_m = (v16u8)__msa_ilvod_h((v8i16)tmp1_m, (v8i16)tmp0_m); \
  1618. tmp3_m = (v16u8)__msa_ilvod_h((v8i16)out7, (v8i16)out5); \
  1619. out2 = (v16u8)__msa_ilvev_w((v4i32)tmp3_m, (v4i32)tmp2_m); \
  1620. out6 = (v16u8)__msa_ilvod_w((v4i32)tmp3_m, (v4i32)tmp2_m); \
  1621. \
  1622. ILVEV_H2_UB(tmp4_m, tmp5_m, tmp6_m, tmp7_m, tmp2_m, tmp3_m); \
  1623. out1 = (v16u8)__msa_ilvev_w((v4i32)tmp3_m, (v4i32)tmp2_m); \
  1624. out5 = (v16u8)__msa_ilvod_w((v4i32)tmp3_m, (v4i32)tmp2_m); \
  1625. \
  1626. tmp2_m = (v16u8)__msa_ilvod_h((v8i16)tmp5_m, (v8i16)tmp4_m); \
  1627. tmp3_m = (v16u8)__msa_ilvod_h((v8i16)tmp7_m, (v8i16)tmp6_m); \
  1628. out3 = (v16u8)__msa_ilvev_w((v4i32)tmp3_m, (v4i32)tmp2_m); \
  1629. out7 = (v16u8)__msa_ilvod_w((v4i32)tmp3_m, (v4i32)tmp2_m); \
  1630. }
  1631. /* Description : Transpose 4x4 block with half word elements in vectors
  1632. Arguments : Inputs - in0, in1, in2, in3
  1633. Outputs - out0, out1, out2, out3
  1634. Return Type - signed halfword
  1635. */
  1636. #define TRANSPOSE4x4_SH_SH(in0, in1, in2, in3, out0, out1, out2, out3) \
  1637. { \
  1638. v8i16 s0_m, s1_m; \
  1639. \
  1640. ILVR_H2_SH(in1, in0, in3, in2, s0_m, s1_m); \
  1641. ILVRL_W2_SH(s1_m, s0_m, out0, out2); \
  1642. out1 = (v8i16)__msa_ilvl_d((v2i64)out0, (v2i64)out0); \
  1643. out3 = (v8i16)__msa_ilvl_d((v2i64)out0, (v2i64)out2); \
  1644. }
  1645. /* Description : Transpose 4x8 block with half word elements in vectors
  1646. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1647. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  1648. Return Type - signed halfword
  1649. */
  1650. #define TRANSPOSE4X8_SH_SH(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  1651. out2, out3, out4, out5, out6, out7) \
  1652. { \
  1653. v8i16 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  1654. v8i16 tmp0_n, tmp1_n, tmp2_n, tmp3_n; \
  1655. v8i16 zero_m = { 0 }; \
  1656. \
  1657. ILVR_H4_SH(in1, in0, in3, in2, in5, in4, in7, in6, tmp0_n, tmp1_n, tmp2_n, \
  1658. tmp3_n); \
  1659. ILVRL_W2_SH(tmp1_n, tmp0_n, tmp0_m, tmp2_m); \
  1660. ILVRL_W2_SH(tmp3_n, tmp2_n, tmp1_m, tmp3_m); \
  1661. \
  1662. out0 = (v8i16)__msa_ilvr_d((v2i64)tmp1_m, (v2i64)tmp0_m); \
  1663. out1 = (v8i16)__msa_ilvl_d((v2i64)tmp1_m, (v2i64)tmp0_m); \
  1664. out2 = (v8i16)__msa_ilvr_d((v2i64)tmp3_m, (v2i64)tmp2_m); \
  1665. out3 = (v8i16)__msa_ilvl_d((v2i64)tmp3_m, (v2i64)tmp2_m); \
  1666. \
  1667. out4 = zero_m; \
  1668. out5 = zero_m; \
  1669. out6 = zero_m; \
  1670. out7 = zero_m; \
  1671. }
  1672. /* Description : Transpose 8x4 block with half word elements in vectors
  1673. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1674. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  1675. Return Type - signed halfword
  1676. */
  1677. #define TRANSPOSE8X4_SH_SH(in0, in1, in2, in3, out0, out1, out2, out3) \
  1678. { \
  1679. v8i16 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  1680. \
  1681. ILVR_H2_SH(in1, in0, in3, in2, tmp0_m, tmp1_m); \
  1682. ILVL_H2_SH(in1, in0, in3, in2, tmp2_m, tmp3_m); \
  1683. ILVR_W2_SH(tmp1_m, tmp0_m, tmp3_m, tmp2_m, out0, out2); \
  1684. ILVL_W2_SH(tmp1_m, tmp0_m, tmp3_m, tmp2_m, out1, out3); \
  1685. }
  1686. /* Description : Transpose 8x8 block with half word elements in vectors
  1687. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1688. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  1689. Return Type - as per RTYPE
  1690. */
  1691. #define TRANSPOSE8x8_H(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, \
  1692. out1, out2, out3, out4, out5, out6, out7) \
  1693. { \
  1694. v8i16 s0_m, s1_m; \
  1695. v8i16 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  1696. v8i16 tmp4_m, tmp5_m, tmp6_m, tmp7_m; \
  1697. \
  1698. ILVR_H2_SH(in6, in4, in7, in5, s0_m, s1_m); \
  1699. ILVRL_H2_SH(s1_m, s0_m, tmp0_m, tmp1_m); \
  1700. ILVL_H2_SH(in6, in4, in7, in5, s0_m, s1_m); \
  1701. ILVRL_H2_SH(s1_m, s0_m, tmp2_m, tmp3_m); \
  1702. ILVR_H2_SH(in2, in0, in3, in1, s0_m, s1_m); \
  1703. ILVRL_H2_SH(s1_m, s0_m, tmp4_m, tmp5_m); \
  1704. ILVL_H2_SH(in2, in0, in3, in1, s0_m, s1_m); \
  1705. ILVRL_H2_SH(s1_m, s0_m, tmp6_m, tmp7_m); \
  1706. PCKEV_D4(RTYPE, tmp0_m, tmp4_m, tmp1_m, tmp5_m, tmp2_m, tmp6_m, tmp3_m, \
  1707. tmp7_m, out0, out2, out4, out6); \
  1708. out1 = (RTYPE)__msa_pckod_d((v2i64)tmp0_m, (v2i64)tmp4_m); \
  1709. out3 = (RTYPE)__msa_pckod_d((v2i64)tmp1_m, (v2i64)tmp5_m); \
  1710. out5 = (RTYPE)__msa_pckod_d((v2i64)tmp2_m, (v2i64)tmp6_m); \
  1711. out7 = (RTYPE)__msa_pckod_d((v2i64)tmp3_m, (v2i64)tmp7_m); \
  1712. }
  1713. #define TRANSPOSE8x8_SH_SH(...) TRANSPOSE8x8_H(v8i16, __VA_ARGS__)
  1714. /* Description : Transpose 4x4 block with word elements in vectors
  1715. Arguments : Inputs - in0, in1, in2, in3
  1716. Outputs - out0, out1, out2, out3
  1717. Return Type - signed word
  1718. */
  1719. #define TRANSPOSE4x4_SW_SW(in0, in1, in2, in3, out0, out1, out2, out3) \
  1720. { \
  1721. v4i32 s0_m, s1_m, s2_m, s3_m; \
  1722. \
  1723. ILVRL_W2_SW(in1, in0, s0_m, s1_m); \
  1724. ILVRL_W2_SW(in3, in2, s2_m, s3_m); \
  1725. \
  1726. out0 = (v4i32)__msa_ilvr_d((v2i64)s2_m, (v2i64)s0_m); \
  1727. out1 = (v4i32)__msa_ilvl_d((v2i64)s2_m, (v2i64)s0_m); \
  1728. out2 = (v4i32)__msa_ilvr_d((v2i64)s3_m, (v2i64)s1_m); \
  1729. out3 = (v4i32)__msa_ilvl_d((v2i64)s3_m, (v2i64)s1_m); \
  1730. }
  1731. /* Description : Add block 4x4
  1732. Arguments : Inputs - in0, in1, in2, in3, pdst, stride
  1733. Details : Least significant 4 bytes from each input vector are added to
  1734. the destination bytes, clipped between 0-255 and stored.
  1735. */
  1736. #define ADDBLK_ST4x4_UB(in0, in1, in2, in3, pdst, stride) \
  1737. { \
  1738. uint32_t src0_m, src1_m, src2_m, src3_m; \
  1739. v8i16 inp0_m, inp1_m, res0_m, res1_m; \
  1740. v16i8 dst0_m = { 0 }; \
  1741. v16i8 dst1_m = { 0 }; \
  1742. v16i8 zero_m = { 0 }; \
  1743. \
  1744. ILVR_D2_SH(in1, in0, in3, in2, inp0_m, inp1_m) \
  1745. LW4(pdst, stride, src0_m, src1_m, src2_m, src3_m); \
  1746. INSERT_W2_SB(src0_m, src1_m, dst0_m); \
  1747. INSERT_W2_SB(src2_m, src3_m, dst1_m); \
  1748. ILVR_B2_SH(zero_m, dst0_m, zero_m, dst1_m, res0_m, res1_m); \
  1749. ADD2(res0_m, inp0_m, res1_m, inp1_m, res0_m, res1_m); \
  1750. CLIP_SH2_0_255(res0_m, res1_m); \
  1751. PCKEV_B2_SB(res0_m, res0_m, res1_m, res1_m, dst0_m, dst1_m); \
  1752. ST4x4_UB(dst0_m, dst1_m, 0, 1, 0, 1, pdst, stride); \
  1753. }
  1754. /* Description : Pack even elements of input vectors & xor with 128
  1755. Arguments : Inputs - in0, in1
  1756. Output - out_m
  1757. Return Type - unsigned byte
  1758. Details : Signed byte even elements from 'in0' and 'in1' are packed
  1759. together in one vector and the resulting vector is xor'ed with
  1760. 128 to shift the range from signed to unsigned byte
  1761. */
  1762. #define PCKEV_XORI128_UB(in0, in1) \
  1763. ({ \
  1764. v16u8 out_m; \
  1765. \
  1766. out_m = (v16u8)__msa_pckev_b((v16i8)in1, (v16i8)in0); \
  1767. out_m = (v16u8)__msa_xori_b((v16u8)out_m, 128); \
  1768. out_m; \
  1769. })
  1770. /* Description : Converts inputs to unsigned bytes, interleave, average & store
  1771. as 8x4 unsigned byte block
  1772. Arguments : Inputs - in0, in1, in2, in3, dst0, dst1, pdst, stride
  1773. */
  1774. #define CONVERT_UB_AVG_ST8x4_UB(in0, in1, in2, in3, dst0, dst1, pdst, stride) \
  1775. { \
  1776. v16u8 tmp0_m, tmp1_m; \
  1777. uint8_t *pdst_m = (uint8_t *)(pdst); \
  1778. \
  1779. tmp0_m = PCKEV_XORI128_UB(in0, in1); \
  1780. tmp1_m = PCKEV_XORI128_UB(in2, in3); \
  1781. AVER_UB2_UB(tmp0_m, dst0, tmp1_m, dst1, tmp0_m, tmp1_m); \
  1782. ST8x4_UB(tmp0_m, tmp1_m, pdst_m, stride); \
  1783. }
  1784. /* Description : Pack even byte elements and store byte vector in destination
  1785. memory
  1786. Arguments : Inputs - in0, in1, pdst
  1787. */
  1788. #define PCKEV_ST_SB(in0, in1, pdst) \
  1789. { \
  1790. v16i8 tmp_m; \
  1791. \
  1792. tmp_m = __msa_pckev_b((v16i8)in1, (v16i8)in0); \
  1793. ST_SB(tmp_m, (pdst)); \
  1794. }
  1795. /* Description : Horizontal 2 tap filter kernel code
  1796. Arguments : Inputs - in0, in1, mask, coeff, shift
  1797. */
  1798. #define HORIZ_2TAP_FILT_UH(in0, in1, mask, coeff, shift) \
  1799. ({ \
  1800. v16i8 tmp0_m; \
  1801. v8u16 tmp1_m; \
  1802. \
  1803. tmp0_m = __msa_vshf_b((v16i8)mask, (v16i8)in1, (v16i8)in0); \
  1804. tmp1_m = __msa_dotp_u_h((v16u8)tmp0_m, (v16u8)coeff); \
  1805. tmp1_m = (v8u16)__msa_srari_h((v8i16)tmp1_m, shift); \
  1806. \
  1807. tmp1_m; \
  1808. })
  1809. #endif /* VPX_DSP_MIPS_MACROS_MSA_H_ */