CpuTestAlu32.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #define Alu32
  2. using NUnit.Framework;
  3. using System;
  4. namespace Ryujinx.Tests.Cpu
  5. {
  6. [Category("Alu32")]
  7. public sealed class CpuTestAlu32 : CpuTest32
  8. {
  9. #if Alu32
  10. #region "ValueSource (Opcodes)"
  11. private static uint[] _Ssat_Usat_()
  12. {
  13. return new uint[]
  14. {
  15. 0xe6a00010u, // SSAT R0, #1, R0, LSL #0
  16. 0xe6a00050u, // SSAT R0, #1, R0, ASR #32
  17. 0xe6e00010u, // USAT R0, #0, R0, LSL #0
  18. 0xe6e00050u // USAT R0, #0, R0, ASR #32
  19. };
  20. }
  21. private static uint[] _Ssat16_Usat16_()
  22. {
  23. return new uint[]
  24. {
  25. 0xe6a00f30u, // SSAT16 R0, #1, R0
  26. 0xe6e00f30u, // USAT16 R0, #0, R0
  27. };
  28. }
  29. private static uint[] _Lsr_Lsl_Asr_Ror_()
  30. {
  31. return new uint[]
  32. {
  33. 0xe1b00030u, // LSRS R0, R0, R0
  34. 0xe1b00010u, // LSLS R0, R0, R0
  35. 0xe1b00050u, // ASRS R0, R0, R0
  36. 0xe1b00070u // RORS R0, R0, R0
  37. };
  38. }
  39. #endregion
  40. private const int RndCnt = 2;
  41. [Test, Pairwise, Description("RBIT <Rd>, <Rn>")]
  42. public void Rbit_32bit([Values(0u, 0xdu)] uint rd,
  43. [Values(1u, 0xdu)] uint rm,
  44. [Values(0x00000000u, 0x7FFFFFFFu,
  45. 0x80000000u, 0xFFFFFFFFu)] [Random(RndCnt)] uint wn)
  46. {
  47. uint opcode = 0xe6ff0f30u; // RBIT R0, R0
  48. opcode |= ((rm & 15) << 0) | ((rd & 15) << 12);
  49. uint w31 = TestContext.CurrentContext.Random.NextUInt();
  50. SingleOpcode(opcode, r1: wn, sp: w31);
  51. CompareAgainstUnicorn();
  52. }
  53. [Test, Pairwise]
  54. public void Lsr_Lsl_Asr_Ror([ValueSource("_Lsr_Lsl_Asr_Ror_")] uint opcode,
  55. [Values(0x00000000u, 0x7FFFFFFFu,
  56. 0x80000000u, 0xFFFFFFFFu)] [Random(RndCnt)] uint shiftValue,
  57. [Range(0, 31)] [Values(32, 256, 768, -1, -23)] int shiftAmount)
  58. {
  59. uint rd = 0;
  60. uint rm = 1;
  61. uint rs = 2;
  62. opcode |= ((rm & 15) << 0) | ((rd & 15) << 12) | ((rs & 15) << 8);
  63. SingleOpcode(opcode, r1: shiftValue, r2: (uint)shiftAmount);
  64. CompareAgainstUnicorn();
  65. }
  66. [Test, Pairwise]
  67. public void Ssat_Usat([ValueSource("_Ssat_Usat_")] uint opcode,
  68. [Values(0u, 0xdu)] uint rd,
  69. [Values(1u, 0xdu)] uint rn,
  70. [Values(0u, 7u, 8u, 0xfu, 0x10u, 0x1fu)] uint sat,
  71. [Values(0u, 7u, 8u, 0xfu, 0x10u, 0x1fu)] uint shift,
  72. [Values(0x00000000u, 0x7FFFFFFFu,
  73. 0x80000000u, 0xFFFFFFFFu)] [Random(RndCnt)] uint wn)
  74. {
  75. opcode |= ((rn & 15) << 0) | ((shift & 31) << 7) | ((rd & 15) << 12) | ((sat & 31) << 16);
  76. uint w31 = TestContext.CurrentContext.Random.NextUInt();
  77. SingleOpcode(opcode, r1: wn, sp: w31);
  78. CompareAgainstUnicorn();
  79. }
  80. [Test, Pairwise]
  81. public void Ssat16_Usat16([ValueSource("_Ssat16_Usat16_")] uint opcode,
  82. [Values(0u, 0xdu)] uint rd,
  83. [Values(1u, 0xdu)] uint rn,
  84. [Values(0u, 7u, 8u, 0xfu)] uint sat,
  85. [Values(0x00000000u, 0x7FFFFFFFu,
  86. 0x80000000u, 0xFFFFFFFFu)] [Random(RndCnt)] uint wn)
  87. {
  88. opcode |= ((rn & 15) << 0) | ((rd & 15) << 12) | ((sat & 15) << 16);
  89. uint w31 = TestContext.CurrentContext.Random.NextUInt();
  90. SingleOpcode(opcode, r1: wn, sp: w31);
  91. CompareAgainstUnicorn();
  92. }
  93. #endif
  94. }
  95. }