AInstEmitSimd.cs 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270
  1. using ChocolArm64.Decoder;
  2. using ChocolArm64.State;
  3. using ChocolArm64.Translation;
  4. using System;
  5. using System.Reflection;
  6. using System.Reflection.Emit;
  7. using static ChocolArm64.Instruction.AInstEmitMemoryHelper;
  8. namespace ChocolArm64.Instruction
  9. {
  10. static partial class AInstEmit
  11. {
  12. public static void Add_V(AILEmitterCtx Context) => EmitVectorBinaryZx(Context, OpCodes.Add);
  13. public static void Addp_V(AILEmitterCtx Context)
  14. {
  15. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  16. Context.EmitLdvec(Op.Rn);
  17. Context.EmitLdvec(Op.Rm);
  18. Context.EmitLdc_I4(Op.Size);
  19. ASoftFallback.EmitCall(Context,
  20. nameof(ASoftFallback.Addp64),
  21. nameof(ASoftFallback.Addp128));
  22. Context.EmitStvec(Op.Rd);
  23. }
  24. public static void Addv_V(AILEmitterCtx Context) => EmitVectorAddv(Context);
  25. public static void And_V(AILEmitterCtx Context) => EmitVectorBinaryZx(Context, OpCodes.And);
  26. public static void Bic_V(AILEmitterCtx Context) => EmitVectorBic(Context);
  27. public static void Bic_Vi(AILEmitterCtx Context)
  28. {
  29. AOpCodeSimdImm Op = (AOpCodeSimdImm)Context.CurrOp;
  30. Context.EmitLdvec(Op.Rd);
  31. Context.EmitLdc_I8(Op.Imm);
  32. Context.EmitLdc_I4(Op.Size);
  33. ASoftFallback.EmitCall(Context,
  34. nameof(ASoftFallback.Bic_Vi64),
  35. nameof(ASoftFallback.Bic_Vi128));
  36. Context.EmitStvec(Op.Rd);
  37. }
  38. public static void Bsl_V(AILEmitterCtx Context) => EmitVectorBsl(Context);
  39. public static void Cmeq_V(AILEmitterCtx Context) => EmitVectorCmp(Context, OpCodes.Beq_S);
  40. public static void Cmge_V(AILEmitterCtx Context) => EmitVectorCmp(Context, OpCodes.Bge_S);
  41. public static void Cmgt_V(AILEmitterCtx Context) => EmitVectorCmp(Context, OpCodes.Bgt_S);
  42. public static void Cmhi_V(AILEmitterCtx Context) => EmitVectorCmp(Context, OpCodes.Bgt_Un_S);
  43. public static void Cmhs_V(AILEmitterCtx Context) => EmitVectorCmp(Context, OpCodes.Bge_Un_S);
  44. public static void Cmle_V(AILEmitterCtx Context) => EmitVectorCmp(Context, OpCodes.Ble_S);
  45. public static void Cmlt_V(AILEmitterCtx Context) => EmitVectorCmp(Context, OpCodes.Blt_S);
  46. public static void Cnt_V(AILEmitterCtx Context)
  47. {
  48. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  49. Context.EmitLdvec(Op.Rn);
  50. ASoftFallback.EmitCall(Context,
  51. nameof(ASoftFallback.Cnt64),
  52. nameof(ASoftFallback.Cnt128));
  53. Context.EmitStvec(Op.Rd);
  54. }
  55. public static void Dup_Gp(AILEmitterCtx Context)
  56. {
  57. AOpCodeSimdIns Op = (AOpCodeSimdIns)Context.CurrOp;
  58. Context.EmitLdintzr(Op.Rn);
  59. Context.EmitLdc_I4(Op.Size);
  60. ASoftFallback.EmitCall(Context,
  61. nameof(ASoftFallback.Dup_Gp64),
  62. nameof(ASoftFallback.Dup_Gp128));
  63. Context.EmitStvec(Op.Rd);
  64. }
  65. public static void Dup_V(AILEmitterCtx Context)
  66. {
  67. AOpCodeSimdIns Op = (AOpCodeSimdIns)Context.CurrOp;
  68. Context.EmitLdvec(Op.Rn);
  69. Context.EmitLdc_I4(Op.DstIndex);
  70. Context.EmitLdc_I4(Op.Size);
  71. ASoftFallback.EmitCall(Context,
  72. nameof(ASoftFallback.Dup_V64),
  73. nameof(ASoftFallback.Dup_V128));
  74. Context.EmitStvec(Op.Rd);
  75. }
  76. public static void Eor_V(AILEmitterCtx Context) => EmitVectorBinaryZx(Context, OpCodes.Xor);
  77. public static void Fadd_V(AILEmitterCtx Context) => EmitVectorBinaryFOp(Context, OpCodes.Add);
  78. public static void Fcvtzs_V(AILEmitterCtx Context) => EmitVectorFcvts(Context);
  79. public static void Fcvtzu_V(AILEmitterCtx Context) => EmitVectorFcvtu(Context);
  80. public static void Fmla_V(AILEmitterCtx Context)
  81. {
  82. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  83. Context.EmitLdvec(Op.Rd);
  84. Context.EmitLdvec(Op.Rn);
  85. Context.EmitLdvec(Op.Rm);
  86. Context.EmitLdc_I4(Op.SizeF);
  87. ASoftFallback.EmitCall(Context,
  88. nameof(ASoftFallback.Fmla64),
  89. nameof(ASoftFallback.Fmla128));
  90. Context.EmitStvec(Op.Rd);
  91. }
  92. public static void Fmla_Vs(AILEmitterCtx Context)
  93. {
  94. AOpCodeSimdRegElem Op = (AOpCodeSimdRegElem)Context.CurrOp;
  95. Context.EmitLdvec(Op.Rd);
  96. Context.EmitLdvec(Op.Rn);
  97. Context.EmitLdvec(Op.Rm);
  98. Context.EmitLdc_I4(Op.Index);
  99. Context.EmitLdc_I4(Op.SizeF);
  100. ASoftFallback.EmitCall(Context,
  101. nameof(ASoftFallback.Fmla_Ve64),
  102. nameof(ASoftFallback.Fmla_Ve128));
  103. Context.EmitStvec(Op.Rd);
  104. }
  105. public static void Fmov_V(AILEmitterCtx Context)
  106. {
  107. AOpCodeSimdImm Op = (AOpCodeSimdImm)Context.CurrOp;
  108. Context.EmitLdc_I8(Op.Imm);
  109. Context.EmitLdc_I4(Op.Size + 2);
  110. ASoftFallback.EmitCall(Context,
  111. nameof(ASoftFallback.Dup_Gp64),
  112. nameof(ASoftFallback.Dup_Gp128));
  113. Context.EmitStvec(Op.Rd);
  114. }
  115. public static void Fmul_V(AILEmitterCtx Context) => EmitVectorBinaryFOp(Context, OpCodes.Mul);
  116. public static void Fmul_Vs(AILEmitterCtx Context)
  117. {
  118. AOpCodeSimdRegElem Op = (AOpCodeSimdRegElem)Context.CurrOp;
  119. Context.EmitLdvec(Op.Rn);
  120. Context.EmitLdvec(Op.Rm);
  121. Context.EmitLdc_I4(Op.Index);
  122. Context.EmitLdc_I4(Op.SizeF);
  123. ASoftFallback.EmitCall(Context,
  124. nameof(ASoftFallback.Fmul_Ve64),
  125. nameof(ASoftFallback.Fmul_Ve128));
  126. Context.EmitStvec(Op.Rd);
  127. }
  128. public static void Fsub_V(AILEmitterCtx Context) => EmitVectorBinaryFOp(Context, OpCodes.Sub);
  129. public static void Ins_Gp(AILEmitterCtx Context)
  130. {
  131. AOpCodeSimdIns Op = (AOpCodeSimdIns)Context.CurrOp;
  132. Context.EmitLdvec(Op.Rd);
  133. Context.EmitLdintzr(Op.Rn);
  134. Context.EmitLdc_I4(Op.DstIndex);
  135. Context.EmitLdc_I4(Op.Size);
  136. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.Ins_Gp));
  137. Context.EmitStvec(Op.Rd);
  138. }
  139. public static void Ins_V(AILEmitterCtx Context)
  140. {
  141. AOpCodeSimdIns Op = (AOpCodeSimdIns)Context.CurrOp;
  142. Context.EmitLdvec(Op.Rd);
  143. Context.EmitLdvec(Op.Rn);
  144. Context.EmitLdc_I4(Op.SrcIndex);
  145. Context.EmitLdc_I4(Op.DstIndex);
  146. Context.EmitLdc_I4(Op.Size);
  147. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.Ins_V));
  148. Context.EmitStvec(Op.Rd);
  149. }
  150. public static void Ld__Vms(AILEmitterCtx Context) => EmitSimdMemMs(Context, IsLoad: true);
  151. public static void Ld__Vss(AILEmitterCtx Context) => EmitSimdMemSs(Context, IsLoad: true);
  152. public static void Mla_V(AILEmitterCtx Context) => EmitVectorMla(Context);
  153. public static void Movi_V(AILEmitterCtx Context) => EmitMovi_V(Context, false);
  154. public static void Mul_V(AILEmitterCtx Context) => EmitVectorBinaryZx(Context, OpCodes.Mul);
  155. public static void Mvni_V(AILEmitterCtx Context) => EmitMovi_V(Context, true);
  156. private static void EmitMovi_V(AILEmitterCtx Context, bool Not)
  157. {
  158. AOpCodeSimdImm Op = (AOpCodeSimdImm)Context.CurrOp;
  159. Context.EmitLdc_I8(Not ? ~Op.Imm : Op.Imm);
  160. Context.EmitLdc_I4(Op.Size);
  161. ASoftFallback.EmitCall(Context,
  162. nameof(ASoftFallback.Dup_Gp64),
  163. nameof(ASoftFallback.Dup_Gp128));
  164. Context.EmitStvec(Op.Rd);
  165. }
  166. public static void Neg_V(AILEmitterCtx Context) => EmitVectorUnarySx(Context, OpCodes.Neg);
  167. public static void Not_V(AILEmitterCtx Context) => EmitVectorUnaryZx(Context, OpCodes.Not);
  168. public static void Orr_V(AILEmitterCtx Context) => EmitVectorBinaryZx(Context, OpCodes.Or);
  169. public static void Orr_Vi(AILEmitterCtx Context)
  170. {
  171. AOpCodeSimdImm Op = (AOpCodeSimdImm)Context.CurrOp;
  172. Context.EmitLdvec(Op.Rd);
  173. Context.EmitLdc_I8(Op.Imm);
  174. Context.EmitLdc_I4(Op.Size);
  175. ASoftFallback.EmitCall(Context,
  176. nameof(ASoftFallback.Orr_Vi64),
  177. nameof(ASoftFallback.Orr_Vi128));
  178. Context.EmitStvec(Op.Rd);
  179. }
  180. public static void Saddw_V(AILEmitterCtx Context)
  181. {
  182. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  183. Context.EmitLdvec(Op.Rn);
  184. Context.EmitLdvec(Op.Rm);
  185. Context.EmitLdc_I4(Op.Size);
  186. ASoftFallback.EmitCall(Context,
  187. nameof(ASoftFallback.Saddw),
  188. nameof(ASoftFallback.Saddw2));
  189. Context.EmitStvec(Op.Rd);
  190. }
  191. public static void Scvtf_V(AILEmitterCtx Context) => EmitVectorScvtf(Context);
  192. public static void Shl_V(AILEmitterCtx Context)
  193. {
  194. AOpCodeSimdShImm Op = (AOpCodeSimdShImm)Context.CurrOp;
  195. EmitVectorImmBinaryZx(Context, OpCodes.Shl, Op.Imm - (8 << Op.Size));
  196. }
  197. public static void Shrn_V(AILEmitterCtx Context)
  198. {
  199. AOpCodeSimdShImm Op = (AOpCodeSimdShImm)Context.CurrOp;
  200. EmitVectorImmNarrowBinaryZx(Context, OpCodes.Shr_Un, (8 << (Op.Size + 1)) - Op.Imm);
  201. }
  202. public static void Smax_V(AILEmitterCtx Context) => EmitVectorSmax(Context);
  203. public static void Smin_V(AILEmitterCtx Context) => EmitVectorSmin(Context);
  204. public static void Sshl_V(AILEmitterCtx Context) => EmitVectorSshl(Context);
  205. public static void Sshll_V(AILEmitterCtx Context)
  206. {
  207. AOpCodeSimdShImm Op = (AOpCodeSimdShImm)Context.CurrOp;
  208. Context.EmitLdvec(Op.Rn);
  209. Context.EmitLdc_I4(Op.Imm - (8 << Op.Size));
  210. Context.EmitLdc_I4(Op.Size);
  211. ASoftFallback.EmitCall(Context,
  212. nameof(ASoftFallback.Sshll),
  213. nameof(ASoftFallback.Sshll2));
  214. Context.EmitStvec(Op.Rd);
  215. }
  216. public static void Sshr_V(AILEmitterCtx Context)
  217. {
  218. AOpCodeSimdShImm Op = (AOpCodeSimdShImm)Context.CurrOp;
  219. EmitVectorImmBinarySx(Context, OpCodes.Shr, (8 << (Op.Size + 1)) - Op.Imm);
  220. }
  221. public static void St__Vms(AILEmitterCtx Context) => EmitSimdMemMs(Context, IsLoad: false);
  222. public static void St__Vss(AILEmitterCtx Context) => EmitSimdMemSs(Context, IsLoad: false);
  223. public static void Sub_V(AILEmitterCtx Context) => EmitVectorBinaryZx(Context, OpCodes.Sub);
  224. public static void Tbl_V(AILEmitterCtx Context)
  225. {
  226. AOpCodeSimdTbl Op = (AOpCodeSimdTbl)Context.CurrOp;
  227. Context.EmitLdvec(Op.Rm);
  228. for (int Index = 0; Index < Op.Size; Index++)
  229. {
  230. Context.EmitLdvec((Op.Rn + Index) & 0x1f);
  231. }
  232. switch (Op.Size)
  233. {
  234. case 1: ASoftFallback.EmitCall(Context,
  235. nameof(ASoftFallback.Tbl1_V64),
  236. nameof(ASoftFallback.Tbl1_V128)); break;
  237. case 2: ASoftFallback.EmitCall(Context,
  238. nameof(ASoftFallback.Tbl2_V64),
  239. nameof(ASoftFallback.Tbl2_V128)); break;
  240. case 3: ASoftFallback.EmitCall(Context,
  241. nameof(ASoftFallback.Tbl3_V64),
  242. nameof(ASoftFallback.Tbl3_V128)); break;
  243. case 4: ASoftFallback.EmitCall(Context,
  244. nameof(ASoftFallback.Tbl4_V64),
  245. nameof(ASoftFallback.Tbl4_V128)); break;
  246. default: throw new InvalidOperationException();
  247. }
  248. Context.EmitStvec(Op.Rd);
  249. }
  250. public static void Uaddlv_V(AILEmitterCtx Context)
  251. {
  252. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  253. Context.EmitLdvec(Op.Rn);
  254. Context.EmitLdc_I4(Op.Size);
  255. ASoftFallback.EmitCall(Context,
  256. nameof(ASoftFallback.Uaddlv64),
  257. nameof(ASoftFallback.Uaddlv128));
  258. Context.EmitStvec(Op.Rd);
  259. }
  260. public static void Uaddw_V(AILEmitterCtx Context)
  261. {
  262. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  263. Context.EmitLdvec(Op.Rn);
  264. Context.EmitLdvec(Op.Rm);
  265. Context.EmitLdc_I4(Op.Size);
  266. ASoftFallback.EmitCall(Context,
  267. nameof(ASoftFallback.Uaddw),
  268. nameof(ASoftFallback.Uaddw2));
  269. Context.EmitStvec(Op.Rd);
  270. }
  271. public static void Ucvtf_V(AILEmitterCtx Context)
  272. {
  273. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  274. Context.EmitLdvec(Op.Rn);
  275. if (Op.Size == 0)
  276. {
  277. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.Ucvtf_V_F));
  278. }
  279. else if (Op.Size == 1)
  280. {
  281. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.Ucvtf_V_D));
  282. }
  283. else
  284. {
  285. throw new InvalidOperationException();
  286. }
  287. Context.EmitStvec(Op.Rd);
  288. }
  289. public static void Umov_S(AILEmitterCtx Context)
  290. {
  291. AOpCodeSimdIns Op = (AOpCodeSimdIns)Context.CurrOp;
  292. Context.EmitLdvec(Op.Rn);
  293. Context.EmitLdc_I4(Op.DstIndex);
  294. Context.EmitLdc_I4(Op.Size);
  295. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.ExtractVec));
  296. Context.EmitStintzr(Op.Rd);
  297. }
  298. public static void Ushl_V(AILEmitterCtx Context) => EmitVectorUshl(Context);
  299. public static void Ushll_V(AILEmitterCtx Context)
  300. {
  301. AOpCodeSimdShImm Op = (AOpCodeSimdShImm)Context.CurrOp;
  302. Context.EmitLdvec(Op.Rn);
  303. Context.EmitLdc_I4(Op.Imm - (8 << Op.Size));
  304. Context.EmitLdc_I4(Op.Size);
  305. ASoftFallback.EmitCall(Context,
  306. nameof(ASoftFallback.Ushll),
  307. nameof(ASoftFallback.Ushll2));
  308. Context.EmitStvec(Op.Rd);
  309. }
  310. public static void Ushr_V(AILEmitterCtx Context)
  311. {
  312. EmitVectorShr(Context, ShrFlags.None);
  313. }
  314. public static void Usra_V(AILEmitterCtx Context)
  315. {
  316. EmitVectorShr(Context, ShrFlags.Accumulate);
  317. }
  318. public static void Uzp1_V(AILEmitterCtx Context)
  319. {
  320. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  321. Context.EmitLdvec(Op.Rn);
  322. Context.EmitLdvec(Op.Rm);
  323. Context.EmitLdc_I4(Op.Size);
  324. ASoftFallback.EmitCall(Context,
  325. nameof(ASoftFallback.Uzp1_V64),
  326. nameof(ASoftFallback.Uzp1_V128));
  327. Context.EmitStvec(Op.Rd);
  328. }
  329. public static void Xtn_V(AILEmitterCtx Context)
  330. {
  331. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  332. Context.EmitLdvec(Op.Rn);
  333. Context.EmitLdc_I4(Op.Size);
  334. ASoftFallback.EmitCall(Context,
  335. nameof(ASoftFallback.Xtn),
  336. nameof(ASoftFallback.Xtn2));
  337. Context.EmitStvec(Op.Rd);
  338. }
  339. private static void EmitSimdMemMs(AILEmitterCtx Context, bool IsLoad)
  340. {
  341. AOpCodeSimdMemMs Op = (AOpCodeSimdMemMs)Context.CurrOp;
  342. int Offset = 0;
  343. for (int Rep = 0; Rep < Op.Reps; Rep++)
  344. for (int Elem = 0; Elem < Op.Elems; Elem++)
  345. for (int SElem = 0; SElem < Op.SElems; SElem++)
  346. {
  347. int Rtt = (Op.Rt + Rep + SElem) & 0x1f;
  348. if (IsLoad)
  349. {
  350. Context.EmitLdvec(Rtt);
  351. Context.EmitLdc_I4(Elem);
  352. Context.EmitLdc_I4(Op.Size);
  353. Context.EmitLdarg(ATranslatedSub.MemoryArgIdx);
  354. Context.EmitLdint(Op.Rn);
  355. Context.EmitLdc_I8(Offset);
  356. Context.Emit(OpCodes.Add);
  357. EmitReadZxCall(Context, Op.Size);
  358. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.InsertVec));
  359. Context.EmitStvec(Rtt);
  360. if (Op.RegisterSize == ARegisterSize.SIMD64 && Elem == Op.Elems - 1)
  361. {
  362. EmitVectorZeroUpper(Context, Rtt);
  363. }
  364. }
  365. else
  366. {
  367. Context.EmitLdarg(ATranslatedSub.MemoryArgIdx);
  368. Context.EmitLdint(Op.Rn);
  369. Context.EmitLdc_I8(Offset);
  370. Context.Emit(OpCodes.Add);
  371. Context.EmitLdvec(Rtt);
  372. Context.EmitLdc_I4(Elem);
  373. Context.EmitLdc_I4(Op.Size);
  374. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.ExtractVec));
  375. EmitWriteCall(Context, Op.Size);
  376. }
  377. Offset += 1 << Op.Size;
  378. }
  379. if (Op.WBack)
  380. {
  381. Context.EmitLdint(Op.Rn);
  382. if (Op.Rm != ARegisters.ZRIndex)
  383. {
  384. Context.EmitLdint(Op.Rm);
  385. }
  386. else
  387. {
  388. Context.EmitLdc_I8(Offset);
  389. }
  390. Context.Emit(OpCodes.Add);
  391. Context.EmitStint(Op.Rn);
  392. }
  393. }
  394. private static void EmitSimdMemSs(AILEmitterCtx Context, bool IsLoad)
  395. {
  396. AOpCodeSimdMemSs Op = (AOpCodeSimdMemSs)Context.CurrOp;
  397. //TODO: Replicate mode.
  398. int Offset = 0;
  399. for (int SElem = 0; SElem < Op.SElems; SElem++)
  400. {
  401. int Rt = (Op.Rt + SElem) & 0x1f;
  402. if (IsLoad)
  403. {
  404. Context.EmitLdvec(Rt);
  405. Context.EmitLdc_I4(Op.Index);
  406. Context.EmitLdc_I4(Op.Size);
  407. Context.EmitLdarg(ATranslatedSub.MemoryArgIdx);
  408. Context.EmitLdint(Op.Rn);
  409. Context.EmitLdc_I8(Offset);
  410. Context.Emit(OpCodes.Add);
  411. EmitReadZxCall(Context, Op.Size);
  412. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.InsertVec));
  413. Context.EmitStvec(Rt);
  414. if (Op.RegisterSize == ARegisterSize.SIMD64)
  415. {
  416. EmitVectorZeroUpper(Context, Rt);
  417. }
  418. }
  419. else
  420. {
  421. Context.EmitLdarg(ATranslatedSub.MemoryArgIdx);
  422. Context.EmitLdint(Op.Rn);
  423. Context.EmitLdc_I8(Offset);
  424. Context.Emit(OpCodes.Add);
  425. Context.EmitLdvec(Rt);
  426. Context.EmitLdc_I4(Op.Index);
  427. Context.EmitLdc_I4(Op.Size);
  428. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.ExtractVec));
  429. EmitWriteCall(Context, Op.Size);
  430. }
  431. Offset += 1 << Op.Size;
  432. }
  433. if (Op.WBack)
  434. {
  435. Context.EmitLdint(Op.Rn);
  436. if (Op.Rm != ARegisters.ZRIndex)
  437. {
  438. Context.EmitLdint(Op.Rm);
  439. }
  440. else
  441. {
  442. Context.EmitLdc_I8(Offset);
  443. }
  444. Context.Emit(OpCodes.Add);
  445. Context.EmitStint(Op.Rn);
  446. }
  447. }
  448. private static void EmitVectorAddv(AILEmitterCtx Context)
  449. {
  450. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  451. int Bytes = Context.CurrOp.GetBitsCount() >> 3;
  452. EmitVectorZeroLower(Context, Op.Rd);
  453. EmitVectorZeroUpper(Context, Op.Rd);
  454. Context.EmitLdvec(Op.Rd);
  455. Context.EmitLdc_I4(0);
  456. Context.EmitLdc_I4(Op.Size);
  457. EmitVectorExtractZx(Context, Op.Rn, 0, Op.Size);
  458. for (int Index = 1; Index < (Bytes >> Op.Size); Index++)
  459. {
  460. EmitVectorExtractZx(Context, Op.Rn, Index, Op.Size);
  461. Context.Emit(OpCodes.Add);
  462. }
  463. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.InsertVec));
  464. Context.EmitStvec(Op.Rd);
  465. }
  466. private static void EmitVectorBic(AILEmitterCtx Context)
  467. {
  468. EmitVectorBinaryZx(Context, () =>
  469. {
  470. Context.Emit(OpCodes.Not);
  471. Context.Emit(OpCodes.And);
  472. });
  473. }
  474. private static void EmitVectorBsl(AILEmitterCtx Context)
  475. {
  476. EmitVectorTernaryZx(Context, () =>
  477. {
  478. Context.EmitSttmp();
  479. Context.EmitLdtmp();
  480. Context.Emit(OpCodes.Xor);
  481. Context.Emit(OpCodes.And);
  482. Context.EmitLdtmp();
  483. Context.Emit(OpCodes.Xor);
  484. });
  485. }
  486. private static void EmitVectorMla(AILEmitterCtx Context)
  487. {
  488. EmitVectorTernaryZx(Context, () =>
  489. {
  490. Context.Emit(OpCodes.Mul);
  491. Context.Emit(OpCodes.Add);
  492. });
  493. }
  494. private static void EmitVectorSmax(AILEmitterCtx Context)
  495. {
  496. Type[] Types = new Type[] { typeof(long), typeof(long) };
  497. MethodInfo MthdInfo = typeof(Math).GetMethod(nameof(Math.Max), Types);
  498. EmitVectorBinarySx(Context, () => Context.EmitCall(MthdInfo));
  499. }
  500. private static void EmitVectorSmin(AILEmitterCtx Context)
  501. {
  502. Type[] Types = new Type[] { typeof(long), typeof(long) };
  503. MethodInfo MthdInfo = typeof(Math).GetMethod(nameof(Math.Min), Types);
  504. EmitVectorBinarySx(Context, () => Context.EmitCall(MthdInfo));
  505. }
  506. private static void EmitVectorSshl(AILEmitterCtx Context) => EmitVectorShl(Context, true);
  507. private static void EmitVectorUshl(AILEmitterCtx Context) => EmitVectorShl(Context, false);
  508. private static void EmitVectorShl(AILEmitterCtx Context, bool Signed)
  509. {
  510. //This instruction shifts the value on vector A by the number of bits
  511. //specified on the signed, lower 8 bits of vector B. If the shift value
  512. //is greater or equal to the data size of each lane, then the result is zero.
  513. //Additionally, negative shifts produces right shifts by the negated shift value.
  514. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  515. int MaxShift = 8 << Op.Size;
  516. Action Emit = () =>
  517. {
  518. AILLabel LblShl = new AILLabel();
  519. AILLabel LblZero = new AILLabel();
  520. AILLabel LblEnd = new AILLabel();
  521. void EmitShift(OpCode ILOp)
  522. {
  523. Context.Emit(OpCodes.Dup);
  524. Context.EmitLdc_I4(MaxShift);
  525. Context.Emit(OpCodes.Bge_S, LblZero);
  526. Context.Emit(ILOp);
  527. Context.Emit(OpCodes.Br_S, LblEnd);
  528. }
  529. Context.Emit(OpCodes.Conv_I1);
  530. Context.Emit(OpCodes.Dup);
  531. Context.EmitLdc_I4(0);
  532. Context.Emit(OpCodes.Bge_S, LblShl);
  533. Context.Emit(OpCodes.Neg);
  534. EmitShift(Signed
  535. ? OpCodes.Shr
  536. : OpCodes.Shr_Un);
  537. Context.MarkLabel(LblShl);
  538. EmitShift(OpCodes.Shl);
  539. Context.MarkLabel(LblZero);
  540. Context.Emit(OpCodes.Pop);
  541. Context.Emit(OpCodes.Pop);
  542. Context.EmitLdc_I8(0);
  543. Context.MarkLabel(LblEnd);
  544. };
  545. if (Signed)
  546. {
  547. EmitVectorBinarySx(Context, Emit);
  548. }
  549. else
  550. {
  551. EmitVectorBinaryZx(Context, Emit);
  552. }
  553. }
  554. private enum ShrFlags
  555. {
  556. None = 0,
  557. Signed = 1 << 0,
  558. Rounding = 1 << 1,
  559. Accumulate = 1 << 2
  560. }
  561. private static void EmitVectorShr(AILEmitterCtx Context, ShrFlags Flags)
  562. {
  563. AOpCodeSimdShImm Op = (AOpCodeSimdShImm)Context.CurrOp;
  564. int Shift = (8 << (Op.Size + 1)) - Op.Imm;
  565. if (Flags.HasFlag(ShrFlags.Accumulate))
  566. {
  567. Action Emit = () =>
  568. {
  569. Context.EmitLdc_I4(Shift);
  570. Context.Emit(OpCodes.Shr_Un);
  571. Context.Emit(OpCodes.Add);
  572. };
  573. EmitVectorOp(Context, Emit, OperFlags.RdRn, Signed: false);
  574. }
  575. else
  576. {
  577. EmitVectorUnaryZx(Context, () =>
  578. {
  579. Context.EmitLdc_I4(Shift);
  580. Context.Emit(OpCodes.Shr_Un);
  581. });
  582. }
  583. }
  584. private static void EmitVectorFcvts(AILEmitterCtx Context)
  585. {
  586. EmitVectorFcvtOp(Context, Signed: true);
  587. }
  588. private static void EmitVectorFcvtu(AILEmitterCtx Context)
  589. {
  590. EmitVectorFcvtOp(Context, Signed: false);
  591. }
  592. private static void EmitVectorScvtf(AILEmitterCtx Context)
  593. {
  594. EmitVectorCvtfOp(Context, Signed: true);
  595. }
  596. private static void EmitVectorUcvtf(AILEmitterCtx Context)
  597. {
  598. EmitVectorCvtfOp(Context, Signed: false);
  599. }
  600. private static void EmitVectorFcvtOp(AILEmitterCtx Context, bool Signed)
  601. {
  602. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  603. int SizeF = Op.Size & 1;
  604. int SizeI = SizeF + 2;
  605. int FBits = GetFBits(Context);
  606. int Bytes = Context.CurrOp.GetBitsCount() >> 3;
  607. for (int Index = 0; Index < (Bytes >> SizeI); Index++)
  608. {
  609. EmitVectorExtractF(Context, Op.Rn, Index, SizeF);
  610. Context.EmitLdc_I4(FBits);
  611. if (SizeF == 0)
  612. {
  613. ASoftFallback.EmitCall(Context, Signed
  614. ? nameof(ASoftFallback.SatSingleToInt32)
  615. : nameof(ASoftFallback.SatSingleToUInt32));
  616. }
  617. else if (SizeF == 1)
  618. {
  619. ASoftFallback.EmitCall(Context, Signed
  620. ? nameof(ASoftFallback.SatDoubleToInt64)
  621. : nameof(ASoftFallback.SatDoubleToUInt64));
  622. }
  623. EmitVectorInsert(Context, Op.Rd, Index, SizeI);
  624. }
  625. if (Op.RegisterSize == ARegisterSize.SIMD64)
  626. {
  627. EmitVectorZeroUpper(Context, Op.Rd);
  628. }
  629. }
  630. private static void EmitVectorCvtfOp(AILEmitterCtx Context, bool Signed)
  631. {
  632. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  633. int SizeF = Op.Size & 1;
  634. int SizeI = SizeF + 2;
  635. int FBits = GetFBits(Context);
  636. int Bytes = Context.CurrOp.GetBitsCount() >> 3;
  637. for (int Index = 0; Index < (Bytes >> SizeI); Index++)
  638. {
  639. EmitVectorExtract(Context, Op.Rn, Index, SizeI, Signed);
  640. Context.EmitLdc_I4(FBits);
  641. if (SizeF == 0)
  642. {
  643. Context.Emit(OpCodes.Conv_I4);
  644. ASoftFallback.EmitCall(Context, Signed
  645. ? nameof(ASoftFallback.Int32ToSingle)
  646. : nameof(ASoftFallback.UInt32ToSingle));
  647. }
  648. else if (SizeF == 1)
  649. {
  650. ASoftFallback.EmitCall(Context, Signed
  651. ? nameof(ASoftFallback.Int64ToDouble)
  652. : nameof(ASoftFallback.UInt64ToDouble));
  653. }
  654. EmitVectorInsertF(Context, Op.Rd, Index, SizeF);
  655. }
  656. if (Op.RegisterSize == ARegisterSize.SIMD64)
  657. {
  658. EmitVectorZeroUpper(Context, Op.Rd);
  659. }
  660. }
  661. private static int GetFBits(AILEmitterCtx Context)
  662. {
  663. if (Context.CurrOp is AOpCodeSimdShImm Op)
  664. {
  665. return (8 << (Op.Size + 1)) - Op.Imm;
  666. }
  667. return 0;
  668. }
  669. private static void EmitVectorBinaryFOp(AILEmitterCtx Context, OpCode ILOp)
  670. {
  671. EmitVectorBinaryFOp(Context, () => Context.Emit(ILOp));
  672. }
  673. private static void EmitVectorBinaryFOp(AILEmitterCtx Context, Action Emit)
  674. {
  675. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  676. int SizeF = Op.Size & 1;
  677. int Bytes = Context.CurrOp.GetBitsCount() >> 3;
  678. for (int Index = 0; Index < (Bytes >> SizeF + 2); Index++)
  679. {
  680. EmitVectorExtractF(Context, Op.Rn, Index, SizeF);
  681. EmitVectorExtractF(Context, Op.Rm, Index, SizeF);
  682. Emit();
  683. EmitVectorInsertF(Context, Op.Rd, Index, SizeF);
  684. }
  685. if (Op.RegisterSize == ARegisterSize.SIMD64)
  686. {
  687. EmitVectorZeroUpper(Context, Op.Rd);
  688. }
  689. }
  690. private static void EmitVectorUnarySx(AILEmitterCtx Context, OpCode ILOp)
  691. {
  692. EmitVectorUnarySx(Context, () => Context.Emit(ILOp));
  693. }
  694. private static void EmitVectorUnaryZx(AILEmitterCtx Context, OpCode ILOp)
  695. {
  696. EmitVectorUnaryZx(Context, () => Context.Emit(ILOp));
  697. }
  698. private static void EmitVectorBinaryZx(AILEmitterCtx Context, OpCode ILOp)
  699. {
  700. EmitVectorBinaryZx(Context, () => Context.Emit(ILOp));
  701. }
  702. private static void EmitVectorUnarySx(AILEmitterCtx Context, Action Emit)
  703. {
  704. EmitVectorOp(Context, Emit, OperFlags.Rn, true);
  705. }
  706. private static void EmitVectorBinarySx(AILEmitterCtx Context, Action Emit)
  707. {
  708. EmitVectorOp(Context, Emit, OperFlags.RnRm, true);
  709. }
  710. private static void EmitVectorUnaryZx(AILEmitterCtx Context, Action Emit)
  711. {
  712. EmitVectorOp(Context, Emit, OperFlags.Rn, false);
  713. }
  714. private static void EmitVectorBinaryZx(AILEmitterCtx Context, Action Emit)
  715. {
  716. EmitVectorOp(Context, Emit, OperFlags.RnRm, false);
  717. }
  718. private static void EmitVectorTernaryZx(AILEmitterCtx Context, Action Emit)
  719. {
  720. EmitVectorOp(Context, Emit, OperFlags.RdRnRm, false);
  721. }
  722. [Flags]
  723. private enum OperFlags
  724. {
  725. Rd = 1 << 0,
  726. Rn = 1 << 1,
  727. Rm = 1 << 2,
  728. RnRm = Rn | Rm,
  729. RdRn = Rd | Rn,
  730. RdRnRm = Rd | Rn | Rm
  731. }
  732. private static void EmitVectorOp(AILEmitterCtx Context, Action Emit, OperFlags Opers, bool Signed)
  733. {
  734. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  735. int Bytes = Context.CurrOp.GetBitsCount() >> 3;
  736. for (int Index = 0; Index < (Bytes >> Op.Size); Index++)
  737. {
  738. if (Opers.HasFlag(OperFlags.Rd))
  739. {
  740. EmitVectorExtract(Context, Op.Rd, Index, Op.Size, Signed);
  741. }
  742. if (Opers.HasFlag(OperFlags.Rn))
  743. {
  744. EmitVectorExtract(Context, Op.Rn, Index, Op.Size, Signed);
  745. }
  746. if (Opers.HasFlag(OperFlags.Rm))
  747. {
  748. EmitVectorExtract(Context, ((AOpCodeSimdReg)Op).Rm, Index, Op.Size, Signed);
  749. }
  750. Emit();
  751. EmitVectorInsert(Context, Op.Rd, Index, Op.Size);
  752. }
  753. if (Op.RegisterSize == ARegisterSize.SIMD64)
  754. {
  755. EmitVectorZeroUpper(Context, Op.Rd);
  756. }
  757. }
  758. private static void EmitVectorImmBinarySx(AILEmitterCtx Context, OpCode ILOp, int Imm)
  759. {
  760. EmitVectorImmBinarySx(Context, () => Context.Emit(ILOp), Imm);
  761. }
  762. private static void EmitVectorImmBinaryZx(AILEmitterCtx Context, OpCode ILOp, int Imm)
  763. {
  764. EmitVectorImmBinaryZx(Context, () => Context.Emit(ILOp), Imm);
  765. }
  766. private static void EmitVectorImmBinarySx(AILEmitterCtx Context, Action Emit, int Imm)
  767. {
  768. EmitVectorImmBinaryOp(Context, Emit, Imm, true);
  769. }
  770. private static void EmitVectorImmBinaryZx(AILEmitterCtx Context, Action Emit, int Imm)
  771. {
  772. EmitVectorImmBinaryOp(Context, Emit, Imm, false);
  773. }
  774. private static void EmitVectorImmBinaryOp(AILEmitterCtx Context, Action Emit, int Imm, bool Signed)
  775. {
  776. AOpCodeSimdShImm Op = (AOpCodeSimdShImm)Context.CurrOp;
  777. int Bytes = Context.CurrOp.GetBitsCount() >> 3;
  778. for (int Index = 0; Index < (Bytes >> Op.Size); Index++)
  779. {
  780. EmitVectorExtract(Context, Op.Rn, Index, Op.Size, Signed);
  781. Context.EmitLdc_I4(Imm);
  782. Emit();
  783. EmitVectorInsert(Context, Op.Rd, Index, Op.Size);
  784. }
  785. if (Op.RegisterSize == ARegisterSize.SIMD64)
  786. {
  787. EmitVectorZeroUpper(Context, Op.Rd);
  788. }
  789. }
  790. private static void EmitVectorImmNarrowBinarySx(AILEmitterCtx Context, OpCode ILOp, int Imm)
  791. {
  792. EmitVectorImmNarrowBinarySx(Context, () => Context.Emit(ILOp), Imm);
  793. }
  794. private static void EmitVectorImmNarrowBinaryZx(AILEmitterCtx Context, OpCode ILOp, int Imm)
  795. {
  796. EmitVectorImmNarrowBinaryZx(Context, () => Context.Emit(ILOp), Imm);
  797. }
  798. private static void EmitVectorImmNarrowBinarySx(AILEmitterCtx Context, Action Emit, int Imm)
  799. {
  800. EmitVectorImmNarrowBinaryOp(Context, Emit, Imm, true);
  801. }
  802. private static void EmitVectorImmNarrowBinaryZx(AILEmitterCtx Context, Action Emit, int Imm)
  803. {
  804. EmitVectorImmNarrowBinaryOp(Context, Emit, Imm, false);
  805. }
  806. private static void EmitVectorImmNarrowBinaryOp(AILEmitterCtx Context, Action Emit, int Imm, bool Signed)
  807. {
  808. AOpCodeSimdShImm Op = (AOpCodeSimdShImm)Context.CurrOp;
  809. if (Op.Size < 0 || Op.Size > 2)
  810. {
  811. throw new InvalidOperationException(Op.Size.ToString());
  812. }
  813. int Elems = 8 >> Op.Size;
  814. int Part = Op.RegisterSize == ARegisterSize.SIMD128 ? Elems : 0;
  815. for (int Index = 0; Index < Elems; Index++)
  816. {
  817. EmitVectorExtract(Context, Op.Rn, Index, Op.Size + 1, Signed);
  818. Context.EmitLdc_I4(Imm);
  819. Emit();
  820. EmitVectorInsert(Context, Op.Rd, Part + Index, Op.Size);
  821. }
  822. if (Part == 0)
  823. {
  824. EmitVectorZeroUpper(Context, Op.Rd);
  825. }
  826. }
  827. private static void EmitVectorCmp(AILEmitterCtx Context, OpCode ILOp)
  828. {
  829. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  830. int Bytes = Context.CurrOp.GetBitsCount() >> 3;
  831. ulong SzMask = ulong.MaxValue >> (64 - (8 << Op.Size));
  832. for (int Index = 0; Index < (Bytes >> Op.Size); Index++)
  833. {
  834. EmitVectorExtractSx(Context, Op.Rn, Index, Op.Size);
  835. if (Op is AOpCodeSimdReg BinOp)
  836. {
  837. EmitVectorExtractSx(Context, BinOp.Rm, Index, Op.Size);
  838. }
  839. else
  840. {
  841. Context.EmitLdc_I8(0);
  842. }
  843. AILLabel LblTrue = new AILLabel();
  844. AILLabel LblEnd = new AILLabel();
  845. Context.Emit(ILOp, LblTrue);
  846. EmitVectorInsert(Context, Op.Rd, Index, Op.Size, 0);
  847. Context.Emit(OpCodes.Br_S, LblEnd);
  848. Context.MarkLabel(LblTrue);
  849. EmitVectorInsert(Context, Op.Rd, Index, Op.Size, (long)SzMask);
  850. Context.MarkLabel(LblEnd);
  851. }
  852. if (Op.RegisterSize == ARegisterSize.SIMD64)
  853. {
  854. EmitVectorZeroUpper(Context, Op.Rd);
  855. }
  856. }
  857. private static void EmitVectorExtractF(AILEmitterCtx Context, int Reg, int Index, int Size)
  858. {
  859. Context.EmitLdvec(Reg);
  860. Context.EmitLdc_I4(Index);
  861. if (Size == 0)
  862. {
  863. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorExtractSingle));
  864. }
  865. else if (Size == 1)
  866. {
  867. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorExtractDouble));
  868. }
  869. else
  870. {
  871. throw new ArgumentOutOfRangeException(nameof(Size));
  872. }
  873. }
  874. private static void EmitVectorExtractSx(AILEmitterCtx Context, int Reg, int Index, int Size)
  875. {
  876. EmitVectorExtract(Context, Reg, Index, Size, true);
  877. }
  878. private static void EmitVectorExtractZx(AILEmitterCtx Context, int Reg, int Index, int Size)
  879. {
  880. EmitVectorExtract(Context, Reg, Index, Size, false);
  881. }
  882. private static void EmitVectorExtract(AILEmitterCtx Context, int Reg, int Index, int Size, bool Signed)
  883. {
  884. if (Size < 0 || Size > 3)
  885. {
  886. throw new ArgumentOutOfRangeException(nameof(Size));
  887. }
  888. IAOpCodeSimd Op = (IAOpCodeSimd)Context.CurrOp;
  889. Context.EmitLdvec(Reg);
  890. Context.EmitLdc_I4(Index);
  891. Context.EmitLdc_I4(Size);
  892. ASoftFallback.EmitCall(Context, Signed
  893. ? nameof(ASoftFallback.ExtractSVec)
  894. : nameof(ASoftFallback.ExtractVec));
  895. }
  896. private static void EmitVectorZeroLower(AILEmitterCtx Context, int Rd)
  897. {
  898. EmitVectorInsert(Context, Rd, 0, 3, 0);
  899. }
  900. private static void EmitVectorZeroUpper(AILEmitterCtx Context, int Rd)
  901. {
  902. EmitVectorInsert(Context, Rd, 1, 3, 0);
  903. }
  904. private static void EmitVectorInsertF(AILEmitterCtx Context, int Reg, int Index, int Size)
  905. {
  906. Context.EmitLdvec(Reg);
  907. Context.EmitLdc_I4(Index);
  908. if (Size == 0)
  909. {
  910. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorInsertSingle));
  911. }
  912. else if (Size == 1)
  913. {
  914. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorInsertDouble));
  915. }
  916. else
  917. {
  918. throw new ArgumentOutOfRangeException(nameof(Size));
  919. }
  920. Context.EmitStvec(Reg);
  921. }
  922. private static void EmitVectorInsert(AILEmitterCtx Context, int Reg, int Index, int Size)
  923. {
  924. if (Size < 0 || Size > 3)
  925. {
  926. throw new ArgumentOutOfRangeException(nameof(Size));
  927. }
  928. Context.EmitLdvec(Reg);
  929. Context.EmitLdc_I4(Index);
  930. Context.EmitLdc_I4(Size);
  931. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorInsertInt));
  932. Context.EmitStvec(Reg);
  933. }
  934. private static void EmitVectorInsert(AILEmitterCtx Context, int Reg, int Index, int Size, long Value)
  935. {
  936. if (Size < 0 || Size > 3)
  937. {
  938. throw new ArgumentOutOfRangeException(nameof(Size));
  939. }
  940. Context.EmitLdvec(Reg);
  941. Context.EmitLdc_I4(Index);
  942. Context.EmitLdc_I4(Size);
  943. Context.EmitLdc_I8(Value);
  944. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.InsertVec));
  945. Context.EmitStvec(Reg);
  946. }
  947. }
  948. }