CpuTestSimdCvt32.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #define SimdCvt32
  2. using ARMeilleure.State;
  3. using NUnit.Framework;
  4. using System;
  5. using System.Collections.Generic;
  6. namespace Ryujinx.Tests.Cpu
  7. {
  8. [Category("SimdCvt32")]
  9. public sealed class CpuTestSimdCvt32 : CpuTest32
  10. {
  11. #if SimdCvt32
  12. #region "ValueSource (Opcodes)"
  13. #endregion
  14. #region "ValueSource (Types)"
  15. private static uint[] _1S_()
  16. {
  17. return new uint[] { 0x00000000u, 0x7FFFFFFFu,
  18. 0x80000000u, 0xFFFFFFFFu };
  19. }
  20. private static IEnumerable<uint> _1S_F_()
  21. {
  22. yield return 0xFF7FFFFFu; // -Max Normal (float.MinValue)
  23. yield return 0x80800000u; // -Min Normal
  24. yield return 0x807FFFFFu; // -Max Subnormal
  25. yield return 0x80000001u; // -Min Subnormal (-float.Epsilon)
  26. yield return 0x7F7FFFFFu; // +Max Normal (float.MaxValue)
  27. yield return 0x00800000u; // +Min Normal
  28. yield return 0x007FFFFFu; // +Max Subnormal
  29. yield return 0x00000001u; // +Min Subnormal (float.Epsilon)
  30. if (!NoZeros)
  31. {
  32. yield return 0x80000000u; // -Zero
  33. yield return 0x00000000u; // +Zero
  34. }
  35. if (!NoInfs)
  36. {
  37. yield return 0xFF800000u; // -Infinity
  38. yield return 0x7F800000u; // +Infinity
  39. }
  40. if (!NoNaNs)
  41. {
  42. yield return 0xFFC00000u; // -QNaN (all zeros payload) (float.NaN)
  43. yield return 0xFFBFFFFFu; // -SNaN (all ones payload)
  44. yield return 0x7FC00000u; // +QNaN (all zeros payload) (-float.NaN) (DefaultNaN)
  45. yield return 0x7FBFFFFFu; // +SNaN (all ones payload)
  46. }
  47. for (int cnt = 1; cnt <= RndCnt; cnt++)
  48. {
  49. yield return GenNormalS();
  50. yield return GenSubnormalS();
  51. }
  52. }
  53. private static IEnumerable<ulong> _1D_F_()
  54. {
  55. yield return 0xFFEFFFFFFFFFFFFFul; // -Max Normal (double.MinValue)
  56. yield return 0x8010000000000000ul; // -Min Normal
  57. yield return 0x800FFFFFFFFFFFFFul; // -Max Subnormal
  58. yield return 0x8000000000000001ul; // -Min Subnormal (-double.Epsilon)
  59. yield return 0x7FEFFFFFFFFFFFFFul; // +Max Normal (double.MaxValue)
  60. yield return 0x0010000000000000ul; // +Min Normal
  61. yield return 0x000FFFFFFFFFFFFFul; // +Max Subnormal
  62. yield return 0x0000000000000001ul; // +Min Subnormal (double.Epsilon)
  63. if (!NoZeros)
  64. {
  65. yield return 0x8000000000000000ul; // -Zero
  66. yield return 0x0000000000000000ul; // +Zero
  67. }
  68. if (!NoInfs)
  69. {
  70. yield return 0xFFF0000000000000ul; // -Infinity
  71. yield return 0x7FF0000000000000ul; // +Infinity
  72. }
  73. if (!NoNaNs)
  74. {
  75. yield return 0xFFF8000000000000ul; // -QNaN (all zeros payload) (double.NaN)
  76. yield return 0xFFF7FFFFFFFFFFFFul; // -SNaN (all ones payload)
  77. yield return 0x7FF8000000000000ul; // +QNaN (all zeros payload) (-double.NaN) (DefaultNaN)
  78. yield return 0x7FF7FFFFFFFFFFFFul; // +SNaN (all ones payload)
  79. }
  80. for (int cnt = 1; cnt <= RndCnt; cnt++)
  81. {
  82. yield return GenNormalD();
  83. yield return GenSubnormalD();
  84. }
  85. }
  86. #endregion
  87. private const int RndCnt = 2;
  88. private static readonly bool NoZeros = false;
  89. private static readonly bool NoInfs = false;
  90. private static readonly bool NoNaNs = false;
  91. [Explicit]
  92. [Test, Pairwise, Description("VCVT.<dt>.F32 <Sd>, <Sm>")]
  93. public void Vcvt_F32_I32([Values(0u, 1u, 2u, 3u)] uint rd,
  94. [Values(0u, 1u, 2u, 3u)] uint rm,
  95. [ValueSource(nameof(_1S_F_))] uint s0,
  96. [ValueSource(nameof(_1S_F_))] uint s1,
  97. [ValueSource(nameof(_1S_F_))] uint s2,
  98. [ValueSource(nameof(_1S_F_))] uint s3,
  99. [Values] bool unsigned) // <U32, S32>
  100. {
  101. uint opcode = 0xeebc0ac0u; // VCVT.U32.F32 S0, S0
  102. if (!unsigned)
  103. {
  104. opcode |= 1 << 16; // opc2<0>
  105. }
  106. opcode |= ((rd & 0x1e) << 11) | ((rd & 0x1) << 22);
  107. opcode |= ((rm & 0x1e) >> 1) | ((rm & 0x1) << 5);
  108. V128 v0 = MakeVectorE0E1E2E3(s0, s1, s2, s3);
  109. SingleOpcode(opcode, v0: v0);
  110. CompareAgainstUnicorn();
  111. }
  112. [Explicit]
  113. [Test, Pairwise, Description("VCVT.<dt>.F64 <Sd>, <Dm>")]
  114. public void Vcvt_F64_I32([Values(0u, 1u, 2u, 3u)] uint rd,
  115. [Values(0u, 1u)] uint rm,
  116. [ValueSource(nameof(_1D_F_))] ulong d0,
  117. [ValueSource(nameof(_1D_F_))] ulong d1,
  118. [Values] bool unsigned) // <U32, S32>
  119. {
  120. uint opcode = 0xeebc0bc0u; // VCVT.U32.F64 S0, D0
  121. if (!unsigned)
  122. {
  123. opcode |= 1 << 16; // opc2<0>
  124. }
  125. opcode |= ((rd & 0x1e) << 11) | ((rd & 0x1) << 22);
  126. opcode |= ((rm & 0xf) << 0) | ((rm & 0x10) << 1);
  127. V128 v0 = MakeVectorE0E1(d0, d1);
  128. SingleOpcode(opcode, v0: v0);
  129. CompareAgainstUnicorn();
  130. }
  131. [Explicit]
  132. [Test, Pairwise, Description("VCVT.F32.<dt> <Sd>, <Sm>")]
  133. public void Vcvt_I32_F32([Values(0u, 1u, 2u, 3u)] uint rd,
  134. [Values(0u, 1u, 2u, 3u)] uint rm,
  135. [ValueSource(nameof(_1S_))] [Random(RndCnt)] uint s0,
  136. [ValueSource(nameof(_1S_))] [Random(RndCnt)] uint s1,
  137. [ValueSource(nameof(_1S_))] [Random(RndCnt)] uint s2,
  138. [ValueSource(nameof(_1S_))] [Random(RndCnt)] uint s3,
  139. [Values] bool unsigned, // <U32, S32>
  140. [Values(RMode.Rn)] RMode rMode)
  141. {
  142. uint opcode = 0xeeb80a40u; // VCVT.F32.U32 S0, S0
  143. if (!unsigned)
  144. {
  145. opcode |= 1 << 7; // op
  146. }
  147. opcode |= ((rm & 0x1e) >> 1) | ((rm & 0x1) << 5);
  148. opcode |= ((rd & 0x1e) << 11) | ((rd & 0x1) << 22);
  149. V128 v0 = MakeVectorE0E1E2E3(s0, s1, s2, s3);
  150. int fpscr = (int)rMode << (int)Fpcr.RMode;
  151. SingleOpcode(opcode, v0: v0, fpscr: fpscr);
  152. CompareAgainstUnicorn();
  153. }
  154. [Explicit]
  155. [Test, Pairwise, Description("VCVT.F64.<dt> <Dd>, <Sm>")]
  156. public void Vcvt_I32_F64([Values(0u, 1u)] uint rd,
  157. [Values(0u, 1u, 2u, 3u)] uint rm,
  158. [ValueSource(nameof(_1S_))] [Random(RndCnt)] uint s0,
  159. [ValueSource(nameof(_1S_))] [Random(RndCnt)] uint s1,
  160. [ValueSource(nameof(_1S_))] [Random(RndCnt)] uint s2,
  161. [ValueSource(nameof(_1S_))] [Random(RndCnt)] uint s3,
  162. [Values] bool unsigned, // <U32, S32>
  163. [Values(RMode.Rn)] RMode rMode)
  164. {
  165. uint opcode = 0xeeb80b40u; // VCVT.F64.U32 D0, S0
  166. if (!unsigned)
  167. {
  168. opcode |= 1 << 7; // op
  169. }
  170. opcode |= ((rm & 0x1e) >> 1) | ((rm & 0x1) << 5);
  171. opcode |= ((rd & 0xf) << 12) | ((rd & 0x10) << 18);
  172. V128 v0 = MakeVectorE0E1E2E3(s0, s1, s2, s3);
  173. int fpscr = (int)rMode << (int)Fpcr.RMode;
  174. SingleOpcode(opcode, v0: v0, fpscr: fpscr);
  175. CompareAgainstUnicorn();
  176. }
  177. [Test, Pairwise, Description("VRINTX.F<size> <Sd>, <Sm>")]
  178. public void Vrintx_S([Values(0u, 1u)] uint rd,
  179. [Values(0u, 1u)] uint rm,
  180. [Values(2u, 3u)] uint size,
  181. [ValueSource(nameof(_1D_F_))] ulong s0,
  182. [ValueSource(nameof(_1D_F_))] ulong s1,
  183. [ValueSource(nameof(_1D_F_))] ulong s2,
  184. [Values(RMode.Rn, RMode.Rm, RMode.Rp)] RMode rMode)
  185. {
  186. uint opcode = 0xEB70A40;
  187. V128 v0, v1, v2;
  188. if (size == 2)
  189. {
  190. opcode |= ((rm & 0x1e) >> 1) | ((rm & 0x1) << 5);
  191. opcode |= ((rd & 0x1e) >> 11) | ((rm & 0x1) << 22);
  192. v0 = MakeVectorE0E1((uint)BitConverter.SingleToInt32Bits(s0), (uint)BitConverter.SingleToInt32Bits(s0));
  193. v1 = MakeVectorE0E1((uint)BitConverter.SingleToInt32Bits(s1), (uint)BitConverter.SingleToInt32Bits(s0));
  194. v2 = MakeVectorE0E1((uint)BitConverter.SingleToInt32Bits(s2), (uint)BitConverter.SingleToInt32Bits(s1));
  195. }
  196. else
  197. {
  198. opcode |= ((rm & 0xf) << 0) | ((rd & 0x10) << 1);
  199. opcode |= ((rd & 0xf) << 12) | ((rd & 0x10) << 18);
  200. v0 = MakeVectorE0E1((uint)BitConverter.DoubleToInt64Bits(s0), (uint)BitConverter.DoubleToInt64Bits(s0));
  201. v1 = MakeVectorE0E1((uint)BitConverter.DoubleToInt64Bits(s1), (uint)BitConverter.DoubleToInt64Bits(s0));
  202. v2 = MakeVectorE0E1((uint)BitConverter.DoubleToInt64Bits(s2), (uint)BitConverter.DoubleToInt64Bits(s1));
  203. }
  204. opcode |= ((size & 3) << 8);
  205. int fpscr = (int)rMode << (int)Fpcr.RMode;
  206. SingleOpcode(opcode, v0: v0, v1: v1, v2: v2, fpscr: fpscr);
  207. CompareAgainstUnicorn();
  208. }
  209. #endif
  210. }
  211. }