CpuTestSimdIns.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #define SimdIns
  2. using NUnit.Framework;
  3. using System.Runtime.Intrinsics;
  4. namespace Ryujinx.Tests.Cpu
  5. {
  6. [Category("SimdIns")]
  7. public sealed class CpuTestSimdIns : CpuTest
  8. {
  9. #if SimdIns
  10. #region "ValueSource"
  11. private static ulong[] _1D_()
  12. {
  13. return new ulong[] { 0x0000000000000000ul, 0x7FFFFFFFFFFFFFFFul,
  14. 0x8000000000000000ul, 0xFFFFFFFFFFFFFFFFul };
  15. }
  16. private static ulong[] _8B4H_()
  17. {
  18. return new ulong[] { 0x0000000000000000ul, 0x7F7F7F7F7F7F7F7Ful,
  19. 0x8080808080808080ul, 0x7FFF7FFF7FFF7FFFul,
  20. 0x8000800080008000ul, 0xFFFFFFFFFFFFFFFFul };
  21. }
  22. private static ulong[] _8B4H2S_()
  23. {
  24. return new ulong[] { 0x0000000000000000ul, 0x7F7F7F7F7F7F7F7Ful,
  25. 0x8080808080808080ul, 0x7FFF7FFF7FFF7FFFul,
  26. 0x8000800080008000ul, 0x7FFFFFFF7FFFFFFFul,
  27. 0x8000000080000000ul, 0xFFFFFFFFFFFFFFFFul };
  28. }
  29. private static uint[] _W_()
  30. {
  31. return new uint[] { 0x00000000u, 0x0000007Fu,
  32. 0x00000080u, 0x000000FFu,
  33. 0x00007FFFu, 0x00008000u,
  34. 0x0000FFFFu, 0x7FFFFFFFu,
  35. 0x80000000u, 0xFFFFFFFFu };
  36. }
  37. private static ulong[] _X_()
  38. {
  39. return new ulong[] { 0x0000000000000000ul, 0x7FFFFFFFFFFFFFFFul,
  40. 0x8000000000000000ul, 0xFFFFFFFFFFFFFFFFul };
  41. }
  42. #endregion
  43. private const int RndCnt = 2;
  44. [Test, Pairwise, Description("DUP <Vd>.<T>, <R><n>")]
  45. public void Dup_Gp_W([Values(0u)] uint rd,
  46. [Values(1u, 31u)] uint rn,
  47. [ValueSource("_W_")] [Random(RndCnt)] uint wn,
  48. [Values(0, 1, 2)] int size, // Q0: <8B, 4H, 2S>
  49. [Values(0b0u, 0b1u)] uint q) // Q1: <16B, 8H, 4S>
  50. {
  51. uint imm5 = (1u << size) & 0x1Fu;
  52. uint opcode = 0x0E000C00; // RESERVED
  53. opcode |= ((rn & 31) << 5) | ((rd & 31) << 0);
  54. opcode |= (imm5 << 16);
  55. opcode |= ((q & 1) << 30);
  56. ulong z = TestContext.CurrentContext.Random.NextULong();
  57. Vector128<float> v0 = MakeVectorE0E1(z, z);
  58. SingleOpcode(opcode, x1: wn, v0: v0);
  59. CompareAgainstUnicorn();
  60. }
  61. [Test, Pairwise, Description("DUP <Vd>.<T>, <R><n>")]
  62. public void Dup_Gp_X([Values(0u)] uint rd,
  63. [Values(1u, 31u)] uint rn,
  64. [ValueSource("_X_")] [Random(RndCnt)] ulong xn)
  65. {
  66. uint opcode = 0x4E080C00; // DUP V0.2D, X0
  67. opcode |= ((rn & 31) << 5) | ((rd & 31) << 0);
  68. ulong z = TestContext.CurrentContext.Random.NextULong();
  69. Vector128<float> v0 = MakeVectorE0E1(z, z);
  70. SingleOpcode(opcode, x1: xn, v0: v0);
  71. CompareAgainstUnicorn();
  72. }
  73. [Test, Pairwise, Description("SMOV <Wd>, <Vn>.<Ts>[<index>]")]
  74. public void Smov_S_W([Values(0u, 31u)] uint rd,
  75. [Values(1u)] uint rn,
  76. [ValueSource("_8B4H_")] [Random(RndCnt)] ulong a,
  77. [Values(0, 1)] int size, // <B, H>
  78. [Values(0u, 1u, 2u, 3u)] uint index)
  79. {
  80. uint imm5 = (index << (size + 1) | 1u << size) & 0x1Fu;
  81. uint opcode = 0x0E002C00; // RESERVED
  82. opcode |= ((rn & 31) << 5) | ((rd & 31) << 0);
  83. opcode |= (imm5 << 16);
  84. ulong x0 = (ulong)TestContext.CurrentContext.Random.NextUInt() << 32;
  85. uint w31 = TestContext.CurrentContext.Random.NextUInt();
  86. Vector128<float> v1 = MakeVectorE0(a);
  87. SingleOpcode(opcode, x0: x0, x31: w31, v1: v1);
  88. CompareAgainstUnicorn();
  89. }
  90. [Test, Pairwise, Description("SMOV <Xd>, <Vn>.<Ts>[<index>]")]
  91. public void Smov_S_X([Values(0u, 31u)] uint rd,
  92. [Values(1u)] uint rn,
  93. [ValueSource("_8B4H2S_")] [Random(RndCnt)] ulong a,
  94. [Values(0, 1, 2)] int size, // <B, H, S>
  95. [Values(0u, 1u)] uint index)
  96. {
  97. uint imm5 = (index << (size + 1) | 1u << size) & 0x1Fu;
  98. uint opcode = 0x4E002C00; // RESERVED
  99. opcode |= ((rn & 31) << 5) | ((rd & 31) << 0);
  100. opcode |= (imm5 << 16);
  101. ulong x31 = TestContext.CurrentContext.Random.NextULong();
  102. Vector128<float> v1 = MakeVectorE0(a);
  103. SingleOpcode(opcode, x31: x31, v1: v1);
  104. CompareAgainstUnicorn();
  105. }
  106. [Test, Pairwise, Description("UMOV <Wd>, <Vn>.<Ts>[<index>]")]
  107. public void Umov_S_W([Values(0u, 31u)] uint rd,
  108. [Values(1u)] uint rn,
  109. [ValueSource("_8B4H2S_")] [Random(RndCnt)] ulong a,
  110. [Values(0, 1, 2)] int size, // <B, H, S>
  111. [Values(0u, 1u)] uint index)
  112. {
  113. uint imm5 = (index << (size + 1) | 1u << size) & 0x1Fu;
  114. uint opcode = 0x0E003C00; // RESERVED
  115. opcode |= ((rn & 31) << 5) | ((rd & 31) << 0);
  116. opcode |= (imm5 << 16);
  117. ulong x0 = (ulong)TestContext.CurrentContext.Random.NextUInt() << 32;
  118. uint w31 = TestContext.CurrentContext.Random.NextUInt();
  119. Vector128<float> v1 = MakeVectorE0(a);
  120. SingleOpcode(opcode, x0: x0, x31: w31, v1: v1);
  121. CompareAgainstUnicorn();
  122. }
  123. [Test, Pairwise, Description("UMOV <Xd>, <Vn>.<Ts>[<index>]")]
  124. public void Umov_S_X([Values(0u, 31u)] uint rd,
  125. [Values(1u)] uint rn,
  126. [ValueSource("_1D_")] [Random(RndCnt)] ulong a,
  127. [Values(3)] int size, // <D>
  128. [Values(0u)] uint index)
  129. {
  130. uint imm5 = (index << (size + 1) | 1u << size) & 0x1Fu;
  131. uint opcode = 0x4E003C00; // RESERVED
  132. opcode |= ((rn & 31) << 5) | ((rd & 31) << 0);
  133. opcode |= (imm5 << 16);
  134. ulong x31 = TestContext.CurrentContext.Random.NextULong();
  135. Vector128<float> v1 = MakeVectorE0(a);
  136. SingleOpcode(opcode, x31: x31, v1: v1);
  137. CompareAgainstUnicorn();
  138. }
  139. #endif
  140. }
  141. }