CpuTestSimdTbl.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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[] _SingleRegisterTable_V_8B_16B_()
  82. {
  83. return new uint[]
  84. {
  85. 0x0E000000u, // TBL V0.8B, { V0.16B }, V0.8B
  86. 0x0E001000u // TBX V0.8B, { V0.16B }, V0.8B
  87. };
  88. }
  89. private static uint[] _TwoRegisterTable_V_8B_16B_()
  90. {
  91. return new uint[]
  92. {
  93. 0x0E002000u, // TBL V0.8B, { V0.16B, V1.16B }, V0.8B
  94. 0x0E003000u // TBX V0.8B, { V0.16B, V1.16B }, V0.8B
  95. };
  96. }
  97. private static uint[] _ThreeRegisterTable_V_8B_16B_()
  98. {
  99. return new uint[]
  100. {
  101. 0x0E004000u, // TBL V0.8B, { V0.16B, V1.16B, V2.16B }, V0.8B
  102. 0x0E005000u // TBX V0.8B, { V0.16B, V1.16B, V2.16B }, V0.8B
  103. };
  104. }
  105. private static uint[] _FourRegisterTable_V_8B_16B_()
  106. {
  107. return new uint[]
  108. {
  109. 0x0E006000u, // TBL V0.8B, { V0.16B, V1.16B, V2.16B, V3.16B }, V0.8B
  110. 0x0E006000u // TBX V0.8B, { V0.16B, V1.16B, V2.16B, V3.16B }, V0.8B
  111. };
  112. }
  113. #endregion
  114. private const int RndCntDest = 2;
  115. private const int RndCntTbls = 2;
  116. private const int RndCntIdxs = 2;
  117. [Test, Pairwise]
  118. public void SingleRegisterTable_V_8B_16B([ValueSource("_SingleRegisterTable_V_8B_16B_")] uint opcodes,
  119. [Values(0u)] uint rd,
  120. [Values(1u)] uint rn,
  121. [Values(2u)] uint rm,
  122. [ValueSource("_8B_")] [Random(RndCntDest)] ulong z,
  123. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table0,
  124. [ValueSource("_GenIdxsForTbl1_")] ulong indexes,
  125. [Values(0b0u, 0b1u)] uint q) // <8B, 16B>
  126. {
  127. opcodes |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
  128. opcodes |= ((q & 1) << 30);
  129. V128 v0 = MakeVectorE0E1(z, z);
  130. V128 v1 = MakeVectorE0E1(table0, table0);
  131. V128 v2 = MakeVectorE0E1(indexes, q == 1u ? indexes : 0ul);
  132. SingleOpcode(opcodes, v0: v0, v1: v1, v2: v2);
  133. CompareAgainstUnicorn();
  134. }
  135. [Test, Pairwise]
  136. public void TwoRegisterTable_V_8B_16B([ValueSource("_TwoRegisterTable_V_8B_16B_")] uint opcodes,
  137. [Values(0u)] uint rd,
  138. [Values(1u)] uint rn,
  139. [Values(3u)] uint rm,
  140. [ValueSource("_8B_")] [Random(RndCntDest)] ulong z,
  141. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table0,
  142. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table1,
  143. [ValueSource("_GenIdxsForTbl2_")] ulong indexes,
  144. [Values(0b0u, 0b1u)] uint q) // <8B, 16B>
  145. {
  146. opcodes |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
  147. opcodes |= ((q & 1) << 30);
  148. V128 v0 = MakeVectorE0E1(z, z);
  149. V128 v1 = MakeVectorE0E1(table0, table0);
  150. V128 v2 = MakeVectorE0E1(table1, table1);
  151. V128 v3 = MakeVectorE0E1(indexes, q == 1u ? indexes : 0ul);
  152. SingleOpcode(opcodes, v0: v0, v1: v1, v2: v2, v3: v3);
  153. CompareAgainstUnicorn();
  154. }
  155. [Test, Pairwise]
  156. public void Mod_TwoRegisterTable_V_8B_16B([ValueSource("_TwoRegisterTable_V_8B_16B_")] uint opcodes,
  157. [Values(30u, 1u)] uint rd,
  158. [Values(31u)] uint rn,
  159. [Values(1u, 30u)] uint rm,
  160. [ValueSource("_8B_")] [Random(RndCntDest)] ulong z,
  161. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table0,
  162. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table1,
  163. [ValueSource("_GenIdxsForTbl2_")] ulong indexes,
  164. [Values(0b0u, 0b1u)] uint q) // <8B, 16B>
  165. {
  166. opcodes |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
  167. opcodes |= ((q & 1) << 30);
  168. V128 v30 = MakeVectorE0E1(z, z);
  169. V128 v31 = MakeVectorE0E1(table0, table0);
  170. V128 v0 = MakeVectorE0E1(table1, table1);
  171. V128 v1 = MakeVectorE0E1(indexes, indexes);
  172. SingleOpcode(opcodes, v0: v0, v1: v1, v30: v30, v31: v31);
  173. CompareAgainstUnicorn();
  174. }
  175. [Test, Pairwise]
  176. public void ThreeRegisterTable_V_8B_16B([ValueSource("_ThreeRegisterTable_V_8B_16B_")] uint opcodes,
  177. [Values(0u)] uint rd,
  178. [Values(1u)] uint rn,
  179. [Values(4u)] uint rm,
  180. [ValueSource("_8B_")] [Random(RndCntDest)] ulong z,
  181. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table0,
  182. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table1,
  183. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table2,
  184. [ValueSource("_GenIdxsForTbl3_")] ulong indexes,
  185. [Values(0b0u, 0b1u)] uint q) // <8B, 16B>
  186. {
  187. opcodes |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
  188. opcodes |= ((q & 1) << 30);
  189. V128 v0 = MakeVectorE0E1(z, z);
  190. V128 v1 = MakeVectorE0E1(table0, table0);
  191. V128 v2 = MakeVectorE0E1(table1, table1);
  192. V128 v3 = MakeVectorE0E1(table2, table2);
  193. V128 v4 = MakeVectorE0E1(indexes, q == 1u ? indexes : 0ul);
  194. SingleOpcode(opcodes, v0: v0, v1: v1, v2: v2, v3: v3, v4: v4);
  195. CompareAgainstUnicorn();
  196. }
  197. [Test, Pairwise]
  198. public void Mod_ThreeRegisterTable_V_8B_16B([ValueSource("_ThreeRegisterTable_V_8B_16B_")] uint opcodes,
  199. [Values(30u, 2u)] uint rd,
  200. [Values(31u)] uint rn,
  201. [Values(2u, 30u)] uint rm,
  202. [ValueSource("_8B_")] [Random(RndCntDest)] ulong z,
  203. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table0,
  204. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table1,
  205. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table2,
  206. [ValueSource("_GenIdxsForTbl3_")] ulong indexes,
  207. [Values(0b0u, 0b1u)] uint q) // <8B, 16B>
  208. {
  209. opcodes |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
  210. opcodes |= ((q & 1) << 30);
  211. V128 v30 = MakeVectorE0E1(z, z);
  212. V128 v31 = MakeVectorE0E1(table0, table0);
  213. V128 v0 = MakeVectorE0E1(table1, table1);
  214. V128 v1 = MakeVectorE0E1(table2, table2);
  215. V128 v2 = MakeVectorE0E1(indexes, indexes);
  216. SingleOpcode(opcodes, v0: v0, v1: v1, v2: v2, v30: v30, v31: v31);
  217. CompareAgainstUnicorn();
  218. }
  219. [Test, Pairwise]
  220. public void FourRegisterTable_V_8B_16B([ValueSource("_FourRegisterTable_V_8B_16B_")] uint opcodes,
  221. [Values(0u)] uint rd,
  222. [Values(1u)] uint rn,
  223. [Values(5u)] uint rm,
  224. [ValueSource("_8B_")] [Random(RndCntDest)] ulong z,
  225. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table0,
  226. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table1,
  227. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table2,
  228. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table3,
  229. [ValueSource("_GenIdxsForTbl4_")] ulong indexes,
  230. [Values(0b0u, 0b1u)] uint q) // <8B, 16B>
  231. {
  232. opcodes |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
  233. opcodes |= ((q & 1) << 30);
  234. V128 v0 = MakeVectorE0E1(z, z);
  235. V128 v1 = MakeVectorE0E1(table0, table0);
  236. V128 v2 = MakeVectorE0E1(table1, table1);
  237. V128 v3 = MakeVectorE0E1(table2, table2);
  238. V128 v4 = MakeVectorE0E1(table3, table3);
  239. V128 v5 = MakeVectorE0E1(indexes, q == 1u ? indexes : 0ul);
  240. SingleOpcode(opcodes, v0: v0, v1: v1, v2: v2, v3: v3, v4: v4, v5: v5);
  241. CompareAgainstUnicorn();
  242. }
  243. [Test, Pairwise]
  244. public void Mod_FourRegisterTable_V_8B_16B([ValueSource("_FourRegisterTable_V_8B_16B_")] uint opcodes,
  245. [Values(30u, 3u)] uint rd,
  246. [Values(31u)] uint rn,
  247. [Values(3u, 30u)] uint rm,
  248. [ValueSource("_8B_")] [Random(RndCntDest)] ulong z,
  249. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table0,
  250. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table1,
  251. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table2,
  252. [ValueSource("_8B_")] [Random(RndCntTbls)] ulong table3,
  253. [ValueSource("_GenIdxsForTbl4_")] ulong indexes,
  254. [Values(0b0u, 0b1u)] uint q) // <8B, 16B>
  255. {
  256. opcodes |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
  257. opcodes |= ((q & 1) << 30);
  258. V128 v30 = MakeVectorE0E1(z, z);
  259. V128 v31 = MakeVectorE0E1(table0, table0);
  260. V128 v0 = MakeVectorE0E1(table1, table1);
  261. V128 v1 = MakeVectorE0E1(table2, table2);
  262. V128 v2 = MakeVectorE0E1(table3, table3);
  263. V128 v3 = MakeVectorE0E1(indexes, indexes);
  264. SingleOpcode(opcodes, v0: v0, v1: v1, v2: v2, v3: v3, v30: v30, v31: v31);
  265. CompareAgainstUnicorn();
  266. }
  267. #endif
  268. }
  269. }