daily update on 20240305 by nitload youmu
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
#if NET5_0_OR_GREATER
|
||||
|
||||
using System.Runtime.Intrinsics;
|
||||
|
||||
#endif
|
||||
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[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);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Write<T>(int index, T value) where T : struct
|
||||
{
|
||||
fixed (Vector4* p = &vec)
|
||||
*((T*)(p) + index) = value;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public string ToString(int sample)
|
||||
{
|
||||
string str = "";
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
str += $"{Convert.ToString(this.Read<byte>(i), sample)} ";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
#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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user