AInstEmitSimdHelper.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. using ChocolArm64.Decoder;
  2. using ChocolArm64.State;
  3. using ChocolArm64.Translation;
  4. using System;
  5. using System.Reflection;
  6. namespace ChocolArm64.Instruction
  7. {
  8. static class AInstEmitSimdHelper
  9. {
  10. [Flags]
  11. public enum OperFlags
  12. {
  13. Rd = 1 << 0,
  14. Rn = 1 << 1,
  15. Rm = 1 << 2,
  16. Ra = 1 << 3,
  17. RnRm = Rn | Rm,
  18. RdRn = Rd | Rn,
  19. RaRnRm = Ra | Rn | Rm,
  20. RdRnRm = Rd | Rn | Rm
  21. }
  22. public static int GetImmShl(AOpCodeSimdShImm Op)
  23. {
  24. return Op.Imm - (8 << Op.Size);
  25. }
  26. public static int GetImmShr(AOpCodeSimdShImm Op)
  27. {
  28. return (8 << (Op.Size + 1)) - Op.Imm;
  29. }
  30. public static void EmitUnaryMathCall(AILEmitterCtx Context, string Name)
  31. {
  32. IAOpCodeSimd Op = (IAOpCodeSimd)Context.CurrOp;
  33. int SizeF = Op.Size & 1;
  34. MethodInfo MthdInfo;
  35. if (SizeF == 0)
  36. {
  37. MthdInfo = typeof(MathF).GetMethod(Name, new Type[] { typeof(float) });
  38. }
  39. else /* if (SizeF == 1) */
  40. {
  41. MthdInfo = typeof(Math).GetMethod(Name, new Type[] { typeof(double) });
  42. }
  43. Context.EmitCall(MthdInfo);
  44. }
  45. public static void EmitBinaryMathCall(AILEmitterCtx Context, string Name)
  46. {
  47. IAOpCodeSimd Op = (IAOpCodeSimd)Context.CurrOp;
  48. int SizeF = Op.Size & 1;
  49. MethodInfo MthdInfo;
  50. if (SizeF == 0)
  51. {
  52. MthdInfo = typeof(MathF).GetMethod(Name, new Type[] { typeof(float), typeof(float) });
  53. }
  54. else /* if (SizeF == 1) */
  55. {
  56. MthdInfo = typeof(Math).GetMethod(Name, new Type[] { typeof(double), typeof(double) });
  57. }
  58. Context.EmitCall(MthdInfo);
  59. }
  60. public static void EmitRoundMathCall(AILEmitterCtx Context, MidpointRounding RoundMode)
  61. {
  62. IAOpCodeSimd Op = (IAOpCodeSimd)Context.CurrOp;
  63. int SizeF = Op.Size & 1;
  64. Context.EmitLdc_I4((int)RoundMode);
  65. MethodInfo MthdInfo;
  66. Type[] Types = new Type[] { null, typeof(MidpointRounding) };
  67. Types[0] = SizeF == 0
  68. ? typeof(float)
  69. : typeof(double);
  70. if (SizeF == 0)
  71. {
  72. MthdInfo = typeof(MathF).GetMethod(nameof(MathF.Round), Types);
  73. }
  74. else /* if (SizeF == 1) */
  75. {
  76. MthdInfo = typeof(Math).GetMethod(nameof(Math.Round), Types);
  77. }
  78. Context.EmitCall(MthdInfo);
  79. }
  80. public static void EmitScalarUnaryOpSx(AILEmitterCtx Context, Action Emit)
  81. {
  82. EmitScalarOp(Context, Emit, OperFlags.Rn, true);
  83. }
  84. public static void EmitScalarBinaryOpSx(AILEmitterCtx Context, Action Emit)
  85. {
  86. EmitScalarOp(Context, Emit, OperFlags.RnRm, true);
  87. }
  88. public static void EmitScalarUnaryOpZx(AILEmitterCtx Context, Action Emit)
  89. {
  90. EmitScalarOp(Context, Emit, OperFlags.Rn, false);
  91. }
  92. public static void EmitScalarBinaryOpZx(AILEmitterCtx Context, Action Emit)
  93. {
  94. EmitScalarOp(Context, Emit, OperFlags.RnRm, false);
  95. }
  96. public static void EmitScalarTernaryOpZx(AILEmitterCtx Context, Action Emit)
  97. {
  98. EmitScalarOp(Context, Emit, OperFlags.RdRnRm, false);
  99. }
  100. public static void EmitScalarOp(AILEmitterCtx Context, Action Emit, OperFlags Opers, bool Signed)
  101. {
  102. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  103. if (Opers.HasFlag(OperFlags.Rd))
  104. {
  105. EmitVectorExtract(Context, Op.Rd, 0, Op.Size, Signed);
  106. }
  107. if (Opers.HasFlag(OperFlags.Rn))
  108. {
  109. EmitVectorExtract(Context, Op.Rn, 0, Op.Size, Signed);
  110. }
  111. if (Opers.HasFlag(OperFlags.Rm))
  112. {
  113. EmitVectorExtract(Context, ((AOpCodeSimdReg)Op).Rm, 0, Op.Size, Signed);
  114. }
  115. Emit();
  116. EmitScalarSet(Context, Op.Rd, Op.Size);
  117. }
  118. public static void EmitScalarUnaryOpF(AILEmitterCtx Context, Action Emit)
  119. {
  120. EmitScalarOpF(Context, Emit, OperFlags.Rn);
  121. }
  122. public static void EmitScalarBinaryOpF(AILEmitterCtx Context, Action Emit)
  123. {
  124. EmitScalarOpF(Context, Emit, OperFlags.RnRm);
  125. }
  126. public static void EmitScalarTernaryRaOpF(AILEmitterCtx Context, Action Emit)
  127. {
  128. EmitScalarOpF(Context, Emit, OperFlags.RaRnRm);
  129. }
  130. public static void EmitScalarOpF(AILEmitterCtx Context, Action Emit, OperFlags Opers)
  131. {
  132. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  133. int SizeF = Op.Size & 1;
  134. if (Opers.HasFlag(OperFlags.Ra))
  135. {
  136. EmitVectorExtractF(Context, ((AOpCodeSimdReg)Op).Ra, 0, SizeF);
  137. }
  138. if (Opers.HasFlag(OperFlags.Rn))
  139. {
  140. EmitVectorExtractF(Context, Op.Rn, 0, SizeF);
  141. }
  142. if (Opers.HasFlag(OperFlags.Rm))
  143. {
  144. EmitVectorExtractF(Context, ((AOpCodeSimdReg)Op).Rm, 0, SizeF);
  145. }
  146. Emit();
  147. EmitScalarSetF(Context, Op.Rd, SizeF);
  148. }
  149. public static void EmitVectorUnaryOpF(AILEmitterCtx Context, Action Emit)
  150. {
  151. EmitVectorOpF(Context, Emit, OperFlags.Rn);
  152. }
  153. public static void EmitVectorBinaryOpF(AILEmitterCtx Context, Action Emit)
  154. {
  155. EmitVectorOpF(Context, Emit, OperFlags.RnRm);
  156. }
  157. public static void EmitVectorTernaryOpF(AILEmitterCtx Context, Action Emit)
  158. {
  159. EmitVectorOpF(Context, Emit, OperFlags.RdRnRm);
  160. }
  161. public static void EmitVectorOpF(AILEmitterCtx Context, Action Emit, OperFlags Opers)
  162. {
  163. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  164. int SizeF = Op.Size & 1;
  165. int Bytes = Context.CurrOp.GetBitsCount() >> 3;
  166. for (int Index = 0; Index < (Bytes >> SizeF + 2); Index++)
  167. {
  168. if (Opers.HasFlag(OperFlags.Rd))
  169. {
  170. EmitVectorExtractF(Context, Op.Rd, Index, SizeF);
  171. }
  172. if (Opers.HasFlag(OperFlags.Rn))
  173. {
  174. EmitVectorExtractF(Context, Op.Rn, Index, SizeF);
  175. }
  176. if (Opers.HasFlag(OperFlags.Rm))
  177. {
  178. EmitVectorExtractF(Context, ((AOpCodeSimdReg)Op).Rm, Index, SizeF);
  179. }
  180. Emit();
  181. EmitVectorInsertF(Context, Op.Rd, Index, SizeF);
  182. }
  183. if (Op.RegisterSize == ARegisterSize.SIMD64)
  184. {
  185. EmitVectorZeroUpper(Context, Op.Rd);
  186. }
  187. }
  188. public static void EmitVectorBinaryOpByElemF(AILEmitterCtx Context, Action Emit)
  189. {
  190. AOpCodeSimdRegElemF Op = (AOpCodeSimdRegElemF)Context.CurrOp;
  191. EmitVectorOpByElemF(Context, Emit, Op.Index, Ternary: false);
  192. }
  193. public static void EmitVectorTernaryOpByElemF(AILEmitterCtx Context, Action Emit)
  194. {
  195. AOpCodeSimdRegElemF Op = (AOpCodeSimdRegElemF)Context.CurrOp;
  196. EmitVectorOpByElemF(Context, Emit, Op.Index, Ternary: true);
  197. }
  198. public static void EmitVectorOpByElemF(AILEmitterCtx Context, Action Emit, int Elem, bool Ternary)
  199. {
  200. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  201. int SizeF = Op.Size & 1;
  202. int Bytes = Context.CurrOp.GetBitsCount() >> 3;
  203. for (int Index = 0; Index < (Bytes >> SizeF + 2); Index++)
  204. {
  205. if (Ternary)
  206. {
  207. EmitVectorExtractF(Context, Op.Rd, Index, SizeF);
  208. }
  209. EmitVectorExtractF(Context, Op.Rn, Index, SizeF);
  210. EmitVectorExtractF(Context, Op.Rm, Elem, SizeF);
  211. Emit();
  212. EmitVectorInsertTmpF(Context, Index, SizeF);
  213. }
  214. Context.EmitLdvectmp();
  215. Context.EmitStvec(Op.Rd);
  216. if (Op.RegisterSize == ARegisterSize.SIMD64)
  217. {
  218. EmitVectorZeroUpper(Context, Op.Rd);
  219. }
  220. }
  221. public static void EmitVectorUnaryOpSx(AILEmitterCtx Context, Action Emit)
  222. {
  223. EmitVectorOp(Context, Emit, OperFlags.Rn, true);
  224. }
  225. public static void EmitVectorBinaryOpSx(AILEmitterCtx Context, Action Emit)
  226. {
  227. EmitVectorOp(Context, Emit, OperFlags.RnRm, true);
  228. }
  229. public static void EmitVectorUnaryOpZx(AILEmitterCtx Context, Action Emit)
  230. {
  231. EmitVectorOp(Context, Emit, OperFlags.Rn, false);
  232. }
  233. public static void EmitVectorBinaryOpZx(AILEmitterCtx Context, Action Emit)
  234. {
  235. EmitVectorOp(Context, Emit, OperFlags.RnRm, false);
  236. }
  237. public static void EmitVectorTernaryOpZx(AILEmitterCtx Context, Action Emit)
  238. {
  239. EmitVectorOp(Context, Emit, OperFlags.RdRnRm, false);
  240. }
  241. public static void EmitVectorOp(AILEmitterCtx Context, Action Emit, OperFlags Opers, bool Signed)
  242. {
  243. AOpCodeSimd Op = (AOpCodeSimd)Context.CurrOp;
  244. int Bytes = Context.CurrOp.GetBitsCount() >> 3;
  245. for (int Index = 0; Index < (Bytes >> Op.Size); Index++)
  246. {
  247. if (Opers.HasFlag(OperFlags.Rd))
  248. {
  249. EmitVectorExtract(Context, Op.Rd, Index, Op.Size, Signed);
  250. }
  251. if (Opers.HasFlag(OperFlags.Rn))
  252. {
  253. EmitVectorExtract(Context, Op.Rn, Index, Op.Size, Signed);
  254. }
  255. if (Opers.HasFlag(OperFlags.Rm))
  256. {
  257. EmitVectorExtract(Context, ((AOpCodeSimdReg)Op).Rm, Index, Op.Size, Signed);
  258. }
  259. Emit();
  260. EmitVectorInsert(Context, Op.Rd, Index, Op.Size);
  261. }
  262. if (Op.RegisterSize == ARegisterSize.SIMD64)
  263. {
  264. EmitVectorZeroUpper(Context, Op.Rd);
  265. }
  266. }
  267. public static void EmitVectorBinaryOpByElemSx(AILEmitterCtx Context, Action Emit)
  268. {
  269. AOpCodeSimdRegElem Op = (AOpCodeSimdRegElem)Context.CurrOp;
  270. EmitVectorOpByElem(Context, Emit, Op.Index, false, true);
  271. }
  272. public static void EmitVectorBinaryOpByElemZx(AILEmitterCtx Context, Action Emit)
  273. {
  274. AOpCodeSimdRegElem Op = (AOpCodeSimdRegElem)Context.CurrOp;
  275. EmitVectorOpByElem(Context, Emit, Op.Index, false, false);
  276. }
  277. public static void EmitVectorTernaryOpByElemZx(AILEmitterCtx Context, Action Emit)
  278. {
  279. AOpCodeSimdRegElem Op = (AOpCodeSimdRegElem)Context.CurrOp;
  280. EmitVectorOpByElem(Context, Emit, Op.Index, true, false);
  281. }
  282. public static void EmitVectorOpByElem(AILEmitterCtx Context, Action Emit, int Elem, bool Ternary, bool Signed)
  283. {
  284. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  285. int Bytes = Context.CurrOp.GetBitsCount() >> 3;
  286. for (int Index = 0; Index < (Bytes >> Op.Size); Index++)
  287. {
  288. if (Ternary)
  289. {
  290. EmitVectorExtract(Context, Op.Rd, Index, Op.Size, Signed);
  291. }
  292. EmitVectorExtract(Context, Op.Rn, Index, Op.Size, Signed);
  293. EmitVectorExtract(Context, Op.Rm, Elem, Op.Size, Signed);
  294. Emit();
  295. EmitVectorInsertTmp(Context, Index, Op.Size);
  296. }
  297. Context.EmitLdvectmp();
  298. Context.EmitStvec(Op.Rd);
  299. if (Op.RegisterSize == ARegisterSize.SIMD64)
  300. {
  301. EmitVectorZeroUpper(Context, Op.Rd);
  302. }
  303. }
  304. public static void EmitVectorImmUnaryOp(AILEmitterCtx Context, Action Emit)
  305. {
  306. EmitVectorImmOp(Context, Emit, false);
  307. }
  308. public static void EmitVectorImmBinaryOp(AILEmitterCtx Context, Action Emit)
  309. {
  310. EmitVectorImmOp(Context, Emit, true);
  311. }
  312. public static void EmitVectorImmOp(AILEmitterCtx Context, Action Emit, bool Binary)
  313. {
  314. AOpCodeSimdImm Op = (AOpCodeSimdImm)Context.CurrOp;
  315. int Bytes = Context.CurrOp.GetBitsCount() >> 3;
  316. for (int Index = 0; Index < (Bytes >> Op.Size); Index++)
  317. {
  318. if (Binary)
  319. {
  320. EmitVectorExtractZx(Context, Op.Rd, Index, Op.Size);
  321. }
  322. Context.EmitLdc_I8(Op.Imm);
  323. Emit();
  324. EmitVectorInsert(Context, Op.Rd, Index, Op.Size);
  325. }
  326. if (Op.RegisterSize == ARegisterSize.SIMD64)
  327. {
  328. EmitVectorZeroUpper(Context, Op.Rd);
  329. }
  330. }
  331. public static void EmitVectorWidenRmBinaryOpSx(AILEmitterCtx Context, Action Emit)
  332. {
  333. EmitVectorWidenRmBinaryOp(Context, Emit, true);
  334. }
  335. public static void EmitVectorWidenRmBinaryOpZx(AILEmitterCtx Context, Action Emit)
  336. {
  337. EmitVectorWidenRmBinaryOp(Context, Emit, false);
  338. }
  339. public static void EmitVectorWidenRmBinaryOp(AILEmitterCtx Context, Action Emit, bool Signed)
  340. {
  341. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  342. int Elems = 8 >> Op.Size;
  343. int Part = Op.RegisterSize == ARegisterSize.SIMD128 ? Elems : 0;
  344. for (int Index = 0; Index < Elems; Index++)
  345. {
  346. EmitVectorExtract(Context, Op.Rn, Index, Op.Size + 1, Signed);
  347. EmitVectorExtract(Context, Op.Rm, Part + Index, Op.Size, Signed);
  348. Emit();
  349. EmitVectorInsertTmp(Context, Index, Op.Size + 1);
  350. }
  351. Context.EmitLdvectmp();
  352. Context.EmitStvec(Op.Rd);
  353. }
  354. public static void EmitVectorWidenRnRmBinaryOpSx(AILEmitterCtx Context, Action Emit)
  355. {
  356. EmitVectorWidenRnRmOp(Context, Emit, false, true);
  357. }
  358. public static void EmitVectorWidenRnRmBinaryOpZx(AILEmitterCtx Context, Action Emit)
  359. {
  360. EmitVectorWidenRnRmOp(Context, Emit, false, false);
  361. }
  362. public static void EmitVectorWidenRnRmTernaryOpSx(AILEmitterCtx Context, Action Emit)
  363. {
  364. EmitVectorWidenRnRmOp(Context, Emit, true, true);
  365. }
  366. public static void EmitVectorWidenRnRmTernaryOpZx(AILEmitterCtx Context, Action Emit)
  367. {
  368. EmitVectorWidenRnRmOp(Context, Emit, true, false);
  369. }
  370. public static void EmitVectorWidenRnRmOp(AILEmitterCtx Context, Action Emit, bool Ternary, bool Signed)
  371. {
  372. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  373. int Elems = 8 >> Op.Size;
  374. int Part = Op.RegisterSize == ARegisterSize.SIMD128 ? Elems : 0;
  375. for (int Index = 0; Index < Elems; Index++)
  376. {
  377. if (Ternary)
  378. {
  379. EmitVectorExtract(Context, Op.Rd, Index, Op.Size + 1, Signed);
  380. }
  381. EmitVectorExtract(Context, Op.Rn, Part + Index, Op.Size, Signed);
  382. EmitVectorExtract(Context, Op.Rm, Part + Index, Op.Size, Signed);
  383. Emit();
  384. EmitVectorInsertTmp(Context, Index, Op.Size + 1);
  385. }
  386. Context.EmitLdvectmp();
  387. Context.EmitStvec(Op.Rd);
  388. }
  389. public static void EmitScalarSet(AILEmitterCtx Context, int Reg, int Size)
  390. {
  391. EmitVectorZeroAll(Context, Reg);
  392. EmitVectorInsert(Context, Reg, 0, Size);
  393. }
  394. public static void EmitScalarSetF(AILEmitterCtx Context, int Reg, int Size)
  395. {
  396. EmitVectorZeroAll(Context, Reg);
  397. EmitVectorInsertF(Context, Reg, 0, Size);
  398. }
  399. public static void EmitVectorExtractSx(AILEmitterCtx Context, int Reg, int Index, int Size)
  400. {
  401. EmitVectorExtract(Context, Reg, Index, Size, true);
  402. }
  403. public static void EmitVectorExtractZx(AILEmitterCtx Context, int Reg, int Index, int Size)
  404. {
  405. EmitVectorExtract(Context, Reg, Index, Size, false);
  406. }
  407. public static void EmitVectorExtract(AILEmitterCtx Context, int Reg, int Index, int Size, bool Signed)
  408. {
  409. if (Size < 0 || Size > 3)
  410. {
  411. throw new ArgumentOutOfRangeException(nameof(Size));
  412. }
  413. IAOpCodeSimd Op = (IAOpCodeSimd)Context.CurrOp;
  414. Context.EmitLdvec(Reg);
  415. Context.EmitLdc_I4(Index);
  416. Context.EmitLdc_I4(Size);
  417. ASoftFallback.EmitCall(Context, Signed
  418. ? nameof(ASoftFallback.VectorExtractIntSx)
  419. : nameof(ASoftFallback.VectorExtractIntZx));
  420. }
  421. public static void EmitVectorExtractF(AILEmitterCtx Context, int Reg, int Index, int Size)
  422. {
  423. Context.EmitLdvec(Reg);
  424. Context.EmitLdc_I4(Index);
  425. if (Size == 0)
  426. {
  427. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorExtractSingle));
  428. }
  429. else if (Size == 1)
  430. {
  431. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorExtractDouble));
  432. }
  433. else
  434. {
  435. throw new ArgumentOutOfRangeException(nameof(Size));
  436. }
  437. }
  438. public static void EmitVectorZeroAll(AILEmitterCtx Context, int Rd)
  439. {
  440. EmitVectorZeroLower(Context, Rd);
  441. EmitVectorZeroUpper(Context, Rd);
  442. }
  443. public static void EmitVectorZeroLower(AILEmitterCtx Context, int Rd)
  444. {
  445. EmitVectorInsert(Context, Rd, 0, 3, 0);
  446. }
  447. public static void EmitVectorZeroUpper(AILEmitterCtx Context, int Rd)
  448. {
  449. EmitVectorInsert(Context, Rd, 1, 3, 0);
  450. }
  451. public static void EmitVectorInsert(AILEmitterCtx Context, int Reg, int Index, int Size)
  452. {
  453. if (Size < 0 || Size > 3)
  454. {
  455. throw new ArgumentOutOfRangeException(nameof(Size));
  456. }
  457. Context.EmitLdvec(Reg);
  458. Context.EmitLdc_I4(Index);
  459. Context.EmitLdc_I4(Size);
  460. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorInsertInt));
  461. Context.EmitStvec(Reg);
  462. }
  463. public static void EmitVectorInsertTmp(AILEmitterCtx Context, int Index, int Size)
  464. {
  465. if (Size < 0 || Size > 3)
  466. {
  467. throw new ArgumentOutOfRangeException(nameof(Size));
  468. }
  469. Context.EmitLdvectmp();
  470. Context.EmitLdc_I4(Index);
  471. Context.EmitLdc_I4(Size);
  472. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorInsertInt));
  473. Context.EmitStvectmp();
  474. }
  475. public static void EmitVectorInsert(AILEmitterCtx Context, int Reg, int Index, int Size, long Value)
  476. {
  477. if (Size < 0 || Size > 3)
  478. {
  479. throw new ArgumentOutOfRangeException(nameof(Size));
  480. }
  481. Context.EmitLdc_I8(Value);
  482. Context.EmitLdvec(Reg);
  483. Context.EmitLdc_I4(Index);
  484. Context.EmitLdc_I4(Size);
  485. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorInsertInt));
  486. Context.EmitStvec(Reg);
  487. }
  488. public static void EmitVectorInsertF(AILEmitterCtx Context, int Reg, int Index, int Size)
  489. {
  490. Context.EmitLdvec(Reg);
  491. Context.EmitLdc_I4(Index);
  492. if (Size == 0)
  493. {
  494. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorInsertSingle));
  495. }
  496. else if (Size == 1)
  497. {
  498. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorInsertDouble));
  499. }
  500. else
  501. {
  502. throw new ArgumentOutOfRangeException(nameof(Size));
  503. }
  504. Context.EmitStvec(Reg);
  505. }
  506. public static void EmitVectorInsertTmpF(AILEmitterCtx Context, int Index, int Size)
  507. {
  508. Context.EmitLdvectmp();
  509. Context.EmitLdc_I4(Index);
  510. if (Size == 0)
  511. {
  512. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorInsertSingle));
  513. }
  514. else if (Size == 1)
  515. {
  516. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorInsertDouble));
  517. }
  518. else
  519. {
  520. throw new ArgumentOutOfRangeException(nameof(Size));
  521. }
  522. Context.EmitStvectmp();
  523. }
  524. }
  525. }