2018-02-23 12:29:20 +00:00
|
|
|
using ChocolArm64;
|
2018-02-16 00:04:38 +00:00
|
|
|
using ChocolArm64.Memory;
|
|
|
|
using ChocolArm64.State;
|
2018-06-18 18:55:26 +01:00
|
|
|
|
2018-02-16 00:04:38 +00:00
|
|
|
using NUnit.Framework;
|
2018-06-18 18:55:26 +01:00
|
|
|
|
2018-05-12 00:10:27 +01:00
|
|
|
using System;
|
2018-08-15 19:59:51 +01:00
|
|
|
using System.Runtime.InteropServices;
|
2018-05-12 00:10:27 +01:00
|
|
|
using System.Runtime.Intrinsics;
|
|
|
|
using System.Runtime.Intrinsics.X86;
|
2018-06-11 01:46:42 +01:00
|
|
|
using System.Threading;
|
2018-02-16 00:04:38 +00:00
|
|
|
|
|
|
|
namespace Ryujinx.Tests.Cpu
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2018-02-23 12:29:20 +00:00
|
|
|
public class CpuTest
|
2018-02-16 00:04:38 +00:00
|
|
|
{
|
2018-02-23 12:29:20 +00:00
|
|
|
protected long Position { get; private set; }
|
|
|
|
private long Size;
|
|
|
|
|
|
|
|
private long EntryPoint;
|
|
|
|
|
2018-08-15 19:59:51 +01:00
|
|
|
private IntPtr RamPointer;
|
|
|
|
|
2018-02-23 12:29:20 +00:00
|
|
|
private AMemory Memory;
|
|
|
|
private AThread Thread;
|
2018-02-16 00:04:38 +00:00
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
2018-02-23 12:29:20 +00:00
|
|
|
Position = 0x0;
|
|
|
|
Size = 0x1000;
|
|
|
|
|
|
|
|
EntryPoint = Position;
|
|
|
|
|
2018-02-26 01:14:58 +00:00
|
|
|
ATranslator Translator = new ATranslator();
|
2018-08-15 19:59:51 +01:00
|
|
|
RamPointer = Marshal.AllocHGlobal(new IntPtr(Size));
|
|
|
|
Memory = new AMemory(RamPointer);
|
|
|
|
Memory.Map(Position, 0, Size);
|
2018-03-12 04:04:52 +00:00
|
|
|
Thread = new AThread(Translator, Memory, EntryPoint);
|
2018-02-16 00:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
public void Teardown()
|
|
|
|
{
|
2018-08-15 19:59:51 +01:00
|
|
|
Marshal.FreeHGlobal(RamPointer);
|
2018-02-23 12:29:20 +00:00
|
|
|
Memory = null;
|
2018-06-18 18:55:26 +01:00
|
|
|
Thread = null;
|
2018-02-16 00:04:38 +00:00
|
|
|
}
|
|
|
|
|
2018-02-23 12:29:20 +00:00
|
|
|
protected void Reset()
|
2018-02-16 00:04:38 +00:00
|
|
|
{
|
2018-02-23 12:29:20 +00:00
|
|
|
Teardown();
|
|
|
|
Setup();
|
2018-02-16 00:04:38 +00:00
|
|
|
}
|
|
|
|
|
2018-02-23 12:29:20 +00:00
|
|
|
protected void Opcode(uint Opcode)
|
2018-02-16 00:04:38 +00:00
|
|
|
{
|
2018-08-15 19:59:51 +01:00
|
|
|
Thread.Memory.WriteUInt32(Position, Opcode);
|
2018-02-23 12:29:20 +00:00
|
|
|
Position += 4;
|
|
|
|
}
|
2018-02-16 00:04:38 +00:00
|
|
|
|
2018-04-18 21:22:45 +01:00
|
|
|
protected void SetThreadState(ulong X0 = 0, ulong X1 = 0, ulong X2 = 0, ulong X3 = 0, ulong X31 = 0,
|
2018-05-12 00:10:27 +01:00
|
|
|
Vector128<float> V0 = default(Vector128<float>),
|
|
|
|
Vector128<float> V1 = default(Vector128<float>),
|
|
|
|
Vector128<float> V2 = default(Vector128<float>),
|
2018-04-30 00:39:58 +01:00
|
|
|
bool Overflow = false, bool Carry = false, bool Zero = false, bool Negative = false,
|
|
|
|
int Fpcr = 0x0, int Fpsr = 0x0)
|
2018-02-23 12:29:20 +00:00
|
|
|
{
|
2018-02-18 19:28:07 +00:00
|
|
|
Thread.ThreadState.X0 = X0;
|
|
|
|
Thread.ThreadState.X1 = X1;
|
|
|
|
Thread.ThreadState.X2 = X2;
|
2018-04-18 21:22:45 +01:00
|
|
|
Thread.ThreadState.X3 = X3;
|
2018-02-25 01:50:58 +00:00
|
|
|
Thread.ThreadState.X31 = X31;
|
2018-02-18 19:28:07 +00:00
|
|
|
Thread.ThreadState.V0 = V0;
|
|
|
|
Thread.ThreadState.V1 = V1;
|
|
|
|
Thread.ThreadState.V2 = V2;
|
2018-02-23 14:53:32 +00:00
|
|
|
Thread.ThreadState.Overflow = Overflow;
|
|
|
|
Thread.ThreadState.Carry = Carry;
|
|
|
|
Thread.ThreadState.Zero = Zero;
|
|
|
|
Thread.ThreadState.Negative = Negative;
|
2018-03-05 12:21:19 +00:00
|
|
|
Thread.ThreadState.Fpcr = Fpcr;
|
2018-04-30 00:39:58 +01:00
|
|
|
Thread.ThreadState.Fpsr = Fpsr;
|
2018-02-23 12:29:20 +00: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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected AThreadState GetThreadState()
|
|
|
|
{
|
2018-02-18 19:28:07 +00:00
|
|
|
return Thread.ThreadState;
|
2018-02-16 00:04:38 +00:00
|
|
|
}
|
|
|
|
|
2018-02-23 12:29:20 +00:00
|
|
|
protected AThreadState SingleOpcode(uint Opcode,
|
2018-04-18 21:22:45 +01:00
|
|
|
ulong X0 = 0, ulong X1 = 0, ulong X2 = 0, ulong X3 = 0, ulong X31 = 0,
|
2018-05-12 00:10:27 +01:00
|
|
|
Vector128<float> V0 = default(Vector128<float>),
|
|
|
|
Vector128<float> V1 = default(Vector128<float>),
|
|
|
|
Vector128<float> V2 = default(Vector128<float>),
|
2018-04-30 00:39:58 +01:00
|
|
|
bool Overflow = false, bool Carry = false, bool Zero = false, bool Negative = false,
|
|
|
|
int Fpcr = 0x0, int Fpsr = 0x0)
|
2018-02-16 00:04:38 +00:00
|
|
|
{
|
2018-02-23 12:29:20 +00:00
|
|
|
this.Opcode(Opcode);
|
|
|
|
this.Opcode(0xD4200000); // BRK #0
|
|
|
|
this.Opcode(0xD65F03C0); // RET
|
2018-04-30 00:39:58 +01:00
|
|
|
SetThreadState(X0, X1, X2, X3, X31, V0, V1, V2, Overflow, Carry, Zero, Negative, Fpcr, Fpsr);
|
2018-02-23 12:29:20 +00:00
|
|
|
ExecuteOpcodes();
|
|
|
|
|
|
|
|
return GetThreadState();
|
2018-02-16 00:04:38 +00:00
|
|
|
}
|
2018-05-12 00:10:27 +01:00
|
|
|
|
2018-06-30 16:40:41 +01:00
|
|
|
protected static Vector128<float> MakeVectorE0(double E0)
|
2018-05-12 00:10:27 +01:00
|
|
|
{
|
2018-06-30 16:40:41 +01: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-26 02:32:29 +01:00
|
|
|
}
|
2018-05-12 00:10:27 +01:00
|
|
|
|
2018-06-30 16:40:41 +01: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-26 02:32:29 +01:00
|
|
|
{
|
2018-06-30 16:40:41 +01:00
|
|
|
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-26 02:32:29 +01:00
|
|
|
}
|
|
|
|
|
2018-06-30 16:40:41 +01: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-26 02:32:29 +01:00
|
|
|
{
|
2018-06-30 16:40:41 +01:00
|
|
|
return Sse.StaticCast<long, float>(Sse2.SetVector128(BitConverter.DoubleToInt64Bits(E1), 0));
|
2018-05-12 00:10:27 +01:00
|
|
|
}
|
|
|
|
|
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-26 02:32:29 +01:00
|
|
|
protected static double VectorExtractDouble(Vector128<float> Vector, byte Index)
|
2018-05-12 00:10:27 +01:00
|
|
|
{
|
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-26 02:32:29 +01:00
|
|
|
long Value = Sse41.Extract(Sse.StaticCast<float, long>(Vector), Index);
|
|
|
|
|
|
|
|
return BitConverter.Int64BitsToDouble(Value);
|
2018-05-12 00:10:27 +01:00
|
|
|
}
|
|
|
|
|
2018-06-30 16:40:41 +01:00
|
|
|
protected static Vector128<float> MakeVectorE0(ulong E0)
|
2018-05-12 00:10:27 +01:00
|
|
|
{
|
2018-06-30 16:40:41 +01:00
|
|
|
return Sse.StaticCast<ulong, float>(Sse2.SetVector128(0, E0));
|
2018-05-12 00:10:27 +01:00
|
|
|
}
|
|
|
|
|
2018-06-30 16:40:41 +01:00
|
|
|
protected static Vector128<float> MakeVectorE0E1(ulong E0, ulong E1)
|
2018-05-12 00:10:27 +01:00
|
|
|
{
|
2018-06-30 16:40:41 +01:00
|
|
|
return Sse.StaticCast<ulong, float>(Sse2.SetVector128(E1, E0));
|
2018-05-12 00:10:27 +01:00
|
|
|
}
|
|
|
|
|
2018-06-30 16:40:41 +01:00
|
|
|
protected static Vector128<float> MakeVectorE1(ulong E1)
|
2018-05-12 00:10:27 +01:00
|
|
|
{
|
2018-06-30 16:40:41 +01:00
|
|
|
return Sse.StaticCast<ulong, float>(Sse2.SetVector128(E1, 0));
|
2018-05-12 00:10:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected static ulong GetVectorE0(Vector128<float> Vector)
|
|
|
|
{
|
2018-06-30 16:40:41 +01:00
|
|
|
return Sse41.Extract(Sse.StaticCast<float, ulong>(Vector), (byte)0);
|
2018-05-12 00:10:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected static ulong GetVectorE1(Vector128<float> Vector)
|
|
|
|
{
|
2018-06-30 16:40:41 +01:00
|
|
|
return Sse41.Extract(Sse.StaticCast<float, ulong>(Vector), (byte)1);
|
2018-05-12 00:10:27 +01:00
|
|
|
}
|
2018-02-16 00:04:38 +00:00
|
|
|
}
|
|
|
|
}
|