CpuTestSimdRegElemF.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. #define SimdRegElemF
  2. using ChocolArm64.State;
  3. using NUnit.Framework;
  4. using System.Collections.Generic;
  5. using System.Runtime.Intrinsics;
  6. namespace Ryujinx.Tests.Cpu
  7. {
  8. [Category("SimdRegElemF")] // Tested: second half of 2018.
  9. public sealed class CpuTestSimdRegElemF : CpuTest
  10. {
  11. #if SimdRegElemF
  12. #region "ValueSource (Types)"
  13. private static IEnumerable<ulong> _1S_F_()
  14. {
  15. yield return 0x00000000FF7FFFFFul; // -Max Normal (float.MinValue)
  16. yield return 0x0000000080800000ul; // -Min Normal
  17. yield return 0x00000000807FFFFFul; // -Max Subnormal
  18. yield return 0x0000000080000001ul; // -Min Subnormal (-float.Epsilon)
  19. yield return 0x000000007F7FFFFFul; // +Max Normal (float.MaxValue)
  20. yield return 0x0000000000800000ul; // +Min Normal
  21. yield return 0x00000000007FFFFFul; // +Max Subnormal
  22. yield return 0x0000000000000001ul; // +Min Subnormal (float.Epsilon)
  23. if (!NoZeros)
  24. {
  25. yield return 0x0000000080000000ul; // -Zero
  26. yield return 0x0000000000000000ul; // +Zero
  27. }
  28. if (!NoInfs)
  29. {
  30. yield return 0x00000000FF800000ul; // -Infinity
  31. yield return 0x000000007F800000ul; // +Infinity
  32. }
  33. if (!NoNaNs)
  34. {
  35. yield return 0x00000000FFC00000ul; // -QNaN (all zeros payload) (float.NaN)
  36. yield return 0x00000000FFBFFFFFul; // -SNaN (all ones payload)
  37. yield return 0x000000007FC00000ul; // +QNaN (all zeros payload) (-float.NaN) (DefaultNaN)
  38. yield return 0x000000007FBFFFFFul; // +SNaN (all ones payload)
  39. }
  40. for (int Cnt = 1; Cnt <= RndCnt; Cnt++)
  41. {
  42. ulong Grbg = TestContext.CurrentContext.Random.NextUInt();
  43. ulong Rnd1 = GenNormal_S();
  44. ulong Rnd2 = GenSubnormal_S();
  45. yield return (Grbg << 32) | Rnd1;
  46. yield return (Grbg << 32) | Rnd2;
  47. }
  48. }
  49. private static IEnumerable<ulong> _2S_F_()
  50. {
  51. yield return 0xFF7FFFFFFF7FFFFFul; // -Max Normal (float.MinValue)
  52. yield return 0x8080000080800000ul; // -Min Normal
  53. yield return 0x807FFFFF807FFFFFul; // -Max Subnormal
  54. yield return 0x8000000180000001ul; // -Min Subnormal (-float.Epsilon)
  55. yield return 0x7F7FFFFF7F7FFFFFul; // +Max Normal (float.MaxValue)
  56. yield return 0x0080000000800000ul; // +Min Normal
  57. yield return 0x007FFFFF007FFFFFul; // +Max Subnormal
  58. yield return 0x0000000100000001ul; // +Min Subnormal (float.Epsilon)
  59. if (!NoZeros)
  60. {
  61. yield return 0x8000000080000000ul; // -Zero
  62. yield return 0x0000000000000000ul; // +Zero
  63. }
  64. if (!NoInfs)
  65. {
  66. yield return 0xFF800000FF800000ul; // -Infinity
  67. yield return 0x7F8000007F800000ul; // +Infinity
  68. }
  69. if (!NoNaNs)
  70. {
  71. yield return 0xFFC00000FFC00000ul; // -QNaN (all zeros payload) (float.NaN)
  72. yield return 0xFFBFFFFFFFBFFFFFul; // -SNaN (all ones payload)
  73. yield return 0x7FC000007FC00000ul; // +QNaN (all zeros payload) (-float.NaN) (DefaultNaN)
  74. yield return 0x7FBFFFFF7FBFFFFFul; // +SNaN (all ones payload)
  75. }
  76. for (int Cnt = 1; Cnt <= RndCnt; Cnt++)
  77. {
  78. ulong Rnd1 = GenNormal_S();
  79. ulong Rnd2 = GenSubnormal_S();
  80. yield return (Rnd1 << 32) | Rnd1;
  81. yield return (Rnd2 << 32) | Rnd2;
  82. }
  83. }
  84. private static IEnumerable<ulong> _1D_F_()
  85. {
  86. yield return 0xFFEFFFFFFFFFFFFFul; // -Max Normal (double.MinValue)
  87. yield return 0x8010000000000000ul; // -Min Normal
  88. yield return 0x800FFFFFFFFFFFFFul; // -Max Subnormal
  89. yield return 0x8000000000000001ul; // -Min Subnormal (-double.Epsilon)
  90. yield return 0x7FEFFFFFFFFFFFFFul; // +Max Normal (double.MaxValue)
  91. yield return 0x0010000000000000ul; // +Min Normal
  92. yield return 0x000FFFFFFFFFFFFFul; // +Max Subnormal
  93. yield return 0x0000000000000001ul; // +Min Subnormal (double.Epsilon)
  94. if (!NoZeros)
  95. {
  96. yield return 0x8000000000000000ul; // -Zero
  97. yield return 0x0000000000000000ul; // +Zero
  98. }
  99. if (!NoInfs)
  100. {
  101. yield return 0xFFF0000000000000ul; // -Infinity
  102. yield return 0x7FF0000000000000ul; // +Infinity
  103. }
  104. if (!NoNaNs)
  105. {
  106. yield return 0xFFF8000000000000ul; // -QNaN (all zeros payload) (double.NaN)
  107. yield return 0xFFF7FFFFFFFFFFFFul; // -SNaN (all ones payload)
  108. yield return 0x7FF8000000000000ul; // +QNaN (all zeros payload) (-double.NaN) (DefaultNaN)
  109. yield return 0x7FF7FFFFFFFFFFFFul; // +SNaN (all ones payload)
  110. }
  111. for (int Cnt = 1; Cnt <= RndCnt; Cnt++)
  112. {
  113. ulong Rnd1 = GenNormal_D();
  114. ulong Rnd2 = GenSubnormal_D();
  115. yield return Rnd1;
  116. yield return Rnd2;
  117. }
  118. }
  119. #endregion
  120. #region "ValueSource (Opcodes)"
  121. private static uint[] _F_Mla_Mls_Se_S_()
  122. {
  123. return new uint[]
  124. {
  125. 0x5F821020u, // FMLA S0, S1, V2.S[0]
  126. 0x5F825020u // FMLS S0, S1, V2.S[0]
  127. };
  128. }
  129. private static uint[] _F_Mla_Mls_Se_D_()
  130. {
  131. return new uint[]
  132. {
  133. 0x5FC21020u, // FMLA D0, D1, V2.D[0]
  134. 0x5FC25020u // FMLS D0, D1, V2.D[0]
  135. };
  136. }
  137. private static uint[] _F_Mla_Mls_Ve_2S_4S_()
  138. {
  139. return new uint[]
  140. {
  141. 0x0F801000u, // FMLA V0.2S, V0.2S, V0.S[0]
  142. 0x0F805000u // FMLS V0.2S, V0.2S, V0.S[0]
  143. };
  144. }
  145. private static uint[] _F_Mla_Mls_Ve_2D_()
  146. {
  147. return new uint[]
  148. {
  149. 0x4FC01000u, // FMLA V0.2D, V0.2D, V0.D[0]
  150. 0x4FC05000u // FMLS V0.2D, V0.2D, V0.D[0]
  151. };
  152. }
  153. private static uint[] _F_Mul_Mulx_Se_S_()
  154. {
  155. return new uint[]
  156. {
  157. 0x5F829020u, // FMUL S0, S1, V2.S[0]
  158. 0x7F829020u // FMULX S0, S1, V2.S[0]
  159. };
  160. }
  161. private static uint[] _F_Mul_Mulx_Se_D_()
  162. {
  163. return new uint[]
  164. {
  165. 0x5FC29020u, // FMUL D0, D1, V2.D[0]
  166. 0x7FC29020u // FMULX D0, D1, V2.D[0]
  167. };
  168. }
  169. private static uint[] _F_Mul_Mulx_Ve_2S_4S_()
  170. {
  171. return new uint[]
  172. {
  173. 0x0F809000u, // FMUL V0.2S, V0.2S, V0.S[0]
  174. 0x2F809000u // FMULX V0.2S, V0.2S, V0.S[0]
  175. };
  176. }
  177. private static uint[] _F_Mul_Mulx_Ve_2D_()
  178. {
  179. return new uint[]
  180. {
  181. 0x4FC09000u, // FMUL V0.2D, V0.2D, V0.D[0]
  182. 0x6FC09000u // FMULX V0.2D, V0.2D, V0.D[0]
  183. };
  184. }
  185. #endregion
  186. private const int RndCnt = 2;
  187. private static readonly bool NoZeros = false;
  188. private static readonly bool NoInfs = false;
  189. private static readonly bool NoNaNs = false;
  190. [Test, Pairwise] [Explicit] // Fused.
  191. public void F_Mla_Mls_Se_S([ValueSource("_F_Mla_Mls_Se_S_")] uint Opcodes,
  192. [ValueSource("_1S_F_")] ulong Z,
  193. [ValueSource("_1S_F_")] ulong A,
  194. [ValueSource("_2S_F_")] ulong B,
  195. [Values(0u, 1u, 2u, 3u)] uint Index)
  196. {
  197. uint H = (Index >> 1) & 1;
  198. uint L = Index & 1;
  199. Opcodes |= (L << 21) | (H << 11);
  200. Vector128<float> V0 = MakeVectorE0E1(Z, Z);
  201. Vector128<float> V1 = MakeVectorE0(A);
  202. Vector128<float> V2 = MakeVectorE0E1(B, B * H);
  203. int Fpcr = (int)TestContext.CurrentContext.Random.NextUInt() & (1 << (int)FPCR.DN);
  204. AThreadState ThreadState = SingleOpcode(Opcodes, V0: V0, V1: V1, V2: V2, Fpcr: Fpcr);
  205. CompareAgainstUnicorn(FPSR.IOC, FpSkips.IfUnderflow, FpTolerances.UpToOneUlps_S);
  206. }
  207. [Test, Pairwise] [Explicit] // Fused.
  208. public void F_Mla_Mls_Se_D([ValueSource("_F_Mla_Mls_Se_D_")] uint Opcodes,
  209. [ValueSource("_1D_F_")] ulong Z,
  210. [ValueSource("_1D_F_")] ulong A,
  211. [ValueSource("_1D_F_")] ulong B,
  212. [Values(0u, 1u)] uint Index)
  213. {
  214. uint H = Index & 1;
  215. Opcodes |= H << 11;
  216. Vector128<float> V0 = MakeVectorE0E1(Z, Z);
  217. Vector128<float> V1 = MakeVectorE0(A);
  218. Vector128<float> V2 = MakeVectorE0E1(B, B * H);
  219. int Fpcr = (int)TestContext.CurrentContext.Random.NextUInt() & (1 << (int)FPCR.DN);
  220. AThreadState ThreadState = SingleOpcode(Opcodes, V0: V0, V1: V1, V2: V2, Fpcr: Fpcr);
  221. CompareAgainstUnicorn(FPSR.IOC, FpSkips.IfUnderflow, FpTolerances.UpToOneUlps_D);
  222. }
  223. [Test, Pairwise] [Explicit] // Fused.
  224. public void F_Mla_Mls_Ve_2S_4S([ValueSource("_F_Mla_Mls_Ve_2S_4S_")] uint Opcodes,
  225. [Values(0u)] uint Rd,
  226. [Values(1u, 0u)] uint Rn,
  227. [Values(2u, 0u)] uint Rm,
  228. [ValueSource("_2S_F_")] ulong Z,
  229. [ValueSource("_2S_F_")] ulong A,
  230. [ValueSource("_2S_F_")] ulong B,
  231. [Values(0u, 1u, 2u, 3u)] uint Index,
  232. [Values(0b0u, 0b1u)] uint Q) // <2S, 4S>
  233. {
  234. uint H = (Index >> 1) & 1;
  235. uint L = Index & 1;
  236. Opcodes |= ((Rm & 31) << 16) | ((Rn & 31) << 5) | ((Rd & 31) << 0);
  237. Opcodes |= (L << 21) | (H << 11);
  238. Opcodes |= ((Q & 1) << 30);
  239. Vector128<float> V0 = MakeVectorE0E1(Z, Z);
  240. Vector128<float> V1 = MakeVectorE0E1(A, A * Q);
  241. Vector128<float> V2 = MakeVectorE0E1(B, B * H);
  242. int Fpcr = (int)TestContext.CurrentContext.Random.NextUInt() & (1 << (int)FPCR.DN);
  243. AThreadState ThreadState = SingleOpcode(Opcodes, V0: V0, V1: V1, V2: V2, Fpcr: Fpcr);
  244. CompareAgainstUnicorn(FPSR.IOC, FpSkips.IfUnderflow, FpTolerances.UpToOneUlps_S);
  245. }
  246. [Test, Pairwise] [Explicit] // Fused.
  247. public void F_Mla_Mls_Ve_2D([ValueSource("_F_Mla_Mls_Ve_2D_")] uint Opcodes,
  248. [Values(0u)] uint Rd,
  249. [Values(1u, 0u)] uint Rn,
  250. [Values(2u, 0u)] uint Rm,
  251. [ValueSource("_1D_F_")] ulong Z,
  252. [ValueSource("_1D_F_")] ulong A,
  253. [ValueSource("_1D_F_")] ulong B,
  254. [Values(0u, 1u)] uint Index)
  255. {
  256. uint H = Index & 1;
  257. Opcodes |= ((Rm & 31) << 16) | ((Rn & 31) << 5) | ((Rd & 31) << 0);
  258. Opcodes |= H << 11;
  259. Vector128<float> V0 = MakeVectorE0E1(Z, Z);
  260. Vector128<float> V1 = MakeVectorE0E1(A, A);
  261. Vector128<float> V2 = MakeVectorE0E1(B, B * H);
  262. int Fpcr = (int)TestContext.CurrentContext.Random.NextUInt() & (1 << (int)FPCR.DN);
  263. AThreadState ThreadState = SingleOpcode(Opcodes, V0: V0, V1: V1, V2: V2, Fpcr: Fpcr);
  264. CompareAgainstUnicorn(FPSR.IOC, FpSkips.IfUnderflow, FpTolerances.UpToOneUlps_D);
  265. }
  266. [Test, Pairwise] [Explicit]
  267. public void F_Mul_Mulx_Se_S([ValueSource("_F_Mul_Mulx_Se_S_")] uint Opcodes,
  268. [ValueSource("_1S_F_")] ulong A,
  269. [ValueSource("_2S_F_")] ulong B,
  270. [Values(0u, 1u, 2u, 3u)] uint Index)
  271. {
  272. uint H = (Index >> 1) & 1;
  273. uint L = Index & 1;
  274. Opcodes |= (L << 21) | (H << 11);
  275. ulong Z = TestContext.CurrentContext.Random.NextULong();
  276. Vector128<float> V0 = MakeVectorE0E1(Z, Z);
  277. Vector128<float> V1 = MakeVectorE0(A);
  278. Vector128<float> V2 = MakeVectorE0E1(B, B * H);
  279. int Fpcr = (int)TestContext.CurrentContext.Random.NextUInt() & (1 << (int)FPCR.DN);
  280. AThreadState ThreadState = SingleOpcode(Opcodes, V0: V0, V1: V1, V2: V2, Fpcr: Fpcr);
  281. CompareAgainstUnicorn(FpsrMask: FPSR.IOC);
  282. }
  283. [Test, Pairwise] [Explicit]
  284. public void F_Mul_Mulx_Se_D([ValueSource("_F_Mul_Mulx_Se_D_")] uint Opcodes,
  285. [ValueSource("_1D_F_")] ulong A,
  286. [ValueSource("_1D_F_")] ulong B,
  287. [Values(0u, 1u)] uint Index)
  288. {
  289. uint H = Index & 1;
  290. Opcodes |= H << 11;
  291. ulong Z = TestContext.CurrentContext.Random.NextULong();
  292. Vector128<float> V0 = MakeVectorE1(Z);
  293. Vector128<float> V1 = MakeVectorE0(A);
  294. Vector128<float> V2 = MakeVectorE0E1(B, B * H);
  295. int Fpcr = (int)TestContext.CurrentContext.Random.NextUInt() & (1 << (int)FPCR.DN);
  296. AThreadState ThreadState = SingleOpcode(Opcodes, V0: V0, V1: V1, V2: V2, Fpcr: Fpcr);
  297. CompareAgainstUnicorn(FpsrMask: FPSR.IOC);
  298. }
  299. [Test, Pairwise] [Explicit]
  300. public void F_Mul_Mulx_Ve_2S_4S([ValueSource("_F_Mul_Mulx_Ve_2S_4S_")] uint Opcodes,
  301. [Values(0u)] uint Rd,
  302. [Values(1u, 0u)] uint Rn,
  303. [Values(2u, 0u)] uint Rm,
  304. [ValueSource("_2S_F_")] ulong Z,
  305. [ValueSource("_2S_F_")] ulong A,
  306. [ValueSource("_2S_F_")] ulong B,
  307. [Values(0u, 1u, 2u, 3u)] uint Index,
  308. [Values(0b0u, 0b1u)] uint Q) // <2S, 4S>
  309. {
  310. uint H = (Index >> 1) & 1;
  311. uint L = Index & 1;
  312. Opcodes |= ((Rm & 31) << 16) | ((Rn & 31) << 5) | ((Rd & 31) << 0);
  313. Opcodes |= (L << 21) | (H << 11);
  314. Opcodes |= ((Q & 1) << 30);
  315. Vector128<float> V0 = MakeVectorE0E1(Z, Z);
  316. Vector128<float> V1 = MakeVectorE0E1(A, A * Q);
  317. Vector128<float> V2 = MakeVectorE0E1(B, B * H);
  318. int Fpcr = (int)TestContext.CurrentContext.Random.NextUInt() & (1 << (int)FPCR.DN);
  319. AThreadState ThreadState = SingleOpcode(Opcodes, V0: V0, V1: V1, V2: V2, Fpcr: Fpcr);
  320. CompareAgainstUnicorn(FpsrMask: FPSR.IOC);
  321. }
  322. [Test, Pairwise] [Explicit]
  323. public void F_Mul_Mulx_Ve_2D([ValueSource("_F_Mul_Mulx_Ve_2D_")] uint Opcodes,
  324. [Values(0u)] uint Rd,
  325. [Values(1u, 0u)] uint Rn,
  326. [Values(2u, 0u)] uint Rm,
  327. [ValueSource("_1D_F_")] ulong Z,
  328. [ValueSource("_1D_F_")] ulong A,
  329. [ValueSource("_1D_F_")] ulong B,
  330. [Values(0u, 1u)] uint Index)
  331. {
  332. uint H = Index & 1;
  333. Opcodes |= ((Rm & 31) << 16) | ((Rn & 31) << 5) | ((Rd & 31) << 0);
  334. Opcodes |= H << 11;
  335. Vector128<float> V0 = MakeVectorE0E1(Z, Z);
  336. Vector128<float> V1 = MakeVectorE0E1(A, A);
  337. Vector128<float> V2 = MakeVectorE0E1(B, B * H);
  338. int Fpcr = (int)TestContext.CurrentContext.Random.NextUInt() & (1 << (int)FPCR.DN);
  339. AThreadState ThreadState = SingleOpcode(Opcodes, V0: V0, V1: V1, V2: V2, Fpcr: Fpcr);
  340. CompareAgainstUnicorn(FpsrMask: FPSR.IOC);
  341. }
  342. #endif
  343. }
  344. }