CpuTestSystem.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #define System
  2. using ARMeilleure.State;
  3. using NUnit.Framework;
  4. using System.Collections.Generic;
  5. namespace Ryujinx.Tests.Cpu
  6. {
  7. [Category("System")]
  8. public sealed class CpuTestSystem : CpuTest
  9. {
  10. #if System
  11. #region "ValueSource (Types)"
  12. private static IEnumerable<ulong> _GenNzcv_()
  13. {
  14. yield return 0x0000000000000000ul;
  15. yield return 0x7FFFFFFFFFFFFFFFul;
  16. yield return 0x8000000000000000ul;
  17. yield return 0xFFFFFFFFFFFFFFFFul;
  18. bool v = TestContext.CurrentContext.Random.NextBool();
  19. bool c = TestContext.CurrentContext.Random.NextBool();
  20. bool z = TestContext.CurrentContext.Random.NextBool();
  21. bool n = TestContext.CurrentContext.Random.NextBool();
  22. ulong rnd = 0UL;
  23. rnd |= (v ? 1UL : 0UL) << (int)PState.VFlag;
  24. rnd |= (c ? 1UL : 0UL) << (int)PState.CFlag;
  25. rnd |= (z ? 1UL : 0UL) << (int)PState.ZFlag;
  26. rnd |= (n ? 1UL : 0UL) << (int)PState.NFlag;
  27. yield return rnd;
  28. }
  29. #endregion
  30. #region "ValueSource (Opcodes)"
  31. private static uint[] _MrsMsr_Nzcv_()
  32. {
  33. return new uint[]
  34. {
  35. 0xD53B4200u, // MRS X0, NZCV
  36. 0xD51B4200u // MSR NZCV, X0
  37. };
  38. }
  39. #endregion
  40. private const int RndCnt = 2;
  41. [Test, Pairwise]
  42. public void MrsMsr_Nzcv([ValueSource("_MrsMsr_Nzcv_")] uint opcodes,
  43. [Values(0u, 1u, 31u)] uint rt,
  44. [ValueSource("_GenNzcv_")] [Random(RndCnt)] ulong xt)
  45. {
  46. opcodes |= (rt & 31) << 0;
  47. bool v = TestContext.CurrentContext.Random.NextBool();
  48. bool c = TestContext.CurrentContext.Random.NextBool();
  49. bool z = TestContext.CurrentContext.Random.NextBool();
  50. bool n = TestContext.CurrentContext.Random.NextBool();
  51. ulong x31 = TestContext.CurrentContext.Random.NextULong();
  52. SingleOpcode(opcodes, x0: xt, x1: xt, x31: x31, overflow: v, carry: c, zero: z, negative: n);
  53. CompareAgainstUnicorn();
  54. }
  55. #endif
  56. }
  57. }