InstEmitSimdArithmetic.cs 106 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056
  1. // https://github.com/intel/ARM_NEON_2_x86_SSE/blob/master/NEON_2_SSE.h
  2. using ChocolArm64.Decoders;
  3. using ChocolArm64.State;
  4. using ChocolArm64.Translation;
  5. using System;
  6. using System.Reflection;
  7. using System.Reflection.Emit;
  8. using System.Runtime.Intrinsics;
  9. using System.Runtime.Intrinsics.X86;
  10. using static ChocolArm64.Instructions.InstEmitSimdHelper;
  11. namespace ChocolArm64.Instructions
  12. {
  13. static partial class InstEmit
  14. {
  15. public static void Abs_S(ILEmitterCtx context)
  16. {
  17. EmitScalarUnaryOpSx(context, () => EmitAbs(context));
  18. }
  19. public static void Abs_V(ILEmitterCtx context)
  20. {
  21. EmitVectorUnaryOpSx(context, () => EmitAbs(context));
  22. }
  23. public static void Add_S(ILEmitterCtx context)
  24. {
  25. EmitScalarBinaryOpZx(context, () => context.Emit(OpCodes.Add));
  26. }
  27. public static void Add_V(ILEmitterCtx context)
  28. {
  29. if (Optimizations.UseSse2)
  30. {
  31. EmitSse2Op(context, nameof(Sse2.Add));
  32. }
  33. else
  34. {
  35. EmitVectorBinaryOpZx(context, () => context.Emit(OpCodes.Add));
  36. }
  37. }
  38. public static void Addhn_V(ILEmitterCtx context)
  39. {
  40. EmitHighNarrow(context, () => context.Emit(OpCodes.Add), round: false);
  41. }
  42. public static void Addp_S(ILEmitterCtx context)
  43. {
  44. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  45. EmitVectorExtractZx(context, op.Rn, 0, op.Size);
  46. EmitVectorExtractZx(context, op.Rn, 1, op.Size);
  47. context.Emit(OpCodes.Add);
  48. EmitScalarSet(context, op.Rd, op.Size);
  49. }
  50. public static void Addp_V(ILEmitterCtx context)
  51. {
  52. EmitVectorPairwiseOpZx(context, () => context.Emit(OpCodes.Add));
  53. }
  54. public static void Addv_V(ILEmitterCtx context)
  55. {
  56. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  57. int bytes = op.GetBitsCount() >> 3;
  58. int elems = bytes >> op.Size;
  59. EmitVectorExtractZx(context, op.Rn, 0, op.Size);
  60. for (int index = 1; index < elems; index++)
  61. {
  62. EmitVectorExtractZx(context, op.Rn, index, op.Size);
  63. context.Emit(OpCodes.Add);
  64. }
  65. EmitScalarSet(context, op.Rd, op.Size);
  66. }
  67. public static void Cls_V(ILEmitterCtx context)
  68. {
  69. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  70. int bytes = op.GetBitsCount() >> 3;
  71. int elems = bytes >> op.Size;
  72. int eSize = 8 << op.Size;
  73. for (int index = 0; index < elems; index++)
  74. {
  75. EmitVectorExtractZx(context, op.Rn, index, op.Size);
  76. context.EmitLdc_I4(eSize);
  77. SoftFallback.EmitCall(context, nameof(SoftFallback.CountLeadingSigns));
  78. EmitVectorInsert(context, op.Rd, index, op.Size);
  79. }
  80. if (op.RegisterSize == RegisterSize.Simd64)
  81. {
  82. EmitVectorZeroUpper(context, op.Rd);
  83. }
  84. }
  85. public static void Clz_V(ILEmitterCtx context)
  86. {
  87. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  88. int bytes = op.GetBitsCount() >> 3;
  89. int elems = bytes >> op.Size;
  90. int eSize = 8 << op.Size;
  91. for (int index = 0; index < elems; index++)
  92. {
  93. EmitVectorExtractZx(context, op.Rn, index, op.Size);
  94. if (Lzcnt.IsSupported && eSize == 32)
  95. {
  96. context.Emit(OpCodes.Conv_U4);
  97. context.EmitCall(typeof(Lzcnt).GetMethod(nameof(Lzcnt.LeadingZeroCount), new Type[] { typeof(uint) }));
  98. context.Emit(OpCodes.Conv_U8);
  99. }
  100. else
  101. {
  102. context.EmitLdc_I4(eSize);
  103. SoftFallback.EmitCall(context, nameof(SoftFallback.CountLeadingZeros));
  104. }
  105. EmitVectorInsert(context, op.Rd, index, op.Size);
  106. }
  107. if (op.RegisterSize == RegisterSize.Simd64)
  108. {
  109. EmitVectorZeroUpper(context, op.Rd);
  110. }
  111. }
  112. public static void Cnt_V(ILEmitterCtx context)
  113. {
  114. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  115. int elems = op.RegisterSize == RegisterSize.Simd128 ? 16 : 8;
  116. for (int index = 0; index < elems; index++)
  117. {
  118. EmitVectorExtractZx(context, op.Rn, index, 0);
  119. if (Popcnt.IsSupported)
  120. {
  121. context.EmitCall(typeof(Popcnt).GetMethod(nameof(Popcnt.PopCount), new Type[] { typeof(ulong) }));
  122. }
  123. else
  124. {
  125. SoftFallback.EmitCall(context, nameof(SoftFallback.CountSetBits8));
  126. }
  127. EmitVectorInsert(context, op.Rd, index, 0);
  128. }
  129. if (op.RegisterSize == RegisterSize.Simd64)
  130. {
  131. EmitVectorZeroUpper(context, op.Rd);
  132. }
  133. }
  134. public static void Fabd_S(ILEmitterCtx context)
  135. {
  136. EmitScalarBinaryOpF(context, () =>
  137. {
  138. context.Emit(OpCodes.Sub);
  139. EmitUnaryMathCall(context, nameof(Math.Abs));
  140. });
  141. }
  142. public static void Fabs_S(ILEmitterCtx context)
  143. {
  144. if (Optimizations.UseSse2)
  145. {
  146. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  147. if (op.Size == 0)
  148. {
  149. Type[] typesSsv = new Type[] { typeof(float) };
  150. Type[] typesAndNot = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
  151. context.EmitLdc_R4(-0f);
  152. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetScalarVector128), typesSsv));
  153. context.EmitLdvec(op.Rn);
  154. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.AndNot), typesAndNot));
  155. context.EmitStvec(op.Rd);
  156. EmitVectorZero32_128(context, op.Rd);
  157. }
  158. else /* if (op.Size == 1) */
  159. {
  160. Type[] typesSsv = new Type[] { typeof(double) };
  161. Type[] typesAndNot = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
  162. context.EmitLdc_R8(-0d);
  163. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetScalarVector128), typesSsv));
  164. EmitLdvecWithCastToDouble(context, op.Rn);
  165. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.AndNot), typesAndNot));
  166. EmitStvecWithCastFromDouble(context, op.Rd);
  167. EmitVectorZeroUpper(context, op.Rd);
  168. }
  169. }
  170. else
  171. {
  172. EmitScalarUnaryOpF(context, () =>
  173. {
  174. EmitUnaryMathCall(context, nameof(Math.Abs));
  175. });
  176. }
  177. }
  178. public static void Fabs_V(ILEmitterCtx context)
  179. {
  180. if (Optimizations.UseSse2)
  181. {
  182. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  183. int sizeF = op.Size & 1;
  184. if (sizeF == 0)
  185. {
  186. Type[] typesSav = new Type[] { typeof(float) };
  187. Type[] typesAndNot = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
  188. context.EmitLdc_R4(-0f);
  189. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetAllVector128), typesSav));
  190. context.EmitLdvec(op.Rn);
  191. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.AndNot), typesAndNot));
  192. context.EmitStvec(op.Rd);
  193. if (op.RegisterSize == RegisterSize.Simd64)
  194. {
  195. EmitVectorZeroUpper(context, op.Rd);
  196. }
  197. }
  198. else /* if (sizeF == 1) */
  199. {
  200. Type[] typesSav = new Type[] { typeof(double) };
  201. Type[] typesAndNot = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
  202. context.EmitLdc_R8(-0d);
  203. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
  204. EmitLdvecWithCastToDouble(context, op.Rn);
  205. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.AndNot), typesAndNot));
  206. EmitStvecWithCastFromDouble(context, op.Rd);
  207. }
  208. }
  209. else
  210. {
  211. EmitVectorUnaryOpF(context, () =>
  212. {
  213. EmitUnaryMathCall(context, nameof(Math.Abs));
  214. });
  215. }
  216. }
  217. public static void Fadd_S(ILEmitterCtx context)
  218. {
  219. if (Optimizations.FastFP && Optimizations.UseSse
  220. && Optimizations.UseSse2)
  221. {
  222. EmitScalarSseOrSse2OpF(context, nameof(Sse.AddScalar));
  223. }
  224. else
  225. {
  226. EmitScalarBinaryOpF(context, () =>
  227. {
  228. EmitSoftFloatCall(context, nameof(SoftFloat32.FPAdd));
  229. });
  230. }
  231. }
  232. public static void Fadd_V(ILEmitterCtx context)
  233. {
  234. if (Optimizations.FastFP && Optimizations.UseSse
  235. && Optimizations.UseSse2)
  236. {
  237. EmitVectorSseOrSse2OpF(context, nameof(Sse.Add));
  238. }
  239. else
  240. {
  241. EmitVectorBinaryOpF(context, () =>
  242. {
  243. EmitSoftFloatCall(context, nameof(SoftFloat32.FPAdd));
  244. });
  245. }
  246. }
  247. public static void Faddp_S(ILEmitterCtx context)
  248. {
  249. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  250. int sizeF = op.Size & 1;
  251. EmitVectorExtractF(context, op.Rn, 0, sizeF);
  252. EmitVectorExtractF(context, op.Rn, 1, sizeF);
  253. context.Emit(OpCodes.Add);
  254. EmitScalarSetF(context, op.Rd, sizeF);
  255. }
  256. public static void Faddp_V(ILEmitterCtx context)
  257. {
  258. EmitVectorPairwiseOpF(context, () => context.Emit(OpCodes.Add));
  259. }
  260. public static void Fdiv_S(ILEmitterCtx context)
  261. {
  262. if (Optimizations.FastFP && Optimizations.UseSse
  263. && Optimizations.UseSse2)
  264. {
  265. EmitScalarSseOrSse2OpF(context, nameof(Sse.DivideScalar));
  266. }
  267. else
  268. {
  269. EmitScalarBinaryOpF(context, () =>
  270. {
  271. EmitSoftFloatCall(context, nameof(SoftFloat32.FPDiv));
  272. });
  273. }
  274. }
  275. public static void Fdiv_V(ILEmitterCtx context)
  276. {
  277. if (Optimizations.FastFP && Optimizations.UseSse
  278. && Optimizations.UseSse2)
  279. {
  280. EmitVectorSseOrSse2OpF(context, nameof(Sse.Divide));
  281. }
  282. else
  283. {
  284. EmitVectorBinaryOpF(context, () =>
  285. {
  286. EmitSoftFloatCall(context, nameof(SoftFloat32.FPDiv));
  287. });
  288. }
  289. }
  290. public static void Fmadd_S(ILEmitterCtx context) // Fused.
  291. {
  292. if (Optimizations.FastFP && Optimizations.UseSse2)
  293. {
  294. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  295. if (op.Size == 0)
  296. {
  297. Type[] typesMulAdd = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
  298. context.EmitLdvec(op.Ra);
  299. context.EmitLdvec(op.Rn);
  300. context.EmitLdvec(op.Rm);
  301. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.MultiplyScalar), typesMulAdd));
  302. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.AddScalar), typesMulAdd));
  303. context.EmitStvec(op.Rd);
  304. EmitVectorZero32_128(context, op.Rd);
  305. }
  306. else /* if (op.Size == 1) */
  307. {
  308. Type[] typesMulAdd = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
  309. EmitLdvecWithCastToDouble(context, op.Ra);
  310. EmitLdvecWithCastToDouble(context, op.Rn);
  311. EmitLdvecWithCastToDouble(context, op.Rm);
  312. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.MultiplyScalar), typesMulAdd));
  313. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.AddScalar), typesMulAdd));
  314. EmitStvecWithCastFromDouble(context, op.Rd);
  315. EmitVectorZeroUpper(context, op.Rd);
  316. }
  317. }
  318. else
  319. {
  320. EmitScalarTernaryRaOpF(context, () =>
  321. {
  322. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMulAdd));
  323. });
  324. }
  325. }
  326. public static void Fmax_S(ILEmitterCtx context)
  327. {
  328. if (Optimizations.FastFP && Optimizations.UseSse
  329. && Optimizations.UseSse2)
  330. {
  331. EmitScalarSseOrSse2OpF(context, nameof(Sse.MaxScalar));
  332. }
  333. else
  334. {
  335. EmitScalarBinaryOpF(context, () =>
  336. {
  337. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMax));
  338. });
  339. }
  340. }
  341. public static void Fmax_V(ILEmitterCtx context)
  342. {
  343. if (Optimizations.FastFP && Optimizations.UseSse
  344. && Optimizations.UseSse2)
  345. {
  346. EmitVectorSseOrSse2OpF(context, nameof(Sse.Max));
  347. }
  348. else
  349. {
  350. EmitVectorBinaryOpF(context, () =>
  351. {
  352. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMax));
  353. });
  354. }
  355. }
  356. public static void Fmaxnm_S(ILEmitterCtx context)
  357. {
  358. EmitScalarBinaryOpF(context, () =>
  359. {
  360. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMaxNum));
  361. });
  362. }
  363. public static void Fmaxnm_V(ILEmitterCtx context)
  364. {
  365. EmitVectorBinaryOpF(context, () =>
  366. {
  367. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMaxNum));
  368. });
  369. }
  370. public static void Fmaxp_V(ILEmitterCtx context)
  371. {
  372. EmitVectorPairwiseOpF(context, () =>
  373. {
  374. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMax));
  375. });
  376. }
  377. public static void Fmin_S(ILEmitterCtx context)
  378. {
  379. if (Optimizations.FastFP && Optimizations.UseSse
  380. && Optimizations.UseSse2)
  381. {
  382. EmitScalarSseOrSse2OpF(context, nameof(Sse.MinScalar));
  383. }
  384. else
  385. {
  386. EmitScalarBinaryOpF(context, () =>
  387. {
  388. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMin));
  389. });
  390. }
  391. }
  392. public static void Fmin_V(ILEmitterCtx context)
  393. {
  394. if (Optimizations.FastFP && Optimizations.UseSse
  395. && Optimizations.UseSse2)
  396. {
  397. EmitVectorSseOrSse2OpF(context, nameof(Sse.Min));
  398. }
  399. else
  400. {
  401. EmitVectorBinaryOpF(context, () =>
  402. {
  403. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMin));
  404. });
  405. }
  406. }
  407. public static void Fminnm_S(ILEmitterCtx context)
  408. {
  409. EmitScalarBinaryOpF(context, () =>
  410. {
  411. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMinNum));
  412. });
  413. }
  414. public static void Fminnm_V(ILEmitterCtx context)
  415. {
  416. EmitVectorBinaryOpF(context, () =>
  417. {
  418. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMinNum));
  419. });
  420. }
  421. public static void Fminp_V(ILEmitterCtx context)
  422. {
  423. EmitVectorPairwiseOpF(context, () =>
  424. {
  425. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMin));
  426. });
  427. }
  428. public static void Fmla_Se(ILEmitterCtx context)
  429. {
  430. EmitScalarTernaryOpByElemF(context, () =>
  431. {
  432. context.Emit(OpCodes.Mul);
  433. context.Emit(OpCodes.Add);
  434. });
  435. }
  436. public static void Fmla_V(ILEmitterCtx context) // Fused.
  437. {
  438. if (Optimizations.FastFP && Optimizations.UseSse2)
  439. {
  440. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  441. int sizeF = op.Size & 1;
  442. if (sizeF == 0)
  443. {
  444. Type[] typesMulAdd = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
  445. context.EmitLdvec(op.Rd);
  446. context.EmitLdvec(op.Rn);
  447. context.EmitLdvec(op.Rm);
  448. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), typesMulAdd));
  449. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Add), typesMulAdd));
  450. context.EmitStvec(op.Rd);
  451. if (op.RegisterSize == RegisterSize.Simd64)
  452. {
  453. EmitVectorZeroUpper(context, op.Rd);
  454. }
  455. }
  456. else /* if (sizeF == 1) */
  457. {
  458. Type[] typesMulAdd = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
  459. EmitLdvecWithCastToDouble(context, op.Rd);
  460. EmitLdvecWithCastToDouble(context, op.Rn);
  461. EmitLdvecWithCastToDouble(context, op.Rm);
  462. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), typesMulAdd));
  463. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesMulAdd));
  464. EmitStvecWithCastFromDouble(context, op.Rd);
  465. }
  466. }
  467. else
  468. {
  469. EmitVectorTernaryOpF(context, () =>
  470. {
  471. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMulAdd));
  472. });
  473. }
  474. }
  475. public static void Fmla_Ve(ILEmitterCtx context) // Fused.
  476. {
  477. if (Optimizations.FastFP && Optimizations.UseSse2)
  478. {
  479. OpCodeSimdRegElemF64 op = (OpCodeSimdRegElemF64)context.CurrOp;
  480. int sizeF = op.Size & 1;
  481. if (sizeF == 0)
  482. {
  483. Type[] typesSfl = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>), typeof(byte) };
  484. Type[] typesMulAdd = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
  485. context.EmitLdvec(op.Rd);
  486. context.EmitLdvec(op.Rn);
  487. context.EmitLdvec(op.Rm);
  488. context.Emit(OpCodes.Dup);
  489. context.EmitLdc_I4(op.Index | op.Index << 2 | op.Index << 4 | op.Index << 6);
  490. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Shuffle), typesSfl));
  491. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), typesMulAdd));
  492. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Add), typesMulAdd));
  493. context.EmitStvec(op.Rd);
  494. if (op.RegisterSize == RegisterSize.Simd64)
  495. {
  496. EmitVectorZeroUpper(context, op.Rd);
  497. }
  498. }
  499. else /* if (sizeF == 1) */
  500. {
  501. Type[] typesSfl = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>), typeof(byte) };
  502. Type[] typesMulAdd = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
  503. EmitLdvecWithCastToDouble(context, op.Rd);
  504. EmitLdvecWithCastToDouble(context, op.Rn);
  505. EmitLdvecWithCastToDouble(context, op.Rm);
  506. context.Emit(OpCodes.Dup);
  507. context.EmitLdc_I4(op.Index | op.Index << 1);
  508. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), typesSfl));
  509. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), typesMulAdd));
  510. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesMulAdd));
  511. EmitStvecWithCastFromDouble(context, op.Rd);
  512. }
  513. }
  514. else
  515. {
  516. EmitVectorTernaryOpByElemF(context, () =>
  517. {
  518. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMulAdd));
  519. });
  520. }
  521. }
  522. public static void Fmls_Se(ILEmitterCtx context)
  523. {
  524. EmitScalarTernaryOpByElemF(context, () =>
  525. {
  526. context.Emit(OpCodes.Mul);
  527. context.Emit(OpCodes.Sub);
  528. });
  529. }
  530. public static void Fmls_V(ILEmitterCtx context) // Fused.
  531. {
  532. if (Optimizations.FastFP && Optimizations.UseSse2)
  533. {
  534. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  535. int sizeF = op.Size & 1;
  536. if (sizeF == 0)
  537. {
  538. Type[] typesMulSub = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
  539. context.EmitLdvec(op.Rd);
  540. context.EmitLdvec(op.Rn);
  541. context.EmitLdvec(op.Rm);
  542. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), typesMulSub));
  543. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Subtract), typesMulSub));
  544. context.EmitStvec(op.Rd);
  545. if (op.RegisterSize == RegisterSize.Simd64)
  546. {
  547. EmitVectorZeroUpper(context, op.Rd);
  548. }
  549. }
  550. else /* if (sizeF == 1) */
  551. {
  552. Type[] typesMulSub = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
  553. EmitLdvecWithCastToDouble(context, op.Rd);
  554. EmitLdvecWithCastToDouble(context, op.Rn);
  555. EmitLdvecWithCastToDouble(context, op.Rm);
  556. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), typesMulSub));
  557. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesMulSub));
  558. EmitStvecWithCastFromDouble(context, op.Rd);
  559. }
  560. }
  561. else
  562. {
  563. EmitVectorTernaryOpF(context, () =>
  564. {
  565. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMulSub));
  566. });
  567. }
  568. }
  569. public static void Fmls_Ve(ILEmitterCtx context) // Fused.
  570. {
  571. if (Optimizations.FastFP && Optimizations.UseSse2)
  572. {
  573. OpCodeSimdRegElemF64 op = (OpCodeSimdRegElemF64)context.CurrOp;
  574. int sizeF = op.Size & 1;
  575. if (sizeF == 0)
  576. {
  577. Type[] typesSfl = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>), typeof(byte) };
  578. Type[] typesMulSub = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
  579. context.EmitLdvec(op.Rd);
  580. context.EmitLdvec(op.Rn);
  581. context.EmitLdvec(op.Rm);
  582. context.Emit(OpCodes.Dup);
  583. context.EmitLdc_I4(op.Index | op.Index << 2 | op.Index << 4 | op.Index << 6);
  584. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Shuffle), typesSfl));
  585. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), typesMulSub));
  586. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Subtract), typesMulSub));
  587. context.EmitStvec(op.Rd);
  588. if (op.RegisterSize == RegisterSize.Simd64)
  589. {
  590. EmitVectorZeroUpper(context, op.Rd);
  591. }
  592. }
  593. else /* if (sizeF == 1) */
  594. {
  595. Type[] typesSfl = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>), typeof(byte) };
  596. Type[] typesMulSub = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
  597. EmitLdvecWithCastToDouble(context, op.Rd);
  598. EmitLdvecWithCastToDouble(context, op.Rn);
  599. EmitLdvecWithCastToDouble(context, op.Rm);
  600. context.Emit(OpCodes.Dup);
  601. context.EmitLdc_I4(op.Index | op.Index << 1);
  602. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), typesSfl));
  603. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), typesMulSub));
  604. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesMulSub));
  605. EmitStvecWithCastFromDouble(context, op.Rd);
  606. }
  607. }
  608. else
  609. {
  610. EmitVectorTernaryOpByElemF(context, () =>
  611. {
  612. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMulSub));
  613. });
  614. }
  615. }
  616. public static void Fmsub_S(ILEmitterCtx context) // Fused.
  617. {
  618. if (Optimizations.FastFP && Optimizations.UseSse2)
  619. {
  620. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  621. if (op.Size == 0)
  622. {
  623. Type[] typesMulSub = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
  624. context.EmitLdvec(op.Ra);
  625. context.EmitLdvec(op.Rn);
  626. context.EmitLdvec(op.Rm);
  627. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.MultiplyScalar), typesMulSub));
  628. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SubtractScalar), typesMulSub));
  629. context.EmitStvec(op.Rd);
  630. EmitVectorZero32_128(context, op.Rd);
  631. }
  632. else /* if (op.Size == 1) */
  633. {
  634. Type[] typesMulSub = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
  635. EmitLdvecWithCastToDouble(context, op.Ra);
  636. EmitLdvecWithCastToDouble(context, op.Rn);
  637. EmitLdvecWithCastToDouble(context, op.Rm);
  638. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.MultiplyScalar), typesMulSub));
  639. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SubtractScalar), typesMulSub));
  640. EmitStvecWithCastFromDouble(context, op.Rd);
  641. EmitVectorZeroUpper(context, op.Rd);
  642. }
  643. }
  644. else
  645. {
  646. EmitScalarTernaryRaOpF(context, () =>
  647. {
  648. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMulSub));
  649. });
  650. }
  651. }
  652. public static void Fmul_S(ILEmitterCtx context)
  653. {
  654. if (Optimizations.FastFP && Optimizations.UseSse
  655. && Optimizations.UseSse2)
  656. {
  657. EmitScalarSseOrSse2OpF(context, nameof(Sse.MultiplyScalar));
  658. }
  659. else
  660. {
  661. EmitScalarBinaryOpF(context, () =>
  662. {
  663. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMul));
  664. });
  665. }
  666. }
  667. public static void Fmul_Se(ILEmitterCtx context)
  668. {
  669. EmitScalarBinaryOpByElemF(context, () => context.Emit(OpCodes.Mul));
  670. }
  671. public static void Fmul_V(ILEmitterCtx context)
  672. {
  673. if (Optimizations.FastFP && Optimizations.UseSse
  674. && Optimizations.UseSse2)
  675. {
  676. EmitVectorSseOrSse2OpF(context, nameof(Sse.Multiply));
  677. }
  678. else
  679. {
  680. EmitVectorBinaryOpF(context, () =>
  681. {
  682. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMul));
  683. });
  684. }
  685. }
  686. public static void Fmul_Ve(ILEmitterCtx context)
  687. {
  688. if (Optimizations.FastFP && Optimizations.UseSse2)
  689. {
  690. OpCodeSimdRegElemF64 op = (OpCodeSimdRegElemF64)context.CurrOp;
  691. int sizeF = op.Size & 1;
  692. if (sizeF == 0)
  693. {
  694. Type[] typesSfl = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>), typeof(byte) };
  695. Type[] typesMul = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
  696. context.EmitLdvec(op.Rn);
  697. context.EmitLdvec(op.Rm);
  698. context.Emit(OpCodes.Dup);
  699. context.EmitLdc_I4(op.Index | op.Index << 2 | op.Index << 4 | op.Index << 6);
  700. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Shuffle), typesSfl));
  701. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), typesMul));
  702. context.EmitStvec(op.Rd);
  703. if (op.RegisterSize == RegisterSize.Simd64)
  704. {
  705. EmitVectorZeroUpper(context, op.Rd);
  706. }
  707. }
  708. else /* if (sizeF == 1) */
  709. {
  710. Type[] typesSfl = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>), typeof(byte) };
  711. Type[] typesMul = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
  712. EmitLdvecWithCastToDouble(context, op.Rn);
  713. EmitLdvecWithCastToDouble(context, op.Rm);
  714. context.Emit(OpCodes.Dup);
  715. context.EmitLdc_I4(op.Index | op.Index << 1);
  716. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), typesSfl));
  717. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), typesMul));
  718. EmitStvecWithCastFromDouble(context, op.Rd);
  719. }
  720. }
  721. else
  722. {
  723. EmitVectorBinaryOpByElemF(context, () =>
  724. {
  725. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMul));
  726. });
  727. }
  728. }
  729. public static void Fmulx_S(ILEmitterCtx context)
  730. {
  731. EmitScalarBinaryOpF(context, () =>
  732. {
  733. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMulX));
  734. });
  735. }
  736. public static void Fmulx_Se(ILEmitterCtx context)
  737. {
  738. EmitScalarBinaryOpByElemF(context, () =>
  739. {
  740. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMulX));
  741. });
  742. }
  743. public static void Fmulx_V(ILEmitterCtx context)
  744. {
  745. EmitVectorBinaryOpF(context, () =>
  746. {
  747. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMulX));
  748. });
  749. }
  750. public static void Fmulx_Ve(ILEmitterCtx context)
  751. {
  752. EmitVectorBinaryOpByElemF(context, () =>
  753. {
  754. EmitSoftFloatCall(context, nameof(SoftFloat32.FPMulX));
  755. });
  756. }
  757. public static void Fneg_S(ILEmitterCtx context)
  758. {
  759. if (Optimizations.UseSse2)
  760. {
  761. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  762. if (op.Size == 0)
  763. {
  764. Type[] typesSsv = new Type[] { typeof(float) };
  765. Type[] typesXor = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
  766. context.EmitLdc_R4(-0f);
  767. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetScalarVector128), typesSsv));
  768. context.EmitLdvec(op.Rn);
  769. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Xor), typesXor));
  770. context.EmitStvec(op.Rd);
  771. EmitVectorZero32_128(context, op.Rd);
  772. }
  773. else /* if (op.Size == 1) */
  774. {
  775. Type[] typesSsv = new Type[] { typeof(double) };
  776. Type[] typesXor = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
  777. context.EmitLdc_R8(-0d);
  778. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetScalarVector128), typesSsv));
  779. EmitLdvecWithCastToDouble(context, op.Rn);
  780. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Xor), typesXor));
  781. EmitStvecWithCastFromDouble(context, op.Rd);
  782. EmitVectorZeroUpper(context, op.Rd);
  783. }
  784. }
  785. else
  786. {
  787. EmitScalarUnaryOpF(context, () => context.Emit(OpCodes.Neg));
  788. }
  789. }
  790. public static void Fneg_V(ILEmitterCtx context)
  791. {
  792. if (Optimizations.UseSse2)
  793. {
  794. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  795. int sizeF = op.Size & 1;
  796. if (sizeF == 0)
  797. {
  798. Type[] typesSav = new Type[] { typeof(float) };
  799. Type[] typesXor = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
  800. context.EmitLdc_R4(-0f);
  801. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetAllVector128), typesSav));
  802. context.EmitLdvec(op.Rn);
  803. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Xor), typesXor));
  804. context.EmitStvec(op.Rd);
  805. if (op.RegisterSize == RegisterSize.Simd64)
  806. {
  807. EmitVectorZeroUpper(context, op.Rd);
  808. }
  809. }
  810. else /* if (sizeF == 1) */
  811. {
  812. Type[] typesSav = new Type[] { typeof(double) };
  813. Type[] typesXor = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
  814. context.EmitLdc_R8(-0d);
  815. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
  816. EmitLdvecWithCastToDouble(context, op.Rn);
  817. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Xor), typesXor));
  818. EmitStvecWithCastFromDouble(context, op.Rd);
  819. }
  820. }
  821. else
  822. {
  823. EmitVectorUnaryOpF(context, () => context.Emit(OpCodes.Neg));
  824. }
  825. }
  826. public static void Fnmadd_S(ILEmitterCtx context)
  827. {
  828. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  829. int sizeF = op.Size & 1;
  830. EmitVectorExtractF(context, op.Rn, 0, sizeF);
  831. context.Emit(OpCodes.Neg);
  832. EmitVectorExtractF(context, op.Rm, 0, sizeF);
  833. context.Emit(OpCodes.Mul);
  834. EmitVectorExtractF(context, op.Ra, 0, sizeF);
  835. context.Emit(OpCodes.Sub);
  836. EmitScalarSetF(context, op.Rd, sizeF);
  837. }
  838. public static void Fnmsub_S(ILEmitterCtx context)
  839. {
  840. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  841. int sizeF = op.Size & 1;
  842. EmitVectorExtractF(context, op.Rn, 0, sizeF);
  843. EmitVectorExtractF(context, op.Rm, 0, sizeF);
  844. context.Emit(OpCodes.Mul);
  845. EmitVectorExtractF(context, op.Ra, 0, sizeF);
  846. context.Emit(OpCodes.Sub);
  847. EmitScalarSetF(context, op.Rd, sizeF);
  848. }
  849. public static void Fnmul_S(ILEmitterCtx context)
  850. {
  851. EmitScalarBinaryOpF(context, () =>
  852. {
  853. context.Emit(OpCodes.Mul);
  854. context.Emit(OpCodes.Neg);
  855. });
  856. }
  857. public static void Frecpe_S(ILEmitterCtx context)
  858. {
  859. EmitScalarUnaryOpF(context, () =>
  860. {
  861. EmitUnarySoftFloatCall(context, nameof(SoftFloat.RecipEstimate));
  862. });
  863. }
  864. public static void Frecpe_V(ILEmitterCtx context)
  865. {
  866. EmitVectorUnaryOpF(context, () =>
  867. {
  868. EmitUnarySoftFloatCall(context, nameof(SoftFloat.RecipEstimate));
  869. });
  870. }
  871. public static void Frecps_S(ILEmitterCtx context) // Fused.
  872. {
  873. if (Optimizations.FastFP && Optimizations.UseSse2)
  874. {
  875. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  876. int sizeF = op.Size & 1;
  877. if (sizeF == 0)
  878. {
  879. Type[] typesSsv = new Type[] { typeof(float) };
  880. Type[] typesMulSub = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
  881. context.EmitLdc_R4(2f);
  882. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetScalarVector128), typesSsv));
  883. context.EmitLdvec(op.Rn);
  884. context.EmitLdvec(op.Rm);
  885. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.MultiplyScalar), typesMulSub));
  886. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SubtractScalar), typesMulSub));
  887. context.EmitStvec(op.Rd);
  888. EmitVectorZero32_128(context, op.Rd);
  889. }
  890. else /* if (sizeF == 1) */
  891. {
  892. Type[] typesSsv = new Type[] { typeof(double) };
  893. Type[] typesMulSub = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
  894. context.EmitLdc_R8(2d);
  895. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetScalarVector128), typesSsv));
  896. EmitLdvecWithCastToDouble(context, op.Rn);
  897. EmitLdvecWithCastToDouble(context, op.Rm);
  898. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.MultiplyScalar), typesMulSub));
  899. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SubtractScalar), typesMulSub));
  900. EmitStvecWithCastFromDouble(context, op.Rd);
  901. EmitVectorZeroUpper(context, op.Rd);
  902. }
  903. }
  904. else
  905. {
  906. EmitScalarBinaryOpF(context, () =>
  907. {
  908. EmitSoftFloatCall(context, nameof(SoftFloat32.FPRecipStepFused));
  909. });
  910. }
  911. }
  912. public static void Frecps_V(ILEmitterCtx context) // Fused.
  913. {
  914. if (Optimizations.FastFP && Optimizations.UseSse2)
  915. {
  916. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  917. int sizeF = op.Size & 1;
  918. if (sizeF == 0)
  919. {
  920. Type[] typesSav = new Type[] { typeof(float) };
  921. Type[] typesMulSub = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
  922. context.EmitLdc_R4(2f);
  923. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetAllVector128), typesSav));
  924. context.EmitLdvec(op.Rn);
  925. context.EmitLdvec(op.Rm);
  926. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), typesMulSub));
  927. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Subtract), typesMulSub));
  928. context.EmitStvec(op.Rd);
  929. if (op.RegisterSize == RegisterSize.Simd64)
  930. {
  931. EmitVectorZeroUpper(context, op.Rd);
  932. }
  933. }
  934. else /* if (sizeF == 1) */
  935. {
  936. Type[] typesSav = new Type[] { typeof(double) };
  937. Type[] typesMulSub = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
  938. context.EmitLdc_R8(2d);
  939. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
  940. EmitLdvecWithCastToDouble(context, op.Rn);
  941. EmitLdvecWithCastToDouble(context, op.Rm);
  942. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), typesMulSub));
  943. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesMulSub));
  944. EmitStvecWithCastFromDouble(context, op.Rd);
  945. }
  946. }
  947. else
  948. {
  949. EmitVectorBinaryOpF(context, () =>
  950. {
  951. EmitSoftFloatCall(context, nameof(SoftFloat32.FPRecipStepFused));
  952. });
  953. }
  954. }
  955. public static void Frecpx_S(ILEmitterCtx context)
  956. {
  957. EmitScalarUnaryOpF(context, () =>
  958. {
  959. EmitSoftFloatCall(context, nameof(SoftFloat32.FPRecpX));
  960. });
  961. }
  962. public static void Frinta_S(ILEmitterCtx context)
  963. {
  964. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  965. EmitVectorExtractF(context, op.Rn, 0, op.Size);
  966. EmitRoundMathCall(context, MidpointRounding.AwayFromZero);
  967. EmitScalarSetF(context, op.Rd, op.Size);
  968. }
  969. public static void Frinta_V(ILEmitterCtx context)
  970. {
  971. EmitVectorUnaryOpF(context, () =>
  972. {
  973. EmitRoundMathCall(context, MidpointRounding.AwayFromZero);
  974. });
  975. }
  976. public static void Frinti_S(ILEmitterCtx context)
  977. {
  978. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  979. EmitScalarUnaryOpF(context, () =>
  980. {
  981. context.EmitLdarg(TranslatedSub.StateArgIdx);
  982. if (op.Size == 0)
  983. {
  984. VectorHelper.EmitCall(context, nameof(VectorHelper.RoundF));
  985. }
  986. else if (op.Size == 1)
  987. {
  988. VectorHelper.EmitCall(context, nameof(VectorHelper.Round));
  989. }
  990. else
  991. {
  992. throw new InvalidOperationException();
  993. }
  994. });
  995. }
  996. public static void Frinti_V(ILEmitterCtx context)
  997. {
  998. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  999. int sizeF = op.Size & 1;
  1000. EmitVectorUnaryOpF(context, () =>
  1001. {
  1002. context.EmitLdarg(TranslatedSub.StateArgIdx);
  1003. if (sizeF == 0)
  1004. {
  1005. VectorHelper.EmitCall(context, nameof(VectorHelper.RoundF));
  1006. }
  1007. else if (sizeF == 1)
  1008. {
  1009. VectorHelper.EmitCall(context, nameof(VectorHelper.Round));
  1010. }
  1011. else
  1012. {
  1013. throw new InvalidOperationException();
  1014. }
  1015. });
  1016. }
  1017. public static void Frintm_S(ILEmitterCtx context)
  1018. {
  1019. EmitScalarUnaryOpF(context, () =>
  1020. {
  1021. EmitUnaryMathCall(context, nameof(Math.Floor));
  1022. });
  1023. }
  1024. public static void Frintm_V(ILEmitterCtx context)
  1025. {
  1026. EmitVectorUnaryOpF(context, () =>
  1027. {
  1028. EmitUnaryMathCall(context, nameof(Math.Floor));
  1029. });
  1030. }
  1031. public static void Frintn_S(ILEmitterCtx context)
  1032. {
  1033. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  1034. EmitVectorExtractF(context, op.Rn, 0, op.Size);
  1035. EmitRoundMathCall(context, MidpointRounding.ToEven);
  1036. EmitScalarSetF(context, op.Rd, op.Size);
  1037. }
  1038. public static void Frintn_V(ILEmitterCtx context)
  1039. {
  1040. EmitVectorUnaryOpF(context, () =>
  1041. {
  1042. EmitRoundMathCall(context, MidpointRounding.ToEven);
  1043. });
  1044. }
  1045. public static void Frintp_S(ILEmitterCtx context)
  1046. {
  1047. EmitScalarUnaryOpF(context, () =>
  1048. {
  1049. EmitUnaryMathCall(context, nameof(Math.Ceiling));
  1050. });
  1051. }
  1052. public static void Frintp_V(ILEmitterCtx context)
  1053. {
  1054. EmitVectorUnaryOpF(context, () =>
  1055. {
  1056. EmitUnaryMathCall(context, nameof(Math.Ceiling));
  1057. });
  1058. }
  1059. public static void Frintx_S(ILEmitterCtx context)
  1060. {
  1061. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  1062. EmitScalarUnaryOpF(context, () =>
  1063. {
  1064. context.EmitLdarg(TranslatedSub.StateArgIdx);
  1065. if (op.Size == 0)
  1066. {
  1067. VectorHelper.EmitCall(context, nameof(VectorHelper.RoundF));
  1068. }
  1069. else if (op.Size == 1)
  1070. {
  1071. VectorHelper.EmitCall(context, nameof(VectorHelper.Round));
  1072. }
  1073. else
  1074. {
  1075. throw new InvalidOperationException();
  1076. }
  1077. });
  1078. }
  1079. public static void Frintx_V(ILEmitterCtx context)
  1080. {
  1081. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  1082. EmitVectorUnaryOpF(context, () =>
  1083. {
  1084. context.EmitLdarg(TranslatedSub.StateArgIdx);
  1085. if (op.Size == 0)
  1086. {
  1087. VectorHelper.EmitCall(context, nameof(VectorHelper.RoundF));
  1088. }
  1089. else if (op.Size == 1)
  1090. {
  1091. VectorHelper.EmitCall(context, nameof(VectorHelper.Round));
  1092. }
  1093. else
  1094. {
  1095. throw new InvalidOperationException();
  1096. }
  1097. });
  1098. }
  1099. public static void Frintz_S(ILEmitterCtx context)
  1100. {
  1101. EmitScalarUnaryOpF(context, () =>
  1102. {
  1103. EmitUnaryMathCall(context, nameof(Math.Truncate));
  1104. });
  1105. }
  1106. public static void Frintz_V(ILEmitterCtx context)
  1107. {
  1108. EmitVectorUnaryOpF(context, () =>
  1109. {
  1110. EmitUnaryMathCall(context, nameof(Math.Truncate));
  1111. });
  1112. }
  1113. public static void Frsqrte_S(ILEmitterCtx context)
  1114. {
  1115. EmitScalarUnaryOpF(context, () =>
  1116. {
  1117. EmitUnarySoftFloatCall(context, nameof(SoftFloat.InvSqrtEstimate));
  1118. });
  1119. }
  1120. public static void Frsqrte_V(ILEmitterCtx context)
  1121. {
  1122. EmitVectorUnaryOpF(context, () =>
  1123. {
  1124. EmitUnarySoftFloatCall(context, nameof(SoftFloat.InvSqrtEstimate));
  1125. });
  1126. }
  1127. public static void Frsqrts_S(ILEmitterCtx context) // Fused.
  1128. {
  1129. if (Optimizations.FastFP && Optimizations.UseSse2)
  1130. {
  1131. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  1132. int sizeF = op.Size & 1;
  1133. if (sizeF == 0)
  1134. {
  1135. Type[] typesSsv = new Type[] { typeof(float) };
  1136. Type[] typesMulSub = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
  1137. context.EmitLdc_R4(0.5f);
  1138. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetScalarVector128), typesSsv));
  1139. context.EmitLdc_R4(3f);
  1140. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetScalarVector128), typesSsv));
  1141. context.EmitLdvec(op.Rn);
  1142. context.EmitLdvec(op.Rm);
  1143. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.MultiplyScalar), typesMulSub));
  1144. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SubtractScalar), typesMulSub));
  1145. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.MultiplyScalar), typesMulSub));
  1146. context.EmitStvec(op.Rd);
  1147. EmitVectorZero32_128(context, op.Rd);
  1148. }
  1149. else /* if (sizeF == 1) */
  1150. {
  1151. Type[] typesSsv = new Type[] { typeof(double) };
  1152. Type[] typesMulSub = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
  1153. context.EmitLdc_R8(0.5d);
  1154. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetScalarVector128), typesSsv));
  1155. context.EmitLdc_R8(3d);
  1156. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetScalarVector128), typesSsv));
  1157. EmitLdvecWithCastToDouble(context, op.Rn);
  1158. EmitLdvecWithCastToDouble(context, op.Rm);
  1159. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.MultiplyScalar), typesMulSub));
  1160. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SubtractScalar), typesMulSub));
  1161. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.MultiplyScalar), typesMulSub));
  1162. EmitStvecWithCastFromDouble(context, op.Rd);
  1163. EmitVectorZeroUpper(context, op.Rd);
  1164. }
  1165. }
  1166. else
  1167. {
  1168. EmitScalarBinaryOpF(context, () =>
  1169. {
  1170. EmitSoftFloatCall(context, nameof(SoftFloat32.FPRSqrtStepFused));
  1171. });
  1172. }
  1173. }
  1174. public static void Frsqrts_V(ILEmitterCtx context) // Fused.
  1175. {
  1176. if (Optimizations.FastFP && Optimizations.UseSse2)
  1177. {
  1178. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  1179. int sizeF = op.Size & 1;
  1180. if (sizeF == 0)
  1181. {
  1182. Type[] typesSav = new Type[] { typeof(float) };
  1183. Type[] typesMulSub = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
  1184. context.EmitLdc_R4(0.5f);
  1185. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetAllVector128), typesSav));
  1186. context.EmitLdc_R4(3f);
  1187. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetAllVector128), typesSav));
  1188. context.EmitLdvec(op.Rn);
  1189. context.EmitLdvec(op.Rm);
  1190. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), typesMulSub));
  1191. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Subtract), typesMulSub));
  1192. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), typesMulSub));
  1193. context.EmitStvec(op.Rd);
  1194. if (op.RegisterSize == RegisterSize.Simd64)
  1195. {
  1196. EmitVectorZeroUpper(context, op.Rd);
  1197. }
  1198. }
  1199. else /* if (sizeF == 1) */
  1200. {
  1201. Type[] typesSav = new Type[] { typeof(double) };
  1202. Type[] typesMulSub = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
  1203. context.EmitLdc_R8(0.5d);
  1204. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
  1205. context.EmitLdc_R8(3d);
  1206. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
  1207. EmitLdvecWithCastToDouble(context, op.Rn);
  1208. EmitLdvecWithCastToDouble(context, op.Rm);
  1209. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), typesMulSub));
  1210. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesMulSub));
  1211. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), typesMulSub));
  1212. EmitStvecWithCastFromDouble(context, op.Rd);
  1213. }
  1214. }
  1215. else
  1216. {
  1217. EmitVectorBinaryOpF(context, () =>
  1218. {
  1219. EmitSoftFloatCall(context, nameof(SoftFloat32.FPRSqrtStepFused));
  1220. });
  1221. }
  1222. }
  1223. public static void Fsqrt_S(ILEmitterCtx context)
  1224. {
  1225. if (Optimizations.FastFP && Optimizations.UseSse
  1226. && Optimizations.UseSse2)
  1227. {
  1228. EmitScalarSseOrSse2OpF(context, nameof(Sse.SqrtScalar));
  1229. }
  1230. else
  1231. {
  1232. EmitScalarUnaryOpF(context, () =>
  1233. {
  1234. EmitSoftFloatCall(context, nameof(SoftFloat32.FPSqrt));
  1235. });
  1236. }
  1237. }
  1238. public static void Fsqrt_V(ILEmitterCtx context)
  1239. {
  1240. if (Optimizations.FastFP && Optimizations.UseSse
  1241. && Optimizations.UseSse2)
  1242. {
  1243. EmitVectorSseOrSse2OpF(context, nameof(Sse.Sqrt));
  1244. }
  1245. else
  1246. {
  1247. EmitVectorUnaryOpF(context, () =>
  1248. {
  1249. EmitSoftFloatCall(context, nameof(SoftFloat32.FPSqrt));
  1250. });
  1251. }
  1252. }
  1253. public static void Fsub_S(ILEmitterCtx context)
  1254. {
  1255. if (Optimizations.FastFP && Optimizations.UseSse
  1256. && Optimizations.UseSse2)
  1257. {
  1258. EmitScalarSseOrSse2OpF(context, nameof(Sse.SubtractScalar));
  1259. }
  1260. else
  1261. {
  1262. EmitScalarBinaryOpF(context, () =>
  1263. {
  1264. EmitSoftFloatCall(context, nameof(SoftFloat32.FPSub));
  1265. });
  1266. }
  1267. }
  1268. public static void Fsub_V(ILEmitterCtx context)
  1269. {
  1270. if (Optimizations.FastFP && Optimizations.UseSse
  1271. && Optimizations.UseSse2)
  1272. {
  1273. EmitVectorSseOrSse2OpF(context, nameof(Sse.Subtract));
  1274. }
  1275. else
  1276. {
  1277. EmitVectorBinaryOpF(context, () =>
  1278. {
  1279. EmitSoftFloatCall(context, nameof(SoftFloat32.FPSub));
  1280. });
  1281. }
  1282. }
  1283. public static void Mla_V(ILEmitterCtx context)
  1284. {
  1285. EmitVectorTernaryOpZx(context, () =>
  1286. {
  1287. context.Emit(OpCodes.Mul);
  1288. context.Emit(OpCodes.Add);
  1289. });
  1290. }
  1291. public static void Mla_Ve(ILEmitterCtx context)
  1292. {
  1293. EmitVectorTernaryOpByElemZx(context, () =>
  1294. {
  1295. context.Emit(OpCodes.Mul);
  1296. context.Emit(OpCodes.Add);
  1297. });
  1298. }
  1299. public static void Mls_V(ILEmitterCtx context)
  1300. {
  1301. EmitVectorTernaryOpZx(context, () =>
  1302. {
  1303. context.Emit(OpCodes.Mul);
  1304. context.Emit(OpCodes.Sub);
  1305. });
  1306. }
  1307. public static void Mls_Ve(ILEmitterCtx context)
  1308. {
  1309. EmitVectorTernaryOpByElemZx(context, () =>
  1310. {
  1311. context.Emit(OpCodes.Mul);
  1312. context.Emit(OpCodes.Sub);
  1313. });
  1314. }
  1315. public static void Mul_V(ILEmitterCtx context)
  1316. {
  1317. EmitVectorBinaryOpZx(context, () => context.Emit(OpCodes.Mul));
  1318. }
  1319. public static void Mul_Ve(ILEmitterCtx context)
  1320. {
  1321. EmitVectorBinaryOpByElemZx(context, () => context.Emit(OpCodes.Mul));
  1322. }
  1323. public static void Neg_S(ILEmitterCtx context)
  1324. {
  1325. EmitScalarUnaryOpSx(context, () => context.Emit(OpCodes.Neg));
  1326. }
  1327. public static void Neg_V(ILEmitterCtx context)
  1328. {
  1329. if (Optimizations.UseSse2)
  1330. {
  1331. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  1332. Type[] typesSub = new Type[] { VectorIntTypesPerSizeLog2[op.Size], VectorIntTypesPerSizeLog2[op.Size] };
  1333. string[] namesSzv = new string[] { nameof(VectorHelper.VectorSByteZero),
  1334. nameof(VectorHelper.VectorInt16Zero),
  1335. nameof(VectorHelper.VectorInt32Zero),
  1336. nameof(VectorHelper.VectorInt64Zero) };
  1337. VectorHelper.EmitCall(context, namesSzv[op.Size]);
  1338. EmitLdvecWithSignedCast(context, op.Rn, op.Size);
  1339. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesSub));
  1340. EmitStvecWithSignedCast(context, op.Rd, op.Size);
  1341. if (op.RegisterSize == RegisterSize.Simd64)
  1342. {
  1343. EmitVectorZeroUpper(context, op.Rd);
  1344. }
  1345. }
  1346. else
  1347. {
  1348. EmitVectorUnaryOpSx(context, () => context.Emit(OpCodes.Neg));
  1349. }
  1350. }
  1351. public static void Raddhn_V(ILEmitterCtx context)
  1352. {
  1353. EmitHighNarrow(context, () => context.Emit(OpCodes.Add), round: true);
  1354. }
  1355. public static void Rsubhn_V(ILEmitterCtx context)
  1356. {
  1357. EmitHighNarrow(context, () => context.Emit(OpCodes.Sub), round: true);
  1358. }
  1359. public static void Saba_V(ILEmitterCtx context)
  1360. {
  1361. EmitVectorTernaryOpSx(context, () =>
  1362. {
  1363. context.Emit(OpCodes.Sub);
  1364. EmitAbs(context);
  1365. context.Emit(OpCodes.Add);
  1366. });
  1367. }
  1368. public static void Sabal_V(ILEmitterCtx context)
  1369. {
  1370. EmitVectorWidenRnRmTernaryOpSx(context, () =>
  1371. {
  1372. context.Emit(OpCodes.Sub);
  1373. EmitAbs(context);
  1374. context.Emit(OpCodes.Add);
  1375. });
  1376. }
  1377. public static void Sabd_V(ILEmitterCtx context)
  1378. {
  1379. EmitVectorBinaryOpSx(context, () =>
  1380. {
  1381. context.Emit(OpCodes.Sub);
  1382. EmitAbs(context);
  1383. });
  1384. }
  1385. public static void Sabdl_V(ILEmitterCtx context)
  1386. {
  1387. EmitVectorWidenRnRmBinaryOpSx(context, () =>
  1388. {
  1389. context.Emit(OpCodes.Sub);
  1390. EmitAbs(context);
  1391. });
  1392. }
  1393. public static void Sadalp_V(ILEmitterCtx context)
  1394. {
  1395. EmitAddLongPairwise(context, signed: true, accumulate: true);
  1396. }
  1397. public static void Saddl_V(ILEmitterCtx context)
  1398. {
  1399. if (Optimizations.UseSse41)
  1400. {
  1401. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  1402. Type[] typesSrl = new Type[] { VectorIntTypesPerSizeLog2[op.Size], typeof(byte) };
  1403. Type[] typesCvt = new Type[] { VectorIntTypesPerSizeLog2[op.Size] };
  1404. Type[] typesAdd = new Type[] { VectorIntTypesPerSizeLog2[op.Size + 1],
  1405. VectorIntTypesPerSizeLog2[op.Size + 1] };
  1406. string[] namesCvt = new string[] { nameof(Sse41.ConvertToVector128Int16),
  1407. nameof(Sse41.ConvertToVector128Int32),
  1408. nameof(Sse41.ConvertToVector128Int64) };
  1409. int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
  1410. EmitLdvecWithSignedCast(context, op.Rn, op.Size);
  1411. context.EmitLdc_I4(numBytes);
  1412. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
  1413. context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
  1414. EmitLdvecWithSignedCast(context, op.Rm, op.Size);
  1415. context.EmitLdc_I4(numBytes);
  1416. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
  1417. context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
  1418. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesAdd));
  1419. EmitStvecWithSignedCast(context, op.Rd, op.Size + 1);
  1420. }
  1421. else
  1422. {
  1423. EmitVectorWidenRnRmBinaryOpSx(context, () => context.Emit(OpCodes.Add));
  1424. }
  1425. }
  1426. public static void Saddlp_V(ILEmitterCtx context)
  1427. {
  1428. EmitAddLongPairwise(context, signed: true, accumulate: false);
  1429. }
  1430. public static void Saddw_V(ILEmitterCtx context)
  1431. {
  1432. if (Optimizations.UseSse41)
  1433. {
  1434. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  1435. Type[] typesSrl = new Type[] { VectorIntTypesPerSizeLog2[op.Size], typeof(byte) };
  1436. Type[] typesCvt = new Type[] { VectorIntTypesPerSizeLog2[op.Size] };
  1437. Type[] typesAdd = new Type[] { VectorIntTypesPerSizeLog2[op.Size + 1],
  1438. VectorIntTypesPerSizeLog2[op.Size + 1] };
  1439. string[] namesCvt = new string[] { nameof(Sse41.ConvertToVector128Int16),
  1440. nameof(Sse41.ConvertToVector128Int32),
  1441. nameof(Sse41.ConvertToVector128Int64) };
  1442. int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
  1443. EmitLdvecWithSignedCast(context, op.Rn, op.Size + 1);
  1444. EmitLdvecWithSignedCast(context, op.Rm, op.Size);
  1445. context.EmitLdc_I4(numBytes);
  1446. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
  1447. context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
  1448. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesAdd));
  1449. EmitStvecWithSignedCast(context, op.Rd, op.Size + 1);
  1450. }
  1451. else
  1452. {
  1453. EmitVectorWidenRmBinaryOpSx(context, () => context.Emit(OpCodes.Add));
  1454. }
  1455. }
  1456. public static void Shadd_V(ILEmitterCtx context)
  1457. {
  1458. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  1459. if (Optimizations.UseSse2 && op.Size > 0)
  1460. {
  1461. Type[] typesSra = new Type[] { VectorIntTypesPerSizeLog2[op.Size], typeof(byte) };
  1462. Type[] typesAndXorAdd = new Type[] { VectorIntTypesPerSizeLog2[op.Size], VectorIntTypesPerSizeLog2[op.Size] };
  1463. EmitLdvecWithSignedCast(context, op.Rn, op.Size);
  1464. context.Emit(OpCodes.Dup);
  1465. context.EmitStvectmp();
  1466. EmitLdvecWithSignedCast(context, op.Rm, op.Size);
  1467. context.Emit(OpCodes.Dup);
  1468. context.EmitStvectmp2();
  1469. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.And), typesAndXorAdd));
  1470. context.EmitLdvectmp();
  1471. context.EmitLdvectmp2();
  1472. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Xor), typesAndXorAdd));
  1473. context.EmitLdc_I4(1);
  1474. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightArithmetic), typesSra));
  1475. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesAndXorAdd));
  1476. EmitStvecWithSignedCast(context, op.Rd, op.Size);
  1477. if (op.RegisterSize == RegisterSize.Simd64)
  1478. {
  1479. EmitVectorZeroUpper(context, op.Rd);
  1480. }
  1481. }
  1482. else
  1483. {
  1484. EmitVectorBinaryOpSx(context, () =>
  1485. {
  1486. context.Emit(OpCodes.Add);
  1487. context.Emit(OpCodes.Ldc_I4_1);
  1488. context.Emit(OpCodes.Shr);
  1489. });
  1490. }
  1491. }
  1492. public static void Shsub_V(ILEmitterCtx context)
  1493. {
  1494. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  1495. if (Optimizations.UseSse2 && op.Size < 2)
  1496. {
  1497. Type[] typesSav = new Type[] { IntTypesPerSizeLog2[op.Size] };
  1498. Type[] typesAddSub = new Type[] { VectorIntTypesPerSizeLog2 [op.Size], VectorIntTypesPerSizeLog2 [op.Size] };
  1499. Type[] typesAvg = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], VectorUIntTypesPerSizeLog2[op.Size] };
  1500. context.EmitLdc_I4(op.Size == 0 ? sbyte.MinValue : short.MinValue);
  1501. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
  1502. context.EmitStvectmp();
  1503. EmitLdvecWithSignedCast(context, op.Rn, op.Size);
  1504. context.EmitLdvectmp();
  1505. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesAddSub));
  1506. context.Emit(OpCodes.Dup);
  1507. EmitLdvecWithSignedCast(context, op.Rm, op.Size);
  1508. context.EmitLdvectmp();
  1509. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesAddSub));
  1510. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Average), typesAvg));
  1511. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesAddSub));
  1512. EmitStvecWithSignedCast(context, op.Rd, op.Size);
  1513. if (op.RegisterSize == RegisterSize.Simd64)
  1514. {
  1515. EmitVectorZeroUpper(context, op.Rd);
  1516. }
  1517. }
  1518. else
  1519. {
  1520. EmitVectorBinaryOpSx(context, () =>
  1521. {
  1522. context.Emit(OpCodes.Sub);
  1523. context.Emit(OpCodes.Ldc_I4_1);
  1524. context.Emit(OpCodes.Shr);
  1525. });
  1526. }
  1527. }
  1528. public static void Smax_V(ILEmitterCtx context)
  1529. {
  1530. if (Optimizations.UseSse41)
  1531. {
  1532. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  1533. Type[] typesMax = new Type[] { VectorIntTypesPerSizeLog2[op.Size], VectorIntTypesPerSizeLog2[op.Size] };
  1534. Type typeSse = op.Size == 1 ? typeof(Sse2) : typeof(Sse41);
  1535. EmitLdvecWithSignedCast(context, op.Rn, op.Size);
  1536. EmitLdvecWithSignedCast(context, op.Rm, op.Size);
  1537. context.EmitCall(typeSse.GetMethod(nameof(Sse2.Max), typesMax));
  1538. EmitStvecWithSignedCast(context, op.Rd, op.Size);
  1539. if (op.RegisterSize == RegisterSize.Simd64)
  1540. {
  1541. EmitVectorZeroUpper(context, op.Rd);
  1542. }
  1543. }
  1544. else
  1545. {
  1546. Type[] types = new Type[] { typeof(long), typeof(long) };
  1547. MethodInfo mthdInfo = typeof(Math).GetMethod(nameof(Math.Max), types);
  1548. EmitVectorBinaryOpSx(context, () => context.EmitCall(mthdInfo));
  1549. }
  1550. }
  1551. public static void Smaxp_V(ILEmitterCtx context)
  1552. {
  1553. Type[] types = new Type[] { typeof(long), typeof(long) };
  1554. MethodInfo mthdInfo = typeof(Math).GetMethod(nameof(Math.Max), types);
  1555. EmitVectorPairwiseOpSx(context, () => context.EmitCall(mthdInfo));
  1556. }
  1557. public static void Smin_V(ILEmitterCtx context)
  1558. {
  1559. if (Optimizations.UseSse41)
  1560. {
  1561. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  1562. Type[] typesMin = new Type[] { VectorIntTypesPerSizeLog2[op.Size], VectorIntTypesPerSizeLog2[op.Size] };
  1563. Type typeSse = op.Size == 1 ? typeof(Sse2) : typeof(Sse41);
  1564. EmitLdvecWithSignedCast(context, op.Rn, op.Size);
  1565. EmitLdvecWithSignedCast(context, op.Rm, op.Size);
  1566. context.EmitCall(typeSse.GetMethod(nameof(Sse2.Min), typesMin));
  1567. EmitStvecWithSignedCast(context, op.Rd, op.Size);
  1568. if (op.RegisterSize == RegisterSize.Simd64)
  1569. {
  1570. EmitVectorZeroUpper(context, op.Rd);
  1571. }
  1572. }
  1573. else
  1574. {
  1575. Type[] types = new Type[] { typeof(long), typeof(long) };
  1576. MethodInfo mthdInfo = typeof(Math).GetMethod(nameof(Math.Min), types);
  1577. EmitVectorBinaryOpSx(context, () => context.EmitCall(mthdInfo));
  1578. }
  1579. }
  1580. public static void Sminp_V(ILEmitterCtx context)
  1581. {
  1582. Type[] types = new Type[] { typeof(long), typeof(long) };
  1583. MethodInfo mthdInfo = typeof(Math).GetMethod(nameof(Math.Min), types);
  1584. EmitVectorPairwiseOpSx(context, () => context.EmitCall(mthdInfo));
  1585. }
  1586. public static void Smlal_V(ILEmitterCtx context)
  1587. {
  1588. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  1589. if (Optimizations.UseSse41 && op.Size < 2)
  1590. {
  1591. Type[] typesSrl = new Type[] { VectorIntTypesPerSizeLog2[op.Size], typeof(byte) };
  1592. Type[] typesCvt = new Type[] { VectorIntTypesPerSizeLog2[op.Size] };
  1593. Type[] typesMulAdd = new Type[] { VectorIntTypesPerSizeLog2[op.Size + 1],
  1594. VectorIntTypesPerSizeLog2[op.Size + 1] };
  1595. Type typeSse = op.Size == 0 ? typeof(Sse2) : typeof(Sse41);
  1596. string nameCvt = op.Size == 0
  1597. ? nameof(Sse41.ConvertToVector128Int16)
  1598. : nameof(Sse41.ConvertToVector128Int32);
  1599. int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
  1600. EmitLdvecWithSignedCast(context, op.Rd, op.Size + 1);
  1601. EmitLdvecWithSignedCast(context, op.Rn, op.Size);
  1602. context.EmitLdc_I4(numBytes);
  1603. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
  1604. context.EmitCall(typeof(Sse41).GetMethod(nameCvt, typesCvt));
  1605. EmitLdvecWithSignedCast(context, op.Rm, op.Size);
  1606. context.EmitLdc_I4(numBytes);
  1607. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
  1608. context.EmitCall(typeof(Sse41).GetMethod(nameCvt, typesCvt));
  1609. context.EmitCall(typeSse.GetMethod(nameof(Sse2.MultiplyLow), typesMulAdd));
  1610. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesMulAdd));
  1611. EmitStvecWithSignedCast(context, op.Rd, op.Size + 1);
  1612. }
  1613. else
  1614. {
  1615. EmitVectorWidenRnRmTernaryOpSx(context, () =>
  1616. {
  1617. context.Emit(OpCodes.Mul);
  1618. context.Emit(OpCodes.Add);
  1619. });
  1620. }
  1621. }
  1622. public static void Smlsl_V(ILEmitterCtx context)
  1623. {
  1624. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  1625. if (Optimizations.UseSse41 && op.Size < 2)
  1626. {
  1627. Type[] typesSrl = new Type[] { VectorIntTypesPerSizeLog2[op.Size], typeof(byte) };
  1628. Type[] typesCvt = new Type[] { VectorIntTypesPerSizeLog2[op.Size] };
  1629. Type[] typesMulSub = new Type[] { VectorIntTypesPerSizeLog2[op.Size + 1],
  1630. VectorIntTypesPerSizeLog2[op.Size + 1] };
  1631. Type typeSse = op.Size == 0 ? typeof(Sse2) : typeof(Sse41);
  1632. string nameCvt = op.Size == 0
  1633. ? nameof(Sse41.ConvertToVector128Int16)
  1634. : nameof(Sse41.ConvertToVector128Int32);
  1635. int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
  1636. EmitLdvecWithSignedCast(context, op.Rd, op.Size + 1);
  1637. EmitLdvecWithSignedCast(context, op.Rn, op.Size);
  1638. context.EmitLdc_I4(numBytes);
  1639. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
  1640. context.EmitCall(typeof(Sse41).GetMethod(nameCvt, typesCvt));
  1641. EmitLdvecWithSignedCast(context, op.Rm, op.Size);
  1642. context.EmitLdc_I4(numBytes);
  1643. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
  1644. context.EmitCall(typeof(Sse41).GetMethod(nameCvt, typesCvt));
  1645. context.EmitCall(typeSse.GetMethod(nameof(Sse2.MultiplyLow), typesMulSub));
  1646. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesMulSub));
  1647. EmitStvecWithSignedCast(context, op.Rd, op.Size + 1);
  1648. }
  1649. else
  1650. {
  1651. EmitVectorWidenRnRmTernaryOpSx(context, () =>
  1652. {
  1653. context.Emit(OpCodes.Mul);
  1654. context.Emit(OpCodes.Sub);
  1655. });
  1656. }
  1657. }
  1658. public static void Smull_V(ILEmitterCtx context)
  1659. {
  1660. EmitVectorWidenRnRmBinaryOpSx(context, () => context.Emit(OpCodes.Mul));
  1661. }
  1662. public static void Sqabs_S(ILEmitterCtx context)
  1663. {
  1664. EmitScalarSaturatingUnaryOpSx(context, () => EmitAbs(context));
  1665. }
  1666. public static void Sqabs_V(ILEmitterCtx context)
  1667. {
  1668. EmitVectorSaturatingUnaryOpSx(context, () => EmitAbs(context));
  1669. }
  1670. public static void Sqadd_S(ILEmitterCtx context)
  1671. {
  1672. EmitScalarSaturatingBinaryOpSx(context, SaturatingFlags.Add);
  1673. }
  1674. public static void Sqadd_V(ILEmitterCtx context)
  1675. {
  1676. EmitVectorSaturatingBinaryOpSx(context, SaturatingFlags.Add);
  1677. }
  1678. public static void Sqdmulh_S(ILEmitterCtx context)
  1679. {
  1680. EmitSaturatingBinaryOp(context, () => EmitDoublingMultiplyHighHalf(context, round: false), SaturatingFlags.ScalarSx);
  1681. }
  1682. public static void Sqdmulh_V(ILEmitterCtx context)
  1683. {
  1684. EmitSaturatingBinaryOp(context, () => EmitDoublingMultiplyHighHalf(context, round: false), SaturatingFlags.VectorSx);
  1685. }
  1686. public static void Sqneg_S(ILEmitterCtx context)
  1687. {
  1688. EmitScalarSaturatingUnaryOpSx(context, () => context.Emit(OpCodes.Neg));
  1689. }
  1690. public static void Sqneg_V(ILEmitterCtx context)
  1691. {
  1692. EmitVectorSaturatingUnaryOpSx(context, () => context.Emit(OpCodes.Neg));
  1693. }
  1694. public static void Sqrdmulh_S(ILEmitterCtx context)
  1695. {
  1696. EmitSaturatingBinaryOp(context, () => EmitDoublingMultiplyHighHalf(context, round: true), SaturatingFlags.ScalarSx);
  1697. }
  1698. public static void Sqrdmulh_V(ILEmitterCtx context)
  1699. {
  1700. EmitSaturatingBinaryOp(context, () => EmitDoublingMultiplyHighHalf(context, round: true), SaturatingFlags.VectorSx);
  1701. }
  1702. public static void Sqsub_S(ILEmitterCtx context)
  1703. {
  1704. EmitScalarSaturatingBinaryOpSx(context, SaturatingFlags.Sub);
  1705. }
  1706. public static void Sqsub_V(ILEmitterCtx context)
  1707. {
  1708. EmitVectorSaturatingBinaryOpSx(context, SaturatingFlags.Sub);
  1709. }
  1710. public static void Sqxtn_S(ILEmitterCtx context)
  1711. {
  1712. EmitSaturatingNarrowOp(context, SaturatingNarrowFlags.ScalarSxSx);
  1713. }
  1714. public static void Sqxtn_V(ILEmitterCtx context)
  1715. {
  1716. EmitSaturatingNarrowOp(context, SaturatingNarrowFlags.VectorSxSx);
  1717. }
  1718. public static void Sqxtun_S(ILEmitterCtx context)
  1719. {
  1720. EmitSaturatingNarrowOp(context, SaturatingNarrowFlags.ScalarSxZx);
  1721. }
  1722. public static void Sqxtun_V(ILEmitterCtx context)
  1723. {
  1724. EmitSaturatingNarrowOp(context, SaturatingNarrowFlags.VectorSxZx);
  1725. }
  1726. public static void Srhadd_V(ILEmitterCtx context)
  1727. {
  1728. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  1729. if (Optimizations.UseSse2 && op.Size < 2)
  1730. {
  1731. Type[] typesSav = new Type[] { IntTypesPerSizeLog2[op.Size] };
  1732. Type[] typesSubAdd = new Type[] { VectorIntTypesPerSizeLog2 [op.Size], VectorIntTypesPerSizeLog2 [op.Size] };
  1733. Type[] typesAvg = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], VectorUIntTypesPerSizeLog2[op.Size] };
  1734. context.EmitLdc_I4(op.Size == 0 ? sbyte.MinValue : short.MinValue);
  1735. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
  1736. context.Emit(OpCodes.Dup);
  1737. context.EmitStvectmp();
  1738. EmitLdvecWithSignedCast(context, op.Rn, op.Size);
  1739. context.EmitLdvectmp();
  1740. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesSubAdd));
  1741. EmitLdvecWithSignedCast(context, op.Rm, op.Size);
  1742. context.EmitLdvectmp();
  1743. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesSubAdd));
  1744. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Average), typesAvg));
  1745. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesSubAdd));
  1746. EmitStvecWithSignedCast(context, op.Rd, op.Size);
  1747. if (op.RegisterSize == RegisterSize.Simd64)
  1748. {
  1749. EmitVectorZeroUpper(context, op.Rd);
  1750. }
  1751. }
  1752. else
  1753. {
  1754. EmitVectorBinaryOpSx(context, () =>
  1755. {
  1756. context.Emit(OpCodes.Add);
  1757. context.Emit(OpCodes.Ldc_I4_1);
  1758. context.Emit(OpCodes.Add);
  1759. context.Emit(OpCodes.Ldc_I4_1);
  1760. context.Emit(OpCodes.Shr);
  1761. });
  1762. }
  1763. }
  1764. public static void Ssubl_V(ILEmitterCtx context)
  1765. {
  1766. if (Optimizations.UseSse41)
  1767. {
  1768. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  1769. Type[] typesSrl = new Type[] { VectorIntTypesPerSizeLog2[op.Size], typeof(byte) };
  1770. Type[] typesCvt = new Type[] { VectorIntTypesPerSizeLog2[op.Size] };
  1771. Type[] typesSub = new Type[] { VectorIntTypesPerSizeLog2[op.Size + 1],
  1772. VectorIntTypesPerSizeLog2[op.Size + 1] };
  1773. string[] namesCvt = new string[] { nameof(Sse41.ConvertToVector128Int16),
  1774. nameof(Sse41.ConvertToVector128Int32),
  1775. nameof(Sse41.ConvertToVector128Int64) };
  1776. int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
  1777. EmitLdvecWithSignedCast(context, op.Rn, op.Size);
  1778. context.EmitLdc_I4(numBytes);
  1779. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
  1780. context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
  1781. EmitLdvecWithSignedCast(context, op.Rm, op.Size);
  1782. context.EmitLdc_I4(numBytes);
  1783. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
  1784. context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
  1785. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesSub));
  1786. EmitStvecWithSignedCast(context, op.Rd, op.Size + 1);
  1787. }
  1788. else
  1789. {
  1790. EmitVectorWidenRnRmBinaryOpSx(context, () => context.Emit(OpCodes.Sub));
  1791. }
  1792. }
  1793. public static void Ssubw_V(ILEmitterCtx context)
  1794. {
  1795. if (Optimizations.UseSse41)
  1796. {
  1797. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  1798. Type[] typesSrl = new Type[] { VectorIntTypesPerSizeLog2[op.Size], typeof(byte) };
  1799. Type[] typesCvt = new Type[] { VectorIntTypesPerSizeLog2[op.Size] };
  1800. Type[] typesSub = new Type[] { VectorIntTypesPerSizeLog2[op.Size + 1],
  1801. VectorIntTypesPerSizeLog2[op.Size + 1] };
  1802. string[] namesCvt = new string[] { nameof(Sse41.ConvertToVector128Int16),
  1803. nameof(Sse41.ConvertToVector128Int32),
  1804. nameof(Sse41.ConvertToVector128Int64) };
  1805. int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
  1806. EmitLdvecWithSignedCast(context, op.Rn, op.Size + 1);
  1807. EmitLdvecWithSignedCast(context, op.Rm, op.Size);
  1808. context.EmitLdc_I4(numBytes);
  1809. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
  1810. context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
  1811. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesSub));
  1812. EmitStvecWithSignedCast(context, op.Rd, op.Size + 1);
  1813. }
  1814. else
  1815. {
  1816. EmitVectorWidenRmBinaryOpSx(context, () => context.Emit(OpCodes.Sub));
  1817. }
  1818. }
  1819. public static void Sub_S(ILEmitterCtx context)
  1820. {
  1821. EmitScalarBinaryOpZx(context, () => context.Emit(OpCodes.Sub));
  1822. }
  1823. public static void Sub_V(ILEmitterCtx context)
  1824. {
  1825. if (Optimizations.UseSse2)
  1826. {
  1827. EmitSse2Op(context, nameof(Sse2.Subtract));
  1828. }
  1829. else
  1830. {
  1831. EmitVectorBinaryOpZx(context, () => context.Emit(OpCodes.Sub));
  1832. }
  1833. }
  1834. public static void Subhn_V(ILEmitterCtx context)
  1835. {
  1836. EmitHighNarrow(context, () => context.Emit(OpCodes.Sub), round: false);
  1837. }
  1838. public static void Suqadd_S(ILEmitterCtx context)
  1839. {
  1840. EmitScalarSaturatingBinaryOpSx(context, SaturatingFlags.Accumulate);
  1841. }
  1842. public static void Suqadd_V(ILEmitterCtx context)
  1843. {
  1844. EmitVectorSaturatingBinaryOpSx(context, SaturatingFlags.Accumulate);
  1845. }
  1846. public static void Uaba_V(ILEmitterCtx context)
  1847. {
  1848. EmitVectorTernaryOpZx(context, () =>
  1849. {
  1850. context.Emit(OpCodes.Sub);
  1851. EmitAbs(context);
  1852. context.Emit(OpCodes.Add);
  1853. });
  1854. }
  1855. public static void Uabal_V(ILEmitterCtx context)
  1856. {
  1857. EmitVectorWidenRnRmTernaryOpZx(context, () =>
  1858. {
  1859. context.Emit(OpCodes.Sub);
  1860. EmitAbs(context);
  1861. context.Emit(OpCodes.Add);
  1862. });
  1863. }
  1864. public static void Uabd_V(ILEmitterCtx context)
  1865. {
  1866. EmitVectorBinaryOpZx(context, () =>
  1867. {
  1868. context.Emit(OpCodes.Sub);
  1869. EmitAbs(context);
  1870. });
  1871. }
  1872. public static void Uabdl_V(ILEmitterCtx context)
  1873. {
  1874. EmitVectorWidenRnRmBinaryOpZx(context, () =>
  1875. {
  1876. context.Emit(OpCodes.Sub);
  1877. EmitAbs(context);
  1878. });
  1879. }
  1880. public static void Uadalp_V(ILEmitterCtx context)
  1881. {
  1882. EmitAddLongPairwise(context, signed: false, accumulate: true);
  1883. }
  1884. public static void Uaddl_V(ILEmitterCtx context)
  1885. {
  1886. if (Optimizations.UseSse41)
  1887. {
  1888. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  1889. Type[] typesSrl = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], typeof(byte) };
  1890. Type[] typesCvt = new Type[] { VectorUIntTypesPerSizeLog2[op.Size] };
  1891. Type[] typesAdd = new Type[] { VectorUIntTypesPerSizeLog2[op.Size + 1],
  1892. VectorUIntTypesPerSizeLog2[op.Size + 1] };
  1893. string[] namesCvt = new string[] { nameof(Sse41.ConvertToVector128Int16),
  1894. nameof(Sse41.ConvertToVector128Int32),
  1895. nameof(Sse41.ConvertToVector128Int64) };
  1896. int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
  1897. EmitLdvecWithUnsignedCast(context, op.Rn, op.Size);
  1898. context.EmitLdc_I4(numBytes);
  1899. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
  1900. context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
  1901. EmitLdvecWithUnsignedCast(context, op.Rm, op.Size);
  1902. context.EmitLdc_I4(numBytes);
  1903. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
  1904. context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
  1905. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesAdd));
  1906. EmitStvecWithUnsignedCast(context, op.Rd, op.Size + 1);
  1907. }
  1908. else
  1909. {
  1910. EmitVectorWidenRnRmBinaryOpZx(context, () => context.Emit(OpCodes.Add));
  1911. }
  1912. }
  1913. public static void Uaddlp_V(ILEmitterCtx context)
  1914. {
  1915. EmitAddLongPairwise(context, signed: false, accumulate: false);
  1916. }
  1917. public static void Uaddlv_V(ILEmitterCtx context)
  1918. {
  1919. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  1920. int bytes = op.GetBitsCount() >> 3;
  1921. int elems = bytes >> op.Size;
  1922. EmitVectorExtractZx(context, op.Rn, 0, op.Size);
  1923. for (int index = 1; index < elems; index++)
  1924. {
  1925. EmitVectorExtractZx(context, op.Rn, index, op.Size);
  1926. context.Emit(OpCodes.Add);
  1927. }
  1928. EmitScalarSet(context, op.Rd, op.Size + 1);
  1929. }
  1930. public static void Uaddw_V(ILEmitterCtx context)
  1931. {
  1932. if (Optimizations.UseSse41)
  1933. {
  1934. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  1935. Type[] typesSrl = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], typeof(byte) };
  1936. Type[] typesCvt = new Type[] { VectorUIntTypesPerSizeLog2[op.Size] };
  1937. Type[] typesAdd = new Type[] { VectorUIntTypesPerSizeLog2[op.Size + 1],
  1938. VectorUIntTypesPerSizeLog2[op.Size + 1] };
  1939. string[] namesCvt = new string[] { nameof(Sse41.ConvertToVector128Int16),
  1940. nameof(Sse41.ConvertToVector128Int32),
  1941. nameof(Sse41.ConvertToVector128Int64) };
  1942. int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
  1943. EmitLdvecWithUnsignedCast(context, op.Rn, op.Size + 1);
  1944. EmitLdvecWithUnsignedCast(context, op.Rm, op.Size);
  1945. context.EmitLdc_I4(numBytes);
  1946. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
  1947. context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
  1948. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesAdd));
  1949. EmitStvecWithUnsignedCast(context, op.Rd, op.Size + 1);
  1950. }
  1951. else
  1952. {
  1953. EmitVectorWidenRmBinaryOpZx(context, () => context.Emit(OpCodes.Add));
  1954. }
  1955. }
  1956. public static void Uhadd_V(ILEmitterCtx context)
  1957. {
  1958. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  1959. if (Optimizations.UseSse2 && op.Size > 0)
  1960. {
  1961. Type[] typesSrl = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], typeof(byte) };
  1962. Type[] typesAndXorAdd = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], VectorUIntTypesPerSizeLog2[op.Size] };
  1963. EmitLdvecWithUnsignedCast(context, op.Rn, op.Size);
  1964. context.Emit(OpCodes.Dup);
  1965. context.EmitStvectmp();
  1966. EmitLdvecWithUnsignedCast(context, op.Rm, op.Size);
  1967. context.Emit(OpCodes.Dup);
  1968. context.EmitStvectmp2();
  1969. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.And), typesAndXorAdd));
  1970. context.EmitLdvectmp();
  1971. context.EmitLdvectmp2();
  1972. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Xor), typesAndXorAdd));
  1973. context.EmitLdc_I4(1);
  1974. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical), typesSrl));
  1975. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesAndXorAdd));
  1976. EmitStvecWithUnsignedCast(context, op.Rd, op.Size);
  1977. if (op.RegisterSize == RegisterSize.Simd64)
  1978. {
  1979. EmitVectorZeroUpper(context, op.Rd);
  1980. }
  1981. }
  1982. else
  1983. {
  1984. EmitVectorBinaryOpZx(context, () =>
  1985. {
  1986. context.Emit(OpCodes.Add);
  1987. context.Emit(OpCodes.Ldc_I4_1);
  1988. context.Emit(OpCodes.Shr_Un);
  1989. });
  1990. }
  1991. }
  1992. public static void Uhsub_V(ILEmitterCtx context)
  1993. {
  1994. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  1995. if (Optimizations.UseSse2 && op.Size < 2)
  1996. {
  1997. Type[] typesAvgSub = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], VectorUIntTypesPerSizeLog2[op.Size] };
  1998. EmitLdvecWithUnsignedCast(context, op.Rn, op.Size);
  1999. context.Emit(OpCodes.Dup);
  2000. EmitLdvecWithUnsignedCast(context, op.Rm, op.Size);
  2001. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Average), typesAvgSub));
  2002. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesAvgSub));
  2003. EmitStvecWithUnsignedCast(context, op.Rd, op.Size);
  2004. if (op.RegisterSize == RegisterSize.Simd64)
  2005. {
  2006. EmitVectorZeroUpper(context, op.Rd);
  2007. }
  2008. }
  2009. else
  2010. {
  2011. EmitVectorBinaryOpZx(context, () =>
  2012. {
  2013. context.Emit(OpCodes.Sub);
  2014. context.Emit(OpCodes.Ldc_I4_1);
  2015. context.Emit(OpCodes.Shr_Un);
  2016. });
  2017. }
  2018. }
  2019. public static void Umax_V(ILEmitterCtx context)
  2020. {
  2021. if (Optimizations.UseSse41)
  2022. {
  2023. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  2024. Type[] typesMax = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], VectorUIntTypesPerSizeLog2[op.Size] };
  2025. Type typeSse = op.Size == 0 ? typeof(Sse2) : typeof(Sse41);
  2026. EmitLdvecWithUnsignedCast(context, op.Rn, op.Size);
  2027. EmitLdvecWithUnsignedCast(context, op.Rm, op.Size);
  2028. context.EmitCall(typeSse.GetMethod(nameof(Sse2.Max), typesMax));
  2029. EmitStvecWithUnsignedCast(context, op.Rd, op.Size);
  2030. if (op.RegisterSize == RegisterSize.Simd64)
  2031. {
  2032. EmitVectorZeroUpper(context, op.Rd);
  2033. }
  2034. }
  2035. else
  2036. {
  2037. Type[] types = new Type[] { typeof(ulong), typeof(ulong) };
  2038. MethodInfo mthdInfo = typeof(Math).GetMethod(nameof(Math.Max), types);
  2039. EmitVectorBinaryOpZx(context, () => context.EmitCall(mthdInfo));
  2040. }
  2041. }
  2042. public static void Umaxp_V(ILEmitterCtx context)
  2043. {
  2044. Type[] types = new Type[] { typeof(ulong), typeof(ulong) };
  2045. MethodInfo mthdInfo = typeof(Math).GetMethod(nameof(Math.Max), types);
  2046. EmitVectorPairwiseOpZx(context, () => context.EmitCall(mthdInfo));
  2047. }
  2048. public static void Umin_V(ILEmitterCtx context)
  2049. {
  2050. if (Optimizations.UseSse41)
  2051. {
  2052. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  2053. Type[] typesMin = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], VectorUIntTypesPerSizeLog2[op.Size] };
  2054. Type typeSse = op.Size == 0 ? typeof(Sse2) : typeof(Sse41);
  2055. EmitLdvecWithUnsignedCast(context, op.Rn, op.Size);
  2056. EmitLdvecWithUnsignedCast(context, op.Rm, op.Size);
  2057. context.EmitCall(typeSse.GetMethod(nameof(Sse2.Min), typesMin));
  2058. EmitStvecWithUnsignedCast(context, op.Rd, op.Size);
  2059. if (op.RegisterSize == RegisterSize.Simd64)
  2060. {
  2061. EmitVectorZeroUpper(context, op.Rd);
  2062. }
  2063. }
  2064. else
  2065. {
  2066. Type[] types = new Type[] { typeof(ulong), typeof(ulong) };
  2067. MethodInfo mthdInfo = typeof(Math).GetMethod(nameof(Math.Min), types);
  2068. EmitVectorBinaryOpZx(context, () => context.EmitCall(mthdInfo));
  2069. }
  2070. }
  2071. public static void Uminp_V(ILEmitterCtx context)
  2072. {
  2073. Type[] types = new Type[] { typeof(ulong), typeof(ulong) };
  2074. MethodInfo mthdInfo = typeof(Math).GetMethod(nameof(Math.Min), types);
  2075. EmitVectorPairwiseOpZx(context, () => context.EmitCall(mthdInfo));
  2076. }
  2077. public static void Umlal_V(ILEmitterCtx context)
  2078. {
  2079. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  2080. if (Optimizations.UseSse41 && op.Size < 2)
  2081. {
  2082. Type[] typesSrl = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], typeof(byte) };
  2083. Type[] typesCvt = new Type[] { VectorUIntTypesPerSizeLog2[op.Size] };
  2084. Type[] typesMulAdd = new Type[] { VectorIntTypesPerSizeLog2 [op.Size + 1],
  2085. VectorIntTypesPerSizeLog2 [op.Size + 1] };
  2086. Type typeSse = op.Size == 0 ? typeof(Sse2) : typeof(Sse41);
  2087. string nameCvt = op.Size == 0
  2088. ? nameof(Sse41.ConvertToVector128Int16)
  2089. : nameof(Sse41.ConvertToVector128Int32);
  2090. int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
  2091. EmitLdvecWithUnsignedCast(context, op.Rd, op.Size + 1);
  2092. EmitLdvecWithUnsignedCast(context, op.Rn, op.Size);
  2093. context.EmitLdc_I4(numBytes);
  2094. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
  2095. context.EmitCall(typeof(Sse41).GetMethod(nameCvt, typesCvt));
  2096. EmitLdvecWithUnsignedCast(context, op.Rm, op.Size);
  2097. context.EmitLdc_I4(numBytes);
  2098. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
  2099. context.EmitCall(typeof(Sse41).GetMethod(nameCvt, typesCvt));
  2100. context.EmitCall(typeSse.GetMethod(nameof(Sse2.MultiplyLow), typesMulAdd));
  2101. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesMulAdd));
  2102. EmitStvecWithUnsignedCast(context, op.Rd, op.Size + 1);
  2103. }
  2104. else
  2105. {
  2106. EmitVectorWidenRnRmTernaryOpZx(context, () =>
  2107. {
  2108. context.Emit(OpCodes.Mul);
  2109. context.Emit(OpCodes.Add);
  2110. });
  2111. }
  2112. }
  2113. public static void Umlsl_V(ILEmitterCtx context)
  2114. {
  2115. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  2116. if (Optimizations.UseSse41 && op.Size < 2)
  2117. {
  2118. Type[] typesSrl = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], typeof(byte) };
  2119. Type[] typesCvt = new Type[] { VectorUIntTypesPerSizeLog2[op.Size] };
  2120. Type[] typesMulSub = new Type[] { VectorIntTypesPerSizeLog2 [op.Size + 1],
  2121. VectorIntTypesPerSizeLog2 [op.Size + 1] };
  2122. Type typeSse = op.Size == 0 ? typeof(Sse2) : typeof(Sse41);
  2123. string nameCvt = op.Size == 0
  2124. ? nameof(Sse41.ConvertToVector128Int16)
  2125. : nameof(Sse41.ConvertToVector128Int32);
  2126. int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
  2127. EmitLdvecWithUnsignedCast(context, op.Rd, op.Size + 1);
  2128. EmitLdvecWithUnsignedCast(context, op.Rn, op.Size);
  2129. context.EmitLdc_I4(numBytes);
  2130. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
  2131. context.EmitCall(typeof(Sse41).GetMethod(nameCvt, typesCvt));
  2132. EmitLdvecWithUnsignedCast(context, op.Rm, op.Size);
  2133. context.EmitLdc_I4(numBytes);
  2134. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
  2135. context.EmitCall(typeof(Sse41).GetMethod(nameCvt, typesCvt));
  2136. context.EmitCall(typeSse.GetMethod(nameof(Sse2.MultiplyLow), typesMulSub));
  2137. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesMulSub));
  2138. EmitStvecWithUnsignedCast(context, op.Rd, op.Size + 1);
  2139. }
  2140. else
  2141. {
  2142. EmitVectorWidenRnRmTernaryOpZx(context, () =>
  2143. {
  2144. context.Emit(OpCodes.Mul);
  2145. context.Emit(OpCodes.Sub);
  2146. });
  2147. }
  2148. }
  2149. public static void Umull_V(ILEmitterCtx context)
  2150. {
  2151. EmitVectorWidenRnRmBinaryOpZx(context, () => context.Emit(OpCodes.Mul));
  2152. }
  2153. public static void Uqadd_S(ILEmitterCtx context)
  2154. {
  2155. EmitScalarSaturatingBinaryOpZx(context, SaturatingFlags.Add);
  2156. }
  2157. public static void Uqadd_V(ILEmitterCtx context)
  2158. {
  2159. EmitVectorSaturatingBinaryOpZx(context, SaturatingFlags.Add);
  2160. }
  2161. public static void Uqsub_S(ILEmitterCtx context)
  2162. {
  2163. EmitScalarSaturatingBinaryOpZx(context, SaturatingFlags.Sub);
  2164. }
  2165. public static void Uqsub_V(ILEmitterCtx context)
  2166. {
  2167. EmitVectorSaturatingBinaryOpZx(context, SaturatingFlags.Sub);
  2168. }
  2169. public static void Uqxtn_S(ILEmitterCtx context)
  2170. {
  2171. EmitSaturatingNarrowOp(context, SaturatingNarrowFlags.ScalarZxZx);
  2172. }
  2173. public static void Uqxtn_V(ILEmitterCtx context)
  2174. {
  2175. EmitSaturatingNarrowOp(context, SaturatingNarrowFlags.VectorZxZx);
  2176. }
  2177. public static void Urhadd_V(ILEmitterCtx context)
  2178. {
  2179. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  2180. if (Optimizations.UseSse2 && op.Size < 2)
  2181. {
  2182. Type[] typesAvg = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], VectorUIntTypesPerSizeLog2[op.Size] };
  2183. EmitLdvecWithUnsignedCast(context, op.Rn, op.Size);
  2184. EmitLdvecWithUnsignedCast(context, op.Rm, op.Size);
  2185. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Average), typesAvg));
  2186. EmitStvecWithUnsignedCast(context, op.Rd, op.Size);
  2187. if (op.RegisterSize == RegisterSize.Simd64)
  2188. {
  2189. EmitVectorZeroUpper(context, op.Rd);
  2190. }
  2191. }
  2192. else
  2193. {
  2194. EmitVectorBinaryOpZx(context, () =>
  2195. {
  2196. context.Emit(OpCodes.Add);
  2197. context.Emit(OpCodes.Ldc_I4_1);
  2198. context.Emit(OpCodes.Add);
  2199. context.Emit(OpCodes.Ldc_I4_1);
  2200. context.Emit(OpCodes.Shr_Un);
  2201. });
  2202. }
  2203. }
  2204. public static void Usqadd_S(ILEmitterCtx context)
  2205. {
  2206. EmitScalarSaturatingBinaryOpZx(context, SaturatingFlags.Accumulate);
  2207. }
  2208. public static void Usqadd_V(ILEmitterCtx context)
  2209. {
  2210. EmitVectorSaturatingBinaryOpZx(context, SaturatingFlags.Accumulate);
  2211. }
  2212. public static void Usubl_V(ILEmitterCtx context)
  2213. {
  2214. if (Optimizations.UseSse41)
  2215. {
  2216. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  2217. Type[] typesSrl = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], typeof(byte) };
  2218. Type[] typesCvt = new Type[] { VectorUIntTypesPerSizeLog2[op.Size] };
  2219. Type[] typesSub = new Type[] { VectorUIntTypesPerSizeLog2[op.Size + 1],
  2220. VectorUIntTypesPerSizeLog2[op.Size + 1] };
  2221. string[] namesCvt = new string[] { nameof(Sse41.ConvertToVector128Int16),
  2222. nameof(Sse41.ConvertToVector128Int32),
  2223. nameof(Sse41.ConvertToVector128Int64) };
  2224. int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
  2225. EmitLdvecWithUnsignedCast(context, op.Rn, op.Size);
  2226. context.EmitLdc_I4(numBytes);
  2227. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
  2228. context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
  2229. EmitLdvecWithUnsignedCast(context, op.Rm, op.Size);
  2230. context.EmitLdc_I4(numBytes);
  2231. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
  2232. context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
  2233. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesSub));
  2234. EmitStvecWithUnsignedCast(context, op.Rd, op.Size + 1);
  2235. }
  2236. else
  2237. {
  2238. EmitVectorWidenRnRmBinaryOpZx(context, () => context.Emit(OpCodes.Sub));
  2239. }
  2240. }
  2241. public static void Usubw_V(ILEmitterCtx context)
  2242. {
  2243. if (Optimizations.UseSse41)
  2244. {
  2245. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  2246. Type[] typesSrl = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], typeof(byte) };
  2247. Type[] typesCvt = new Type[] { VectorUIntTypesPerSizeLog2[op.Size] };
  2248. Type[] typesSub = new Type[] { VectorUIntTypesPerSizeLog2[op.Size + 1],
  2249. VectorUIntTypesPerSizeLog2[op.Size + 1] };
  2250. string[] namesCvt = new string[] { nameof(Sse41.ConvertToVector128Int16),
  2251. nameof(Sse41.ConvertToVector128Int32),
  2252. nameof(Sse41.ConvertToVector128Int64) };
  2253. int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
  2254. EmitLdvecWithUnsignedCast(context, op.Rn, op.Size + 1);
  2255. EmitLdvecWithUnsignedCast(context, op.Rm, op.Size);
  2256. context.EmitLdc_I4(numBytes);
  2257. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
  2258. context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
  2259. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesSub));
  2260. EmitStvecWithUnsignedCast(context, op.Rd, op.Size + 1);
  2261. }
  2262. else
  2263. {
  2264. EmitVectorWidenRmBinaryOpZx(context, () => context.Emit(OpCodes.Sub));
  2265. }
  2266. }
  2267. private static void EmitAbs(ILEmitterCtx context)
  2268. {
  2269. ILLabel lblTrue = new ILLabel();
  2270. context.Emit(OpCodes.Dup);
  2271. context.Emit(OpCodes.Ldc_I4_0);
  2272. context.Emit(OpCodes.Bge_S, lblTrue);
  2273. context.Emit(OpCodes.Neg);
  2274. context.MarkLabel(lblTrue);
  2275. }
  2276. private static void EmitAddLongPairwise(ILEmitterCtx context, bool signed, bool accumulate)
  2277. {
  2278. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  2279. int words = op.GetBitsCount() >> 4;
  2280. int pairs = words >> op.Size;
  2281. for (int index = 0; index < pairs; index++)
  2282. {
  2283. int idx = index << 1;
  2284. EmitVectorExtract(context, op.Rn, idx, op.Size, signed);
  2285. EmitVectorExtract(context, op.Rn, idx + 1, op.Size, signed);
  2286. context.Emit(OpCodes.Add);
  2287. if (accumulate)
  2288. {
  2289. EmitVectorExtract(context, op.Rd, index, op.Size + 1, signed);
  2290. context.Emit(OpCodes.Add);
  2291. }
  2292. EmitVectorInsertTmp(context, index, op.Size + 1);
  2293. }
  2294. context.EmitLdvectmp();
  2295. context.EmitStvec(op.Rd);
  2296. if (op.RegisterSize == RegisterSize.Simd64)
  2297. {
  2298. EmitVectorZeroUpper(context, op.Rd);
  2299. }
  2300. }
  2301. private static void EmitDoublingMultiplyHighHalf(ILEmitterCtx context, bool round)
  2302. {
  2303. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  2304. int eSize = 8 << op.Size;
  2305. context.Emit(OpCodes.Mul);
  2306. if (!round)
  2307. {
  2308. context.EmitAsr(eSize - 1);
  2309. }
  2310. else
  2311. {
  2312. long roundConst = 1L << (eSize - 1);
  2313. ILLabel lblTrue = new ILLabel();
  2314. context.EmitLsl(1);
  2315. context.EmitLdc_I8(roundConst);
  2316. context.Emit(OpCodes.Add);
  2317. context.EmitAsr(eSize);
  2318. context.Emit(OpCodes.Dup);
  2319. context.EmitLdc_I8((long)int.MinValue);
  2320. context.Emit(OpCodes.Bne_Un_S, lblTrue);
  2321. context.Emit(OpCodes.Neg);
  2322. context.MarkLabel(lblTrue);
  2323. }
  2324. }
  2325. private static void EmitHighNarrow(ILEmitterCtx context, Action emit, bool round)
  2326. {
  2327. OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
  2328. int elems = 8 >> op.Size;
  2329. int eSize = 8 << op.Size;
  2330. int part = op.RegisterSize == RegisterSize.Simd128 ? elems : 0;
  2331. long roundConst = 1L << (eSize - 1);
  2332. if (part != 0)
  2333. {
  2334. context.EmitLdvec(op.Rd);
  2335. context.EmitStvectmp();
  2336. }
  2337. for (int index = 0; index < elems; index++)
  2338. {
  2339. EmitVectorExtractZx(context, op.Rn, index, op.Size + 1);
  2340. EmitVectorExtractZx(context, op.Rm, index, op.Size + 1);
  2341. emit();
  2342. if (round)
  2343. {
  2344. context.EmitLdc_I8(roundConst);
  2345. context.Emit(OpCodes.Add);
  2346. }
  2347. context.EmitLsr(eSize);
  2348. EmitVectorInsertTmp(context, part + index, op.Size);
  2349. }
  2350. context.EmitLdvectmp();
  2351. context.EmitStvec(op.Rd);
  2352. if (part == 0)
  2353. {
  2354. EmitVectorZeroUpper(context, op.Rd);
  2355. }
  2356. }
  2357. }
  2358. }