Update Bits.cs
This commit is contained in:
parent
e31dcd94c9
commit
44ff85ac88
1 changed files with 73 additions and 8 deletions
|
@ -15,14 +15,15 @@ namespace Ryujinx.Tests.Cpu.Tester.Types
|
||||||
public Bits(bool[] values) => bits = new BitArray(values);
|
public Bits(bool[] values) => bits = new BitArray(values);
|
||||||
public Bits(byte[] bytes) => bits = new BitArray(bytes);
|
public Bits(byte[] bytes) => bits = new BitArray(bytes);
|
||||||
public Bits(Bits bits) => this.bits = new BitArray(bits.bits);
|
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) => bits = new BitArray(length);
|
||||||
public Bits(int length, bool defaultValue) => bits = new BitArray(length, defaultValue);
|
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(ulong value) => bits = new BitArray(BitConverter.GetBytes(value));
|
||||||
public Bits(uint 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(ushort value) => bits = new BitArray(BitConverter.GetBytes(value));
|
||||||
public Bits(byte value) => bits = new BitArray(new byte[1] {value});
|
public Bits(byte value) => bits = new BitArray(new byte[1] {value});
|
||||||
|
|
||||||
|
private BitArray ToBitArray() => new BitArray(bits);
|
||||||
public ulong ToUInt64()
|
public ulong ToUInt64()
|
||||||
{
|
{
|
||||||
byte[] dst = new byte[8];
|
byte[] dst = new byte[8];
|
||||||
|
@ -39,7 +40,22 @@ namespace Ryujinx.Tests.Cpu.Tester.Types
|
||||||
|
|
||||||
return BitConverter.ToUInt32(dst, 0);
|
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: "<>".
|
public bool this[int index] // ASL: "<>".
|
||||||
{
|
{
|
||||||
|
@ -166,17 +182,66 @@ namespace Ryujinx.Tests.Cpu.Tester.Types
|
||||||
|
|
||||||
BigInteger dst;
|
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);
|
||||||
dst = left.ToUInt64() + right;
|
|
||||||
}
|
}
|
||||||
else
|
public static Bits operator +(Bits left, Bits right) // ASL: "+".
|
||||||
{
|
{
|
||||||
throw new ArgumentOutOfRangeException();
|
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);
|
||||||
|
}
|
||||||
|
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);
|
return dst.SubBigInteger(left.Count - 1, 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue