InstEmitSimdCvt.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. using ChocolArm64.Decoders;
  2. using ChocolArm64.State;
  3. using ChocolArm64.Translation;
  4. using System;
  5. using System.Reflection.Emit;
  6. using System.Runtime.Intrinsics;
  7. using System.Runtime.Intrinsics.X86;
  8. using static ChocolArm64.Instructions.InstEmitSimdHelper;
  9. namespace ChocolArm64.Instructions
  10. {
  11. static partial class InstEmit
  12. {
  13. public static void Fcvt_S(ILEmitterCtx context)
  14. {
  15. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  16. if (Optimizations.UseSse2)
  17. {
  18. if (op.Size == 1 && op.Opc == 0)
  19. {
  20. //Double -> Single.
  21. VectorHelper.EmitCall(context, nameof(VectorHelper.VectorSingleZero));
  22. EmitLdvecWithCastToDouble(context, op.Rn);
  23. Type[] types = new Type[] { typeof(Vector128<float>), typeof(Vector128<double>) };
  24. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertScalarToVector128Single), types));
  25. context.EmitStvec(op.Rd);
  26. }
  27. else if (op.Size == 0 && op.Opc == 1)
  28. {
  29. //Single -> Double.
  30. VectorHelper.EmitCall(context, nameof(VectorHelper.VectorDoubleZero));
  31. context.EmitLdvec(op.Rn);
  32. Type[] types = new Type[] { typeof(Vector128<double>), typeof(Vector128<float>) };
  33. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertScalarToVector128Double), types));
  34. EmitStvecWithCastFromDouble(context, op.Rd);
  35. }
  36. else
  37. {
  38. //Invalid encoding.
  39. throw new InvalidOperationException();
  40. }
  41. }
  42. else
  43. {
  44. EmitVectorExtractF(context, op.Rn, 0, op.Size);
  45. EmitFloatCast(context, op.Opc);
  46. EmitScalarSetF(context, op.Rd, op.Opc);
  47. }
  48. }
  49. public static void Fcvtas_Gp(ILEmitterCtx context)
  50. {
  51. EmitFcvt_s_Gp(context, () => EmitRoundMathCall(context, MidpointRounding.AwayFromZero));
  52. }
  53. public static void Fcvtau_Gp(ILEmitterCtx context)
  54. {
  55. EmitFcvt_u_Gp(context, () => EmitRoundMathCall(context, MidpointRounding.AwayFromZero));
  56. }
  57. public static void Fcvtl_V(ILEmitterCtx context)
  58. {
  59. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  60. int sizeF = op.Size & 1;
  61. if (Optimizations.UseSse2 && sizeF == 1)
  62. {
  63. Type[] typesCvt = new Type[] { typeof(Vector128<float>) };
  64. string nameMov = op.RegisterSize == RegisterSize.Simd128
  65. ? nameof(Sse.MoveHighToLow)
  66. : nameof(Sse.MoveLowToHigh);
  67. context.EmitLdvec(op.Rn);
  68. context.Emit(OpCodes.Dup);
  69. context.EmitCall(typeof(Sse).GetMethod(nameMov));
  70. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToVector128Double), typesCvt));
  71. EmitStvecWithCastFromDouble(context, op.Rd);
  72. }
  73. else
  74. {
  75. int elems = 4 >> sizeF;
  76. int part = op.RegisterSize == RegisterSize.Simd128 ? elems : 0;
  77. for (int index = 0; index < elems; index++)
  78. {
  79. if (sizeF == 0)
  80. {
  81. EmitVectorExtractZx(context, op.Rn, part + index, 1);
  82. context.Emit(OpCodes.Conv_U2);
  83. context.EmitLdarg(TranslatedSub.StateArgIdx);
  84. context.EmitCall(typeof(SoftFloat16_32), nameof(SoftFloat16_32.FPConvert));
  85. }
  86. else /* if (sizeF == 1) */
  87. {
  88. EmitVectorExtractF(context, op.Rn, part + index, 0);
  89. context.Emit(OpCodes.Conv_R8);
  90. }
  91. EmitVectorInsertTmpF(context, index, sizeF);
  92. }
  93. context.EmitLdvectmp();
  94. context.EmitStvec(op.Rd);
  95. }
  96. }
  97. public static void Fcvtms_Gp(ILEmitterCtx context)
  98. {
  99. EmitFcvt_s_Gp(context, () => EmitUnaryMathCall(context, nameof(Math.Floor)));
  100. }
  101. public static void Fcvtmu_Gp(ILEmitterCtx context)
  102. {
  103. EmitFcvt_u_Gp(context, () => EmitUnaryMathCall(context, nameof(Math.Floor)));
  104. }
  105. public static void Fcvtn_V(ILEmitterCtx context)
  106. {
  107. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  108. int sizeF = op.Size & 1;
  109. if (Optimizations.UseSse2 && sizeF == 1)
  110. {
  111. Type[] typesCvt = new Type[] { typeof(Vector128<double>) };
  112. string nameMov = op.RegisterSize == RegisterSize.Simd128
  113. ? nameof(Sse.MoveLowToHigh)
  114. : nameof(Sse.MoveHighToLow);
  115. context.EmitLdvec(op.Rd);
  116. VectorHelper.EmitCall(context, nameof(VectorHelper.VectorSingleZero));
  117. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.MoveLowToHigh)));
  118. EmitLdvecWithCastToDouble(context, op.Rn);
  119. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToVector128Single), typesCvt));
  120. context.Emit(OpCodes.Dup);
  121. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.MoveLowToHigh)));
  122. context.EmitCall(typeof(Sse).GetMethod(nameMov));
  123. context.EmitStvec(op.Rd);
  124. }
  125. else
  126. {
  127. int elems = 4 >> sizeF;
  128. int part = op.RegisterSize == RegisterSize.Simd128 ? elems : 0;
  129. if (part != 0)
  130. {
  131. context.EmitLdvec(op.Rd);
  132. context.EmitStvectmp();
  133. }
  134. for (int index = 0; index < elems; index++)
  135. {
  136. EmitVectorExtractF(context, op.Rn, index, sizeF);
  137. if (sizeF == 0)
  138. {
  139. context.EmitLdarg(TranslatedSub.StateArgIdx);
  140. context.EmitCall(typeof(SoftFloat32_16), nameof(SoftFloat32_16.FPConvert));
  141. context.Emit(OpCodes.Conv_U8);
  142. EmitVectorInsertTmp(context, part + index, 1);
  143. }
  144. else /* if (sizeF == 1) */
  145. {
  146. context.Emit(OpCodes.Conv_R4);
  147. EmitVectorInsertTmpF(context, part + index, 0);
  148. }
  149. }
  150. context.EmitLdvectmp();
  151. context.EmitStvec(op.Rd);
  152. if (part == 0)
  153. {
  154. EmitVectorZeroUpper(context, op.Rd);
  155. }
  156. }
  157. }
  158. public static void Fcvtns_S(ILEmitterCtx context)
  159. {
  160. EmitFcvtn(context, signed: true, scalar: true);
  161. }
  162. public static void Fcvtns_V(ILEmitterCtx context)
  163. {
  164. EmitFcvtn(context, signed: true, scalar: false);
  165. }
  166. public static void Fcvtnu_S(ILEmitterCtx context)
  167. {
  168. EmitFcvtn(context, signed: false, scalar: true);
  169. }
  170. public static void Fcvtnu_V(ILEmitterCtx context)
  171. {
  172. EmitFcvtn(context, signed: false, scalar: false);
  173. }
  174. public static void Fcvtps_Gp(ILEmitterCtx context)
  175. {
  176. EmitFcvt_s_Gp(context, () => EmitUnaryMathCall(context, nameof(Math.Ceiling)));
  177. }
  178. public static void Fcvtpu_Gp(ILEmitterCtx context)
  179. {
  180. EmitFcvt_u_Gp(context, () => EmitUnaryMathCall(context, nameof(Math.Ceiling)));
  181. }
  182. public static void Fcvtzs_Gp(ILEmitterCtx context)
  183. {
  184. EmitFcvt_s_Gp(context, () => { });
  185. }
  186. public static void Fcvtzs_Gp_Fixed(ILEmitterCtx context)
  187. {
  188. EmitFcvtzs_Gp_Fix(context);
  189. }
  190. public static void Fcvtzs_S(ILEmitterCtx context)
  191. {
  192. EmitScalarFcvtzs(context);
  193. }
  194. public static void Fcvtzs_V(ILEmitterCtx context)
  195. {
  196. EmitVectorFcvtzs(context);
  197. }
  198. public static void Fcvtzu_Gp(ILEmitterCtx context)
  199. {
  200. EmitFcvt_u_Gp(context, () => { });
  201. }
  202. public static void Fcvtzu_Gp_Fixed(ILEmitterCtx context)
  203. {
  204. EmitFcvtzu_Gp_Fix(context);
  205. }
  206. public static void Fcvtzu_S(ILEmitterCtx context)
  207. {
  208. EmitScalarFcvtzu(context);
  209. }
  210. public static void Fcvtzu_V(ILEmitterCtx context)
  211. {
  212. EmitVectorFcvtzu(context);
  213. }
  214. public static void Scvtf_Gp(ILEmitterCtx context)
  215. {
  216. OpCodeSimdCvt64 op = (OpCodeSimdCvt64)context.CurrOp;
  217. context.EmitLdintzr(op.Rn);
  218. if (context.CurrOp.RegisterSize == RegisterSize.Int32)
  219. {
  220. context.Emit(OpCodes.Conv_U4);
  221. }
  222. EmitFloatCast(context, op.Size);
  223. EmitScalarSetF(context, op.Rd, op.Size);
  224. }
  225. public static void Scvtf_S(ILEmitterCtx context)
  226. {
  227. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  228. EmitVectorExtractSx(context, op.Rn, 0, op.Size + 2);
  229. EmitFloatCast(context, op.Size);
  230. EmitScalarSetF(context, op.Rd, op.Size);
  231. }
  232. public static void Scvtf_V(ILEmitterCtx context)
  233. {
  234. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  235. int sizeF = op.Size & 1;
  236. if (Optimizations.UseSse2 && sizeF == 0)
  237. {
  238. Type[] typesCvt = new Type[] { typeof(Vector128<int>) };
  239. EmitLdvecWithSignedCast(context, op.Rn, 2);
  240. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToVector128Single), typesCvt));
  241. context.EmitStvec(op.Rd);
  242. if (op.RegisterSize == RegisterSize.Simd64)
  243. {
  244. EmitVectorZeroUpper(context, op.Rd);
  245. }
  246. }
  247. else
  248. {
  249. EmitVectorCvtf(context, signed: true);
  250. }
  251. }
  252. public static void Ucvtf_Gp(ILEmitterCtx context)
  253. {
  254. OpCodeSimdCvt64 op = (OpCodeSimdCvt64)context.CurrOp;
  255. context.EmitLdintzr(op.Rn);
  256. if (context.CurrOp.RegisterSize == RegisterSize.Int32)
  257. {
  258. context.Emit(OpCodes.Conv_U4);
  259. }
  260. context.Emit(OpCodes.Conv_R_Un);
  261. EmitFloatCast(context, op.Size);
  262. EmitScalarSetF(context, op.Rd, op.Size);
  263. }
  264. public static void Ucvtf_S(ILEmitterCtx context)
  265. {
  266. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  267. EmitVectorExtractZx(context, op.Rn, 0, op.Size + 2);
  268. context.Emit(OpCodes.Conv_R_Un);
  269. EmitFloatCast(context, op.Size);
  270. EmitScalarSetF(context, op.Rd, op.Size);
  271. }
  272. public static void Ucvtf_V(ILEmitterCtx context)
  273. {
  274. EmitVectorCvtf(context, signed: false);
  275. }
  276. private static int GetFBits(ILEmitterCtx context)
  277. {
  278. if (context.CurrOp is OpCodeSimdShImm64 op)
  279. {
  280. return GetImmShr(op);
  281. }
  282. return 0;
  283. }
  284. private static void EmitFloatCast(ILEmitterCtx context, int size)
  285. {
  286. if (size == 0)
  287. {
  288. context.Emit(OpCodes.Conv_R4);
  289. }
  290. else if (size == 1)
  291. {
  292. context.Emit(OpCodes.Conv_R8);
  293. }
  294. else
  295. {
  296. throw new ArgumentOutOfRangeException(nameof(size));
  297. }
  298. }
  299. private static void EmitFcvtn(ILEmitterCtx context, bool signed, bool scalar)
  300. {
  301. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  302. int sizeF = op.Size & 1;
  303. int sizeI = sizeF + 2;
  304. int bytes = op.GetBitsCount() >> 3;
  305. int elems = !scalar ? bytes >> sizeI : 1;
  306. if (scalar && (sizeF == 0))
  307. {
  308. EmitVectorZeroLowerTmp(context);
  309. }
  310. for (int index = 0; index < elems; index++)
  311. {
  312. EmitVectorExtractF(context, op.Rn, index, sizeF);
  313. EmitRoundMathCall(context, MidpointRounding.ToEven);
  314. if (sizeF == 0)
  315. {
  316. VectorHelper.EmitCall(context, signed
  317. ? nameof(VectorHelper.SatF32ToS32)
  318. : nameof(VectorHelper.SatF32ToU32));
  319. context.Emit(OpCodes.Conv_U8);
  320. }
  321. else /* if (sizeF == 1) */
  322. {
  323. VectorHelper.EmitCall(context, signed
  324. ? nameof(VectorHelper.SatF64ToS64)
  325. : nameof(VectorHelper.SatF64ToU64));
  326. }
  327. EmitVectorInsertTmp(context, index, sizeI);
  328. }
  329. context.EmitLdvectmp();
  330. context.EmitStvec(op.Rd);
  331. if ((op.RegisterSize == RegisterSize.Simd64) || scalar)
  332. {
  333. EmitVectorZeroUpper(context, op.Rd);
  334. }
  335. }
  336. private static void EmitFcvt_s_Gp(ILEmitterCtx context, Action emit)
  337. {
  338. EmitFcvt___Gp(context, emit, true);
  339. }
  340. private static void EmitFcvt_u_Gp(ILEmitterCtx context, Action emit)
  341. {
  342. EmitFcvt___Gp(context, emit, false);
  343. }
  344. private static void EmitFcvt___Gp(ILEmitterCtx context, Action emit, bool signed)
  345. {
  346. OpCodeSimdCvt64 op = (OpCodeSimdCvt64)context.CurrOp;
  347. EmitVectorExtractF(context, op.Rn, 0, op.Size);
  348. emit();
  349. if (signed)
  350. {
  351. EmitScalarFcvts(context, op.Size, 0);
  352. }
  353. else
  354. {
  355. EmitScalarFcvtu(context, op.Size, 0);
  356. }
  357. if (context.CurrOp.RegisterSize == RegisterSize.Int32)
  358. {
  359. context.Emit(OpCodes.Conv_U8);
  360. }
  361. context.EmitStintzr(op.Rd);
  362. }
  363. private static void EmitFcvtzs_Gp_Fix(ILEmitterCtx context)
  364. {
  365. EmitFcvtz__Gp_Fix(context, true);
  366. }
  367. private static void EmitFcvtzu_Gp_Fix(ILEmitterCtx context)
  368. {
  369. EmitFcvtz__Gp_Fix(context, false);
  370. }
  371. private static void EmitFcvtz__Gp_Fix(ILEmitterCtx context, bool signed)
  372. {
  373. OpCodeSimdCvt64 op = (OpCodeSimdCvt64)context.CurrOp;
  374. EmitVectorExtractF(context, op.Rn, 0, op.Size);
  375. if (signed)
  376. {
  377. EmitScalarFcvts(context, op.Size, op.FBits);
  378. }
  379. else
  380. {
  381. EmitScalarFcvtu(context, op.Size, op.FBits);
  382. }
  383. if (context.CurrOp.RegisterSize == RegisterSize.Int32)
  384. {
  385. context.Emit(OpCodes.Conv_U8);
  386. }
  387. context.EmitStintzr(op.Rd);
  388. }
  389. private static void EmitVectorCvtf(ILEmitterCtx context, bool signed)
  390. {
  391. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  392. int sizeF = op.Size & 1;
  393. int sizeI = sizeF + 2;
  394. int fBits = GetFBits(context);
  395. int bytes = op.GetBitsCount() >> 3;
  396. int elems = bytes >> sizeI;
  397. for (int index = 0; index < elems; index++)
  398. {
  399. EmitVectorExtract(context, op.Rn, index, sizeI, signed);
  400. if (!signed)
  401. {
  402. context.Emit(OpCodes.Conv_R_Un);
  403. }
  404. context.Emit(sizeF == 0
  405. ? OpCodes.Conv_R4
  406. : OpCodes.Conv_R8);
  407. EmitI2fFBitsMul(context, sizeF, fBits);
  408. EmitVectorInsertF(context, op.Rd, index, sizeF);
  409. }
  410. if (op.RegisterSize == RegisterSize.Simd64)
  411. {
  412. EmitVectorZeroUpper(context, op.Rd);
  413. }
  414. }
  415. private static void EmitScalarFcvtzs(ILEmitterCtx context)
  416. {
  417. EmitScalarFcvtz(context, true);
  418. }
  419. private static void EmitScalarFcvtzu(ILEmitterCtx context)
  420. {
  421. EmitScalarFcvtz(context, false);
  422. }
  423. private static void EmitScalarFcvtz(ILEmitterCtx context, bool signed)
  424. {
  425. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  426. int sizeF = op.Size & 1;
  427. int sizeI = sizeF + 2;
  428. int fBits = GetFBits(context);
  429. EmitVectorExtractF(context, op.Rn, 0, sizeF);
  430. EmitF2iFBitsMul(context, sizeF, fBits);
  431. if (sizeF == 0)
  432. {
  433. VectorHelper.EmitCall(context, signed
  434. ? nameof(VectorHelper.SatF32ToS32)
  435. : nameof(VectorHelper.SatF32ToU32));
  436. }
  437. else /* if (sizeF == 1) */
  438. {
  439. VectorHelper.EmitCall(context, signed
  440. ? nameof(VectorHelper.SatF64ToS64)
  441. : nameof(VectorHelper.SatF64ToU64));
  442. }
  443. if (sizeF == 0)
  444. {
  445. context.Emit(OpCodes.Conv_U8);
  446. }
  447. EmitScalarSet(context, op.Rd, sizeI);
  448. }
  449. private static void EmitVectorFcvtzs(ILEmitterCtx context)
  450. {
  451. EmitVectorFcvtz(context, true);
  452. }
  453. private static void EmitVectorFcvtzu(ILEmitterCtx context)
  454. {
  455. EmitVectorFcvtz(context, false);
  456. }
  457. private static void EmitVectorFcvtz(ILEmitterCtx context, bool signed)
  458. {
  459. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  460. int sizeF = op.Size & 1;
  461. int sizeI = sizeF + 2;
  462. int fBits = GetFBits(context);
  463. int bytes = op.GetBitsCount() >> 3;
  464. int elems = bytes >> sizeI;
  465. for (int index = 0; index < elems; index++)
  466. {
  467. EmitVectorExtractF(context, op.Rn, index, sizeF);
  468. EmitF2iFBitsMul(context, sizeF, fBits);
  469. if (sizeF == 0)
  470. {
  471. VectorHelper.EmitCall(context, signed
  472. ? nameof(VectorHelper.SatF32ToS32)
  473. : nameof(VectorHelper.SatF32ToU32));
  474. }
  475. else /* if (sizeF == 1) */
  476. {
  477. VectorHelper.EmitCall(context, signed
  478. ? nameof(VectorHelper.SatF64ToS64)
  479. : nameof(VectorHelper.SatF64ToU64));
  480. }
  481. if (sizeF == 0)
  482. {
  483. context.Emit(OpCodes.Conv_U8);
  484. }
  485. EmitVectorInsert(context, op.Rd, index, sizeI);
  486. }
  487. if (op.RegisterSize == RegisterSize.Simd64)
  488. {
  489. EmitVectorZeroUpper(context, op.Rd);
  490. }
  491. }
  492. private static void EmitScalarFcvts(ILEmitterCtx context, int size, int fBits)
  493. {
  494. if (size < 0 || size > 1)
  495. {
  496. throw new ArgumentOutOfRangeException(nameof(size));
  497. }
  498. EmitF2iFBitsMul(context, size, fBits);
  499. if (context.CurrOp.RegisterSize == RegisterSize.Int32)
  500. {
  501. if (size == 0)
  502. {
  503. VectorHelper.EmitCall(context, nameof(VectorHelper.SatF32ToS32));
  504. }
  505. else /* if (size == 1) */
  506. {
  507. VectorHelper.EmitCall(context, nameof(VectorHelper.SatF64ToS32));
  508. }
  509. }
  510. else
  511. {
  512. if (size == 0)
  513. {
  514. VectorHelper.EmitCall(context, nameof(VectorHelper.SatF32ToS64));
  515. }
  516. else /* if (size == 1) */
  517. {
  518. VectorHelper.EmitCall(context, nameof(VectorHelper.SatF64ToS64));
  519. }
  520. }
  521. }
  522. private static void EmitScalarFcvtu(ILEmitterCtx context, int size, int fBits)
  523. {
  524. if (size < 0 || size > 1)
  525. {
  526. throw new ArgumentOutOfRangeException(nameof(size));
  527. }
  528. EmitF2iFBitsMul(context, size, fBits);
  529. if (context.CurrOp.RegisterSize == RegisterSize.Int32)
  530. {
  531. if (size == 0)
  532. {
  533. VectorHelper.EmitCall(context, nameof(VectorHelper.SatF32ToU32));
  534. }
  535. else /* if (size == 1) */
  536. {
  537. VectorHelper.EmitCall(context, nameof(VectorHelper.SatF64ToU32));
  538. }
  539. }
  540. else
  541. {
  542. if (size == 0)
  543. {
  544. VectorHelper.EmitCall(context, nameof(VectorHelper.SatF32ToU64));
  545. }
  546. else /* if (size == 1) */
  547. {
  548. VectorHelper.EmitCall(context, nameof(VectorHelper.SatF64ToU64));
  549. }
  550. }
  551. }
  552. private static void EmitF2iFBitsMul(ILEmitterCtx context, int size, int fBits)
  553. {
  554. if (fBits != 0)
  555. {
  556. if (size == 0)
  557. {
  558. context.EmitLdc_R4(MathF.Pow(2f, fBits));
  559. }
  560. else if (size == 1)
  561. {
  562. context.EmitLdc_R8(Math.Pow(2d, fBits));
  563. }
  564. else
  565. {
  566. throw new ArgumentOutOfRangeException(nameof(size));
  567. }
  568. context.Emit(OpCodes.Mul);
  569. }
  570. }
  571. private static void EmitI2fFBitsMul(ILEmitterCtx context, int size, int fBits)
  572. {
  573. if (fBits != 0)
  574. {
  575. if (size == 0)
  576. {
  577. context.EmitLdc_R4(1f / MathF.Pow(2f, fBits));
  578. }
  579. else if (size == 1)
  580. {
  581. context.EmitLdc_R8(1d / Math.Pow(2d, fBits));
  582. }
  583. else
  584. {
  585. throw new ArgumentOutOfRangeException(nameof(size));
  586. }
  587. context.Emit(OpCodes.Mul);
  588. }
  589. }
  590. }
  591. }