CpuTestMisc32.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #define Misc32
  2. using ARMeilleure.State;
  3. using NUnit.Framework;
  4. using System.Collections.Generic;
  5. namespace Ryujinx.Tests.Cpu
  6. {
  7. [Category("Misc32")]
  8. public sealed class CpuTestMisc32 : CpuTest32
  9. {
  10. #if Misc32
  11. #region "ValueSource (Types)"
  12. private static IEnumerable<ulong> _1S_F_()
  13. {
  14. yield return 0x00000000FF7FFFFFul; // -Max Normal (float.MinValue)
  15. yield return 0x0000000080800000ul; // -Min Normal
  16. yield return 0x00000000807FFFFFul; // -Max Subnormal
  17. yield return 0x0000000080000001ul; // -Min Subnormal (-float.Epsilon)
  18. yield return 0x000000007F7FFFFFul; // +Max Normal (float.MaxValue)
  19. yield return 0x0000000000800000ul; // +Min Normal
  20. yield return 0x00000000007FFFFFul; // +Max Subnormal
  21. yield return 0x0000000000000001ul; // +Min Subnormal (float.Epsilon)
  22. if (!NoZeros)
  23. {
  24. yield return 0x0000000080000000ul; // -Zero
  25. yield return 0x0000000000000000ul; // +Zero
  26. }
  27. if (!NoInfs)
  28. {
  29. yield return 0x00000000FF800000ul; // -Infinity
  30. yield return 0x000000007F800000ul; // +Infinity
  31. }
  32. if (!NoNaNs)
  33. {
  34. yield return 0x00000000FFC00000ul; // -QNaN (all zeros payload) (float.NaN)
  35. yield return 0x00000000FFBFFFFFul; // -SNaN (all ones payload)
  36. yield return 0x000000007FC00000ul; // +QNaN (all zeros payload) (-float.NaN) (DefaultNaN)
  37. yield return 0x000000007FBFFFFFul; // +SNaN (all ones payload)
  38. }
  39. for (int cnt = 1; cnt <= RndCnt; cnt++)
  40. {
  41. ulong grbg = TestContext.CurrentContext.Random.NextUInt();
  42. ulong rnd1 = GenNormalS();
  43. ulong rnd2 = GenSubnormalS();
  44. yield return (grbg << 32) | rnd1;
  45. yield return (grbg << 32) | rnd2;
  46. }
  47. }
  48. #endregion
  49. private const int RndCnt = 2;
  50. private static readonly bool NoZeros = false;
  51. private static readonly bool NoInfs = false;
  52. private static readonly bool NoNaNs = false;
  53. [Test, Pairwise]
  54. public void Vmsr_Vcmp_Vmrs([ValueSource("_1S_F_")] ulong a,
  55. [ValueSource("_1S_F_")] ulong b,
  56. [Values] bool mode1,
  57. [Values] bool mode2,
  58. [Values] bool mode3)
  59. {
  60. V128 v4 = MakeVectorE0(a);
  61. V128 v5 = MakeVectorE0(b);
  62. uint r0 = mode1
  63. ? TestContext.CurrentContext.Random.NextUInt(0xf) << 28
  64. : TestContext.CurrentContext.Random.NextUInt();
  65. bool v = mode3 ? TestContext.CurrentContext.Random.NextBool() : false;
  66. bool c = mode3 ? TestContext.CurrentContext.Random.NextBool() : false;
  67. bool z = mode3 ? TestContext.CurrentContext.Random.NextBool() : false;
  68. bool n = mode3 ? TestContext.CurrentContext.Random.NextBool() : false;
  69. int fpscr = mode1
  70. ? (int)TestContext.CurrentContext.Random.NextUInt()
  71. : (int)TestContext.CurrentContext.Random.NextUInt(0xf) << 28;
  72. SetContext(r0: r0, v4: v4, v5: v5, overflow: v, carry: c, zero: z, negative: n, fpscr: fpscr);
  73. if (mode1)
  74. {
  75. Opcode(0xEEE10A10); // VMSR FPSCR, R0
  76. }
  77. Opcode(0xEEB48A4A); // VCMP.F32 S16, S20
  78. if (mode2)
  79. {
  80. Opcode(0xEEF10A10); // VMRS R0, FPSCR
  81. Opcode(0xE200020F); // AND R0, #0xF0000000 // R0 &= "Fpsr.Nzcv".
  82. }
  83. if (mode3)
  84. {
  85. Opcode(0xEEF1FA10); // VMRS APSR_NZCV, FPSCR
  86. }
  87. Opcode(0xE12FFF1E); // BX LR
  88. ExecuteOpcodes();
  89. CompareAgainstUnicorn(fpsrMask: Fpsr.Nzcv);
  90. }
  91. #endif
  92. }
  93. }