| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270 |
- // https://github.com/intel/ARM_NEON_2_x86_SSE/blob/master/NEON_2_SSE.h
- using ChocolArm64.Decoders;
- using ChocolArm64.State;
- using ChocolArm64.Translation;
- using System;
- using System.Reflection;
- using System.Reflection.Emit;
- using System.Runtime.Intrinsics;
- using System.Runtime.Intrinsics.X86;
- using static ChocolArm64.Instructions.InstEmitSimdHelper;
- namespace ChocolArm64.Instructions
- {
- static partial class InstEmit
- {
- public static void Abs_S(ILEmitterCtx context)
- {
- EmitScalarUnaryOpSx(context, () => EmitAbs(context));
- }
- public static void Abs_V(ILEmitterCtx context)
- {
- EmitVectorUnaryOpSx(context, () => EmitAbs(context));
- }
- public static void Add_S(ILEmitterCtx context)
- {
- EmitScalarBinaryOpZx(context, () => context.Emit(OpCodes.Add));
- }
- public static void Add_V(ILEmitterCtx context)
- {
- if (Optimizations.UseSse2)
- {
- EmitSse2Op(context, nameof(Sse2.Add));
- }
- else
- {
- EmitVectorBinaryOpZx(context, () => context.Emit(OpCodes.Add));
- }
- }
- public static void Addhn_V(ILEmitterCtx context)
- {
- EmitHighNarrow(context, () => context.Emit(OpCodes.Add), round: false);
- }
- public static void Addp_S(ILEmitterCtx context)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- EmitVectorExtractZx(context, op.Rn, 0, op.Size);
- EmitVectorExtractZx(context, op.Rn, 1, op.Size);
- context.Emit(OpCodes.Add);
- EmitScalarSet(context, op.Rd, op.Size);
- }
- public static void Addp_V(ILEmitterCtx context)
- {
- EmitVectorPairwiseOpZx(context, () => context.Emit(OpCodes.Add));
- }
- public static void Addv_V(ILEmitterCtx context)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- int bytes = op.GetBitsCount() >> 3;
- int elems = bytes >> op.Size;
- EmitVectorExtractZx(context, op.Rn, 0, op.Size);
- for (int index = 1; index < elems; index++)
- {
- EmitVectorExtractZx(context, op.Rn, index, op.Size);
- context.Emit(OpCodes.Add);
- }
- EmitScalarSet(context, op.Rd, op.Size);
- }
- public static void Cls_V(ILEmitterCtx context)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- int bytes = op.GetBitsCount() >> 3;
- int elems = bytes >> op.Size;
- int eSize = 8 << op.Size;
- for (int index = 0; index < elems; index++)
- {
- EmitVectorExtractZx(context, op.Rn, index, op.Size);
- context.EmitLdc_I4(eSize);
- SoftFallback.EmitCall(context, nameof(SoftFallback.CountLeadingSigns));
- EmitVectorInsert(context, op.Rd, index, op.Size);
- }
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- public static void Clz_V(ILEmitterCtx context)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- int bytes = op.GetBitsCount() >> 3;
- int elems = bytes >> op.Size;
- int eSize = 8 << op.Size;
- for (int index = 0; index < elems; index++)
- {
- EmitVectorExtractZx(context, op.Rn, index, op.Size);
- if (Lzcnt.IsSupported && eSize == 32)
- {
- context.Emit(OpCodes.Conv_U4);
- context.EmitCall(typeof(Lzcnt).GetMethod(nameof(Lzcnt.LeadingZeroCount), new Type[] { typeof(uint) }));
- context.Emit(OpCodes.Conv_U8);
- }
- else
- {
- context.EmitLdc_I4(eSize);
- SoftFallback.EmitCall(context, nameof(SoftFallback.CountLeadingZeros));
- }
- EmitVectorInsert(context, op.Rd, index, op.Size);
- }
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- public static void Cnt_V(ILEmitterCtx context)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- int elems = op.RegisterSize == RegisterSize.Simd128 ? 16 : 8;
- for (int index = 0; index < elems; index++)
- {
- EmitVectorExtractZx(context, op.Rn, index, 0);
- if (Popcnt.IsSupported)
- {
- context.EmitCall(typeof(Popcnt).GetMethod(nameof(Popcnt.PopCount), new Type[] { typeof(ulong) }));
- }
- else
- {
- SoftFallback.EmitCall(context, nameof(SoftFallback.CountSetBits8));
- }
- EmitVectorInsert(context, op.Rd, index, 0);
- }
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- public static void Fabd_S(ILEmitterCtx context)
- {
- if (Optimizations.FastFP && Optimizations.UseSse2)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- int sizeF = op.Size & 1;
- if (sizeF == 0)
- {
- Type[] typesSsv = new Type[] { typeof(float) };
- Type[] typesSubAndNot = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
- context.EmitLdc_R4(-0f);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetScalarVector128), typesSsv));
- context.EmitLdvec(op.Rn);
- context.EmitLdvec(op.Rm);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SubtractScalar), typesSubAndNot));
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.AndNot), typesSubAndNot));
- context.EmitStvec(op.Rd);
- EmitVectorZero32_128(context, op.Rd);
- }
- else /* if (sizeF == 1) */
- {
- Type[] typesSsv = new Type[] { typeof(double) };
- Type[] typesSubAndNot = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
- context.EmitLdc_R8(-0d);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetScalarVector128), typesSsv));
- EmitLdvecWithCastToDouble(context, op.Rn);
- EmitLdvecWithCastToDouble(context, op.Rm);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SubtractScalar), typesSubAndNot));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.AndNot), typesSubAndNot));
- EmitStvecWithCastFromDouble(context, op.Rd);
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else
- {
- EmitScalarBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPSub));
- EmitUnaryMathCall(context, nameof(Math.Abs));
- });
- }
- }
- public static void Fabd_V(ILEmitterCtx context)
- {
- if (Optimizations.FastFP && Optimizations.UseSse2)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- int sizeF = op.Size & 1;
- if (sizeF == 0)
- {
- Type[] typesSav = new Type[] { typeof(float) };
- Type[] typesSubAndNot = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
- context.EmitLdc_R4(-0f);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetAllVector128), typesSav));
- context.EmitLdvec(op.Rn);
- context.EmitLdvec(op.Rm);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Subtract), typesSubAndNot));
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.AndNot), typesSubAndNot));
- context.EmitStvec(op.Rd);
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else /* if (sizeF == 1) */
- {
- Type[] typesSav = new Type[] { typeof(double) };
- Type[] typesSubAndNot = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
- context.EmitLdc_R8(-0d);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
- EmitLdvecWithCastToDouble(context, op.Rn);
- EmitLdvecWithCastToDouble(context, op.Rm);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesSubAndNot));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.AndNot), typesSubAndNot));
- EmitStvecWithCastFromDouble(context, op.Rd);
- }
- }
- else
- {
- EmitVectorBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPSub));
- EmitUnaryMathCall(context, nameof(Math.Abs));
- });
- }
- }
- public static void Fabs_S(ILEmitterCtx context)
- {
- if (Optimizations.UseSse2)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- if (op.Size == 0)
- {
- Type[] typesSsv = new Type[] { typeof(float) };
- Type[] typesAndNot = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
- context.EmitLdc_R4(-0f);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetScalarVector128), typesSsv));
- context.EmitLdvec(op.Rn);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.AndNot), typesAndNot));
- context.EmitStvec(op.Rd);
- EmitVectorZero32_128(context, op.Rd);
- }
- else /* if (op.Size == 1) */
- {
- Type[] typesSsv = new Type[] { typeof(double) };
- Type[] typesAndNot = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
- context.EmitLdc_R8(-0d);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetScalarVector128), typesSsv));
- EmitLdvecWithCastToDouble(context, op.Rn);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.AndNot), typesAndNot));
- EmitStvecWithCastFromDouble(context, op.Rd);
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else
- {
- EmitScalarUnaryOpF(context, () =>
- {
- EmitUnaryMathCall(context, nameof(Math.Abs));
- });
- }
- }
- public static void Fabs_V(ILEmitterCtx context)
- {
- if (Optimizations.UseSse2)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- int sizeF = op.Size & 1;
- if (sizeF == 0)
- {
- Type[] typesSav = new Type[] { typeof(float) };
- Type[] typesAndNot = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
- context.EmitLdc_R4(-0f);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetAllVector128), typesSav));
- context.EmitLdvec(op.Rn);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.AndNot), typesAndNot));
- context.EmitStvec(op.Rd);
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else /* if (sizeF == 1) */
- {
- Type[] typesSav = new Type[] { typeof(double) };
- Type[] typesAndNot = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
- context.EmitLdc_R8(-0d);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
- EmitLdvecWithCastToDouble(context, op.Rn);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.AndNot), typesAndNot));
- EmitStvecWithCastFromDouble(context, op.Rd);
- }
- }
- else
- {
- EmitVectorUnaryOpF(context, () =>
- {
- EmitUnaryMathCall(context, nameof(Math.Abs));
- });
- }
- }
- public static void Fadd_S(ILEmitterCtx context)
- {
- if (Optimizations.FastFP && Optimizations.UseSse
- && Optimizations.UseSse2)
- {
- EmitScalarSseOrSse2OpF(context, nameof(Sse.AddScalar));
- }
- else
- {
- EmitScalarBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPAdd));
- });
- }
- }
- public static void Fadd_V(ILEmitterCtx context)
- {
- if (Optimizations.FastFP && Optimizations.UseSse
- && Optimizations.UseSse2)
- {
- EmitVectorSseOrSse2OpF(context, nameof(Sse.Add));
- }
- else
- {
- EmitVectorBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPAdd));
- });
- }
- }
- public static void Faddp_S(ILEmitterCtx context)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- int sizeF = op.Size & 1;
- if (Optimizations.FastFP && Optimizations.UseSse3)
- {
- if (sizeF == 0)
- {
- Type[] typesAddH = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
- context.EmitLdvec(op.Rn);
- context.Emit(OpCodes.Dup);
- context.EmitCall(typeof(Sse3).GetMethod(nameof(Sse3.HorizontalAdd), typesAddH));
- context.EmitStvec(op.Rd);
- EmitVectorZero32_128(context, op.Rd);
- }
- else /* if (sizeF == 1) */
- {
- Type[] typesAddH = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
- EmitLdvecWithCastToDouble(context, op.Rn);
- context.Emit(OpCodes.Dup);
- context.EmitCall(typeof(Sse3).GetMethod(nameof(Sse3.HorizontalAdd), typesAddH));
- EmitStvecWithCastFromDouble(context, op.Rd);
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else
- {
- EmitVectorExtractF(context, op.Rn, 0, sizeF);
- EmitVectorExtractF(context, op.Rn, 1, sizeF);
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPAdd));
- EmitScalarSetF(context, op.Rd, sizeF);
- }
- }
- public static void Faddp_V(ILEmitterCtx context)
- {
- if (Optimizations.FastFP && Optimizations.UseSse
- && Optimizations.UseSse2)
- {
- EmitVectorPairwiseSseOrSse2OpF(context, nameof(Sse.Add));
- }
- else
- {
- EmitVectorPairwiseOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPAdd));
- });
- }
- }
- public static void Fdiv_S(ILEmitterCtx context)
- {
- if (Optimizations.FastFP && Optimizations.UseSse
- && Optimizations.UseSse2)
- {
- EmitScalarSseOrSse2OpF(context, nameof(Sse.DivideScalar));
- }
- else
- {
- EmitScalarBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPDiv));
- });
- }
- }
- public static void Fdiv_V(ILEmitterCtx context)
- {
- if (Optimizations.FastFP && Optimizations.UseSse
- && Optimizations.UseSse2)
- {
- EmitVectorSseOrSse2OpF(context, nameof(Sse.Divide));
- }
- else
- {
- EmitVectorBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPDiv));
- });
- }
- }
- public static void Fmadd_S(ILEmitterCtx context) // Fused.
- {
- if (Optimizations.FastFP && Optimizations.UseSse2)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- if (op.Size == 0)
- {
- Type[] typesMulAdd = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
- context.EmitLdvec(op.Ra);
- context.EmitLdvec(op.Rn);
- context.EmitLdvec(op.Rm);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.MultiplyScalar), typesMulAdd));
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.AddScalar), typesMulAdd));
- context.EmitStvec(op.Rd);
- EmitVectorZero32_128(context, op.Rd);
- }
- else /* if (op.Size == 1) */
- {
- Type[] typesMulAdd = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
- EmitLdvecWithCastToDouble(context, op.Ra);
- EmitLdvecWithCastToDouble(context, op.Rn);
- EmitLdvecWithCastToDouble(context, op.Rm);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.MultiplyScalar), typesMulAdd));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.AddScalar), typesMulAdd));
- EmitStvecWithCastFromDouble(context, op.Rd);
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else
- {
- EmitScalarTernaryRaOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMulAdd));
- });
- }
- }
- public static void Fmax_S(ILEmitterCtx context)
- {
- if (Optimizations.FastFP && Optimizations.UseSse
- && Optimizations.UseSse2)
- {
- EmitScalarSseOrSse2OpF(context, nameof(Sse.MaxScalar));
- }
- else
- {
- EmitScalarBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMax));
- });
- }
- }
- public static void Fmax_V(ILEmitterCtx context)
- {
- if (Optimizations.FastFP && Optimizations.UseSse
- && Optimizations.UseSse2)
- {
- EmitVectorSseOrSse2OpF(context, nameof(Sse.Max));
- }
- else
- {
- EmitVectorBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMax));
- });
- }
- }
- public static void Fmaxnm_S(ILEmitterCtx context)
- {
- EmitScalarBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMaxNum));
- });
- }
- public static void Fmaxnm_V(ILEmitterCtx context)
- {
- EmitVectorBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMaxNum));
- });
- }
- public static void Fmaxp_V(ILEmitterCtx context)
- {
- if (Optimizations.FastFP && Optimizations.UseSse
- && Optimizations.UseSse2)
- {
- EmitVectorPairwiseSseOrSse2OpF(context, nameof(Sse.Max));
- }
- else
- {
- EmitVectorPairwiseOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMax));
- });
- }
- }
- public static void Fmin_S(ILEmitterCtx context)
- {
- if (Optimizations.FastFP && Optimizations.UseSse
- && Optimizations.UseSse2)
- {
- EmitScalarSseOrSse2OpF(context, nameof(Sse.MinScalar));
- }
- else
- {
- EmitScalarBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMin));
- });
- }
- }
- public static void Fmin_V(ILEmitterCtx context)
- {
- if (Optimizations.FastFP && Optimizations.UseSse
- && Optimizations.UseSse2)
- {
- EmitVectorSseOrSse2OpF(context, nameof(Sse.Min));
- }
- else
- {
- EmitVectorBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMin));
- });
- }
- }
- public static void Fminnm_S(ILEmitterCtx context)
- {
- EmitScalarBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMinNum));
- });
- }
- public static void Fminnm_V(ILEmitterCtx context)
- {
- EmitVectorBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMinNum));
- });
- }
- public static void Fminp_V(ILEmitterCtx context)
- {
- if (Optimizations.FastFP && Optimizations.UseSse
- && Optimizations.UseSse2)
- {
- EmitVectorPairwiseSseOrSse2OpF(context, nameof(Sse.Min));
- }
- else
- {
- EmitVectorPairwiseOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMin));
- });
- }
- }
- public static void Fmla_Se(ILEmitterCtx context)
- {
- EmitScalarTernaryOpByElemF(context, () =>
- {
- context.Emit(OpCodes.Mul);
- context.Emit(OpCodes.Add);
- });
- }
- public static void Fmla_V(ILEmitterCtx context) // Fused.
- {
- if (Optimizations.FastFP && Optimizations.UseSse2)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- int sizeF = op.Size & 1;
- if (sizeF == 0)
- {
- Type[] typesMulAdd = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
- context.EmitLdvec(op.Rd);
- context.EmitLdvec(op.Rn);
- context.EmitLdvec(op.Rm);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), typesMulAdd));
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Add), typesMulAdd));
- context.EmitStvec(op.Rd);
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else /* if (sizeF == 1) */
- {
- Type[] typesMulAdd = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
- EmitLdvecWithCastToDouble(context, op.Rd);
- EmitLdvecWithCastToDouble(context, op.Rn);
- EmitLdvecWithCastToDouble(context, op.Rm);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), typesMulAdd));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesMulAdd));
- EmitStvecWithCastFromDouble(context, op.Rd);
- }
- }
- else
- {
- EmitVectorTernaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMulAdd));
- });
- }
- }
- public static void Fmla_Ve(ILEmitterCtx context) // Fused.
- {
- if (Optimizations.FastFP && Optimizations.UseSse2)
- {
- OpCodeSimdRegElemF64 op = (OpCodeSimdRegElemF64)context.CurrOp;
- int sizeF = op.Size & 1;
- if (sizeF == 0)
- {
- Type[] typesSfl = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>), typeof(byte) };
- Type[] typesMulAdd = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
- context.EmitLdvec(op.Rd);
- context.EmitLdvec(op.Rn);
- context.EmitLdvec(op.Rm);
- context.Emit(OpCodes.Dup);
- context.EmitLdc_I4(op.Index | op.Index << 2 | op.Index << 4 | op.Index << 6);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Shuffle), typesSfl));
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), typesMulAdd));
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Add), typesMulAdd));
- context.EmitStvec(op.Rd);
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else /* if (sizeF == 1) */
- {
- Type[] typesSfl = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>), typeof(byte) };
- Type[] typesMulAdd = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
- EmitLdvecWithCastToDouble(context, op.Rd);
- EmitLdvecWithCastToDouble(context, op.Rn);
- EmitLdvecWithCastToDouble(context, op.Rm);
- context.Emit(OpCodes.Dup);
- context.EmitLdc_I4(op.Index | op.Index << 1);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), typesSfl));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), typesMulAdd));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesMulAdd));
- EmitStvecWithCastFromDouble(context, op.Rd);
- }
- }
- else
- {
- EmitVectorTernaryOpByElemF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMulAdd));
- });
- }
- }
- public static void Fmls_Se(ILEmitterCtx context)
- {
- EmitScalarTernaryOpByElemF(context, () =>
- {
- context.Emit(OpCodes.Mul);
- context.Emit(OpCodes.Sub);
- });
- }
- public static void Fmls_V(ILEmitterCtx context) // Fused.
- {
- if (Optimizations.FastFP && Optimizations.UseSse2)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- int sizeF = op.Size & 1;
- if (sizeF == 0)
- {
- Type[] typesMulSub = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
- context.EmitLdvec(op.Rd);
- context.EmitLdvec(op.Rn);
- context.EmitLdvec(op.Rm);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), typesMulSub));
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Subtract), typesMulSub));
- context.EmitStvec(op.Rd);
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else /* if (sizeF == 1) */
- {
- Type[] typesMulSub = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
- EmitLdvecWithCastToDouble(context, op.Rd);
- EmitLdvecWithCastToDouble(context, op.Rn);
- EmitLdvecWithCastToDouble(context, op.Rm);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), typesMulSub));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesMulSub));
- EmitStvecWithCastFromDouble(context, op.Rd);
- }
- }
- else
- {
- EmitVectorTernaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMulSub));
- });
- }
- }
- public static void Fmls_Ve(ILEmitterCtx context) // Fused.
- {
- if (Optimizations.FastFP && Optimizations.UseSse2)
- {
- OpCodeSimdRegElemF64 op = (OpCodeSimdRegElemF64)context.CurrOp;
- int sizeF = op.Size & 1;
- if (sizeF == 0)
- {
- Type[] typesSfl = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>), typeof(byte) };
- Type[] typesMulSub = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
- context.EmitLdvec(op.Rd);
- context.EmitLdvec(op.Rn);
- context.EmitLdvec(op.Rm);
- context.Emit(OpCodes.Dup);
- context.EmitLdc_I4(op.Index | op.Index << 2 | op.Index << 4 | op.Index << 6);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Shuffle), typesSfl));
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), typesMulSub));
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Subtract), typesMulSub));
- context.EmitStvec(op.Rd);
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else /* if (sizeF == 1) */
- {
- Type[] typesSfl = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>), typeof(byte) };
- Type[] typesMulSub = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
- EmitLdvecWithCastToDouble(context, op.Rd);
- EmitLdvecWithCastToDouble(context, op.Rn);
- EmitLdvecWithCastToDouble(context, op.Rm);
- context.Emit(OpCodes.Dup);
- context.EmitLdc_I4(op.Index | op.Index << 1);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), typesSfl));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), typesMulSub));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesMulSub));
- EmitStvecWithCastFromDouble(context, op.Rd);
- }
- }
- else
- {
- EmitVectorTernaryOpByElemF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMulSub));
- });
- }
- }
- public static void Fmsub_S(ILEmitterCtx context) // Fused.
- {
- if (Optimizations.FastFP && Optimizations.UseSse2)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- if (op.Size == 0)
- {
- Type[] typesMulSub = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
- context.EmitLdvec(op.Ra);
- context.EmitLdvec(op.Rn);
- context.EmitLdvec(op.Rm);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.MultiplyScalar), typesMulSub));
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SubtractScalar), typesMulSub));
- context.EmitStvec(op.Rd);
- EmitVectorZero32_128(context, op.Rd);
- }
- else /* if (op.Size == 1) */
- {
- Type[] typesMulSub = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
- EmitLdvecWithCastToDouble(context, op.Ra);
- EmitLdvecWithCastToDouble(context, op.Rn);
- EmitLdvecWithCastToDouble(context, op.Rm);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.MultiplyScalar), typesMulSub));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SubtractScalar), typesMulSub));
- EmitStvecWithCastFromDouble(context, op.Rd);
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else
- {
- EmitScalarTernaryRaOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMulSub));
- });
- }
- }
- public static void Fmul_S(ILEmitterCtx context)
- {
- if (Optimizations.FastFP && Optimizations.UseSse
- && Optimizations.UseSse2)
- {
- EmitScalarSseOrSse2OpF(context, nameof(Sse.MultiplyScalar));
- }
- else
- {
- EmitScalarBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMul));
- });
- }
- }
- public static void Fmul_Se(ILEmitterCtx context)
- {
- EmitScalarBinaryOpByElemF(context, () => context.Emit(OpCodes.Mul));
- }
- public static void Fmul_V(ILEmitterCtx context)
- {
- if (Optimizations.FastFP && Optimizations.UseSse
- && Optimizations.UseSse2)
- {
- EmitVectorSseOrSse2OpF(context, nameof(Sse.Multiply));
- }
- else
- {
- EmitVectorBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMul));
- });
- }
- }
- public static void Fmul_Ve(ILEmitterCtx context)
- {
- if (Optimizations.FastFP && Optimizations.UseSse2)
- {
- OpCodeSimdRegElemF64 op = (OpCodeSimdRegElemF64)context.CurrOp;
- int sizeF = op.Size & 1;
- if (sizeF == 0)
- {
- Type[] typesSfl = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>), typeof(byte) };
- Type[] typesMul = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
- context.EmitLdvec(op.Rn);
- context.EmitLdvec(op.Rm);
- context.Emit(OpCodes.Dup);
- context.EmitLdc_I4(op.Index | op.Index << 2 | op.Index << 4 | op.Index << 6);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Shuffle), typesSfl));
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), typesMul));
- context.EmitStvec(op.Rd);
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else /* if (sizeF == 1) */
- {
- Type[] typesSfl = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>), typeof(byte) };
- Type[] typesMul = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
- EmitLdvecWithCastToDouble(context, op.Rn);
- EmitLdvecWithCastToDouble(context, op.Rm);
- context.Emit(OpCodes.Dup);
- context.EmitLdc_I4(op.Index | op.Index << 1);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), typesSfl));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), typesMul));
- EmitStvecWithCastFromDouble(context, op.Rd);
- }
- }
- else
- {
- EmitVectorBinaryOpByElemF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMul));
- });
- }
- }
- public static void Fmulx_S(ILEmitterCtx context)
- {
- EmitScalarBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMulX));
- });
- }
- public static void Fmulx_Se(ILEmitterCtx context)
- {
- EmitScalarBinaryOpByElemF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMulX));
- });
- }
- public static void Fmulx_V(ILEmitterCtx context)
- {
- EmitVectorBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMulX));
- });
- }
- public static void Fmulx_Ve(ILEmitterCtx context)
- {
- EmitVectorBinaryOpByElemF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPMulX));
- });
- }
- public static void Fneg_S(ILEmitterCtx context)
- {
- if (Optimizations.UseSse2)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- if (op.Size == 0)
- {
- Type[] typesSsv = new Type[] { typeof(float) };
- Type[] typesXor = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
- context.EmitLdc_R4(-0f);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetScalarVector128), typesSsv));
- context.EmitLdvec(op.Rn);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Xor), typesXor));
- context.EmitStvec(op.Rd);
- EmitVectorZero32_128(context, op.Rd);
- }
- else /* if (op.Size == 1) */
- {
- Type[] typesSsv = new Type[] { typeof(double) };
- Type[] typesXor = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
- context.EmitLdc_R8(-0d);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetScalarVector128), typesSsv));
- EmitLdvecWithCastToDouble(context, op.Rn);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Xor), typesXor));
- EmitStvecWithCastFromDouble(context, op.Rd);
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else
- {
- EmitScalarUnaryOpF(context, () => context.Emit(OpCodes.Neg));
- }
- }
- public static void Fneg_V(ILEmitterCtx context)
- {
- if (Optimizations.UseSse2)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- int sizeF = op.Size & 1;
- if (sizeF == 0)
- {
- Type[] typesSav = new Type[] { typeof(float) };
- Type[] typesXor = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
- context.EmitLdc_R4(-0f);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetAllVector128), typesSav));
- context.EmitLdvec(op.Rn);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Xor), typesXor));
- context.EmitStvec(op.Rd);
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else /* if (sizeF == 1) */
- {
- Type[] typesSav = new Type[] { typeof(double) };
- Type[] typesXor = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
- context.EmitLdc_R8(-0d);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
- EmitLdvecWithCastToDouble(context, op.Rn);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Xor), typesXor));
- EmitStvecWithCastFromDouble(context, op.Rd);
- }
- }
- else
- {
- EmitVectorUnaryOpF(context, () => context.Emit(OpCodes.Neg));
- }
- }
- public static void Fnmadd_S(ILEmitterCtx context)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- int sizeF = op.Size & 1;
- EmitVectorExtractF(context, op.Rn, 0, sizeF);
- context.Emit(OpCodes.Neg);
- EmitVectorExtractF(context, op.Rm, 0, sizeF);
- context.Emit(OpCodes.Mul);
- EmitVectorExtractF(context, op.Ra, 0, sizeF);
- context.Emit(OpCodes.Sub);
- EmitScalarSetF(context, op.Rd, sizeF);
- }
- public static void Fnmsub_S(ILEmitterCtx context)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- int sizeF = op.Size & 1;
- EmitVectorExtractF(context, op.Rn, 0, sizeF);
- EmitVectorExtractF(context, op.Rm, 0, sizeF);
- context.Emit(OpCodes.Mul);
- EmitVectorExtractF(context, op.Ra, 0, sizeF);
- context.Emit(OpCodes.Sub);
- EmitScalarSetF(context, op.Rd, sizeF);
- }
- public static void Fnmul_S(ILEmitterCtx context)
- {
- EmitScalarBinaryOpF(context, () =>
- {
- context.Emit(OpCodes.Mul);
- context.Emit(OpCodes.Neg);
- });
- }
- public static void Frecpe_S(ILEmitterCtx context)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- int sizeF = op.Size & 1;
- if (Optimizations.FastFP && Optimizations.UseSse
- && sizeF == 0)
- {
- EmitScalarSseOrSse2OpF(context, nameof(Sse.ReciprocalScalar));
- }
- else
- {
- EmitScalarUnaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPRecipEstimate));
- });
- }
- }
- public static void Frecpe_V(ILEmitterCtx context)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- int sizeF = op.Size & 1;
- if (Optimizations.FastFP && Optimizations.UseSse
- && sizeF == 0)
- {
- EmitVectorSseOrSse2OpF(context, nameof(Sse.Reciprocal));
- }
- else
- {
- EmitVectorUnaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPRecipEstimate));
- });
- }
- }
- public static void Frecps_S(ILEmitterCtx context) // Fused.
- {
- if (Optimizations.FastFP && Optimizations.UseSse2)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- int sizeF = op.Size & 1;
- if (sizeF == 0)
- {
- Type[] typesSsv = new Type[] { typeof(float) };
- Type[] typesMulSub = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
- context.EmitLdc_R4(2f);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetScalarVector128), typesSsv));
- context.EmitLdvec(op.Rn);
- context.EmitLdvec(op.Rm);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.MultiplyScalar), typesMulSub));
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SubtractScalar), typesMulSub));
- context.EmitStvec(op.Rd);
- EmitVectorZero32_128(context, op.Rd);
- }
- else /* if (sizeF == 1) */
- {
- Type[] typesSsv = new Type[] { typeof(double) };
- Type[] typesMulSub = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
- context.EmitLdc_R8(2d);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetScalarVector128), typesSsv));
- EmitLdvecWithCastToDouble(context, op.Rn);
- EmitLdvecWithCastToDouble(context, op.Rm);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.MultiplyScalar), typesMulSub));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SubtractScalar), typesMulSub));
- EmitStvecWithCastFromDouble(context, op.Rd);
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else
- {
- EmitScalarBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPRecipStepFused));
- });
- }
- }
- public static void Frecps_V(ILEmitterCtx context) // Fused.
- {
- if (Optimizations.FastFP && Optimizations.UseSse2)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- int sizeF = op.Size & 1;
- if (sizeF == 0)
- {
- Type[] typesSav = new Type[] { typeof(float) };
- Type[] typesMulSub = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
- context.EmitLdc_R4(2f);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetAllVector128), typesSav));
- context.EmitLdvec(op.Rn);
- context.EmitLdvec(op.Rm);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), typesMulSub));
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Subtract), typesMulSub));
- context.EmitStvec(op.Rd);
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else /* if (sizeF == 1) */
- {
- Type[] typesSav = new Type[] { typeof(double) };
- Type[] typesMulSub = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
- context.EmitLdc_R8(2d);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
- EmitLdvecWithCastToDouble(context, op.Rn);
- EmitLdvecWithCastToDouble(context, op.Rm);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), typesMulSub));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesMulSub));
- EmitStvecWithCastFromDouble(context, op.Rd);
- }
- }
- else
- {
- EmitVectorBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPRecipStepFused));
- });
- }
- }
- public static void Frecpx_S(ILEmitterCtx context)
- {
- EmitScalarUnaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPRecpX));
- });
- }
- public static void Frinta_S(ILEmitterCtx context)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- EmitVectorExtractF(context, op.Rn, 0, op.Size);
- EmitRoundMathCall(context, MidpointRounding.AwayFromZero);
- EmitScalarSetF(context, op.Rd, op.Size);
- }
- public static void Frinta_V(ILEmitterCtx context)
- {
- EmitVectorUnaryOpF(context, () =>
- {
- EmitRoundMathCall(context, MidpointRounding.AwayFromZero);
- });
- }
- public static void Frinti_S(ILEmitterCtx context)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- EmitScalarUnaryOpF(context, () =>
- {
- context.EmitLdarg(TranslatedSub.StateArgIdx);
- if (op.Size == 0)
- {
- VectorHelper.EmitCall(context, nameof(VectorHelper.RoundF));
- }
- else if (op.Size == 1)
- {
- VectorHelper.EmitCall(context, nameof(VectorHelper.Round));
- }
- else
- {
- throw new InvalidOperationException();
- }
- });
- }
- public static void Frinti_V(ILEmitterCtx context)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- int sizeF = op.Size & 1;
- EmitVectorUnaryOpF(context, () =>
- {
- context.EmitLdarg(TranslatedSub.StateArgIdx);
- if (sizeF == 0)
- {
- VectorHelper.EmitCall(context, nameof(VectorHelper.RoundF));
- }
- else if (sizeF == 1)
- {
- VectorHelper.EmitCall(context, nameof(VectorHelper.Round));
- }
- else
- {
- throw new InvalidOperationException();
- }
- });
- }
- public static void Frintm_S(ILEmitterCtx context)
- {
- EmitScalarUnaryOpF(context, () =>
- {
- EmitUnaryMathCall(context, nameof(Math.Floor));
- });
- }
- public static void Frintm_V(ILEmitterCtx context)
- {
- EmitVectorUnaryOpF(context, () =>
- {
- EmitUnaryMathCall(context, nameof(Math.Floor));
- });
- }
- public static void Frintn_S(ILEmitterCtx context)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- EmitVectorExtractF(context, op.Rn, 0, op.Size);
- EmitRoundMathCall(context, MidpointRounding.ToEven);
- EmitScalarSetF(context, op.Rd, op.Size);
- }
- public static void Frintn_V(ILEmitterCtx context)
- {
- EmitVectorUnaryOpF(context, () =>
- {
- EmitRoundMathCall(context, MidpointRounding.ToEven);
- });
- }
- public static void Frintp_S(ILEmitterCtx context)
- {
- EmitScalarUnaryOpF(context, () =>
- {
- EmitUnaryMathCall(context, nameof(Math.Ceiling));
- });
- }
- public static void Frintp_V(ILEmitterCtx context)
- {
- EmitVectorUnaryOpF(context, () =>
- {
- EmitUnaryMathCall(context, nameof(Math.Ceiling));
- });
- }
- public static void Frintx_S(ILEmitterCtx context)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- EmitScalarUnaryOpF(context, () =>
- {
- context.EmitLdarg(TranslatedSub.StateArgIdx);
- if (op.Size == 0)
- {
- VectorHelper.EmitCall(context, nameof(VectorHelper.RoundF));
- }
- else if (op.Size == 1)
- {
- VectorHelper.EmitCall(context, nameof(VectorHelper.Round));
- }
- else
- {
- throw new InvalidOperationException();
- }
- });
- }
- public static void Frintx_V(ILEmitterCtx context)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- EmitVectorUnaryOpF(context, () =>
- {
- context.EmitLdarg(TranslatedSub.StateArgIdx);
- if (op.Size == 0)
- {
- VectorHelper.EmitCall(context, nameof(VectorHelper.RoundF));
- }
- else if (op.Size == 1)
- {
- VectorHelper.EmitCall(context, nameof(VectorHelper.Round));
- }
- else
- {
- throw new InvalidOperationException();
- }
- });
- }
- public static void Frintz_S(ILEmitterCtx context)
- {
- EmitScalarUnaryOpF(context, () =>
- {
- EmitUnaryMathCall(context, nameof(Math.Truncate));
- });
- }
- public static void Frintz_V(ILEmitterCtx context)
- {
- EmitVectorUnaryOpF(context, () =>
- {
- EmitUnaryMathCall(context, nameof(Math.Truncate));
- });
- }
- public static void Frsqrte_S(ILEmitterCtx context)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- int sizeF = op.Size & 1;
- if (Optimizations.FastFP && Optimizations.UseSse
- && sizeF == 0)
- {
- EmitScalarSseOrSse2OpF(context, nameof(Sse.ReciprocalSqrtScalar));
- }
- else
- {
- EmitScalarUnaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPRSqrtEstimate));
- });
- }
- }
- public static void Frsqrte_V(ILEmitterCtx context)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- int sizeF = op.Size & 1;
- if (Optimizations.FastFP && Optimizations.UseSse
- && sizeF == 0)
- {
- EmitVectorSseOrSse2OpF(context, nameof(Sse.ReciprocalSqrt));
- }
- else
- {
- EmitVectorUnaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPRSqrtEstimate));
- });
- }
- }
- public static void Frsqrts_S(ILEmitterCtx context) // Fused.
- {
- if (Optimizations.FastFP && Optimizations.UseSse2)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- int sizeF = op.Size & 1;
- if (sizeF == 0)
- {
- Type[] typesSsv = new Type[] { typeof(float) };
- Type[] typesMulSub = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
- context.EmitLdc_R4(0.5f);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetScalarVector128), typesSsv));
- context.EmitLdc_R4(3f);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetScalarVector128), typesSsv));
- context.EmitLdvec(op.Rn);
- context.EmitLdvec(op.Rm);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.MultiplyScalar), typesMulSub));
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SubtractScalar), typesMulSub));
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.MultiplyScalar), typesMulSub));
- context.EmitStvec(op.Rd);
- EmitVectorZero32_128(context, op.Rd);
- }
- else /* if (sizeF == 1) */
- {
- Type[] typesSsv = new Type[] { typeof(double) };
- Type[] typesMulSub = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
- context.EmitLdc_R8(0.5d);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetScalarVector128), typesSsv));
- context.EmitLdc_R8(3d);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetScalarVector128), typesSsv));
- EmitLdvecWithCastToDouble(context, op.Rn);
- EmitLdvecWithCastToDouble(context, op.Rm);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.MultiplyScalar), typesMulSub));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SubtractScalar), typesMulSub));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.MultiplyScalar), typesMulSub));
- EmitStvecWithCastFromDouble(context, op.Rd);
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else
- {
- EmitScalarBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPRSqrtStepFused));
- });
- }
- }
- public static void Frsqrts_V(ILEmitterCtx context) // Fused.
- {
- if (Optimizations.FastFP && Optimizations.UseSse2)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- int sizeF = op.Size & 1;
- if (sizeF == 0)
- {
- Type[] typesSav = new Type[] { typeof(float) };
- Type[] typesMulSub = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
- context.EmitLdc_R4(0.5f);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetAllVector128), typesSav));
- context.EmitLdc_R4(3f);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetAllVector128), typesSav));
- context.EmitLdvec(op.Rn);
- context.EmitLdvec(op.Rm);
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), typesMulSub));
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Subtract), typesMulSub));
- context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), typesMulSub));
- context.EmitStvec(op.Rd);
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else /* if (sizeF == 1) */
- {
- Type[] typesSav = new Type[] { typeof(double) };
- Type[] typesMulSub = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
- context.EmitLdc_R8(0.5d);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
- context.EmitLdc_R8(3d);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
- EmitLdvecWithCastToDouble(context, op.Rn);
- EmitLdvecWithCastToDouble(context, op.Rm);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), typesMulSub));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesMulSub));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), typesMulSub));
- EmitStvecWithCastFromDouble(context, op.Rd);
- }
- }
- else
- {
- EmitVectorBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPRSqrtStepFused));
- });
- }
- }
- public static void Fsqrt_S(ILEmitterCtx context)
- {
- if (Optimizations.FastFP && Optimizations.UseSse
- && Optimizations.UseSse2)
- {
- EmitScalarSseOrSse2OpF(context, nameof(Sse.SqrtScalar));
- }
- else
- {
- EmitScalarUnaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPSqrt));
- });
- }
- }
- public static void Fsqrt_V(ILEmitterCtx context)
- {
- if (Optimizations.FastFP && Optimizations.UseSse
- && Optimizations.UseSse2)
- {
- EmitVectorSseOrSse2OpF(context, nameof(Sse.Sqrt));
- }
- else
- {
- EmitVectorUnaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPSqrt));
- });
- }
- }
- public static void Fsub_S(ILEmitterCtx context)
- {
- if (Optimizations.FastFP && Optimizations.UseSse
- && Optimizations.UseSse2)
- {
- EmitScalarSseOrSse2OpF(context, nameof(Sse.SubtractScalar));
- }
- else
- {
- EmitScalarBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPSub));
- });
- }
- }
- public static void Fsub_V(ILEmitterCtx context)
- {
- if (Optimizations.FastFP && Optimizations.UseSse
- && Optimizations.UseSse2)
- {
- EmitVectorSseOrSse2OpF(context, nameof(Sse.Subtract));
- }
- else
- {
- EmitVectorBinaryOpF(context, () =>
- {
- EmitSoftFloatCall(context, nameof(SoftFloat32.FPSub));
- });
- }
- }
- public static void Mla_V(ILEmitterCtx context)
- {
- EmitVectorTernaryOpZx(context, () =>
- {
- context.Emit(OpCodes.Mul);
- context.Emit(OpCodes.Add);
- });
- }
- public static void Mla_Ve(ILEmitterCtx context)
- {
- EmitVectorTernaryOpByElemZx(context, () =>
- {
- context.Emit(OpCodes.Mul);
- context.Emit(OpCodes.Add);
- });
- }
- public static void Mls_V(ILEmitterCtx context)
- {
- EmitVectorTernaryOpZx(context, () =>
- {
- context.Emit(OpCodes.Mul);
- context.Emit(OpCodes.Sub);
- });
- }
- public static void Mls_Ve(ILEmitterCtx context)
- {
- EmitVectorTernaryOpByElemZx(context, () =>
- {
- context.Emit(OpCodes.Mul);
- context.Emit(OpCodes.Sub);
- });
- }
- public static void Mul_V(ILEmitterCtx context)
- {
- EmitVectorBinaryOpZx(context, () => context.Emit(OpCodes.Mul));
- }
- public static void Mul_Ve(ILEmitterCtx context)
- {
- EmitVectorBinaryOpByElemZx(context, () => context.Emit(OpCodes.Mul));
- }
- public static void Neg_S(ILEmitterCtx context)
- {
- EmitScalarUnaryOpSx(context, () => context.Emit(OpCodes.Neg));
- }
- public static void Neg_V(ILEmitterCtx context)
- {
- if (Optimizations.UseSse2)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- Type[] typesSub = new Type[] { VectorIntTypesPerSizeLog2[op.Size], VectorIntTypesPerSizeLog2[op.Size] };
- string[] namesSzv = new string[] { nameof(VectorHelper.VectorSByteZero),
- nameof(VectorHelper.VectorInt16Zero),
- nameof(VectorHelper.VectorInt32Zero),
- nameof(VectorHelper.VectorInt64Zero) };
- VectorHelper.EmitCall(context, namesSzv[op.Size]);
- EmitLdvecWithSignedCast(context, op.Rn, op.Size);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesSub));
- EmitStvecWithSignedCast(context, op.Rd, op.Size);
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else
- {
- EmitVectorUnaryOpSx(context, () => context.Emit(OpCodes.Neg));
- }
- }
- public static void Raddhn_V(ILEmitterCtx context)
- {
- EmitHighNarrow(context, () => context.Emit(OpCodes.Add), round: true);
- }
- public static void Rsubhn_V(ILEmitterCtx context)
- {
- EmitHighNarrow(context, () => context.Emit(OpCodes.Sub), round: true);
- }
- public static void Saba_V(ILEmitterCtx context)
- {
- EmitVectorTernaryOpSx(context, () =>
- {
- context.Emit(OpCodes.Sub);
- EmitAbs(context);
- context.Emit(OpCodes.Add);
- });
- }
- public static void Sabal_V(ILEmitterCtx context)
- {
- EmitVectorWidenRnRmTernaryOpSx(context, () =>
- {
- context.Emit(OpCodes.Sub);
- EmitAbs(context);
- context.Emit(OpCodes.Add);
- });
- }
- public static void Sabd_V(ILEmitterCtx context)
- {
- EmitVectorBinaryOpSx(context, () =>
- {
- context.Emit(OpCodes.Sub);
- EmitAbs(context);
- });
- }
- public static void Sabdl_V(ILEmitterCtx context)
- {
- EmitVectorWidenRnRmBinaryOpSx(context, () =>
- {
- context.Emit(OpCodes.Sub);
- EmitAbs(context);
- });
- }
- public static void Sadalp_V(ILEmitterCtx context)
- {
- EmitAddLongPairwise(context, signed: true, accumulate: true);
- }
- public static void Saddl_V(ILEmitterCtx context)
- {
- if (Optimizations.UseSse41)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- Type[] typesSrl = new Type[] { VectorIntTypesPerSizeLog2[op.Size], typeof(byte) };
- Type[] typesCvt = new Type[] { VectorIntTypesPerSizeLog2[op.Size] };
- Type[] typesAdd = new Type[] { VectorIntTypesPerSizeLog2[op.Size + 1],
- VectorIntTypesPerSizeLog2[op.Size + 1] };
- string[] namesCvt = new string[] { nameof(Sse41.ConvertToVector128Int16),
- nameof(Sse41.ConvertToVector128Int32),
- nameof(Sse41.ConvertToVector128Int64) };
- int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
- EmitLdvecWithSignedCast(context, op.Rn, op.Size);
- context.EmitLdc_I4(numBytes);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
- context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
- EmitLdvecWithSignedCast(context, op.Rm, op.Size);
- context.EmitLdc_I4(numBytes);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
- context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesAdd));
- EmitStvecWithSignedCast(context, op.Rd, op.Size + 1);
- }
- else
- {
- EmitVectorWidenRnRmBinaryOpSx(context, () => context.Emit(OpCodes.Add));
- }
- }
- public static void Saddlp_V(ILEmitterCtx context)
- {
- EmitAddLongPairwise(context, signed: true, accumulate: false);
- }
- public static void Saddw_V(ILEmitterCtx context)
- {
- if (Optimizations.UseSse41)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- Type[] typesSrl = new Type[] { VectorIntTypesPerSizeLog2[op.Size], typeof(byte) };
- Type[] typesCvt = new Type[] { VectorIntTypesPerSizeLog2[op.Size] };
- Type[] typesAdd = new Type[] { VectorIntTypesPerSizeLog2[op.Size + 1],
- VectorIntTypesPerSizeLog2[op.Size + 1] };
- string[] namesCvt = new string[] { nameof(Sse41.ConvertToVector128Int16),
- nameof(Sse41.ConvertToVector128Int32),
- nameof(Sse41.ConvertToVector128Int64) };
- int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
- EmitLdvecWithSignedCast(context, op.Rn, op.Size + 1);
- EmitLdvecWithSignedCast(context, op.Rm, op.Size);
- context.EmitLdc_I4(numBytes);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
- context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesAdd));
- EmitStvecWithSignedCast(context, op.Rd, op.Size + 1);
- }
- else
- {
- EmitVectorWidenRmBinaryOpSx(context, () => context.Emit(OpCodes.Add));
- }
- }
- public static void Shadd_V(ILEmitterCtx context)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- if (Optimizations.UseSse2 && op.Size > 0)
- {
- Type[] typesSra = new Type[] { VectorIntTypesPerSizeLog2[op.Size], typeof(byte) };
- Type[] typesAndXorAdd = new Type[] { VectorIntTypesPerSizeLog2[op.Size], VectorIntTypesPerSizeLog2[op.Size] };
- EmitLdvecWithSignedCast(context, op.Rn, op.Size);
- context.Emit(OpCodes.Dup);
- context.EmitStvectmp();
- EmitLdvecWithSignedCast(context, op.Rm, op.Size);
- context.Emit(OpCodes.Dup);
- context.EmitStvectmp2();
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.And), typesAndXorAdd));
- context.EmitLdvectmp();
- context.EmitLdvectmp2();
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Xor), typesAndXorAdd));
- context.EmitLdc_I4(1);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightArithmetic), typesSra));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesAndXorAdd));
- EmitStvecWithSignedCast(context, op.Rd, op.Size);
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else
- {
- EmitVectorBinaryOpSx(context, () =>
- {
- context.Emit(OpCodes.Add);
- context.Emit(OpCodes.Ldc_I4_1);
- context.Emit(OpCodes.Shr);
- });
- }
- }
- public static void Shsub_V(ILEmitterCtx context)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- if (Optimizations.UseSse2 && op.Size < 2)
- {
- Type[] typesSav = new Type[] { IntTypesPerSizeLog2[op.Size] };
- Type[] typesAddSub = new Type[] { VectorIntTypesPerSizeLog2 [op.Size], VectorIntTypesPerSizeLog2 [op.Size] };
- Type[] typesAvg = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], VectorUIntTypesPerSizeLog2[op.Size] };
- context.EmitLdc_I4(op.Size == 0 ? sbyte.MinValue : short.MinValue);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
- context.EmitStvectmp();
- EmitLdvecWithSignedCast(context, op.Rn, op.Size);
- context.EmitLdvectmp();
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesAddSub));
- context.Emit(OpCodes.Dup);
- EmitLdvecWithSignedCast(context, op.Rm, op.Size);
- context.EmitLdvectmp();
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesAddSub));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Average), typesAvg));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesAddSub));
- EmitStvecWithSignedCast(context, op.Rd, op.Size);
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else
- {
- EmitVectorBinaryOpSx(context, () =>
- {
- context.Emit(OpCodes.Sub);
- context.Emit(OpCodes.Ldc_I4_1);
- context.Emit(OpCodes.Shr);
- });
- }
- }
- public static void Smax_V(ILEmitterCtx context)
- {
- if (Optimizations.UseSse41)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- Type[] typesMax = new Type[] { VectorIntTypesPerSizeLog2[op.Size], VectorIntTypesPerSizeLog2[op.Size] };
- Type typeSse = op.Size == 1 ? typeof(Sse2) : typeof(Sse41);
- EmitLdvecWithSignedCast(context, op.Rn, op.Size);
- EmitLdvecWithSignedCast(context, op.Rm, op.Size);
- context.EmitCall(typeSse.GetMethod(nameof(Sse2.Max), typesMax));
- EmitStvecWithSignedCast(context, op.Rd, op.Size);
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else
- {
- Type[] types = new Type[] { typeof(long), typeof(long) };
- MethodInfo mthdInfo = typeof(Math).GetMethod(nameof(Math.Max), types);
- EmitVectorBinaryOpSx(context, () => context.EmitCall(mthdInfo));
- }
- }
- public static void Smaxp_V(ILEmitterCtx context)
- {
- Type[] types = new Type[] { typeof(long), typeof(long) };
- MethodInfo mthdInfo = typeof(Math).GetMethod(nameof(Math.Max), types);
- EmitVectorPairwiseOpSx(context, () => context.EmitCall(mthdInfo));
- }
- public static void Smin_V(ILEmitterCtx context)
- {
- if (Optimizations.UseSse41)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- Type[] typesMin = new Type[] { VectorIntTypesPerSizeLog2[op.Size], VectorIntTypesPerSizeLog2[op.Size] };
- Type typeSse = op.Size == 1 ? typeof(Sse2) : typeof(Sse41);
- EmitLdvecWithSignedCast(context, op.Rn, op.Size);
- EmitLdvecWithSignedCast(context, op.Rm, op.Size);
- context.EmitCall(typeSse.GetMethod(nameof(Sse2.Min), typesMin));
- EmitStvecWithSignedCast(context, op.Rd, op.Size);
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else
- {
- Type[] types = new Type[] { typeof(long), typeof(long) };
- MethodInfo mthdInfo = typeof(Math).GetMethod(nameof(Math.Min), types);
- EmitVectorBinaryOpSx(context, () => context.EmitCall(mthdInfo));
- }
- }
- public static void Sminp_V(ILEmitterCtx context)
- {
- Type[] types = new Type[] { typeof(long), typeof(long) };
- MethodInfo mthdInfo = typeof(Math).GetMethod(nameof(Math.Min), types);
- EmitVectorPairwiseOpSx(context, () => context.EmitCall(mthdInfo));
- }
- public static void Smlal_V(ILEmitterCtx context)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- if (Optimizations.UseSse41 && op.Size < 2)
- {
- Type[] typesSrl = new Type[] { VectorIntTypesPerSizeLog2[op.Size], typeof(byte) };
- Type[] typesCvt = new Type[] { VectorIntTypesPerSizeLog2[op.Size] };
- Type[] typesMulAdd = new Type[] { VectorIntTypesPerSizeLog2[op.Size + 1],
- VectorIntTypesPerSizeLog2[op.Size + 1] };
- Type typeSse = op.Size == 0 ? typeof(Sse2) : typeof(Sse41);
- string nameCvt = op.Size == 0
- ? nameof(Sse41.ConvertToVector128Int16)
- : nameof(Sse41.ConvertToVector128Int32);
- int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
- EmitLdvecWithSignedCast(context, op.Rd, op.Size + 1);
- EmitLdvecWithSignedCast(context, op.Rn, op.Size);
- context.EmitLdc_I4(numBytes);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
- context.EmitCall(typeof(Sse41).GetMethod(nameCvt, typesCvt));
- EmitLdvecWithSignedCast(context, op.Rm, op.Size);
- context.EmitLdc_I4(numBytes);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
- context.EmitCall(typeof(Sse41).GetMethod(nameCvt, typesCvt));
- context.EmitCall(typeSse.GetMethod(nameof(Sse2.MultiplyLow), typesMulAdd));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesMulAdd));
- EmitStvecWithSignedCast(context, op.Rd, op.Size + 1);
- }
- else
- {
- EmitVectorWidenRnRmTernaryOpSx(context, () =>
- {
- context.Emit(OpCodes.Mul);
- context.Emit(OpCodes.Add);
- });
- }
- }
- public static void Smlsl_V(ILEmitterCtx context)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- if (Optimizations.UseSse41 && op.Size < 2)
- {
- Type[] typesSrl = new Type[] { VectorIntTypesPerSizeLog2[op.Size], typeof(byte) };
- Type[] typesCvt = new Type[] { VectorIntTypesPerSizeLog2[op.Size] };
- Type[] typesMulSub = new Type[] { VectorIntTypesPerSizeLog2[op.Size + 1],
- VectorIntTypesPerSizeLog2[op.Size + 1] };
- Type typeSse = op.Size == 0 ? typeof(Sse2) : typeof(Sse41);
- string nameCvt = op.Size == 0
- ? nameof(Sse41.ConvertToVector128Int16)
- : nameof(Sse41.ConvertToVector128Int32);
- int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
- EmitLdvecWithSignedCast(context, op.Rd, op.Size + 1);
- EmitLdvecWithSignedCast(context, op.Rn, op.Size);
- context.EmitLdc_I4(numBytes);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
- context.EmitCall(typeof(Sse41).GetMethod(nameCvt, typesCvt));
- EmitLdvecWithSignedCast(context, op.Rm, op.Size);
- context.EmitLdc_I4(numBytes);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
- context.EmitCall(typeof(Sse41).GetMethod(nameCvt, typesCvt));
- context.EmitCall(typeSse.GetMethod(nameof(Sse2.MultiplyLow), typesMulSub));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesMulSub));
- EmitStvecWithSignedCast(context, op.Rd, op.Size + 1);
- }
- else
- {
- EmitVectorWidenRnRmTernaryOpSx(context, () =>
- {
- context.Emit(OpCodes.Mul);
- context.Emit(OpCodes.Sub);
- });
- }
- }
- public static void Smull_V(ILEmitterCtx context)
- {
- EmitVectorWidenRnRmBinaryOpSx(context, () => context.Emit(OpCodes.Mul));
- }
- public static void Sqabs_S(ILEmitterCtx context)
- {
- EmitScalarSaturatingUnaryOpSx(context, () => EmitAbs(context));
- }
- public static void Sqabs_V(ILEmitterCtx context)
- {
- EmitVectorSaturatingUnaryOpSx(context, () => EmitAbs(context));
- }
- public static void Sqadd_S(ILEmitterCtx context)
- {
- EmitScalarSaturatingBinaryOpSx(context, SaturatingFlags.Add);
- }
- public static void Sqadd_V(ILEmitterCtx context)
- {
- EmitVectorSaturatingBinaryOpSx(context, SaturatingFlags.Add);
- }
- public static void Sqdmulh_S(ILEmitterCtx context)
- {
- EmitSaturatingBinaryOp(context, () => EmitDoublingMultiplyHighHalf(context, round: false), SaturatingFlags.ScalarSx);
- }
- public static void Sqdmulh_V(ILEmitterCtx context)
- {
- EmitSaturatingBinaryOp(context, () => EmitDoublingMultiplyHighHalf(context, round: false), SaturatingFlags.VectorSx);
- }
- public static void Sqneg_S(ILEmitterCtx context)
- {
- EmitScalarSaturatingUnaryOpSx(context, () => context.Emit(OpCodes.Neg));
- }
- public static void Sqneg_V(ILEmitterCtx context)
- {
- EmitVectorSaturatingUnaryOpSx(context, () => context.Emit(OpCodes.Neg));
- }
- public static void Sqrdmulh_S(ILEmitterCtx context)
- {
- EmitSaturatingBinaryOp(context, () => EmitDoublingMultiplyHighHalf(context, round: true), SaturatingFlags.ScalarSx);
- }
- public static void Sqrdmulh_V(ILEmitterCtx context)
- {
- EmitSaturatingBinaryOp(context, () => EmitDoublingMultiplyHighHalf(context, round: true), SaturatingFlags.VectorSx);
- }
- public static void Sqsub_S(ILEmitterCtx context)
- {
- EmitScalarSaturatingBinaryOpSx(context, SaturatingFlags.Sub);
- }
- public static void Sqsub_V(ILEmitterCtx context)
- {
- EmitVectorSaturatingBinaryOpSx(context, SaturatingFlags.Sub);
- }
- public static void Sqxtn_S(ILEmitterCtx context)
- {
- EmitSaturatingNarrowOp(context, SaturatingNarrowFlags.ScalarSxSx);
- }
- public static void Sqxtn_V(ILEmitterCtx context)
- {
- EmitSaturatingNarrowOp(context, SaturatingNarrowFlags.VectorSxSx);
- }
- public static void Sqxtun_S(ILEmitterCtx context)
- {
- EmitSaturatingNarrowOp(context, SaturatingNarrowFlags.ScalarSxZx);
- }
- public static void Sqxtun_V(ILEmitterCtx context)
- {
- EmitSaturatingNarrowOp(context, SaturatingNarrowFlags.VectorSxZx);
- }
- public static void Srhadd_V(ILEmitterCtx context)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- if (Optimizations.UseSse2 && op.Size < 2)
- {
- Type[] typesSav = new Type[] { IntTypesPerSizeLog2[op.Size] };
- Type[] typesSubAdd = new Type[] { VectorIntTypesPerSizeLog2 [op.Size], VectorIntTypesPerSizeLog2 [op.Size] };
- Type[] typesAvg = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], VectorUIntTypesPerSizeLog2[op.Size] };
- context.EmitLdc_I4(op.Size == 0 ? sbyte.MinValue : short.MinValue);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
- context.Emit(OpCodes.Dup);
- context.EmitStvectmp();
- EmitLdvecWithSignedCast(context, op.Rn, op.Size);
- context.EmitLdvectmp();
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesSubAdd));
- EmitLdvecWithSignedCast(context, op.Rm, op.Size);
- context.EmitLdvectmp();
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesSubAdd));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Average), typesAvg));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesSubAdd));
- EmitStvecWithSignedCast(context, op.Rd, op.Size);
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else
- {
- EmitVectorBinaryOpSx(context, () =>
- {
- context.Emit(OpCodes.Add);
- context.Emit(OpCodes.Ldc_I4_1);
- context.Emit(OpCodes.Add);
- context.Emit(OpCodes.Ldc_I4_1);
- context.Emit(OpCodes.Shr);
- });
- }
- }
- public static void Ssubl_V(ILEmitterCtx context)
- {
- if (Optimizations.UseSse41)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- Type[] typesSrl = new Type[] { VectorIntTypesPerSizeLog2[op.Size], typeof(byte) };
- Type[] typesCvt = new Type[] { VectorIntTypesPerSizeLog2[op.Size] };
- Type[] typesSub = new Type[] { VectorIntTypesPerSizeLog2[op.Size + 1],
- VectorIntTypesPerSizeLog2[op.Size + 1] };
- string[] namesCvt = new string[] { nameof(Sse41.ConvertToVector128Int16),
- nameof(Sse41.ConvertToVector128Int32),
- nameof(Sse41.ConvertToVector128Int64) };
- int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
- EmitLdvecWithSignedCast(context, op.Rn, op.Size);
- context.EmitLdc_I4(numBytes);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
- context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
- EmitLdvecWithSignedCast(context, op.Rm, op.Size);
- context.EmitLdc_I4(numBytes);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
- context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesSub));
- EmitStvecWithSignedCast(context, op.Rd, op.Size + 1);
- }
- else
- {
- EmitVectorWidenRnRmBinaryOpSx(context, () => context.Emit(OpCodes.Sub));
- }
- }
- public static void Ssubw_V(ILEmitterCtx context)
- {
- if (Optimizations.UseSse41)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- Type[] typesSrl = new Type[] { VectorIntTypesPerSizeLog2[op.Size], typeof(byte) };
- Type[] typesCvt = new Type[] { VectorIntTypesPerSizeLog2[op.Size] };
- Type[] typesSub = new Type[] { VectorIntTypesPerSizeLog2[op.Size + 1],
- VectorIntTypesPerSizeLog2[op.Size + 1] };
- string[] namesCvt = new string[] { nameof(Sse41.ConvertToVector128Int16),
- nameof(Sse41.ConvertToVector128Int32),
- nameof(Sse41.ConvertToVector128Int64) };
- int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
- EmitLdvecWithSignedCast(context, op.Rn, op.Size + 1);
- EmitLdvecWithSignedCast(context, op.Rm, op.Size);
- context.EmitLdc_I4(numBytes);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
- context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesSub));
- EmitStvecWithSignedCast(context, op.Rd, op.Size + 1);
- }
- else
- {
- EmitVectorWidenRmBinaryOpSx(context, () => context.Emit(OpCodes.Sub));
- }
- }
- public static void Sub_S(ILEmitterCtx context)
- {
- EmitScalarBinaryOpZx(context, () => context.Emit(OpCodes.Sub));
- }
- public static void Sub_V(ILEmitterCtx context)
- {
- if (Optimizations.UseSse2)
- {
- EmitSse2Op(context, nameof(Sse2.Subtract));
- }
- else
- {
- EmitVectorBinaryOpZx(context, () => context.Emit(OpCodes.Sub));
- }
- }
- public static void Subhn_V(ILEmitterCtx context)
- {
- EmitHighNarrow(context, () => context.Emit(OpCodes.Sub), round: false);
- }
- public static void Suqadd_S(ILEmitterCtx context)
- {
- EmitScalarSaturatingBinaryOpSx(context, SaturatingFlags.Accumulate);
- }
- public static void Suqadd_V(ILEmitterCtx context)
- {
- EmitVectorSaturatingBinaryOpSx(context, SaturatingFlags.Accumulate);
- }
- public static void Uaba_V(ILEmitterCtx context)
- {
- EmitVectorTernaryOpZx(context, () =>
- {
- context.Emit(OpCodes.Sub);
- EmitAbs(context);
- context.Emit(OpCodes.Add);
- });
- }
- public static void Uabal_V(ILEmitterCtx context)
- {
- EmitVectorWidenRnRmTernaryOpZx(context, () =>
- {
- context.Emit(OpCodes.Sub);
- EmitAbs(context);
- context.Emit(OpCodes.Add);
- });
- }
- public static void Uabd_V(ILEmitterCtx context)
- {
- EmitVectorBinaryOpZx(context, () =>
- {
- context.Emit(OpCodes.Sub);
- EmitAbs(context);
- });
- }
- public static void Uabdl_V(ILEmitterCtx context)
- {
- EmitVectorWidenRnRmBinaryOpZx(context, () =>
- {
- context.Emit(OpCodes.Sub);
- EmitAbs(context);
- });
- }
- public static void Uadalp_V(ILEmitterCtx context)
- {
- EmitAddLongPairwise(context, signed: false, accumulate: true);
- }
- public static void Uaddl_V(ILEmitterCtx context)
- {
- if (Optimizations.UseSse41)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- Type[] typesSrl = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], typeof(byte) };
- Type[] typesCvt = new Type[] { VectorUIntTypesPerSizeLog2[op.Size] };
- Type[] typesAdd = new Type[] { VectorUIntTypesPerSizeLog2[op.Size + 1],
- VectorUIntTypesPerSizeLog2[op.Size + 1] };
- string[] namesCvt = new string[] { nameof(Sse41.ConvertToVector128Int16),
- nameof(Sse41.ConvertToVector128Int32),
- nameof(Sse41.ConvertToVector128Int64) };
- int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
- EmitLdvecWithUnsignedCast(context, op.Rn, op.Size);
- context.EmitLdc_I4(numBytes);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
- context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
- EmitLdvecWithUnsignedCast(context, op.Rm, op.Size);
- context.EmitLdc_I4(numBytes);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
- context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesAdd));
- EmitStvecWithUnsignedCast(context, op.Rd, op.Size + 1);
- }
- else
- {
- EmitVectorWidenRnRmBinaryOpZx(context, () => context.Emit(OpCodes.Add));
- }
- }
- public static void Uaddlp_V(ILEmitterCtx context)
- {
- EmitAddLongPairwise(context, signed: false, accumulate: false);
- }
- public static void Uaddlv_V(ILEmitterCtx context)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- int bytes = op.GetBitsCount() >> 3;
- int elems = bytes >> op.Size;
- EmitVectorExtractZx(context, op.Rn, 0, op.Size);
- for (int index = 1; index < elems; index++)
- {
- EmitVectorExtractZx(context, op.Rn, index, op.Size);
- context.Emit(OpCodes.Add);
- }
- EmitScalarSet(context, op.Rd, op.Size + 1);
- }
- public static void Uaddw_V(ILEmitterCtx context)
- {
- if (Optimizations.UseSse41)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- Type[] typesSrl = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], typeof(byte) };
- Type[] typesCvt = new Type[] { VectorUIntTypesPerSizeLog2[op.Size] };
- Type[] typesAdd = new Type[] { VectorUIntTypesPerSizeLog2[op.Size + 1],
- VectorUIntTypesPerSizeLog2[op.Size + 1] };
- string[] namesCvt = new string[] { nameof(Sse41.ConvertToVector128Int16),
- nameof(Sse41.ConvertToVector128Int32),
- nameof(Sse41.ConvertToVector128Int64) };
- int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
- EmitLdvecWithUnsignedCast(context, op.Rn, op.Size + 1);
- EmitLdvecWithUnsignedCast(context, op.Rm, op.Size);
- context.EmitLdc_I4(numBytes);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
- context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesAdd));
- EmitStvecWithUnsignedCast(context, op.Rd, op.Size + 1);
- }
- else
- {
- EmitVectorWidenRmBinaryOpZx(context, () => context.Emit(OpCodes.Add));
- }
- }
- public static void Uhadd_V(ILEmitterCtx context)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- if (Optimizations.UseSse2 && op.Size > 0)
- {
- Type[] typesSrl = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], typeof(byte) };
- Type[] typesAndXorAdd = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], VectorUIntTypesPerSizeLog2[op.Size] };
- EmitLdvecWithUnsignedCast(context, op.Rn, op.Size);
- context.Emit(OpCodes.Dup);
- context.EmitStvectmp();
- EmitLdvecWithUnsignedCast(context, op.Rm, op.Size);
- context.Emit(OpCodes.Dup);
- context.EmitStvectmp2();
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.And), typesAndXorAdd));
- context.EmitLdvectmp();
- context.EmitLdvectmp2();
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Xor), typesAndXorAdd));
- context.EmitLdc_I4(1);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical), typesSrl));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesAndXorAdd));
- EmitStvecWithUnsignedCast(context, op.Rd, op.Size);
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else
- {
- EmitVectorBinaryOpZx(context, () =>
- {
- context.Emit(OpCodes.Add);
- context.Emit(OpCodes.Ldc_I4_1);
- context.Emit(OpCodes.Shr_Un);
- });
- }
- }
- public static void Uhsub_V(ILEmitterCtx context)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- if (Optimizations.UseSse2 && op.Size < 2)
- {
- Type[] typesAvgSub = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], VectorUIntTypesPerSizeLog2[op.Size] };
- EmitLdvecWithUnsignedCast(context, op.Rn, op.Size);
- context.Emit(OpCodes.Dup);
- EmitLdvecWithUnsignedCast(context, op.Rm, op.Size);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Average), typesAvgSub));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesAvgSub));
- EmitStvecWithUnsignedCast(context, op.Rd, op.Size);
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else
- {
- EmitVectorBinaryOpZx(context, () =>
- {
- context.Emit(OpCodes.Sub);
- context.Emit(OpCodes.Ldc_I4_1);
- context.Emit(OpCodes.Shr_Un);
- });
- }
- }
- public static void Umax_V(ILEmitterCtx context)
- {
- if (Optimizations.UseSse41)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- Type[] typesMax = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], VectorUIntTypesPerSizeLog2[op.Size] };
- Type typeSse = op.Size == 0 ? typeof(Sse2) : typeof(Sse41);
- EmitLdvecWithUnsignedCast(context, op.Rn, op.Size);
- EmitLdvecWithUnsignedCast(context, op.Rm, op.Size);
- context.EmitCall(typeSse.GetMethod(nameof(Sse2.Max), typesMax));
- EmitStvecWithUnsignedCast(context, op.Rd, op.Size);
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else
- {
- Type[] types = new Type[] { typeof(ulong), typeof(ulong) };
- MethodInfo mthdInfo = typeof(Math).GetMethod(nameof(Math.Max), types);
- EmitVectorBinaryOpZx(context, () => context.EmitCall(mthdInfo));
- }
- }
- public static void Umaxp_V(ILEmitterCtx context)
- {
- Type[] types = new Type[] { typeof(ulong), typeof(ulong) };
- MethodInfo mthdInfo = typeof(Math).GetMethod(nameof(Math.Max), types);
- EmitVectorPairwiseOpZx(context, () => context.EmitCall(mthdInfo));
- }
- public static void Umin_V(ILEmitterCtx context)
- {
- if (Optimizations.UseSse41)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- Type[] typesMin = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], VectorUIntTypesPerSizeLog2[op.Size] };
- Type typeSse = op.Size == 0 ? typeof(Sse2) : typeof(Sse41);
- EmitLdvecWithUnsignedCast(context, op.Rn, op.Size);
- EmitLdvecWithUnsignedCast(context, op.Rm, op.Size);
- context.EmitCall(typeSse.GetMethod(nameof(Sse2.Min), typesMin));
- EmitStvecWithUnsignedCast(context, op.Rd, op.Size);
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else
- {
- Type[] types = new Type[] { typeof(ulong), typeof(ulong) };
- MethodInfo mthdInfo = typeof(Math).GetMethod(nameof(Math.Min), types);
- EmitVectorBinaryOpZx(context, () => context.EmitCall(mthdInfo));
- }
- }
- public static void Uminp_V(ILEmitterCtx context)
- {
- Type[] types = new Type[] { typeof(ulong), typeof(ulong) };
- MethodInfo mthdInfo = typeof(Math).GetMethod(nameof(Math.Min), types);
- EmitVectorPairwiseOpZx(context, () => context.EmitCall(mthdInfo));
- }
- public static void Umlal_V(ILEmitterCtx context)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- if (Optimizations.UseSse41 && op.Size < 2)
- {
- Type[] typesSrl = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], typeof(byte) };
- Type[] typesCvt = new Type[] { VectorUIntTypesPerSizeLog2[op.Size] };
- Type[] typesMulAdd = new Type[] { VectorIntTypesPerSizeLog2 [op.Size + 1],
- VectorIntTypesPerSizeLog2 [op.Size + 1] };
- Type typeSse = op.Size == 0 ? typeof(Sse2) : typeof(Sse41);
- string nameCvt = op.Size == 0
- ? nameof(Sse41.ConvertToVector128Int16)
- : nameof(Sse41.ConvertToVector128Int32);
- int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
- EmitLdvecWithUnsignedCast(context, op.Rd, op.Size + 1);
- EmitLdvecWithUnsignedCast(context, op.Rn, op.Size);
- context.EmitLdc_I4(numBytes);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
- context.EmitCall(typeof(Sse41).GetMethod(nameCvt, typesCvt));
- EmitLdvecWithUnsignedCast(context, op.Rm, op.Size);
- context.EmitLdc_I4(numBytes);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
- context.EmitCall(typeof(Sse41).GetMethod(nameCvt, typesCvt));
- context.EmitCall(typeSse.GetMethod(nameof(Sse2.MultiplyLow), typesMulAdd));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesMulAdd));
- EmitStvecWithUnsignedCast(context, op.Rd, op.Size + 1);
- }
- else
- {
- EmitVectorWidenRnRmTernaryOpZx(context, () =>
- {
- context.Emit(OpCodes.Mul);
- context.Emit(OpCodes.Add);
- });
- }
- }
- public static void Umlsl_V(ILEmitterCtx context)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- if (Optimizations.UseSse41 && op.Size < 2)
- {
- Type[] typesSrl = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], typeof(byte) };
- Type[] typesCvt = new Type[] { VectorUIntTypesPerSizeLog2[op.Size] };
- Type[] typesMulSub = new Type[] { VectorIntTypesPerSizeLog2 [op.Size + 1],
- VectorIntTypesPerSizeLog2 [op.Size + 1] };
- Type typeSse = op.Size == 0 ? typeof(Sse2) : typeof(Sse41);
- string nameCvt = op.Size == 0
- ? nameof(Sse41.ConvertToVector128Int16)
- : nameof(Sse41.ConvertToVector128Int32);
- int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
- EmitLdvecWithUnsignedCast(context, op.Rd, op.Size + 1);
- EmitLdvecWithUnsignedCast(context, op.Rn, op.Size);
- context.EmitLdc_I4(numBytes);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
- context.EmitCall(typeof(Sse41).GetMethod(nameCvt, typesCvt));
- EmitLdvecWithUnsignedCast(context, op.Rm, op.Size);
- context.EmitLdc_I4(numBytes);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
- context.EmitCall(typeof(Sse41).GetMethod(nameCvt, typesCvt));
- context.EmitCall(typeSse.GetMethod(nameof(Sse2.MultiplyLow), typesMulSub));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesMulSub));
- EmitStvecWithUnsignedCast(context, op.Rd, op.Size + 1);
- }
- else
- {
- EmitVectorWidenRnRmTernaryOpZx(context, () =>
- {
- context.Emit(OpCodes.Mul);
- context.Emit(OpCodes.Sub);
- });
- }
- }
- public static void Umull_V(ILEmitterCtx context)
- {
- EmitVectorWidenRnRmBinaryOpZx(context, () => context.Emit(OpCodes.Mul));
- }
- public static void Uqadd_S(ILEmitterCtx context)
- {
- EmitScalarSaturatingBinaryOpZx(context, SaturatingFlags.Add);
- }
- public static void Uqadd_V(ILEmitterCtx context)
- {
- EmitVectorSaturatingBinaryOpZx(context, SaturatingFlags.Add);
- }
- public static void Uqsub_S(ILEmitterCtx context)
- {
- EmitScalarSaturatingBinaryOpZx(context, SaturatingFlags.Sub);
- }
- public static void Uqsub_V(ILEmitterCtx context)
- {
- EmitVectorSaturatingBinaryOpZx(context, SaturatingFlags.Sub);
- }
- public static void Uqxtn_S(ILEmitterCtx context)
- {
- EmitSaturatingNarrowOp(context, SaturatingNarrowFlags.ScalarZxZx);
- }
- public static void Uqxtn_V(ILEmitterCtx context)
- {
- EmitSaturatingNarrowOp(context, SaturatingNarrowFlags.VectorZxZx);
- }
- public static void Urhadd_V(ILEmitterCtx context)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- if (Optimizations.UseSse2 && op.Size < 2)
- {
- Type[] typesAvg = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], VectorUIntTypesPerSizeLog2[op.Size] };
- EmitLdvecWithUnsignedCast(context, op.Rn, op.Size);
- EmitLdvecWithUnsignedCast(context, op.Rm, op.Size);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Average), typesAvg));
- EmitStvecWithUnsignedCast(context, op.Rd, op.Size);
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- else
- {
- EmitVectorBinaryOpZx(context, () =>
- {
- context.Emit(OpCodes.Add);
- context.Emit(OpCodes.Ldc_I4_1);
- context.Emit(OpCodes.Add);
- context.Emit(OpCodes.Ldc_I4_1);
- context.Emit(OpCodes.Shr_Un);
- });
- }
- }
- public static void Usqadd_S(ILEmitterCtx context)
- {
- EmitScalarSaturatingBinaryOpZx(context, SaturatingFlags.Accumulate);
- }
- public static void Usqadd_V(ILEmitterCtx context)
- {
- EmitVectorSaturatingBinaryOpZx(context, SaturatingFlags.Accumulate);
- }
- public static void Usubl_V(ILEmitterCtx context)
- {
- if (Optimizations.UseSse41)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- Type[] typesSrl = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], typeof(byte) };
- Type[] typesCvt = new Type[] { VectorUIntTypesPerSizeLog2[op.Size] };
- Type[] typesSub = new Type[] { VectorUIntTypesPerSizeLog2[op.Size + 1],
- VectorUIntTypesPerSizeLog2[op.Size + 1] };
- string[] namesCvt = new string[] { nameof(Sse41.ConvertToVector128Int16),
- nameof(Sse41.ConvertToVector128Int32),
- nameof(Sse41.ConvertToVector128Int64) };
- int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
- EmitLdvecWithUnsignedCast(context, op.Rn, op.Size);
- context.EmitLdc_I4(numBytes);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
- context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
- EmitLdvecWithUnsignedCast(context, op.Rm, op.Size);
- context.EmitLdc_I4(numBytes);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
- context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesSub));
- EmitStvecWithUnsignedCast(context, op.Rd, op.Size + 1);
- }
- else
- {
- EmitVectorWidenRnRmBinaryOpZx(context, () => context.Emit(OpCodes.Sub));
- }
- }
- public static void Usubw_V(ILEmitterCtx context)
- {
- if (Optimizations.UseSse41)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- Type[] typesSrl = new Type[] { VectorUIntTypesPerSizeLog2[op.Size], typeof(byte) };
- Type[] typesCvt = new Type[] { VectorUIntTypesPerSizeLog2[op.Size] };
- Type[] typesSub = new Type[] { VectorUIntTypesPerSizeLog2[op.Size + 1],
- VectorUIntTypesPerSizeLog2[op.Size + 1] };
- string[] namesCvt = new string[] { nameof(Sse41.ConvertToVector128Int16),
- nameof(Sse41.ConvertToVector128Int32),
- nameof(Sse41.ConvertToVector128Int64) };
- int numBytes = op.RegisterSize == RegisterSize.Simd128 ? 8 : 0;
- EmitLdvecWithUnsignedCast(context, op.Rn, op.Size + 1);
- EmitLdvecWithUnsignedCast(context, op.Rm, op.Size);
- context.EmitLdc_I4(numBytes);
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSrl));
- context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt));
- context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), typesSub));
- EmitStvecWithUnsignedCast(context, op.Rd, op.Size + 1);
- }
- else
- {
- EmitVectorWidenRmBinaryOpZx(context, () => context.Emit(OpCodes.Sub));
- }
- }
- private static void EmitAbs(ILEmitterCtx context)
- {
- ILLabel lblTrue = new ILLabel();
- context.Emit(OpCodes.Dup);
- context.Emit(OpCodes.Ldc_I4_0);
- context.Emit(OpCodes.Bge_S, lblTrue);
- context.Emit(OpCodes.Neg);
- context.MarkLabel(lblTrue);
- }
- private static void EmitAddLongPairwise(ILEmitterCtx context, bool signed, bool accumulate)
- {
- OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
- int words = op.GetBitsCount() >> 4;
- int pairs = words >> op.Size;
- for (int index = 0; index < pairs; index++)
- {
- int idx = index << 1;
- EmitVectorExtract(context, op.Rn, idx, op.Size, signed);
- EmitVectorExtract(context, op.Rn, idx + 1, op.Size, signed);
- context.Emit(OpCodes.Add);
- if (accumulate)
- {
- EmitVectorExtract(context, op.Rd, index, op.Size + 1, signed);
- context.Emit(OpCodes.Add);
- }
- EmitVectorInsertTmp(context, index, op.Size + 1);
- }
- context.EmitLdvectmp();
- context.EmitStvec(op.Rd);
- if (op.RegisterSize == RegisterSize.Simd64)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- private static void EmitDoublingMultiplyHighHalf(ILEmitterCtx context, bool round)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- int eSize = 8 << op.Size;
- context.Emit(OpCodes.Mul);
- if (!round)
- {
- context.EmitAsr(eSize - 1);
- }
- else
- {
- long roundConst = 1L << (eSize - 1);
- ILLabel lblTrue = new ILLabel();
- context.EmitLsl(1);
- context.EmitLdc_I8(roundConst);
- context.Emit(OpCodes.Add);
- context.EmitAsr(eSize);
- context.Emit(OpCodes.Dup);
- context.EmitLdc_I8((long)int.MinValue);
- context.Emit(OpCodes.Bne_Un_S, lblTrue);
- context.Emit(OpCodes.Neg);
- context.MarkLabel(lblTrue);
- }
- }
- private static void EmitHighNarrow(ILEmitterCtx context, Action emit, bool round)
- {
- OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;
- int elems = 8 >> op.Size;
- int eSize = 8 << op.Size;
- int part = op.RegisterSize == RegisterSize.Simd128 ? elems : 0;
- long roundConst = 1L << (eSize - 1);
- if (part != 0)
- {
- context.EmitLdvec(op.Rd);
- context.EmitStvectmp();
- }
- for (int index = 0; index < elems; index++)
- {
- EmitVectorExtractZx(context, op.Rn, index, op.Size + 1);
- EmitVectorExtractZx(context, op.Rm, index, op.Size + 1);
- emit();
- if (round)
- {
- context.EmitLdc_I8(roundConst);
- context.Emit(OpCodes.Add);
- }
- context.EmitLsr(eSize);
- EmitVectorInsertTmp(context, part + index, op.Size);
- }
- context.EmitLdvectmp();
- context.EmitStvec(op.Rd);
- if (part == 0)
- {
- EmitVectorZeroUpper(context, op.Rd);
- }
- }
- }
- }
|