CpuTestSimdImm.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. #define SimdImm
  2. using ARMeilleure.State;
  3. using NUnit.Framework;
  4. using System.Collections.Generic;
  5. namespace Ryujinx.Tests.Cpu
  6. {
  7. [Category("SimdImm")]
  8. public sealed class CpuTestSimdImm : CpuTest
  9. {
  10. #if SimdImm
  11. #region "Helper methods"
  12. // abcdefgh -> aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffffgggggggghhhhhhhh
  13. private static ulong ExpandImm8(byte imm8)
  14. {
  15. ulong imm64 = 0ul;
  16. for (int i = 0, j = 0; i < 8; i++, j += 8)
  17. {
  18. if (((imm8 >> i) & 0b1) != 0)
  19. {
  20. imm64 |= 0b11111111ul << j;
  21. }
  22. }
  23. return imm64;
  24. }
  25. // aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffffgggggggghhhhhhhh -> abcdefgh
  26. private static byte ShrinkImm64(ulong imm64)
  27. {
  28. byte imm8 = 0;
  29. for (int i = 0, j = 0; i < 8; i++, j += 8)
  30. {
  31. if (((imm64 >> j) & 0b11111111ul) != 0ul) // Note: no format check.
  32. {
  33. imm8 |= (byte)(0b1 << i);
  34. }
  35. }
  36. return imm8;
  37. }
  38. #endregion
  39. #region "ValueSource (Types)"
  40. private static ulong[] _2S_()
  41. {
  42. return new ulong[] { 0x0000000000000000ul, 0x7FFFFFFF7FFFFFFFul,
  43. 0x8000000080000000ul, 0xFFFFFFFFFFFFFFFFul };
  44. }
  45. private static ulong[] _4H_()
  46. {
  47. return new ulong[] { 0x0000000000000000ul, 0x7FFF7FFF7FFF7FFFul,
  48. 0x8000800080008000ul, 0xFFFFFFFFFFFFFFFFul };
  49. }
  50. private static IEnumerable<byte> _8BIT_IMM_()
  51. {
  52. yield return 0x00;
  53. yield return 0x7F;
  54. yield return 0x80;
  55. yield return 0xFF;
  56. for (int cnt = 1; cnt <= RndCntImm8; cnt++)
  57. {
  58. byte imm8 = TestContext.CurrentContext.Random.NextByte();
  59. yield return imm8;
  60. }
  61. }
  62. private static IEnumerable<ulong> _64BIT_IMM_()
  63. {
  64. yield return ExpandImm8(0x00);
  65. yield return ExpandImm8(0x7F);
  66. yield return ExpandImm8(0x80);
  67. yield return ExpandImm8(0xFF);
  68. for (int cnt = 1; cnt <= RndCntImm64; cnt++)
  69. {
  70. byte imm8 = TestContext.CurrentContext.Random.NextByte();
  71. yield return ExpandImm8(imm8);
  72. }
  73. }
  74. #endregion
  75. #region "ValueSource (Opcodes)"
  76. private static uint[] _Bic_Orr_Vi_16bit_()
  77. {
  78. return new uint[]
  79. {
  80. 0x2F009400u, // BIC V0.4H, #0
  81. 0x0F009400u // ORR V0.4H, #0
  82. };
  83. }
  84. private static uint[] _Bic_Orr_Vi_32bit_()
  85. {
  86. return new uint[]
  87. {
  88. 0x2F001400u, // BIC V0.2S, #0
  89. 0x0F001400u // ORR V0.2S, #0
  90. };
  91. }
  92. private static uint[] _F_Mov_Vi_2S_()
  93. {
  94. return new uint[]
  95. {
  96. 0x0F00F400u // FMOV V0.2S, #2.0
  97. };
  98. }
  99. private static uint[] _F_Mov_Vi_4S_()
  100. {
  101. return new uint[]
  102. {
  103. 0x4F00F400u // FMOV V0.4S, #2.0
  104. };
  105. }
  106. private static uint[] _F_Mov_Vi_2D_()
  107. {
  108. return new uint[]
  109. {
  110. 0x6F00F400u // FMOV V0.2D, #2.0
  111. };
  112. }
  113. private static uint[] _Movi_V_8bit_()
  114. {
  115. return new uint[]
  116. {
  117. 0x0F00E400u // MOVI V0.8B, #0
  118. };
  119. }
  120. private static uint[] _Movi_Mvni_V_16bit_shifted_imm_()
  121. {
  122. return new uint[]
  123. {
  124. 0x0F008400u, // MOVI V0.4H, #0
  125. 0x2F008400u // MVNI V0.4H, #0
  126. };
  127. }
  128. private static uint[] _Movi_Mvni_V_32bit_shifted_imm_()
  129. {
  130. return new uint[]
  131. {
  132. 0x0F000400u, // MOVI V0.2S, #0
  133. 0x2F000400u // MVNI V0.2S, #0
  134. };
  135. }
  136. private static uint[] _Movi_Mvni_V_32bit_shifting_ones_()
  137. {
  138. return new uint[]
  139. {
  140. 0x0F00C400u, // MOVI V0.2S, #0, MSL #8
  141. 0x2F00C400u // MVNI V0.2S, #0, MSL #8
  142. };
  143. }
  144. private static uint[] _Movi_V_64bit_scalar_()
  145. {
  146. return new uint[]
  147. {
  148. 0x2F00E400u // MOVI D0, #0
  149. };
  150. }
  151. private static uint[] _Movi_V_64bit_vector_()
  152. {
  153. return new uint[]
  154. {
  155. 0x6F00E400u // MOVI V0.2D, #0
  156. };
  157. }
  158. #endregion
  159. private const int RndCnt = 2;
  160. private const int RndCntImm8 = 2;
  161. private const int RndCntImm64 = 2;
  162. [Test, Pairwise]
  163. public void Bic_Orr_Vi_16bit([ValueSource("_Bic_Orr_Vi_16bit_")] uint opcodes,
  164. [ValueSource("_4H_")] [Random(RndCnt)] ulong z,
  165. [ValueSource("_8BIT_IMM_")] byte imm8,
  166. [Values(0b0u, 0b1u)] uint amount, // <0, 8>
  167. [Values(0b0u, 0b1u)] uint q) // <4H, 8H>
  168. {
  169. uint abc = (imm8 & 0xE0u) >> 5;
  170. uint defgh = (imm8 & 0x1Fu);
  171. opcodes |= (abc << 16) | (defgh << 5);
  172. opcodes |= ((amount & 1) << 13);
  173. opcodes |= ((q & 1) << 30);
  174. V128 v0 = MakeVectorE0E1(z, z);
  175. SingleOpcode(opcodes, v0: v0);
  176. CompareAgainstUnicorn();
  177. }
  178. [Test, Pairwise]
  179. public void Bic_Orr_Vi_32bit([ValueSource("_Bic_Orr_Vi_32bit_")] uint opcodes,
  180. [ValueSource("_2S_")] [Random(RndCnt)] ulong z,
  181. [ValueSource("_8BIT_IMM_")] byte imm8,
  182. [Values(0b00u, 0b01u, 0b10u, 0b11u)] uint amount, // <0, 8, 16, 24>
  183. [Values(0b0u, 0b1u)] uint q) // <2S, 4S>
  184. {
  185. uint abc = (imm8 & 0xE0u) >> 5;
  186. uint defgh = (imm8 & 0x1Fu);
  187. opcodes |= (abc << 16) | (defgh << 5);
  188. opcodes |= ((amount & 3) << 13);
  189. opcodes |= ((q & 1) << 30);
  190. V128 v0 = MakeVectorE0E1(z, z);
  191. SingleOpcode(opcodes, v0: v0);
  192. CompareAgainstUnicorn();
  193. }
  194. [Test, Pairwise] [Explicit]
  195. public void F_Mov_Vi_2S([ValueSource("_F_Mov_Vi_2S_")] uint opcodes,
  196. [Range(0u, 255u, 1u)] uint abcdefgh)
  197. {
  198. uint abc = (abcdefgh & 0xE0u) >> 5;
  199. uint defgh = (abcdefgh & 0x1Fu);
  200. opcodes |= (abc << 16) | (defgh << 5);
  201. ulong z = TestContext.CurrentContext.Random.NextULong();
  202. V128 v0 = MakeVectorE1(z);
  203. SingleOpcode(opcodes, v0: v0);
  204. CompareAgainstUnicorn();
  205. }
  206. [Test, Pairwise] [Explicit]
  207. public void F_Mov_Vi_4S([ValueSource("_F_Mov_Vi_4S_")] uint opcodes,
  208. [Range(0u, 255u, 1u)] uint abcdefgh)
  209. {
  210. uint abc = (abcdefgh & 0xE0u) >> 5;
  211. uint defgh = (abcdefgh & 0x1Fu);
  212. opcodes |= (abc << 16) | (defgh << 5);
  213. SingleOpcode(opcodes);
  214. CompareAgainstUnicorn();
  215. }
  216. [Test, Pairwise] [Explicit]
  217. public void F_Mov_Vi_2D([ValueSource("_F_Mov_Vi_2D_")] uint opcodes,
  218. [Range(0u, 255u, 1u)] uint abcdefgh)
  219. {
  220. uint abc = (abcdefgh & 0xE0u) >> 5;
  221. uint defgh = (abcdefgh & 0x1Fu);
  222. opcodes |= (abc << 16) | (defgh << 5);
  223. SingleOpcode(opcodes);
  224. CompareAgainstUnicorn();
  225. }
  226. [Test, Pairwise]
  227. public void Movi_V_8bit([ValueSource("_Movi_V_8bit_")] uint opcodes,
  228. [ValueSource("_8BIT_IMM_")] byte imm8,
  229. [Values(0b0u, 0b1u)] uint q) // <8B, 16B>
  230. {
  231. uint abc = (imm8 & 0xE0u) >> 5;
  232. uint defgh = (imm8 & 0x1Fu);
  233. opcodes |= (abc << 16) | (defgh << 5);
  234. opcodes |= ((q & 1) << 30);
  235. ulong z = TestContext.CurrentContext.Random.NextULong();
  236. V128 v0 = MakeVectorE1(q == 0u ? z : 0ul);
  237. SingleOpcode(opcodes, v0: v0);
  238. CompareAgainstUnicorn();
  239. }
  240. [Test, Pairwise]
  241. public void Movi_Mvni_V_16bit_shifted_imm([ValueSource("_Movi_Mvni_V_16bit_shifted_imm_")] uint opcodes,
  242. [ValueSource("_8BIT_IMM_")] byte imm8,
  243. [Values(0b0u, 0b1u)] uint amount, // <0, 8>
  244. [Values(0b0u, 0b1u)] uint q) // <4H, 8H>
  245. {
  246. uint abc = (imm8 & 0xE0u) >> 5;
  247. uint defgh = (imm8 & 0x1Fu);
  248. opcodes |= (abc << 16) | (defgh << 5);
  249. opcodes |= ((amount & 1) << 13);
  250. opcodes |= ((q & 1) << 30);
  251. ulong z = TestContext.CurrentContext.Random.NextULong();
  252. V128 v0 = MakeVectorE1(q == 0u ? z : 0ul);
  253. SingleOpcode(opcodes, v0: v0);
  254. CompareAgainstUnicorn();
  255. }
  256. [Test, Pairwise]
  257. public void Movi_Mvni_V_32bit_shifted_imm([ValueSource("_Movi_Mvni_V_32bit_shifted_imm_")] uint opcodes,
  258. [ValueSource("_8BIT_IMM_")] byte imm8,
  259. [Values(0b00u, 0b01u, 0b10u, 0b11u)] uint amount, // <0, 8, 16, 24>
  260. [Values(0b0u, 0b1u)] uint q) // <2S, 4S>
  261. {
  262. uint abc = (imm8 & 0xE0u) >> 5;
  263. uint defgh = (imm8 & 0x1Fu);
  264. opcodes |= (abc << 16) | (defgh << 5);
  265. opcodes |= ((amount & 3) << 13);
  266. opcodes |= ((q & 1) << 30);
  267. ulong z = TestContext.CurrentContext.Random.NextULong();
  268. V128 v0 = MakeVectorE1(q == 0u ? z : 0ul);
  269. SingleOpcode(opcodes, v0: v0);
  270. CompareAgainstUnicorn();
  271. }
  272. [Test, Pairwise]
  273. public void Movi_Mvni_V_32bit_shifting_ones([ValueSource("_Movi_Mvni_V_32bit_shifting_ones_")] uint opcodes,
  274. [ValueSource("_8BIT_IMM_")] byte imm8,
  275. [Values(0b0u, 0b1u)] uint amount, // <8, 16>
  276. [Values(0b0u, 0b1u)] uint q) // <2S, 4S>
  277. {
  278. uint abc = (imm8 & 0xE0u) >> 5;
  279. uint defgh = (imm8 & 0x1Fu);
  280. opcodes |= (abc << 16) | (defgh << 5);
  281. opcodes |= ((amount & 1) << 12);
  282. opcodes |= ((q & 1) << 30);
  283. ulong z = TestContext.CurrentContext.Random.NextULong();
  284. V128 v0 = MakeVectorE1(q == 0u ? z : 0ul);
  285. SingleOpcode(opcodes, v0: v0);
  286. CompareAgainstUnicorn();
  287. }
  288. [Test, Pairwise]
  289. public void Movi_V_64bit_scalar([ValueSource("_Movi_V_64bit_scalar_")] uint opcodes,
  290. [ValueSource("_64BIT_IMM_")] ulong imm)
  291. {
  292. byte imm8 = ShrinkImm64(imm);
  293. uint abc = (imm8 & 0xE0u) >> 5;
  294. uint defgh = (imm8 & 0x1Fu);
  295. opcodes |= (abc << 16) | (defgh << 5);
  296. ulong z = TestContext.CurrentContext.Random.NextULong();
  297. V128 v0 = MakeVectorE1(z);
  298. SingleOpcode(opcodes, v0: v0);
  299. CompareAgainstUnicorn();
  300. }
  301. [Test, Pairwise]
  302. public void Movi_V_64bit_vector([ValueSource("_Movi_V_64bit_vector_")] uint opcodes,
  303. [ValueSource("_64BIT_IMM_")] ulong imm)
  304. {
  305. byte imm8 = ShrinkImm64(imm);
  306. uint abc = (imm8 & 0xE0u) >> 5;
  307. uint defgh = (imm8 & 0x1Fu);
  308. opcodes |= (abc << 16) | (defgh << 5);
  309. SingleOpcode(opcodes);
  310. CompareAgainstUnicorn();
  311. }
  312. #endif
  313. }
  314. }