InstEmitSimdArithmetic.cs 104 KB

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