macros_msa.h 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969
  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_VPX_DSP_MIPS_MACROS_MSA_H_
  11. #define VPX_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_B2_SH(...) VSHF_B2(v8i16, __VA_ARGS__)
  517. #define VSHF_B4(RTYPE, in0, in1, mask0, mask1, mask2, mask3, out0, out1, out2, \
  518. out3) \
  519. { \
  520. VSHF_B2(RTYPE, in0, in1, in0, in1, mask0, mask1, out0, out1); \
  521. VSHF_B2(RTYPE, in0, in1, in0, in1, mask2, mask3, out2, out3); \
  522. }
  523. #define VSHF_B4_SB(...) VSHF_B4(v16i8, __VA_ARGS__)
  524. #define VSHF_B4_SH(...) VSHF_B4(v8i16, __VA_ARGS__)
  525. /* Description : Dot product of byte vector elements
  526. Arguments : Inputs - mult0, mult1, cnst0, cnst1
  527. Outputs - out0, out1
  528. Return Type - as per RTYPE
  529. Details : Unsigned byte elements from 'mult0' are multiplied with
  530. unsigned byte elements from 'cnst0' producing a result
  531. twice the size of input i.e. unsigned halfword.
  532. The multiplication result of adjacent odd-even elements
  533. are added together and written to the 'out0' vector
  534. */
  535. #define DOTP_UB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  536. { \
  537. out0 = (RTYPE)__msa_dotp_u_h((v16u8)mult0, (v16u8)cnst0); \
  538. out1 = (RTYPE)__msa_dotp_u_h((v16u8)mult1, (v16u8)cnst1); \
  539. }
  540. #define DOTP_UB2_UH(...) DOTP_UB2(v8u16, __VA_ARGS__)
  541. #define DOTP_UB4(RTYPE, mult0, mult1, mult2, mult3, cnst0, cnst1, cnst2, \
  542. cnst3, out0, out1, out2, out3) \
  543. { \
  544. DOTP_UB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  545. DOTP_UB2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  546. }
  547. #define DOTP_UB4_UH(...) DOTP_UB4(v8u16, __VA_ARGS__)
  548. /* Description : Dot product of byte vector elements
  549. Arguments : Inputs - mult0, mult1, cnst0, cnst1
  550. Outputs - out0, out1
  551. Return Type - as per RTYPE
  552. Details : Signed byte elements from 'mult0' are multiplied with
  553. signed byte elements from 'cnst0' producing a result
  554. twice the size of input i.e. signed halfword.
  555. The multiplication result of adjacent odd-even elements
  556. are added together and written to the 'out0' vector
  557. */
  558. #define DOTP_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  559. { \
  560. out0 = (RTYPE)__msa_dotp_s_h((v16i8)mult0, (v16i8)cnst0); \
  561. out1 = (RTYPE)__msa_dotp_s_h((v16i8)mult1, (v16i8)cnst1); \
  562. }
  563. #define DOTP_SB2_SH(...) DOTP_SB2(v8i16, __VA_ARGS__)
  564. #define DOTP_SB4(RTYPE, mult0, mult1, mult2, mult3, cnst0, cnst1, cnst2, \
  565. cnst3, out0, out1, out2, out3) \
  566. { \
  567. DOTP_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  568. DOTP_SB2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  569. }
  570. #define DOTP_SB4_SH(...) DOTP_SB4(v8i16, __VA_ARGS__)
  571. /* Description : Dot product of halfword vector elements
  572. Arguments : Inputs - mult0, mult1, cnst0, cnst1
  573. Outputs - out0, out1
  574. Return Type - as per RTYPE
  575. Details : Signed halfword elements from 'mult0' are multiplied with
  576. signed halfword elements from 'cnst0' producing a result
  577. twice the size of input i.e. signed word.
  578. The multiplication result of adjacent odd-even elements
  579. are added together and written to the 'out0' vector
  580. */
  581. #define DOTP_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  582. { \
  583. out0 = (RTYPE)__msa_dotp_s_w((v8i16)mult0, (v8i16)cnst0); \
  584. out1 = (RTYPE)__msa_dotp_s_w((v8i16)mult1, (v8i16)cnst1); \
  585. }
  586. #define DOTP_SH2_SW(...) DOTP_SH2(v4i32, __VA_ARGS__)
  587. #define DOTP_SH4(RTYPE, mult0, mult1, mult2, mult3, cnst0, cnst1, cnst2, \
  588. cnst3, out0, out1, out2, out3) \
  589. { \
  590. DOTP_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  591. DOTP_SH2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  592. }
  593. #define DOTP_SH4_SW(...) DOTP_SH4(v4i32, __VA_ARGS__)
  594. /* Description : Dot product of word vector elements
  595. Arguments : Inputs - mult0, mult1, cnst0, cnst1
  596. Outputs - out0, out1
  597. Return Type - as per RTYPE
  598. Details : Signed word elements from 'mult0' are multiplied with
  599. signed word elements from 'cnst0' producing a result
  600. twice the size of input i.e. signed double word.
  601. The multiplication result of adjacent odd-even elements
  602. are added together and written to the 'out0' vector
  603. */
  604. #define DOTP_SW2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  605. { \
  606. out0 = (RTYPE)__msa_dotp_s_d((v4i32)mult0, (v4i32)cnst0); \
  607. out1 = (RTYPE)__msa_dotp_s_d((v4i32)mult1, (v4i32)cnst1); \
  608. }
  609. #define DOTP_SW2_SD(...) DOTP_SW2(v2i64, __VA_ARGS__)
  610. /* Description : Dot product & addition of byte vector elements
  611. Arguments : Inputs - mult0, mult1, cnst0, cnst1
  612. Outputs - out0, out1
  613. Return Type - as per RTYPE
  614. Details : Signed byte elements from 'mult0' are multiplied with
  615. signed byte elements from 'cnst0' producing a result
  616. twice the size of input i.e. signed halfword.
  617. The multiplication result of adjacent odd-even elements
  618. are added to the 'out0' vector
  619. */
  620. #define DPADD_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  621. { \
  622. out0 = (RTYPE)__msa_dpadd_s_h((v8i16)out0, (v16i8)mult0, (v16i8)cnst0); \
  623. out1 = (RTYPE)__msa_dpadd_s_h((v8i16)out1, (v16i8)mult1, (v16i8)cnst1); \
  624. }
  625. #define DPADD_SB2_SH(...) DPADD_SB2(v8i16, __VA_ARGS__)
  626. #define DPADD_SB4(RTYPE, mult0, mult1, mult2, mult3, cnst0, cnst1, cnst2, \
  627. cnst3, out0, out1, out2, out3) \
  628. { \
  629. DPADD_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1); \
  630. DPADD_SB2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3); \
  631. }
  632. #define DPADD_SB4_SH(...) DPADD_SB4(v8i16, __VA_ARGS__)
  633. /* Description : Dot product & addition of halfword vector elements
  634. Arguments : Inputs - mult0, mult1, cnst0, cnst1
  635. Outputs - out0, out1
  636. Return Type - as per RTYPE
  637. Details : Signed halfword elements from 'mult0' are multiplied with
  638. signed halfword elements from 'cnst0' producing a result
  639. twice the size of input i.e. signed word.
  640. The multiplication result of adjacent odd-even elements
  641. are added to the 'out0' vector
  642. */
  643. #define DPADD_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) \
  644. { \
  645. out0 = (RTYPE)__msa_dpadd_s_w((v4i32)out0, (v8i16)mult0, (v8i16)cnst0); \
  646. out1 = (RTYPE)__msa_dpadd_s_w((v4i32)out1, (v8i16)mult1, (v8i16)cnst1); \
  647. }
  648. #define DPADD_SH2_SW(...) DPADD_SH2(v4i32, __VA_ARGS__)
  649. /* Description : Dot product & addition of double word vector elements
  650. Arguments : Inputs - mult0, mult1
  651. Outputs - out0, out1
  652. Return Type - as per RTYPE
  653. Details : Each signed word element from 'mult0' is multiplied with itself
  654. producing an intermediate result twice the size of input
  655. i.e. signed double word
  656. The multiplication result of adjacent odd-even elements
  657. are added to the 'out0' vector
  658. */
  659. #define DPADD_SD2(RTYPE, mult0, mult1, out0, out1) \
  660. { \
  661. out0 = (RTYPE)__msa_dpadd_s_d((v2i64)out0, (v4i32)mult0, (v4i32)mult0); \
  662. out1 = (RTYPE)__msa_dpadd_s_d((v2i64)out1, (v4i32)mult1, (v4i32)mult1); \
  663. }
  664. #define DPADD_SD2_SD(...) DPADD_SD2(v2i64, __VA_ARGS__)
  665. /* Description : Minimum values between unsigned elements of
  666. either vector are copied to the output vector
  667. Arguments : Inputs - in0, in1, min_vec
  668. Outputs - in place operation
  669. Return Type - as per RTYPE
  670. Details : Minimum of unsigned halfword element values from 'in0' and
  671. 'min_vec' are written to output vector 'in0'
  672. */
  673. #define MIN_UH2(RTYPE, in0, in1, min_vec) \
  674. { \
  675. in0 = (RTYPE)__msa_min_u_h((v8u16)in0, min_vec); \
  676. in1 = (RTYPE)__msa_min_u_h((v8u16)in1, min_vec); \
  677. }
  678. #define MIN_UH2_UH(...) MIN_UH2(v8u16, __VA_ARGS__)
  679. #define MIN_UH4(RTYPE, in0, in1, in2, in3, min_vec) \
  680. { \
  681. MIN_UH2(RTYPE, in0, in1, min_vec); \
  682. MIN_UH2(RTYPE, in2, in3, min_vec); \
  683. }
  684. #define MIN_UH4_UH(...) MIN_UH4(v8u16, __VA_ARGS__)
  685. /* Description : Clips all signed halfword elements of input vector
  686. between 0 & 255
  687. Arguments : Input - in
  688. Output - out_m
  689. Return Type - signed halfword
  690. */
  691. #define CLIP_SH_0_255(in) \
  692. ({ \
  693. v8i16 max_m = __msa_ldi_h(255); \
  694. v8i16 out_m; \
  695. \
  696. out_m = __msa_maxi_s_h((v8i16)in, 0); \
  697. out_m = __msa_min_s_h((v8i16)max_m, (v8i16)out_m); \
  698. out_m; \
  699. })
  700. #define CLIP_SH2_0_255(in0, in1) \
  701. { \
  702. in0 = CLIP_SH_0_255(in0); \
  703. in1 = CLIP_SH_0_255(in1); \
  704. }
  705. #define CLIP_SH4_0_255(in0, in1, in2, in3) \
  706. { \
  707. CLIP_SH2_0_255(in0, in1); \
  708. CLIP_SH2_0_255(in2, in3); \
  709. }
  710. /* Description : Horizontal addition of 4 signed word elements of input vector
  711. Arguments : Input - in (signed word vector)
  712. Output - sum_m (i32 sum)
  713. Return Type - signed word (GP)
  714. Details : 4 signed word elements of 'in' vector are added together and
  715. the resulting integer sum is returned
  716. */
  717. #define HADD_SW_S32(in) \
  718. ({ \
  719. v2i64 res0_m, res1_m; \
  720. int32_t sum_m; \
  721. \
  722. res0_m = __msa_hadd_s_d((v4i32)in, (v4i32)in); \
  723. res1_m = __msa_splati_d(res0_m, 1); \
  724. res0_m = res0_m + res1_m; \
  725. sum_m = __msa_copy_s_w((v4i32)res0_m, 0); \
  726. sum_m; \
  727. })
  728. /* Description : Horizontal addition of 4 unsigned word elements
  729. Arguments : Input - in (unsigned word vector)
  730. Output - sum_m (u32 sum)
  731. Return Type - unsigned word (GP)
  732. Details : 4 unsigned word elements of 'in' vector are added together and
  733. the resulting integer sum is returned
  734. */
  735. #define HADD_UW_U32(in) \
  736. ({ \
  737. v2u64 res0_m, res1_m; \
  738. uint32_t sum_m; \
  739. \
  740. res0_m = __msa_hadd_u_d((v4u32)in, (v4u32)in); \
  741. res1_m = (v2u64)__msa_splati_d((v2i64)res0_m, 1); \
  742. res0_m += res1_m; \
  743. sum_m = __msa_copy_u_w((v4i32)res0_m, 0); \
  744. sum_m; \
  745. })
  746. /* Description : Horizontal addition of 8 unsigned halfword elements
  747. Arguments : Input - in (unsigned halfword vector)
  748. Output - sum_m (u32 sum)
  749. Return Type - unsigned word
  750. Details : 8 unsigned halfword elements of 'in' vector are added
  751. together and the resulting integer sum is returned
  752. */
  753. #define HADD_UH_U32(in) \
  754. ({ \
  755. v4u32 res_m; \
  756. uint32_t sum_m; \
  757. \
  758. res_m = __msa_hadd_u_w((v8u16)in, (v8u16)in); \
  759. sum_m = HADD_UW_U32(res_m); \
  760. sum_m; \
  761. })
  762. /* Description : Horizontal addition of unsigned byte vector elements
  763. Arguments : Inputs - in0, in1
  764. Outputs - out0, out1
  765. Return Type - as per RTYPE
  766. Details : Each unsigned odd byte element from 'in0' is added to
  767. even unsigned byte element from 'in0' (pairwise) and the
  768. halfword result is written to 'out0'
  769. */
  770. #define HADD_UB2(RTYPE, in0, in1, out0, out1) \
  771. { \
  772. out0 = (RTYPE)__msa_hadd_u_h((v16u8)in0, (v16u8)in0); \
  773. out1 = (RTYPE)__msa_hadd_u_h((v16u8)in1, (v16u8)in1); \
  774. }
  775. #define HADD_UB2_UH(...) HADD_UB2(v8u16, __VA_ARGS__)
  776. #define HADD_UB4(RTYPE, in0, in1, in2, in3, out0, out1, out2, out3) \
  777. { \
  778. HADD_UB2(RTYPE, in0, in1, out0, out1); \
  779. HADD_UB2(RTYPE, in2, in3, out2, out3); \
  780. }
  781. #define HADD_UB4_UH(...) HADD_UB4(v8u16, __VA_ARGS__)
  782. /* Description : Horizontal subtraction of unsigned byte vector elements
  783. Arguments : Inputs - in0, in1
  784. Outputs - out0, out1
  785. Return Type - as per RTYPE
  786. Details : Each unsigned odd byte element from 'in0' is subtracted from
  787. even unsigned byte element from 'in0' (pairwise) and the
  788. halfword result is written to 'out0'
  789. */
  790. #define HSUB_UB2(RTYPE, in0, in1, out0, out1) \
  791. { \
  792. out0 = (RTYPE)__msa_hsub_u_h((v16u8)in0, (v16u8)in0); \
  793. out1 = (RTYPE)__msa_hsub_u_h((v16u8)in1, (v16u8)in1); \
  794. }
  795. #define HSUB_UB2_SH(...) HSUB_UB2(v8i16, __VA_ARGS__)
  796. /* Description : SAD (Sum of Absolute Difference)
  797. Arguments : Inputs - in0, in1, ref0, ref1
  798. Outputs - sad_m (halfword vector)
  799. Return Type - unsigned halfword
  800. Details : Absolute difference of all the byte elements from 'in0' with
  801. 'ref0' is calculated and preserved in 'diff0'. Then even-odd
  802. pairs are added together to generate 8 halfword results.
  803. */
  804. #define SAD_UB2_UH(in0, in1, ref0, ref1) \
  805. ({ \
  806. v16u8 diff0_m, diff1_m; \
  807. v8u16 sad_m = { 0 }; \
  808. \
  809. diff0_m = __msa_asub_u_b((v16u8)in0, (v16u8)ref0); \
  810. diff1_m = __msa_asub_u_b((v16u8)in1, (v16u8)ref1); \
  811. \
  812. sad_m += __msa_hadd_u_h((v16u8)diff0_m, (v16u8)diff0_m); \
  813. sad_m += __msa_hadd_u_h((v16u8)diff1_m, (v16u8)diff1_m); \
  814. \
  815. sad_m; \
  816. })
  817. /* Description : Horizontal subtraction of signed halfword vector elements
  818. Arguments : Inputs - in0, in1
  819. Outputs - out0, out1
  820. Return Type - as per RTYPE
  821. Details : Each signed odd halfword element from 'in0' is subtracted from
  822. even signed halfword element from 'in0' (pairwise) and the
  823. word result is written to 'out0'
  824. */
  825. #define HSUB_UH2(RTYPE, in0, in1, out0, out1) \
  826. { \
  827. out0 = (RTYPE)__msa_hsub_s_w((v8i16)in0, (v8i16)in0); \
  828. out1 = (RTYPE)__msa_hsub_s_w((v8i16)in1, (v8i16)in1); \
  829. }
  830. #define HSUB_UH2_SW(...) HSUB_UH2(v4i32, __VA_ARGS__)
  831. /* Description : Set element n input vector to GPR value
  832. Arguments : Inputs - in0, in1, in2, in3
  833. Output - out
  834. Return Type - as per RTYPE
  835. Details : Set element 0 in vector 'out' to value specified in 'in0'
  836. */
  837. #define INSERT_W2(RTYPE, in0, in1, out) \
  838. { \
  839. out = (RTYPE)__msa_insert_w((v4i32)out, 0, in0); \
  840. out = (RTYPE)__msa_insert_w((v4i32)out, 1, in1); \
  841. }
  842. #define INSERT_W2_SB(...) INSERT_W2(v16i8, __VA_ARGS__)
  843. #define INSERT_W4(RTYPE, in0, in1, in2, in3, out) \
  844. { \
  845. out = (RTYPE)__msa_insert_w((v4i32)out, 0, in0); \
  846. out = (RTYPE)__msa_insert_w((v4i32)out, 1, in1); \
  847. out = (RTYPE)__msa_insert_w((v4i32)out, 2, in2); \
  848. out = (RTYPE)__msa_insert_w((v4i32)out, 3, in3); \
  849. }
  850. #define INSERT_W4_UB(...) INSERT_W4(v16u8, __VA_ARGS__)
  851. #define INSERT_W4_SB(...) INSERT_W4(v16i8, __VA_ARGS__)
  852. #define INSERT_D2(RTYPE, in0, in1, out) \
  853. { \
  854. out = (RTYPE)__msa_insert_d((v2i64)out, 0, in0); \
  855. out = (RTYPE)__msa_insert_d((v2i64)out, 1, in1); \
  856. }
  857. #define INSERT_D2_UB(...) INSERT_D2(v16u8, __VA_ARGS__)
  858. #define INSERT_D2_SB(...) INSERT_D2(v16i8, __VA_ARGS__)
  859. #define INSERT_D2_SH(...) INSERT_D2(v8i16, __VA_ARGS__)
  860. /* Description : Interleave even byte elements from vectors
  861. Arguments : Inputs - in0, in1, in2, in3
  862. Outputs - out0, out1
  863. Return Type - as per RTYPE
  864. Details : Even byte elements of 'in0' and 'in1' are interleaved
  865. and written to 'out0'
  866. */
  867. #define ILVEV_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  868. { \
  869. out0 = (RTYPE)__msa_ilvev_b((v16i8)in1, (v16i8)in0); \
  870. out1 = (RTYPE)__msa_ilvev_b((v16i8)in3, (v16i8)in2); \
  871. }
  872. #define ILVEV_B2_UB(...) ILVEV_B2(v16u8, __VA_ARGS__)
  873. #define ILVEV_B2_SH(...) ILVEV_B2(v8i16, __VA_ARGS__)
  874. /* Description : Interleave even halfword elements from vectors
  875. Arguments : Inputs - in0, in1, in2, in3
  876. Outputs - out0, out1
  877. Return Type - as per RTYPE
  878. Details : Even halfword elements of 'in0' and 'in1' are interleaved
  879. and written to 'out0'
  880. */
  881. #define ILVEV_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  882. { \
  883. out0 = (RTYPE)__msa_ilvev_h((v8i16)in1, (v8i16)in0); \
  884. out1 = (RTYPE)__msa_ilvev_h((v8i16)in3, (v8i16)in2); \
  885. }
  886. #define ILVEV_H2_UB(...) ILVEV_H2(v16u8, __VA_ARGS__)
  887. #define ILVEV_H2_SH(...) ILVEV_H2(v8i16, __VA_ARGS__)
  888. #define ILVEV_H2_SW(...) ILVEV_H2(v4i32, __VA_ARGS__)
  889. /* Description : Interleave even word elements from vectors
  890. Arguments : Inputs - in0, in1, in2, in3
  891. Outputs - out0, out1
  892. Return Type - as per RTYPE
  893. Details : Even word elements of 'in0' and 'in1' are interleaved
  894. and written to 'out0'
  895. */
  896. #define ILVEV_W2(RTYPE, in0, in1, in2, in3, out0, out1) \
  897. { \
  898. out0 = (RTYPE)__msa_ilvev_w((v4i32)in1, (v4i32)in0); \
  899. out1 = (RTYPE)__msa_ilvev_w((v4i32)in3, (v4i32)in2); \
  900. }
  901. #define ILVEV_W2_SB(...) ILVEV_W2(v16i8, __VA_ARGS__)
  902. /* Description : Interleave even double word elements from vectors
  903. Arguments : Inputs - in0, in1, in2, in3
  904. Outputs - out0, out1
  905. Return Type - as per RTYPE
  906. Details : Even double word elements of 'in0' and 'in1' are interleaved
  907. and written to 'out0'
  908. */
  909. #define ILVEV_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  910. { \
  911. out0 = (RTYPE)__msa_ilvev_d((v2i64)in1, (v2i64)in0); \
  912. out1 = (RTYPE)__msa_ilvev_d((v2i64)in3, (v2i64)in2); \
  913. }
  914. #define ILVEV_D2_UB(...) ILVEV_D2(v16u8, __VA_ARGS__)
  915. /* Description : Interleave left half of byte elements from vectors
  916. Arguments : Inputs - in0, in1, in2, in3
  917. Outputs - out0, out1
  918. Return Type - as per RTYPE
  919. Details : Left half of byte elements of 'in0' and 'in1' are interleaved
  920. and written to 'out0'.
  921. */
  922. #define ILVL_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  923. { \
  924. out0 = (RTYPE)__msa_ilvl_b((v16i8)in0, (v16i8)in1); \
  925. out1 = (RTYPE)__msa_ilvl_b((v16i8)in2, (v16i8)in3); \
  926. }
  927. #define ILVL_B2_UB(...) ILVL_B2(v16u8, __VA_ARGS__)
  928. #define ILVL_B2_SB(...) ILVL_B2(v16i8, __VA_ARGS__)
  929. #define ILVL_B2_UH(...) ILVL_B2(v8u16, __VA_ARGS__)
  930. #define ILVL_B2_SH(...) ILVL_B2(v8i16, __VA_ARGS__)
  931. #define ILVL_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  932. out2, out3) \
  933. { \
  934. ILVL_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  935. ILVL_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
  936. }
  937. #define ILVL_B4_SB(...) ILVL_B4(v16i8, __VA_ARGS__)
  938. #define ILVL_B4_SH(...) ILVL_B4(v8i16, __VA_ARGS__)
  939. #define ILVL_B4_UH(...) ILVL_B4(v8u16, __VA_ARGS__)
  940. /* Description : Interleave left half of halfword elements from vectors
  941. Arguments : Inputs - in0, in1, in2, in3
  942. Outputs - out0, out1
  943. Return Type - as per RTYPE
  944. Details : Left half of halfword elements of 'in0' and 'in1' are
  945. interleaved and written to 'out0'.
  946. */
  947. #define ILVL_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  948. { \
  949. out0 = (RTYPE)__msa_ilvl_h((v8i16)in0, (v8i16)in1); \
  950. out1 = (RTYPE)__msa_ilvl_h((v8i16)in2, (v8i16)in3); \
  951. }
  952. #define ILVL_H2_SH(...) ILVL_H2(v8i16, __VA_ARGS__)
  953. #define ILVL_H2_SW(...) ILVL_H2(v4i32, __VA_ARGS__)
  954. /* Description : Interleave left half of word elements from vectors
  955. Arguments : Inputs - in0, in1, in2, in3
  956. Outputs - out0, out1
  957. Return Type - as per RTYPE
  958. Details : Left half of word elements of 'in0' and 'in1' are interleaved
  959. and written to 'out0'.
  960. */
  961. #define ILVL_W2(RTYPE, in0, in1, in2, in3, out0, out1) \
  962. { \
  963. out0 = (RTYPE)__msa_ilvl_w((v4i32)in0, (v4i32)in1); \
  964. out1 = (RTYPE)__msa_ilvl_w((v4i32)in2, (v4i32)in3); \
  965. }
  966. #define ILVL_W2_UB(...) ILVL_W2(v16u8, __VA_ARGS__)
  967. #define ILVL_W2_SH(...) ILVL_W2(v8i16, __VA_ARGS__)
  968. /* Description : Interleave right half of byte elements from vectors
  969. Arguments : Inputs - in0, in1, in2, in3
  970. Outputs - out0, out1
  971. Return Type - as per RTYPE
  972. Details : Right half of byte elements of 'in0' and 'in1' are interleaved
  973. and written to out0.
  974. */
  975. #define ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  976. { \
  977. out0 = (RTYPE)__msa_ilvr_b((v16i8)in0, (v16i8)in1); \
  978. out1 = (RTYPE)__msa_ilvr_b((v16i8)in2, (v16i8)in3); \
  979. }
  980. #define ILVR_B2_UB(...) ILVR_B2(v16u8, __VA_ARGS__)
  981. #define ILVR_B2_SB(...) ILVR_B2(v16i8, __VA_ARGS__)
  982. #define ILVR_B2_UH(...) ILVR_B2(v8u16, __VA_ARGS__)
  983. #define ILVR_B2_SH(...) ILVR_B2(v8i16, __VA_ARGS__)
  984. #define ILVR_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  985. out2, out3) \
  986. { \
  987. ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  988. ILVR_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
  989. }
  990. #define ILVR_B4_UB(...) ILVR_B4(v16u8, __VA_ARGS__)
  991. #define ILVR_B4_SB(...) ILVR_B4(v16i8, __VA_ARGS__)
  992. #define ILVR_B4_UH(...) ILVR_B4(v8u16, __VA_ARGS__)
  993. #define ILVR_B4_SH(...) ILVR_B4(v8i16, __VA_ARGS__)
  994. #define ILVR_B8(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, in8, in9, in10, \
  995. in11, in12, in13, in14, in15, out0, out1, out2, out3, out4, \
  996. out5, out6, out7) \
  997. { \
  998. ILVR_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, \
  999. out3); \
  1000. ILVR_B4(RTYPE, in8, in9, in10, in11, in12, in13, in14, in15, out4, out5, \
  1001. out6, out7); \
  1002. }
  1003. #define ILVR_B8_UH(...) ILVR_B8(v8u16, __VA_ARGS__)
  1004. /* Description : Interleave right half of halfword elements from vectors
  1005. Arguments : Inputs - in0, in1, in2, in3
  1006. Outputs - out0, out1
  1007. Return Type - as per RTYPE
  1008. Details : Right half of halfword elements of 'in0' and 'in1' are
  1009. interleaved and written to 'out0'.
  1010. */
  1011. #define ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1012. { \
  1013. out0 = (RTYPE)__msa_ilvr_h((v8i16)in0, (v8i16)in1); \
  1014. out1 = (RTYPE)__msa_ilvr_h((v8i16)in2, (v8i16)in3); \
  1015. }
  1016. #define ILVR_H2_SH(...) ILVR_H2(v8i16, __VA_ARGS__)
  1017. #define ILVR_H2_SW(...) ILVR_H2(v4i32, __VA_ARGS__)
  1018. #define ILVR_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  1019. out2, out3) \
  1020. { \
  1021. ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1022. ILVR_H2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1023. }
  1024. #define ILVR_H4_SH(...) ILVR_H4(v8i16, __VA_ARGS__)
  1025. #define ILVR_W2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1026. { \
  1027. out0 = (RTYPE)__msa_ilvr_w((v4i32)in0, (v4i32)in1); \
  1028. out1 = (RTYPE)__msa_ilvr_w((v4i32)in2, (v4i32)in3); \
  1029. }
  1030. #define ILVR_W2_UB(...) ILVR_W2(v16u8, __VA_ARGS__)
  1031. #define ILVR_W2_SH(...) ILVR_W2(v8i16, __VA_ARGS__)
  1032. #define ILVR_W4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  1033. out2, out3) \
  1034. { \
  1035. ILVR_W2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1036. ILVR_W2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1037. }
  1038. #define ILVR_W4_UB(...) ILVR_W4(v16u8, __VA_ARGS__)
  1039. /* Description : Interleave right half of double word elements from vectors
  1040. Arguments : Inputs - in0, in1, in2, in3
  1041. Outputs - out0, out1
  1042. Return Type - as per RTYPE
  1043. Details : Right half of double word elements of 'in0' and 'in1' are
  1044. interleaved and written to 'out0'.
  1045. */
  1046. #define ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1047. { \
  1048. out0 = (RTYPE)__msa_ilvr_d((v2i64)(in0), (v2i64)(in1)); \
  1049. out1 = (RTYPE)__msa_ilvr_d((v2i64)(in2), (v2i64)(in3)); \
  1050. }
  1051. #define ILVR_D2_UB(...) ILVR_D2(v16u8, __VA_ARGS__)
  1052. #define ILVR_D2_SB(...) ILVR_D2(v16i8, __VA_ARGS__)
  1053. #define ILVR_D2_SH(...) ILVR_D2(v8i16, __VA_ARGS__)
  1054. #define ILVR_D3(RTYPE, in0, in1, in2, in3, in4, in5, out0, out1, out2) \
  1055. { \
  1056. ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1057. out2 = (RTYPE)__msa_ilvr_d((v2i64)(in4), (v2i64)(in5)); \
  1058. }
  1059. #define ILVR_D3_SB(...) ILVR_D3(v16i8, __VA_ARGS__)
  1060. #define ILVR_D4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  1061. out2, out3) \
  1062. { \
  1063. ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1064. ILVR_D2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1065. }
  1066. #define ILVR_D4_SB(...) ILVR_D4(v16i8, __VA_ARGS__)
  1067. #define ILVR_D4_UB(...) ILVR_D4(v16u8, __VA_ARGS__)
  1068. /* Description : Interleave both left and right half of input vectors
  1069. Arguments : Inputs - in0, in1
  1070. Outputs - out0, out1
  1071. Return Type - as per RTYPE
  1072. Details : Right half of byte elements from 'in0' and 'in1' are
  1073. interleaved and written to 'out0'
  1074. */
  1075. #define ILVRL_B2(RTYPE, in0, in1, out0, out1) \
  1076. { \
  1077. out0 = (RTYPE)__msa_ilvr_b((v16i8)in0, (v16i8)in1); \
  1078. out1 = (RTYPE)__msa_ilvl_b((v16i8)in0, (v16i8)in1); \
  1079. }
  1080. #define ILVRL_B2_UB(...) ILVRL_B2(v16u8, __VA_ARGS__)
  1081. #define ILVRL_B2_SB(...) ILVRL_B2(v16i8, __VA_ARGS__)
  1082. #define ILVRL_B2_UH(...) ILVRL_B2(v8u16, __VA_ARGS__)
  1083. #define ILVRL_B2_SH(...) ILVRL_B2(v8i16, __VA_ARGS__)
  1084. #define ILVRL_H2(RTYPE, in0, in1, out0, out1) \
  1085. { \
  1086. out0 = (RTYPE)__msa_ilvr_h((v8i16)in0, (v8i16)in1); \
  1087. out1 = (RTYPE)__msa_ilvl_h((v8i16)in0, (v8i16)in1); \
  1088. }
  1089. #define ILVRL_H2_SH(...) ILVRL_H2(v8i16, __VA_ARGS__)
  1090. #define ILVRL_H2_SW(...) ILVRL_H2(v4i32, __VA_ARGS__)
  1091. #define ILVRL_W2(RTYPE, in0, in1, out0, out1) \
  1092. { \
  1093. out0 = (RTYPE)__msa_ilvr_w((v4i32)in0, (v4i32)in1); \
  1094. out1 = (RTYPE)__msa_ilvl_w((v4i32)in0, (v4i32)in1); \
  1095. }
  1096. #define ILVRL_W2_UB(...) ILVRL_W2(v16u8, __VA_ARGS__)
  1097. #define ILVRL_W2_SB(...) ILVRL_W2(v16i8, __VA_ARGS__)
  1098. #define ILVRL_W2_SH(...) ILVRL_W2(v8i16, __VA_ARGS__)
  1099. #define ILVRL_W2_SW(...) ILVRL_W2(v4i32, __VA_ARGS__)
  1100. /* Description : Saturate the halfword element values to the max
  1101. unsigned value of (sat_val + 1) bits
  1102. The element data width remains unchanged
  1103. Arguments : Inputs - in0, in1, sat_val
  1104. Outputs - in place operation
  1105. Return Type - as per RTYPE
  1106. Details : Each unsigned halfword element from 'in0' is saturated to the
  1107. value generated with (sat_val + 1) bit range.
  1108. The results are written in place
  1109. */
  1110. #define SAT_UH2(RTYPE, in0, in1, sat_val) \
  1111. { \
  1112. in0 = (RTYPE)__msa_sat_u_h((v8u16)in0, sat_val); \
  1113. in1 = (RTYPE)__msa_sat_u_h((v8u16)in1, sat_val); \
  1114. }
  1115. #define SAT_UH2_UH(...) SAT_UH2(v8u16, __VA_ARGS__)
  1116. #define SAT_UH4(RTYPE, in0, in1, in2, in3, sat_val) \
  1117. { \
  1118. SAT_UH2(RTYPE, in0, in1, sat_val); \
  1119. SAT_UH2(RTYPE, in2, in3, sat_val) \
  1120. }
  1121. #define SAT_UH4_UH(...) SAT_UH4(v8u16, __VA_ARGS__)
  1122. /* Description : Saturate the halfword element values to the max
  1123. unsigned value of (sat_val + 1) bits
  1124. The element data width remains unchanged
  1125. Arguments : Inputs - in0, in1, sat_val
  1126. Outputs - in place operation
  1127. Return Type - as per RTYPE
  1128. Details : Each unsigned halfword element from 'in0' is saturated to the
  1129. value generated with (sat_val + 1) bit range
  1130. The results are written in place
  1131. */
  1132. #define SAT_SH2(RTYPE, in0, in1, sat_val) \
  1133. { \
  1134. in0 = (RTYPE)__msa_sat_s_h((v8i16)in0, sat_val); \
  1135. in1 = (RTYPE)__msa_sat_s_h((v8i16)in1, sat_val); \
  1136. }
  1137. #define SAT_SH2_SH(...) SAT_SH2(v8i16, __VA_ARGS__)
  1138. #define SAT_SH4(RTYPE, in0, in1, in2, in3, sat_val) \
  1139. { \
  1140. SAT_SH2(RTYPE, in0, in1, sat_val); \
  1141. SAT_SH2(RTYPE, in2, in3, sat_val); \
  1142. }
  1143. #define SAT_SH4_SH(...) SAT_SH4(v8i16, __VA_ARGS__)
  1144. /* Description : Indexed halfword element values are replicated to all
  1145. elements in output vector
  1146. Arguments : Inputs - in, idx0, idx1
  1147. Outputs - out0, out1
  1148. Return Type - as per RTYPE
  1149. Details : 'idx0' element value from 'in' vector is replicated to all
  1150. elements in 'out0' vector
  1151. Valid index range for halfword operation is 0-7
  1152. */
  1153. #define SPLATI_H2(RTYPE, in, idx0, idx1, out0, out1) \
  1154. { \
  1155. out0 = (RTYPE)__msa_splati_h((v8i16)in, idx0); \
  1156. out1 = (RTYPE)__msa_splati_h((v8i16)in, idx1); \
  1157. }
  1158. #define SPLATI_H2_SH(...) SPLATI_H2(v8i16, __VA_ARGS__)
  1159. #define SPLATI_H4(RTYPE, in, idx0, idx1, idx2, idx3, out0, out1, out2, out3) \
  1160. { \
  1161. SPLATI_H2(RTYPE, in, idx0, idx1, out0, out1); \
  1162. SPLATI_H2(RTYPE, in, idx2, idx3, out2, out3); \
  1163. }
  1164. #define SPLATI_H4_SB(...) SPLATI_H4(v16i8, __VA_ARGS__)
  1165. #define SPLATI_H4_SH(...) SPLATI_H4(v8i16, __VA_ARGS__)
  1166. /* Description : Pack even byte elements of vector pairs
  1167. Arguments : Inputs - in0, in1, in2, in3
  1168. Outputs - out0, out1
  1169. Return Type - as per RTYPE
  1170. Details : Even byte elements of 'in0' are copied to the left half of
  1171. 'out0' & even byte elements of 'in1' are copied to the right
  1172. half of 'out0'.
  1173. */
  1174. #define PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1175. { \
  1176. out0 = (RTYPE)__msa_pckev_b((v16i8)in0, (v16i8)in1); \
  1177. out1 = (RTYPE)__msa_pckev_b((v16i8)in2, (v16i8)in3); \
  1178. }
  1179. #define PCKEV_B2_SB(...) PCKEV_B2(v16i8, __VA_ARGS__)
  1180. #define PCKEV_B2_UB(...) PCKEV_B2(v16u8, __VA_ARGS__)
  1181. #define PCKEV_B2_SH(...) PCKEV_B2(v8i16, __VA_ARGS__)
  1182. #define PCKEV_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  1183. out2, out3) \
  1184. { \
  1185. PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1186. PCKEV_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1187. }
  1188. #define PCKEV_B4_SB(...) PCKEV_B4(v16i8, __VA_ARGS__)
  1189. #define PCKEV_B4_UB(...) PCKEV_B4(v16u8, __VA_ARGS__)
  1190. #define PCKEV_B4_SH(...) PCKEV_B4(v8i16, __VA_ARGS__)
  1191. /* Description : Pack even halfword elements of vector pairs
  1192. Arguments : Inputs - in0, in1, in2, in3
  1193. Outputs - out0, out1
  1194. Return Type - as per RTYPE
  1195. Details : Even halfword elements of 'in0' are copied to the left half of
  1196. 'out0' & even halfword elements of 'in1' are copied to the
  1197. right half of 'out0'.
  1198. */
  1199. #define PCKEV_H2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1200. { \
  1201. out0 = (RTYPE)__msa_pckev_h((v8i16)in0, (v8i16)in1); \
  1202. out1 = (RTYPE)__msa_pckev_h((v8i16)in2, (v8i16)in3); \
  1203. }
  1204. #define PCKEV_H2_SH(...) PCKEV_H2(v8i16, __VA_ARGS__)
  1205. #define PCKEV_H2_SW(...) PCKEV_H2(v4i32, __VA_ARGS__)
  1206. #define PCKEV_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  1207. out2, out3) \
  1208. { \
  1209. PCKEV_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1210. PCKEV_H2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1211. }
  1212. #define PCKEV_H4_SH(...) PCKEV_H4(v8i16, __VA_ARGS__)
  1213. /* Description : Pack even double word elements of vector pairs
  1214. Arguments : Inputs - in0, in1, in2, in3
  1215. Outputs - out0, out1
  1216. Return Type - as per RTYPE
  1217. Details : Even double elements of 'in0' are copied to the left half of
  1218. 'out0' & even double elements of 'in1' are copied to the right
  1219. half of 'out0'.
  1220. */
  1221. #define PCKEV_D2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1222. { \
  1223. out0 = (RTYPE)__msa_pckev_d((v2i64)in0, (v2i64)in1); \
  1224. out1 = (RTYPE)__msa_pckev_d((v2i64)in2, (v2i64)in3); \
  1225. }
  1226. #define PCKEV_D2_UB(...) PCKEV_D2(v16u8, __VA_ARGS__)
  1227. #define PCKEV_D2_SH(...) PCKEV_D2(v8i16, __VA_ARGS__)
  1228. #define PCKEV_D4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  1229. out2, out3) \
  1230. { \
  1231. PCKEV_D2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1232. PCKEV_D2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1233. }
  1234. #define PCKEV_D4_UB(...) PCKEV_D4(v16u8, __VA_ARGS__)
  1235. /* Description : Each byte element is logically xor'ed with immediate 128
  1236. Arguments : Inputs - in0, in1
  1237. Outputs - in place operation
  1238. Return Type - as per RTYPE
  1239. Details : Each unsigned byte element from input vector 'in0' is
  1240. logically xor'ed with 128 and the result is stored in-place.
  1241. */
  1242. #define XORI_B2_128(RTYPE, in0, in1) \
  1243. { \
  1244. in0 = (RTYPE)__msa_xori_b((v16u8)in0, 128); \
  1245. in1 = (RTYPE)__msa_xori_b((v16u8)in1, 128); \
  1246. }
  1247. #define XORI_B2_128_UB(...) XORI_B2_128(v16u8, __VA_ARGS__)
  1248. #define XORI_B2_128_SB(...) XORI_B2_128(v16i8, __VA_ARGS__)
  1249. #define XORI_B3_128(RTYPE, in0, in1, in2) \
  1250. { \
  1251. XORI_B2_128(RTYPE, in0, in1); \
  1252. in2 = (RTYPE)__msa_xori_b((v16u8)in2, 128); \
  1253. }
  1254. #define XORI_B3_128_SB(...) XORI_B3_128(v16i8, __VA_ARGS__)
  1255. #define XORI_B4_128(RTYPE, in0, in1, in2, in3) \
  1256. { \
  1257. XORI_B2_128(RTYPE, in0, in1); \
  1258. XORI_B2_128(RTYPE, in2, in3); \
  1259. }
  1260. #define XORI_B4_128_UB(...) XORI_B4_128(v16u8, __VA_ARGS__)
  1261. #define XORI_B4_128_SB(...) XORI_B4_128(v16i8, __VA_ARGS__)
  1262. #define XORI_B7_128(RTYPE, in0, in1, in2, in3, in4, in5, in6) \
  1263. { \
  1264. XORI_B4_128(RTYPE, in0, in1, in2, in3); \
  1265. XORI_B3_128(RTYPE, in4, in5, in6); \
  1266. }
  1267. #define XORI_B7_128_SB(...) XORI_B7_128(v16i8, __VA_ARGS__)
  1268. /* Description : Average of signed halfword elements -> (a + b) / 2
  1269. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1270. Outputs - out0, out1, out2, out3
  1271. Return Type - as per RTYPE
  1272. Details : Each signed halfword element from 'in0' is added to each
  1273. signed halfword element of 'in1' with full precision resulting
  1274. in one extra bit in the result. The result is then divided by
  1275. 2 and written to 'out0'
  1276. */
  1277. #define AVE_SH4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  1278. out2, out3) \
  1279. { \
  1280. out0 = (RTYPE)__msa_ave_s_h((v8i16)in0, (v8i16)in1); \
  1281. out1 = (RTYPE)__msa_ave_s_h((v8i16)in2, (v8i16)in3); \
  1282. out2 = (RTYPE)__msa_ave_s_h((v8i16)in4, (v8i16)in5); \
  1283. out3 = (RTYPE)__msa_ave_s_h((v8i16)in6, (v8i16)in7); \
  1284. }
  1285. #define AVE_SH4_SH(...) AVE_SH4(v8i16, __VA_ARGS__)
  1286. /* Description : Addition of signed halfword elements and signed saturation
  1287. Arguments : Inputs - in0, in1, in2, in3
  1288. Outputs - out0, out1
  1289. Return Type - as per RTYPE
  1290. Details : Signed halfword elements from 'in0' are added to signed
  1291. halfword elements of 'in1'. The result is then signed saturated
  1292. between halfword data type range
  1293. */
  1294. #define ADDS_SH2(RTYPE, in0, in1, in2, in3, out0, out1) \
  1295. { \
  1296. out0 = (RTYPE)__msa_adds_s_h((v8i16)in0, (v8i16)in1); \
  1297. out1 = (RTYPE)__msa_adds_s_h((v8i16)in2, (v8i16)in3); \
  1298. }
  1299. #define ADDS_SH2_SH(...) ADDS_SH2(v8i16, __VA_ARGS__)
  1300. #define ADDS_SH4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  1301. out2, out3) \
  1302. { \
  1303. ADDS_SH2(RTYPE, in0, in1, in2, in3, out0, out1); \
  1304. ADDS_SH2(RTYPE, in4, in5, in6, in7, out2, out3); \
  1305. }
  1306. #define ADDS_SH4_SH(...) ADDS_SH4(v8i16, __VA_ARGS__)
  1307. /* Description : Shift left all elements of vector (generic for all data types)
  1308. Arguments : Inputs - in0, in1, in2, in3, shift
  1309. Outputs - in place operation
  1310. Return Type - as per input vector RTYPE
  1311. Details : Each element of vector 'in0' is left shifted by 'shift' and
  1312. the result is written in-place.
  1313. */
  1314. #define SLLI_4V(in0, in1, in2, in3, shift) \
  1315. { \
  1316. in0 = in0 << shift; \
  1317. in1 = in1 << shift; \
  1318. in2 = in2 << shift; \
  1319. in3 = in3 << shift; \
  1320. }
  1321. /* Description : Arithmetic shift right all elements of vector
  1322. (generic for all data types)
  1323. Arguments : Inputs - in0, in1, in2, in3, shift
  1324. Outputs - in place operation
  1325. Return Type - as per input vector RTYPE
  1326. Details : Each element of vector 'in0' is right shifted by 'shift' and
  1327. the result is written in-place. 'shift' is a GP variable.
  1328. */
  1329. #define SRA_2V(in0, in1, shift) \
  1330. { \
  1331. in0 = in0 >> shift; \
  1332. in1 = in1 >> shift; \
  1333. }
  1334. #define SRA_4V(in0, in1, in2, in3, shift) \
  1335. { \
  1336. in0 = in0 >> shift; \
  1337. in1 = in1 >> shift; \
  1338. in2 = in2 >> shift; \
  1339. in3 = in3 >> shift; \
  1340. }
  1341. /* Description : Shift right arithmetic rounded words
  1342. Arguments : Inputs - in0, in1, shift
  1343. Outputs - in place operation
  1344. Return Type - as per RTYPE
  1345. Details : Each element of vector 'in0' is shifted right arithmetically by
  1346. the number of bits in the corresponding element in the vector
  1347. 'shift'. The last discarded bit is added to shifted value for
  1348. rounding and the result is written in-place.
  1349. 'shift' is a vector.
  1350. */
  1351. #define SRAR_W2(RTYPE, in0, in1, shift) \
  1352. { \
  1353. in0 = (RTYPE)__msa_srar_w((v4i32)in0, (v4i32)shift); \
  1354. in1 = (RTYPE)__msa_srar_w((v4i32)in1, (v4i32)shift); \
  1355. }
  1356. #define SRAR_W4(RTYPE, in0, in1, in2, in3, shift) \
  1357. { \
  1358. SRAR_W2(RTYPE, in0, in1, shift) \
  1359. SRAR_W2(RTYPE, in2, in3, shift) \
  1360. }
  1361. #define SRAR_W4_SW(...) SRAR_W4(v4i32, __VA_ARGS__)
  1362. /* Description : Shift right arithmetic rounded (immediate)
  1363. Arguments : Inputs - in0, in1, shift
  1364. Outputs - in place operation
  1365. Return Type - as per RTYPE
  1366. Details : Each element of vector 'in0' is shifted right arithmetically by
  1367. the value in 'shift'. The last discarded bit is added to the
  1368. shifted value for rounding and the result is written in-place.
  1369. 'shift' is an immediate value.
  1370. */
  1371. #define SRARI_H2(RTYPE, in0, in1, shift) \
  1372. { \
  1373. in0 = (RTYPE)__msa_srari_h((v8i16)in0, shift); \
  1374. in1 = (RTYPE)__msa_srari_h((v8i16)in1, shift); \
  1375. }
  1376. #define SRARI_H2_UH(...) SRARI_H2(v8u16, __VA_ARGS__)
  1377. #define SRARI_H2_SH(...) SRARI_H2(v8i16, __VA_ARGS__)
  1378. #define SRARI_H4(RTYPE, in0, in1, in2, in3, shift) \
  1379. { \
  1380. SRARI_H2(RTYPE, in0, in1, shift); \
  1381. SRARI_H2(RTYPE, in2, in3, shift); \
  1382. }
  1383. #define SRARI_H4_UH(...) SRARI_H4(v8u16, __VA_ARGS__)
  1384. #define SRARI_H4_SH(...) SRARI_H4(v8i16, __VA_ARGS__)
  1385. #define SRARI_W2(RTYPE, in0, in1, shift) \
  1386. { \
  1387. in0 = (RTYPE)__msa_srari_w((v4i32)in0, shift); \
  1388. in1 = (RTYPE)__msa_srari_w((v4i32)in1, shift); \
  1389. }
  1390. #define SRARI_W2_SW(...) SRARI_W2(v4i32, __VA_ARGS__)
  1391. #define SRARI_W4(RTYPE, in0, in1, in2, in3, shift) \
  1392. { \
  1393. SRARI_W2(RTYPE, in0, in1, shift); \
  1394. SRARI_W2(RTYPE, in2, in3, shift); \
  1395. }
  1396. #define SRARI_W4_SW(...) SRARI_W4(v4i32, __VA_ARGS__)
  1397. /* Description : Logical shift right all elements of vector (immediate)
  1398. Arguments : Inputs - in0, in1, in2, in3, shift
  1399. Outputs - out0, out1, out2, out3
  1400. Return Type - as per RTYPE
  1401. Details : Each element of vector 'in0' is right shifted by 'shift' and
  1402. the result is written in-place. 'shift' is an immediate value.
  1403. */
  1404. #define SRLI_H4(RTYPE, in0, in1, in2, in3, out0, out1, out2, out3, shift) \
  1405. { \
  1406. out0 = (RTYPE)__msa_srli_h((v8i16)in0, shift); \
  1407. out1 = (RTYPE)__msa_srli_h((v8i16)in1, shift); \
  1408. out2 = (RTYPE)__msa_srli_h((v8i16)in2, shift); \
  1409. out3 = (RTYPE)__msa_srli_h((v8i16)in3, shift); \
  1410. }
  1411. #define SRLI_H4_SH(...) SRLI_H4(v8i16, __VA_ARGS__)
  1412. /* Description : Multiplication of pairs of vectors
  1413. Arguments : Inputs - in0, in1, in2, in3
  1414. Outputs - out0, out1
  1415. Details : Each element from 'in0' is multiplied with elements from 'in1'
  1416. and the result is written to 'out0'
  1417. */
  1418. #define MUL2(in0, in1, in2, in3, out0, out1) \
  1419. { \
  1420. out0 = in0 * in1; \
  1421. out1 = in2 * in3; \
  1422. }
  1423. #define MUL4(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, out3) \
  1424. { \
  1425. MUL2(in0, in1, in2, in3, out0, out1); \
  1426. MUL2(in4, in5, in6, in7, out2, out3); \
  1427. }
  1428. /* Description : Addition of 2 pairs of vectors
  1429. Arguments : Inputs - in0, in1, in2, in3
  1430. Outputs - out0, out1
  1431. Details : Each element in 'in0' is added to 'in1' and result is written
  1432. to 'out0'.
  1433. */
  1434. #define ADD2(in0, in1, in2, in3, out0, out1) \
  1435. { \
  1436. out0 = in0 + in1; \
  1437. out1 = in2 + in3; \
  1438. }
  1439. #define ADD4(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, out3) \
  1440. { \
  1441. ADD2(in0, in1, in2, in3, out0, out1); \
  1442. ADD2(in4, in5, in6, in7, out2, out3); \
  1443. }
  1444. /* Description : Subtraction of 2 pairs of vectors
  1445. Arguments : Inputs - in0, in1, in2, in3
  1446. Outputs - out0, out1
  1447. Details : Each element in 'in1' is subtracted from 'in0' and result is
  1448. written to 'out0'.
  1449. */
  1450. #define SUB2(in0, in1, in2, in3, out0, out1) \
  1451. { \
  1452. out0 = in0 - in1; \
  1453. out1 = in2 - in3; \
  1454. }
  1455. #define SUB4(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, out3) \
  1456. { \
  1457. out0 = in0 - in1; \
  1458. out1 = in2 - in3; \
  1459. out2 = in4 - in5; \
  1460. out3 = in6 - in7; \
  1461. }
  1462. /* Description : Sign extend halfword elements from right half of the vector
  1463. Arguments : Input - in (halfword vector)
  1464. Output - out (sign extended word vector)
  1465. Return Type - signed word
  1466. Details : Sign bit of halfword elements from input vector 'in' is
  1467. extracted and interleaved with same vector 'in0' to generate
  1468. 4 word elements keeping sign intact
  1469. */
  1470. #define UNPCK_R_SH_SW(in, out) \
  1471. { \
  1472. v8i16 sign_m; \
  1473. \
  1474. sign_m = __msa_clti_s_h((v8i16)in, 0); \
  1475. out = (v4i32)__msa_ilvr_h(sign_m, (v8i16)in); \
  1476. }
  1477. /* Description : Sign extend byte elements from input vector and return
  1478. halfword results in pair of vectors
  1479. Arguments : Input - in (byte vector)
  1480. Outputs - out0, out1 (sign extended halfword vectors)
  1481. Return Type - signed halfword
  1482. Details : Sign bit of byte elements from input vector 'in' is
  1483. extracted and interleaved right with same vector 'in0' to
  1484. generate 8 signed halfword elements in 'out0'
  1485. Then interleaved left with same vector 'in0' to
  1486. generate 8 signed halfword elements in 'out1'
  1487. */
  1488. #define UNPCK_SB_SH(in, out0, out1) \
  1489. { \
  1490. v16i8 tmp_m; \
  1491. \
  1492. tmp_m = __msa_clti_s_b((v16i8)in, 0); \
  1493. ILVRL_B2_SH(tmp_m, in, out0, out1); \
  1494. }
  1495. /* Description : Zero extend unsigned byte elements to halfword elements
  1496. Arguments : Input - in (unsigned byte vector)
  1497. Outputs - out0, out1 (unsigned halfword vectors)
  1498. Return Type - signed halfword
  1499. Details : Zero extended right half of vector is returned in 'out0'
  1500. Zero extended left half of vector is returned in 'out1'
  1501. */
  1502. #define UNPCK_UB_SH(in, out0, out1) \
  1503. { \
  1504. v16i8 zero_m = { 0 }; \
  1505. \
  1506. ILVRL_B2_SH(zero_m, in, out0, out1); \
  1507. }
  1508. /* Description : Sign extend halfword elements from input vector and return
  1509. the result in pair of vectors
  1510. Arguments : Input - in (halfword vector)
  1511. Outputs - out0, out1 (sign extended word vectors)
  1512. Return Type - signed word
  1513. Details : Sign bit of halfword elements from input vector 'in' is
  1514. extracted and interleaved right with same vector 'in0' to
  1515. generate 4 signed word elements in 'out0'
  1516. Then interleaved left with same vector 'in0' to
  1517. generate 4 signed word elements in 'out1'
  1518. */
  1519. #define UNPCK_SH_SW(in, out0, out1) \
  1520. { \
  1521. v8i16 tmp_m; \
  1522. \
  1523. tmp_m = __msa_clti_s_h((v8i16)in, 0); \
  1524. ILVRL_H2_SW(tmp_m, in, out0, out1); \
  1525. }
  1526. /* Description : Butterfly of 4 input vectors
  1527. Arguments : Inputs - in0, in1, in2, in3
  1528. Outputs - out0, out1, out2, out3
  1529. Details : Butterfly operation
  1530. */
  1531. #define BUTTERFLY_4(in0, in1, in2, in3, out0, out1, out2, out3) \
  1532. { \
  1533. out0 = in0 + in3; \
  1534. out1 = in1 + in2; \
  1535. \
  1536. out2 = in1 - in2; \
  1537. out3 = in0 - in3; \
  1538. }
  1539. /* Description : Butterfly of 8 input vectors
  1540. Arguments : Inputs - in0 ... in7
  1541. Outputs - out0 .. out7
  1542. Details : Butterfly operation
  1543. */
  1544. #define BUTTERFLY_8(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, out2, \
  1545. out3, out4, out5, out6, out7) \
  1546. { \
  1547. out0 = in0 + in7; \
  1548. out1 = in1 + in6; \
  1549. out2 = in2 + in5; \
  1550. out3 = in3 + in4; \
  1551. \
  1552. out4 = in3 - in4; \
  1553. out5 = in2 - in5; \
  1554. out6 = in1 - in6; \
  1555. out7 = in0 - in7; \
  1556. }
  1557. /* Description : Butterfly of 16 input vectors
  1558. Arguments : Inputs - in0 ... in15
  1559. Outputs - out0 .. out15
  1560. Details : Butterfly operation
  1561. */
  1562. #define BUTTERFLY_16(in0, in1, in2, in3, in4, in5, in6, in7, in8, in9, in10, \
  1563. in11, in12, in13, in14, in15, out0, out1, out2, out3, \
  1564. out4, out5, out6, out7, out8, out9, out10, out11, out12, \
  1565. out13, out14, out15) \
  1566. { \
  1567. out0 = in0 + in15; \
  1568. out1 = in1 + in14; \
  1569. out2 = in2 + in13; \
  1570. out3 = in3 + in12; \
  1571. out4 = in4 + in11; \
  1572. out5 = in5 + in10; \
  1573. out6 = in6 + in9; \
  1574. out7 = in7 + in8; \
  1575. \
  1576. out8 = in7 - in8; \
  1577. out9 = in6 - in9; \
  1578. out10 = in5 - in10; \
  1579. out11 = in4 - in11; \
  1580. out12 = in3 - in12; \
  1581. out13 = in2 - in13; \
  1582. out14 = in1 - in14; \
  1583. out15 = in0 - in15; \
  1584. }
  1585. /* Description : Transpose input 8x8 byte block
  1586. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1587. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  1588. Return Type - as per RTYPE
  1589. */
  1590. #define TRANSPOSE8x8_UB(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, \
  1591. out1, out2, out3, out4, out5, out6, out7) \
  1592. { \
  1593. v16i8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  1594. v16i8 tmp4_m, tmp5_m, tmp6_m, tmp7_m; \
  1595. \
  1596. ILVR_B4_SB(in2, in0, in3, in1, in6, in4, in7, in5, tmp0_m, tmp1_m, tmp2_m, \
  1597. tmp3_m); \
  1598. ILVRL_B2_SB(tmp1_m, tmp0_m, tmp4_m, tmp5_m); \
  1599. ILVRL_B2_SB(tmp3_m, tmp2_m, tmp6_m, tmp7_m); \
  1600. ILVRL_W2(RTYPE, tmp6_m, tmp4_m, out0, out2); \
  1601. ILVRL_W2(RTYPE, tmp7_m, tmp5_m, out4, out6); \
  1602. SLDI_B2_0(RTYPE, out0, out2, out1, out3, 8); \
  1603. SLDI_B2_0(RTYPE, out4, out6, out5, out7, 8); \
  1604. }
  1605. #define TRANSPOSE8x8_UB_UB(...) TRANSPOSE8x8_UB(v16u8, __VA_ARGS__)
  1606. /* Description : Transpose 16x8 block into 8x16 with byte elements in vectors
  1607. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7,
  1608. in8, in9, in10, in11, in12, in13, in14, in15
  1609. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  1610. Return Type - unsigned byte
  1611. */
  1612. #define TRANSPOSE16x8_UB_UB(in0, in1, in2, in3, in4, in5, in6, in7, in8, in9, \
  1613. in10, in11, in12, in13, in14, in15, out0, out1, \
  1614. out2, out3, out4, out5, out6, out7) \
  1615. { \
  1616. v16u8 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  1617. v16u8 tmp4_m, tmp5_m, tmp6_m, tmp7_m; \
  1618. \
  1619. ILVEV_D2_UB(in0, in8, in1, in9, out7, out6); \
  1620. ILVEV_D2_UB(in2, in10, in3, in11, out5, out4); \
  1621. ILVEV_D2_UB(in4, in12, in5, in13, out3, out2); \
  1622. ILVEV_D2_UB(in6, in14, in7, in15, out1, out0); \
  1623. \
  1624. tmp0_m = (v16u8)__msa_ilvev_b((v16i8)out6, (v16i8)out7); \
  1625. tmp4_m = (v16u8)__msa_ilvod_b((v16i8)out6, (v16i8)out7); \
  1626. tmp1_m = (v16u8)__msa_ilvev_b((v16i8)out4, (v16i8)out5); \
  1627. tmp5_m = (v16u8)__msa_ilvod_b((v16i8)out4, (v16i8)out5); \
  1628. out5 = (v16u8)__msa_ilvev_b((v16i8)out2, (v16i8)out3); \
  1629. tmp6_m = (v16u8)__msa_ilvod_b((v16i8)out2, (v16i8)out3); \
  1630. out7 = (v16u8)__msa_ilvev_b((v16i8)out0, (v16i8)out1); \
  1631. tmp7_m = (v16u8)__msa_ilvod_b((v16i8)out0, (v16i8)out1); \
  1632. \
  1633. ILVEV_H2_UB(tmp0_m, tmp1_m, out5, out7, tmp2_m, tmp3_m); \
  1634. out0 = (v16u8)__msa_ilvev_w((v4i32)tmp3_m, (v4i32)tmp2_m); \
  1635. out4 = (v16u8)__msa_ilvod_w((v4i32)tmp3_m, (v4i32)tmp2_m); \
  1636. \
  1637. tmp2_m = (v16u8)__msa_ilvod_h((v8i16)tmp1_m, (v8i16)tmp0_m); \
  1638. tmp3_m = (v16u8)__msa_ilvod_h((v8i16)out7, (v8i16)out5); \
  1639. out2 = (v16u8)__msa_ilvev_w((v4i32)tmp3_m, (v4i32)tmp2_m); \
  1640. out6 = (v16u8)__msa_ilvod_w((v4i32)tmp3_m, (v4i32)tmp2_m); \
  1641. \
  1642. ILVEV_H2_UB(tmp4_m, tmp5_m, tmp6_m, tmp7_m, tmp2_m, tmp3_m); \
  1643. out1 = (v16u8)__msa_ilvev_w((v4i32)tmp3_m, (v4i32)tmp2_m); \
  1644. out5 = (v16u8)__msa_ilvod_w((v4i32)tmp3_m, (v4i32)tmp2_m); \
  1645. \
  1646. tmp2_m = (v16u8)__msa_ilvod_h((v8i16)tmp5_m, (v8i16)tmp4_m); \
  1647. tmp3_m = (v16u8)__msa_ilvod_h((v8i16)tmp7_m, (v8i16)tmp6_m); \
  1648. out3 = (v16u8)__msa_ilvev_w((v4i32)tmp3_m, (v4i32)tmp2_m); \
  1649. out7 = (v16u8)__msa_ilvod_w((v4i32)tmp3_m, (v4i32)tmp2_m); \
  1650. }
  1651. /* Description : Transpose 4x4 block with half word elements in vectors
  1652. Arguments : Inputs - in0, in1, in2, in3
  1653. Outputs - out0, out1, out2, out3
  1654. Return Type - signed halfword
  1655. */
  1656. #define TRANSPOSE4x4_SH_SH(in0, in1, in2, in3, out0, out1, out2, out3) \
  1657. { \
  1658. v8i16 s0_m, s1_m; \
  1659. \
  1660. ILVR_H2_SH(in1, in0, in3, in2, s0_m, s1_m); \
  1661. ILVRL_W2_SH(s1_m, s0_m, out0, out2); \
  1662. out1 = (v8i16)__msa_ilvl_d((v2i64)out0, (v2i64)out0); \
  1663. out3 = (v8i16)__msa_ilvl_d((v2i64)out0, (v2i64)out2); \
  1664. }
  1665. /* Description : Transpose 4x8 block with half word elements in vectors
  1666. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1667. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  1668. Return Type - signed halfword
  1669. */
  1670. #define TRANSPOSE4X8_SH_SH(in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \
  1671. out2, out3, out4, out5, out6, out7) \
  1672. { \
  1673. v8i16 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  1674. v8i16 tmp0_n, tmp1_n, tmp2_n, tmp3_n; \
  1675. v8i16 zero_m = { 0 }; \
  1676. \
  1677. ILVR_H4_SH(in1, in0, in3, in2, in5, in4, in7, in6, tmp0_n, tmp1_n, tmp2_n, \
  1678. tmp3_n); \
  1679. ILVRL_W2_SH(tmp1_n, tmp0_n, tmp0_m, tmp2_m); \
  1680. ILVRL_W2_SH(tmp3_n, tmp2_n, tmp1_m, tmp3_m); \
  1681. \
  1682. out0 = (v8i16)__msa_ilvr_d((v2i64)tmp1_m, (v2i64)tmp0_m); \
  1683. out1 = (v8i16)__msa_ilvl_d((v2i64)tmp1_m, (v2i64)tmp0_m); \
  1684. out2 = (v8i16)__msa_ilvr_d((v2i64)tmp3_m, (v2i64)tmp2_m); \
  1685. out3 = (v8i16)__msa_ilvl_d((v2i64)tmp3_m, (v2i64)tmp2_m); \
  1686. \
  1687. out4 = zero_m; \
  1688. out5 = zero_m; \
  1689. out6 = zero_m; \
  1690. out7 = zero_m; \
  1691. }
  1692. /* Description : Transpose 8x4 block with half word elements in vectors
  1693. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1694. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  1695. Return Type - signed halfword
  1696. */
  1697. #define TRANSPOSE8X4_SH_SH(in0, in1, in2, in3, out0, out1, out2, out3) \
  1698. { \
  1699. v8i16 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  1700. \
  1701. ILVR_H2_SH(in1, in0, in3, in2, tmp0_m, tmp1_m); \
  1702. ILVL_H2_SH(in1, in0, in3, in2, tmp2_m, tmp3_m); \
  1703. ILVR_W2_SH(tmp1_m, tmp0_m, tmp3_m, tmp2_m, out0, out2); \
  1704. ILVL_W2_SH(tmp1_m, tmp0_m, tmp3_m, tmp2_m, out1, out3); \
  1705. }
  1706. /* Description : Transpose 8x8 block with half word elements in vectors
  1707. Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7
  1708. Outputs - out0, out1, out2, out3, out4, out5, out6, out7
  1709. Return Type - as per RTYPE
  1710. */
  1711. #define TRANSPOSE8x8_H(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, \
  1712. out1, out2, out3, out4, out5, out6, out7) \
  1713. { \
  1714. v8i16 s0_m, s1_m; \
  1715. v8i16 tmp0_m, tmp1_m, tmp2_m, tmp3_m; \
  1716. v8i16 tmp4_m, tmp5_m, tmp6_m, tmp7_m; \
  1717. \
  1718. ILVR_H2_SH(in6, in4, in7, in5, s0_m, s1_m); \
  1719. ILVRL_H2_SH(s1_m, s0_m, tmp0_m, tmp1_m); \
  1720. ILVL_H2_SH(in6, in4, in7, in5, s0_m, s1_m); \
  1721. ILVRL_H2_SH(s1_m, s0_m, tmp2_m, tmp3_m); \
  1722. ILVR_H2_SH(in2, in0, in3, in1, s0_m, s1_m); \
  1723. ILVRL_H2_SH(s1_m, s0_m, tmp4_m, tmp5_m); \
  1724. ILVL_H2_SH(in2, in0, in3, in1, s0_m, s1_m); \
  1725. ILVRL_H2_SH(s1_m, s0_m, tmp6_m, tmp7_m); \
  1726. PCKEV_D4(RTYPE, tmp0_m, tmp4_m, tmp1_m, tmp5_m, tmp2_m, tmp6_m, tmp3_m, \
  1727. tmp7_m, out0, out2, out4, out6); \
  1728. out1 = (RTYPE)__msa_pckod_d((v2i64)tmp0_m, (v2i64)tmp4_m); \
  1729. out3 = (RTYPE)__msa_pckod_d((v2i64)tmp1_m, (v2i64)tmp5_m); \
  1730. out5 = (RTYPE)__msa_pckod_d((v2i64)tmp2_m, (v2i64)tmp6_m); \
  1731. out7 = (RTYPE)__msa_pckod_d((v2i64)tmp3_m, (v2i64)tmp7_m); \
  1732. }
  1733. #define TRANSPOSE8x8_SH_SH(...) TRANSPOSE8x8_H(v8i16, __VA_ARGS__)
  1734. /* Description : Transpose 4x4 block with word elements in vectors
  1735. Arguments : Inputs - in0, in1, in2, in3
  1736. Outputs - out0, out1, out2, out3
  1737. Return Type - signed word
  1738. */
  1739. #define TRANSPOSE4x4_SW_SW(in0, in1, in2, in3, out0, out1, out2, out3) \
  1740. { \
  1741. v4i32 s0_m, s1_m, s2_m, s3_m; \
  1742. \
  1743. ILVRL_W2_SW(in1, in0, s0_m, s1_m); \
  1744. ILVRL_W2_SW(in3, in2, s2_m, s3_m); \
  1745. \
  1746. out0 = (v4i32)__msa_ilvr_d((v2i64)s2_m, (v2i64)s0_m); \
  1747. out1 = (v4i32)__msa_ilvl_d((v2i64)s2_m, (v2i64)s0_m); \
  1748. out2 = (v4i32)__msa_ilvr_d((v2i64)s3_m, (v2i64)s1_m); \
  1749. out3 = (v4i32)__msa_ilvl_d((v2i64)s3_m, (v2i64)s1_m); \
  1750. }
  1751. /* Description : Add block 4x4
  1752. Arguments : Inputs - in0, in1, in2, in3, pdst, stride
  1753. Details : Least significant 4 bytes from each input vector are added to
  1754. the destination bytes, clipped between 0-255 and stored.
  1755. */
  1756. #define ADDBLK_ST4x4_UB(in0, in1, in2, in3, pdst, stride) \
  1757. { \
  1758. uint32_t src0_m, src1_m, src2_m, src3_m; \
  1759. v8i16 inp0_m, inp1_m, res0_m, res1_m; \
  1760. v16i8 dst0_m = { 0 }; \
  1761. v16i8 dst1_m = { 0 }; \
  1762. v16i8 zero_m = { 0 }; \
  1763. \
  1764. ILVR_D2_SH(in1, in0, in3, in2, inp0_m, inp1_m) \
  1765. LW4(pdst, stride, src0_m, src1_m, src2_m, src3_m); \
  1766. INSERT_W2_SB(src0_m, src1_m, dst0_m); \
  1767. INSERT_W2_SB(src2_m, src3_m, dst1_m); \
  1768. ILVR_B2_SH(zero_m, dst0_m, zero_m, dst1_m, res0_m, res1_m); \
  1769. ADD2(res0_m, inp0_m, res1_m, inp1_m, res0_m, res1_m); \
  1770. CLIP_SH2_0_255(res0_m, res1_m); \
  1771. PCKEV_B2_SB(res0_m, res0_m, res1_m, res1_m, dst0_m, dst1_m); \
  1772. ST4x4_UB(dst0_m, dst1_m, 0, 1, 0, 1, pdst, stride); \
  1773. }
  1774. /* Description : Pack even elements of input vectors & xor with 128
  1775. Arguments : Inputs - in0, in1
  1776. Output - out_m
  1777. Return Type - unsigned byte
  1778. Details : Signed byte even elements from 'in0' and 'in1' are packed
  1779. together in one vector and the resulting vector is xor'ed with
  1780. 128 to shift the range from signed to unsigned byte
  1781. */
  1782. #define PCKEV_XORI128_UB(in0, in1) \
  1783. ({ \
  1784. v16u8 out_m; \
  1785. \
  1786. out_m = (v16u8)__msa_pckev_b((v16i8)in1, (v16i8)in0); \
  1787. out_m = (v16u8)__msa_xori_b((v16u8)out_m, 128); \
  1788. out_m; \
  1789. })
  1790. /* Description : Converts inputs to unsigned bytes, interleave, average & store
  1791. as 8x4 unsigned byte block
  1792. Arguments : Inputs - in0, in1, in2, in3, dst0, dst1, pdst, stride
  1793. */
  1794. #define CONVERT_UB_AVG_ST8x4_UB(in0, in1, in2, in3, dst0, dst1, pdst, stride) \
  1795. { \
  1796. v16u8 tmp0_m, tmp1_m; \
  1797. uint8_t *pdst_m = (uint8_t *)(pdst); \
  1798. \
  1799. tmp0_m = PCKEV_XORI128_UB(in0, in1); \
  1800. tmp1_m = PCKEV_XORI128_UB(in2, in3); \
  1801. AVER_UB2_UB(tmp0_m, dst0, tmp1_m, dst1, tmp0_m, tmp1_m); \
  1802. ST8x4_UB(tmp0_m, tmp1_m, pdst_m, stride); \
  1803. }
  1804. /* Description : Pack even byte elements and store byte vector in destination
  1805. memory
  1806. Arguments : Inputs - in0, in1, pdst
  1807. */
  1808. #define PCKEV_ST_SB(in0, in1, pdst) \
  1809. { \
  1810. v16i8 tmp_m; \
  1811. \
  1812. tmp_m = __msa_pckev_b((v16i8)in1, (v16i8)in0); \
  1813. ST_SB(tmp_m, (pdst)); \
  1814. }
  1815. /* Description : Horizontal 2 tap filter kernel code
  1816. Arguments : Inputs - in0, in1, mask, coeff, shift
  1817. */
  1818. #define HORIZ_2TAP_FILT_UH(in0, in1, mask, coeff, shift) \
  1819. ({ \
  1820. v16i8 tmp0_m; \
  1821. v8u16 tmp1_m; \
  1822. \
  1823. tmp0_m = __msa_vshf_b((v16i8)mask, (v16i8)in1, (v16i8)in0); \
  1824. tmp1_m = __msa_dotp_u_h((v16u8)tmp0_m, (v16u8)coeff); \
  1825. tmp1_m = (v8u16)__msa_srari_h((v8i16)tmp1_m, shift); \
  1826. \
  1827. tmp1_m; \
  1828. })
  1829. #endif // VPX_VPX_DSP_MIPS_MACROS_MSA_H_