AInstEmitSimdHelper.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  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, Index, Op.Size, Signed);
  294. Emit();
  295. EmitVectorInsert(Context, Op.Rd, Index, Op.Size);
  296. }
  297. if (Op.RegisterSize == ARegisterSize.SIMD64)
  298. {
  299. EmitVectorZeroUpper(Context, Op.Rd);
  300. }
  301. }
  302. public static void EmitVectorImmUnaryOp(AILEmitterCtx Context, Action Emit)
  303. {
  304. EmitVectorImmOp(Context, Emit, false);
  305. }
  306. public static void EmitVectorImmBinaryOp(AILEmitterCtx Context, Action Emit)
  307. {
  308. EmitVectorImmOp(Context, Emit, true);
  309. }
  310. public static void EmitVectorImmOp(AILEmitterCtx Context, Action Emit, bool Binary)
  311. {
  312. AOpCodeSimdImm Op = (AOpCodeSimdImm)Context.CurrOp;
  313. int Bytes = Context.CurrOp.GetBitsCount() >> 3;
  314. for (int Index = 0; Index < (Bytes >> Op.Size); Index++)
  315. {
  316. if (Binary)
  317. {
  318. EmitVectorExtractZx(Context, Op.Rd, Index, Op.Size);
  319. }
  320. Context.EmitLdc_I8(Op.Imm);
  321. Emit();
  322. EmitVectorInsert(Context, Op.Rd, Index, Op.Size);
  323. }
  324. if (Op.RegisterSize == ARegisterSize.SIMD64)
  325. {
  326. EmitVectorZeroUpper(Context, Op.Rd);
  327. }
  328. }
  329. public static void EmitVectorWidenRmBinaryOpSx(AILEmitterCtx Context, Action Emit)
  330. {
  331. EmitVectorWidenRmBinaryOp(Context, Emit, true);
  332. }
  333. public static void EmitVectorWidenRmBinaryOpZx(AILEmitterCtx Context, Action Emit)
  334. {
  335. EmitVectorWidenRmBinaryOp(Context, Emit, false);
  336. }
  337. public static void EmitVectorWidenRmBinaryOp(AILEmitterCtx Context, Action Emit, bool Signed)
  338. {
  339. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  340. int Elems = 8 >> Op.Size;
  341. int Part = Op.RegisterSize == ARegisterSize.SIMD128 ? Elems : 0;
  342. for (int Index = 0; Index < Elems; Index++)
  343. {
  344. EmitVectorExtract(Context, Op.Rn, Index, Op.Size + 1, Signed);
  345. EmitVectorExtract(Context, Op.Rm, Part + Index, Op.Size, Signed);
  346. Emit();
  347. EmitVectorInsertTmp(Context, Index, Op.Size + 1);
  348. }
  349. Context.EmitLdvectmp();
  350. Context.EmitStvec(Op.Rd);
  351. }
  352. public static void EmitVectorWidenRnRmBinaryOpSx(AILEmitterCtx Context, Action Emit)
  353. {
  354. EmitVectorWidenRnRmOp(Context, Emit, false, true);
  355. }
  356. public static void EmitVectorWidenRnRmBinaryOpZx(AILEmitterCtx Context, Action Emit)
  357. {
  358. EmitVectorWidenRnRmOp(Context, Emit, false, false);
  359. }
  360. public static void EmitVectorWidenRnRmTernaryOpSx(AILEmitterCtx Context, Action Emit)
  361. {
  362. EmitVectorWidenRnRmOp(Context, Emit, true, true);
  363. }
  364. public static void EmitVectorWidenRnRmTernaryOpZx(AILEmitterCtx Context, Action Emit)
  365. {
  366. EmitVectorWidenRnRmOp(Context, Emit, true, false);
  367. }
  368. public static void EmitVectorWidenRnRmOp(AILEmitterCtx Context, Action Emit, bool Ternary, bool Signed)
  369. {
  370. AOpCodeSimdReg Op = (AOpCodeSimdReg)Context.CurrOp;
  371. int Elems = 8 >> Op.Size;
  372. int Part = Op.RegisterSize == ARegisterSize.SIMD128 ? Elems : 0;
  373. for (int Index = 0; Index < Elems; Index++)
  374. {
  375. if (Ternary)
  376. {
  377. EmitVectorExtract(Context, Op.Rd, Index, Op.Size + 1, Signed);
  378. }
  379. EmitVectorExtract(Context, Op.Rn, Part + Index, Op.Size, Signed);
  380. EmitVectorExtract(Context, Op.Rm, Part + Index, Op.Size, Signed);
  381. Emit();
  382. EmitVectorInsertTmp(Context, Index, Op.Size + 1);
  383. }
  384. Context.EmitLdvectmp();
  385. Context.EmitStvec(Op.Rd);
  386. }
  387. public static void EmitScalarSet(AILEmitterCtx Context, int Reg, int Size)
  388. {
  389. EmitVectorZeroAll(Context, Reg);
  390. EmitVectorInsert(Context, Reg, 0, Size);
  391. }
  392. public static void EmitScalarSetF(AILEmitterCtx Context, int Reg, int Size)
  393. {
  394. EmitVectorZeroAll(Context, Reg);
  395. EmitVectorInsertF(Context, Reg, 0, Size);
  396. }
  397. public static void EmitVectorExtractSx(AILEmitterCtx Context, int Reg, int Index, int Size)
  398. {
  399. EmitVectorExtract(Context, Reg, Index, Size, true);
  400. }
  401. public static void EmitVectorExtractZx(AILEmitterCtx Context, int Reg, int Index, int Size)
  402. {
  403. EmitVectorExtract(Context, Reg, Index, Size, false);
  404. }
  405. public static void EmitVectorExtract(AILEmitterCtx Context, int Reg, int Index, int Size, bool Signed)
  406. {
  407. if (Size < 0 || Size > 3)
  408. {
  409. throw new ArgumentOutOfRangeException(nameof(Size));
  410. }
  411. IAOpCodeSimd Op = (IAOpCodeSimd)Context.CurrOp;
  412. Context.EmitLdvec(Reg);
  413. Context.EmitLdc_I4(Index);
  414. Context.EmitLdc_I4(Size);
  415. ASoftFallback.EmitCall(Context, Signed
  416. ? nameof(ASoftFallback.VectorExtractIntSx)
  417. : nameof(ASoftFallback.VectorExtractIntZx));
  418. }
  419. public static void EmitVectorExtractF(AILEmitterCtx Context, int Reg, int Index, int Size)
  420. {
  421. Context.EmitLdvec(Reg);
  422. Context.EmitLdc_I4(Index);
  423. if (Size == 0)
  424. {
  425. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorExtractSingle));
  426. }
  427. else if (Size == 1)
  428. {
  429. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorExtractDouble));
  430. }
  431. else
  432. {
  433. throw new ArgumentOutOfRangeException(nameof(Size));
  434. }
  435. }
  436. public static void EmitVectorZeroAll(AILEmitterCtx Context, int Rd)
  437. {
  438. EmitVectorZeroLower(Context, Rd);
  439. EmitVectorZeroUpper(Context, Rd);
  440. }
  441. public static void EmitVectorZeroLower(AILEmitterCtx Context, int Rd)
  442. {
  443. EmitVectorInsert(Context, Rd, 0, 3, 0);
  444. }
  445. public static void EmitVectorZeroUpper(AILEmitterCtx Context, int Rd)
  446. {
  447. EmitVectorInsert(Context, Rd, 1, 3, 0);
  448. }
  449. public static void EmitVectorInsert(AILEmitterCtx Context, int Reg, int Index, int Size)
  450. {
  451. if (Size < 0 || Size > 3)
  452. {
  453. throw new ArgumentOutOfRangeException(nameof(Size));
  454. }
  455. Context.EmitLdvec(Reg);
  456. Context.EmitLdc_I4(Index);
  457. Context.EmitLdc_I4(Size);
  458. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorInsertInt));
  459. Context.EmitStvec(Reg);
  460. }
  461. public static void EmitVectorInsertTmp(AILEmitterCtx Context, int Index, int Size)
  462. {
  463. if (Size < 0 || Size > 3)
  464. {
  465. throw new ArgumentOutOfRangeException(nameof(Size));
  466. }
  467. Context.EmitLdvectmp();
  468. Context.EmitLdc_I4(Index);
  469. Context.EmitLdc_I4(Size);
  470. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorInsertInt));
  471. Context.EmitStvectmp();
  472. }
  473. public static void EmitVectorInsert(AILEmitterCtx Context, int Reg, int Index, int Size, long Value)
  474. {
  475. if (Size < 0 || Size > 3)
  476. {
  477. throw new ArgumentOutOfRangeException(nameof(Size));
  478. }
  479. Context.EmitLdc_I8(Value);
  480. Context.EmitLdvec(Reg);
  481. Context.EmitLdc_I4(Index);
  482. Context.EmitLdc_I4(Size);
  483. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorInsertInt));
  484. Context.EmitStvec(Reg);
  485. }
  486. public static void EmitVectorInsertF(AILEmitterCtx Context, int Reg, int Index, int Size)
  487. {
  488. Context.EmitLdvec(Reg);
  489. Context.EmitLdc_I4(Index);
  490. if (Size == 0)
  491. {
  492. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorInsertSingle));
  493. }
  494. else if (Size == 1)
  495. {
  496. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorInsertDouble));
  497. }
  498. else
  499. {
  500. throw new ArgumentOutOfRangeException(nameof(Size));
  501. }
  502. Context.EmitStvec(Reg);
  503. }
  504. public static void EmitVectorInsertTmpF(AILEmitterCtx Context, int Index, int Size)
  505. {
  506. Context.EmitLdvectmp();
  507. Context.EmitLdc_I4(Index);
  508. if (Size == 0)
  509. {
  510. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorInsertSingle));
  511. }
  512. else if (Size == 1)
  513. {
  514. ASoftFallback.EmitCall(Context, nameof(ASoftFallback.VectorInsertDouble));
  515. }
  516. else
  517. {
  518. throw new ArgumentOutOfRangeException(nameof(Size));
  519. }
  520. Context.EmitStvectmp();
  521. }
  522. }
  523. }