aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Tests/Cpu/Tester/Types
diff options
context:
space:
mode:
Diffstat (limited to 'Ryujinx.Tests/Cpu/Tester/Types')
-rw-r--r--Ryujinx.Tests/Cpu/Tester/Types/Bits.cs81
1 files changed, 73 insertions, 8 deletions
diff --git a/Ryujinx.Tests/Cpu/Tester/Types/Bits.cs b/Ryujinx.Tests/Cpu/Tester/Types/Bits.cs
index f4ee966c..30d63264 100644
--- a/Ryujinx.Tests/Cpu/Tester/Types/Bits.cs
+++ b/Ryujinx.Tests/Cpu/Tester/Types/Bits.cs
@@ -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);