Convert ALU binary CPU tests to xUnit

This commit is contained in:
TSR Berry 2023-07-08 23:57:14 +02:00
parent 966747cdfd
commit f16119c183
No known key found for this signature in database
GPG key ID: 52353C0A4CCA15E2
2 changed files with 147 additions and 122 deletions

View file

@ -1,5 +1,7 @@
// #define AluBinary
#define AluBinary
using ARMeilleure.State;
using System;
using Xunit;
namespace Ryujinx.Tests.Cpu
@ -52,12 +54,35 @@ namespace Ryujinx.Tests.Cpu
}
#endregion
[Test, Combinatorial]
public void Crc32_b_h_w_x([Values(0u)] uint rd,
[Values(1u)] uint rn,
[Values(2u)] uint rm,
[Range(0u, 3u)] uint size,
[ValueSource(nameof(_CRC32_Test_Values_))] CrcTest test)
private static readonly ulong[] _testData_xn =
{
0x0000000000000000ul, 0x7FFFFFFFFFFFFFFFul,
0x8000000000000000ul, 0xFFFFFFFFFFFFFFFFul,
};
private static readonly uint[] _testData_wn =
{
0x00000000u, 0x7FFFFFFFu,
0x80000000u, 0xFFFFFFFFu,
};
private static readonly uint[] _testData_Crc32_rd =
{
0u,
};
private static readonly uint[] _testData_Crc32_rn =
{
1u,
};
private static readonly uint[] _testData_Crc32_rm =
{
2u,
};
public static readonly MatrixTheoryData<uint, uint, uint, uint, CrcTest> TestData_Crc32 = new(_testData_Crc32_rd, _testData_Crc32_rn, _testData_Crc32_rm, RangeUtils.RangeData(0u, 3u, 1u), _CRC32_Test_Values_());
[Theory]
[MemberData(nameof(TestData_Crc32))]
public void Crc32_b_h_w_x(uint rd, uint rn, uint rm, uint size, CrcTest test)
{
uint opcode = 0x1AC04000; // CRC32B W0, W0, W0
@ -69,233 +94,219 @@ namespace Ryujinx.Tests.Cpu
opcode |= 0x80000000;
}
uint w31 = TestContext.CurrentContext.Random.NextUInt();
uint w31 = Random.Shared.NextUInt();
SingleOpcode(opcode, x1: test.Crc, x2: test.Value, x31: w31, runUnicorn: false);
ExecutionContext context = GetContext();
ulong result = context.GetX((int)rd);
Assert.That(result == test.Results[size]);
Assert.True(result == test.Results[size]);
}
[Test, Pairwise, Description("CRC32X <Wd>, <Wn>, <Xm>"), Ignore("Unicorn fails.")]
public void Crc32x([Values(0u, 31u)] uint rd,
[Values(1u, 31u)] uint rn,
[Values(2u, 31u)] uint rm,
[Values(0x00000000u, 0xFFFFFFFFu)] uint wn,
[Values((ulong)0x00_00_00_00_00_00_00_00,
(ulong)0x7F_FF_FF_FF_FF_FF_FF_FF,
0x80_00_00_00_00_00_00_00,
0xFF_FF_FF_FF_FF_FF_FF_FF)] ulong xm)
private static readonly uint[] _testData_Crc32x_rd =
{
0u, 31u,
};
private static readonly uint[] _testData_Crc32x_rn =
{
1u, 31u,
};
private static readonly uint[] _testData_Crc32x_rm =
{
2u, 31u,
};
private static readonly uint[] _testData_Crc32x_wn =
{
0x00000000u, 0xFFFFFFFFu,
};
public static readonly MatrixTheoryData<uint, uint, uint, uint, ulong> TestData_Crc32x = new(_testData_Crc32x_rd, _testData_Crc32x_rn, _testData_Crc32x_rm, _testData_Crc32x_wn, _testData_xn);
[Theory(DisplayName = "CRC32X <Wd>, <Wn>, <Xm>", Skip = "Unicorn fails.")]
[MemberData(nameof(TestData_Crc32x))]
public void Crc32x(uint rd, uint rn, uint rm, uint wn, ulong xm)
{
uint opcode = 0x9AC04C00; // CRC32X W0, W0, X0
opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
uint w31 = TestContext.CurrentContext.Random.NextUInt();
uint w31 = Random.Shared.NextUInt();
SingleOpcode(opcode, x1: wn, x2: xm, x31: w31);
CompareAgainstUnicorn();
}
[Test, Pairwise, Description("CRC32W <Wd>, <Wn>, <Wm>"), Ignore("Unicorn fails.")]
public void Crc32w([Values(0u, 31u)] uint rd,
[Values(1u, 31u)] uint rn,
[Values(2u, 31u)] uint rm,
[Values(0x00000000u, 0xFFFFFFFFu)] uint wn,
[Values((uint)0x00_00_00_00, (uint)0x7F_FF_FF_FF,
0x80_00_00_00, 0xFF_FF_FF_FF)] uint wm)
public static readonly MatrixTheoryData<uint, uint, uint, uint, uint> TestData_Crc32w = new(_testData_Crc32x_rd, _testData_Crc32x_rn, _testData_Crc32x_rm, _testData_Crc32x_wn, _testData_wn);
[Theory(DisplayName = "CRC32W <Wd>, <Wn>, <Wm>", Skip = "Unicorn fails.")]
[MemberData(nameof(TestData_Crc32w))]
public void Crc32w(uint rd, uint rn, uint rm, uint wn, uint wm)
{
uint opcode = 0x1AC04800; // CRC32W W0, W0, W0
opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
uint w31 = TestContext.CurrentContext.Random.NextUInt();
uint w31 = Random.Shared.NextUInt();
SingleOpcode(opcode, x1: wn, x2: wm, x31: w31);
CompareAgainstUnicorn();
}
[Test, Pairwise, Description("CRC32H <Wd>, <Wn>, <Wm>"), Ignore("Unicorn fails.")]
public void Crc32h([Values(0u, 31u)] uint rd,
[Values(1u, 31u)] uint rn,
[Values(2u, 31u)] uint rm,
[Values(0x00000000u, 0xFFFFFFFFu)] uint wn,
[Values((ushort)0x00_00, (ushort)0x7F_FF,
(ushort)0x80_00, (ushort)0xFF_FF)] ushort wm)
private static readonly ushort[] _testData_Crc32h_wm =
{
0x00_00, 0x7F_FF,
0x80_00, 0xFF_FF,
};
public static readonly MatrixTheoryData<uint, uint, uint, uint, ushort> TestData_Crc32h = new(_testData_Crc32x_rd, _testData_Crc32x_rn, _testData_Crc32x_rm, _testData_Crc32x_wn, _testData_Crc32h_wm);
[Theory(DisplayName = "CRC32H <Wd>, <Wn>, <Wm>", Skip = "Unicorn fails.")]
[MemberData(nameof(TestData_Crc32h))]
public void Crc32h(uint rd, uint rn, uint rm, uint wn, ushort wm)
{
uint opcode = 0x1AC04400; // CRC32H W0, W0, W0
opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
uint w31 = TestContext.CurrentContext.Random.NextUInt();
uint w31 = Random.Shared.NextUInt();
SingleOpcode(opcode, x1: wn, x2: wm, x31: w31);
CompareAgainstUnicorn();
}
[Test, Pairwise, Description("CRC32B <Wd>, <Wn>, <Wm>"), Ignore("Unicorn fails.")]
public void Crc32b([Values(0u, 31u)] uint rd,
[Values(1u, 31u)] uint rn,
[Values(2u, 31u)] uint rm,
[Values(0x00000000u, 0xFFFFFFFFu)] uint wn,
[Values((byte)0x00, (byte)0x7F,
(byte)0x80, (byte)0xFF)] byte wm)
private static readonly byte[] _testData_Crc32b_wm =
{
0x00, 0x7F,
0x80, 0xFF,
};
public static readonly MatrixTheoryData<uint, uint, uint, uint, byte> TestData_Crc32b = new(_testData_Crc32x_rd, _testData_Crc32x_rn, _testData_Crc32x_rm, _testData_Crc32x_wn, _testData_Crc32b_wm);
[Theory(DisplayName = "CRC32B <Wd>, <Wn>, <Wm>", Skip = "Unicorn fails.")]
[MemberData(nameof(TestData_Crc32b))]
public void Crc32b(uint rd, uint rn, uint rm, uint wn, byte wm)
{
uint opcode = 0x1AC04000; // CRC32B W0, W0, W0
opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
uint w31 = TestContext.CurrentContext.Random.NextUInt();
uint w31 = Random.Shared.NextUInt();
SingleOpcode(opcode, x1: wn, x2: wm, x31: w31);
CompareAgainstUnicorn();
}
[Test, Pairwise, Description("CRC32CX <Wd>, <Wn>, <Xm>")]
public void Crc32cx([Values(0u, 31u)] uint rd,
[Values(1u, 31u)] uint rn,
[Values(2u, 31u)] uint rm,
[Values(0x00000000u, 0xFFFFFFFFu)] uint wn,
[Values((ulong)0x00_00_00_00_00_00_00_00,
(ulong)0x7F_FF_FF_FF_FF_FF_FF_FF,
0x80_00_00_00_00_00_00_00,
0xFF_FF_FF_FF_FF_FF_FF_FF)] ulong xm)
[Theory(DisplayName = "CRC32CX <Wd>, <Wn>, <Xm>")]
[MemberData(nameof(TestData_Crc32x))]
public void Crc32cx(uint rd, uint rn, uint rm, uint wn, ulong xm)
{
uint opcode = 0x9AC05C00; // CRC32CX W0, W0, X0
opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
uint w31 = TestContext.CurrentContext.Random.NextUInt();
uint w31 = Random.Shared.NextUInt();
SingleOpcode(opcode, x1: wn, x2: xm, x31: w31);
CompareAgainstUnicorn();
}
[Test, Pairwise, Description("CRC32CW <Wd>, <Wn>, <Wm>")]
public void Crc32cw([Values(0u, 31u)] uint rd,
[Values(1u, 31u)] uint rn,
[Values(2u, 31u)] uint rm,
[Values(0x00000000u, 0xFFFFFFFFu)] uint wn,
[Values((uint)0x00_00_00_00, (uint)0x7F_FF_FF_FF,
0x80_00_00_00, 0xFF_FF_FF_FF)] uint wm)
[Theory(DisplayName = "CRC32CW <Wd>, <Wn>, <Wm>")]
[MemberData(nameof(TestData_Crc32w))]
public void Crc32cw(uint rd, uint rn, uint rm, uint wn, uint wm)
{
uint opcode = 0x1AC05800; // CRC32CW W0, W0, W0
opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
uint w31 = TestContext.CurrentContext.Random.NextUInt();
uint w31 = Random.Shared.NextUInt();
SingleOpcode(opcode, x1: wn, x2: wm, x31: w31);
CompareAgainstUnicorn();
}
[Test, Pairwise, Description("CRC32CH <Wd>, <Wn>, <Wm>")]
public void Crc32ch([Values(0u, 31u)] uint rd,
[Values(1u, 31u)] uint rn,
[Values(2u, 31u)] uint rm,
[Values(0x00000000u, 0xFFFFFFFFu)] uint wn,
[Values((ushort)0x00_00, (ushort)0x7F_FF,
(ushort)0x80_00, (ushort)0xFF_FF)] ushort wm)
[Theory(DisplayName = "CRC32CH <Wd>, <Wn>, <Wm>")]
[MemberData(nameof(TestData_Crc32h))]
public void Crc32ch(uint rd, uint rn, uint rm, uint wn, ushort wm)
{
uint opcode = 0x1AC05400; // CRC32CH W0, W0, W0
opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
uint w31 = TestContext.CurrentContext.Random.NextUInt();
uint w31 = Random.Shared.NextUInt();
SingleOpcode(opcode, x1: wn, x2: wm, x31: w31);
CompareAgainstUnicorn();
}
[Test, Pairwise, Description("CRC32CB <Wd>, <Wn>, <Wm>")]
public void Crc32cb([Values(0u, 31u)] uint rd,
[Values(1u, 31u)] uint rn,
[Values(2u, 31u)] uint rm,
[Values(0x00000000u, 0xFFFFFFFFu)] uint wn,
[Values((byte)0x00, (byte)0x7F,
(byte)0x80, (byte)0xFF)] byte wm)
[Theory(DisplayName = "CRC32CB <Wd>, <Wn>, <Wm>")]
[MemberData(nameof(TestData_Crc32b))]
public void Crc32cb(uint rd, uint rn, uint rm, uint wn, byte wm)
{
uint opcode = 0x1AC05000; // CRC32CB W0, W0, W0
opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
uint w31 = TestContext.CurrentContext.Random.NextUInt();
uint w31 = Random.Shared.NextUInt();
SingleOpcode(opcode, x1: wn, x2: wm, x31: w31);
CompareAgainstUnicorn();
}
[Test, Pairwise, Description("SDIV <Xd>, <Xn>, <Xm>")]
public void Sdiv_64bit([Values(0u, 31u)] uint rd,
[Values(1u, 31u)] uint rn,
[Values(2u, 31u)] uint rm,
[Values(0x0000000000000000ul, 0x7FFFFFFFFFFFFFFFul,
0x8000000000000000ul, 0xFFFFFFFFFFFFFFFFul)] ulong xn,
[Values(0x0000000000000000ul, 0x7FFFFFFFFFFFFFFFul,
0x8000000000000000ul, 0xFFFFFFFFFFFFFFFFul)] ulong xm)
public static readonly MatrixTheoryData<uint, uint, uint, ulong, ulong> TestData_Sdiv64 = new(_testData_Crc32x_rd, _testData_Crc32x_rn, _testData_Crc32x_rm, _testData_xn, _testData_xn);
[Theory(DisplayName = "SDIV <Xd>, <Xn>, <Xm>")]
[MemberData(nameof(TestData_Sdiv64))]
public void Sdiv_64bit(uint rd, uint rn, uint rm, ulong xn, ulong xm)
{
uint opcode = 0x9AC00C00; // SDIV X0, X0, X0
opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
ulong x31 = TestContext.CurrentContext.Random.NextULong();
ulong x31 = Random.Shared.NextULong();
SingleOpcode(opcode, x1: xn, x2: xm, x31: x31);
CompareAgainstUnicorn();
}
[Test, Pairwise, Description("SDIV <Wd>, <Wn>, <Wm>")]
public void Sdiv_32bit([Values(0u, 31u)] uint rd,
[Values(1u, 31u)] uint rn,
[Values(2u, 31u)] uint rm,
[Values(0x00000000u, 0x7FFFFFFFu,
0x80000000u, 0xFFFFFFFFu)] uint wn,
[Values(0x00000000u, 0x7FFFFFFFu,
0x80000000u, 0xFFFFFFFFu)] uint wm)
public static readonly MatrixTheoryData<uint, uint, uint, uint, uint> TestData_Sdiv32 = new(_testData_Crc32x_rd, _testData_Crc32x_rn, _testData_Crc32x_rm, _testData_wn, _testData_wn);
[Theory(DisplayName = "SDIV <Wd>, <Wn>, <Wm>")]
[MemberData(nameof(TestData_Sdiv32))]
public void Sdiv_32bit(uint rd, uint rn, uint rm, uint wn, uint wm)
{
uint opcode = 0x1AC00C00; // SDIV W0, W0, W0
opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
uint w31 = TestContext.CurrentContext.Random.NextUInt();
uint w31 = Random.Shared.NextUInt();
SingleOpcode(opcode, x1: wn, x2: wm, x31: w31);
CompareAgainstUnicorn();
}
[Test, Pairwise, Description("UDIV <Xd>, <Xn>, <Xm>")]
public void Udiv_64bit([Values(0u, 31u)] uint rd,
[Values(1u, 31u)] uint rn,
[Values(2u, 31u)] uint rm,
[Values(0x0000000000000000ul, 0x7FFFFFFFFFFFFFFFul,
0x8000000000000000ul, 0xFFFFFFFFFFFFFFFFul)] ulong xn,
[Values(0x0000000000000000ul, 0x7FFFFFFFFFFFFFFFul,
0x8000000000000000ul, 0xFFFFFFFFFFFFFFFFul)] ulong xm)
[Theory(DisplayName = "UDIV <Xd>, <Xn>, <Xm>")]
[MemberData(nameof(TestData_Sdiv64))]
public void Udiv_64bit(uint rd, uint rn, uint rm, ulong xn, ulong xm)
{
uint opcode = 0x9AC00800; // UDIV X0, X0, X0
opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
ulong x31 = TestContext.CurrentContext.Random.NextULong();
ulong x31 = Random.Shared.NextULong();
SingleOpcode(opcode, x1: xn, x2: xm, x31: x31);
CompareAgainstUnicorn();
}
[Test, Pairwise, Description("UDIV <Wd>, <Wn>, <Wm>")]
public void Udiv_32bit([Values(0u, 31u)] uint rd,
[Values(1u, 31u)] uint rn,
[Values(2u, 31u)] uint rm,
[Values(0x00000000u, 0x7FFFFFFFu,
0x80000000u, 0xFFFFFFFFu)] uint wn,
[Values(0x00000000u, 0x7FFFFFFFu,
0x80000000u, 0xFFFFFFFFu)] uint wm)
[Theory(DisplayName = "UDIV <Wd>, <Wn>, <Wm>")]
[MemberData(nameof(TestData_Sdiv32))]
public void Udiv_32bit(uint rd, uint rn, uint rm, uint wn, uint wm)
{
uint opcode = 0x1AC00800; // UDIV W0, W0, W0
opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0);
uint w31 = TestContext.CurrentContext.Random.NextUInt();
uint w31 = Random.Shared.NextUInt();
SingleOpcode(opcode, x1: wn, x2: wm, x31: w31);

