generic_macros_msa.h 144 KB

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