CpuTestSimdFcond.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #define SimdFcond
  2. using NUnit.Framework;
  3. using System.Collections.Generic;
  4. using System.Runtime.Intrinsics;
  5. namespace Ryujinx.Tests.Cpu
  6. {
  7. [Category("SimdFcond")]
  8. public sealed class CpuTestSimdFcond : CpuTest
  9. {
  10. #if SimdFcond
  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. private static IEnumerable<ulong> _1D_F_()
  49. {
  50. yield return 0xFFEFFFFFFFFFFFFFul; // -Max Normal (double.MinValue)
  51. yield return 0x8010000000000000ul; // -Min Normal
  52. yield return 0x800FFFFFFFFFFFFFul; // -Max Subnormal
  53. yield return 0x8000000000000001ul; // -Min Subnormal (-double.Epsilon)
  54. yield return 0x7FEFFFFFFFFFFFFFul; // +Max Normal (double.MaxValue)
  55. yield return 0x0010000000000000ul; // +Min Normal
  56. yield return 0x000FFFFFFFFFFFFFul; // +Max Subnormal
  57. yield return 0x0000000000000001ul; // +Min Subnormal (double.Epsilon)
  58. if (!NoZeros)
  59. {
  60. yield return 0x8000000000000000ul; // -Zero
  61. yield return 0x0000000000000000ul; // +Zero
  62. }
  63. if (!NoInfs)
  64. {
  65. yield return 0xFFF0000000000000ul; // -Infinity
  66. yield return 0x7FF0000000000000ul; // +Infinity
  67. }
  68. if (!NoNaNs)
  69. {
  70. yield return 0xFFF8000000000000ul; // -QNaN (all zeros payload) (double.NaN)
  71. yield return 0xFFF7FFFFFFFFFFFFul; // -SNaN (all ones payload)
  72. yield return 0x7FF8000000000000ul; // +QNaN (all zeros payload) (-double.NaN) (DefaultNaN)
  73. yield return 0x7FF7FFFFFFFFFFFFul; // +SNaN (all ones payload)
  74. }
  75. for (int cnt = 1; cnt <= RndCnt; cnt++)
  76. {
  77. ulong rnd1 = GenNormalD();
  78. ulong rnd2 = GenSubnormalD();
  79. yield return rnd1;
  80. yield return rnd2;
  81. }
  82. }
  83. #endregion
  84. #region "ValueSource (Opcodes)"
  85. private static uint[] _F_Ccmp_Ccmpe_S_S_()
  86. {
  87. return new uint[]
  88. {
  89. 0x1E220420u, // FCCMP S1, S2, #0, EQ
  90. 0x1E220430u // FCCMPE S1, S2, #0, EQ
  91. };
  92. }
  93. private static uint[] _F_Ccmp_Ccmpe_S_D_()
  94. {
  95. return new uint[]
  96. {
  97. 0x1E620420u, // FCCMP D1, D2, #0, EQ
  98. 0x1E620430u // FCCMPE D1, D2, #0, EQ
  99. };
  100. }
  101. #endregion
  102. private const int RndCnt = 2;
  103. private const int RndCntNzcv = 2;
  104. private static readonly bool NoZeros = false;
  105. private static readonly bool NoInfs = false;
  106. private static readonly bool NoNaNs = false;
  107. [Test, Pairwise] [Explicit]
  108. public void F_Ccmp_Ccmpe_S_S([ValueSource("_F_Ccmp_Ccmpe_S_S_")] uint opcodes,
  109. [ValueSource("_1S_F_")] ulong a,
  110. [ValueSource("_1S_F_")] ulong b,
  111. [Random(0u, 15u, RndCntNzcv)] uint nzcv,
  112. [Values(0b0000u, 0b0001u, 0b0010u, 0b0011u, // <EQ, NE, CS/HS, CC/LO,
  113. 0b0100u, 0b0101u, 0b0110u, 0b0111u, // MI, PL, VS, VC,
  114. 0b1000u, 0b1001u, 0b1010u, 0b1011u, // HI, LS, GE, LT,
  115. 0b1100u, 0b1101u, 0b1110u, 0b1111u)] uint cond) // GT, LE, AL, NV>
  116. {
  117. opcodes |= ((cond & 15) << 12) | ((nzcv & 15) << 0);
  118. Vector128<float> v1 = MakeVectorE0(a);
  119. Vector128<float> v2 = MakeVectorE0(b);
  120. bool v = TestContext.CurrentContext.Random.NextBool();
  121. bool c = TestContext.CurrentContext.Random.NextBool();
  122. bool z = TestContext.CurrentContext.Random.NextBool();
  123. bool n = TestContext.CurrentContext.Random.NextBool();
  124. SingleOpcode(opcodes, v1: v1, v2: v2, overflow: v, carry: c, zero: z, negative: n);
  125. CompareAgainstUnicorn(fpsrMask: Fpsr.Ioc);
  126. }
  127. [Test, Pairwise] [Explicit]
  128. public void F_Ccmp_Ccmpe_S_D([ValueSource("_F_Ccmp_Ccmpe_S_D_")] uint opcodes,
  129. [ValueSource("_1D_F_")] ulong a,
  130. [ValueSource("_1D_F_")] ulong b,
  131. [Random(0u, 15u, RndCntNzcv)] uint nzcv,
  132. [Values(0b0000u, 0b0001u, 0b0010u, 0b0011u, // <EQ, NE, CS/HS, CC/LO,
  133. 0b0100u, 0b0101u, 0b0110u, 0b0111u, // MI, PL, VS, VC,
  134. 0b1000u, 0b1001u, 0b1010u, 0b1011u, // HI, LS, GE, LT,
  135. 0b1100u, 0b1101u, 0b1110u, 0b1111u)] uint cond) // GT, LE, AL, NV>
  136. {
  137. opcodes |= ((cond & 15) << 12) | ((nzcv & 15) << 0);
  138. Vector128<float> v1 = MakeVectorE0(a);
  139. Vector128<float> v2 = MakeVectorE0(b);
  140. bool v = TestContext.CurrentContext.Random.NextBool();
  141. bool c = TestContext.CurrentContext.Random.NextBool();
  142. bool z = TestContext.CurrentContext.Random.NextBool();
  143. bool n = TestContext.CurrentContext.Random.NextBool();
  144. SingleOpcode(opcodes, v1: v1, v2: v2, overflow: v, carry: c, zero: z, negative: n);
  145. CompareAgainstUnicorn(fpsrMask: Fpsr.Ioc);
  146. }
  147. #endif
  148. }
  149. }