generic_macros_msa.h 147 KB

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