InstEmitSimdArithmetic.cs 130 KB

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