View file

@ -1,5 +1,7 @@
// #define AluBinary32
#define AluBinary32
using ARMeilleure.State;
using System;
using Xunit;
namespace Ryujinx.Tests.Cpu
@ -64,12 +66,24 @@ namespace Ryujinx.Tests.Cpu
}
#endregion
[Test, Combinatorial]
public void Crc32_Crc32c_b_h_w([Values(0u)] uint rd,
[Values(1u)] uint rn,
[Values(2u)] uint rm,
[Range(0u, 2u)] uint size,
[ValueSource(nameof(_CRC32_Test_Values_))] CrcTest32 test)
private static uint[] _testData_rd =
{
0u,
};
private static uint[] _testData_rn =
{
1u,
};
private static uint[] _testData_rm =
{
2u,
};
public static readonly MatrixTheoryData<uint, uint, uint, uint, CrcTest32> TestData = new(_testData_rd, _testData_rn, _testData_rm, RangeUtils.RangeData(0u, 2u, 1u), _CRC32_Test_Values_());
[Theory]
[MemberData(nameof(TestData))]
public void Crc32_Crc32c_b_h_w(uint rd, uint rn, uint rm, uint size, CrcTest32 test)
{
// Unicorn does not yet support 32bit crc instructions, so test against a known table of results/values.
@ -81,13 +95,13 @@ namespace Ryujinx.Tests.Cpu
opcode |= 1 << 9;
}
uint sp = TestContext.CurrentContext.Random.NextUInt();
uint sp = Random.Shared.NextUInt();
SingleOpcode(opcode, r1: test.Crc, r2: test.Value, sp: sp, runUnicorn: false);
ExecutionContext context = GetContext();
ulong result = context.GetX((int)rd);
Assert.That(result == test.Results[size]);
Assert.True(result == test.Results[size]);
}
#endif
}