CpuTestSimdTbl.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. #define SimdTbl
  2. using ARMeilleure.State;
  3. using NUnit.Framework;
  4. using System.Collections.Generic;
  5. namespace Ryujinx.Tests.Cpu
  6. {
  7. [Category("SimdTbl")]
  8. public sealed class CpuTestSimdTbl : CpuTest
  9. {
  10. #if SimdTbl
  11. #region "Helper methods"
  12. private static ulong GenIdxsForTbls(int regs)
  13. {
  14. const byte idxInRngMin = (byte)0;
  15. byte idxInRngMax = (byte)((16 * regs) - 1);
  16. byte idxOutRngMin = (byte) (16 * regs);
  17. const byte idxOutRngMax = (byte)255;
  18. ulong idxs = 0ul;
  19. for (int cnt = 1; cnt <= 8; cnt++)
  20. {
  21. ulong idxInRng = (ulong)TestContext.CurrentContext.Random.NextByte(idxInRngMin, idxInRngMax);
  22. ulong idxOutRng = (ulong)TestContext.CurrentContext.Random.NextByte(idxOutRngMin, idxOutRngMax);
  23. ulong idx = TestContext.CurrentContext.Random.NextBool() ? idxInRng : idxOutRng;
  24. idxs = (idxs << 8) | idx;
  25. }
  26. return idxs;
  27. }
  28. #endregion
  29. #region "ValueSource (Types)"
  30. private static ulong[] _8B_()
  31. {
  32. return new ulong[] { 0x0000000000000000ul, 0x7F7F7F7F7F7F7F7Ful,
  33. 0x8080808080808080ul, 0xFFFFFFFFFFFFFFFFul };
  34. }
  35. private static IEnumerable<ulong> _GenIdxsForTbl1_()
  36. {
  37. yield return 0x0000000000000000ul;
  38. yield return 0x7F7F7F7F7F7F7F7Ful;
  39. yield return 0x8080808080808080ul;
  40. yield return 0xFFFFFFFFFFFFFFFFul;
  41. for (int cnt = 1; cnt <= RndCntIdxs; cnt++)
  42. {
  43. yield return GenIdxsForTbls(regs: 1);
  44. }
  45. }
  46. private static IEnumerable<ulong> _GenIdxsForTbl2_()
  47. {
  48. yield return 0x0000000000000000ul;
  49. yield return 0x7F7F7F7F7F7F7F7Ful;
  50. yield return 0x8080808080808080ul;
  51. yield return 0xFFFFFFFFFFFFFFFFul;
  52. for (int cnt = 1; cnt <= RndCntIdxs; cnt++)
  53. {
  54. yield return GenIdxsForTbls(regs: 2);
  55. }
  56. }
  57. private static IEnumerable<ulong> _GenIdxsForTbl3_()
  58. {
  59. yield return 0x0000000000000000ul;
  60. yield return 0x7F7F7F7F7F7F7F7Ful;
  61. yield return 0x8080808080808080ul;
  62. yield return 0xFFFFFFFFFFFFFFFFul;
  63. for (int cnt = 1; cnt <= RndCntIdxs; cnt++)
  64. {
  65. yield return GenIdxsForTbls(regs: 3);
  66. }
  67. }
  68. private static IEnumerable<ulong> _GenIdxsForTbl4_()
  69. {
  70. yield return 0x0000000000000000ul;
  71. yield return 0x7F7F7F7F7F7F7F7Ful;
  72. yield return 0x8080808080808080ul;
  73. yield return 0xFFFFFFFFFFFFFFFFul;
  74. for (int cnt = 1; cnt <= RndCntIdxs; cnt++)
  75. {
  76. yield return GenIdxsForTbls(regs: 4);
  77. }
  78. }
  79. #endregion
  80. #region "ValueSource (Opcodes)"
  81. private static uint[] _SingleRegTbl_V_8B_16B_()
  82. {
  83. return new uint[]
  84. {
  85. 0x0E000000u, // TBL V0.8B, { V0.16B }, V0.8B
  86. };
  87. }
  88. private static uint[] _TwoRegTbl_V_8B_16B_()
  89. {
  90. return new uint[]
  91. {
  92. 0x0E002000u, // TBL V0.8B, { V0.16B, V1.16B }, V0.8B
  93. };
  94. }
  95. private static uint[] _ThreeRegTbl_V_8B_16B_()
  96. {
  97. return new uint[]
  98. {
  99. 0x0E004000u, // TBL V0.8B, { V0.16B, V1.16B, V2.16B }, V0.8B
  100. };
  101. }
  102. private static uint[] _FourRegTbl_V_8B_16B_()
  103. {
  104. return new uint[]
  105. {
  106. 0x0E006000u, // TBL V0.8B, { V0.16B, V1.16B, V2.16B, V3.16B }, V0.8B
  107. };
  108. }
  109. #endregion
  110. private const int RndCntTbls = 2;
  111. private const int RndCntIdxs = 2;
  112. [Test, Pairwise, Description("TBL <Vd>.<Ta>, { <Vn>.16B }, <Vm>.<Ta>")]
  113. public void SingleRegTbl_V_8B_16B([ValueSource("_SingleRegTbl_V_8B_16B_")] uint opcodes,
  114. [Values(0u)] uint rd,
  115. [Values(1u)] uint rn,
  116. [Values(2u)] uint rm,
  117. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table0,
  118. [ValueSource("_GenIdxsForTbl1_")] ulong indexes,
  119. [Values(0b0u, 0b1u)] uint q) // <8B, 16B>
  120. {
  121. opcodes |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
  122. opcodes |= ((q & 1) << 30);
  123. ulong z = TestContext.CurrentContext.Random.NextULong();
  124. V128 v0 = MakeVectorE0E1(z, z);
  125. V128 v1 = MakeVectorE0E1(table0, table0);
  126. V128 v2 = MakeVectorE0E1(indexes, q == 1u ? indexes : 0ul);
  127. SingleOpcode(opcodes, v0: v0, v1: v1, v2: v2);
  128. CompareAgainstUnicorn();
  129. }
  130. [Test, Pairwise, Description("TBL <Vd>.<Ta>, { <Vn>.16B, <Vn+1>.16B }, <Vm>.<Ta>")]
  131. public void TwoRegTbl_V_8B_16B([ValueSource("_TwoRegTbl_V_8B_16B_")] uint opcodes,
  132. [Values(0u)] uint rd,
  133. [Values(1u)] uint rn,
  134. [Values(3u)] uint rm,
  135. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table0,
  136. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table1,
  137. [ValueSource("_GenIdxsForTbl2_")] ulong indexes,
  138. [Values(0b0u, 0b1u)] uint q) // <8B, 16B>
  139. {
  140. opcodes |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
  141. opcodes |= ((q & 1) << 30);
  142. ulong z = TestContext.CurrentContext.Random.NextULong();
  143. V128 v0 = MakeVectorE0E1(z, z);
  144. V128 v1 = MakeVectorE0E1(table0, table0);
  145. V128 v2 = MakeVectorE0E1(table1, table1);
  146. V128 v3 = MakeVectorE0E1(indexes, q == 1u ? indexes : 0ul);
  147. SingleOpcode(opcodes, v0: v0, v1: v1, v2: v2, v3: v3);
  148. CompareAgainstUnicorn();
  149. }
  150. [Test, Pairwise, Description("TBL <Vd>.<Ta>, { <Vn>.16B, <Vn+1>.16B }, <Vm>.<Ta>")]
  151. public void Mod_TwoRegTbl_V_8B_16B([ValueSource("_TwoRegTbl_V_8B_16B_")] uint opcodes,
  152. [Values(30u, 1u)] uint rd,
  153. [Values(31u)] uint rn,
  154. [Values(1u, 30u)] uint rm,
  155. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table0,
  156. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table1,
  157. [ValueSource("_GenIdxsForTbl2_")] ulong indexes,
  158. [Values(0b0u, 0b1u)] uint q) // <8B, 16B>
  159. {
  160. opcodes |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
  161. opcodes |= ((q & 1) << 30);
  162. ulong z = TestContext.CurrentContext.Random.NextULong();
  163. V128 v30 = MakeVectorE0E1(z, z);
  164. V128 v31 = MakeVectorE0E1(table0, table0);
  165. V128 v0 = MakeVectorE0E1(table1, table1);
  166. V128 v1 = MakeVectorE0E1(indexes, indexes);
  167. SingleOpcode(opcodes, v0: v0, v1: v1, v30: v30, v31: v31);
  168. CompareAgainstUnicorn();
  169. }
  170. [Test, Pairwise, Description("TBL <Vd>.<Ta>, { <Vn>.16B, <Vn+1>.16B, <Vn+2>.16B }, <Vm>.<Ta>")]
  171. public void ThreeRegTbl_V_8B_16B([ValueSource("_ThreeRegTbl_V_8B_16B_")] uint opcodes,
  172. [Values(0u)] uint rd,
  173. [Values(1u)] uint rn,
  174. [Values(4u)] uint rm,
  175. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table0,
  176. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table1,
  177. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table2,
  178. [ValueSource("_GenIdxsForTbl3_")] ulong indexes,
  179. [Values(0b0u, 0b1u)] uint q) // <8B, 16B>
  180. {
  181. opcodes |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
  182. opcodes |= ((q & 1) << 30);
  183. ulong z = TestContext.CurrentContext.Random.NextULong();
  184. V128 v0 = MakeVectorE0E1(z, z);
  185. V128 v1 = MakeVectorE0E1(table0, table0);
  186. V128 v2 = MakeVectorE0E1(table1, table1);
  187. V128 v3 = MakeVectorE0E1(table2, table2);
  188. V128 v4 = MakeVectorE0E1(indexes, q == 1u ? indexes : 0ul);
  189. SingleOpcode(opcodes, v0: v0, v1: v1, v2: v2, v3: v3, v4: v4);
  190. CompareAgainstUnicorn();
  191. }
  192. [Test, Pairwise, Description("TBL <Vd>.<Ta>, { <Vn>.16B, <Vn+1>.16B, <Vn+2>.16B }, <Vm>.<Ta>")]
  193. public void Mod_ThreeRegTbl_V_8B_16B([ValueSource("_ThreeRegTbl_V_8B_16B_")] uint opcodes,
  194. [Values(30u, 2u)] uint rd,
  195. [Values(31u)] uint rn,
  196. [Values(2u, 30u)] uint rm,
  197. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table0,
  198. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table1,
  199. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table2,
  200. [ValueSource("_GenIdxsForTbl3_")] ulong indexes,
  201. [Values(0b0u, 0b1u)] uint q) // <8B, 16B>
  202. {
  203. opcodes |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
  204. opcodes |= ((q & 1) << 30);
  205. ulong z = TestContext.CurrentContext.Random.NextULong();
  206. V128 v30 = MakeVectorE0E1(z, z);
  207. V128 v31 = MakeVectorE0E1(table0, table0);
  208. V128 v0 = MakeVectorE0E1(table1, table1);
  209. V128 v1 = MakeVectorE0E1(table2, table2);
  210. V128 v2 = MakeVectorE0E1(indexes, indexes);
  211. SingleOpcode(opcodes, v0: v0, v1: v1, v2: v2, v30: v30, v31: v31);
  212. CompareAgainstUnicorn();
  213. }
  214. [Test, Pairwise, Description("TBL <Vd>.<Ta>, { <Vn>.16B, <Vn+1>.16B, <Vn+2>.16B, <Vn+3>.16B }, <Vm>.<Ta>")]
  215. public void FourRegTbl_V_8B_16B([ValueSource("_FourRegTbl_V_8B_16B_")] uint opcodes,
  216. [Values(0u)] uint rd,
  217. [Values(1u)] uint rn,
  218. [Values(5u)] uint rm,
  219. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table0,
  220. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table1,
  221. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table2,
  222. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table3,
  223. [ValueSource("_GenIdxsForTbl4_")] ulong indexes,
  224. [Values(0b0u, 0b1u)] uint q) // <8B, 16B>
  225. {
  226. opcodes |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
  227. opcodes |= ((q & 1) << 30);
  228. ulong z = TestContext.CurrentContext.Random.NextULong();
  229. V128 v0 = MakeVectorE0E1(z, z);
  230. V128 v1 = MakeVectorE0E1(table0, table0);
  231. V128 v2 = MakeVectorE0E1(table1, table1);
  232. V128 v3 = MakeVectorE0E1(table2, table2);
  233. V128 v4 = MakeVectorE0E1(table3, table3);
  234. V128 v5 = MakeVectorE0E1(indexes, q == 1u ? indexes : 0ul);
  235. SingleOpcode(opcodes, v0: v0, v1: v1, v2: v2, v3: v3, v4: v4, v5: v5);
  236. CompareAgainstUnicorn();
  237. }
  238. [Test, Pairwise, Description("TBL <Vd>.<Ta>, { <Vn>.16B, <Vn+1>.16B, <Vn+2>.16B, <Vn+3>.16B }, <Vm>.<Ta>")]
  239. public void Mod_FourRegTbl_V_8B_16B([ValueSource("_FourRegTbl_V_8B_16B_")] uint opcodes,
  240. [Values(30u, 3u)] uint rd,
  241. [Values(31u)] uint rn,
  242. [Values(3u, 30u)] uint rm,
  243. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table0,
  244. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table1,
  245. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table2,
  246. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table3,
  247. [ValueSource("_GenIdxsForTbl4_")] ulong indexes,
  248. [Values(0b0u, 0b1u)] uint q) // <8B, 16B>
  249. {
  250. opcodes |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
  251. opcodes |= ((q & 1) << 30);
  252. ulong z = TestContext.CurrentContext.Random.NextULong();
  253. V128 v30 = MakeVectorE0E1(z, z);
  254. V128 v31 = MakeVectorE0E1(table0, table0);
  255. V128 v0 = MakeVectorE0E1(table1, table1);
  256. V128 v1 = MakeVectorE0E1(table2, table2);
  257. V128 v2 = MakeVectorE0E1(table3, table3);
  258. V128 v3 = MakeVectorE0E1(indexes, indexes);
  259. SingleOpcode(opcodes, v0: v0, v1: v1, v2: v2, v3: v3, v30: v30, v31: v31);
  260. CompareAgainstUnicorn();
  261. }
  262. #endif
  263. }
  264. }