InstEmitSimdCvt.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  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. Type[] typesCvt = new Type[] { typeof(Vector128<float>), typeof(Vector128<double>) };
  22. VectorHelper.EmitCall(context, nameof(VectorHelper.VectorSingleZero));
  23. context.EmitLdvec(op.Rn);
  24. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertScalarToVector128Single), typesCvt));
  25. context.EmitStvec(op.Rd);
  26. }
  27. else if (op.Size == 0 && op.Opc == 1)
  28. {
  29. //Single -> Double.
  30. Type[] typesCvt = new Type[] { typeof(Vector128<double>), typeof(Vector128<float>) };
  31. VectorHelper.EmitCall(context, nameof(VectorHelper.VectorDoubleZero));
  32. context.EmitLdvec(op.Rn);
  33. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertScalarToVector128Double), typesCvt));
  34. context.EmitStvec(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. context.EmitLdvec(op.Rn);
  65. if (op.RegisterSize == RegisterSize.Simd128)
  66. {
  67. context.EmitLdvec(op.Rn);
  68. context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.MoveHighToLow)));
  69. }
  70. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToVector128Double), typesCvt));
  71. context.EmitStvec(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. context.EmitLdvec(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_Fixed(context);
  189. }
  190. public static void Fcvtzs_S(ILEmitterCtx context)
  191. {
  192. EmitFcvtz(context, signed: true, scalar: true);
  193. }
  194. public static void Fcvtzs_V(ILEmitterCtx context)
  195. {
  196. EmitFcvtz(context, signed: true, scalar: false);
  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_Fixed(context);
  205. }
  206. public static void Fcvtzu_S(ILEmitterCtx context)
  207. {
  208. EmitFcvtz(context, signed: false, scalar: true);
  209. }
  210. public static void Fcvtzu_V(ILEmitterCtx context)
  211. {
  212. EmitFcvtz(context, signed: false, scalar: false);
  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_Gp_Fixed(ILEmitterCtx context)
  226. {
  227. OpCodeSimdCvt64 op = (OpCodeSimdCvt64)context.CurrOp;
  228. context.EmitLdintzr(op.Rn);
  229. if (context.CurrOp.RegisterSize == RegisterSize.Int32)
  230. {
  231. context.Emit(OpCodes.Conv_I4);
  232. }
  233. EmitFloatCast(context, op.Size);
  234. EmitI2fFBitsMul(context, op.Size, op.FBits);
  235. EmitScalarSetF(context, op.Rd, op.Size);
  236. }
  237. public static void Scvtf_S(ILEmitterCtx context)
  238. {
  239. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  240. EmitVectorExtractSx(context, op.Rn, 0, op.Size + 2);
  241. EmitFloatCast(context, op.Size);
  242. EmitScalarSetF(context, op.Rd, op.Size);
  243. }
  244. public static void Scvtf_V(ILEmitterCtx context)
  245. {
  246. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  247. int sizeF = op.Size & 1;
  248. if (Optimizations.UseSse2 && sizeF == 0)
  249. {
  250. Type[] typesCvt = new Type[] { typeof(Vector128<int>) };
  251. context.EmitLdvec(op.Rn);
  252. context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToVector128Single), typesCvt));
  253. context.EmitStvec(op.Rd);
  254. if (op.RegisterSize == RegisterSize.Simd64)
  255. {
  256. EmitVectorZeroUpper(context, op.Rd);
  257. }
  258. }
  259. else
  260. {
  261. EmitVectorCvtf(context, signed: true);
  262. }
  263. }
  264. public static void Ucvtf_Gp(ILEmitterCtx context)
  265. {
  266. OpCodeSimdCvt64 op = (OpCodeSimdCvt64)context.CurrOp;
  267. context.EmitLdintzr(op.Rn);
  268. if (context.CurrOp.RegisterSize == RegisterSize.Int32)
  269. {
  270. context.Emit(OpCodes.Conv_U4);
  271. }
  272. context.Emit(OpCodes.Conv_R_Un);
  273. EmitFloatCast(context, op.Size);
  274. EmitScalarSetF(context, op.Rd, op.Size);
  275. }
  276. public static void Ucvtf_Gp_Fixed(ILEmitterCtx context)
  277. {
  278. OpCodeSimdCvt64 op = (OpCodeSimdCvt64)context.CurrOp;
  279. context.EmitLdintzr(op.Rn);
  280. if (context.CurrOp.RegisterSize == RegisterSize.Int32)
  281. {
  282. context.Emit(OpCodes.Conv_U4);
  283. }
  284. context.Emit(OpCodes.Conv_R_Un);
  285. EmitFloatCast(context, op.Size);
  286. EmitI2fFBitsMul(context, op.Size, op.FBits);
  287. EmitScalarSetF(context, op.Rd, op.Size);
  288. }
  289. public static void Ucvtf_S(ILEmitterCtx context)
  290. {
  291. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  292. EmitVectorExtractZx(context, op.Rn, 0, op.Size + 2);
  293. context.Emit(OpCodes.Conv_R_Un);
  294. EmitFloatCast(context, op.Size);
  295. EmitScalarSetF(context, op.Rd, op.Size);
  296. }
  297. public static void Ucvtf_V(ILEmitterCtx context)
  298. {
  299. EmitVectorCvtf(context, signed: false);
  300. }
  301. private static void EmitFcvtn(ILEmitterCtx context, bool signed, bool scalar)
  302. {
  303. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  304. int sizeF = op.Size & 1;
  305. int sizeI = sizeF + 2;
  306. int bytes = op.GetBitsCount() >> 3;
  307. int elems = !scalar ? bytes >> sizeI : 1;
  308. for (int index = 0; index < elems; index++)
  309. {
  310. EmitVectorExtractF(context, op.Rn, index, sizeF);
  311. EmitRoundMathCall(context, MidpointRounding.ToEven);
  312. if (sizeF == 0)
  313. {
  314. VectorHelper.EmitCall(context, signed
  315. ? nameof(VectorHelper.SatF32ToS32)
  316. : nameof(VectorHelper.SatF32ToU32));
  317. context.Emit(OpCodes.Conv_U8);
  318. }
  319. else /* if (sizeF == 1) */
  320. {
  321. VectorHelper.EmitCall(context, signed
  322. ? nameof(VectorHelper.SatF64ToS64)
  323. : nameof(VectorHelper.SatF64ToU64));
  324. }
  325. if (scalar)
  326. {
  327. EmitVectorZeroAll(context, op.Rd);
  328. }
  329. EmitVectorInsert(context, op.Rd, index, sizeI);
  330. }
  331. if (op.RegisterSize == RegisterSize.Simd64)
  332. {
  333. EmitVectorZeroUpper(context, op.Rd);
  334. }
  335. }
  336. private static void EmitFcvtz(ILEmitterCtx context, bool signed, bool scalar)
  337. {
  338. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  339. int sizeF = op.Size & 1;
  340. int sizeI = sizeF + 2;
  341. int fBits = GetFBits(context);
  342. int bytes = op.GetBitsCount() >> 3;
  343. int elems = !scalar ? bytes >> sizeI : 1;
  344. for (int index = 0; index < elems; index++)
  345. {
  346. EmitVectorExtractF(context, op.Rn, index, sizeF);
  347. EmitF2iFBitsMul(context, sizeF, fBits);
  348. if (sizeF == 0)
  349. {
  350. VectorHelper.EmitCall(context, signed
  351. ? nameof(VectorHelper.SatF32ToS32)
  352. : nameof(VectorHelper.SatF32ToU32));
  353. context.Emit(OpCodes.Conv_U8);
  354. }
  355. else /* if (sizeF == 1) */
  356. {
  357. VectorHelper.EmitCall(context, signed
  358. ? nameof(VectorHelper.SatF64ToS64)
  359. : nameof(VectorHelper.SatF64ToU64));
  360. }
  361. if (scalar)
  362. {
  363. EmitVectorZeroAll(context, op.Rd);
  364. }
  365. EmitVectorInsert(context, op.Rd, index, sizeI);
  366. }
  367. if (op.RegisterSize == RegisterSize.Simd64)
  368. {
  369. EmitVectorZeroUpper(context, op.Rd);
  370. }
  371. }
  372. private static void EmitFcvt_s_Gp(ILEmitterCtx context, Action emit)
  373. {
  374. EmitFcvt___Gp(context, emit, true);
  375. }
  376. private static void EmitFcvt_u_Gp(ILEmitterCtx context, Action emit)
  377. {
  378. EmitFcvt___Gp(context, emit, false);
  379. }
  380. private static void EmitFcvt___Gp(ILEmitterCtx context, Action emit, bool signed)
  381. {
  382. OpCodeSimdCvt64 op = (OpCodeSimdCvt64)context.CurrOp;
  383. EmitVectorExtractF(context, op.Rn, 0, op.Size);
  384. emit();
  385. if (signed)
  386. {
  387. EmitScalarFcvts(context, op.Size, 0);
  388. }
  389. else
  390. {
  391. EmitScalarFcvtu(context, op.Size, 0);
  392. }
  393. if (context.CurrOp.RegisterSize == RegisterSize.Int32)
  394. {
  395. context.Emit(OpCodes.Conv_U8);
  396. }
  397. context.EmitStintzr(op.Rd);
  398. }
  399. private static void EmitFcvtzs_Gp_Fixed(ILEmitterCtx context)
  400. {
  401. EmitFcvtz__Gp_Fixed(context, true);
  402. }
  403. private static void EmitFcvtzu_Gp_Fixed(ILEmitterCtx context)
  404. {
  405. EmitFcvtz__Gp_Fixed(context, false);
  406. }
  407. private static void EmitFcvtz__Gp_Fixed(ILEmitterCtx context, bool signed)
  408. {
  409. OpCodeSimdCvt64 op = (OpCodeSimdCvt64)context.CurrOp;
  410. EmitVectorExtractF(context, op.Rn, 0, op.Size);
  411. if (signed)
  412. {
  413. EmitScalarFcvts(context, op.Size, op.FBits);
  414. }
  415. else
  416. {
  417. EmitScalarFcvtu(context, op.Size, op.FBits);
  418. }
  419. if (context.CurrOp.RegisterSize == RegisterSize.Int32)
  420. {
  421. context.Emit(OpCodes.Conv_U8);
  422. }
  423. context.EmitStintzr(op.Rd);
  424. }
  425. private static void EmitVectorCvtf(ILEmitterCtx context, bool signed)
  426. {
  427. OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
  428. int sizeF = op.Size & 1;
  429. int sizeI = sizeF + 2;
  430. int fBits = GetFBits(context);
  431. int bytes = op.GetBitsCount() >> 3;
  432. int elems = bytes >> sizeI;
  433. for (int index = 0; index < elems; index++)
  434. {
  435. EmitVectorExtract(context, op.Rn, index, sizeI, signed);
  436. if (!signed)
  437. {
  438. context.Emit(OpCodes.Conv_R_Un);
  439. }
  440. EmitFloatCast(context, sizeF);
  441. EmitI2fFBitsMul(context, sizeF, fBits);
  442. EmitVectorInsertF(context, op.Rd, index, sizeF);
  443. }
  444. if (op.RegisterSize == RegisterSize.Simd64)
  445. {
  446. EmitVectorZeroUpper(context, op.Rd);
  447. }
  448. }
  449. private static int GetFBits(ILEmitterCtx context)
  450. {
  451. if (context.CurrOp is OpCodeSimdShImm64 op)
  452. {
  453. return GetImmShr(op);
  454. }
  455. return 0;
  456. }
  457. private static void EmitFloatCast(ILEmitterCtx context, int size)
  458. {
  459. if (size == 0)
  460. {
  461. context.Emit(OpCodes.Conv_R4);
  462. }
  463. else if (size == 1)
  464. {
  465. context.Emit(OpCodes.Conv_R8);
  466. }
  467. else
  468. {
  469. throw new ArgumentOutOfRangeException(nameof(size));
  470. }
  471. }
  472. private static void EmitScalarFcvts(ILEmitterCtx context, int size, int fBits)
  473. {
  474. if (size < 0 || size > 1)
  475. {
  476. throw new ArgumentOutOfRangeException(nameof(size));
  477. }
  478. EmitF2iFBitsMul(context, size, fBits);
  479. if (context.CurrOp.RegisterSize == RegisterSize.Int32)
  480. {
  481. if (size == 0)
  482. {
  483. VectorHelper.EmitCall(context, nameof(VectorHelper.SatF32ToS32));
  484. }
  485. else /* if (size == 1) */
  486. {
  487. VectorHelper.EmitCall(context, nameof(VectorHelper.SatF64ToS32));
  488. }
  489. }
  490. else
  491. {
  492. if (size == 0)
  493. {
  494. VectorHelper.EmitCall(context, nameof(VectorHelper.SatF32ToS64));
  495. }
  496. else /* if (size == 1) */
  497. {
  498. VectorHelper.EmitCall(context, nameof(VectorHelper.SatF64ToS64));
  499. }
  500. }
  501. }
  502. private static void EmitScalarFcvtu(ILEmitterCtx context, int size, int fBits)
  503. {
  504. if (size < 0 || size > 1)
  505. {
  506. throw new ArgumentOutOfRangeException(nameof(size));
  507. }
  508. EmitF2iFBitsMul(context, size, fBits);
  509. if (context.CurrOp.RegisterSize == RegisterSize.Int32)
  510. {
  511. if (size == 0)
  512. {
  513. VectorHelper.EmitCall(context, nameof(VectorHelper.SatF32ToU32));
  514. }
  515. else /* if (size == 1) */
  516. {
  517. VectorHelper.EmitCall(context, nameof(VectorHelper.SatF64ToU32));
  518. }
  519. }
  520. else
  521. {
  522. if (size == 0)
  523. {
  524. VectorHelper.EmitCall(context, nameof(VectorHelper.SatF32ToU64));
  525. }
  526. else /* if (size == 1) */
  527. {
  528. VectorHelper.EmitCall(context, nameof(VectorHelper.SatF64ToU64));
  529. }
  530. }
  531. }
  532. private static void EmitF2iFBitsMul(ILEmitterCtx context, int size, int fBits)
  533. {
  534. if (fBits != 0)
  535. {
  536. if (size == 0)
  537. {
  538. context.EmitLdc_R4(MathF.Pow(2f, fBits));
  539. }
  540. else if (size == 1)
  541. {
  542. context.EmitLdc_R8(Math.Pow(2d, fBits));
  543. }
  544. else
  545. {
  546. throw new ArgumentOutOfRangeException(nameof(size));
  547. }
  548. context.Emit(OpCodes.Mul);
  549. }
  550. }
  551. private static void EmitI2fFBitsMul(ILEmitterCtx context, int size, int fBits)
  552. {
  553. if (fBits != 0)
  554. {
  555. if (size == 0)
  556. {
  557. context.EmitLdc_R4(1f / MathF.Pow(2f, fBits));
  558. }
  559. else if (size == 1)
  560. {
  561. context.EmitLdc_R8(1d / Math.Pow(2d, fBits));
  562. }
  563. else
  564. {
  565. throw new ArgumentOutOfRangeException(nameof(size));
  566. }
  567. context.Emit(OpCodes.Mul);
  568. }
  569. }
  570. }
  571. }