daily update on 20240305 by nitload youmu

This commit is contained in:
YoumuLiu
2024-03-05 10:17:02 +08:00
parent 1f2fca4c8f
commit 6a0cccae79
156 changed files with 23040 additions and 1385 deletions
+117
View File
@@ -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
}
}
+11 -16
View File
@@ -6,13 +6,15 @@ using System.Runtime.InteropServices;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit, Size = 7*4*sizeof(float)+ sizeof(bool),Pack =16 )]
[StructLayout(LayoutKind.Explicit, Size = 7 * 4 * sizeof(float) + sizeof(bool), Pack = 16)]
public struct Matrix4x3 : IEquatable<Matrix4x3>
{
[FieldOffset(0)]
internal Mat3 mat;
[FieldOffset(3 * 4 * sizeof(float))]
internal Mat4 transpose;
[FieldOffset(7 * 4 * sizeof(float))]
internal bool isTransposed;
@@ -62,7 +64,6 @@ namespace StgSharp.Math
}
set
{
if (rowNum > 3 || rowNum < 0)
{
throw new ArgumentOutOfRangeException(nameof(columNum));
@@ -92,7 +93,6 @@ namespace StgSharp.Math
fixed (Mat4* target = &this.transpose)
{
InternalIO.Transpose3to4_internal(source, target);
}
isTransposed = true;
}
@@ -108,7 +108,6 @@ namespace StgSharp.Math
return EqualityComparer<Mat3>.Default.Equals(mat, other.mat);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix4x3 operator +(Matrix4x3 left, Matrix4x3 right)
{
@@ -127,7 +126,6 @@ namespace StgSharp.Math
left.mat.colum1 - right.mat.colum1,
left.mat.colum2 - right.mat.colum2
);
}
public static bool operator ==(Matrix4x3 left, Matrix4x3 right)
@@ -159,7 +157,7 @@ namespace StgSharp.Math
mat.mat.colum2 / value
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix4x2 operator *(Matrix4x3 left, Matrix3x2 right)
{
@@ -167,19 +165,19 @@ namespace StgSharp.Math
return new Matrix4x2(
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
Vector4.Dot(left.transpose.colum3, right.mat.colum1)
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix4x3 operator *(Matrix4x3 left, Matrix3x3 right)
{
@@ -223,7 +221,7 @@ namespace StgSharp.Math
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
Vector4.Dot(left.transpose.colum2, right.mat.colum2),
Vector4.Dot(left.transpose.colum2, right.mat.colum3),
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
Vector4.Dot(left.transpose.colum3, right.mat.colum1),
Vector4.Dot(left.transpose.colum3, right.mat.colum2),
@@ -240,8 +238,5 @@ namespace StgSharp.Math
mat.colum2.GetHashCode()
);
}
}
}
}
+2 -19
View File
@@ -1,5 +1,6 @@
using StgSharp.Controlling;
using StgSharp.Math;
using System;
using System.Data.Common;
using System.Numerics;
@@ -7,23 +8,6 @@ using System.Runtime.InteropServices;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public unsafe struct M128
{
[FieldOffset(0)] internal fixed float Single[4];
[FieldOffset(0)] internal fixed double Double[2];
[FieldOffset(0)] internal fixed sbyte Int8[16];
[FieldOffset(0)] internal fixed short Int16[8];
[FieldOffset(0)] internal fixed int Int32[4];
[FieldOffset(0)] internal fixed long Int64[2];
[FieldOffset(0)] internal fixed byte UInt8[16];
[FieldOffset(0)] internal fixed ushort UInt16[8];
[FieldOffset(0)] internal fixed uint UInt32[4];
[FieldOffset(0)] internal fixed ulong UInt64[2];
}
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
public struct Vec4d
{
@@ -35,7 +19,6 @@ namespace StgSharp.Math
[FieldOffset(8)] public float Z;
[FieldOffset(12)] public float W;
public Vec4d(float x, float y, float z, float w)
{
vec = new Vector4(x, y, z, w);
@@ -46,4 +29,4 @@ namespace StgSharp.Math
return vec.reg;
}
}
}
}