CpuTestSimdFcond.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #define SimdFcond
  2. using ARMeilleure.State;
  3. using NUnit.Framework;
  4. using System.Collections.Generic;
  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. private static uint[] _F_Csel_S_S_()
  102. {
  103. return new uint[]
  104. {
  105. 0x1E220C20u // FCSEL S0, S1, S2, EQ
  106. };
  107. }
  108. private static uint[] _F_Csel_S_D_()
  109. {
  110. return new uint[]
  111. {
  112. 0x1E620C20u // FCSEL D0, D1, D2, EQ
  113. };
  114. }
  115. #endregion
  116. private const int RndCnt = 2;
  117. private const int RndCntNzcv = 2;
  118. private static readonly bool NoZeros = false;
  119. private static readonly bool NoInfs = false;
  120. private static readonly bool NoNaNs = false;
  121. [Test, Pairwise] [Explicit]
  122. public void F_Ccmp_Ccmpe_S_S([ValueSource("_F_Ccmp_Ccmpe_S_S_")] uint opcodes,
  123. [ValueSource("_1S_F_")] ulong a,
  124. [ValueSource("_1S_F_")] ulong b,
  125. [Random(0u, 15u, RndCntNzcv)] uint nzcv,
  126. [Values(0b0000u, 0b0001u, 0b0010u, 0b0011u, // <EQ, NE, CS/HS, CC/LO,
  127. 0b0100u, 0b0101u, 0b0110u, 0b0111u, // MI, PL, VS, VC,
  128. 0b1000u, 0b1001u, 0b1010u, 0b1011u, // HI, LS, GE, LT,
  129. 0b1100u, 0b1101u, 0b1110u, 0b1111u)] uint cond) // GT, LE, AL, NV>
  130. {
  131. opcodes |= ((cond & 15) << 12) | ((nzcv & 15) << 0);
  132. V128 v1 = MakeVectorE0(a);
  133. V128 v2 = MakeVectorE0(b);
  134. bool v = TestContext.CurrentContext.Random.NextBool();
  135. bool c = TestContext.CurrentContext.Random.NextBool();
  136. bool z = TestContext.CurrentContext.Random.NextBool();
  137. bool n = TestContext.CurrentContext.Random.NextBool();
  138. SingleOpcode(opcodes, v1: v1, v2: v2, overflow: v, carry: c, zero: z, negative: n);
  139. CompareAgainstUnicorn(fpsrMask: Fpsr.Ioc);
  140. }
  141. [Test, Pairwise] [Explicit]
  142. public void F_Ccmp_Ccmpe_S_D([ValueSource("_F_Ccmp_Ccmpe_S_D_")] uint opcodes,
  143. [ValueSource("_1D_F_")] ulong a,
  144. [ValueSource("_1D_F_")] ulong b,
  145. [Random(0u, 15u, RndCntNzcv)] uint nzcv,
  146. [Values(0b0000u, 0b0001u, 0b0010u, 0b0011u, // <EQ, NE, CS/HS, CC/LO,
  147. 0b0100u, 0b0101u, 0b0110u, 0b0111u, // MI, PL, VS, VC,
  148. 0b1000u, 0b1001u, 0b1010u, 0b1011u, // HI, LS, GE, LT,
  149. 0b1100u, 0b1101u, 0b1110u, 0b1111u)] uint cond) // GT, LE, AL, NV>
  150. {
  151. opcodes |= ((cond & 15) << 12) | ((nzcv & 15) << 0);
  152. V128 v1 = MakeVectorE0(a);
  153. V128 v2 = MakeVectorE0(b);
  154. bool v = TestContext.CurrentContext.Random.NextBool();
  155. bool c = TestContext.CurrentContext.Random.NextBool();
  156. bool z = TestContext.CurrentContext.Random.NextBool();
  157. bool n = TestContext.CurrentContext.Random.NextBool();
  158. SingleOpcode(opcodes, v1: v1, v2: v2, overflow: v, carry: c, zero: z, negative: n);
  159. CompareAgainstUnicorn(fpsrMask: Fpsr.Ioc);
  160. }
  161. [Test, Pairwise] [Explicit]
  162. public void F_Csel_S_S([ValueSource("_F_Csel_S_S_")] uint opcodes,
  163. [ValueSource("_1S_F_")] ulong a,
  164. [ValueSource("_1S_F_")] ulong b,
  165. [Values(0b0000u, 0b0001u, 0b0010u, 0b0011u, // <EQ, NE, CS/HS, CC/LO,
  166. 0b0100u, 0b0101u, 0b0110u, 0b0111u, // MI, PL, VS, VC,
  167. 0b1000u, 0b1001u, 0b1010u, 0b1011u, // HI, LS, GE, LT,
  168. 0b1100u, 0b1101u, 0b1110u, 0b1111u)] uint cond) // GT, LE, AL, NV>
  169. {
  170. opcodes |= ((cond & 15) << 12);
  171. ulong z = TestContext.CurrentContext.Random.NextULong();
  172. V128 v0 = MakeVectorE0E1(z, z);
  173. V128 v1 = MakeVectorE0(a);
  174. V128 v2 = MakeVectorE0(b);
  175. SingleOpcode(opcodes, v0: v0, v1: v1, v2: v2);
  176. CompareAgainstUnicorn();
  177. }
  178. [Test, Pairwise] [Explicit]
  179. public void F_Csel_S_D([ValueSource("_F_Csel_S_D_")] uint opcodes,
  180. [ValueSource("_1D_F_")] ulong a,
  181. [ValueSource("_1D_F_")] ulong b,
  182. [Values(0b0000u, 0b0001u, 0b0010u, 0b0011u, // <EQ, NE, CS/HS, CC/LO,
  183. 0b0100u, 0b0101u, 0b0110u, 0b0111u, // MI, PL, VS, VC,
  184. 0b1000u, 0b1001u, 0b1010u, 0b1011u, // HI, LS, GE, LT,
  185. 0b1100u, 0b1101u, 0b1110u, 0b1111u)] uint cond) // GT, LE, AL, NV>
  186. {
  187. opcodes |= ((cond & 15) << 12);
  188. ulong z = TestContext.CurrentContext.Random.NextULong();
  189. V128 v0 = MakeVectorE1(z);
  190. V128 v1 = MakeVectorE0(a);
  191. V128 v2 = MakeVectorE0(b);
  192. SingleOpcode(opcodes, v0: v0, v1: v1, v2: v2);
  193. CompareAgainstUnicorn();
  194. }
  195. #endif
  196. }
  197. }