CpuTestMov.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #define Mov
  2. using ChocolArm64.State;
  3. using NUnit.Framework;
  4. namespace Ryujinx.Tests.Cpu
  5. {
  6. [Category("Mov")] // Tested: second half of 2018.
  7. public sealed class CpuTestMov : CpuTest
  8. {
  9. #if Mov
  10. private const int RndCntImm = 2;
  11. [Test, Pairwise, Description("MOVK <Xd>, #<imm>{, LSL #<shift>}")]
  12. public void Movk_64bit([Values(0u, 31u)] uint Rd,
  13. [Random(RndCntImm)] ulong _Xd,
  14. [Values(0u, 65535u)] [Random(0u, 65535u, RndCntImm)] uint imm,
  15. [Values(0u, 16u, 32u, 48u)] uint shift)
  16. {
  17. uint Opcode = 0xF2800000; // MOVK X0, #0, LSL #0
  18. Opcode |= ((Rd & 31) << 0);
  19. Opcode |= (((shift / 16) & 3) << 21) | ((imm & 65535) << 5);
  20. ulong _X31 = TestContext.CurrentContext.Random.NextULong();
  21. AThreadState ThreadState = SingleOpcode(Opcode, X0: _Xd, X31: _X31);
  22. CompareAgainstUnicorn();
  23. }
  24. [Test, Pairwise, Description("MOVK <Wd>, #<imm>{, LSL #<shift>}")]
  25. public void Movk_32bit([Values(0u, 31u)] uint Rd,
  26. [Random(RndCntImm)] uint _Wd,
  27. [Values(0u, 65535u)] [Random(0u, 65535u, RndCntImm)] uint imm,
  28. [Values(0u, 16u)] uint shift)
  29. {
  30. uint Opcode = 0x72800000; // MOVK W0, #0, LSL #0
  31. Opcode |= ((Rd & 31) << 0);
  32. Opcode |= (((shift / 16) & 3) << 21) | ((imm & 65535) << 5);
  33. uint _W31 = TestContext.CurrentContext.Random.NextUInt();
  34. AThreadState ThreadState = SingleOpcode(Opcode, X0: _Wd, X31: _W31);
  35. CompareAgainstUnicorn();
  36. }
  37. [Test, Pairwise, Description("MOVN <Xd>, #<imm>{, LSL #<shift>}")]
  38. public void Movn_64bit([Values(0u, 31u)] uint Rd,
  39. [Values(0u, 65535u)] [Random(0u, 65535u, RndCntImm)] uint imm,
  40. [Values(0u, 16u, 32u, 48u)] uint shift)
  41. {
  42. uint Opcode = 0x92800000; // MOVN X0, #0, LSL #0
  43. Opcode |= ((Rd & 31) << 0);
  44. Opcode |= (((shift / 16) & 3) << 21) | ((imm & 65535) << 5);
  45. ulong _X31 = TestContext.CurrentContext.Random.NextULong();
  46. AThreadState ThreadState = SingleOpcode(Opcode, X31: _X31);
  47. CompareAgainstUnicorn();
  48. }
  49. [Test, Pairwise, Description("MOVN <Wd>, #<imm>{, LSL #<shift>}")]
  50. public void Movn_32bit([Values(0u, 31u)] uint Rd,
  51. [Values(0u, 65535u)] [Random(0u, 65535u, RndCntImm)] uint imm,
  52. [Values(0u, 16u)] uint shift)
  53. {
  54. uint Opcode = 0x12800000; // MOVN W0, #0, LSL #0
  55. Opcode |= ((Rd & 31) << 0);
  56. Opcode |= (((shift / 16) & 3) << 21) | ((imm & 65535) << 5);
  57. uint _W31 = TestContext.CurrentContext.Random.NextUInt();
  58. AThreadState ThreadState = SingleOpcode(Opcode, X31: _W31);
  59. CompareAgainstUnicorn();
  60. }
  61. [Test, Pairwise, Description("MOVZ <Xd>, #<imm>{, LSL #<shift>}")]
  62. public void Movz_64bit([Values(0u, 31u)] uint Rd,
  63. [Values(0u, 65535u)] [Random(0u, 65535u, RndCntImm)] uint imm,
  64. [Values(0u, 16u, 32u, 48u)] uint shift)
  65. {
  66. uint Opcode = 0xD2800000; // MOVZ X0, #0, LSL #0
  67. Opcode |= ((Rd & 31) << 0);
  68. Opcode |= (((shift / 16) & 3) << 21) | ((imm & 65535) << 5);
  69. ulong _X31 = TestContext.CurrentContext.Random.NextULong();
  70. AThreadState ThreadState = SingleOpcode(Opcode, X31: _X31);
  71. CompareAgainstUnicorn();
  72. }
  73. [Test, Pairwise, Description("MOVZ <Wd>, #<imm>{, LSL #<shift>}")]
  74. public void Movz_32bit([Values(0u, 31u)] uint Rd,
  75. [Values(0u, 65535u)] [Random(0u, 65535u, RndCntImm)] uint imm,
  76. [Values(0u, 16u)] uint shift)
  77. {
  78. uint Opcode = 0x52800000; // MOVZ W0, #0, LSL #0
  79. Opcode |= ((Rd & 31) << 0);
  80. Opcode |= (((shift / 16) & 3) << 21) | ((imm & 65535) << 5);
  81. uint _W31 = TestContext.CurrentContext.Random.NextUInt();
  82. AThreadState ThreadState = SingleOpcode(Opcode, X31: _W31);
  83. CompareAgainstUnicorn();
  84. }
  85. #endif
  86. }
  87. }