Add ADDHN{2}, RADDHN{2}, SUBHN{2}, RSUBHN{2} (vector) instructions. Add 8 Tests. (#92)

* Update AOpCodeTable.cs

* Update AInstEmitSimdArithmetic.cs

* Update Pseudocode.cs

* Update Instructions.cs

* Update Bits.cs

* Create CpuTestSimd.cs

* Create CpuTestSimdReg.cs

* Update CpuTestSimd.cs

Provide a better supply of input values for the 20 Simd Tests.

* Update CpuTestSimdReg.cs

Provide a better supply of input values for the 20 Simd Tests.

* Update AOpCodeTable.cs

* Update AInstEmitSimdArithmetic.cs

* Update CpuTestSimd.cs

* Update CpuTestSimdReg.cs
This commit is contained in:
LDj3SNuD 2018-04-20 17:40:15 +02:00 committed by gdkchan
parent 03002f6537
commit 2ccd995cb2
7 changed files with 1410 additions and 17 deletions

View file

@ -1,7 +1,7 @@
// https://github.com/LDj3SNuD/ARM_v8-A_AArch64_Instructions_Tester/blob/master/Tester/Instructions.cs
// https://meriac.github.io/archex/A64_v83A_ISA/index.xml
/* https://meriac.github.io/archex/A64_v83A_ISA/fpsimdindex.xml */
// https://meriac.github.io/archex/A64_v83A_ISA/fpsimdindex.xml
using System.Numerics;
@ -1674,9 +1674,578 @@ namespace Ryujinx.Tests.Cpu.Tester
#endregion
}
/*
internal static class Advanced
internal static class SimdFp
{
#region "Simd"
// https://meriac.github.io/archex/A64_v83A_ISA/abs_advsimd.xml#ABS_asisdmisc_R
public static void Abs_S(Bits size, Bits Rn, Bits Rd)
{
bool U = false;
/* Decode Scalar */
int d = (int)UInt(Rd);
int n = (int)UInt(Rn);
/* if size != '11' then ReservedValue(); */
int esize = 8 << (int)UInt(size);
int datasize = esize;
int elements = 1;
bool neg = (U == true);
/* Operation */
/* CheckFPAdvSIMDEnabled64(); */
Bits result = new Bits(datasize);
Bits operand = V(datasize, n);
BigInteger element;
for (int e = 0; e <= elements - 1; e++)
{
element = SInt(Elem(operand, e, esize));
if (neg)
{
element = -element;
}
else
{
element = Abs(element);
}
Elem(result, e, esize, element.SubBigInteger(esize - 1, 0));
}
V(d, result);
}
// https://meriac.github.io/archex/A64_v83A_ISA/abs_advsimd.xml#ABS_asimdmisc_R
public static void Abs_V(bool Q, Bits size, Bits Rn, Bits Rd)
{
bool U = false;
/* Decode Vector */
int d = (int)UInt(Rd);
int n = (int)UInt(Rn);
/* if size:Q == '110' then ReservedValue(); */
int esize = 8 << (int)UInt(size);
int datasize = (Q ? 128 : 64);
int elements = datasize / esize;
bool neg = (U == true);
/* Operation */
/* CheckFPAdvSIMDEnabled64(); */
Bits result = new Bits(datasize);
Bits operand = V(datasize, n);
BigInteger element;
for (int e = 0; e <= elements - 1; e++)
{
element = SInt(Elem(operand, e, esize));
if (neg)
{
element = -element;
}
else
{
element = Abs(element);
}
Elem(result, e, esize, element.SubBigInteger(esize - 1, 0));
}
V(d, result);
}
// https://meriac.github.io/archex/A64_v83A_ISA/neg_advsimd.xml#NEG_asisdmisc_R
public static void Neg_S(Bits size, Bits Rn, Bits Rd)
{
bool U = true;
/* Decode Scalar */
int d = (int)UInt(Rd);
int n = (int)UInt(Rn);
/* if size != '11' then ReservedValue(); */
int esize = 8 << (int)UInt(size);
int datasize = esize;
int elements = 1;
bool neg = (U == true);
/* Operation */
/* CheckFPAdvSIMDEnabled64(); */
Bits result = new Bits(datasize);
Bits operand = V(datasize, n);
BigInteger element;
for (int e = 0; e <= elements - 1; e++)
{
element = SInt(Elem(operand, e, esize));
if (neg)
{
element = -element;
}
else
{
element = Abs(element);
}
Elem(result, e, esize, element.SubBigInteger(esize - 1, 0));
}
V(d, result);
}
// https://meriac.github.io/archex/A64_v83A_ISA/neg_advsimd.xml#NEG_asimdmisc_R
public static void Neg_V(bool Q, Bits size, Bits Rn, Bits Rd)
{
bool U = true;
/* Decode Vector */
int d = (int)UInt(Rd);
int n = (int)UInt(Rn);
/* if size:Q == '110' then ReservedValue(); */
int esize = 8 << (int)UInt(size);
int datasize = (Q ? 128 : 64);
int elements = datasize / esize;
bool neg = (U == true);
/* Operation */
/* CheckFPAdvSIMDEnabled64(); */
Bits result = new Bits(datasize);
Bits operand = V(datasize, n);
BigInteger element;
for (int e = 0; e <= elements - 1; e++)
{
element = SInt(Elem(operand, e, esize));
if (neg)
{
element = -element;
}
else
{
element = Abs(element);
}
Elem(result, e, esize, element.SubBigInteger(esize - 1, 0));
}
V(d, result);
}
#endregion
#region "SimdReg"
// https://meriac.github.io/archex/A64_v83A_ISA/add_advsimd.xml#ADD_asisdsame_only
public static void Add_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
{
bool U = false;
/* Decode Scalar */
int d = (int)UInt(Rd);
int n = (int)UInt(Rn);
int m = (int)UInt(Rm);
/* if size != '11' then ReservedValue(); */
int esize = 8 << (int)UInt(size);
int datasize = esize;
int elements = 1;
bool sub_op = (U == true);
/* Operation */
/* CheckFPAdvSIMDEnabled64(); */
Bits result = new Bits(datasize);
Bits operand1 = V(datasize, n);
Bits operand2 = V(datasize, m);
Bits element1;
Bits element2;
for (int e = 0; e <= elements - 1; e++)
{
element1 = Elem(operand1, e, esize);
element2 = Elem(operand2, e, esize);
if (sub_op)
{
Elem(result, e, esize, element1 - element2);
}
else
{
Elem(result, e, esize, element1 + element2);
}
}
V(d, result);
}
// https://meriac.github.io/archex/A64_v83A_ISA/add_advsimd.xml#ADD_asimdsame_only
public static void Add_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
{
bool U = false;
/* Decode Vector */
int d = (int)UInt(Rd);
int n = (int)UInt(Rn);
int m = (int)UInt(Rm);
/* if size:Q == '110' then ReservedValue(); */
int esize = 8 << (int)UInt(size);
int datasize = (Q ? 128 : 64);
int elements = datasize / esize;
bool sub_op = (U == true);
/* Operation */
/* CheckFPAdvSIMDEnabled64(); */
Bits result = new Bits(datasize);
Bits operand1 = V(datasize, n);
Bits operand2 = V(datasize, m);
Bits element1;
Bits element2;
for (int e = 0; e <= elements - 1; e++)
{
element1 = Elem(operand1, e, esize);
element2 = Elem(operand2, e, esize);
if (sub_op)
{
Elem(result, e, esize, element1 - element2);
}
else
{
Elem(result, e, esize, element1 + element2);
}
}
V(d, result);
}
// https://meriac.github.io/archex/A64_v83A_ISA/addhn_advsimd.xml
public static void Addhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
{
bool U = false;
bool o1 = false;
/* Decode */
int d = (int)UInt(Rd);
int n = (int)UInt(Rn);
int m = (int)UInt(Rm);
/* if size == '11' then ReservedValue(); */
int esize = 8 << (int)UInt(size);
int datasize = 64;
int part = (int)UInt(Q);
int elements = datasize / esize;
bool sub_op = (o1 == true);
bool round = (U == true);
/* Operation */
/* CheckFPAdvSIMDEnabled64(); */
Bits result = new Bits(datasize);
Bits operand1 = V(2 * datasize, n);
Bits operand2 = V(2 * datasize, m);
BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
Bits sum;
Bits element1;
Bits element2;
for (int e = 0; e <= elements - 1; e++)
{
element1 = Elem(operand1, e, 2 * esize);
element2 = Elem(operand2, e, 2 * esize);
if (sub_op)
{
sum = element1 - element2;
}
else
{
sum = element1 + element2;
}
sum = sum + round_const;
Elem(result, e, esize, sum[2 * esize - 1, esize]);
}
Vpart(d, part, result);
}
// https://meriac.github.io/archex/A64_v83A_ISA/raddhn_advsimd.xml
public static void Raddhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
{
bool U = true;
bool o1 = false;
/* Decode */
int d = (int)UInt(Rd);
int n = (int)UInt(Rn);
int m = (int)UInt(Rm);
/* if size == '11' then ReservedValue(); */
int esize = 8 << (int)UInt(size);
int datasize = 64;
int part = (int)UInt(Q);
int elements = datasize / esize;
bool sub_op = (o1 == true);
bool round = (U == true);
/* Operation */
/* CheckFPAdvSIMDEnabled64(); */
Bits result = new Bits(datasize);
Bits operand1 = V(2 * datasize, n);
Bits operand2 = V(2 * datasize, m);
BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
Bits sum;
Bits element1;
Bits element2;
for (int e = 0; e <= elements - 1; e++)
{
element1 = Elem(operand1, e, 2 * esize);
element2 = Elem(operand2, e, 2 * esize);
if (sub_op)
{
sum = element1 - element2;
}
else
{
sum = element1 + element2;
}
sum = sum + round_const;
Elem(result, e, esize, sum[2 * esize - 1, esize]);
}
Vpart(d, part, result);
}
// https://meriac.github.io/archex/A64_v83A_ISA/rsubhn_advsimd.xml
public static void Rsubhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
{
bool U = true;
bool o1 = true;
/* Decode */
int d = (int)UInt(Rd);
int n = (int)UInt(Rn);
int m = (int)UInt(Rm);
/* if size == '11' then ReservedValue(); */
int esize = 8 << (int)UInt(size);
int datasize = 64;
int part = (int)UInt(Q);
int elements = datasize / esize;
bool sub_op = (o1 == true);
bool round = (U == true);
/* Operation */
/* CheckFPAdvSIMDEnabled64(); */
Bits result = new Bits(datasize);
Bits operand1 = V(2 * datasize, n);
Bits operand2 = V(2 * datasize, m);
BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
Bits sum;
Bits element1;
Bits element2;
for (int e = 0; e <= elements - 1; e++)
{
element1 = Elem(operand1, e, 2 * esize);
element2 = Elem(operand2, e, 2 * esize);
if (sub_op)
{
sum = element1 - element2;
}
else
{
sum = element1 + element2;
}
sum = sum + round_const;
Elem(result, e, esize, sum[2 * esize - 1, esize]);
}
Vpart(d, part, result);
}
// https://meriac.github.io/archex/A64_v83A_ISA/sub_advsimd.xml#SUB_asisdsame_only
public static void Sub_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
{
bool U = true;
/* Decode Scalar */
int d = (int)UInt(Rd);
int n = (int)UInt(Rn);
int m = (int)UInt(Rm);
/* if size != '11' then ReservedValue(); */
int esize = 8 << (int)UInt(size);
int datasize = esize;
int elements = 1;
bool sub_op = (U == true);
/* Operation */
/* CheckFPAdvSIMDEnabled64(); */
Bits result = new Bits(datasize);
Bits operand1 = V(datasize, n);
Bits operand2 = V(datasize, m);
Bits element1;
Bits element2;
for (int e = 0; e <= elements - 1; e++)
{
element1 = Elem(operand1, e, esize);
element2 = Elem(operand2, e, esize);
if (sub_op)
{
Elem(result, e, esize, element1 - element2);
}
else
{
Elem(result, e, esize, element1 + element2);
}
}
V(d, result);
}
// https://meriac.github.io/archex/A64_v83A_ISA/sub_advsimd.xml#SUB_asimdsame_only
public static void Sub_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
{
bool U = true;
/* Decode Vector */
int d = (int)UInt(Rd);
int n = (int)UInt(Rn);
int m = (int)UInt(Rm);
/* if size:Q == '110' then ReservedValue(); */
int esize = 8 << (int)UInt(size);
int datasize = (Q ? 128 : 64);
int elements = datasize / esize;
bool sub_op = (U == true);
/* Operation */
/* CheckFPAdvSIMDEnabled64(); */
Bits result = new Bits(datasize);
Bits operand1 = V(datasize, n);
Bits operand2 = V(datasize, m);
Bits element1;
Bits element2;
for (int e = 0; e <= elements - 1; e++)
{
element1 = Elem(operand1, e, esize);
element2 = Elem(operand2, e, esize);
if (sub_op)
{
Elem(result, e, esize, element1 - element2);
}
else
{
Elem(result, e, esize, element1 + element2);
}
}
V(d, result);
}
// https://meriac.github.io/archex/A64_v83A_ISA/subhn_advsimd.xml
public static void Subhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
{
bool U = false;
bool o1 = true;
/* Decode */
int d = (int)UInt(Rd);
int n = (int)UInt(Rn);
int m = (int)UInt(Rm);
/* if size == '11' then ReservedValue(); */
int esize = 8 << (int)UInt(size);
int datasize = 64;
int part = (int)UInt(Q);
int elements = datasize / esize;
bool sub_op = (o1 == true);
bool round = (U == true);
/* Operation */
/* CheckFPAdvSIMDEnabled64(); */
Bits result = new Bits(datasize);
Bits operand1 = V(2 * datasize, n);
Bits operand2 = V(2 * datasize, m);
BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
Bits sum;
Bits element1;
Bits element2;
for (int e = 0; e <= elements - 1; e++)
{
element1 = Elem(operand1, e, 2 * esize);
element2 = Elem(operand2, e, 2 * esize);
if (sub_op)
{
sum = element1 - element2;
}
else
{
sum = element1 + element2;
}
sum = sum + round_const;
Elem(result, e, esize, sum[2 * esize - 1, esize]);
}
Vpart(d, part, result);
}
#endregion
}
*/
}

