117 lines
3.5 KiB
C#
117 lines
3.5 KiB
C#
using System;
|
|
using System.Numerics;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Runtime.InteropServices;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace StgSharp.Data
|
|
{
|
|
[StructLayout(LayoutKind.Explicit, Pack = 16)]
|
|
public unsafe struct M128
|
|
{
|
|
|
|
[FieldOffset(0)] internal Vector4 vec;
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public T Read<T>(int index) where T : struct
|
|
{
|
|
fixed (Vector4* p = &vec)
|
|
{
|
|
return *(((T*)p) + index);
|
|
}
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
public string ToString(int sample)
|
|
{
|
|
string str = string.Empty;
|
|
for (int i = 15; i >= 0; i--)
|
|
{
|
|
str += $"{Convert.ToString(this.Read<byte>(i), sample)} ";
|
|
}
|
|
return str;
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public void Write<T>(int index, T value) where T : struct
|
|
#if NET8_0_OR_GREATER
|
|
, INumber
|
|
#endif
|
|
{
|
|
fixed (Vector4* p = &vec)
|
|
{
|
|
*(((T*)p) + index) = value;
|
|
}
|
|
}
|
|
|
|
#if NET5_0_OR_GREATER
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static explicit operator Vector128<byte>(M128 m)
|
|
{
|
|
return Vector128.As<float, byte>(m.vec.AsVector128());
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static explicit operator Vector128<sbyte>(M128 m)
|
|
{
|
|
return Vector128.As<float, sbyte>(m.vec.AsVector128());
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static explicit operator Vector128<short>(M128 m)
|
|
{
|
|
return Vector128.As<float, short>(m.vec.AsVector128());
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static explicit operator Vector128<ushort>(M128 m)
|
|
{
|
|
return Vector128.As<float, ushort>(m.vec.AsVector128());
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static explicit operator Vector128<int>(M128 m)
|
|
{
|
|
return Vector128.As<float, int>(m.vec.AsVector128());
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static explicit operator Vector128<uint>(M128 m)
|
|
{
|
|
return Vector128.As<float, uint>(m.vec.AsVector128());
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static explicit operator Vector128<long>(M128 m)
|
|
{
|
|
return Vector128.As<float, long>(m.vec.AsVector128());
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static explicit operator Vector128<ulong>(M128 m)
|
|
{
|
|
return Vector128.As<float, ulong>(m.vec.AsVector128());
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static explicit operator Vector128<float>(M128 m)
|
|
{
|
|
return Vector128.As<float, float>(m.vec.AsVector128());
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static explicit operator Vector128<double>(M128 m)
|
|
{
|
|
return Vector128.As<float, double>(m.vec.AsVector128());
|
|
}
|
|
|
|
#endif
|
|
}
|
|
}
|