mirror of
https://github.com/creeperlv/SVM.git
synced 2026-01-11 12:59:54 +00:00
Made some basic staff.
This commit is contained in:
216
src/SVM.Core/Data/CompactByte.cs
Normal file
216
src/SVM.Core/Data/CompactByte.cs
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace SVM.Core.Data
|
||||||
|
{
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct CompactByte : INumbericData<CompactByte>
|
||||||
|
{
|
||||||
|
public byte Value;
|
||||||
|
public CompactByte(byte value) { Value = value; }
|
||||||
|
public CompactByte(int value) { Value = (byte)value; }
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactByte Add(CompactByte R)
|
||||||
|
{
|
||||||
|
return new CompactByte(Value + R.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactByte Sub(CompactByte R)
|
||||||
|
{
|
||||||
|
return new CompactByte(Value - R.Value);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactByte Mul(CompactByte R)
|
||||||
|
{
|
||||||
|
return new CompactByte(Value * R.Value);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactByte Div(CompactByte R)
|
||||||
|
{
|
||||||
|
return new CompactByte(Value / R.Value);
|
||||||
|
}
|
||||||
|
public SCVMSimpleResult<CompactByte> AddOF(CompactByte R)
|
||||||
|
{
|
||||||
|
CompactByte result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactByte(Value + R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactByte(Value + R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactByte>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactByte> SubOF(CompactByte R)
|
||||||
|
{
|
||||||
|
CompactByte result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactByte(Value - R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactByte(Value - R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactByte>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactByte> DivOF(CompactByte R)
|
||||||
|
{
|
||||||
|
CompactByte result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactByte(Value / R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactByte(Value / R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactByte>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactByte> MulOF(CompactByte R)
|
||||||
|
{
|
||||||
|
CompactByte result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactByte(Value * R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactByte(Value * R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactByte>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LT(CompactByte R)
|
||||||
|
{
|
||||||
|
return Value < R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GT(CompactByte R)
|
||||||
|
{
|
||||||
|
return Value > R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LE(CompactByte R)
|
||||||
|
{
|
||||||
|
return Value <= R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GE(CompactByte R)
|
||||||
|
{
|
||||||
|
return Value >= R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool EQ(CompactByte R)
|
||||||
|
{
|
||||||
|
return Value == R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool NE(CompactByte R)
|
||||||
|
{
|
||||||
|
return Value != R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactByte> Cast_Byte()
|
||||||
|
{
|
||||||
|
return new CompactByte(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactSByte> Cast_SByte()
|
||||||
|
{
|
||||||
|
return new CompactSByte((sbyte)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactShort> Cast_Short()
|
||||||
|
{
|
||||||
|
return new CompactShort(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactUShort> Cast_UShort()
|
||||||
|
{
|
||||||
|
return new CompactUShort(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactInt> Cast_Int()
|
||||||
|
{
|
||||||
|
return new CompactInt(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactUInt> Cast_UInt()
|
||||||
|
{
|
||||||
|
return new CompactUInt(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactLong> Cast_Long()
|
||||||
|
{
|
||||||
|
return new CompactLong(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactULong> Cast_ULong()
|
||||||
|
{
|
||||||
|
return new CompactULong(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactDouble> Cast_Double()
|
||||||
|
{
|
||||||
|
return new CompactDouble(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactSingle> Cast_Float()
|
||||||
|
{
|
||||||
|
return new CompactSingle(Value);
|
||||||
|
}
|
||||||
|
public unsafe void Write(byte* targetPtr)
|
||||||
|
{
|
||||||
|
targetPtr[0] = Value;
|
||||||
|
}
|
||||||
|
public int SizeOf()
|
||||||
|
{
|
||||||
|
return sizeof(byte);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompactByte Mod(CompactByte R)
|
||||||
|
{
|
||||||
|
return new CompactByte(Value % R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
214
src/SVM.Core/Data/CompactDouble.cs
Normal file
214
src/SVM.Core/Data/CompactDouble.cs
Normal file
@@ -0,0 +1,214 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace SVM.Core.Data
|
||||||
|
{
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct CompactDouble : INumbericData<CompactDouble>
|
||||||
|
{
|
||||||
|
public double Value;
|
||||||
|
public CompactDouble(double value) { Value = value; }
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactDouble Add(CompactDouble R)
|
||||||
|
{
|
||||||
|
return new CompactDouble(Value + R.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactDouble Sub(CompactDouble R)
|
||||||
|
{
|
||||||
|
return new CompactDouble(Value - R.Value);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactDouble Mul(CompactDouble R)
|
||||||
|
{
|
||||||
|
return new CompactDouble(Value * R.Value);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactDouble Div(CompactDouble R)
|
||||||
|
{
|
||||||
|
return new CompactDouble(Value / R.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactDouble> AddOF(CompactDouble R)
|
||||||
|
{
|
||||||
|
CompactDouble result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactDouble(Value + R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactDouble(Value + R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactDouble>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactDouble> SubOF(CompactDouble R)
|
||||||
|
{
|
||||||
|
CompactDouble result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactDouble(Value - R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactDouble(Value - R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactDouble>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactDouble> DivOF(CompactDouble R)
|
||||||
|
{
|
||||||
|
CompactDouble result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactDouble(Value / R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactDouble(Value / R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactDouble>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactDouble> MulOF(CompactDouble R)
|
||||||
|
{
|
||||||
|
CompactDouble result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactDouble(Value * R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactDouble(Value * R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactDouble>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LT(CompactDouble R)
|
||||||
|
{
|
||||||
|
return Value < R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GT(CompactDouble R)
|
||||||
|
{
|
||||||
|
return Value > R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LE(CompactDouble R)
|
||||||
|
{
|
||||||
|
return Value <= R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GE(CompactDouble R)
|
||||||
|
{
|
||||||
|
return Value >= R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool EQ(CompactDouble R)
|
||||||
|
{
|
||||||
|
return Value == R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool NE(CompactDouble R)
|
||||||
|
{
|
||||||
|
return Value != R.Value;
|
||||||
|
}
|
||||||
|
public INumbericData<CompactByte> Cast_Byte()
|
||||||
|
{
|
||||||
|
return new CompactByte((byte)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactSByte> Cast_SByte()
|
||||||
|
{
|
||||||
|
return new CompactSByte((sbyte)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactShort> Cast_Short()
|
||||||
|
{
|
||||||
|
return new CompactShort((short)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactUShort> Cast_UShort()
|
||||||
|
{
|
||||||
|
return new CompactUShort((ushort)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactInt> Cast_Int()
|
||||||
|
{
|
||||||
|
return new CompactInt((int)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactUInt> Cast_UInt()
|
||||||
|
{
|
||||||
|
return new CompactUInt((uint)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactLong> Cast_Long()
|
||||||
|
{
|
||||||
|
return new CompactLong((long)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactULong> Cast_ULong()
|
||||||
|
{
|
||||||
|
return new CompactULong((ulong)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactDouble> Cast_Double()
|
||||||
|
{
|
||||||
|
return new CompactDouble(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactSingle> Cast_Float()
|
||||||
|
{
|
||||||
|
return new CompactSingle((float)Value);
|
||||||
|
}
|
||||||
|
public unsafe void Write(byte* targetPtr)
|
||||||
|
{
|
||||||
|
((double*)targetPtr)[0] = Value;
|
||||||
|
}
|
||||||
|
public int SizeOf()
|
||||||
|
{
|
||||||
|
return sizeof(double);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompactDouble Mod(CompactDouble R)
|
||||||
|
{
|
||||||
|
return new CompactDouble(Value % R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
216
src/SVM.Core/Data/CompactInt.cs
Normal file
216
src/SVM.Core/Data/CompactInt.cs
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
|
||||||
|
namespace SVM.Core.Data
|
||||||
|
{
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct CompactInt : INumbericData<CompactInt>
|
||||||
|
{
|
||||||
|
public int Value;
|
||||||
|
public CompactInt(int value) { Value = value; }
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactInt Add(CompactInt R)
|
||||||
|
{
|
||||||
|
return new CompactInt(Value + R.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactInt Sub(CompactInt R)
|
||||||
|
{
|
||||||
|
return new CompactInt(Value - R.Value);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactInt Mul(CompactInt R)
|
||||||
|
{
|
||||||
|
return new CompactInt(Value * R.Value);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactInt Div(CompactInt R)
|
||||||
|
{
|
||||||
|
return new CompactInt(Value / R.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactInt> AddOF(CompactInt R)
|
||||||
|
{
|
||||||
|
CompactInt result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactInt(Value + R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactInt(Value + R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactInt>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactInt> SubOF(CompactInt R)
|
||||||
|
{
|
||||||
|
CompactInt result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactInt(Value - R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactInt(Value - R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactInt>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactInt> DivOF(CompactInt R)
|
||||||
|
{
|
||||||
|
CompactInt result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactInt(Value / R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactInt(Value / R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactInt>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactInt> MulOF(CompactInt R)
|
||||||
|
{
|
||||||
|
CompactInt result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactInt(Value * R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactInt(Value * R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactInt>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LT(CompactInt R)
|
||||||
|
{
|
||||||
|
return Value < R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GT(CompactInt R)
|
||||||
|
{
|
||||||
|
return Value > R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LE(CompactInt R)
|
||||||
|
{
|
||||||
|
return Value <= R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GE(CompactInt R)
|
||||||
|
{
|
||||||
|
return Value >= R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool EQ(CompactInt R)
|
||||||
|
{
|
||||||
|
return Value == R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool NE(CompactInt R)
|
||||||
|
{
|
||||||
|
return Value != R.Value;
|
||||||
|
}
|
||||||
|
public INumbericData<CompactByte> Cast_Byte()
|
||||||
|
{
|
||||||
|
return new CompactByte((byte)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactSByte> Cast_SByte()
|
||||||
|
{
|
||||||
|
return new CompactSByte((sbyte)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactShort> Cast_Short()
|
||||||
|
{
|
||||||
|
return new CompactShort((short)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactUShort> Cast_UShort()
|
||||||
|
{
|
||||||
|
return new CompactUShort((ushort)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactInt> Cast_Int()
|
||||||
|
{
|
||||||
|
return new CompactInt(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactUInt> Cast_UInt()
|
||||||
|
{
|
||||||
|
return new CompactUInt((uint)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactLong> Cast_Long()
|
||||||
|
{
|
||||||
|
return new CompactLong(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactULong> Cast_ULong()
|
||||||
|
{
|
||||||
|
return new CompactULong((ulong)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactDouble> Cast_Double()
|
||||||
|
{
|
||||||
|
return new CompactDouble(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactSingle> Cast_Float()
|
||||||
|
{
|
||||||
|
return new CompactSingle(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public unsafe void Write(byte* targetPtr)
|
||||||
|
{
|
||||||
|
((int*)targetPtr)[0] = Value;
|
||||||
|
}
|
||||||
|
public int SizeOf()
|
||||||
|
{
|
||||||
|
return sizeof(int);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompactInt Mod(CompactInt R)
|
||||||
|
{
|
||||||
|
return new CompactInt(Value % R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
213
src/SVM.Core/Data/CompactLong.cs
Normal file
213
src/SVM.Core/Data/CompactLong.cs
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace SVM.Core.Data
|
||||||
|
{
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct CompactLong : INumbericData<CompactLong>
|
||||||
|
{
|
||||||
|
public long Value;
|
||||||
|
public CompactLong(long value) { Value = value; }
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactLong Add(CompactLong R)
|
||||||
|
{
|
||||||
|
return new CompactLong(Value + R.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactLong Sub(CompactLong R)
|
||||||
|
{
|
||||||
|
return new CompactLong(Value - R.Value);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactLong Mul(CompactLong R)
|
||||||
|
{
|
||||||
|
return new CompactLong(Value * R.Value);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactLong Div(CompactLong R)
|
||||||
|
{
|
||||||
|
return new CompactLong(Value / R.Value);
|
||||||
|
}
|
||||||
|
public SCVMSimpleResult<CompactLong> AddOF(CompactLong R)
|
||||||
|
{
|
||||||
|
CompactLong result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactLong(Value + R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactLong(Value + R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactLong>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactLong> SubOF(CompactLong R)
|
||||||
|
{
|
||||||
|
CompactLong result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactLong(Value - R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactLong(Value - R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactLong>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactLong> DivOF(CompactLong R)
|
||||||
|
{
|
||||||
|
CompactLong result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactLong(Value / R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactLong(Value / R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactLong>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactLong> MulOF(CompactLong R)
|
||||||
|
{
|
||||||
|
CompactLong result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactLong(Value * R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactLong(Value * R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactLong>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LT(CompactLong R)
|
||||||
|
{
|
||||||
|
return Value < R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GT(CompactLong R)
|
||||||
|
{
|
||||||
|
return Value > R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LE(CompactLong R)
|
||||||
|
{
|
||||||
|
return Value <= R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GE(CompactLong R)
|
||||||
|
{
|
||||||
|
return Value >= R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool EQ(CompactLong R)
|
||||||
|
{
|
||||||
|
return Value == R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool NE(CompactLong R)
|
||||||
|
{
|
||||||
|
return Value != R.Value;
|
||||||
|
}
|
||||||
|
public INumbericData<CompactByte> Cast_Byte()
|
||||||
|
{
|
||||||
|
return new CompactByte((byte)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactSByte> Cast_SByte()
|
||||||
|
{
|
||||||
|
return new CompactSByte((sbyte)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactShort> Cast_Short()
|
||||||
|
{
|
||||||
|
return new CompactShort((short)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactUShort> Cast_UShort()
|
||||||
|
{
|
||||||
|
return new CompactUShort((ushort)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactInt> Cast_Int()
|
||||||
|
{
|
||||||
|
return new CompactInt((int)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactUInt> Cast_UInt()
|
||||||
|
{
|
||||||
|
return new CompactUInt((uint)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactLong> Cast_Long()
|
||||||
|
{
|
||||||
|
return new CompactLong(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactULong> Cast_ULong()
|
||||||
|
{
|
||||||
|
return new CompactULong((ulong)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactDouble> Cast_Double()
|
||||||
|
{
|
||||||
|
return new CompactDouble(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactSingle> Cast_Float()
|
||||||
|
{
|
||||||
|
return new CompactSingle(Value);
|
||||||
|
}
|
||||||
|
public unsafe void Write(byte* targetPtr)
|
||||||
|
{
|
||||||
|
((long*)targetPtr)[0] = Value;
|
||||||
|
}
|
||||||
|
public int SizeOf()
|
||||||
|
{
|
||||||
|
return sizeof(long);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompactLong Mod(CompactLong R)
|
||||||
|
{
|
||||||
|
return new CompactLong(Value % R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
214
src/SVM.Core/Data/CompactSByte.cs
Normal file
214
src/SVM.Core/Data/CompactSByte.cs
Normal file
@@ -0,0 +1,214 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace SVM.Core.Data
|
||||||
|
{
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct CompactSByte : INumbericData<CompactSByte>
|
||||||
|
{
|
||||||
|
public sbyte Value;
|
||||||
|
public CompactSByte(sbyte value) { Value = value; }
|
||||||
|
public CompactSByte(int value) { Value = (sbyte)value; }
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactSByte Add(CompactSByte R)
|
||||||
|
{
|
||||||
|
return new CompactSByte(Value + R.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactSByte Sub(CompactSByte R)
|
||||||
|
{
|
||||||
|
return new CompactSByte(Value - R.Value);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactSByte Mul(CompactSByte R)
|
||||||
|
{
|
||||||
|
return new CompactSByte(Value * R.Value);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactSByte Div(CompactSByte R)
|
||||||
|
{
|
||||||
|
return new CompactSByte(Value / R.Value);
|
||||||
|
}
|
||||||
|
public SCVMSimpleResult<CompactSByte> AddOF(CompactSByte R)
|
||||||
|
{
|
||||||
|
CompactSByte result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactSByte(Value + R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactSByte(Value + R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactSByte>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactSByte> SubOF(CompactSByte R)
|
||||||
|
{
|
||||||
|
CompactSByte result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactSByte(Value - R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactSByte(Value - R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactSByte>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactSByte> DivOF(CompactSByte R)
|
||||||
|
{
|
||||||
|
CompactSByte result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactSByte(Value / R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactSByte(Value / R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactSByte>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactSByte> MulOF(CompactSByte R)
|
||||||
|
{
|
||||||
|
CompactSByte result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactSByte(Value * R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactSByte(Value * R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactSByte>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LT(CompactSByte R)
|
||||||
|
{
|
||||||
|
return Value < R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GT(CompactSByte R)
|
||||||
|
{
|
||||||
|
return Value > R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LE(CompactSByte R)
|
||||||
|
{
|
||||||
|
return Value <= R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GE(CompactSByte R)
|
||||||
|
{
|
||||||
|
return Value >= R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool EQ(CompactSByte R)
|
||||||
|
{
|
||||||
|
return Value == R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool NE(CompactSByte R)
|
||||||
|
{
|
||||||
|
return Value != R.Value;
|
||||||
|
}
|
||||||
|
public INumbericData<CompactByte> Cast_Byte()
|
||||||
|
{
|
||||||
|
return new CompactByte((byte)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactSByte> Cast_SByte()
|
||||||
|
{
|
||||||
|
return new CompactSByte(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactShort> Cast_Short()
|
||||||
|
{
|
||||||
|
return new CompactShort(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactUShort> Cast_UShort()
|
||||||
|
{
|
||||||
|
return new CompactUShort((ushort)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactInt> Cast_Int()
|
||||||
|
{
|
||||||
|
return new CompactInt(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactUInt> Cast_UInt()
|
||||||
|
{
|
||||||
|
return new CompactUInt((uint)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactLong> Cast_Long()
|
||||||
|
{
|
||||||
|
return new CompactLong(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactULong> Cast_ULong()
|
||||||
|
{
|
||||||
|
return new CompactULong((ulong)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactDouble> Cast_Double()
|
||||||
|
{
|
||||||
|
return new CompactDouble(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactSingle> Cast_Float()
|
||||||
|
{
|
||||||
|
return new CompactSingle(Value);
|
||||||
|
}
|
||||||
|
public unsafe void Write(byte* targetPtr)
|
||||||
|
{
|
||||||
|
((sbyte*)targetPtr)[0] = Value;
|
||||||
|
}
|
||||||
|
public int SizeOf()
|
||||||
|
{
|
||||||
|
return sizeof(sbyte);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompactSByte Mod(CompactSByte R)
|
||||||
|
{
|
||||||
|
return new CompactSByte(Value % R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
213
src/SVM.Core/Data/CompactShort.cs
Normal file
213
src/SVM.Core/Data/CompactShort.cs
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace SVM.Core.Data
|
||||||
|
{
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct CompactShort : INumbericData<CompactShort>
|
||||||
|
{
|
||||||
|
public short Value;
|
||||||
|
public CompactShort(short value) { Value = value; }
|
||||||
|
public CompactShort(int value) { Value = (short)value; }
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactShort Add(CompactShort R)
|
||||||
|
{
|
||||||
|
return new CompactShort(Value + R.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactShort Sub(CompactShort R)
|
||||||
|
{
|
||||||
|
return new CompactShort(Value - R.Value);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactShort Mul(CompactShort R)
|
||||||
|
{
|
||||||
|
return new CompactShort(Value * R.Value);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactShort Div(CompactShort R)
|
||||||
|
{
|
||||||
|
return new CompactShort(Value / R.Value);
|
||||||
|
}
|
||||||
|
public SCVMSimpleResult<CompactShort> AddOF(CompactShort R)
|
||||||
|
{
|
||||||
|
CompactShort result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactShort(Value + R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactShort(Value + R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactShort>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactShort> SubOF(CompactShort R)
|
||||||
|
{
|
||||||
|
CompactShort result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactShort(Value - R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactShort(Value - R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactShort>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactShort> DivOF(CompactShort R)
|
||||||
|
{
|
||||||
|
CompactShort result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactShort(Value / R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactShort(Value / R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactShort>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactShort> MulOF(CompactShort R)
|
||||||
|
{
|
||||||
|
CompactShort result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactShort(Value * R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactShort(Value * R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactShort>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LT(CompactShort R)
|
||||||
|
{
|
||||||
|
return Value < R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GT(CompactShort R)
|
||||||
|
{
|
||||||
|
return Value > R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LE(CompactShort R)
|
||||||
|
{
|
||||||
|
return Value <= R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GE(CompactShort R)
|
||||||
|
{
|
||||||
|
return Value >= R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool EQ(CompactShort R)
|
||||||
|
{
|
||||||
|
return Value == R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool NE(CompactShort R)
|
||||||
|
{
|
||||||
|
return Value != R.Value;
|
||||||
|
}
|
||||||
|
public INumbericData<CompactByte> Cast_Byte()
|
||||||
|
{
|
||||||
|
return new CompactByte((byte)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactSByte> Cast_SByte()
|
||||||
|
{
|
||||||
|
return new CompactSByte((sbyte)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactShort> Cast_Short()
|
||||||
|
{
|
||||||
|
return new CompactShort(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactUShort> Cast_UShort()
|
||||||
|
{
|
||||||
|
return new CompactUShort((ushort)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactInt> Cast_Int()
|
||||||
|
{
|
||||||
|
return new CompactInt(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactUInt> Cast_UInt()
|
||||||
|
{
|
||||||
|
return new CompactUInt((uint)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactLong> Cast_Long()
|
||||||
|
{
|
||||||
|
return new CompactLong(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactULong> Cast_ULong()
|
||||||
|
{
|
||||||
|
return new CompactULong((ulong)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactDouble> Cast_Double()
|
||||||
|
{
|
||||||
|
return new CompactDouble(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactSingle> Cast_Float()
|
||||||
|
{
|
||||||
|
return new CompactSingle(Value);
|
||||||
|
}
|
||||||
|
public unsafe void Write(byte* targetPtr)
|
||||||
|
{
|
||||||
|
((short*)targetPtr)[0] = Value;
|
||||||
|
}
|
||||||
|
public int SizeOf()
|
||||||
|
{
|
||||||
|
return sizeof(short);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompactShort Mod(CompactShort R)
|
||||||
|
{
|
||||||
|
return new CompactShort(Value % R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
213
src/SVM.Core/Data/CompactSingle.cs
Normal file
213
src/SVM.Core/Data/CompactSingle.cs
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace SVM.Core.Data
|
||||||
|
{
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct CompactSingle : INumbericData<CompactSingle>
|
||||||
|
{
|
||||||
|
public float Value;
|
||||||
|
public CompactSingle(float value) { Value = value; }
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactSingle Add(CompactSingle R)
|
||||||
|
{
|
||||||
|
return new CompactSingle(Value + R.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactSingle Sub(CompactSingle R)
|
||||||
|
{
|
||||||
|
return new CompactSingle(Value - R.Value);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactSingle Mul(CompactSingle R)
|
||||||
|
{
|
||||||
|
return new CompactSingle(Value * R.Value);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactSingle Div(CompactSingle R)
|
||||||
|
{
|
||||||
|
return new CompactSingle(Value / R.Value);
|
||||||
|
}
|
||||||
|
public SCVMSimpleResult<CompactSingle> AddOF(CompactSingle R)
|
||||||
|
{
|
||||||
|
CompactSingle result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactSingle(Value + R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactSingle(Value + R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactSingle>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactSingle> SubOF(CompactSingle R)
|
||||||
|
{
|
||||||
|
CompactSingle result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactSingle(Value - R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactSingle(Value - R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactSingle>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactSingle> DivOF(CompactSingle R)
|
||||||
|
{
|
||||||
|
CompactSingle result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactSingle(Value / R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactSingle(Value / R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactSingle>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactSingle> MulOF(CompactSingle R)
|
||||||
|
{
|
||||||
|
CompactSingle result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactSingle(Value * R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactSingle(Value * R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactSingle>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LT(CompactSingle R)
|
||||||
|
{
|
||||||
|
return Value < R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GT(CompactSingle R)
|
||||||
|
{
|
||||||
|
return Value > R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LE(CompactSingle R)
|
||||||
|
{
|
||||||
|
return Value <= R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GE(CompactSingle R)
|
||||||
|
{
|
||||||
|
return Value >= R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool EQ(CompactSingle R)
|
||||||
|
{
|
||||||
|
return Value == R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool NE(CompactSingle R)
|
||||||
|
{
|
||||||
|
return Value != R.Value;
|
||||||
|
}
|
||||||
|
public INumbericData<CompactByte> Cast_Byte()
|
||||||
|
{
|
||||||
|
return new CompactByte((byte)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactSByte> Cast_SByte()
|
||||||
|
{
|
||||||
|
return new CompactSByte((sbyte)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactShort> Cast_Short()
|
||||||
|
{
|
||||||
|
return new CompactShort((short)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactUShort> Cast_UShort()
|
||||||
|
{
|
||||||
|
return new CompactUShort((ushort)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactInt> Cast_Int()
|
||||||
|
{
|
||||||
|
return new CompactInt((int)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactUInt> Cast_UInt()
|
||||||
|
{
|
||||||
|
return new CompactUInt((uint)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactLong> Cast_Long()
|
||||||
|
{
|
||||||
|
return new CompactLong((long)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactULong> Cast_ULong()
|
||||||
|
{
|
||||||
|
return new CompactULong((ulong)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactDouble> Cast_Double()
|
||||||
|
{
|
||||||
|
return new CompactDouble(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactSingle> Cast_Float()
|
||||||
|
{
|
||||||
|
return new CompactSingle(Value);
|
||||||
|
}
|
||||||
|
public unsafe void Write(byte* targetPtr)
|
||||||
|
{
|
||||||
|
((float*)targetPtr)[0] = Value;
|
||||||
|
}
|
||||||
|
public int SizeOf()
|
||||||
|
{
|
||||||
|
return sizeof(float);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompactSingle Mod(CompactSingle R)
|
||||||
|
{
|
||||||
|
return new CompactSingle(Value % R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
213
src/SVM.Core/Data/CompactUInt.cs
Normal file
213
src/SVM.Core/Data/CompactUInt.cs
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace SVM.Core.Data
|
||||||
|
{
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct CompactUInt : INumbericData<CompactUInt>
|
||||||
|
{
|
||||||
|
public uint Value;
|
||||||
|
public CompactUInt(uint value) { Value = value; }
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactUInt Add(CompactUInt R)
|
||||||
|
{
|
||||||
|
return new CompactUInt(Value + R.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactUInt Sub(CompactUInt R)
|
||||||
|
{
|
||||||
|
return new CompactUInt(Value - R.Value);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactUInt Mul(CompactUInt R)
|
||||||
|
{
|
||||||
|
return new CompactUInt(Value * R.Value);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactUInt Div(CompactUInt R)
|
||||||
|
{
|
||||||
|
return new CompactUInt(Value / R.Value);
|
||||||
|
}
|
||||||
|
public SCVMSimpleResult<CompactUInt> AddOF(CompactUInt R)
|
||||||
|
{
|
||||||
|
CompactUInt result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactUInt(Value + R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactUInt(Value + R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactUInt>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactUInt> SubOF(CompactUInt R)
|
||||||
|
{
|
||||||
|
CompactUInt result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactUInt(Value - R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactUInt(Value - R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactUInt>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactUInt> DivOF(CompactUInt R)
|
||||||
|
{
|
||||||
|
CompactUInt result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactUInt(Value / R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactUInt(Value / R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactUInt>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactUInt> MulOF(CompactUInt R)
|
||||||
|
{
|
||||||
|
CompactUInt result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactUInt(Value * R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactUInt(Value * R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactUInt>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LT(CompactUInt R)
|
||||||
|
{
|
||||||
|
return Value < R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GT(CompactUInt R)
|
||||||
|
{
|
||||||
|
return Value > R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LE(CompactUInt R)
|
||||||
|
{
|
||||||
|
return Value <= R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GE(CompactUInt R)
|
||||||
|
{
|
||||||
|
return Value >= R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool EQ(CompactUInt R)
|
||||||
|
{
|
||||||
|
return Value == R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool NE(CompactUInt R)
|
||||||
|
{
|
||||||
|
return Value != R.Value;
|
||||||
|
}
|
||||||
|
public INumbericData<CompactByte> Cast_Byte()
|
||||||
|
{
|
||||||
|
return new CompactByte((byte)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactSByte> Cast_SByte()
|
||||||
|
{
|
||||||
|
return new CompactSByte((sbyte)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactShort> Cast_Short()
|
||||||
|
{
|
||||||
|
return new CompactShort((short)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactUShort> Cast_UShort()
|
||||||
|
{
|
||||||
|
return new CompactUShort((ushort)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactInt> Cast_Int()
|
||||||
|
{
|
||||||
|
return new CompactInt((int)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactUInt> Cast_UInt()
|
||||||
|
{
|
||||||
|
return new CompactUInt(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactLong> Cast_Long()
|
||||||
|
{
|
||||||
|
return new CompactLong(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactULong> Cast_ULong()
|
||||||
|
{
|
||||||
|
return new CompactULong(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactDouble> Cast_Double()
|
||||||
|
{
|
||||||
|
return new CompactDouble(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactSingle> Cast_Float()
|
||||||
|
{
|
||||||
|
return new CompactSingle(Value);
|
||||||
|
}
|
||||||
|
public unsafe void Write(byte* targetPtr)
|
||||||
|
{
|
||||||
|
((uint*)targetPtr)[0] = Value;
|
||||||
|
}
|
||||||
|
public int SizeOf()
|
||||||
|
{
|
||||||
|
return sizeof(uint);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompactUInt Mod(CompactUInt R)
|
||||||
|
{
|
||||||
|
return new CompactUInt(Value % R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
213
src/SVM.Core/Data/CompactULong.cs
Normal file
213
src/SVM.Core/Data/CompactULong.cs
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace SVM.Core.Data
|
||||||
|
{
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct CompactULong : INumbericData<CompactULong>
|
||||||
|
{
|
||||||
|
public ulong Value;
|
||||||
|
public CompactULong(ulong value) { Value = value; }
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactULong Add(CompactULong R)
|
||||||
|
{
|
||||||
|
return new CompactULong(Value + R.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactULong Sub(CompactULong R)
|
||||||
|
{
|
||||||
|
return new CompactULong(Value - R.Value);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactULong Mul(CompactULong R)
|
||||||
|
{
|
||||||
|
return new CompactULong(Value * R.Value);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactULong Div(CompactULong R)
|
||||||
|
{
|
||||||
|
return new CompactULong(Value / R.Value);
|
||||||
|
}
|
||||||
|
public SCVMSimpleResult<CompactULong> AddOF(CompactULong R)
|
||||||
|
{
|
||||||
|
CompactULong result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactULong(Value + R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactULong(Value + R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactULong>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactULong> SubOF(CompactULong R)
|
||||||
|
{
|
||||||
|
CompactULong result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactULong(Value - R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactULong(Value - R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactULong>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactULong> DivOF(CompactULong R)
|
||||||
|
{
|
||||||
|
CompactULong result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactULong(Value / R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactULong(Value / R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactULong>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactULong> MulOF(CompactULong R)
|
||||||
|
{
|
||||||
|
CompactULong result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactULong(Value * R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactULong(Value * R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactULong>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LT(CompactULong R)
|
||||||
|
{
|
||||||
|
return Value < R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GT(CompactULong R)
|
||||||
|
{
|
||||||
|
return Value > R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LE(CompactULong R)
|
||||||
|
{
|
||||||
|
return Value <= R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GE(CompactULong R)
|
||||||
|
{
|
||||||
|
return Value >= R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool EQ(CompactULong R)
|
||||||
|
{
|
||||||
|
return Value == R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool NE(CompactULong R)
|
||||||
|
{
|
||||||
|
return Value != R.Value;
|
||||||
|
}
|
||||||
|
public INumbericData<CompactByte> Cast_Byte()
|
||||||
|
{
|
||||||
|
return new CompactByte((byte)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactSByte> Cast_SByte()
|
||||||
|
{
|
||||||
|
return new CompactSByte((sbyte)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactShort> Cast_Short()
|
||||||
|
{
|
||||||
|
return new CompactShort((short)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactUShort> Cast_UShort()
|
||||||
|
{
|
||||||
|
return new CompactUShort((ushort)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactInt> Cast_Int()
|
||||||
|
{
|
||||||
|
return new CompactInt((int)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactUInt> Cast_UInt()
|
||||||
|
{
|
||||||
|
return new CompactUInt((uint)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactLong> Cast_Long()
|
||||||
|
{
|
||||||
|
return new CompactLong((long)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactULong> Cast_ULong()
|
||||||
|
{
|
||||||
|
return new CompactULong(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactDouble> Cast_Double()
|
||||||
|
{
|
||||||
|
return new CompactDouble(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactSingle> Cast_Float()
|
||||||
|
{
|
||||||
|
return new CompactSingle(Value);
|
||||||
|
}
|
||||||
|
public unsafe void Write(byte* targetPtr)
|
||||||
|
{
|
||||||
|
((ulong*)targetPtr)[0] = Value;
|
||||||
|
}
|
||||||
|
public int SizeOf()
|
||||||
|
{
|
||||||
|
return sizeof(ulong);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompactULong Mod(CompactULong R)
|
||||||
|
{
|
||||||
|
return new CompactULong(Value % R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
216
src/SVM.Core/Data/CompactUShort.cs
Normal file
216
src/SVM.Core/Data/CompactUShort.cs
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace SVM.Core.Data
|
||||||
|
{
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct CompactUShort : INumbericData<CompactUShort>
|
||||||
|
{
|
||||||
|
public ushort Value;
|
||||||
|
public CompactUShort(ushort value) { Value = value; }
|
||||||
|
public CompactUShort(int value) { Value = (ushort)value; }
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactUShort Add(CompactUShort R)
|
||||||
|
{
|
||||||
|
return new CompactUShort(Value + R.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactUShort Sub(CompactUShort R)
|
||||||
|
{
|
||||||
|
return new CompactUShort(Value - R.Value);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactUShort Mul(CompactUShort R)
|
||||||
|
{
|
||||||
|
return new CompactUShort(Value * R.Value);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public CompactUShort Div(CompactUShort R)
|
||||||
|
{
|
||||||
|
return new CompactUShort(Value / R.Value);
|
||||||
|
}
|
||||||
|
public SCVMSimpleResult<CompactUShort> AddOF(CompactUShort R)
|
||||||
|
{
|
||||||
|
CompactUShort result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactUShort(Value + R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactUShort(Value + R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactUShort>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactUShort> SubOF(CompactUShort R)
|
||||||
|
{
|
||||||
|
CompactUShort result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactUShort(Value - R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactUShort(Value - R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactUShort>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactUShort> DivOF(CompactUShort R)
|
||||||
|
{
|
||||||
|
CompactUShort result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactUShort(Value / R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactUShort(Value / R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactUShort>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCVMSimpleResult<CompactUShort> MulOF(CompactUShort R)
|
||||||
|
{
|
||||||
|
CompactUShort result = default;
|
||||||
|
bool IsOF = false;
|
||||||
|
checked
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = new CompactUShort(Value * R.Value);
|
||||||
|
}
|
||||||
|
catch (System.Exception)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
IsOF = true;
|
||||||
|
result = new CompactUShort(Value * R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SCVMSimpleResult<CompactUShort>(IsOF, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LT(CompactUShort R)
|
||||||
|
{
|
||||||
|
return Value < R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GT(CompactUShort R)
|
||||||
|
{
|
||||||
|
return Value > R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LE(CompactUShort R)
|
||||||
|
{
|
||||||
|
return Value <= R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GE(CompactUShort R)
|
||||||
|
{
|
||||||
|
return Value >= R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool EQ(CompactUShort R)
|
||||||
|
{
|
||||||
|
return Value == R.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool NE(CompactUShort R)
|
||||||
|
{
|
||||||
|
return Value != R.Value;
|
||||||
|
}
|
||||||
|
public INumbericData<CompactByte> Cast_Byte()
|
||||||
|
{
|
||||||
|
return new CompactByte((byte)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactSByte> Cast_SByte()
|
||||||
|
{
|
||||||
|
return new CompactSByte((sbyte)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactShort> Cast_Short()
|
||||||
|
{
|
||||||
|
return new CompactShort((short)Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactUShort> Cast_UShort()
|
||||||
|
{
|
||||||
|
return new CompactUShort(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactInt> Cast_Int()
|
||||||
|
{
|
||||||
|
return new CompactInt(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactUInt> Cast_UInt()
|
||||||
|
{
|
||||||
|
return new CompactUInt(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactLong> Cast_Long()
|
||||||
|
{
|
||||||
|
return new CompactLong(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactULong> Cast_ULong()
|
||||||
|
{
|
||||||
|
return new CompactULong(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactDouble> Cast_Double()
|
||||||
|
{
|
||||||
|
return new CompactDouble(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public INumbericData<CompactSingle> Cast_Float()
|
||||||
|
{
|
||||||
|
return new CompactSingle(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public unsafe void Write(byte* targetPtr)
|
||||||
|
{
|
||||||
|
((ushort*)targetPtr)[0] = Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int SizeOf()
|
||||||
|
{
|
||||||
|
return sizeof(ushort);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompactUShort Mod(CompactUShort R)
|
||||||
|
{
|
||||||
|
return new CompactUShort(Value % R.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
68
src/SVM.Core/Data/INumberData.cs
Normal file
68
src/SVM.Core/Data/INumberData.cs
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SVM.Core.Data
|
||||||
|
{
|
||||||
|
public interface INumbericData<T> : IPointerWritable where T : unmanaged
|
||||||
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
T Add(T R);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
T Sub(T R);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
T Mul(T R);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
T Div(T R);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
T Mod(T R);
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
SCVMSimpleResult<T> AddOF(T R);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
SCVMSimpleResult<T> SubOF(T R);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
SCVMSimpleResult<T> DivOF(T R);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
SCVMSimpleResult<T> MulOF(T R);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
bool LT(T R);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
bool GT(T R);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
bool LE(T R);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
bool GE(T R);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
bool EQ(T R);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
bool NE(T R);
|
||||||
|
INumbericData<CompactByte> Cast_Byte();
|
||||||
|
INumbericData<CompactSByte> Cast_SByte();
|
||||||
|
INumbericData<CompactShort> Cast_Short();
|
||||||
|
INumbericData<CompactUShort> Cast_UShort();
|
||||||
|
INumbericData<CompactInt> Cast_Int();
|
||||||
|
INumbericData<CompactUInt> Cast_UInt();
|
||||||
|
INumbericData<CompactLong> Cast_Long();
|
||||||
|
INumbericData<CompactULong> Cast_ULong();
|
||||||
|
INumbericData<CompactDouble> Cast_Double();
|
||||||
|
INumbericData<CompactSingle> Cast_Float();
|
||||||
|
}
|
||||||
|
public unsafe interface IPointerWritable
|
||||||
|
{
|
||||||
|
public void Write(byte* targetPtr);
|
||||||
|
public int SizeOf();
|
||||||
|
}
|
||||||
|
public struct SCVMSimpleResult<T> where T : unmanaged
|
||||||
|
{
|
||||||
|
public bool IsSuccess;
|
||||||
|
public T Value;
|
||||||
|
|
||||||
|
public SCVMSimpleResult(bool isSuccess, T value)
|
||||||
|
{
|
||||||
|
IsSuccess = isSuccess;
|
||||||
|
Value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
284
src/SVM.Core/FuncImpl/MathImpl.cs
Normal file
284
src/SVM.Core/FuncImpl/MathImpl.cs
Normal file
@@ -0,0 +1,284 @@
|
|||||||
|
using SVM.Core.Data;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
namespace SVM.Core.FuncImpl
|
||||||
|
{
|
||||||
|
public static unsafe class MathImpl
|
||||||
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static void MathAdd(Registers register, MState* state, SVMNativeTypes Type, int L, int R, int T, bool CheckOF)
|
||||||
|
{
|
||||||
|
switch (Type)
|
||||||
|
{
|
||||||
|
case SVMNativeTypes.Int8:
|
||||||
|
GenericAdd<CompactSByte>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Int16:
|
||||||
|
GenericAdd<CompactShort>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Int32:
|
||||||
|
GenericAdd<CompactInt>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Int64:
|
||||||
|
GenericAdd<CompactLong>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.UInt8:
|
||||||
|
GenericAdd<CompactByte>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.UInt16:
|
||||||
|
GenericAdd<CompactUShort>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.UInt32:
|
||||||
|
GenericAdd<CompactUInt>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.UInt64:
|
||||||
|
GenericAdd<CompactULong>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Float:
|
||||||
|
GenericAdd<CompactSingle>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Double:
|
||||||
|
GenericAdd<CompactDouble>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static void MathSub(Registers register, MState* state, SVMNativeTypes Type, int L, int R, int T, bool CheckOF)
|
||||||
|
{
|
||||||
|
switch (Type)
|
||||||
|
{
|
||||||
|
case SVMNativeTypes.Int8:
|
||||||
|
GenericSub<CompactSByte>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Int16:
|
||||||
|
GenericSub<CompactShort>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Int32:
|
||||||
|
GenericSub<CompactInt>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Int64:
|
||||||
|
GenericSub<CompactLong>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.UInt8:
|
||||||
|
GenericSub<CompactByte>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.UInt16:
|
||||||
|
GenericSub<CompactUShort>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.UInt32:
|
||||||
|
GenericSub<CompactUInt>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.UInt64:
|
||||||
|
GenericSub<CompactULong>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Float:
|
||||||
|
GenericSub<CompactSingle>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Double:
|
||||||
|
GenericSub<CompactDouble>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static void MathMod(Registers register, MState* state, SVMNativeTypes Type, int L, int R, int T)
|
||||||
|
{
|
||||||
|
switch (Type)
|
||||||
|
{
|
||||||
|
case SVMNativeTypes.Int8:
|
||||||
|
GenericMod<CompactSByte>(register, state, L, R, T);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Int16:
|
||||||
|
GenericMod<CompactShort>(register, state, L, R, T);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Int32:
|
||||||
|
GenericMod<CompactInt>(register, state, L, R, T);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Int64:
|
||||||
|
GenericMod<CompactLong>(register, state, L, R, T);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.UInt8:
|
||||||
|
GenericMod<CompactByte>(register, state, L, R, T);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.UInt16:
|
||||||
|
GenericMod<CompactUShort>(register, state, L, R, T);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.UInt32:
|
||||||
|
GenericMod<CompactUInt>(register, state, L, R, T);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.UInt64:
|
||||||
|
GenericMod<CompactULong>(register, state, L, R, T);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Float:
|
||||||
|
GenericMod<CompactSingle>(register, state, L, R, T);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Double:
|
||||||
|
GenericMod<CompactDouble>(register, state, L, R, T);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static void MathMul(Registers register, MState* state, SVMNativeTypes Type, int L, int R, int T, bool CheckOF)
|
||||||
|
{
|
||||||
|
switch (Type)
|
||||||
|
{
|
||||||
|
case SVMNativeTypes.Int8:
|
||||||
|
GenericMul<CompactSByte>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Int16:
|
||||||
|
GenericMul<CompactShort>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Int32:
|
||||||
|
GenericMul<CompactInt>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Int64:
|
||||||
|
GenericMul<CompactLong>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.UInt8:
|
||||||
|
GenericMul<CompactByte>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.UInt16:
|
||||||
|
GenericMul<CompactUShort>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.UInt32:
|
||||||
|
GenericMul<CompactUInt>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.UInt64:
|
||||||
|
GenericMul<CompactULong>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Float:
|
||||||
|
GenericMul<CompactSingle>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Double:
|
||||||
|
GenericMul<CompactDouble>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static void MathDiv(Registers register, MState* state, SVMNativeTypes Type, int L, int R, int T, bool CheckOF)
|
||||||
|
{
|
||||||
|
switch (Type)
|
||||||
|
{
|
||||||
|
case SVMNativeTypes.Int8:
|
||||||
|
GenericDiv<CompactSByte>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Int16:
|
||||||
|
GenericDiv<CompactShort>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Int32:
|
||||||
|
GenericDiv<CompactInt>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Int64:
|
||||||
|
GenericDiv<CompactLong>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.UInt8:
|
||||||
|
GenericDiv<CompactByte>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.UInt16:
|
||||||
|
GenericDiv<CompactUShort>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.UInt32:
|
||||||
|
GenericDiv<CompactUInt>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.UInt64:
|
||||||
|
GenericDiv<CompactULong>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Float:
|
||||||
|
GenericDiv<CompactSingle>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
case SVMNativeTypes.Double:
|
||||||
|
GenericDiv<CompactDouble>(register, state, L, R, T, CheckOF);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static void GenericAdd<N>(Registers Register, MState* state, int L, int R, int T, bool CheckOF) where N : unmanaged, INumbericData<N>
|
||||||
|
{
|
||||||
|
var LN = Register.GetData<N>(L);
|
||||||
|
var RN = Register.GetData<N>(R);
|
||||||
|
N TN = default;
|
||||||
|
if (CheckOF)
|
||||||
|
{
|
||||||
|
var result = LN.AddOF(RN);
|
||||||
|
TN = result.Value;
|
||||||
|
state->OF = (byte)(result.IsSuccess ? 0 : 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TN = LN.Add(RN);
|
||||||
|
}
|
||||||
|
Register.SetData(T, TN);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static void GenericSub<N>(Registers Register, MState* state, int L, int R, int T, bool CheckOF) where N : unmanaged, INumbericData<N>
|
||||||
|
{
|
||||||
|
var LN = Register.GetData<N>(L);
|
||||||
|
var RN = Register.GetData<N>(R);
|
||||||
|
N TN = default;
|
||||||
|
if (CheckOF)
|
||||||
|
{
|
||||||
|
var result = LN.SubOF(RN);
|
||||||
|
TN = result.Value;
|
||||||
|
state->OF = (byte)(result.IsSuccess ? 0 : 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TN = LN.Sub(RN);
|
||||||
|
}
|
||||||
|
Register.SetData<N>(T, TN);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static void GenericMul<N>(Registers Register, MState* state, int L, int R, int T, bool CheckOF) where N : unmanaged, INumbericData<N>
|
||||||
|
{
|
||||||
|
var LN = Register.GetData<N>(L);
|
||||||
|
var RN = Register.GetData<N>(R);
|
||||||
|
N TN = default;
|
||||||
|
if (CheckOF)
|
||||||
|
{
|
||||||
|
var result = LN.MulOF(RN);
|
||||||
|
TN = result.Value;
|
||||||
|
state->OF = (byte)(result.IsSuccess ? 0 : 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TN = LN.Mul(RN);
|
||||||
|
}
|
||||||
|
Register.SetData<N>(T, TN);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static void GenericDiv<N>(Registers Register, MState* state, int L, int R, int T, bool CheckOF) where N : unmanaged, INumbericData<N>
|
||||||
|
{
|
||||||
|
var LN = Register.GetData<N>(L);
|
||||||
|
var RN = Register.GetData<N>(R);
|
||||||
|
N TN = default;
|
||||||
|
if (CheckOF)
|
||||||
|
{
|
||||||
|
var result = LN.DivOF(RN);
|
||||||
|
TN = result.Value;
|
||||||
|
state->OF = (byte)(result.IsSuccess ? 0 : 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TN = LN.Div(RN);
|
||||||
|
}
|
||||||
|
Register.SetData<N>(T, TN);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static void GenericMod<N>(Registers Register, MState* state, int L, int R, int T) where N : unmanaged, INumbericData<N>
|
||||||
|
{
|
||||||
|
var LN = Register.GetData<N>(L);
|
||||||
|
var RN = Register.GetData<N>(R);
|
||||||
|
Register.SetData<N>(T, LN.Mod(RN));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
41
src/SVM.Core/Registers.cs
Normal file
41
src/SVM.Core/Registers.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using SVM.Core.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using static SVM.Core.stdc.stdlib;
|
||||||
|
namespace SVM.Core
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Offset 0 is always 0.
|
||||||
|
/// </summary>
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct Registers : IDisposable
|
||||||
|
{
|
||||||
|
IntPtr Data;
|
||||||
|
uint Size;
|
||||||
|
public void Init(uint size)
|
||||||
|
{
|
||||||
|
Size = size;
|
||||||
|
Data = malloc(size);
|
||||||
|
}
|
||||||
|
public T ReadData<T>(int RegisterID) where T : unmanaged
|
||||||
|
{
|
||||||
|
if (RegisterID == 0) return default;
|
||||||
|
return Data.GetDataWithOffsetInBytes<T>(RegisterID * sizeof(Int64));
|
||||||
|
}
|
||||||
|
public T GetData<T>(int RegisterID) where T : unmanaged
|
||||||
|
{
|
||||||
|
if (RegisterID == 0) return default;
|
||||||
|
return Data.GetDataWithOffsetInBytes<T>(RegisterID * sizeof(Int64));
|
||||||
|
}
|
||||||
|
public unsafe void SetData<T>(int offset, T d) where T : unmanaged
|
||||||
|
{
|
||||||
|
if (offset == 0) return;
|
||||||
|
if (offset + sizeof(T) > Size) return;
|
||||||
|
((T*)(Data + offset))[0] = d;
|
||||||
|
}
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
free(Data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,24 +1,31 @@
|
|||||||
namespace SVM.Core
|
namespace SVM.Core
|
||||||
{
|
{
|
||||||
public enum SVMInst : byte
|
public enum SVMInstDef : byte
|
||||||
{
|
{
|
||||||
|
// 0 1 2 3 4 5 6
|
||||||
|
// Math [I]Op [I]Type [R]L [R]R [R]T [I]CheckOF
|
||||||
|
BMath,
|
||||||
// 0 1 2 3 4
|
// 0 1 2 3 4
|
||||||
// Add [I]Type [R]L [R]R [R]T
|
// Math [I]Op [I]Type [R]L [R]T
|
||||||
Add,
|
UMath,
|
||||||
Sub,
|
//0 1 2 3 4
|
||||||
Mul,
|
//Cvt [I]SType [I]TType [I]S [I]T
|
||||||
Div,
|
Cvt,
|
||||||
Mod,
|
|
||||||
// Set Conditional Register to 1 if condition met.
|
// Set Conditional Register to 1 if condition met.
|
||||||
// 0 1 2 3 4
|
// 0 1 2 3 4
|
||||||
// Cmp [R]Op [R]L [R]R [R]T
|
// Cmp [R]Op [R]L [R]R [R]T
|
||||||
Cmp,
|
Cmp,
|
||||||
|
//Set Data to Register
|
||||||
|
//SD T
|
||||||
|
//Data (64-bit)
|
||||||
|
SD,
|
||||||
|
|
||||||
// 0 1
|
// 0 1
|
||||||
// JAL RD
|
// JAL RD
|
||||||
// [I]Address (int32)
|
// [I]Address (int32)
|
||||||
JAL,
|
JAL,
|
||||||
// Jump And Link If Conditional Register is set.
|
// Jump And Link If Conditional Register is set.
|
||||||
// JALF RD
|
// JALF RD FlagID
|
||||||
// [I]Address (int32)
|
// [I]Address (int32)
|
||||||
JALF,
|
JALF,
|
||||||
// 0 1 2 3
|
// 0 1 2 3
|
||||||
@@ -31,15 +38,20 @@
|
|||||||
Call,
|
Call,
|
||||||
// Return
|
// Return
|
||||||
Return,
|
Return,
|
||||||
// System
|
// System [I]CallID (uint32)
|
||||||
// [I]CallID (uint64)
|
|
||||||
System,
|
System,
|
||||||
// 0 1 2 3 4 5
|
// 0 1 2 3 4 5
|
||||||
// SIMD Op [R]LAddr [R]RAddr [R]TAddr [R]Len
|
// SIMD Op [R]LAddr [R]RAddr [R]TAddr [R]Len
|
||||||
SIMD,
|
SIMD,
|
||||||
// 0 1 2 3 4
|
//0 1 2
|
||||||
// AdvMath Op [R]L [R]R [R]T
|
//Alloc [R]Size [R]Pointer
|
||||||
AdvMath,
|
Alloc,
|
||||||
|
//0 1 2 3
|
||||||
|
//Alloc [R]Size [R]SPointer [R]TPointer
|
||||||
|
Realloc,
|
||||||
|
//0 1
|
||||||
|
//Alloc [R]Pointer
|
||||||
|
Free,
|
||||||
}
|
}
|
||||||
public enum CmpOperator : byte
|
public enum CmpOperator : byte
|
||||||
{
|
{
|
||||||
@@ -58,6 +70,11 @@
|
|||||||
Float,
|
Float,
|
||||||
Double,
|
Double,
|
||||||
}
|
}
|
||||||
|
public enum ConditionFlag
|
||||||
|
{
|
||||||
|
Cmp,
|
||||||
|
Of,
|
||||||
|
}
|
||||||
public enum SIMDOperator : byte
|
public enum SIMDOperator : byte
|
||||||
{
|
{
|
||||||
Add,
|
Add,
|
||||||
@@ -65,4 +82,20 @@
|
|||||||
Mul,
|
Mul,
|
||||||
Div,
|
Div,
|
||||||
}
|
}
|
||||||
|
public enum BMathOp : byte
|
||||||
|
{
|
||||||
|
Add,
|
||||||
|
Sub,
|
||||||
|
Mul,
|
||||||
|
Div,
|
||||||
|
Mod,
|
||||||
|
}
|
||||||
|
public enum UMathOp : byte
|
||||||
|
{
|
||||||
|
Sin,
|
||||||
|
Cos,
|
||||||
|
Tan,
|
||||||
|
Log,
|
||||||
|
Sqrt
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,85 +1,291 @@
|
|||||||
using System;
|
using SVM.Core.FuncImpl;
|
||||||
using static SVM.Core.stdc.stdlib;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using SVM.Core.Utils;
|
using SVM.Core.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using static SVM.Core.stdc.stdlib;
|
||||||
namespace SVM.Core
|
namespace SVM.Core
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Memory Layout:
|
||||||
|
/// <br/>
|
||||||
|
/// Index 0 - Program.<br/>
|
||||||
|
/// Index 1 - GPMemory:<br/>
|
||||||
|
/// Offset |Length |Usage<br/>
|
||||||
|
/// 0 |StackLength | Stack
|
||||||
|
/// </summary>
|
||||||
public unsafe class SimpleVirtualMachine : IDisposable
|
public unsafe class SimpleVirtualMachine : IDisposable
|
||||||
{
|
{
|
||||||
public Registers registers;
|
public Registers registers;
|
||||||
public MemoryBlock Stack;
|
public MemoryBlock Stack;
|
||||||
public MemoryBlock* GPMemory;
|
public List<MemoryBlock> Memories = new List<MemoryBlock>();
|
||||||
public SVMConfig? Config = null;
|
public SVMConfig? Config = null;
|
||||||
public void Init(uint StackSize = 1024 * 1024, uint RegisterSize = 512)
|
public MState MachineState;
|
||||||
|
public SVMProgram* Program = null;
|
||||||
|
public static uint InitGPMemorySize = 696320;
|
||||||
|
public void Init(uint StackSize = 1024 * 1024, uint RegisterSize = 512, uint GPMemory = uint.MaxValue)
|
||||||
{
|
{
|
||||||
GPMemory = null;
|
registers.Init(RegisterSize);
|
||||||
|
|
||||||
|
uint SPOffset = 2;
|
||||||
|
if (Config != null)
|
||||||
|
{
|
||||||
|
SPOffset = Config.SPRegisterID;
|
||||||
|
}
|
||||||
|
if (GPMemory == 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (GPMemory == uint.MaxValue)
|
||||||
|
{
|
||||||
|
GPMemory = InitGPMemorySize;
|
||||||
|
}
|
||||||
|
MemoryBlock block = new MemoryBlock();
|
||||||
|
block.Init(GPMemory);
|
||||||
|
SetMemory(1, block);
|
||||||
|
registers.SetData<SVMPointer>((int)SPOffset, new SVMPointer() { index = 1, offset = 0 });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void Step()
|
public void Step()
|
||||||
{
|
{
|
||||||
uint SPOffset = 4;
|
uint SPOffset = 2;
|
||||||
uint PCOffset = 0;
|
uint PCOffset = 1;
|
||||||
|
uint ErrorIDOffset = 3;
|
||||||
if (Config != null)
|
if (Config != null)
|
||||||
{
|
{
|
||||||
SPOffset = Config.SPRegisterOffset;
|
SPOffset = Config.SPRegisterID;
|
||||||
PCOffset = Config.PCRegisterOffset;
|
PCOffset = Config.PCRegisterID;
|
||||||
|
ErrorIDOffset = Config.EIDRegisterID;
|
||||||
}
|
}
|
||||||
}
|
if (Program == null) return;
|
||||||
public void SetGPMemory(MemoryBlock* ptr)
|
var PC = registers.GetData<ulong>((int)PCOffset);
|
||||||
|
if (PC >= Program->InstructionCount) return;
|
||||||
|
var currentInstPtr = GetPointer(PC);
|
||||||
|
var Instruction = currentInstPtr.GetData<SVMInstruction>();
|
||||||
|
var def = Instruction.GetDef();
|
||||||
|
fixed (MState* statePtr = &MachineState)
|
||||||
{
|
{
|
||||||
GPMemory = ptr;
|
|
||||||
|
switch (def)
|
||||||
|
{
|
||||||
|
case SVMInstDef.BMath:
|
||||||
|
{
|
||||||
|
var Op = Instruction.GetData<BMathOp>(1);
|
||||||
|
var NativeType = Instruction.GetData<SVMNativeTypes>(2);
|
||||||
|
var L = Instruction.GetData<byte>(3);
|
||||||
|
var R = Instruction.GetData<byte>(4);
|
||||||
|
var T = Instruction.GetData<byte>(5);
|
||||||
|
var Of = Instruction.GetData<byte>(6);
|
||||||
|
switch (Op)
|
||||||
|
{
|
||||||
|
case BMathOp.Add:
|
||||||
|
MathImpl.MathAdd(registers, statePtr, NativeType, L, R, T, Of == 1);
|
||||||
|
break;
|
||||||
|
case BMathOp.Sub:
|
||||||
|
MathImpl.MathSub(registers, statePtr, NativeType, L, R, T, Of == 1);
|
||||||
|
break;
|
||||||
|
case BMathOp.Mul:
|
||||||
|
MathImpl.MathMul(registers, statePtr, NativeType, L, R, T, Of == 1);
|
||||||
|
break;
|
||||||
|
case BMathOp.Div:
|
||||||
|
MathImpl.MathDiv(registers, statePtr, NativeType, L, R, T, Of == 1);
|
||||||
|
break;
|
||||||
|
case BMathOp.Mod:
|
||||||
|
MathImpl.MathMod(registers, statePtr, NativeType, L, R, T);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SVMInstDef.UMath:
|
||||||
|
break;
|
||||||
|
case SVMInstDef.Cvt:
|
||||||
|
break;
|
||||||
|
case SVMInstDef.Cmp:
|
||||||
|
break;
|
||||||
|
case SVMInstDef.SD:
|
||||||
|
{
|
||||||
|
var Reg = Instruction.GetData<byte>(1);
|
||||||
|
PC++;
|
||||||
|
var dataPtr = GetPointer(PC);
|
||||||
|
var data = currentInstPtr.GetData<ulong>();
|
||||||
|
registers.SetData(Reg, data);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SVMInstDef.JAL:
|
||||||
|
break;
|
||||||
|
case SVMInstDef.JALF:
|
||||||
|
break;
|
||||||
|
case SVMInstDef.Load:
|
||||||
|
break;
|
||||||
|
case SVMInstDef.Save:
|
||||||
|
break;
|
||||||
|
case SVMInstDef.Call:
|
||||||
|
break;
|
||||||
|
case SVMInstDef.Return:
|
||||||
|
break;
|
||||||
|
case SVMInstDef.System:
|
||||||
|
if (Config != null)
|
||||||
|
{
|
||||||
|
var target = Instruction.GetData<uint>(1);
|
||||||
|
if (Config.FuncCalls.TryGetValue(target, out var func))
|
||||||
|
{
|
||||||
|
func(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SVMInstDef.SIMD:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PC++;
|
||||||
|
registers.SetData<ulong>((int)PCOffset, PC);
|
||||||
|
}
|
||||||
|
public IntPtr GetPointer(ulong PC)
|
||||||
|
{
|
||||||
|
return GetPointer(new SVMPointer() { offset = (uint)PC, index = 0 });
|
||||||
|
}
|
||||||
|
public IntPtr GetPointer(SVMPointer absoluteAddress)
|
||||||
|
{
|
||||||
|
if (absoluteAddress.index == 0)
|
||||||
|
{
|
||||||
|
ulong offset0 = 0;
|
||||||
|
ulong offset1 = 0;
|
||||||
|
|
||||||
|
if (Program != null)
|
||||||
|
{
|
||||||
|
offset0 = Program->InstructionCount * (ulong)sizeof(SVMInstruction);
|
||||||
|
offset1 = Program->DataSize;
|
||||||
|
if (absoluteAddress.offset < offset0)
|
||||||
|
{
|
||||||
|
|
||||||
|
return IntPtr.Add((IntPtr)Program->instructions, (int)absoluteAddress.offset);
|
||||||
|
}
|
||||||
|
else if (absoluteAddress.offset < offset1)
|
||||||
|
{
|
||||||
|
return IntPtr.Add((IntPtr)Program->instructions, (int)(absoluteAddress.offset - offset0));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var realIndex = absoluteAddress.index - 1;
|
||||||
|
if (realIndex < Memories.Count)
|
||||||
|
{
|
||||||
|
return IntPtr.Add(Memories[(int)realIndex].StartAddress, (int)absoluteAddress.offset);
|
||||||
|
|
||||||
|
}
|
||||||
|
return IntPtr.Zero;
|
||||||
|
}
|
||||||
|
public MemoryBlock SetMemory(int id, MemoryBlock block)
|
||||||
|
{
|
||||||
|
var realID = id - 1;
|
||||||
|
if (id < Memories.Count)
|
||||||
|
{
|
||||||
|
var old = Memories[(int)realID];
|
||||||
|
Memories[(int)realID] = block;
|
||||||
|
return old;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var count = realID - Memories.Count;
|
||||||
|
for (int i = 0; i <= count; i++)
|
||||||
|
{
|
||||||
|
Memories.Add(default);
|
||||||
|
}
|
||||||
|
Memories[(int)realID] = block;
|
||||||
|
return default;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
registers.Dispose();
|
registers.Dispose();
|
||||||
Stack.Dispose();
|
Stack.Dispose();
|
||||||
|
foreach (var item in Memories)
|
||||||
|
{
|
||||||
|
item.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct SVMPointer
|
||||||
|
{
|
||||||
|
public uint offset;
|
||||||
|
public uint index;
|
||||||
|
}
|
||||||
public class SVMConfig
|
public class SVMConfig
|
||||||
{
|
{
|
||||||
public Dictionary<uint, FuncCall> FuncCalls = new Dictionary<uint, FuncCall>();
|
public Dictionary<uint, FuncCall> FuncCalls = new Dictionary<uint, FuncCall>();
|
||||||
public uint SPRegisterOffset;
|
public uint SPRegisterID;
|
||||||
public uint PCRegisterOffset;
|
public uint PCRegisterID;
|
||||||
|
/// <summary>
|
||||||
|
/// Error ID Register.
|
||||||
|
/// </summary>
|
||||||
|
public uint EIDRegisterID;
|
||||||
|
}
|
||||||
|
public unsafe struct SVMProgram
|
||||||
|
{
|
||||||
|
public UInt64 InstructionCount;
|
||||||
|
public UInt64 DataSize;
|
||||||
|
public SVMInstruction* instructions;
|
||||||
|
public byte* data;
|
||||||
|
public static SVMProgram* LoadFromStream(Stream stream)
|
||||||
|
{
|
||||||
|
var program = (SVMProgram*)malloc(sizeof(SVMProgram));
|
||||||
|
|
||||||
|
return program;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public delegate void FuncCall(SimpleVirtualMachine machine);
|
public delegate void FuncCall(SimpleVirtualMachine machine);
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public struct MState
|
public struct MState
|
||||||
{
|
{
|
||||||
public uint PC;
|
public byte OF;
|
||||||
}
|
}
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public struct MemoryBlock : IDisposable
|
public struct MemoryBlock : IDisposable
|
||||||
{
|
{
|
||||||
public IntPtr StartAddress;
|
public IntPtr StartAddress;
|
||||||
public int Size;
|
public uint Size;
|
||||||
|
public void Init(uint Size)
|
||||||
|
{
|
||||||
|
this.Size = Size;
|
||||||
|
StartAddress = malloc(Size);
|
||||||
|
}
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
free(StartAddress);
|
free(StartAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public struct Registers : IDisposable
|
|
||||||
{
|
|
||||||
IntPtr Data;
|
|
||||||
public void Init(int size)
|
|
||||||
{
|
|
||||||
Data = malloc((uint)size);
|
|
||||||
}
|
|
||||||
public T ReadData<T>(int RegisterID) where T : unmanaged
|
|
||||||
{
|
|
||||||
return Data.GetDataWithOffsetInBytes<T>(RegisterID * sizeof(Int64));
|
|
||||||
}
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
free(Data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct Callframe
|
public struct Callframe
|
||||||
{
|
{
|
||||||
public int PC;
|
public ulong PC;
|
||||||
public uint SP;
|
public ulong SP;
|
||||||
|
}
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public unsafe struct SVMInstruction
|
||||||
|
{
|
||||||
|
public ulong data;
|
||||||
|
public T GetData<T>(int offset) where T : unmanaged
|
||||||
|
{
|
||||||
|
fixed (ulong* dataPtr = &data)
|
||||||
|
{
|
||||||
|
return ((T*)(((byte*)dataPtr) + offset))[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public SVMInstDef GetDef()
|
||||||
|
{
|
||||||
|
fixed (ulong* dataPtr = &data)
|
||||||
|
{
|
||||||
|
return ((SVMInstDef*)dataPtr)[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ namespace SVM.Core.stdc
|
|||||||
{
|
{
|
||||||
return Marshal.AllocHGlobal((int)size);
|
return Marshal.AllocHGlobal((int)size);
|
||||||
}
|
}
|
||||||
|
public static IntPtr malloc(int size)
|
||||||
|
{
|
||||||
|
return Marshal.AllocHGlobal(size);
|
||||||
|
}
|
||||||
public static IntPtr realloc(IntPtr ptr, uint size)
|
public static IntPtr realloc(IntPtr ptr, uint size)
|
||||||
{
|
{
|
||||||
return Marshal.ReAllocHGlobal(ptr, (IntPtr)size);
|
return Marshal.ReAllocHGlobal(ptr, (IntPtr)size);
|
||||||
|
|||||||
Reference in New Issue
Block a user