AInstEmitSimdArithmetic.cs 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387
  1. // https://github.com/intel/ARM_NEON_2_x86_SSE/blob/master/NEON_2_SSE.h
  2. using ChocolArm64.Decoder;
  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.Instruction.AInstEmitSimdHelper;
  11. namespace ChocolArm64.Instruction
  12. {
  13. static partial class AInstEmit
  14. {
  15. public static void Abs_S(AILEmitterCtx Context)
  16. {
  17. EmitScalarUnaryOpSx(Context, () => EmitAbs(Context));
  18. }
  19. public static void Abs_V(AILEmitterCtx Context)
  20. {
  21. EmitVectorUnaryOpSx(Context, () => EmitAbs(Context));
  22. }
  23. public static void Add_S(AILEmitterCtx Context)
  24. {
  25. EmitScalarBinaryOpZx(Context, () => Context.Emit(OpCodes.Add));
  26. }
  27. public static void Add_V(AILEmitterCtx Context)
  28. {
  29. if (AOptimizations.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(AILEmitterCtx Context)
  39. {
  40. EmitHighNarrow(Context, () => Context.Emit(OpCodes.Add), Round: false);
  41. }
  42. public static void Addp_S(AILEmitterCtx Context)
  43. {
  44. AOpCodeSimd Op = (AOpCodeSimd)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(AILEmitterCtx Context)
  51. {
  52. EmitVectorPairwiseOpZx(Context, () => Context.Emit(OpCodes.Add));
  53. }
  54. public static void Addv_V(AILEmitterCtx Context)
  55. {
  56. AOpCodeSimd Op = (AOpCodeSimd)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(AILEmitterCtx Context)
  68. {
  69. AOpCodeSimd Op = (AOpCodeSimd)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. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.CountLeadingSigns));
  78. EmitVectorInsert(Context, Op.Rd, Index, Op.Size);
  79. }
  80. if (Op.RegisterSize == ARegisterSize.SIMD64)
  81. {
  82. EmitVectorZeroUpper(Context, Op.Rd);
  83. }
  84. }
  85. public static void Clz_V(AILEmitterCtx Context)
  86. {
  87. AOpCodeSimd Op = (AOpCodeSimd)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. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.CountLeadingZeros));
  104. }
  105. EmitVectorInsert(Context, Op.Rd, Index, Op.Size);
  106. }
  107. if (Op.RegisterSize == ARegisterSize.SIMD64)
  108. {
  109. EmitVectorZeroUpper(Context, Op.Rd);
  110. }
  111. }
  112. public static void Cnt_V(AILEmitterCtx Context)
  113. {
  114. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  115. int Elems = Op.RegisterSize == ARegisterSize.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. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.CountSetBits8));
  126. }
  127. EmitVectorInsert(Context, Op.Rd, Index, 0);
  128. }
  129. if (Op.RegisterSize == ARegisterSize.SIMD64)
  130. {
  131. EmitVectorZeroUpper(Context, Op.Rd);
  132. }
  133. }
  134. public static void Fabd_S(AILEmitterCtx 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(AILEmitterCtx Context)
  143. {
  144. EmitScalarUnaryOpF(Context, () =>
  145. {
  146. EmitUnaryMathCall(Context, nameof(Math.Abs));
  147. });
  148. }
  149. public static void Fabs_V(AILEmitterCtx Context)
  150. {
  151. EmitVectorUnaryOpF(Context, () =>
  152. {
  153. EmitUnaryMathCall(Context, nameof(Math.Abs));
  154. });
  155. }
  156. public static void Fadd_S(AILEmitterCtx Context)
  157. {
  158. if (AOptimizations.FastFP && AOptimizations.UseSse
  159. && AOptimizations.UseSse2)
  160. {
  161. EmitScalarSseOrSse2OpF(Context, nameof(Sse.AddScalar));
  162. }
  163. else
  164. {
  165. EmitScalarBinaryOpF(Context, () =>
  166. {
  167. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPAdd));
  168. });
  169. }
  170. }
  171. public static void Fadd_V(AILEmitterCtx Context)
  172. {
  173. if (AOptimizations.FastFP && AOptimizations.UseSse
  174. && AOptimizations.UseSse2)
  175. {
  176. EmitVectorSseOrSse2OpF(Context, nameof(Sse.Add));
  177. }
  178. else
  179. {
  180. EmitVectorBinaryOpF(Context, () =>
  181. {
  182. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPAdd));
  183. });
  184. }
  185. }
  186. public static void Faddp_S(AILEmitterCtx Context)
  187. {
  188. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  189. int SizeF = Op.Size & 1;
  190. EmitVectorExtractF(Context, Op.Rn, 0, SizeF);
  191. EmitVectorExtractF(Context, Op.Rn, 1, SizeF);
  192. Context.Emit(OpCodes.Add);
  193. EmitScalarSetF(Context, Op.Rd, SizeF);
  194. }
  195. public static void Faddp_V(AILEmitterCtx Context)
  196. {
  197. EmitVectorPairwiseOpF(Context, () => Context.Emit(OpCodes.Add));
  198. }
  199. public static void Fdiv_S(AILEmitterCtx Context)
  200. {
  201. if (AOptimizations.FastFP && AOptimizations.UseSse
  202. && AOptimizations.UseSse2)
  203. {
  204. EmitScalarSseOrSse2OpF(Context, nameof(Sse.DivideScalar));
  205. }
  206. else
  207. {
  208. EmitScalarBinaryOpF(Context, () =>
  209. {
  210. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPDiv));
  211. });
  212. }
  213. }
  214. public static void Fdiv_V(AILEmitterCtx Context)
  215. {
  216. if (AOptimizations.FastFP && AOptimizations.UseSse
  217. && AOptimizations.UseSse2)
  218. {
  219. EmitVectorSseOrSse2OpF(Context, nameof(Sse.Divide));
  220. }
  221. else
  222. {
  223. EmitVectorBinaryOpF(Context, () =>
  224. {
  225. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPDiv));
  226. });
  227. }
  228. }
  229. public static void Fmadd_S(AILEmitterCtx Context)
  230. {
  231. if (AOptimizations.FastFP && AOptimizations.UseSse2)
  232. {
  233. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  234. if (Op.Size == 0)
  235. {
  236. Type[] TypesMulAdd = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
  237. Context.EmitLdvec(Op.Ra);
  238. Context.EmitLdvec(Op.Rn);
  239. Context.EmitLdvec(Op.Rm);
  240. Context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.MultiplyScalar), TypesMulAdd));
  241. Context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.AddScalar), TypesMulAdd));
  242. Context.EmitStvec(Op.Rd);
  243. EmitVectorZero32_128(Context, Op.Rd);
  244. }
  245. else /* if (Op.Size == 1) */
  246. {
  247. Type[] TypesMulAdd = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
  248. EmitLdvecWithCastToDouble(Context, Op.Ra);
  249. EmitLdvecWithCastToDouble(Context, Op.Rn);
  250. EmitLdvecWithCastToDouble(Context, Op.Rm);
  251. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.MultiplyScalar), TypesMulAdd));
  252. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.AddScalar), TypesMulAdd));
  253. EmitStvecWithCastFromDouble(Context, Op.Rd);
  254. EmitVectorZeroUpper(Context, Op.Rd);
  255. }
  256. }
  257. else
  258. {
  259. EmitScalarTernaryRaOpF(Context, () =>
  260. {
  261. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPMulAdd));
  262. });
  263. }
  264. }
  265. public static void Fmax_S(AILEmitterCtx Context)
  266. {
  267. if (AOptimizations.FastFP && AOptimizations.UseSse
  268. && AOptimizations.UseSse2)
  269. {
  270. EmitScalarSseOrSse2OpF(Context, nameof(Sse.MaxScalar));
  271. }
  272. else
  273. {
  274. EmitScalarBinaryOpF(Context, () =>
  275. {
  276. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPMax));
  277. });
  278. }
  279. }
  280. public static void Fmax_V(AILEmitterCtx Context)
  281. {
  282. if (AOptimizations.FastFP && AOptimizations.UseSse
  283. && AOptimizations.UseSse2)
  284. {
  285. EmitVectorSseOrSse2OpF(Context, nameof(Sse.Max));
  286. }
  287. else
  288. {
  289. EmitVectorBinaryOpF(Context, () =>
  290. {
  291. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPMax));
  292. });
  293. }
  294. }
  295. public static void Fmaxnm_S(AILEmitterCtx Context)
  296. {
  297. EmitScalarBinaryOpF(Context, () =>
  298. {
  299. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPMaxNum));
  300. });
  301. }
  302. public static void Fmaxnm_V(AILEmitterCtx Context)
  303. {
  304. EmitVectorBinaryOpF(Context, () =>
  305. {
  306. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPMaxNum));
  307. });
  308. }
  309. public static void Fmaxp_V(AILEmitterCtx Context)
  310. {
  311. EmitVectorPairwiseOpF(Context, () =>
  312. {
  313. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPMax));
  314. });
  315. }
  316. public static void Fmin_S(AILEmitterCtx Context)
  317. {
  318. if (AOptimizations.FastFP && AOptimizations.UseSse
  319. && AOptimizations.UseSse2)
  320. {
  321. EmitScalarSseOrSse2OpF(Context, nameof(Sse.MinScalar));
  322. }
  323. else
  324. {
  325. EmitScalarBinaryOpF(Context, () =>
  326. {
  327. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPMin));
  328. });
  329. }
  330. }
  331. public static void Fmin_V(AILEmitterCtx Context)
  332. {
  333. if (AOptimizations.FastFP && AOptimizations.UseSse
  334. && AOptimizations.UseSse2)
  335. {
  336. EmitVectorSseOrSse2OpF(Context, nameof(Sse.Min));
  337. }
  338. else
  339. {
  340. EmitVectorBinaryOpF(Context, () =>
  341. {
  342. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPMin));
  343. });
  344. }
  345. }
  346. public static void Fminnm_S(AILEmitterCtx Context)
  347. {
  348. EmitScalarBinaryOpF(Context, () =>
  349. {
  350. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPMinNum));
  351. });
  352. }
  353. public static void Fminnm_V(AILEmitterCtx Context)
  354. {
  355. EmitVectorBinaryOpF(Context, () =>
  356. {
  357. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPMinNum));
  358. });
  359. }
  360. public static void Fminp_V(AILEmitterCtx Context)
  361. {
  362. EmitVectorPairwiseOpF(Context, () =>
  363. {
  364. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPMin));
  365. });
  366. }
  367. public static void Fmla_Se(AILEmitterCtx Context)
  368. {
  369. EmitScalarTernaryOpByElemF(Context, () =>
  370. {
  371. Context.Emit(OpCodes.Mul);
  372. Context.Emit(OpCodes.Add);
  373. });
  374. }
  375. public static void Fmla_V(AILEmitterCtx Context)
  376. {
  377. EmitVectorTernaryOpF(Context, () =>
  378. {
  379. Context.Emit(OpCodes.Mul);
  380. Context.Emit(OpCodes.Add);
  381. });
  382. }
  383. public static void Fmla_Ve(AILEmitterCtx Context)
  384. {
  385. EmitVectorTernaryOpByElemF(Context, () =>
  386. {
  387. Context.Emit(OpCodes.Mul);
  388. Context.Emit(OpCodes.Add);
  389. });
  390. }
  391. public static void Fmls_Se(AILEmitterCtx Context)
  392. {
  393. EmitScalarTernaryOpByElemF(Context, () =>
  394. {
  395. Context.Emit(OpCodes.Mul);
  396. Context.Emit(OpCodes.Sub);
  397. });
  398. }
  399. public static void Fmls_V(AILEmitterCtx Context)
  400. {
  401. EmitVectorTernaryOpF(Context, () =>
  402. {
  403. Context.Emit(OpCodes.Mul);
  404. Context.Emit(OpCodes.Sub);
  405. });
  406. }
  407. public static void Fmls_Ve(AILEmitterCtx Context)
  408. {
  409. EmitVectorTernaryOpByElemF(Context, () =>
  410. {
  411. Context.Emit(OpCodes.Mul);
  412. Context.Emit(OpCodes.Sub);
  413. });
  414. }
  415. public static void Fmsub_S(AILEmitterCtx Context)
  416. {
  417. if (AOptimizations.FastFP && AOptimizations.UseSse2)
  418. {
  419. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  420. if (Op.Size == 0)
  421. {
  422. Type[] TypesMulSub = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
  423. Context.EmitLdvec(Op.Ra);
  424. Context.EmitLdvec(Op.Rn);
  425. Context.EmitLdvec(Op.Rm);
  426. Context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.MultiplyScalar), TypesMulSub));
  427. Context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SubtractScalar), TypesMulSub));
  428. Context.EmitStvec(Op.Rd);
  429. EmitVectorZero32_128(Context, Op.Rd);
  430. }
  431. else /* if (Op.Size == 1) */
  432. {
  433. Type[] TypesMulSub = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
  434. EmitLdvecWithCastToDouble(Context, Op.Ra);
  435. EmitLdvecWithCastToDouble(Context, Op.Rn);
  436. EmitLdvecWithCastToDouble(Context, Op.Rm);
  437. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.MultiplyScalar), TypesMulSub));
  438. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SubtractScalar), TypesMulSub));
  439. EmitStvecWithCastFromDouble(Context, Op.Rd);
  440. EmitVectorZeroUpper(Context, Op.Rd);
  441. }
  442. }
  443. else
  444. {
  445. EmitScalarTernaryRaOpF(Context, () =>
  446. {
  447. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPMulSub));
  448. });
  449. }
  450. }
  451. public static void Fmul_S(AILEmitterCtx Context)
  452. {
  453. if (AOptimizations.FastFP && AOptimizations.UseSse
  454. && AOptimizations.UseSse2)
  455. {
  456. EmitScalarSseOrSse2OpF(Context, nameof(Sse.MultiplyScalar));
  457. }
  458. else
  459. {
  460. EmitScalarBinaryOpF(Context, () =>
  461. {
  462. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPMul));
  463. });
  464. }
  465. }
  466. public static void Fmul_Se(AILEmitterCtx Context)
  467. {
  468. EmitScalarBinaryOpByElemF(Context, () => Context.Emit(OpCodes.Mul));
  469. }
  470. public static void Fmul_V(AILEmitterCtx Context)
  471. {
  472. if (AOptimizations.FastFP && AOptimizations.UseSse
  473. && AOptimizations.UseSse2)
  474. {
  475. EmitVectorSseOrSse2OpF(Context, nameof(Sse.Multiply));
  476. }
  477. else
  478. {
  479. EmitVectorBinaryOpF(Context, () =>
  480. {
  481. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPMul));
  482. });
  483. }
  484. }
  485. public static void Fmul_Ve(AILEmitterCtx Context)
  486. {
  487. EmitVectorBinaryOpByElemF(Context, () => Context.Emit(OpCodes.Mul));
  488. }
  489. public static void Fmulx_S(AILEmitterCtx Context)
  490. {
  491. EmitScalarBinaryOpF(Context, () =>
  492. {
  493. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPMulX));
  494. });
  495. }
  496. public static void Fmulx_Se(AILEmitterCtx Context)
  497. {
  498. EmitScalarBinaryOpByElemF(Context, () =>
  499. {
  500. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPMulX));
  501. });
  502. }
  503. public static void Fmulx_V(AILEmitterCtx Context)
  504. {
  505. EmitVectorBinaryOpF(Context, () =>
  506. {
  507. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPMulX));
  508. });
  509. }
  510. public static void Fmulx_Ve(AILEmitterCtx Context)
  511. {
  512. EmitVectorBinaryOpByElemF(Context, () =>
  513. {
  514. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPMulX));
  515. });
  516. }
  517. public static void Fneg_S(AILEmitterCtx Context)
  518. {
  519. EmitScalarUnaryOpF(Context, () => Context.Emit(OpCodes.Neg));
  520. }
  521. public static void Fneg_V(AILEmitterCtx Context)
  522. {
  523. EmitVectorUnaryOpF(Context, () => Context.Emit(OpCodes.Neg));
  524. }
  525. public static void Fnmadd_S(AILEmitterCtx Context)
  526. {
  527. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  528. int SizeF = Op.Size & 1;
  529. EmitVectorExtractF(Context, Op.Rn, 0, SizeF);
  530. Context.Emit(OpCodes.Neg);
  531. EmitVectorExtractF(Context, Op.Rm, 0, SizeF);
  532. Context.Emit(OpCodes.Mul);
  533. EmitVectorExtractF(Context, Op.Ra, 0, SizeF);
  534. Context.Emit(OpCodes.Sub);
  535. EmitScalarSetF(Context, Op.Rd, SizeF);
  536. }
  537. public static void Fnmsub_S(AILEmitterCtx Context)
  538. {
  539. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  540. int SizeF = Op.Size & 1;
  541. EmitVectorExtractF(Context, Op.Rn, 0, SizeF);
  542. EmitVectorExtractF(Context, Op.Rm, 0, SizeF);
  543. Context.Emit(OpCodes.Mul);
  544. EmitVectorExtractF(Context, Op.Ra, 0, SizeF);
  545. Context.Emit(OpCodes.Sub);
  546. EmitScalarSetF(Context, Op.Rd, SizeF);
  547. }
  548. public static void Fnmul_S(AILEmitterCtx Context)
  549. {
  550. EmitScalarBinaryOpF(Context, () =>
  551. {
  552. Context.Emit(OpCodes.Mul);
  553. Context.Emit(OpCodes.Neg);
  554. });
  555. }
  556. public static void Frecpe_S(AILEmitterCtx Context)
  557. {
  558. EmitScalarUnaryOpF(Context, () =>
  559. {
  560. EmitUnarySoftFloatCall(Context, nameof(ASoftFloat.RecipEstimate));
  561. });
  562. }
  563. public static void Frecpe_V(AILEmitterCtx Context)
  564. {
  565. EmitVectorUnaryOpF(Context, () =>
  566. {
  567. EmitUnarySoftFloatCall(Context, nameof(ASoftFloat.RecipEstimate));
  568. });
  569. }
  570. public static void Frecps_S(AILEmitterCtx Context)
  571. {
  572. if (AOptimizations.FastFP && AOptimizations.UseSse2)
  573. {
  574. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  575. int SizeF = Op.Size & 1;
  576. if (SizeF == 0)
  577. {
  578. Type[] TypesSsv = new Type[] { typeof(float) };
  579. Type[] TypesMulSub = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
  580. Context.EmitLdc_R4(2f);
  581. Context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetScalarVector128), TypesSsv));
  582. Context.EmitLdvec(Op.Rn);
  583. Context.EmitLdvec(Op.Rm);
  584. Context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.MultiplyScalar), TypesMulSub));
  585. Context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SubtractScalar), TypesMulSub));
  586. Context.EmitStvec(Op.Rd);
  587. EmitVectorZero32_128(Context, Op.Rd);
  588. }
  589. else /* if (SizeF == 1) */
  590. {
  591. Type[] TypesSsv = new Type[] { typeof(double) };
  592. Type[] TypesMulSub = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
  593. Context.EmitLdc_R8(2d);
  594. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetScalarVector128), TypesSsv));
  595. EmitLdvecWithCastToDouble(Context, Op.Rn);
  596. EmitLdvecWithCastToDouble(Context, Op.Rm);
  597. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.MultiplyScalar), TypesMulSub));
  598. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SubtractScalar), TypesMulSub));
  599. EmitStvecWithCastFromDouble(Context, Op.Rd);
  600. EmitVectorZeroUpper(Context, Op.Rd);
  601. }
  602. }
  603. else
  604. {
  605. EmitScalarBinaryOpF(Context, () =>
  606. {
  607. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPRecipStepFused));
  608. });
  609. }
  610. }
  611. public static void Frecps_V(AILEmitterCtx Context)
  612. {
  613. if (AOptimizations.FastFP && AOptimizations.UseSse2)
  614. {
  615. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  616. int SizeF = Op.Size & 1;
  617. if (SizeF == 0)
  618. {
  619. Type[] TypesSav = new Type[] { typeof(float) };
  620. Type[] TypesMulSub = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
  621. Context.EmitLdc_R4(2f);
  622. Context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetAllVector128), TypesSav));
  623. Context.EmitLdvec(Op.Rn);
  624. Context.EmitLdvec(Op.Rm);
  625. Context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), TypesMulSub));
  626. Context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Subtract), TypesMulSub));
  627. Context.EmitStvec(Op.Rd);
  628. if (Op.RegisterSize == ARegisterSize.SIMD64)
  629. {
  630. EmitVectorZeroUpper(Context, Op.Rd);
  631. }
  632. }
  633. else /* if (SizeF == 1) */
  634. {
  635. Type[] TypesSav = new Type[] { typeof(double) };
  636. Type[] TypesMulSub = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
  637. Context.EmitLdc_R8(2d);
  638. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), TypesSav));
  639. EmitLdvecWithCastToDouble(Context, Op.Rn);
  640. EmitLdvecWithCastToDouble(Context, Op.Rm);
  641. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), TypesMulSub));
  642. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), TypesMulSub));
  643. EmitStvecWithCastFromDouble(Context, Op.Rd);
  644. }
  645. }
  646. else
  647. {
  648. EmitVectorBinaryOpF(Context, () =>
  649. {
  650. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPRecipStepFused));
  651. });
  652. }
  653. }
  654. public static void Frecpx_S(AILEmitterCtx Context)
  655. {
  656. EmitScalarUnaryOpF(Context, () =>
  657. {
  658. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPRecpX));
  659. });
  660. }
  661. public static void Frinta_S(AILEmitterCtx Context)
  662. {
  663. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  664. EmitVectorExtractF(Context, Op.Rn, 0, Op.Size);
  665. EmitRoundMathCall(Context, MidpointRounding.AwayFromZero);
  666. EmitScalarSetF(Context, Op.Rd, Op.Size);
  667. }
  668. public static void Frinta_V(AILEmitterCtx Context)
  669. {
  670. EmitVectorUnaryOpF(Context, () =>
  671. {
  672. EmitRoundMathCall(Context, MidpointRounding.AwayFromZero);
  673. });
  674. }
  675. public static void Frinti_S(AILEmitterCtx Context)
  676. {
  677. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  678. EmitScalarUnaryOpF(Context, () =>
  679. {
  680. Context.EmitLdarg(ATranslatedSub.StateArgIdx);
  681. if (Op.Size == 0)
  682. {
  683. AVectorHelper.EmitCall(Context, nameof(AVectorHelper.RoundF));
  684. }
  685. else if (Op.Size == 1)
  686. {
  687. AVectorHelper.EmitCall(Context, nameof(AVectorHelper.Round));
  688. }
  689. else
  690. {
  691. throw new InvalidOperationException();
  692. }
  693. });
  694. }
  695. public static void Frinti_V(AILEmitterCtx Context)
  696. {
  697. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  698. int SizeF = Op.Size & 1;
  699. EmitVectorUnaryOpF(Context, () =>
  700. {
  701. Context.EmitLdarg(ATranslatedSub.StateArgIdx);
  702. if (SizeF == 0)
  703. {
  704. AVectorHelper.EmitCall(Context, nameof(AVectorHelper.RoundF));
  705. }
  706. else if (SizeF == 1)
  707. {
  708. AVectorHelper.EmitCall(Context, nameof(AVectorHelper.Round));
  709. }
  710. else
  711. {
  712. throw new InvalidOperationException();
  713. }
  714. });
  715. }
  716. public static void Frintm_S(AILEmitterCtx Context)
  717. {
  718. EmitScalarUnaryOpF(Context, () =>
  719. {
  720. EmitUnaryMathCall(Context, nameof(Math.Floor));
  721. });
  722. }
  723. public static void Frintm_V(AILEmitterCtx Context)
  724. {
  725. EmitVectorUnaryOpF(Context, () =>
  726. {
  727. EmitUnaryMathCall(Context, nameof(Math.Floor));
  728. });
  729. }
  730. public static void Frintn_S(AILEmitterCtx Context)
  731. {
  732. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  733. EmitVectorExtractF(Context, Op.Rn, 0, Op.Size);
  734. EmitRoundMathCall(Context, MidpointRounding.ToEven);
  735. EmitScalarSetF(Context, Op.Rd, Op.Size);
  736. }
  737. public static void Frintn_V(AILEmitterCtx Context)
  738. {
  739. EmitVectorUnaryOpF(Context, () =>
  740. {
  741. EmitRoundMathCall(Context, MidpointRounding.ToEven);
  742. });
  743. }
  744. public static void Frintp_S(AILEmitterCtx Context)
  745. {
  746. EmitScalarUnaryOpF(Context, () =>
  747. {
  748. EmitUnaryMathCall(Context, nameof(Math.Ceiling));
  749. });
  750. }
  751. public static void Frintp_V(AILEmitterCtx Context)
  752. {
  753. EmitVectorUnaryOpF(Context, () =>
  754. {
  755. EmitUnaryMathCall(Context, nameof(Math.Ceiling));
  756. });
  757. }
  758. public static void Frintx_S(AILEmitterCtx Context)
  759. {
  760. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  761. EmitScalarUnaryOpF(Context, () =>
  762. {
  763. Context.EmitLdarg(ATranslatedSub.StateArgIdx);
  764. if (Op.Size == 0)
  765. {
  766. AVectorHelper.EmitCall(Context, nameof(AVectorHelper.RoundF));
  767. }
  768. else if (Op.Size == 1)
  769. {
  770. AVectorHelper.EmitCall(Context, nameof(AVectorHelper.Round));
  771. }
  772. else
  773. {
  774. throw new InvalidOperationException();
  775. }
  776. });
  777. }
  778. public static void Frintx_V(AILEmitterCtx Context)
  779. {
  780. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  781. EmitVectorUnaryOpF(Context, () =>
  782. {
  783. Context.EmitLdarg(ATranslatedSub.StateArgIdx);
  784. if (Op.Size == 0)
  785. {
  786. AVectorHelper.EmitCall(Context, nameof(AVectorHelper.RoundF));
  787. }
  788. else if (Op.Size == 1)
  789. {
  790. AVectorHelper.EmitCall(Context, nameof(AVectorHelper.Round));
  791. }
  792. else
  793. {
  794. throw new InvalidOperationException();
  795. }
  796. });
  797. }
  798. public static void Frsqrte_S(AILEmitterCtx Context)
  799. {
  800. EmitScalarUnaryOpF(Context, () =>
  801. {
  802. EmitUnarySoftFloatCall(Context, nameof(ASoftFloat.InvSqrtEstimate));
  803. });
  804. }
  805. public static void Frsqrte_V(AILEmitterCtx Context)
  806. {
  807. EmitVectorUnaryOpF(Context, () =>
  808. {
  809. EmitUnarySoftFloatCall(Context, nameof(ASoftFloat.InvSqrtEstimate));
  810. });
  811. }
  812. public static void Frsqrts_S(AILEmitterCtx Context)
  813. {
  814. if (AOptimizations.FastFP && AOptimizations.UseSse2)
  815. {
  816. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  817. int SizeF = Op.Size & 1;
  818. if (SizeF == 0)
  819. {
  820. Type[] TypesSsv = new Type[] { typeof(float) };
  821. Type[] TypesMulSub = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
  822. Context.EmitLdc_R4(0.5f);
  823. Context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetScalarVector128), TypesSsv));
  824. Context.EmitLdc_R4(3f);
  825. Context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetScalarVector128), TypesSsv));
  826. Context.EmitLdvec(Op.Rn);
  827. Context.EmitLdvec(Op.Rm);
  828. Context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.MultiplyScalar), TypesMulSub));
  829. Context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SubtractScalar), TypesMulSub));
  830. Context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.MultiplyScalar), TypesMulSub));
  831. Context.EmitStvec(Op.Rd);
  832. EmitVectorZero32_128(Context, Op.Rd);
  833. }
  834. else /* if (SizeF == 1) */
  835. {
  836. Type[] TypesSsv = new Type[] { typeof(double) };
  837. Type[] TypesMulSub = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
  838. Context.EmitLdc_R8(0.5d);
  839. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetScalarVector128), TypesSsv));
  840. Context.EmitLdc_R8(3d);
  841. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetScalarVector128), TypesSsv));
  842. EmitLdvecWithCastToDouble(Context, Op.Rn);
  843. EmitLdvecWithCastToDouble(Context, Op.Rm);
  844. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.MultiplyScalar), TypesMulSub));
  845. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SubtractScalar), TypesMulSub));
  846. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.MultiplyScalar), TypesMulSub));
  847. EmitStvecWithCastFromDouble(Context, Op.Rd);
  848. EmitVectorZeroUpper(Context, Op.Rd);
  849. }
  850. }
  851. else
  852. {
  853. EmitScalarBinaryOpF(Context, () =>
  854. {
  855. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPRSqrtStepFused));
  856. });
  857. }
  858. }
  859. public static void Frsqrts_V(AILEmitterCtx Context)
  860. {
  861. if (AOptimizations.FastFP && AOptimizations.UseSse2)
  862. {
  863. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  864. int SizeF = Op.Size & 1;
  865. if (SizeF == 0)
  866. {
  867. Type[] TypesSav = new Type[] { typeof(float) };
  868. Type[] TypesMulSub = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
  869. Context.EmitLdc_R4(0.5f);
  870. Context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetAllVector128), TypesSav));
  871. Context.EmitLdc_R4(3f);
  872. Context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.SetAllVector128), TypesSav));
  873. Context.EmitLdvec(Op.Rn);
  874. Context.EmitLdvec(Op.Rm);
  875. Context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), TypesMulSub));
  876. Context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Subtract), TypesMulSub));
  877. Context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), TypesMulSub));
  878. Context.EmitStvec(Op.Rd);
  879. if (Op.RegisterSize == ARegisterSize.SIMD64)
  880. {
  881. EmitVectorZeroUpper(Context, Op.Rd);
  882. }
  883. }
  884. else /* if (SizeF == 1) */
  885. {
  886. Type[] TypesSav = new Type[] { typeof(double) };
  887. Type[] TypesMulSub = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
  888. Context.EmitLdc_R8(0.5d);
  889. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), TypesSav));
  890. Context.EmitLdc_R8(3d);
  891. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), TypesSav));
  892. EmitLdvecWithCastToDouble(Context, Op.Rn);
  893. EmitLdvecWithCastToDouble(Context, Op.Rm);
  894. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), TypesMulSub));
  895. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), TypesMulSub));
  896. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), TypesMulSub));
  897. EmitStvecWithCastFromDouble(Context, Op.Rd);
  898. }
  899. }
  900. else
  901. {
  902. EmitVectorBinaryOpF(Context, () =>
  903. {
  904. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPRSqrtStepFused));
  905. });
  906. }
  907. }
  908. public static void Fsqrt_S(AILEmitterCtx Context)
  909. {
  910. if (AOptimizations.FastFP && AOptimizations.UseSse
  911. && AOptimizations.UseSse2)
  912. {
  913. EmitScalarSseOrSse2OpF(Context, nameof(Sse.SqrtScalar));
  914. }
  915. else
  916. {
  917. EmitScalarUnaryOpF(Context, () =>
  918. {
  919. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPSqrt));
  920. });
  921. }
  922. }
  923. public static void Fsqrt_V(AILEmitterCtx Context)
  924. {
  925. if (AOptimizations.FastFP && AOptimizations.UseSse
  926. && AOptimizations.UseSse2)
  927. {
  928. EmitVectorSseOrSse2OpF(Context, nameof(Sse.Sqrt));
  929. }
  930. else
  931. {
  932. EmitVectorUnaryOpF(Context, () =>
  933. {
  934. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPSqrt));
  935. });
  936. }
  937. }
  938. public static void Fsub_S(AILEmitterCtx Context)
  939. {
  940. if (AOptimizations.FastFP && AOptimizations.UseSse
  941. && AOptimizations.UseSse2)
  942. {
  943. EmitScalarSseOrSse2OpF(Context, nameof(Sse.SubtractScalar));
  944. }
  945. else
  946. {
  947. EmitScalarBinaryOpF(Context, () =>
  948. {
  949. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPSub));
  950. });
  951. }
  952. }
  953. public static void Fsub_V(AILEmitterCtx Context)
  954. {
  955. if (AOptimizations.FastFP && AOptimizations.UseSse
  956. && AOptimizations.UseSse2)
  957. {
  958. EmitVectorSseOrSse2OpF(Context, nameof(Sse.Subtract));
  959. }
  960. else
  961. {
  962. EmitVectorBinaryOpF(Context, () =>
  963. {
  964. EmitSoftFloatCall(Context, nameof(ASoftFloat_32.FPSub));
  965. });
  966. }
  967. }
  968. public static void Mla_V(AILEmitterCtx Context)
  969. {
  970. EmitVectorTernaryOpZx(Context, () =>
  971. {
  972. Context.Emit(OpCodes.Mul);
  973. Context.Emit(OpCodes.Add);
  974. });
  975. }
  976. public static void Mla_Ve(AILEmitterCtx Context)
  977. {
  978. EmitVectorTernaryOpByElemZx(Context, () =>
  979. {
  980. Context.Emit(OpCodes.Mul);
  981. Context.Emit(OpCodes.Add);
  982. });
  983. }
  984. public static void Mls_V(AILEmitterCtx Context)
  985. {
  986. EmitVectorTernaryOpZx(Context, () =>
  987. {
  988. Context.Emit(OpCodes.Mul);
  989. Context.Emit(OpCodes.Sub);
  990. });
  991. }
  992. public static void Mls_Ve(AILEmitterCtx Context)
  993. {
  994. EmitVectorTernaryOpByElemZx(Context, () =>
  995. {
  996. Context.Emit(OpCodes.Mul);
  997. Context.Emit(OpCodes.Sub);
  998. });
  999. }
  1000. public static void Mul_V(AILEmitterCtx Context)
  1001. {
  1002. EmitVectorBinaryOpZx(Context, () => Context.Emit(OpCodes.Mul));
  1003. }
  1004. public static void Mul_Ve(AILEmitterCtx Context)
  1005. {
  1006. EmitVectorBinaryOpByElemZx(Context, () => Context.Emit(OpCodes.Mul));
  1007. }
  1008. public static void Neg_S(AILEmitterCtx Context)
  1009. {
  1010. EmitScalarUnaryOpSx(Context, () => Context.Emit(OpCodes.Neg));
  1011. }
  1012. public static void Neg_V(AILEmitterCtx Context)
  1013. {
  1014. EmitVectorUnaryOpSx(Context, () => Context.Emit(OpCodes.Neg));
  1015. }
  1016. public static void Raddhn_V(AILEmitterCtx Context)
  1017. {
  1018. EmitHighNarrow(Context, () => Context.Emit(OpCodes.Add), Round: true);
  1019. }
  1020. public static void Rsubhn_V(AILEmitterCtx Context)
  1021. {
  1022. EmitHighNarrow(Context, () => Context.Emit(OpCodes.Sub), Round: true);
  1023. }
  1024. public static void Saba_V(AILEmitterCtx Context)
  1025. {
  1026. EmitVectorTernaryOpSx(Context, () =>
  1027. {
  1028. Context.Emit(OpCodes.Sub);
  1029. EmitAbs(Context);
  1030. Context.Emit(OpCodes.Add);
  1031. });
  1032. }
  1033. public static void Sabal_V(AILEmitterCtx Context)
  1034. {
  1035. EmitVectorWidenRnRmTernaryOpSx(Context, () =>
  1036. {
  1037. Context.Emit(OpCodes.Sub);
  1038. EmitAbs(Context);
  1039. Context.Emit(OpCodes.Add);
  1040. });
  1041. }
  1042. public static void Sabd_V(AILEmitterCtx Context)
  1043. {
  1044. EmitVectorBinaryOpSx(Context, () =>
  1045. {
  1046. Context.Emit(OpCodes.Sub);
  1047. EmitAbs(Context);
  1048. });
  1049. }
  1050. public static void Sabdl_V(AILEmitterCtx Context)
  1051. {
  1052. EmitVectorWidenRnRmBinaryOpSx(Context, () =>
  1053. {
  1054. Context.Emit(OpCodes.Sub);
  1055. EmitAbs(Context);
  1056. });
  1057. }
  1058. public static void Sadalp_V(AILEmitterCtx Context)
  1059. {
  1060. EmitAddLongPairwise(Context, Signed: true, Accumulate: true);
  1061. }
  1062. public static void Saddl_V(AILEmitterCtx Context)
  1063. {
  1064. if (AOptimizations.UseSse41)
  1065. {
  1066. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  1067. Type[] TypesSrl = new Type[] { VectorIntTypesPerSizeLog2[Op.Size], typeof(byte) };
  1068. Type[] TypesCvt = new Type[] { VectorIntTypesPerSizeLog2[Op.Size] };
  1069. Type[] TypesAdd = new Type[] { VectorIntTypesPerSizeLog2[Op.Size + 1],
  1070. VectorIntTypesPerSizeLog2[Op.Size + 1] };
  1071. string[] NamesCvt = new string[] { nameof(Sse41.ConvertToVector128Int16),
  1072. nameof(Sse41.ConvertToVector128Int32),
  1073. nameof(Sse41.ConvertToVector128Int64) };
  1074. int NumBytes = Op.RegisterSize == ARegisterSize.SIMD128 ? 8 : 0;
  1075. EmitLdvecWithSignedCast(Context, Op.Rn, Op.Size);
  1076. Context.EmitLdc_I4(NumBytes);
  1077. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), TypesSrl));
  1078. Context.EmitCall(typeof(Sse41).GetMethod(NamesCvt[Op.Size], TypesCvt));
  1079. EmitLdvecWithUnsignedCast(Context, Op.Rm, Op.Size);
  1080. Context.EmitLdc_I4(NumBytes);
  1081. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), TypesSrl));
  1082. Context.EmitCall(typeof(Sse41).GetMethod(NamesCvt[Op.Size], TypesCvt));
  1083. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), TypesAdd));
  1084. EmitStvecWithSignedCast(Context, Op.Rd, Op.Size + 1);
  1085. }
  1086. else
  1087. {
  1088. EmitVectorWidenRnRmBinaryOpSx(Context, () => Context.Emit(OpCodes.Add));
  1089. }
  1090. }
  1091. public static void Saddlp_V(AILEmitterCtx Context)
  1092. {
  1093. EmitAddLongPairwise(Context, Signed: true, Accumulate: false);
  1094. }
  1095. public static void Saddw_V(AILEmitterCtx Context)
  1096. {
  1097. EmitVectorWidenRmBinaryOpSx(Context, () => Context.Emit(OpCodes.Add));
  1098. }
  1099. public static void Shadd_V(AILEmitterCtx Context)
  1100. {
  1101. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  1102. if (AOptimizations.UseSse2 && Op.Size > 0)
  1103. {
  1104. Type[] TypesSra = new Type[] { VectorIntTypesPerSizeLog2[Op.Size], typeof(byte) };
  1105. Type[] TypesAndXorAdd = new Type[] { VectorIntTypesPerSizeLog2[Op.Size], VectorIntTypesPerSizeLog2[Op.Size] };
  1106. EmitLdvecWithSignedCast(Context, Op.Rn, Op.Size);
  1107. Context.Emit(OpCodes.Dup);
  1108. Context.EmitStvectmp();
  1109. EmitLdvecWithSignedCast(Context, Op.Rm, Op.Size);
  1110. Context.Emit(OpCodes.Dup);
  1111. Context.EmitStvectmp2();
  1112. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.And), TypesAndXorAdd));
  1113. Context.EmitLdvectmp();
  1114. Context.EmitLdvectmp2();
  1115. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Xor), TypesAndXorAdd));
  1116. Context.EmitLdc_I4(1);
  1117. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightArithmetic), TypesSra));
  1118. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), TypesAndXorAdd));
  1119. EmitStvecWithSignedCast(Context, Op.Rd, Op.Size);
  1120. if (Op.RegisterSize == ARegisterSize.SIMD64)
  1121. {
  1122. EmitVectorZeroUpper(Context, Op.Rd);
  1123. }
  1124. }
  1125. else
  1126. {
  1127. EmitVectorBinaryOpSx(Context, () =>
  1128. {
  1129. Context.Emit(OpCodes.Add);
  1130. Context.Emit(OpCodes.Ldc_I4_1);
  1131. Context.Emit(OpCodes.Shr);
  1132. });
  1133. }
  1134. }
  1135. public static void Shsub_V(AILEmitterCtx Context)
  1136. {
  1137. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  1138. if (AOptimizations.UseSse2 && Op.Size < 2)
  1139. {
  1140. Type[] TypesSav = new Type[] { IntTypesPerSizeLog2[Op.Size] };
  1141. Type[] TypesAddSub = new Type[] { VectorIntTypesPerSizeLog2 [Op.Size], VectorIntTypesPerSizeLog2 [Op.Size] };
  1142. Type[] TypesAvg = new Type[] { VectorUIntTypesPerSizeLog2[Op.Size], VectorUIntTypesPerSizeLog2[Op.Size] };
  1143. Context.EmitLdc_I4(Op.Size == 0 ? sbyte.MinValue : short.MinValue);
  1144. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), TypesSav));
  1145. Context.EmitStvectmp();
  1146. EmitLdvecWithSignedCast(Context, Op.Rn, Op.Size);
  1147. Context.EmitLdvectmp();
  1148. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), TypesAddSub));
  1149. Context.Emit(OpCodes.Dup);
  1150. EmitLdvecWithSignedCast(Context, Op.Rm, Op.Size);
  1151. Context.EmitLdvectmp();
  1152. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), TypesAddSub));
  1153. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Average), TypesAvg));
  1154. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), TypesAddSub));
  1155. EmitStvecWithSignedCast(Context, Op.Rd, Op.Size);
  1156. if (Op.RegisterSize == ARegisterSize.SIMD64)
  1157. {
  1158. EmitVectorZeroUpper(Context, Op.Rd);
  1159. }
  1160. }
  1161. else
  1162. {
  1163. EmitVectorBinaryOpSx(Context, () =>
  1164. {
  1165. Context.Emit(OpCodes.Sub);
  1166. Context.Emit(OpCodes.Ldc_I4_1);
  1167. Context.Emit(OpCodes.Shr);
  1168. });
  1169. }
  1170. }
  1171. public static void Smax_V(AILEmitterCtx Context)
  1172. {
  1173. Type[] Types = new Type[] { typeof(long), typeof(long) };
  1174. MethodInfo MthdInfo = typeof(Math).GetMethod(nameof(Math.Max), Types);
  1175. EmitVectorBinaryOpSx(Context, () => Context.EmitCall(MthdInfo));
  1176. }
  1177. public static void Smaxp_V(AILEmitterCtx Context)
  1178. {
  1179. Type[] Types = new Type[] { typeof(long), typeof(long) };
  1180. MethodInfo MthdInfo = typeof(Math).GetMethod(nameof(Math.Max), Types);
  1181. EmitVectorPairwiseOpSx(Context, () => Context.EmitCall(MthdInfo));
  1182. }
  1183. public static void Smin_V(AILEmitterCtx Context)
  1184. {
  1185. Type[] Types = new Type[] { typeof(long), typeof(long) };
  1186. MethodInfo MthdInfo = typeof(Math).GetMethod(nameof(Math.Min), Types);
  1187. EmitVectorBinaryOpSx(Context, () => Context.EmitCall(MthdInfo));
  1188. }
  1189. public static void Sminp_V(AILEmitterCtx Context)
  1190. {
  1191. Type[] Types = new Type[] { typeof(long), typeof(long) };
  1192. MethodInfo MthdInfo = typeof(Math).GetMethod(nameof(Math.Min), Types);
  1193. EmitVectorPairwiseOpSx(Context, () => Context.EmitCall(MthdInfo));
  1194. }
  1195. public static void Smlal_V(AILEmitterCtx Context)
  1196. {
  1197. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  1198. if (AOptimizations.UseSse41 && Op.Size < 2)
  1199. {
  1200. Type[] TypesSrl = new Type[] { VectorIntTypesPerSizeLog2[Op.Size], typeof(byte) };
  1201. Type[] TypesCvt = new Type[] { VectorIntTypesPerSizeLog2[Op.Size] };
  1202. Type[] TypesMulAdd = new Type[] { VectorIntTypesPerSizeLog2[Op.Size + 1],
  1203. VectorIntTypesPerSizeLog2[Op.Size + 1] };
  1204. Type TypeMul = Op.Size == 0 ? typeof(Sse2) : typeof(Sse41);
  1205. string NameCvt = Op.Size == 0
  1206. ? nameof(Sse41.ConvertToVector128Int16)
  1207. : nameof(Sse41.ConvertToVector128Int32);
  1208. int NumBytes = Op.RegisterSize == ARegisterSize.SIMD128 ? 8 : 0;
  1209. EmitLdvecWithSignedCast(Context, Op.Rd, Op.Size + 1);
  1210. EmitLdvecWithSignedCast(Context, Op.Rn, Op.Size);
  1211. Context.EmitLdc_I4(NumBytes);
  1212. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), TypesSrl));
  1213. Context.EmitCall(typeof(Sse41).GetMethod(NameCvt, TypesCvt));
  1214. EmitLdvecWithSignedCast(Context, Op.Rm, Op.Size);
  1215. Context.EmitLdc_I4(NumBytes);
  1216. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), TypesSrl));
  1217. Context.EmitCall(typeof(Sse41).GetMethod(NameCvt, TypesCvt));
  1218. Context.EmitCall(TypeMul.GetMethod(nameof(Sse2.MultiplyLow), TypesMulAdd));
  1219. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), TypesMulAdd));
  1220. EmitStvecWithSignedCast(Context, Op.Rd, Op.Size + 1);
  1221. }
  1222. else
  1223. {
  1224. EmitVectorWidenRnRmTernaryOpSx(Context, () =>
  1225. {
  1226. Context.Emit(OpCodes.Mul);
  1227. Context.Emit(OpCodes.Add);
  1228. });
  1229. }
  1230. }
  1231. public static void Smlsl_V(AILEmitterCtx Context)
  1232. {
  1233. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  1234. if (AOptimizations.UseSse41 && Op.Size < 2)
  1235. {
  1236. Type[] TypesSrl = new Type[] { VectorIntTypesPerSizeLog2[Op.Size], typeof(byte) };
  1237. Type[] TypesCvt = new Type[] { VectorIntTypesPerSizeLog2[Op.Size] };
  1238. Type[] TypesMulSub = new Type[] { VectorIntTypesPerSizeLog2[Op.Size + 1],
  1239. VectorIntTypesPerSizeLog2[Op.Size + 1] };
  1240. Type TypeMul = Op.Size == 0 ? typeof(Sse2) : typeof(Sse41);
  1241. string NameCvt = Op.Size == 0
  1242. ? nameof(Sse41.ConvertToVector128Int16)
  1243. : nameof(Sse41.ConvertToVector128Int32);
  1244. int NumBytes = Op.RegisterSize == ARegisterSize.SIMD128 ? 8 : 0;
  1245. EmitLdvecWithSignedCast(Context, Op.Rd, Op.Size + 1);
  1246. EmitLdvecWithSignedCast(Context, Op.Rn, Op.Size);
  1247. Context.EmitLdc_I4(NumBytes);
  1248. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), TypesSrl));
  1249. Context.EmitCall(typeof(Sse41).GetMethod(NameCvt, TypesCvt));
  1250. EmitLdvecWithSignedCast(Context, Op.Rm, Op.Size);
  1251. Context.EmitLdc_I4(NumBytes);
  1252. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), TypesSrl));
  1253. Context.EmitCall(typeof(Sse41).GetMethod(NameCvt, TypesCvt));
  1254. Context.EmitCall(TypeMul.GetMethod(nameof(Sse2.MultiplyLow), TypesMulSub));
  1255. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), TypesMulSub));
  1256. EmitStvecWithSignedCast(Context, Op.Rd, Op.Size + 1);
  1257. }
  1258. else
  1259. {
  1260. EmitVectorWidenRnRmTernaryOpSx(Context, () =>
  1261. {
  1262. Context.Emit(OpCodes.Mul);
  1263. Context.Emit(OpCodes.Sub);
  1264. });
  1265. }
  1266. }
  1267. public static void Smull_V(AILEmitterCtx Context)
  1268. {
  1269. EmitVectorWidenRnRmBinaryOpSx(Context, () => Context.Emit(OpCodes.Mul));
  1270. }
  1271. public static void Sqabs_S(AILEmitterCtx Context)
  1272. {
  1273. EmitScalarSaturatingUnaryOpSx(Context, () => EmitAbs(Context));
  1274. }
  1275. public static void Sqabs_V(AILEmitterCtx Context)
  1276. {
  1277. EmitVectorSaturatingUnaryOpSx(Context, () => EmitAbs(Context));
  1278. }
  1279. public static void Sqadd_S(AILEmitterCtx Context)
  1280. {
  1281. EmitScalarSaturatingBinaryOpSx(Context, SaturatingFlags.Add);
  1282. }
  1283. public static void Sqadd_V(AILEmitterCtx Context)
  1284. {
  1285. EmitVectorSaturatingBinaryOpSx(Context, SaturatingFlags.Add);
  1286. }
  1287. public static void Sqdmulh_S(AILEmitterCtx Context)
  1288. {
  1289. EmitSaturatingBinaryOp(Context, () => EmitDoublingMultiplyHighHalf(Context, Round: false), SaturatingFlags.ScalarSx);
  1290. }
  1291. public static void Sqdmulh_V(AILEmitterCtx Context)
  1292. {
  1293. EmitSaturatingBinaryOp(Context, () => EmitDoublingMultiplyHighHalf(Context, Round: false), SaturatingFlags.VectorSx);
  1294. }
  1295. public static void Sqneg_S(AILEmitterCtx Context)
  1296. {
  1297. EmitScalarSaturatingUnaryOpSx(Context, () => Context.Emit(OpCodes.Neg));
  1298. }
  1299. public static void Sqneg_V(AILEmitterCtx Context)
  1300. {
  1301. EmitVectorSaturatingUnaryOpSx(Context, () => Context.Emit(OpCodes.Neg));
  1302. }
  1303. public static void Sqrdmulh_S(AILEmitterCtx Context)
  1304. {
  1305. EmitSaturatingBinaryOp(Context, () => EmitDoublingMultiplyHighHalf(Context, Round: true), SaturatingFlags.ScalarSx);
  1306. }
  1307. public static void Sqrdmulh_V(AILEmitterCtx Context)
  1308. {
  1309. EmitSaturatingBinaryOp(Context, () => EmitDoublingMultiplyHighHalf(Context, Round: true), SaturatingFlags.VectorSx);
  1310. }
  1311. public static void Sqsub_S(AILEmitterCtx Context)
  1312. {
  1313. EmitScalarSaturatingBinaryOpSx(Context, SaturatingFlags.Sub);
  1314. }
  1315. public static void Sqsub_V(AILEmitterCtx Context)
  1316. {
  1317. EmitVectorSaturatingBinaryOpSx(Context, SaturatingFlags.Sub);
  1318. }
  1319. public static void Sqxtn_S(AILEmitterCtx Context)
  1320. {
  1321. EmitSaturatingNarrowOp(Context, SaturatingNarrowFlags.ScalarSxSx);
  1322. }
  1323. public static void Sqxtn_V(AILEmitterCtx Context)
  1324. {
  1325. EmitSaturatingNarrowOp(Context, SaturatingNarrowFlags.VectorSxSx);
  1326. }
  1327. public static void Sqxtun_S(AILEmitterCtx Context)
  1328. {
  1329. EmitSaturatingNarrowOp(Context, SaturatingNarrowFlags.ScalarSxZx);
  1330. }
  1331. public static void Sqxtun_V(AILEmitterCtx Context)
  1332. {
  1333. EmitSaturatingNarrowOp(Context, SaturatingNarrowFlags.VectorSxZx);
  1334. }
  1335. public static void Srhadd_V(AILEmitterCtx Context)
  1336. {
  1337. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  1338. if (AOptimizations.UseSse2 && Op.Size < 2)
  1339. {
  1340. Type[] TypesSav = new Type[] { IntTypesPerSizeLog2[Op.Size] };
  1341. Type[] TypesSubAdd = new Type[] { VectorIntTypesPerSizeLog2 [Op.Size], VectorIntTypesPerSizeLog2 [Op.Size] };
  1342. Type[] TypesAvg = new Type[] { VectorUIntTypesPerSizeLog2[Op.Size], VectorUIntTypesPerSizeLog2[Op.Size] };
  1343. Context.EmitLdc_I4(Op.Size == 0 ? sbyte.MinValue : short.MinValue);
  1344. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), TypesSav));
  1345. Context.Emit(OpCodes.Dup);
  1346. Context.EmitStvectmp();
  1347. EmitLdvecWithSignedCast(Context, Op.Rn, Op.Size);
  1348. Context.EmitLdvectmp();
  1349. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), TypesSubAdd));
  1350. EmitLdvecWithSignedCast(Context, Op.Rm, Op.Size);
  1351. Context.EmitLdvectmp();
  1352. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), TypesSubAdd));
  1353. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Average), TypesAvg));
  1354. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), TypesSubAdd));
  1355. EmitStvecWithSignedCast(Context, Op.Rd, Op.Size);
  1356. if (Op.RegisterSize == ARegisterSize.SIMD64)
  1357. {
  1358. EmitVectorZeroUpper(Context, Op.Rd);
  1359. }
  1360. }
  1361. else
  1362. {
  1363. EmitVectorBinaryOpSx(Context, () =>
  1364. {
  1365. Context.Emit(OpCodes.Add);
  1366. Context.Emit(OpCodes.Ldc_I4_1);
  1367. Context.Emit(OpCodes.Add);
  1368. Context.Emit(OpCodes.Ldc_I4_1);
  1369. Context.Emit(OpCodes.Shr);
  1370. });
  1371. }
  1372. }
  1373. public static void Ssubl_V(AILEmitterCtx Context)
  1374. {
  1375. if (AOptimizations.UseSse41)
  1376. {
  1377. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  1378. Type[] TypesSrl = new Type[] { VectorIntTypesPerSizeLog2[Op.Size], typeof(byte) };
  1379. Type[] TypesCvt = new Type[] { VectorIntTypesPerSizeLog2[Op.Size] };
  1380. Type[] TypesSub = new Type[] { VectorIntTypesPerSizeLog2[Op.Size + 1],
  1381. VectorIntTypesPerSizeLog2[Op.Size + 1] };
  1382. string[] NamesCvt = new string[] { nameof(Sse41.ConvertToVector128Int16),
  1383. nameof(Sse41.ConvertToVector128Int32),
  1384. nameof(Sse41.ConvertToVector128Int64) };
  1385. int NumBytes = Op.RegisterSize == ARegisterSize.SIMD128 ? 8 : 0;
  1386. EmitLdvecWithSignedCast(Context, Op.Rn, Op.Size);
  1387. Context.EmitLdc_I4(NumBytes);
  1388. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), TypesSrl));
  1389. Context.EmitCall(typeof(Sse41).GetMethod(NamesCvt[Op.Size], TypesCvt));
  1390. EmitLdvecWithUnsignedCast(Context, Op.Rm, Op.Size);
  1391. Context.EmitLdc_I4(NumBytes);
  1392. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), TypesSrl));
  1393. Context.EmitCall(typeof(Sse41).GetMethod(NamesCvt[Op.Size], TypesCvt));
  1394. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), TypesSub));
  1395. EmitStvecWithSignedCast(Context, Op.Rd, Op.Size + 1);
  1396. }
  1397. else
  1398. {
  1399. EmitVectorWidenRnRmBinaryOpSx(Context, () => Context.Emit(OpCodes.Sub));
  1400. }
  1401. }
  1402. public static void Ssubw_V(AILEmitterCtx Context)
  1403. {
  1404. EmitVectorWidenRmBinaryOpSx(Context, () => Context.Emit(OpCodes.Sub));
  1405. }
  1406. public static void Sub_S(AILEmitterCtx Context)
  1407. {
  1408. EmitScalarBinaryOpZx(Context, () => Context.Emit(OpCodes.Sub));
  1409. }
  1410. public static void Sub_V(AILEmitterCtx Context)
  1411. {
  1412. if (AOptimizations.UseSse2)
  1413. {
  1414. EmitSse2Op(Context, nameof(Sse2.Subtract));
  1415. }
  1416. else
  1417. {
  1418. EmitVectorBinaryOpZx(Context, () => Context.Emit(OpCodes.Sub));
  1419. }
  1420. }
  1421. public static void Subhn_V(AILEmitterCtx Context)
  1422. {
  1423. EmitHighNarrow(Context, () => Context.Emit(OpCodes.Sub), Round: false);
  1424. }
  1425. public static void Suqadd_S(AILEmitterCtx Context)
  1426. {
  1427. EmitScalarSaturatingBinaryOpSx(Context, SaturatingFlags.Accumulate);
  1428. }
  1429. public static void Suqadd_V(AILEmitterCtx Context)
  1430. {
  1431. EmitVectorSaturatingBinaryOpSx(Context, SaturatingFlags.Accumulate);
  1432. }
  1433. public static void Uaba_V(AILEmitterCtx Context)
  1434. {
  1435. EmitVectorTernaryOpZx(Context, () =>
  1436. {
  1437. Context.Emit(OpCodes.Sub);
  1438. EmitAbs(Context);
  1439. Context.Emit(OpCodes.Add);
  1440. });
  1441. }
  1442. public static void Uabal_V(AILEmitterCtx Context)
  1443. {
  1444. EmitVectorWidenRnRmTernaryOpZx(Context, () =>
  1445. {
  1446. Context.Emit(OpCodes.Sub);
  1447. EmitAbs(Context);
  1448. Context.Emit(OpCodes.Add);
  1449. });
  1450. }
  1451. public static void Uabd_V(AILEmitterCtx Context)
  1452. {
  1453. EmitVectorBinaryOpZx(Context, () =>
  1454. {
  1455. Context.Emit(OpCodes.Sub);
  1456. EmitAbs(Context);
  1457. });
  1458. }
  1459. public static void Uabdl_V(AILEmitterCtx Context)
  1460. {
  1461. EmitVectorWidenRnRmBinaryOpZx(Context, () =>
  1462. {
  1463. Context.Emit(OpCodes.Sub);
  1464. EmitAbs(Context);
  1465. });
  1466. }
  1467. public static void Uadalp_V(AILEmitterCtx Context)
  1468. {
  1469. EmitAddLongPairwise(Context, Signed: false, Accumulate: true);
  1470. }
  1471. public static void Uaddl_V(AILEmitterCtx Context)
  1472. {
  1473. if (AOptimizations.UseSse41)
  1474. {
  1475. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  1476. Type[] TypesSrl = new Type[] { VectorUIntTypesPerSizeLog2[Op.Size], typeof(byte) };
  1477. Type[] TypesCvt = new Type[] { VectorUIntTypesPerSizeLog2[Op.Size] };
  1478. Type[] TypesAdd = new Type[] { VectorUIntTypesPerSizeLog2[Op.Size + 1],
  1479. VectorUIntTypesPerSizeLog2[Op.Size + 1] };
  1480. string[] NamesCvt = new string[] { nameof(Sse41.ConvertToVector128Int16),
  1481. nameof(Sse41.ConvertToVector128Int32),
  1482. nameof(Sse41.ConvertToVector128Int64) };
  1483. int NumBytes = Op.RegisterSize == ARegisterSize.SIMD128 ? 8 : 0;
  1484. EmitLdvecWithUnsignedCast(Context, Op.Rn, Op.Size);
  1485. Context.EmitLdc_I4(NumBytes);
  1486. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), TypesSrl));
  1487. Context.EmitCall(typeof(Sse41).GetMethod(NamesCvt[Op.Size], TypesCvt));
  1488. EmitLdvecWithUnsignedCast(Context, Op.Rm, Op.Size);
  1489. Context.EmitLdc_I4(NumBytes);
  1490. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), TypesSrl));
  1491. Context.EmitCall(typeof(Sse41).GetMethod(NamesCvt[Op.Size], TypesCvt));
  1492. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), TypesAdd));
  1493. EmitStvecWithUnsignedCast(Context, Op.Rd, Op.Size + 1);
  1494. }
  1495. else
  1496. {
  1497. EmitVectorWidenRnRmBinaryOpZx(Context, () => Context.Emit(OpCodes.Add));
  1498. }
  1499. }
  1500. public static void Uaddlp_V(AILEmitterCtx Context)
  1501. {
  1502. EmitAddLongPairwise(Context, Signed: false, Accumulate: false);
  1503. }
  1504. public static void Uaddlv_V(AILEmitterCtx Context)
  1505. {
  1506. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  1507. int Bytes = Op.GetBitsCount() >> 3;
  1508. int Elems = Bytes >> Op.Size;
  1509. EmitVectorExtractZx(Context, Op.Rn, 0, Op.Size);
  1510. for (int Index = 1; Index < Elems; Index++)
  1511. {
  1512. EmitVectorExtractZx(Context, Op.Rn, Index, Op.Size);
  1513. Context.Emit(OpCodes.Add);
  1514. }
  1515. EmitScalarSet(Context, Op.Rd, Op.Size + 1);
  1516. }
  1517. public static void Uaddw_V(AILEmitterCtx Context)
  1518. {
  1519. EmitVectorWidenRmBinaryOpZx(Context, () => Context.Emit(OpCodes.Add));
  1520. }
  1521. public static void Uhadd_V(AILEmitterCtx Context)
  1522. {
  1523. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  1524. if (AOptimizations.UseSse2 && Op.Size > 0)
  1525. {
  1526. Type[] TypesSrl = new Type[] { VectorUIntTypesPerSizeLog2[Op.Size], typeof(byte) };
  1527. Type[] TypesAndXorAdd = new Type[] { VectorUIntTypesPerSizeLog2[Op.Size], VectorUIntTypesPerSizeLog2[Op.Size] };
  1528. EmitLdvecWithUnsignedCast(Context, Op.Rn, Op.Size);
  1529. Context.Emit(OpCodes.Dup);
  1530. Context.EmitStvectmp();
  1531. EmitLdvecWithUnsignedCast(Context, Op.Rm, Op.Size);
  1532. Context.Emit(OpCodes.Dup);
  1533. Context.EmitStvectmp2();
  1534. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.And), TypesAndXorAdd));
  1535. Context.EmitLdvectmp();
  1536. Context.EmitLdvectmp2();
  1537. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Xor), TypesAndXorAdd));
  1538. Context.EmitLdc_I4(1);
  1539. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical), TypesSrl));
  1540. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), TypesAndXorAdd));
  1541. EmitStvecWithUnsignedCast(Context, Op.Rd, Op.Size);
  1542. if (Op.RegisterSize == ARegisterSize.SIMD64)
  1543. {
  1544. EmitVectorZeroUpper(Context, Op.Rd);
  1545. }
  1546. }
  1547. else
  1548. {
  1549. EmitVectorBinaryOpZx(Context, () =>
  1550. {
  1551. Context.Emit(OpCodes.Add);
  1552. Context.Emit(OpCodes.Ldc_I4_1);
  1553. Context.Emit(OpCodes.Shr_Un);
  1554. });
  1555. }
  1556. }
  1557. public static void Uhsub_V(AILEmitterCtx Context)
  1558. {
  1559. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  1560. if (AOptimizations.UseSse2 && Op.Size < 2)
  1561. {
  1562. Type[] TypesAvgSub = new Type[] { VectorUIntTypesPerSizeLog2[Op.Size], VectorUIntTypesPerSizeLog2[Op.Size] };
  1563. EmitLdvecWithUnsignedCast(Context, Op.Rn, Op.Size);
  1564. Context.Emit(OpCodes.Dup);
  1565. EmitLdvecWithUnsignedCast(Context, Op.Rm, Op.Size);
  1566. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Average), TypesAvgSub));
  1567. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), TypesAvgSub));
  1568. EmitStvecWithUnsignedCast(Context, Op.Rd, Op.Size);
  1569. if (Op.RegisterSize == ARegisterSize.SIMD64)
  1570. {
  1571. EmitVectorZeroUpper(Context, Op.Rd);
  1572. }
  1573. }
  1574. else
  1575. {
  1576. EmitVectorBinaryOpZx(Context, () =>
  1577. {
  1578. Context.Emit(OpCodes.Sub);
  1579. Context.Emit(OpCodes.Ldc_I4_1);
  1580. Context.Emit(OpCodes.Shr_Un);
  1581. });
  1582. }
  1583. }
  1584. public static void Umax_V(AILEmitterCtx Context)
  1585. {
  1586. Type[] Types = new Type[] { typeof(ulong), typeof(ulong) };
  1587. MethodInfo MthdInfo = typeof(Math).GetMethod(nameof(Math.Max), Types);
  1588. EmitVectorBinaryOpZx(Context, () => Context.EmitCall(MthdInfo));
  1589. }
  1590. public static void Umaxp_V(AILEmitterCtx Context)
  1591. {
  1592. Type[] Types = new Type[] { typeof(ulong), typeof(ulong) };
  1593. MethodInfo MthdInfo = typeof(Math).GetMethod(nameof(Math.Max), Types);
  1594. EmitVectorPairwiseOpZx(Context, () => Context.EmitCall(MthdInfo));
  1595. }
  1596. public static void Umin_V(AILEmitterCtx Context)
  1597. {
  1598. Type[] Types = new Type[] { typeof(ulong), typeof(ulong) };
  1599. MethodInfo MthdInfo = typeof(Math).GetMethod(nameof(Math.Min), Types);
  1600. EmitVectorBinaryOpZx(Context, () => Context.EmitCall(MthdInfo));
  1601. }
  1602. public static void Uminp_V(AILEmitterCtx Context)
  1603. {
  1604. Type[] Types = new Type[] { typeof(ulong), typeof(ulong) };
  1605. MethodInfo MthdInfo = typeof(Math).GetMethod(nameof(Math.Min), Types);
  1606. EmitVectorPairwiseOpZx(Context, () => Context.EmitCall(MthdInfo));
  1607. }
  1608. public static void Umlal_V(AILEmitterCtx Context)
  1609. {
  1610. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  1611. if (AOptimizations.UseSse41 && Op.Size < 2)
  1612. {
  1613. Type[] TypesSrl = new Type[] { VectorUIntTypesPerSizeLog2[Op.Size], typeof(byte) };
  1614. Type[] TypesCvt = new Type[] { VectorUIntTypesPerSizeLog2[Op.Size] };
  1615. Type[] TypesMulAdd = new Type[] { VectorIntTypesPerSizeLog2 [Op.Size + 1],
  1616. VectorIntTypesPerSizeLog2 [Op.Size + 1] };
  1617. Type TypeMul = Op.Size == 0 ? typeof(Sse2) : typeof(Sse41);
  1618. string NameCvt = Op.Size == 0
  1619. ? nameof(Sse41.ConvertToVector128Int16)
  1620. : nameof(Sse41.ConvertToVector128Int32);
  1621. int NumBytes = Op.RegisterSize == ARegisterSize.SIMD128 ? 8 : 0;
  1622. EmitLdvecWithUnsignedCast(Context, Op.Rd, Op.Size + 1);
  1623. EmitLdvecWithUnsignedCast(Context, Op.Rn, Op.Size);
  1624. Context.EmitLdc_I4(NumBytes);
  1625. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), TypesSrl));
  1626. Context.EmitCall(typeof(Sse41).GetMethod(NameCvt, TypesCvt));
  1627. EmitLdvecWithUnsignedCast(Context, Op.Rm, Op.Size);
  1628. Context.EmitLdc_I4(NumBytes);
  1629. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), TypesSrl));
  1630. Context.EmitCall(typeof(Sse41).GetMethod(NameCvt, TypesCvt));
  1631. Context.EmitCall(TypeMul.GetMethod(nameof(Sse2.MultiplyLow), TypesMulAdd));
  1632. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), TypesMulAdd));
  1633. EmitStvecWithUnsignedCast(Context, Op.Rd, Op.Size + 1);
  1634. }
  1635. else
  1636. {
  1637. EmitVectorWidenRnRmTernaryOpZx(Context, () =>
  1638. {
  1639. Context.Emit(OpCodes.Mul);
  1640. Context.Emit(OpCodes.Add);
  1641. });
  1642. }
  1643. }
  1644. public static void Umlsl_V(AILEmitterCtx Context)
  1645. {
  1646. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  1647. if (AOptimizations.UseSse41 && Op.Size < 2)
  1648. {
  1649. Type[] TypesSrl = new Type[] { VectorUIntTypesPerSizeLog2[Op.Size], typeof(byte) };
  1650. Type[] TypesCvt = new Type[] { VectorUIntTypesPerSizeLog2[Op.Size] };
  1651. Type[] TypesMulSub = new Type[] { VectorIntTypesPerSizeLog2 [Op.Size + 1],
  1652. VectorIntTypesPerSizeLog2 [Op.Size + 1] };
  1653. Type TypeMul = Op.Size == 0 ? typeof(Sse2) : typeof(Sse41);
  1654. string NameCvt = Op.Size == 0
  1655. ? nameof(Sse41.ConvertToVector128Int16)
  1656. : nameof(Sse41.ConvertToVector128Int32);
  1657. int NumBytes = Op.RegisterSize == ARegisterSize.SIMD128 ? 8 : 0;
  1658. EmitLdvecWithUnsignedCast(Context, Op.Rd, Op.Size + 1);
  1659. EmitLdvecWithUnsignedCast(Context, Op.Rn, Op.Size);
  1660. Context.EmitLdc_I4(NumBytes);
  1661. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), TypesSrl));
  1662. Context.EmitCall(typeof(Sse41).GetMethod(NameCvt, TypesCvt));
  1663. EmitLdvecWithUnsignedCast(Context, Op.Rm, Op.Size);
  1664. Context.EmitLdc_I4(NumBytes);
  1665. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), TypesSrl));
  1666. Context.EmitCall(typeof(Sse41).GetMethod(NameCvt, TypesCvt));
  1667. Context.EmitCall(TypeMul.GetMethod(nameof(Sse2.MultiplyLow), TypesMulSub));
  1668. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), TypesMulSub));
  1669. EmitStvecWithUnsignedCast(Context, Op.Rd, Op.Size + 1);
  1670. }
  1671. else
  1672. {
  1673. EmitVectorWidenRnRmTernaryOpZx(Context, () =>
  1674. {
  1675. Context.Emit(OpCodes.Mul);
  1676. Context.Emit(OpCodes.Sub);
  1677. });
  1678. }
  1679. }
  1680. public static void Umull_V(AILEmitterCtx Context)
  1681. {
  1682. EmitVectorWidenRnRmBinaryOpZx(Context, () => Context.Emit(OpCodes.Mul));
  1683. }
  1684. public static void Uqadd_S(AILEmitterCtx Context)
  1685. {
  1686. EmitScalarSaturatingBinaryOpZx(Context, SaturatingFlags.Add);
  1687. }
  1688. public static void Uqadd_V(AILEmitterCtx Context)
  1689. {
  1690. EmitVectorSaturatingBinaryOpZx(Context, SaturatingFlags.Add);
  1691. }
  1692. public static void Uqsub_S(AILEmitterCtx Context)
  1693. {
  1694. EmitScalarSaturatingBinaryOpZx(Context, SaturatingFlags.Sub);
  1695. }
  1696. public static void Uqsub_V(AILEmitterCtx Context)
  1697. {
  1698. EmitVectorSaturatingBinaryOpZx(Context, SaturatingFlags.Sub);
  1699. }
  1700. public static void Uqxtn_S(AILEmitterCtx Context)
  1701. {
  1702. EmitSaturatingNarrowOp(Context, SaturatingNarrowFlags.ScalarZxZx);
  1703. }
  1704. public static void Uqxtn_V(AILEmitterCtx Context)
  1705. {
  1706. EmitSaturatingNarrowOp(Context, SaturatingNarrowFlags.VectorZxZx);
  1707. }
  1708. public static void Urhadd_V(AILEmitterCtx Context)
  1709. {
  1710. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  1711. if (AOptimizations.UseSse2 && Op.Size < 2)
  1712. {
  1713. Type[] TypesAvg = new Type[] { VectorUIntTypesPerSizeLog2[Op.Size], VectorUIntTypesPerSizeLog2[Op.Size] };
  1714. EmitLdvecWithUnsignedCast(Context, Op.Rn, Op.Size);
  1715. EmitLdvecWithUnsignedCast(Context, Op.Rm, Op.Size);
  1716. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Average), TypesAvg));
  1717. EmitStvecWithUnsignedCast(Context, Op.Rd, Op.Size);
  1718. if (Op.RegisterSize == ARegisterSize.SIMD64)
  1719. {
  1720. EmitVectorZeroUpper(Context, Op.Rd);
  1721. }
  1722. }
  1723. else
  1724. {
  1725. EmitVectorBinaryOpZx(Context, () =>
  1726. {
  1727. Context.Emit(OpCodes.Add);
  1728. Context.Emit(OpCodes.Ldc_I4_1);
  1729. Context.Emit(OpCodes.Add);
  1730. Context.Emit(OpCodes.Ldc_I4_1);
  1731. Context.Emit(OpCodes.Shr_Un);
  1732. });
  1733. }
  1734. }
  1735. public static void Usqadd_S(AILEmitterCtx Context)
  1736. {
  1737. EmitScalarSaturatingBinaryOpZx(Context, SaturatingFlags.Accumulate);
  1738. }
  1739. public static void Usqadd_V(AILEmitterCtx Context)
  1740. {
  1741. EmitVectorSaturatingBinaryOpZx(Context, SaturatingFlags.Accumulate);
  1742. }
  1743. public static void Usubl_V(AILEmitterCtx Context)
  1744. {
  1745. if (AOptimizations.UseSse41)
  1746. {
  1747. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  1748. Type[] TypesSrl = new Type[] { VectorUIntTypesPerSizeLog2[Op.Size], typeof(byte) };
  1749. Type[] TypesCvt = new Type[] { VectorUIntTypesPerSizeLog2[Op.Size] };
  1750. Type[] TypesSub = new Type[] { VectorUIntTypesPerSizeLog2[Op.Size + 1],
  1751. VectorUIntTypesPerSizeLog2[Op.Size + 1] };
  1752. string[] NamesCvt = new string[] { nameof(Sse41.ConvertToVector128Int16),
  1753. nameof(Sse41.ConvertToVector128Int32),
  1754. nameof(Sse41.ConvertToVector128Int64) };
  1755. int NumBytes = Op.RegisterSize == ARegisterSize.SIMD128 ? 8 : 0;
  1756. EmitLdvecWithUnsignedCast(Context, Op.Rn, Op.Size);
  1757. Context.EmitLdc_I4(NumBytes);
  1758. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), TypesSrl));
  1759. Context.EmitCall(typeof(Sse41).GetMethod(NamesCvt[Op.Size], TypesCvt));
  1760. EmitLdvecWithUnsignedCast(Context, Op.Rm, Op.Size);
  1761. Context.EmitLdc_I4(NumBytes);
  1762. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), TypesSrl));
  1763. Context.EmitCall(typeof(Sse41).GetMethod(NamesCvt[Op.Size], TypesCvt));
  1764. Context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), TypesSub));
  1765. EmitStvecWithUnsignedCast(Context, Op.Rd, Op.Size + 1);
  1766. }
  1767. else
  1768. {
  1769. EmitVectorWidenRnRmBinaryOpZx(Context, () => Context.Emit(OpCodes.Sub));
  1770. }
  1771. }
  1772. public static void Usubw_V(AILEmitterCtx Context)
  1773. {
  1774. EmitVectorWidenRmBinaryOpZx(Context, () => Context.Emit(OpCodes.Sub));
  1775. }
  1776. private static void EmitAbs(AILEmitterCtx Context)
  1777. {
  1778. AILLabel LblTrue = new AILLabel();
  1779. Context.Emit(OpCodes.Dup);
  1780. Context.Emit(OpCodes.Ldc_I4_0);
  1781. Context.Emit(OpCodes.Bge_S, LblTrue);
  1782. Context.Emit(OpCodes.Neg);
  1783. Context.MarkLabel(LblTrue);
  1784. }
  1785. private static void EmitAddLongPairwise(AILEmitterCtx Context, bool Signed, bool Accumulate)
  1786. {
  1787. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  1788. int Words = Op.GetBitsCount() >> 4;
  1789. int Pairs = Words >> Op.Size;
  1790. for (int Index = 0; Index < Pairs; Index++)
  1791. {
  1792. int Idx = Index << 1;
  1793. EmitVectorExtract(Context, Op.Rn, Idx, Op.Size, Signed);
  1794. EmitVectorExtract(Context, Op.Rn, Idx + 1, Op.Size, Signed);
  1795. Context.Emit(OpCodes.Add);
  1796. if (Accumulate)
  1797. {
  1798. EmitVectorExtract(Context, Op.Rd, Index, Op.Size + 1, Signed);
  1799. Context.Emit(OpCodes.Add);
  1800. }
  1801. EmitVectorInsertTmp(Context, Index, Op.Size + 1);
  1802. }
  1803. Context.EmitLdvectmp();
  1804. Context.EmitStvec(Op.Rd);
  1805. if (Op.RegisterSize == ARegisterSize.SIMD64)
  1806. {
  1807. EmitVectorZeroUpper(Context, Op.Rd);
  1808. }
  1809. }
  1810. private static void EmitDoublingMultiplyHighHalf(AILEmitterCtx Context, bool Round)
  1811. {
  1812. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  1813. int ESize = 8 << Op.Size;
  1814. Context.Emit(OpCodes.Mul);
  1815. if (!Round)
  1816. {
  1817. Context.EmitAsr(ESize - 1);
  1818. }
  1819. else
  1820. {
  1821. long RoundConst = 1L << (ESize - 1);
  1822. AILLabel LblTrue = new AILLabel();
  1823. Context.EmitLsl(1);
  1824. Context.EmitLdc_I8(RoundConst);
  1825. Context.Emit(OpCodes.Add);
  1826. Context.EmitAsr(ESize);
  1827. Context.Emit(OpCodes.Dup);
  1828. Context.EmitLdc_I8((long)int.MinValue);
  1829. Context.Emit(OpCodes.Bne_Un_S, LblTrue);
  1830. Context.Emit(OpCodes.Neg);
  1831. Context.MarkLabel(LblTrue);
  1832. }
  1833. }
  1834. private static void EmitHighNarrow(AILEmitterCtx Context, Action Emit, bool Round)
  1835. {
  1836. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  1837. int Elems = 8 >> Op.Size;
  1838. int ESize = 8 << Op.Size;
  1839. int Part = Op.RegisterSize == ARegisterSize.SIMD128 ? Elems : 0;
  1840. long RoundConst = 1L << (ESize - 1);
  1841. if (Part != 0)
  1842. {
  1843. Context.EmitLdvec(Op.Rd);
  1844. Context.EmitStvectmp();
  1845. }
  1846. for (int Index = 0; Index < Elems; Index++)
  1847. {
  1848. EmitVectorExtractZx(Context, Op.Rn, Index, Op.Size + 1);
  1849. EmitVectorExtractZx(Context, Op.Rm, Index, Op.Size + 1);
  1850. Emit();
  1851. if (Round)
  1852. {
  1853. Context.EmitLdc_I8(RoundConst);
  1854. Context.Emit(OpCodes.Add);
  1855. }
  1856. Context.EmitLsr(ESize);
  1857. EmitVectorInsertTmp(Context, Part + Index, Op.Size);
  1858. }
  1859. Context.EmitLdvectmp();
  1860. Context.EmitStvec(Op.Rd);
  1861. if (Part == 0)
  1862. {
  1863. EmitVectorZeroUpper(Context, Op.Rd);
  1864. }
  1865. }
  1866. }
  1867. }