View file

@ -70,6 +70,7 @@ namespace Ryujinx.Tests.Cpu.Tester
// ELR_ELx and SPSR_ELx have UNKNOWN values, so that it
// is impossible to return from a reset in an architecturally defined way.
AArch64.ResetGeneralRegisters();
AArch64.ResetSIMDFPRegisters();
AArch64.ResetSpecialRegisters();
}
#endregion
@ -85,6 +86,16 @@ namespace Ryujinx.Tests.Cpu.Tester
}
}
/* #AArch64.ResetSIMDFPRegisters.0 */
public static void ResetSIMDFPRegisters()
{
for (int i = 0; i <= 31; i++)
{
/* V[i] = bits(128) UNKNOWN; */
_V[i].SetAll(false);
}
}
/* #AArch64.ResetSpecialRegisters.0 */
public static void ResetSpecialRegisters()
{
@ -116,8 +127,8 @@ namespace Ryujinx.Tests.Cpu.Tester
default:
case Bits bits when bits == EL1:
SP_EL1 = ZeroExtend(64, value);
break;
/*case Bits bits when bits == EL2:
break;/*
case Bits bits when bits == EL2:
SP_EL2 = ZeroExtend(64, value);
break;
case Bits bits when bits == EL3:
@ -144,8 +155,8 @@ namespace Ryujinx.Tests.Cpu.Tester
return SP_EL0[width - 1, 0];
default:
case Bits bits when bits == EL1:
return SP_EL1[width - 1, 0];
/*case Bits bits when bits == EL2:
return SP_EL1[width - 1, 0];/*
case Bits bits when bits == EL2:
return SP_EL2[width - 1, 0];
case Bits bits when bits == EL3:
return SP_EL3[width - 1, 0];*/
@ -153,6 +164,64 @@ namespace Ryujinx.Tests.Cpu.Tester
}
}
// #impl-aarch64.V.write.1
public static void V(int n, Bits value)
{
/* int width = value.Count; */
/* assert n >= 0 && n <= 31; */
/* assert width IN {8,16,32,64,128}; */
_V[n] = ZeroExtend(128, value);
}
/* #impl-aarch64.V.read.1 */
public static Bits V(int width, int n)
{
/* assert n >= 0 && n <= 31; */
/* assert width IN {8,16,32,64,128}; */
return _V[n][width - 1, 0];
}
/* #impl-aarch64.Vpart.read.2 */
public static Bits Vpart(int width, int n, int part)
{
/* assert n >= 0 && n <= 31; */
/* assert part IN {0, 1}; */
if (part == 0)
{
/* assert width IN {8,16,32,64}; */
return _V[n][width - 1, 0];
}
else
{
/* assert width == 64; */
return _V[n][(width * 2) - 1, width];
}
}
// #impl-aarch64.Vpart.write.2
public static void Vpart(int n, int part, Bits value)
{
int width = value.Count;
/* assert n >= 0 && n <= 31; */
/* assert part IN {0, 1}; */
if (part == 0)
{
/* assert width IN {8,16,32,64}; */
_V[n] = ZeroExtend(128, value);
}
else
{
/* assert width == 64; */
_V[n][(width * 2) - 1, width] = value[width - 1, 0];
}
}
// #impl-aarch64.X.write.1
public static void X(int n, Bits value)
{
@ -214,6 +283,7 @@ namespace Ryujinx.Tests.Cpu.Tester
public static Bits ExtendReg(int N, int reg, ExtendType type, int shift)
{
/* assert shift >= 0 && shift <= 4; */
Bits val = X(N, reg);
bool unsigned;
int len;
@ -384,6 +454,12 @@ namespace Ryujinx.Tests.Cpu.Tester
_R[i] = new Bits(64, false);
}
_V = new Bits[32];
for (int i = 0; i <= 31; i++)
{
_V[i] = new Bits(128, false);
}
SP_EL0 = new Bits(64, false);
SP_EL1 = new Bits(64, false);
@ -437,6 +513,12 @@ namespace Ryujinx.Tests.Cpu.Tester
return (result, carry_out);
}
// #impl-shared.Abs.1
public static BigInteger Abs(BigInteger x)
{
return (x >= 0 ? x : -x);
}
// #impl-shared.CountLeadingSignBits.1
public static int CountLeadingSignBits(Bits x)
{
@ -453,6 +535,26 @@ namespace Ryujinx.Tests.Cpu.Tester
return (N - 1 - HighestSetBit(x));
}
// #impl-shared.Elem.read.3
public static Bits Elem(/*in */Bits vector, int e, int size)
{
/* int N = vector.Count; */
/* assert e >= 0 && (e+1)*size <= N; */
return vector[e * size + size - 1, e * size];
}
// #impl-shared.Elem.write.3
public static void Elem(/*out */Bits vector, int e, int size, Bits value)
{
/* int N = vector.Count; */
/* assert e >= 0 && (e+1)*size <= N; */
vector[(e + 1) * size - 1, e * size] = value;
}
/* */
public static Bits EOR(Bits x, Bits y)
{
@ -855,6 +957,8 @@ namespace Ryujinx.Tests.Cpu.Tester
#region "functions/registers/"
public static readonly Bits[] _R;
public static readonly Bits[] _V;
public static Bits SP_EL0;
public static Bits SP_EL1;
#endregion

View file

@ -15,14 +15,15 @@ namespace Ryujinx.Tests.Cpu.Tester.Types
public Bits(bool[] values) => bits = new BitArray(values);
public Bits(byte[] bytes) => bits = new BitArray(bytes);
public Bits(Bits bits) => this.bits = new BitArray(bits.bits);
private Bits(BitArray bitArray) => bits = new BitArray(bitArray);
public Bits(int length) => bits = new BitArray(length);
public Bits(int length, bool defaultValue) => bits = new BitArray(length, defaultValue);
private Bits(BitArray bitArray) => bits = new BitArray(bitArray);
public Bits(ulong value) => bits = new BitArray(BitConverter.GetBytes(value));
public Bits(uint value) => bits = new BitArray(BitConverter.GetBytes(value));
public Bits(ushort value) => bits = new BitArray(BitConverter.GetBytes(value));
public Bits(byte value) => bits = new BitArray(new byte[1] {value});
private BitArray ToBitArray() => new BitArray(bits);
public ulong ToUInt64()
{
byte[] dst = new byte[8];
@ -39,7 +40,22 @@ namespace Ryujinx.Tests.Cpu.Tester.Types
return BitConverter.ToUInt32(dst,0);
}
private BitArray ToBitArray() => new BitArray(bits);
public ushort ToUInt16()
{
byte[] dst = new byte[2];
bits.CopyTo(dst, 0);
return BitConverter.ToUInt16(dst,0);
}
public byte ToByte()
{
byte[] dst = new byte[1];
bits.CopyTo(dst, 0);
return dst[0];
}
public bool this[int index] // ASL: "<>".
{
@ -166,17 +182,66 @@ namespace Ryujinx.Tests.Cpu.Tester.Types
BigInteger dst;
if (left.Count <= 32)
switch (left.Count)
{
dst = left.ToUInt32() + right;
case 8: dst = left.ToByte() + right; break;
case 16: dst = left.ToUInt16() + right; break;
case 32: dst = left.ToUInt32() + right; break;
case 64: dst = left.ToUInt64() + right; break;
default: throw new ArgumentOutOfRangeException();
}
else if (left.Count <= 64)
return dst.SubBigInteger(left.Count - 1, 0);
}
public static Bits operator +(Bits left, Bits right) // ASL: "+".
{
if (((object)left == null) || ((object)right == null))
{
dst = left.ToUInt64() + right;
throw new ArgumentNullException();
}
else
if (left.Count != right.Count)
{
throw new ArgumentOutOfRangeException();
throw new ArgumentException();
}
BigInteger dst;
switch (left.Count)
{
case 8: dst = left.ToByte() + (BigInteger)right.ToByte(); break;
case 16: dst = left.ToUInt16() + (BigInteger)right.ToUInt16(); break;
case 32: dst = left.ToUInt32() + (BigInteger)right.ToUInt32(); break;
case 64: dst = left.ToUInt64() + (BigInteger)right.ToUInt64(); break;
default: throw new ArgumentOutOfRangeException();
}
return dst.SubBigInteger(left.Count - 1, 0);
}
public static Bits operator -(Bits left, Bits right) // ASL: "-".
{
if (((object)left == null) || ((object)right == null))
{
throw new ArgumentNullException();
}
if (left.Count != right.Count)
{
throw new ArgumentException();
}
BigInteger dst;
switch (left.Count)
{
case 8: dst = left.ToByte() - (BigInteger)right.ToByte(); break;
case 16: dst = left.ToUInt16() - (BigInteger)right.ToUInt16(); break;
case 32: dst = left.ToUInt32() - (BigInteger)right.ToUInt32(); break;
case 64: dst = left.ToUInt64() - (BigInteger)right.ToUInt64(); break;
default: throw new ArgumentOutOfRangeException();
}
return dst.SubBigInteger(left.Count - 1, 0);