OpCodeT32AluImm.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using ARMeilleure.Common;
  2. using System.Runtime.Intrinsics;
  3. namespace ARMeilleure.Decoders
  4. {
  5. class OpCodeT32AluImm : OpCodeT32Alu, IOpCode32AluImm
  6. {
  7. public int Immediate { get; }
  8. public bool IsRotated { get; }
  9. public new static OpCode Create(InstDescriptor inst, ulong address, int opCode) => new OpCodeT32AluImm(inst, address, opCode);
  10. private static readonly Vector128<int> _factor = Vector128.Create(1, 0x00010001, 0x01000100, 0x01010101);
  11. public OpCodeT32AluImm(InstDescriptor inst, ulong address, int opCode) : base(inst, address, opCode)
  12. {
  13. int imm8 = (opCode >> 0) & 0xff;
  14. int imm3 = (opCode >> 12) & 7;
  15. int imm1 = (opCode >> 26) & 1;
  16. int imm12 = imm8 | (imm3 << 8) | (imm1 << 11);
  17. if ((imm12 >> 10) == 0)
  18. {
  19. Immediate = imm8 * _factor.GetElement((imm12 >> 8) & 3);
  20. IsRotated = false;
  21. }
  22. else
  23. {
  24. int shift = imm12 >> 7;
  25. Immediate = BitUtils.RotateRight(0x80 | (imm12 & 0x7f), shift, 32);
  26. IsRotated = shift != 0;
  27. }
  28. }
  29. }
  30. }