CpuTestSimdReg32.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. #define SimdReg32
  2. using ARMeilleure.State;
  3. using NUnit.Framework;
  4. using System;
  5. using System.Collections.Generic;
  6. namespace Ryujinx.Tests.Cpu
  7. {
  8. [Category("SimdReg32")]
  9. public sealed class CpuTestSimdReg32 : CpuTest32
  10. {
  11. #if SimdReg32
  12. #region "ValueSource (Types)"
  13. private static ulong[] _1B1H1S1D_()
  14. {
  15. return new ulong[] { 0x0000000000000000ul, 0x000000000000007Ful,
  16. 0x0000000000000080ul, 0x00000000000000FFul,
  17. 0x0000000000007FFFul, 0x0000000000008000ul,
  18. 0x000000000000FFFFul, 0x000000007FFFFFFFul,
  19. 0x0000000080000000ul, 0x00000000FFFFFFFFul,
  20. 0x7FFFFFFFFFFFFFFFul, 0x8000000000000000ul,
  21. 0xFFFFFFFFFFFFFFFFul };
  22. }
  23. private static ulong[] _1D_()
  24. {
  25. return new ulong[] { 0x0000000000000000ul, 0x7FFFFFFFFFFFFFFFul,
  26. 0x8000000000000000ul, 0xFFFFFFFFFFFFFFFFul };
  27. }
  28. private static ulong[] _1H1S_()
  29. {
  30. return new ulong[] { 0x0000000000000000ul, 0x0000000000007FFFul,
  31. 0x0000000000008000ul, 0x000000000000FFFFul,
  32. 0x000000007FFFFFFFul, 0x0000000080000000ul,
  33. 0x00000000FFFFFFFFul };
  34. }
  35. private static ulong[] _4H2S_()
  36. {
  37. return new ulong[] { 0x0000000000000000ul, 0x7FFF7FFF7FFF7FFFul,
  38. 0x8000800080008000ul, 0x7FFFFFFF7FFFFFFFul,
  39. 0x8000000080000000ul, 0xFFFFFFFFFFFFFFFFul };
  40. }
  41. private static ulong[] _4H2S1D_()
  42. {
  43. return new ulong[] { 0x0000000000000000ul, 0x7FFF7FFF7FFF7FFFul,
  44. 0x8000800080008000ul, 0x7FFFFFFF7FFFFFFFul,
  45. 0x8000000080000000ul, 0x7FFFFFFFFFFFFFFFul,
  46. 0x8000000000000000ul, 0xFFFFFFFFFFFFFFFFul };
  47. }
  48. private static ulong[] _8B_()
  49. {
  50. return new ulong[] { 0x0000000000000000ul, 0x7F7F7F7F7F7F7F7Ful,
  51. 0x8080808080808080ul, 0xFFFFFFFFFFFFFFFFul };
  52. }
  53. private static ulong[] _8B4H2S_()
  54. {
  55. return new ulong[] { 0x0000000000000000ul, 0x7F7F7F7F7F7F7F7Ful,
  56. 0x8080808080808080ul, 0x7FFF7FFF7FFF7FFFul,
  57. 0x8000800080008000ul, 0x7FFFFFFF7FFFFFFFul,
  58. 0x8000000080000000ul, 0xFFFFFFFFFFFFFFFFul };
  59. }
  60. private static ulong[] _8B4H2S1D_()
  61. {
  62. return new ulong[] { 0x0000000000000000ul, 0x7F7F7F7F7F7F7F7Ful,
  63. 0x8080808080808080ul, 0x7FFF7FFF7FFF7FFFul,
  64. 0x8000800080008000ul, 0x7FFFFFFF7FFFFFFFul,
  65. 0x8000000080000000ul, 0x7FFFFFFFFFFFFFFFul,
  66. 0x8000000000000000ul, 0xFFFFFFFFFFFFFFFFul };
  67. }
  68. private static IEnumerable<ulong> _1S_F_()
  69. {
  70. yield return 0x00000000FF7FFFFFul; // -Max Normal (float.MinValue)
  71. yield return 0x0000000080800000ul; // -Min Normal
  72. yield return 0x00000000807FFFFFul; // -Max Subnormal
  73. yield return 0x0000000080000001ul; // -Min Subnormal (-float.Epsilon)
  74. yield return 0x000000007F7FFFFFul; // +Max Normal (float.MaxValue)
  75. yield return 0x0000000000800000ul; // +Min Normal
  76. yield return 0x00000000007FFFFFul; // +Max Subnormal
  77. yield return 0x0000000000000001ul; // +Min Subnormal (float.Epsilon)
  78. if (!NoZeros)
  79. {
  80. yield return 0x0000000080000000ul; // -Zero
  81. yield return 0x0000000000000000ul; // +Zero
  82. }
  83. if (!NoInfs)
  84. {
  85. yield return 0x00000000FF800000ul; // -Infinity
  86. yield return 0x000000007F800000ul; // +Infinity
  87. }
  88. if (!NoNaNs)
  89. {
  90. yield return 0x00000000FFC00000ul; // -QNaN (all zeros payload) (float.NaN)
  91. yield return 0x00000000FFBFFFFFul; // -SNaN (all ones payload)
  92. yield return 0x000000007FC00000ul; // +QNaN (all zeros payload) (-float.NaN) (DefaultNaN)
  93. yield return 0x000000007FBFFFFFul; // +SNaN (all ones payload)
  94. }
  95. for (int cnt = 1; cnt <= RndCnt; cnt++)
  96. {
  97. ulong grbg = TestContext.CurrentContext.Random.NextUInt();
  98. ulong rnd1 = GenNormalS();
  99. ulong rnd2 = GenSubnormalS();
  100. yield return (grbg << 32) | rnd1;
  101. yield return (grbg << 32) | rnd2;
  102. }
  103. }
  104. private static IEnumerable<ulong> _2S_F_()
  105. {
  106. yield return 0xFF7FFFFFFF7FFFFFul; // -Max Normal (float.MinValue)
  107. yield return 0x8080000080800000ul; // -Min Normal
  108. yield return 0x807FFFFF807FFFFFul; // -Max Subnormal
  109. yield return 0x8000000180000001ul; // -Min Subnormal (-float.Epsilon)
  110. yield return 0x7F7FFFFF7F7FFFFFul; // +Max Normal (float.MaxValue)
  111. yield return 0x0080000000800000ul; // +Min Normal
  112. yield return 0x007FFFFF007FFFFFul; // +Max Subnormal
  113. yield return 0x0000000100000001ul; // +Min Subnormal (float.Epsilon)
  114. if (!NoZeros)
  115. {
  116. yield return 0x8000000080000000ul; // -Zero
  117. yield return 0x0000000000000000ul; // +Zero
  118. }
  119. if (!NoInfs)
  120. {
  121. yield return 0xFF800000FF800000ul; // -Infinity
  122. yield return 0x7F8000007F800000ul; // +Infinity
  123. }
  124. if (!NoNaNs)
  125. {
  126. yield return 0xFFC00000FFC00000ul; // -QNaN (all zeros payload) (float.NaN)
  127. yield return 0xFFBFFFFFFFBFFFFFul; // -SNaN (all ones payload)
  128. yield return 0x7FC000007FC00000ul; // +QNaN (all zeros payload) (-float.NaN) (DefaultNaN)
  129. yield return 0x7FBFFFFF7FBFFFFFul; // +SNaN (all ones payload)
  130. }
  131. for (int cnt = 1; cnt <= RndCnt; cnt++)
  132. {
  133. ulong rnd1 = GenNormalS();
  134. ulong rnd2 = GenSubnormalS();
  135. yield return (rnd1 << 32) | rnd1;
  136. yield return (rnd2 << 32) | rnd2;
  137. }
  138. }
  139. private static IEnumerable<ulong> _1D_F_()
  140. {
  141. yield return 0xFFEFFFFFFFFFFFFFul; // -Max Normal (double.MinValue)
  142. yield return 0x8010000000000000ul; // -Min Normal
  143. yield return 0x800FFFFFFFFFFFFFul; // -Max Subnormal
  144. yield return 0x8000000000000001ul; // -Min Subnormal (-double.Epsilon)
  145. yield return 0x7FEFFFFFFFFFFFFFul; // +Max Normal (double.MaxValue)
  146. yield return 0x0010000000000000ul; // +Min Normal
  147. yield return 0x000FFFFFFFFFFFFFul; // +Max Subnormal
  148. yield return 0x0000000000000001ul; // +Min Subnormal (double.Epsilon)
  149. if (!NoZeros)
  150. {
  151. yield return 0x8000000000000000ul; // -Zero
  152. yield return 0x0000000000000000ul; // +Zero
  153. }
  154. if (!NoInfs)
  155. {
  156. yield return 0xFFF0000000000000ul; // -Infinity
  157. yield return 0x7FF0000000000000ul; // +Infinity
  158. }
  159. if (!NoNaNs)
  160. {
  161. yield return 0xFFF8000000000000ul; // -QNaN (all zeros payload) (double.NaN)
  162. yield return 0xFFF7FFFFFFFFFFFFul; // -SNaN (all ones payload)
  163. yield return 0x7FF8000000000000ul; // +QNaN (all zeros payload) (-double.NaN) (DefaultNaN)
  164. yield return 0x7FF7FFFFFFFFFFFFul; // +SNaN (all ones payload)
  165. }
  166. for (int cnt = 1; cnt <= RndCnt; cnt++)
  167. {
  168. ulong rnd1 = GenNormalD();
  169. ulong rnd2 = GenSubnormalD();
  170. yield return rnd1;
  171. yield return rnd2;
  172. }
  173. }
  174. #endregion
  175. private const int RndCnt = 2;
  176. private static readonly bool NoZeros = false;
  177. private static readonly bool NoInfs = false;
  178. private static readonly bool NoNaNs = false;
  179. [Explicit]
  180. [Test, Pairwise, Description("VADD.f32 V0, V0, V0")]
  181. public void Vadd_f32([Values(0u)] uint rd,
  182. [Values(0u, 1u)] uint rn,
  183. [Values(0u, 2u)] uint rm,
  184. [ValueSource("_2S_F_")] ulong z0,
  185. [ValueSource("_2S_F_")] ulong z1,
  186. [ValueSource("_2S_F_")] ulong a0,
  187. [ValueSource("_2S_F_")] ulong a1,
  188. [ValueSource("_2S_F_")] ulong b0,
  189. [ValueSource("_2S_F_")] ulong b1,
  190. [Values] bool q)
  191. {
  192. uint opcode = 0xf2000d00u; // VADD.F32 D0, D0, D0
  193. if (q)
  194. {
  195. opcode |= 1 << 6;
  196. rm <<= 1;
  197. rn <<= 1;
  198. rd <<= 1;
  199. }
  200. opcode |= ((rm & 0xf) << 0) | ((rm & 0x10) << 1);
  201. opcode |= ((rd & 0xf) << 12) | ((rd & 0x10) << 18);
  202. opcode |= ((rn & 0xf) << 16) | ((rn & 0x10) << 3);
  203. V128 v0 = MakeVectorE0E1(z0, z1);
  204. V128 v1 = MakeVectorE0E1(a0, a1);
  205. V128 v2 = MakeVectorE0E1(b0, b1);
  206. SingleOpcode(opcode, v0: v0, v1: v1, v2: v2);
  207. CompareAgainstUnicorn();
  208. }
  209. [Test, Pairwise, Description("VCMP.f<size> Vd, Vm")]
  210. public void Vcmp([Values(2u, 3u)] uint size,
  211. [ValueSource("_1S_F_")] ulong a,
  212. [ValueSource("_1S_F_")] ulong b,
  213. [Values] bool e)
  214. {
  215. uint opcode = 0xeeb40840u;
  216. uint rm = 1;
  217. uint rd = 2;
  218. if (size == 3)
  219. {
  220. opcode |= ((rm & 0xf) << 0) | ((rm & 0x10) << 1);
  221. opcode |= ((rd & 0xf) << 12) | ((rd & 0x10) << 18);
  222. }
  223. else
  224. {
  225. opcode |= ((rm & 0x1e) >> 1) | ((rm & 0x1) << 5);
  226. opcode |= ((rd & 0x1e) << 11) | ((rd & 0x1) << 22);
  227. }
  228. opcode |= ((size & 3) << 8);
  229. if (e)
  230. {
  231. opcode |= 1 << 7;
  232. }
  233. V128 v1 = MakeVectorE0(a);
  234. V128 v2 = MakeVectorE0(b);
  235. bool v = TestContext.CurrentContext.Random.NextBool();
  236. bool c = TestContext.CurrentContext.Random.NextBool();
  237. bool z = TestContext.CurrentContext.Random.NextBool();
  238. bool n = TestContext.CurrentContext.Random.NextBool();
  239. int fpscr = (int)(TestContext.CurrentContext.Random.NextUInt(0xf) << 28);
  240. SingleOpcode(opcode, v1: v1, v2: v2, overflow: v, carry: c, zero: z, negative: n, fpscr: fpscr, copyFpFlags: true);
  241. CompareAgainstUnicorn();
  242. }
  243. [Test, Pairwise, Description("VMLSL.<type><size> <Vd>, <Vn>, <Vm>")]
  244. public void Vmlsl_I([Values(0u)] uint rd,
  245. [Values(1u, 0u)] uint rn,
  246. [Values(2u, 0u)] uint rm,
  247. [Values(0u, 1u, 2u)] uint size,
  248. [Random(RndCnt)] ulong z,
  249. [Random(RndCnt)] ulong a,
  250. [Random(RndCnt)] ulong b,
  251. [Values] bool u)
  252. {
  253. uint opcode = 0xf2800a00u; // VMLSL.S8 Q0, D0, D0
  254. opcode |= ((rm & 0xf) << 0) | ((rm & 0x10) << 1);
  255. opcode |= ((rd & 0xf) << 12) | ((rd & 0x10) << 18);
  256. opcode |= ((rn & 0xf) << 16) | ((rn & 0x10) << 3);
  257. opcode |= size << 20;
  258. if (u)
  259. {
  260. opcode |= 1 << 24;
  261. }
  262. V128 v0 = MakeVectorE0E1(z, z);
  263. V128 v1 = MakeVectorE0E1(a, z);
  264. V128 v2 = MakeVectorE0E1(b, z);
  265. SingleOpcode(opcode, v0: v0, v1: v1, v2: v2);
  266. CompareAgainstUnicorn();
  267. }
  268. [Test, Pairwise, Description("VMULL.<size> <Vd>, <Vn>, <Vm>")]
  269. public void Vmull_I([Values(0u)] uint rd,
  270. [Values(1u, 0u)] uint rn,
  271. [Values(2u, 0u)] uint rm,
  272. [Values(0u, 1u, 2u)] uint size,
  273. [Random(RndCnt)] ulong z,
  274. [Random(RndCnt)] ulong a,
  275. [Random(RndCnt)] ulong b,
  276. [Values] bool op,
  277. [Values] bool u)
  278. {
  279. uint opcode = 0xf2800c00u; // VMULL.S8 Q0, D0, D0
  280. opcode |= ((rm & 0xf) << 0) | ((rm & 0x10) << 1);
  281. opcode |= ((rd & 0xf) << 12) | ((rd & 0x10) << 18);
  282. opcode |= ((rn & 0xf) << 16) | ((rn & 0x10) << 3);
  283. if (op)
  284. {
  285. opcode |= 1 << 9;
  286. size = 0;
  287. u = false;
  288. }
  289. opcode |= size << 20;
  290. if (u)
  291. {
  292. opcode |= 1 << 24;
  293. }
  294. V128 v0 = MakeVectorE0E1(z, z);
  295. V128 v1 = MakeVectorE0E1(a, z);
  296. V128 v2 = MakeVectorE0E1(b, z);
  297. SingleOpcode(opcode, v0: v0, v1: v1, v2: v2);
  298. CompareAgainstUnicorn();
  299. }
  300. [Test, Pairwise, Description("VSHL.<size> {<Vd>}, <Vm>, <Vn>")]
  301. public void Vshl([Values(0u)] uint rd,
  302. [Values(1u, 0u)] uint rn,
  303. [Values(2u, 0u)] uint rm,
  304. [Values(0u, 1u, 2u, 3u)] uint size,
  305. [Random(RndCnt)] ulong z,
  306. [Random(RndCnt)] ulong a,
  307. [Random(RndCnt)] ulong b,
  308. [Values] bool q,
  309. [Values] bool u)
  310. {
  311. uint opcode = 0xf2000400u; // VSHL.S8 D0, D0, D0
  312. if (q)
  313. {
  314. opcode |= 1 << 6;
  315. rm <<= 1;
  316. rn <<= 1;
  317. rd <<= 1;
  318. }
  319. if (u)
  320. {
  321. opcode |= 1 << 24;
  322. }
  323. opcode |= ((rm & 0xf) << 0) | ((rm & 0x10) << 1);
  324. opcode |= ((rd & 0xf) << 12) | ((rd & 0x10) << 18);
  325. opcode |= ((rn & 0xf) << 16) | ((rn & 0x10) << 3);
  326. opcode |= size << 20;
  327. V128 v0 = MakeVectorE0E1(z, z);
  328. V128 v1 = MakeVectorE0E1(a, z);
  329. V128 v2 = MakeVectorE0E1(b, z);
  330. SingleOpcode(opcode, v0: v0, v1: v1, v2: v2);
  331. CompareAgainstUnicorn();
  332. }
  333. [Explicit]
  334. [Test, Pairwise, Description("VPADD.f32 V0, V0, V0")]
  335. public void Vpadd_f32([Values(0u)] uint rd,
  336. [Range(0u, 7u)] uint rn,
  337. [Range(0u, 7u)] uint rm)
  338. {
  339. // not currently a slow path test - just a sanity check for pairwise
  340. uint opcode = 0xf3000d00u; // VPADD.F32 D0, D0, D0
  341. opcode |= ((rm & 0xf) << 0) | ((rm & 0x10) << 1);
  342. opcode |= ((rd & 0xf) << 12) | ((rd & 0x10) << 18);
  343. opcode |= ((rn & 0xf) << 16) | ((rn & 0x10) << 3);
  344. var rnd = TestContext.CurrentContext.Random;
  345. V128 v0 = new V128(rnd.NextFloat(int.MinValue, int.MaxValue), rnd.NextFloat(int.MinValue, int.MaxValue), rnd.NextFloat(int.MinValue, int.MaxValue), rnd.NextFloat(int.MinValue, int.MaxValue));
  346. V128 v1 = new V128(rnd.NextFloat(int.MinValue, int.MaxValue), rnd.NextFloat(int.MinValue, int.MaxValue), rnd.NextFloat(int.MinValue, int.MaxValue), rnd.NextFloat(int.MinValue, int.MaxValue));
  347. V128 v2 = new V128(rnd.NextFloat(int.MinValue, int.MaxValue), rnd.NextFloat(int.MinValue, int.MaxValue), rnd.NextFloat(int.MinValue, int.MaxValue), rnd.NextFloat(int.MinValue, int.MaxValue));
  348. SingleOpcode(opcode, v0: v0, v1: v1, v2: v2);
  349. CompareAgainstUnicorn();
  350. }
  351. #endif
  352. }
  353. }