aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Tests/Cpu/CpuTestSystem.cs
blob: 6c498ef0f6be9ac752bc5b527bb7ba7c9feb75d8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#define System

using ARMeilleure.State;
using NUnit.Framework;
using System.Collections.Generic;

namespace Ryujinx.Tests.Cpu
{
    [Category("System")]
    public sealed class CpuTestSystem : CpuTest
    {
#if System

        #region "ValueSource (Types)"
        private static IEnumerable<ulong> _GenNzcv_()
        {
            yield return 0x0000000000000000ul;
            yield return 0x7FFFFFFFFFFFFFFFul;
            yield return 0x8000000000000000ul;
            yield return 0xFFFFFFFFFFFFFFFFul;

            bool v = TestContext.CurrentContext.Random.NextBool();
            bool c = TestContext.CurrentContext.Random.NextBool();
            bool z = TestContext.CurrentContext.Random.NextBool();
            bool n = TestContext.CurrentContext.Random.NextBool();

            ulong rnd = 0UL;

            rnd |= (v ? 1UL : 0UL) << (int)PState.VFlag;
            rnd |= (c ? 1UL : 0UL) << (int)PState.CFlag;
            rnd |= (z ? 1UL : 0UL) << (int)PState.ZFlag;
            rnd |= (n ? 1UL : 0UL) << (int)PState.NFlag;

            yield return rnd;
        }
        #endregion

        #region "ValueSource (Opcodes)"
        private static uint[] _MrsMsr_Nzcv_()
        {
            return new[]
            {
                0xD53B4200u, // MRS X0, NZCV
                0xD51B4200u, // MSR NZCV, X0
            };
        }
        #endregion

        [Test, Pairwise]
        public void MrsMsr_Nzcv([ValueSource(nameof(_MrsMsr_Nzcv_))] uint opcodes,
                                [Values(0u, 1u, 31u)] uint rt,
                                [ValueSource(nameof(_GenNzcv_))] ulong xt)
        {
            opcodes |= (rt & 31) << 0;

            bool v = TestContext.CurrentContext.Random.NextBool();
            bool c = TestContext.CurrentContext.Random.NextBool();
            bool z = TestContext.CurrentContext.Random.NextBool();
            bool n = TestContext.CurrentContext.Random.NextBool();

            ulong x31 = TestContext.CurrentContext.Random.NextULong();

            SingleOpcode(opcodes, x0: xt, x1: xt, x31: x31, overflow: v, carry: c, zero: z, negative: n);

            CompareAgainstUnicorn();
        }
#endif
    }
}