Arm64CodeGenCommonTests.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using ARMeilleure.CodeGen.Arm64;
  2. using NUnit.Framework;
  3. namespace Ryujinx.Tests.Cpu
  4. {
  5. public class Arm64CodeGenCommonTests
  6. {
  7. public struct TestCase
  8. {
  9. public ulong Value;
  10. public bool Valid;
  11. public int ImmN;
  12. public int ImmS;
  13. public int ImmR;
  14. }
  15. public static readonly TestCase[] TestCases =
  16. {
  17. new() { Value = 0, Valid = false, ImmN = 0, ImmS = 0, ImmR = 0 },
  18. new() { Value = 0x970977f35f848714, Valid = false, ImmN = 0, ImmS = 0, ImmR = 0 },
  19. new() { Value = 0xffffffffffffffff, Valid = false, ImmN = 0, ImmS = 0, ImmR = 0 },
  20. new() { Value = 0x5555555555555555, Valid = true, ImmN = 0, ImmS = 0x3c, ImmR = 0 },
  21. new() { Value = 0xaaaaaaaaaaaaaaaa, Valid = true, ImmN = 0, ImmS = 0x3c, ImmR = 1 },
  22. new() { Value = 0x6666666666666666, Valid = true, ImmN = 0, ImmS = 0x39, ImmR = 3 },
  23. new() { Value = 0x1c1c1c1c1c1c1c1c, Valid = true, ImmN = 0, ImmS = 0x32, ImmR = 6 },
  24. new() { Value = 0x0f0f0f0f0f0f0f0f, Valid = true, ImmN = 0, ImmS = 0x33, ImmR = 0 },
  25. new() { Value = 0xf1f1f1f1f1f1f1f1, Valid = true, ImmN = 0, ImmS = 0x34, ImmR = 4 },
  26. new() { Value = 0xe7e7e7e7e7e7e7e7, Valid = true, ImmN = 0, ImmS = 0x35, ImmR = 3 },
  27. new() { Value = 0xc001c001c001c001, Valid = true, ImmN = 0, ImmS = 0x22, ImmR = 2 },
  28. new() { Value = 0x0000038000000380, Valid = true, ImmN = 0, ImmS = 0x02, ImmR = 25 },
  29. new() { Value = 0xffff8fffffff8fff, Valid = true, ImmN = 0, ImmS = 0x1c, ImmR = 17 },
  30. new() { Value = 0x000000000ffff800, Valid = true, ImmN = 1, ImmS = 0x10, ImmR = 53 },
  31. };
  32. [Test]
  33. public void BitImmTests([ValueSource(nameof(TestCases))] TestCase test)
  34. {
  35. bool valid = CodeGenCommon.TryEncodeBitMask(test.Value, out int immN, out int immS, out int immR);
  36. Assert.That(valid, Is.EqualTo(test.Valid));
  37. Assert.That(immN, Is.EqualTo(test.ImmN));
  38. Assert.That(immS, Is.EqualTo(test.ImmS));
  39. Assert.That(immR, Is.EqualTo(test.ImmR));
  40. }
  41. }
  42. }