2018-09-08 19:23:07 +02:00
|
|
|
#define Alu
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-02-16 01:04:38 +01:00
|
|
|
using NUnit.Framework;
|
|
|
|
|
2019-06-12 14:03:31 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2018-02-16 01:04:38 +01:00
|
|
|
namespace Ryujinx.Tests.Cpu
|
|
|
|
{
|
2018-11-01 05:22:09 +01:00
|
|
|
[Category("Alu")]
|
2018-04-18 22:22:45 +02:00
|
|
|
public sealed class CpuTestAlu : CpuTest
|
2018-02-16 01:04:38 +01:00
|
|
|
{
|
2018-04-18 22:22:45 +02:00
|
|
|
#if Alu
|
2019-06-12 14:03:31 +02:00
|
|
|
|
|
|
|
#region "Helper methods"
|
|
|
|
private static uint GenLeadingSignsMinus32(int cnt) // 0 <= cnt <= 31
|
|
|
|
{
|
|
|
|
return ~GenLeadingZeros32(cnt + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static ulong GenLeadingSignsMinus64(int cnt) // 0 <= cnt <= 63
|
|
|
|
{
|
|
|
|
return ~GenLeadingZeros64(cnt + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static uint GenLeadingSignsPlus32(int cnt) // 0 <= cnt <= 31
|
|
|
|
{
|
|
|
|
return GenLeadingZeros32(cnt + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static ulong GenLeadingSignsPlus64(int cnt) // 0 <= cnt <= 63
|
|
|
|
{
|
|
|
|
return GenLeadingZeros64(cnt + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static uint GenLeadingZeros32(int cnt) // 0 <= cnt <= 32
|
|
|
|
{
|
|
|
|
if (cnt == 32) return 0u;
|
|
|
|
if (cnt == 31) return 1u;
|
|
|
|
|
|
|
|
uint rnd = TestContext.CurrentContext.Random.NextUInt();
|
|
|
|
int mask = int.MinValue;
|
|
|
|
|
|
|
|
return (rnd >> (cnt + 1)) | ((uint)mask >> cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static ulong GenLeadingZeros64(int cnt) // 0 <= cnt <= 64
|
|
|
|
{
|
|
|
|
if (cnt == 64) return 0ul;
|
|
|
|
if (cnt == 63) return 1ul;
|
|
|
|
|
|
|
|
ulong rnd = TestContext.CurrentContext.Random.NextULong();
|
|
|
|
long mask = long.MinValue;
|
|
|
|
|
|
|
|
return (rnd >> (cnt + 1)) | ((ulong)mask >> cnt);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region "ValueSource (Types)"
|
|
|
|
private static IEnumerable<ulong> _GenLeadingSignsX_()
|
|
|
|
{
|
|
|
|
for (int cnt = 0; cnt <= 63; cnt++)
|
|
|
|
{
|
|
|
|
yield return GenLeadingSignsMinus64(cnt);
|
|
|
|
yield return GenLeadingSignsPlus64(cnt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static IEnumerable<uint> _GenLeadingSignsW_()
|
|
|
|
{
|
|
|
|
for (int cnt = 0; cnt <= 31; cnt++)
|
|
|
|
{
|
|
|
|
yield return GenLeadingSignsMinus32(cnt);
|
|
|
|
yield return GenLeadingSignsPlus32(cnt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static IEnumerable<ulong> _GenLeadingZerosX_()
|
|
|
|
{
|
|
|
|
for (int cnt = 0; cnt <= 64; cnt++)
|
|
|
|
{
|
|
|
|
yield return GenLeadingZeros64(cnt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static IEnumerable<uint> _GenLeadingZerosW_()
|
|
|
|
{
|
|
|
|
for (int cnt = 0; cnt <= 32; cnt++)
|
|
|
|
{
|
|
|
|
yield return GenLeadingZeros32(cnt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
2018-09-08 19:23:07 +02:00
|
|
|
private const int RndCnt = 2;
|
2018-02-25 02:50:58 +01:00
|
|
|
|
2018-09-08 19:23:07 +02:00
|
|
|
[Test, Pairwise, Description("CLS <Xd>, <Xn>")]
|
2018-11-01 05:22:09 +01:00
|
|
|
public void Cls_64bit([Values(0u, 31u)] uint rd,
|
|
|
|
[Values(1u, 31u)] uint rn,
|
2019-06-12 14:03:31 +02:00
|
|
|
[ValueSource("_GenLeadingSignsX_")] [Random(RndCnt)] ulong xn)
|
2018-02-25 02:50:58 +01:00
|
|
|
{
|
2018-11-01 05:22:09 +01:00
|
|
|
uint opcode = 0xDAC01400; // CLS X0, X0
|
|
|
|
opcode |= ((rn & 31) << 5) | ((rd & 31) << 0);
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-11-01 05:22:09 +01:00
|
|
|
ulong x31 = TestContext.CurrentContext.Random.NextULong();
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-11-01 05:22:09 +01:00
|
|
|
SingleOpcode(opcode, x1: xn, x31: x31);
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-09-01 16:24:05 +02:00
|
|
|
CompareAgainstUnicorn();
|
2018-02-23 15:53:32 +01:00
|
|
|
}
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-09-08 19:23:07 +02:00
|
|
|
[Test, Pairwise, Description("CLS <Wd>, <Wn>")]
|
2018-11-01 05:22:09 +01:00
|
|
|
public void Cls_32bit([Values(0u, 31u)] uint rd,
|
|
|
|
[Values(1u, 31u)] uint rn,
|
2019-06-12 14:03:31 +02:00
|
|
|
[ValueSource("_GenLeadingSignsW_")] [Random(RndCnt)] uint wn)
|
2018-02-16 01:04:38 +01:00
|
|
|
{
|
2018-11-01 05:22:09 +01:00
|
|
|
uint opcode = 0x5AC01400; // CLS W0, W0
|
|
|
|
opcode |= ((rn & 31) << 5) | ((rd & 31) << 0);
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-11-01 05:22:09 +01:00
|
|
|
uint w31 = TestContext.CurrentContext.Random.NextUInt();
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-11-01 05:22:09 +01:00
|
|
|
SingleOpcode(opcode, x1: wn, x31: w31);
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-09-08 19:23:07 +02:00
|
|
|
CompareAgainstUnicorn();
|
2018-02-16 01:04:38 +01:00
|
|
|
}
|
|
|
|
|
2018-09-08 19:23:07 +02:00
|
|
|
[Test, Pairwise, Description("CLZ <Xd>, <Xn>")]
|
2018-11-01 05:22:09 +01:00
|
|
|
public void Clz_64bit([Values(0u, 31u)] uint rd,
|
|
|
|
[Values(1u, 31u)] uint rn,
|
2019-06-12 14:03:31 +02:00
|
|
|
[ValueSource("_GenLeadingZerosX_")] [Random(RndCnt)] ulong xn)
|
2018-02-25 02:50:58 +01:00
|
|
|
{
|
2018-11-01 05:22:09 +01:00
|
|
|
uint opcode = 0xDAC01000; // CLZ X0, X0
|
|
|
|
opcode |= ((rn & 31) << 5) | ((rd & 31) << 0);
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-11-01 05:22:09 +01:00
|
|
|
ulong x31 = TestContext.CurrentContext.Random.NextULong();
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-11-01 05:22:09 +01:00
|
|
|
SingleOpcode(opcode, x1: xn, x31: x31);
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-09-01 16:24:05 +02:00
|
|
|
CompareAgainstUnicorn();
|
2018-02-25 02:50:58 +01:00
|
|
|
}
|
|
|
|
|
2018-09-08 19:23:07 +02:00
|
|
|
[Test, Pairwise, Description("CLZ <Wd>, <Wn>")]
|
2018-11-01 05:22:09 +01:00
|
|
|
public void Clz_32bit([Values(0u, 31u)] uint rd,
|
|
|
|
[Values(1u, 31u)] uint rn,
|
2019-06-12 14:03:31 +02:00
|
|
|
[ValueSource("_GenLeadingZerosW_")] [Random(RndCnt)] uint wn)
|
2018-02-16 01:04:38 +01:00
|
|
|
{
|
2018-11-01 05:22:09 +01:00
|
|
|
uint opcode = 0x5AC01000; // CLZ W0, W0
|
|
|
|
opcode |= ((rn & 31) << 5) | ((rd & 31) << 0);
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-11-01 05:22:09 +01:00
|
|
|
uint w31 = TestContext.CurrentContext.Random.NextUInt();
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-11-01 05:22:09 +01:00
|
|
|
SingleOpcode(opcode, x1: wn, x31: w31);
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-09-01 16:24:05 +02:00
|
|
|
CompareAgainstUnicorn();
|
2018-02-16 01:04:38 +01:00
|
|
|
}
|
|
|
|
|
2018-09-08 19:23:07 +02:00
|
|
|
[Test, Pairwise, Description("RBIT <Xd>, <Xn>")]
|
2018-11-01 05:22:09 +01:00
|
|
|
public void Rbit_64bit([Values(0u, 31u)] uint rd,
|
|
|
|
[Values(1u, 31u)] uint rn,
|
2018-04-18 22:22:45 +02:00
|
|
|
[Values(0x0000000000000000ul, 0x7FFFFFFFFFFFFFFFul,
|
2018-11-01 05:22:09 +01:00
|
|
|
0x8000000000000000ul, 0xFFFFFFFFFFFFFFFFul)] [Random(RndCnt)] ulong xn)
|
2018-02-16 01:04:38 +01:00
|
|
|
{
|
2018-11-01 05:22:09 +01:00
|
|
|
uint opcode = 0xDAC00000; // RBIT X0, X0
|
|
|
|
opcode |= ((rn & 31) << 5) | ((rd & 31) << 0);
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-11-01 05:22:09 +01:00
|
|
|
ulong x31 = TestContext.CurrentContext.Random.NextULong();
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-11-01 05:22:09 +01:00
|
|
|
SingleOpcode(opcode, x1: xn, x31: x31);
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-09-01 16:24:05 +02:00
|
|
|
CompareAgainstUnicorn();
|
2018-03-05 13:21:19 +01:00
|
|
|
}
|
2018-02-23 13:29:20 +01:00
|
|
|
|
2018-09-08 19:23:07 +02:00
|
|
|
[Test, Pairwise, Description("RBIT <Wd>, <Wn>")]
|
2018-11-01 05:22:09 +01:00
|
|
|
public void Rbit_32bit([Values(0u, 31u)] uint rd,
|
|
|
|
[Values(1u, 31u)] uint rn,
|
2018-04-18 22:22:45 +02:00
|
|
|
[Values(0x00000000u, 0x7FFFFFFFu,
|
2018-11-01 05:22:09 +01:00
|
|
|
0x80000000u, 0xFFFFFFFFu)] [Random(RndCnt)] uint wn)
|
2018-03-05 13:21:19 +01:00
|
|
|
{
|
2018-11-01 05:22:09 +01:00
|
|
|
uint opcode = 0x5AC00000; // RBIT W0, W0
|
|
|
|
opcode |= ((rn & 31) << 5) | ((rd & 31) << 0);
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-11-01 05:22:09 +01:00
|
|
|
uint w31 = TestContext.CurrentContext.Random.NextUInt();
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-11-01 05:22:09 +01:00
|
|
|
SingleOpcode(opcode, x1: wn, x31: w31);
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-09-01 16:24:05 +02:00
|
|
|
CompareAgainstUnicorn();
|
2018-04-18 22:22:45 +02:00
|
|
|
}
|
|
|
|
|
2018-09-08 19:23:07 +02:00
|
|
|
[Test, Pairwise, Description("REV16 <Xd>, <Xn>")]
|
2018-11-01 05:22:09 +01:00
|
|
|
public void Rev16_64bit([Values(0u, 31u)] uint rd,
|
|
|
|
[Values(1u, 31u)] uint rn,
|
2018-04-18 22:22:45 +02:00
|
|
|
[Values(0x0000000000000000ul, 0x7FFFFFFFFFFFFFFFul,
|
2018-11-01 05:22:09 +01:00
|
|
|
0x8000000000000000ul, 0xFFFFFFFFFFFFFFFFul)] [Random(RndCnt)] ulong xn)
|
2018-04-18 22:22:45 +02:00
|
|
|
{
|
2018-11-01 05:22:09 +01:00
|
|
|
uint opcode = 0xDAC00400; // REV16 X0, X0
|
|
|
|
opcode |= ((rn & 31) << 5) | ((rd & 31) << 0);
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-11-01 05:22:09 +01:00
|
|
|
ulong x31 = TestContext.CurrentContext.Random.NextULong();
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-11-01 05:22:09 +01:00
|
|
|
SingleOpcode(opcode, x1: xn, x31: x31);
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-09-01 16:24:05 +02:00
|
|
|
CompareAgainstUnicorn();
|
2018-03-05 13:21:19 +01:00
|
|
|
}
|
2018-02-23 13:29:20 +01:00
|
|
|
|
2018-09-08 19:23:07 +02:00
|
|
|
[Test, Pairwise, Description("REV16 <Wd>, <Wn>")]
|
2018-11-01 05:22:09 +01:00
|
|
|
public void Rev16_32bit([Values(0u, 31u)] uint rd,
|
|
|
|
[Values(1u, 31u)] uint rn,
|
2018-04-18 22:22:45 +02:00
|
|
|
[Values(0x00000000u, 0x7FFFFFFFu,
|
2018-11-01 05:22:09 +01:00
|
|
|
0x80000000u, 0xFFFFFFFFu)] [Random(RndCnt)] uint wn)
|
2018-03-05 13:21:19 +01:00
|
|
|
{
|
2018-11-01 05:22:09 +01:00
|
|
|
uint opcode = 0x5AC00400; // REV16 W0, W0
|
|
|
|
opcode |= ((rn & 31) << 5) | ((rd & 31) << 0);
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-11-01 05:22:09 +01:00
|
|
|
uint w31 = TestContext.CurrentContext.Random.NextUInt();
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-11-01 05:22:09 +01:00
|
|
|
SingleOpcode(opcode, x1: wn, x31: w31);
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-09-01 16:24:05 +02:00
|
|
|
CompareAgainstUnicorn();
|
2018-02-16 01:04:38 +01:00
|
|
|
}
|
|
|
|
|
2018-09-08 19:23:07 +02:00
|
|
|
[Test, Pairwise, Description("REV32 <Xd>, <Xn>")]
|
2018-11-01 05:22:09 +01:00
|
|
|
public void Rev32_64bit([Values(0u, 31u)] uint rd,
|
|
|
|
[Values(1u, 31u)] uint rn,
|
2018-04-18 22:22:45 +02:00
|
|
|
[Values(0x0000000000000000ul, 0x7FFFFFFFFFFFFFFFul,
|
2018-11-01 05:22:09 +01:00
|
|
|
0x8000000000000000ul, 0xFFFFFFFFFFFFFFFFul)] [Random(RndCnt)] ulong xn)
|
2018-02-16 01:04:38 +01:00
|
|
|
{
|
2018-11-01 05:22:09 +01:00
|
|
|
uint opcode = 0xDAC00800; // REV32 X0, X0
|
|
|
|
opcode |= ((rn & 31) << 5) | ((rd & 31) << 0);
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-11-01 05:22:09 +01:00
|
|
|
ulong x31 = TestContext.CurrentContext.Random.NextULong();
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-11-01 05:22:09 +01:00
|
|
|
SingleOpcode(opcode, x1: xn, x31: x31);
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-09-01 16:24:05 +02:00
|
|
|
CompareAgainstUnicorn();
|
2018-02-16 01:04:38 +01:00
|
|
|
}
|
|
|
|
|
2018-09-08 19:23:07 +02:00
|
|
|
[Test, Pairwise, Description("REV <Wd>, <Wn>")]
|
2018-11-01 05:22:09 +01:00
|
|
|
public void Rev32_32bit([Values(0u, 31u)] uint rd,
|
|
|
|
[Values(1u, 31u)] uint rn,
|
2018-04-18 22:22:45 +02:00
|
|
|
[Values(0x00000000u, 0x7FFFFFFFu,
|
2018-11-01 05:22:09 +01:00
|
|
|
0x80000000u, 0xFFFFFFFFu)] [Random(RndCnt)] uint wn)
|
2018-02-16 01:04:38 +01:00
|
|
|
{
|
2018-11-01 05:22:09 +01:00
|
|
|
uint opcode = 0x5AC00800; // REV W0, W0
|
|
|
|
opcode |= ((rn & 31) << 5) | ((rd & 31) << 0);
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-11-01 05:22:09 +01:00
|
|
|
uint w31 = TestContext.CurrentContext.Random.NextUInt();
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-11-01 05:22:09 +01:00
|
|
|
SingleOpcode(opcode, x1: wn, x31: w31);
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-09-01 16:24:05 +02:00
|
|
|
CompareAgainstUnicorn();
|
2018-02-16 01:04:38 +01:00
|
|
|
}
|
2018-02-25 02:50:58 +01:00
|
|
|
|
2018-09-08 19:23:07 +02:00
|
|
|
[Test, Pairwise, Description("REV64 <Xd>, <Xn>")]
|
2018-11-01 05:22:09 +01:00
|
|
|
public void Rev64_64bit([Values(0u, 31u)] uint rd,
|
|
|
|
[Values(1u, 31u)] uint rn,
|
2018-04-18 22:22:45 +02:00
|
|
|
[Values(0x0000000000000000ul, 0x7FFFFFFFFFFFFFFFul,
|
2018-11-01 05:22:09 +01:00
|
|
|
0x8000000000000000ul, 0xFFFFFFFFFFFFFFFFul)] [Random(RndCnt)] ulong xn)
|
2018-02-25 02:50:58 +01:00
|
|
|
{
|
2018-11-01 05:22:09 +01:00
|
|
|
uint opcode = 0xDAC00C00; // REV64 X0, X0
|
|
|
|
opcode |= ((rn & 31) << 5) | ((rd & 31) << 0);
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-11-01 05:22:09 +01:00
|
|
|
ulong x31 = TestContext.CurrentContext.Random.NextULong();
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-11-01 05:22:09 +01:00
|
|
|
SingleOpcode(opcode, x1: xn, x31: x31);
|
2018-04-18 22:22:45 +02:00
|
|
|
|
2018-09-01 16:24:05 +02:00
|
|
|
CompareAgainstUnicorn();
|
2018-02-25 02:50:58 +01:00
|
|
|
}
|
2018-04-18 22:22:45 +02:00
|
|
|
#endif
|
2018-02-16 01:04:38 +01:00
|
|
|
}
|
|
|
|
}
|