AInstEmitCcmp.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using ChocolArm64.Decoder;
  2. using ChocolArm64.State;
  3. using ChocolArm64.Translation;
  4. using System;
  5. using System.Reflection.Emit;
  6. using static ChocolArm64.Instruction.AInstEmitAluHelper;
  7. namespace ChocolArm64.Instruction
  8. {
  9. static partial class AInstEmit
  10. {
  11. private enum CcmpOp
  12. {
  13. Cmp,
  14. Cmn
  15. }
  16. public static void Ccmn(AILEmitterCtx Context) => EmitCcmp(Context, CcmpOp.Cmn);
  17. public static void Ccmp(AILEmitterCtx Context) => EmitCcmp(Context, CcmpOp.Cmp);
  18. private static void EmitCcmp(AILEmitterCtx Context, CcmpOp CmpOp)
  19. {
  20. AOpCodeCcmp Op = (AOpCodeCcmp)Context.CurrOp;
  21. AILLabel LblTrue = new AILLabel();
  22. AILLabel LblEnd = new AILLabel();
  23. Context.EmitCondBranch(LblTrue, Op.Cond);
  24. Context.EmitLdc_I4((Op.NZCV >> 0) & 1);
  25. Context.EmitStflg((int)APState.VBit);
  26. Context.EmitLdc_I4((Op.NZCV >> 1) & 1);
  27. Context.EmitStflg((int)APState.CBit);
  28. Context.EmitLdc_I4((Op.NZCV >> 2) & 1);
  29. Context.EmitStflg((int)APState.ZBit);
  30. Context.EmitLdc_I4((Op.NZCV >> 3) & 1);
  31. Context.EmitStflg((int)APState.NBit);
  32. Context.Emit(OpCodes.Br_S, LblEnd);
  33. Context.MarkLabel(LblTrue);
  34. EmitDataLoadOpers(Context);
  35. if (CmpOp == CcmpOp.Cmp)
  36. {
  37. Context.Emit(OpCodes.Sub);
  38. Context.EmitZNFlagCheck();
  39. EmitSubsCCheck(Context);
  40. EmitSubsVCheck(Context);
  41. }
  42. else if (CmpOp == CcmpOp.Cmn)
  43. {
  44. Context.Emit(OpCodes.Add);
  45. Context.EmitZNFlagCheck();
  46. EmitAddsCCheck(Context);
  47. EmitAddsVCheck(Context);
  48. }
  49. else
  50. {
  51. throw new ArgumentException(nameof(CmpOp));
  52. }
  53. Context.Emit(OpCodes.Pop);
  54. Context.MarkLabel(LblEnd);
  55. }
  56. }
  57. }