CpuTestSystem.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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[]
  34. {
  35. 0xD53B4200u, // MRS X0, NZCV
  36. 0xD51B4200u // MSR NZCV, X0
  37. };
  38. }
  39. #endregion
  40. [Test, Pairwise]
  41. public void MrsMsr_Nzcv([ValueSource("_MrsMsr_Nzcv_")] uint opcodes,
  42. [Values(0u, 1u, 31u)] uint rt,
  43. [ValueSource("_GenNzcv_")] ulong xt)
  44. {
  45. opcodes |= (rt & 31) << 0;
  46. bool v = TestContext.CurrentContext.Random.NextBool();
  47. bool c = TestContext.CurrentContext.Random.NextBool();
  48. bool z = TestContext.CurrentContext.Random.NextBool();
  49. bool n = TestContext.CurrentContext.Random.NextBool();
  50. ulong x31 = TestContext.CurrentContext.Random.NextULong();
  51. SingleOpcode(opcodes, x0: xt, x1: xt, x31: x31, overflow: v, carry: c, zero: z, negative: n);
  52. CompareAgainstUnicorn();
  53. }
  54. #endif
  55. }
  56. }