CpuTestSimdReg32.cs 18 KB

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