2018-02-23 07:29:20 -05:00
|
|
|
using ChocolArm64;
|
2018-02-15 19:04:38 -05:00
|
|
|
using ChocolArm64.Memory;
|
|
|
|
using ChocolArm64.State;
|
2018-06-18 13:55:26 -04:00
|
|
|
|
2018-02-15 19:04:38 -05:00
|
|
|
using NUnit.Framework;
|
2018-06-18 13:55:26 -04:00
|
|
|
|
2018-09-01 10:24:05 -04:00
|
|
|
using Ryujinx.Tests.Unicorn;
|
|
|
|
|
2018-05-11 19:10:27 -04:00
|
|
|
using System;
|
2018-08-15 14:59:51 -04:00
|
|
|
using System.Runtime.InteropServices;
|
2018-05-11 19:10:27 -04:00
|
|
|
using System.Runtime.Intrinsics;
|
|
|
|
using System.Runtime.Intrinsics.X86;
|
2018-06-10 20:46:42 -04:00
|
|
|
using System.Threading;
|
2018-02-15 19:04:38 -05:00
|
|
|
|
|
|
|
namespace Ryujinx.Tests.Cpu
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2018-02-23 07:29:20 -05:00
|
|
|
public class CpuTest
|
2018-02-15 19:04:38 -05:00
|
|
|
{
|
2018-02-23 07:29:20 -05:00
|
|
|
protected long Position { get; private set; }
|
|
|
|
private long Size;
|
|
|
|
|
|
|
|
private long EntryPoint;
|
|
|
|
|
2018-08-15 14:59:51 -04:00
|
|
|
private IntPtr RamPointer;
|
|
|
|
|
2018-02-23 07:29:20 -05:00
|
|
|
private AMemory Memory;
|
|
|
|
private AThread Thread;
|
2018-02-15 19:04:38 -05:00
|
|
|
|
2018-09-01 10:24:05 -04:00
|
|
|
private static bool UnicornAvailable;
|
|
|
|
private UnicornAArch64 UnicornEmu;
|
|
|
|
|
|
|
|
static CpuTest()
|
|
|
|
{
|
|
|
|
UnicornAvailable = UnicornAArch64.IsAvailable();
|
2018-09-08 13:23:07 -04:00
|
|
|
|
2018-09-01 10:24:05 -04:00
|
|
|
if (!UnicornAvailable)
|
|
|
|
{
|
2018-09-08 13:23:07 -04:00
|
|
|
Console.WriteLine("WARNING: Could not find Unicorn.");
|
2018-09-01 10:24:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 19:04:38 -05:00
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
2018-09-01 10:24:05 -04:00
|
|
|
Position = 0x1000;
|
2018-09-08 13:23:07 -04:00
|
|
|
Size = 0x1000;
|
2018-02-23 07:29:20 -05:00
|
|
|
|
|
|
|
EntryPoint = Position;
|
|
|
|
|
2018-02-25 20:14:58 -05:00
|
|
|
ATranslator Translator = new ATranslator();
|
2018-08-15 14:59:51 -04:00
|
|
|
RamPointer = Marshal.AllocHGlobal(new IntPtr(Size));
|
|
|
|
Memory = new AMemory(RamPointer);
|
|
|
|
Memory.Map(Position, 0, Size);
|
2018-03-12 00:04:52 -04:00
|
|
|
Thread = new AThread(Translator, Memory, EntryPoint);
|
2018-09-01 10:24:05 -04:00
|
|
|
|
|
|
|
if (UnicornAvailable)
|
|
|
|
{
|
|
|
|
UnicornEmu = new UnicornAArch64();
|
|
|
|
UnicornEmu.MemoryMap((ulong)Position, (ulong)Size, MemoryPermission.READ | MemoryPermission.EXEC);
|
|
|
|
UnicornEmu.PC = (ulong)EntryPoint;
|
|
|
|
}
|
2018-02-15 19:04:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
public void Teardown()
|
|
|
|
{
|
2018-08-15 14:59:51 -04:00
|
|
|
Marshal.FreeHGlobal(RamPointer);
|
2018-02-23 07:29:20 -05:00
|
|
|
Memory = null;
|
2018-06-18 13:55:26 -04:00
|
|
|
Thread = null;
|
2018-09-01 10:24:05 -04:00
|
|
|
UnicornEmu = null;
|
2018-02-15 19:04:38 -05:00
|
|
|
}
|
|
|
|
|
2018-02-23 07:29:20 -05:00
|
|
|
protected void Reset()
|
2018-02-15 19:04:38 -05:00
|
|
|
{
|
2018-02-23 07:29:20 -05:00
|
|
|
Teardown();
|
|
|
|
Setup();
|
2018-02-15 19:04:38 -05:00
|
|
|
}
|
|
|
|
|
2018-02-23 07:29:20 -05:00
|
|
|
protected void Opcode(uint Opcode)
|
2018-02-15 19:04:38 -05:00
|
|
|
{
|
2018-08-15 14:59:51 -04:00
|
|
|
Thread.Memory.WriteUInt32(Position, Opcode);
|
2018-09-08 13:23:07 -04:00
|
|
|
|
2018-09-01 10:24:05 -04:00
|
|
|
if (UnicornAvailable)
|
|
|
|
{
|
|
|
|
UnicornEmu.MemoryWrite32((ulong)Position, Opcode);
|
|
|
|
}
|
2018-09-08 13:23:07 -04:00
|
|
|
|
2018-02-23 07:29:20 -05:00
|
|
|
Position += 4;
|
|
|
|
}
|
2018-02-15 19:04:38 -05:00
|
|
|
|
2018-04-18 16:22:45 -04:00
|
|
|
protected void SetThreadState(ulong X0 = 0, ulong X1 = 0, ulong X2 = 0, ulong X3 = 0, ulong X31 = 0,
|
2018-05-11 19:10:27 -04:00
|
|
|
Vector128<float> V0 = default(Vector128<float>),
|
|
|
|
Vector128<float> V1 = default(Vector128<float>),
|
|
|
|
Vector128<float> V2 = default(Vector128<float>),
|
2018-09-17 00:54:05 -04:00
|
|
|
Vector128<float> V3 = default(Vector128<float>),
|
2018-04-29 19:39:58 -04:00
|
|
|
bool Overflow = false, bool Carry = false, bool Zero = false, bool Negative = false,
|
|
|
|
int Fpcr = 0x0, int Fpsr = 0x0)
|
2018-02-23 07:29:20 -05:00
|
|
|
{
|
2018-02-18 14:28:07 -05:00
|
|
|
Thread.ThreadState.X0 = X0;
|
|
|
|
Thread.ThreadState.X1 = X1;
|
|
|
|
Thread.ThreadState.X2 = X2;
|
2018-04-18 16:22:45 -04:00
|
|
|
Thread.ThreadState.X3 = X3;
|
2018-09-08 13:23:07 -04:00
|
|
|
|
2018-02-24 20:50:58 -05:00
|
|
|
Thread.ThreadState.X31 = X31;
|
2018-09-08 13:23:07 -04:00
|
|
|
|
2018-02-18 14:28:07 -05:00
|
|
|
Thread.ThreadState.V0 = V0;
|
|
|
|
Thread.ThreadState.V1 = V1;
|
|
|
|
Thread.ThreadState.V2 = V2;
|
2018-09-17 00:54:05 -04:00
|
|
|
Thread.ThreadState.V3 = V3;
|
2018-09-08 13:23:07 -04:00
|
|
|
|
2018-02-23 09:53:32 -05:00
|
|
|
Thread.ThreadState.Overflow = Overflow;
|
2018-09-08 13:23:07 -04:00
|
|
|
Thread.ThreadState.Carry = Carry;
|
|
|
|
Thread.ThreadState.Zero = Zero;
|
2018-02-23 09:53:32 -05:00
|
|
|
Thread.ThreadState.Negative = Negative;
|
2018-09-08 13:23:07 -04:00
|
|
|
|
2018-03-05 07:21:19 -05:00
|
|
|
Thread.ThreadState.Fpcr = Fpcr;
|
2018-04-29 19:39:58 -04:00
|
|
|
Thread.ThreadState.Fpsr = Fpsr;
|
2018-09-01 10:24:05 -04:00
|
|
|
|
|
|
|
if (UnicornAvailable)
|
|
|
|
{
|
|
|
|
UnicornEmu.X[0] = X0;
|
|
|
|
UnicornEmu.X[1] = X1;
|
|
|
|
UnicornEmu.X[2] = X2;
|
|
|
|
UnicornEmu.X[3] = X3;
|
2018-09-08 13:23:07 -04:00
|
|
|
|
2018-09-01 10:24:05 -04:00
|
|
|
UnicornEmu.SP = X31;
|
2018-09-08 13:23:07 -04:00
|
|
|
|
2018-09-01 10:24:05 -04:00
|
|
|
UnicornEmu.Q[0] = V0;
|
|
|
|
UnicornEmu.Q[1] = V1;
|
|
|
|
UnicornEmu.Q[2] = V2;
|
2018-09-17 00:54:05 -04:00
|
|
|
UnicornEmu.Q[3] = V3;
|
2018-09-08 13:23:07 -04:00
|
|
|
|
2018-09-01 10:24:05 -04:00
|
|
|
UnicornEmu.OverflowFlag = Overflow;
|
2018-09-08 13:23:07 -04:00
|
|
|
UnicornEmu.CarryFlag = Carry;
|
|
|
|
UnicornEmu.ZeroFlag = Zero;
|
2018-09-01 10:24:05 -04:00
|
|
|
UnicornEmu.NegativeFlag = Negative;
|
2018-09-08 13:23:07 -04:00
|
|
|
|
2018-09-01 10:24:05 -04:00
|
|
|
UnicornEmu.Fpcr = Fpcr;
|
|
|
|
UnicornEmu.Fpsr = Fpsr;
|
|
|
|
}
|
2018-02-23 07:29:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void ExecuteOpcodes()
|
|
|
|
{
|
|
|
|
using (ManualResetEvent Wait = new ManualResetEvent(false))
|
|
|
|
{
|
|
|
|
Thread.ThreadState.Break += (sender, e) => Thread.StopExecution();
|
|
|
|
Thread.WorkFinished += (sender, e) => Wait.Set();
|
|
|
|
|
|
|
|
Thread.Execute();
|
|
|
|
Wait.WaitOne();
|
|
|
|
}
|
2018-09-01 10:24:05 -04:00
|
|
|
|
|
|
|
if (UnicornAvailable)
|
|
|
|
{
|
|
|
|
UnicornEmu.RunForCount((ulong)(Position - EntryPoint - 8) / 4);
|
|
|
|
}
|
2018-02-23 07:29:20 -05:00
|
|
|
}
|
|
|
|
|
2018-09-08 13:23:07 -04:00
|
|
|
protected AThreadState GetThreadState() => Thread.ThreadState;
|
2018-02-15 19:04:38 -05:00
|
|
|
|
2018-02-23 07:29:20 -05:00
|
|
|
protected AThreadState SingleOpcode(uint Opcode,
|
2018-04-18 16:22:45 -04:00
|
|
|
ulong X0 = 0, ulong X1 = 0, ulong X2 = 0, ulong X3 = 0, ulong X31 = 0,
|
2018-05-11 19:10:27 -04:00
|
|
|
Vector128<float> V0 = default(Vector128<float>),
|
|
|
|
Vector128<float> V1 = default(Vector128<float>),
|
|
|
|
Vector128<float> V2 = default(Vector128<float>),
|
2018-09-17 00:54:05 -04:00
|
|
|
Vector128<float> V3 = default(Vector128<float>),
|
2018-04-29 19:39:58 -04:00
|
|
|
bool Overflow = false, bool Carry = false, bool Zero = false, bool Negative = false,
|
|
|
|
int Fpcr = 0x0, int Fpsr = 0x0)
|
2018-02-15 19:04:38 -05:00
|
|
|
{
|
2018-02-23 07:29:20 -05:00
|
|
|
this.Opcode(Opcode);
|
|
|
|
this.Opcode(0xD4200000); // BRK #0
|
|
|
|
this.Opcode(0xD65F03C0); // RET
|
2018-09-17 00:54:05 -04:00
|
|
|
SetThreadState(X0, X1, X2, X3, X31, V0, V1, V2, V3, Overflow, Carry, Zero, Negative, Fpcr, Fpsr);
|
2018-02-23 07:29:20 -05:00
|
|
|
ExecuteOpcodes();
|
|
|
|
|
|
|
|
return GetThreadState();
|
2018-02-15 19:04:38 -05:00
|
|
|
}
|
2018-05-11 19:10:27 -04:00
|
|
|
|
2018-10-05 21:45:59 -04:00
|
|
|
/// <summary>Floating-point Control Register.</summary>
|
|
|
|
protected enum FPCR
|
|
|
|
{
|
|
|
|
/// <summary>Default NaN mode control bit.</summary>
|
|
|
|
DN = 25
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>Floating-point Status Register.</summary>
|
|
|
|
[Flags] protected enum FPSR
|
2018-09-08 13:23:07 -04:00
|
|
|
{
|
|
|
|
None = 0,
|
|
|
|
|
|
|
|
/// <summary>Invalid Operation cumulative floating-point exception bit.</summary>
|
|
|
|
IOC = 1 << 0,
|
|
|
|
/// <summary>Divide by Zero cumulative floating-point exception bit.</summary>
|
|
|
|
DZC = 1 << 1,
|
|
|
|
/// <summary>Overflow cumulative floating-point exception bit.</summary>
|
|
|
|
OFC = 1 << 2,
|
|
|
|
/// <summary>Underflow cumulative floating-point exception bit.</summary>
|
|
|
|
UFC = 1 << 3,
|
|
|
|
/// <summary>Inexact cumulative floating-point exception bit.</summary>
|
|
|
|
IXC = 1 << 4,
|
|
|
|
/// <summary>Input Denormal cumulative floating-point exception bit.</summary>
|
|
|
|
IDC = 1 << 7,
|
2018-10-05 21:45:59 -04:00
|
|
|
|
2018-09-08 13:23:07 -04:00
|
|
|
/// <summary>Cumulative saturation bit.</summary>
|
2018-10-05 21:45:59 -04:00
|
|
|
QC = 1 << 27
|
2018-09-08 13:23:07 -04:00
|
|
|
}
|
|
|
|
|
2018-10-05 21:45:59 -04:00
|
|
|
[Flags] protected enum FpSkips
|
|
|
|
{
|
|
|
|
None = 0,
|
|
|
|
|
|
|
|
IfNaN_S = 1,
|
|
|
|
IfNaN_D = 2,
|
2018-09-17 00:54:05 -04:00
|
|
|
|
2018-10-05 21:45:59 -04:00
|
|
|
IfUnderflow = 4,
|
|
|
|
IfOverflow = 8
|
|
|
|
}
|
|
|
|
|
|
|
|
protected enum FpTolerances
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
|
|
|
|
UpToOneUlps_S,
|
|
|
|
UpToOneUlps_D
|
|
|
|
}
|
2018-09-17 00:54:05 -04:00
|
|
|
|
|
|
|
protected void CompareAgainstUnicorn(
|
2018-10-05 21:45:59 -04:00
|
|
|
FPSR FpsrMask = FPSR.None,
|
|
|
|
FpSkips FpSkips = FpSkips.None,
|
|
|
|
FpTolerances FpTolerances = FpTolerances.None)
|
2018-09-01 10:24:05 -04:00
|
|
|
{
|
|
|
|
if (!UnicornAvailable)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-05 21:45:59 -04:00
|
|
|
if (FpSkips != FpSkips.None)
|
2018-09-17 00:54:05 -04:00
|
|
|
{
|
2018-10-05 21:45:59 -04:00
|
|
|
ManageFpSkips(FpSkips);
|
2018-09-17 00:54:05 -04:00
|
|
|
}
|
|
|
|
|
2018-09-08 13:23:07 -04:00
|
|
|
Assert.That(Thread.ThreadState.X0, Is.EqualTo(UnicornEmu.X[0]));
|
|
|
|
Assert.That(Thread.ThreadState.X1, Is.EqualTo(UnicornEmu.X[1]));
|
|
|
|
Assert.That(Thread.ThreadState.X2, Is.EqualTo(UnicornEmu.X[2]));
|
|
|
|
Assert.That(Thread.ThreadState.X3, Is.EqualTo(UnicornEmu.X[3]));
|
|
|
|
Assert.That(Thread.ThreadState.X4, Is.EqualTo(UnicornEmu.X[4]));
|
|
|
|
Assert.That(Thread.ThreadState.X5, Is.EqualTo(UnicornEmu.X[5]));
|
|
|
|
Assert.That(Thread.ThreadState.X6, Is.EqualTo(UnicornEmu.X[6]));
|
|
|
|
Assert.That(Thread.ThreadState.X7, Is.EqualTo(UnicornEmu.X[7]));
|
|
|
|
Assert.That(Thread.ThreadState.X8, Is.EqualTo(UnicornEmu.X[8]));
|
|
|
|
Assert.That(Thread.ThreadState.X9, Is.EqualTo(UnicornEmu.X[9]));
|
2018-09-01 10:24:05 -04:00
|
|
|
Assert.That(Thread.ThreadState.X10, Is.EqualTo(UnicornEmu.X[10]));
|
|
|
|
Assert.That(Thread.ThreadState.X11, Is.EqualTo(UnicornEmu.X[11]));
|
|
|
|
Assert.That(Thread.ThreadState.X12, Is.EqualTo(UnicornEmu.X[12]));
|
|
|
|
Assert.That(Thread.ThreadState.X13, Is.EqualTo(UnicornEmu.X[13]));
|
|
|
|
Assert.That(Thread.ThreadState.X14, Is.EqualTo(UnicornEmu.X[14]));
|
|
|
|
Assert.That(Thread.ThreadState.X15, Is.EqualTo(UnicornEmu.X[15]));
|
|
|
|
Assert.That(Thread.ThreadState.X16, Is.EqualTo(UnicornEmu.X[16]));
|
|
|
|
Assert.That(Thread.ThreadState.X17, Is.EqualTo(UnicornEmu.X[17]));
|
|
|
|
Assert.That(Thread.ThreadState.X18, Is.EqualTo(UnicornEmu.X[18]));
|
|
|
|
Assert.That(Thread.ThreadState.X19, Is.EqualTo(UnicornEmu.X[19]));
|
|
|
|
Assert.That(Thread.ThreadState.X20, Is.EqualTo(UnicornEmu.X[20]));
|
|
|
|
Assert.That(Thread.ThreadState.X21, Is.EqualTo(UnicornEmu.X[21]));
|
|
|
|
Assert.That(Thread.ThreadState.X22, Is.EqualTo(UnicornEmu.X[22]));
|
|
|
|
Assert.That(Thread.ThreadState.X23, Is.EqualTo(UnicornEmu.X[23]));
|
|
|
|
Assert.That(Thread.ThreadState.X24, Is.EqualTo(UnicornEmu.X[24]));
|
|
|
|
Assert.That(Thread.ThreadState.X25, Is.EqualTo(UnicornEmu.X[25]));
|
|
|
|
Assert.That(Thread.ThreadState.X26, Is.EqualTo(UnicornEmu.X[26]));
|
|
|
|
Assert.That(Thread.ThreadState.X27, Is.EqualTo(UnicornEmu.X[27]));
|
|
|
|
Assert.That(Thread.ThreadState.X28, Is.EqualTo(UnicornEmu.X[28]));
|
|
|
|
Assert.That(Thread.ThreadState.X29, Is.EqualTo(UnicornEmu.X[29]));
|
|
|
|
Assert.That(Thread.ThreadState.X30, Is.EqualTo(UnicornEmu.X[30]));
|
2018-09-08 13:23:07 -04:00
|
|
|
|
2018-09-01 10:24:05 -04:00
|
|
|
Assert.That(Thread.ThreadState.X31, Is.EqualTo(UnicornEmu.SP));
|
2018-09-08 13:23:07 -04:00
|
|
|
|
2018-10-05 21:45:59 -04:00
|
|
|
if (FpTolerances == FpTolerances.None)
|
2018-09-17 00:54:05 -04:00
|
|
|
{
|
|
|
|
Assert.That(Thread.ThreadState.V0, Is.EqualTo(UnicornEmu.Q[0]));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-05 21:45:59 -04:00
|
|
|
ManageFpTolerances(FpTolerances);
|
2018-09-17 00:54:05 -04:00
|
|
|
}
|
2018-09-08 13:23:07 -04:00
|
|
|
Assert.That(Thread.ThreadState.V1, Is.EqualTo(UnicornEmu.Q[1]));
|
|
|
|
Assert.That(Thread.ThreadState.V2, Is.EqualTo(UnicornEmu.Q[2]));
|
|
|
|
Assert.That(Thread.ThreadState.V3, Is.EqualTo(UnicornEmu.Q[3]));
|
|
|
|
Assert.That(Thread.ThreadState.V4, Is.EqualTo(UnicornEmu.Q[4]));
|
|
|
|
Assert.That(Thread.ThreadState.V5, Is.EqualTo(UnicornEmu.Q[5]));
|
|
|
|
Assert.That(Thread.ThreadState.V6, Is.EqualTo(UnicornEmu.Q[6]));
|
|
|
|
Assert.That(Thread.ThreadState.V7, Is.EqualTo(UnicornEmu.Q[7]));
|
|
|
|
Assert.That(Thread.ThreadState.V8, Is.EqualTo(UnicornEmu.Q[8]));
|
|
|
|
Assert.That(Thread.ThreadState.V9, Is.EqualTo(UnicornEmu.Q[9]));
|
2018-09-01 10:24:05 -04:00
|
|
|
Assert.That(Thread.ThreadState.V10, Is.EqualTo(UnicornEmu.Q[10]));
|
|
|
|
Assert.That(Thread.ThreadState.V11, Is.EqualTo(UnicornEmu.Q[11]));
|
|
|
|
Assert.That(Thread.ThreadState.V12, Is.EqualTo(UnicornEmu.Q[12]));
|
|
|
|
Assert.That(Thread.ThreadState.V13, Is.EqualTo(UnicornEmu.Q[13]));
|
|
|
|
Assert.That(Thread.ThreadState.V14, Is.EqualTo(UnicornEmu.Q[14]));
|
|
|
|
Assert.That(Thread.ThreadState.V15, Is.EqualTo(UnicornEmu.Q[15]));
|
|
|
|
Assert.That(Thread.ThreadState.V16, Is.EqualTo(UnicornEmu.Q[16]));
|
|
|
|
Assert.That(Thread.ThreadState.V17, Is.EqualTo(UnicornEmu.Q[17]));
|
|
|
|
Assert.That(Thread.ThreadState.V18, Is.EqualTo(UnicornEmu.Q[18]));
|
|
|
|
Assert.That(Thread.ThreadState.V19, Is.EqualTo(UnicornEmu.Q[19]));
|
|
|
|
Assert.That(Thread.ThreadState.V20, Is.EqualTo(UnicornEmu.Q[20]));
|
|
|
|
Assert.That(Thread.ThreadState.V21, Is.EqualTo(UnicornEmu.Q[21]));
|
|
|
|
Assert.That(Thread.ThreadState.V22, Is.EqualTo(UnicornEmu.Q[22]));
|
|
|
|
Assert.That(Thread.ThreadState.V23, Is.EqualTo(UnicornEmu.Q[23]));
|
|
|
|
Assert.That(Thread.ThreadState.V24, Is.EqualTo(UnicornEmu.Q[24]));
|
|
|
|
Assert.That(Thread.ThreadState.V25, Is.EqualTo(UnicornEmu.Q[25]));
|
|
|
|
Assert.That(Thread.ThreadState.V26, Is.EqualTo(UnicornEmu.Q[26]));
|
|
|
|
Assert.That(Thread.ThreadState.V27, Is.EqualTo(UnicornEmu.Q[27]));
|
|
|
|
Assert.That(Thread.ThreadState.V28, Is.EqualTo(UnicornEmu.Q[28]));
|
|
|
|
Assert.That(Thread.ThreadState.V29, Is.EqualTo(UnicornEmu.Q[29]));
|
|
|
|
Assert.That(Thread.ThreadState.V30, Is.EqualTo(UnicornEmu.Q[30]));
|
|
|
|
Assert.That(Thread.ThreadState.V31, Is.EqualTo(UnicornEmu.Q[31]));
|
|
|
|
Assert.That(Thread.ThreadState.V31, Is.EqualTo(UnicornEmu.Q[31]));
|
2018-09-08 13:23:07 -04:00
|
|
|
|
|
|
|
Assert.That(Thread.ThreadState.Fpcr, Is.EqualTo(UnicornEmu.Fpcr));
|
|
|
|
Assert.That(Thread.ThreadState.Fpsr & (int)FpsrMask, Is.EqualTo(UnicornEmu.Fpsr & (int)FpsrMask));
|
|
|
|
|
2018-09-01 10:24:05 -04:00
|
|
|
Assert.That(Thread.ThreadState.Overflow, Is.EqualTo(UnicornEmu.OverflowFlag));
|
2018-09-08 13:23:07 -04:00
|
|
|
Assert.That(Thread.ThreadState.Carry, Is.EqualTo(UnicornEmu.CarryFlag));
|
|
|
|
Assert.That(Thread.ThreadState.Zero, Is.EqualTo(UnicornEmu.ZeroFlag));
|
2018-09-01 10:24:05 -04:00
|
|
|
Assert.That(Thread.ThreadState.Negative, Is.EqualTo(UnicornEmu.NegativeFlag));
|
|
|
|
}
|
|
|
|
|
2018-10-05 21:45:59 -04:00
|
|
|
private void ManageFpSkips(FpSkips FpSkips)
|
|
|
|
{
|
|
|
|
if (FpSkips.HasFlag(FpSkips.IfNaN_S))
|
|
|
|
{
|
|
|
|
if (float.IsNaN(VectorExtractSingle(UnicornEmu.Q[0], (byte)0)))
|
|
|
|
{
|
|
|
|
Assert.Ignore("NaN test.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (FpSkips.HasFlag(FpSkips.IfNaN_D))
|
|
|
|
{
|
|
|
|
if (double.IsNaN(VectorExtractDouble(UnicornEmu.Q[0], (byte)0)))
|
|
|
|
{
|
|
|
|
Assert.Ignore("NaN test.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FpSkips.HasFlag(FpSkips.IfUnderflow))
|
|
|
|
{
|
|
|
|
if ((UnicornEmu.Fpsr & (int)FPSR.UFC) != 0)
|
|
|
|
{
|
|
|
|
Assert.Ignore("Underflow test.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FpSkips.HasFlag(FpSkips.IfOverflow))
|
|
|
|
{
|
|
|
|
if ((UnicornEmu.Fpsr & (int)FPSR.OFC) != 0)
|
|
|
|
{
|
|
|
|
Assert.Ignore("Overflow test.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ManageFpTolerances(FpTolerances FpTolerances)
|
|
|
|
{
|
|
|
|
if (!Is.EqualTo(UnicornEmu.Q[0]).ApplyTo(Thread.ThreadState.V0).IsSuccess)
|
|
|
|
{
|
|
|
|
if (FpTolerances == FpTolerances.UpToOneUlps_S)
|
|
|
|
{
|
|
|
|
if (IsNormalOrSubnormal_S(VectorExtractSingle(UnicornEmu.Q[0], (byte)0)) &&
|
|
|
|
IsNormalOrSubnormal_S(VectorExtractSingle(Thread.ThreadState.V0, (byte)0)))
|
|
|
|
{
|
|
|
|
Assert.That (VectorExtractSingle(Thread.ThreadState.V0, (byte)0),
|
|
|
|
Is.EqualTo(VectorExtractSingle(UnicornEmu.Q[0], (byte)0)).Within(1).Ulps);
|
|
|
|
Assert.That (VectorExtractSingle(Thread.ThreadState.V0, (byte)1),
|
|
|
|
Is.EqualTo(VectorExtractSingle(UnicornEmu.Q[0], (byte)1)).Within(1).Ulps);
|
|
|
|
Assert.That (VectorExtractSingle(Thread.ThreadState.V0, (byte)2),
|
|
|
|
Is.EqualTo(VectorExtractSingle(UnicornEmu.Q[0], (byte)2)).Within(1).Ulps);
|
|
|
|
Assert.That (VectorExtractSingle(Thread.ThreadState.V0, (byte)3),
|
|
|
|
Is.EqualTo(VectorExtractSingle(UnicornEmu.Q[0], (byte)3)).Within(1).Ulps);
|
|
|
|
|
|
|
|
Console.WriteLine(FpTolerances);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Assert.That(Thread.ThreadState.V0, Is.EqualTo(UnicornEmu.Q[0]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FpTolerances == FpTolerances.UpToOneUlps_D)
|
|
|
|
{
|
|
|
|
if (IsNormalOrSubnormal_D(VectorExtractDouble(UnicornEmu.Q[0], (byte)0)) &&
|
|
|
|
IsNormalOrSubnormal_D(VectorExtractDouble(Thread.ThreadState.V0, (byte)0)))
|
|
|
|
{
|
|
|
|
Assert.That (VectorExtractDouble(Thread.ThreadState.V0, (byte)0),
|
|
|
|
Is.EqualTo(VectorExtractDouble(UnicornEmu.Q[0], (byte)0)).Within(1).Ulps);
|
|
|
|
Assert.That (VectorExtractDouble(Thread.ThreadState.V0, (byte)1),
|
|
|
|
Is.EqualTo(VectorExtractDouble(UnicornEmu.Q[0], (byte)1)).Within(1).Ulps);
|
|
|
|
|
|
|
|
Console.WriteLine(FpTolerances);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Assert.That(Thread.ThreadState.V0, Is.EqualTo(UnicornEmu.Q[0]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsNormalOrSubnormal_S(float f) => float.IsNormal(f) || float.IsSubnormal(f);
|
|
|
|
|
|
|
|
bool IsNormalOrSubnormal_D(double d) => double.IsNormal(d) || double.IsSubnormal(d);
|
|
|
|
}
|
|
|
|
|
2018-06-30 11:40:41 -04:00
|
|
|
protected static Vector128<float> MakeVectorE0(double E0)
|
2018-05-11 19:10:27 -04:00
|
|
|
{
|
2018-08-27 02:44:01 -04:00
|
|
|
if (!Sse2.IsSupported)
|
|
|
|
{
|
|
|
|
throw new PlatformNotSupportedException();
|
|
|
|
}
|
|
|
|
|
2018-06-30 11:40:41 -04:00
|
|
|
return Sse.StaticCast<long, float>(Sse2.SetVector128(0, BitConverter.DoubleToInt64Bits(E0)));
|
Add Sse Opt. for Cmeq_V_2D, Cmgt_V_2D (Reg). Add Sse Opt. for Crc32cb, Crc32ch, Crc32cw, Crc32cx. Add 10 simple tests for Fcmgt, Fcmge, Fcmeq, Fcmle, Fcmlt (S, V) (Reg, Zero). Add 2 Cnt_V tests. (#183)
* Add files via upload
* Add files via upload
* Add files via upload
* CPE
* Add EmitSse42Crc32()
* Update CpuTestSimdCmp.cs
* Update Pseudocode.cs
* Update Instructions.cs
* Update CpuTestSimd.cs
* Update Instructions.cs
2018-06-25 21:32:29 -04:00
|
|
|
}
|
2018-05-11 19:10:27 -04:00
|
|
|
|
2018-06-30 11:40:41 -04:00
|
|
|
protected static Vector128<float> MakeVectorE0E1(double E0, double E1)
|
Add Sse Opt. for Cmeq_V_2D, Cmgt_V_2D (Reg). Add Sse Opt. for Crc32cb, Crc32ch, Crc32cw, Crc32cx. Add 10 simple tests for Fcmgt, Fcmge, Fcmeq, Fcmle, Fcmlt (S, V) (Reg, Zero). Add 2 Cnt_V tests. (#183)
* Add files via upload
* Add files via upload
* Add files via upload
* CPE
* Add EmitSse42Crc32()
* Update CpuTestSimdCmp.cs
* Update Pseudocode.cs
* Update Instructions.cs
* Update CpuTestSimd.cs
* Update Instructions.cs
2018-06-25 21:32:29 -04:00
|
|
|
{
|
2018-08-27 02:44:01 -04:00
|
|
|
if (!Sse2.IsSupported)
|
|
|
|
{
|
|
|
|
throw new PlatformNotSupportedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Sse.StaticCast<long, float>(
|
|
|
|
Sse2.SetVector128(BitConverter.DoubleToInt64Bits(E1), BitConverter.DoubleToInt64Bits(E0)));
|
Add Sse Opt. for Cmeq_V_2D, Cmgt_V_2D (Reg). Add Sse Opt. for Crc32cb, Crc32ch, Crc32cw, Crc32cx. Add 10 simple tests for Fcmgt, Fcmge, Fcmeq, Fcmle, Fcmlt (S, V) (Reg, Zero). Add 2 Cnt_V tests. (#183)
* Add files via upload
* Add files via upload
* Add files via upload
* CPE
* Add EmitSse42Crc32()
* Update CpuTestSimdCmp.cs
* Update Pseudocode.cs
* Update Instructions.cs
* Update CpuTestSimd.cs
* Update Instructions.cs
2018-06-25 21:32:29 -04:00
|
|
|
}
|
|
|
|
|
2018-06-30 11:40:41 -04:00
|
|
|
protected static Vector128<float> MakeVectorE1(double E1)
|
Add Sse Opt. for Cmeq_V_2D, Cmgt_V_2D (Reg). Add Sse Opt. for Crc32cb, Crc32ch, Crc32cw, Crc32cx. Add 10 simple tests for Fcmgt, Fcmge, Fcmeq, Fcmle, Fcmlt (S, V) (Reg, Zero). Add 2 Cnt_V tests. (#183)
* Add files via upload
* Add files via upload
* Add files via upload
* CPE
* Add EmitSse42Crc32()
* Update CpuTestSimdCmp.cs
* Update Pseudocode.cs
* Update Instructions.cs
* Update CpuTestSimd.cs
* Update Instructions.cs
2018-06-25 21:32:29 -04:00
|
|
|
{
|
2018-08-27 02:44:01 -04:00
|
|
|
if (!Sse2.IsSupported)
|
|
|
|
{
|
|
|
|
throw new PlatformNotSupportedException();
|
|
|
|
}
|
|
|
|
|
2018-06-30 11:40:41 -04:00
|
|
|
return Sse.StaticCast<long, float>(Sse2.SetVector128(BitConverter.DoubleToInt64Bits(E1), 0));
|
2018-05-11 19:10:27 -04:00
|
|
|
}
|
|
|
|
|
2018-09-17 00:54:05 -04:00
|
|
|
protected static float VectorExtractSingle(Vector128<float> Vector, byte Index)
|
|
|
|
{
|
|
|
|
if (!Sse41.IsSupported)
|
|
|
|
{
|
|
|
|
throw new PlatformNotSupportedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
int Value = Sse41.Extract(Sse.StaticCast<float, int>(Vector), Index);
|
|
|
|
|
|
|
|
return BitConverter.Int32BitsToSingle(Value);
|
|
|
|
}
|
|
|
|
|
Add Sse Opt. for Cmeq_V_2D, Cmgt_V_2D (Reg). Add Sse Opt. for Crc32cb, Crc32ch, Crc32cw, Crc32cx. Add 10 simple tests for Fcmgt, Fcmge, Fcmeq, Fcmle, Fcmlt (S, V) (Reg, Zero). Add 2 Cnt_V tests. (#183)
* Add files via upload
* Add files via upload
* Add files via upload
* CPE
* Add EmitSse42Crc32()
* Update CpuTestSimdCmp.cs
* Update Pseudocode.cs
* Update Instructions.cs
* Update CpuTestSimd.cs
* Update Instructions.cs
2018-06-25 21:32:29 -04:00
|
|
|
protected static double VectorExtractDouble(Vector128<float> Vector, byte Index)
|
2018-05-11 19:10:27 -04:00
|
|
|
{
|
2018-08-27 02:44:01 -04:00
|
|
|
if (!Sse41.IsSupported)
|
|
|
|
{
|
|
|
|
throw new PlatformNotSupportedException();
|
|
|
|
}
|
|
|
|
|
Add Sse Opt. for Cmeq_V_2D, Cmgt_V_2D (Reg). Add Sse Opt. for Crc32cb, Crc32ch, Crc32cw, Crc32cx. Add 10 simple tests for Fcmgt, Fcmge, Fcmeq, Fcmle, Fcmlt (S, V) (Reg, Zero). Add 2 Cnt_V tests. (#183)
* Add files via upload
* Add files via upload
* Add files via upload
* CPE
* Add EmitSse42Crc32()
* Update CpuTestSimdCmp.cs
* Update Pseudocode.cs
* Update Instructions.cs
* Update CpuTestSimd.cs
* Update Instructions.cs
2018-06-25 21:32:29 -04:00
|
|
|
long Value = Sse41.Extract(Sse.StaticCast<float, long>(Vector), Index);
|
|
|
|
|
|
|
|
return BitConverter.Int64BitsToDouble(Value);
|
2018-05-11 19:10:27 -04:00
|
|
|
}
|
|
|
|
|
2018-06-30 11:40:41 -04:00
|
|
|
protected static Vector128<float> MakeVectorE0(ulong E0)
|
2018-05-11 19:10:27 -04:00
|
|
|
{
|
2018-08-27 02:44:01 -04:00
|
|
|
if (!Sse2.IsSupported)
|
|
|
|
{
|
|
|
|
throw new PlatformNotSupportedException();
|
|
|
|
}
|
|
|
|
|
2018-06-30 11:40:41 -04:00
|
|
|
return Sse.StaticCast<ulong, float>(Sse2.SetVector128(0, E0));
|
2018-05-11 19:10:27 -04:00
|
|
|
}
|
|
|
|
|
2018-06-30 11:40:41 -04:00
|
|
|
protected static Vector128<float> MakeVectorE0E1(ulong E0, ulong E1)
|
2018-05-11 19:10:27 -04:00
|
|
|
{
|
2018-08-27 02:44:01 -04:00
|
|
|
if (!Sse2.IsSupported)
|
|
|
|
{
|
|
|
|
throw new PlatformNotSupportedException();
|
|
|
|
}
|
|
|
|
|
2018-06-30 11:40:41 -04:00
|
|
|
return Sse.StaticCast<ulong, float>(Sse2.SetVector128(E1, E0));
|
2018-05-11 19:10:27 -04:00
|
|
|
}
|
|
|
|
|
2018-06-30 11:40:41 -04:00
|
|
|
protected static Vector128<float> MakeVectorE1(ulong E1)
|
2018-05-11 19:10:27 -04:00
|
|
|
{
|
2018-08-27 02:44:01 -04:00
|
|
|
if (!Sse2.IsSupported)
|
|
|
|
{
|
|
|
|
throw new PlatformNotSupportedException();
|
|
|
|
}
|
|
|
|
|
2018-06-30 11:40:41 -04:00
|
|
|
return Sse.StaticCast<ulong, float>(Sse2.SetVector128(E1, 0));
|
2018-05-11 19:10:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected static ulong GetVectorE0(Vector128<float> Vector)
|
|
|
|
{
|
2018-08-27 02:44:01 -04:00
|
|
|
if (!Sse41.IsSupported)
|
|
|
|
{
|
|
|
|
throw new PlatformNotSupportedException();
|
|
|
|
}
|
|
|
|
|
2018-06-30 11:40:41 -04:00
|
|
|
return Sse41.Extract(Sse.StaticCast<float, ulong>(Vector), (byte)0);
|
2018-05-11 19:10:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected static ulong GetVectorE1(Vector128<float> Vector)
|
|
|
|
{
|
2018-08-27 02:44:01 -04:00
|
|
|
if (!Sse41.IsSupported)
|
|
|
|
{
|
|
|
|
throw new PlatformNotSupportedException();
|
|
|
|
}
|
|
|
|
|
2018-06-30 11:40:41 -04:00
|
|
|
return Sse41.Extract(Sse.StaticCast<float, ulong>(Vector), (byte)1);
|
2018-05-11 19:10:27 -04:00
|
|
|
}
|
2018-09-17 00:54:05 -04:00
|
|
|
|
|
|
|
protected static uint GenNormal_S()
|
|
|
|
{
|
|
|
|
uint Rnd;
|
|
|
|
|
2018-10-05 21:45:59 -04:00
|
|
|
do Rnd = TestContext.CurrentContext.Random.NextUInt();
|
|
|
|
while (( Rnd & 0x7F800000u) == 0u ||
|
|
|
|
(~Rnd & 0x7F800000u) == 0u);
|
2018-09-17 00:54:05 -04:00
|
|
|
|
|
|
|
return Rnd;
|
|
|
|
}
|
|
|
|
|
2018-10-05 21:45:59 -04:00
|
|
|
protected static uint GenSubnormal_S()
|
2018-09-17 00:54:05 -04:00
|
|
|
{
|
|
|
|
uint Rnd;
|
|
|
|
|
|
|
|
do Rnd = TestContext.CurrentContext.Random.NextUInt();
|
|
|
|
while ((Rnd & 0x007FFFFFu) == 0u);
|
|
|
|
|
|
|
|
return Rnd & 0x807FFFFFu;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static ulong GenNormal_D()
|
|
|
|
{
|
|
|
|
ulong Rnd;
|
|
|
|
|
2018-10-05 21:45:59 -04:00
|
|
|
do Rnd = TestContext.CurrentContext.Random.NextULong();
|
|
|
|
while (( Rnd & 0x7FF0000000000000ul) == 0ul ||
|
|
|
|
(~Rnd & 0x7FF0000000000000ul) == 0ul);
|
2018-09-17 00:54:05 -04:00
|
|
|
|
|
|
|
return Rnd;
|
|
|
|
}
|
|
|
|
|
2018-10-05 21:45:59 -04:00
|
|
|
protected static ulong GenSubnormal_D()
|
2018-09-17 00:54:05 -04:00
|
|
|
{
|
|
|
|
ulong Rnd;
|
|
|
|
|
|
|
|
do Rnd = TestContext.CurrentContext.Random.NextULong();
|
|
|
|
while ((Rnd & 0x000FFFFFFFFFFFFFul) == 0ul);
|
|
|
|
|
|
|
|
return Rnd & 0x800FFFFFFFFFFFFFul;
|
|
|
|
}
|
2018-02-15 19:04:38 -05:00
|
|
|
}
|
|
|
|
}
|