Daily update on 20250312-074647 by Nitload Youmu. Additional Message : Change: Temp not want to compile RULE and PROCEDURE

Add: Add factory method to generate more kind of binary operator node
Add: more SIMD intrinsic C function

Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
Nitload
2025-03-12 07:46:48 +08:00
parent 16b813646d
commit 9647c2c68a
29 changed files with 645 additions and 244 deletions
+4
View File
@@ -84,6 +84,10 @@ void load_intrinsic_sse(ssc_intrinsic *context)
context->dot_43 = dot_43_sse;
context->city_hash_simplify = city_hash_simplify_sse;
context->index_pair = index_pair_sse;
context->sub_m2 = submatrix2_sse;
context->sub_m3 = submatrix3_sse;
context->sub_m4 = submatrix4_sse;
}
void load_intrinsic_avx(ssc_intrinsic *context)
+15
View File
@@ -40,3 +40,18 @@ INTERNAL void __cdecl addmatrix2_avx(__2_columnset *left, __2_columnset *right,
__m256 temp = _mm256_add_ps(ALIGN256(left->column[0]), ALIGN256(right->column[0]));
_mm256_storeu_ps(&ans->m[0][0], temp);
}
INTERNAL void __cdecl submatrix2_sse(__2_columnset *left, __2_columnset *right, __2_columnset *ans)
{
__m128 temp0 = _mm_sub_ps(ALIGN(left->column[0]), ALIGN(right->column[0]));
__m128 temp1 = _mm_sub_ps(ALIGN(left->column[1]), ALIGN(right->column[1]));
_mm_storeu_ps(&ans->m[0][0], temp0);
_mm_storeu_ps(&ans->m[0][1], temp1);
}
INTERNAL void __cdecl submatrix2_avx(__2_columnset *left, __2_columnset *right, __2_columnset *ans)
{
__m256 temp = _mm256_sub_ps(ALIGN256(left->column[0]), ALIGN256(right->column[0]));
_mm256_storeu_ps(&ans->m[0][0], temp);
}
+26
View File
@@ -101,4 +101,30 @@ INTERNAL void __cdecl addmatrix3_512(__3_columnset *left, __3_columnset *right,
_mm512_mask_store_ps(ans, 0x0fff, temp);
}
INTERNAL void __cdecl submatrix3_sse(__3_columnset *left, __3_columnset *right, __3_columnset *ans)
{
__m128 temp0 = _mm_sub_ps(ALIGN(left->column[0]), ALIGN(right->column[0]));
__m128 temp1 = _mm_sub_ps(ALIGN(left->column[1]), ALIGN(right->column[1]));
__m128 temp2 = _mm_sub_ps(ALIGN(left->column[2]), ALIGN(right->column[2]));
_mm_storeu_ps(&ans->m[0][0], temp0);
_mm_storeu_ps(&ans->m[0][1], temp1);
_mm_storeu_ps(&ans->m[0][2], temp2);
}
INTERNAL void __cdecl submatrix3_avx(__3_columnset *left, __3_columnset *right, __3_columnset *ans)
{
__m256 temp0 = _mm256_sub_ps(ALIGN256(left->part), ALIGN256(right->part));
__m128 temp1 = _mm_sub_ps(ALIGN(left->column[2]), ALIGN(right->column[2]));
_mm256_storeu_ps(&ans->m[0][0], temp0);
_mm_storeu_ps(&ans->m[0][2], temp1);
}
INTERNAL void __cdecl submatrix3_512(__3_columnset *left, __3_columnset *right, __3_columnset *ans)
{
__m512 temp = _mm512_sub_ps(_mm512_loadu_ps(left), _mm512_loadu_ps(right));
_mm512_mask_store_ps(ans, 0x0fff, temp);
}
#pragma endregion
+19
View File
@@ -82,3 +82,22 @@ INTERNAL void SSCDECL addmatrix4_512(__4_columnset *left, __4_columnset *right,
{
ans->stream = _mm512_add_ps(ALIGN512(left->stream), ALIGN512(right->stream));
}
INTERNAL void SSCDECL submatrix4_sse(__4_columnset *left, __4_columnset *right, __4_columnset *ans)
{
ans->column[0] = _mm_sub_ps(ALIGN(left->column[0]), ALIGN(right->column[0]));
ans->column[1] = _mm_sub_ps(ALIGN(left->column[1]), ALIGN(right->column[1]));
ans->column[2] = _mm_sub_ps(ALIGN(left->column[2]), ALIGN(right->column[2]));
ans->column[3] = _mm_sub_ps(ALIGN(left->column[3]), ALIGN(right->column[3]));
}
INTERNAL void SSCDECL submatrix4_avx(__4_columnset *left, __4_columnset *right, __4_columnset *ans)
{
ans->half[0] = _mm256_sub_ps(ALIGN256(left->half[0]), ALIGN256(right->half[0]));
ans->half[1] = _mm256_sub_ps(ALIGN256(left->half[1]), ALIGN256(right->half[1]));
}
INTERNAL void SSCDECL submatrix4_512(__4_columnset *left, __4_columnset *right, __4_columnset *ans)
{
ans->stream = _mm512_sub_ps(ALIGN512(left->stream), ALIGN512(right->stream));
}
+13 -2
View File
@@ -30,7 +30,7 @@
typedef union uint64_u {
uint64_t u64;
uint32_t u32[2];
}uint64_u;
} uint64_u;
typedef union column_2 {
__m256 stream;
@@ -64,12 +64,17 @@ INTERNAL void normalize(__m128 *source, __m128 *target);
INTERNAL void SSCDECL addmatrix2_sse(__2_columnset *left, __2_columnset *right, __2_columnset *ans);
INTERNAL void SSCDECL addmatrix2_avx(__2_columnset *left, __2_columnset *right, __2_columnset *ans);
INTERNAL void SSCDECL submatrix2_sse(__2_columnset *left, __2_columnset *right, __2_columnset *ans);
INTERNAL void SSCDECL addmatrix2_avx(__2_columnset *left, __2_columnset *right, __2_columnset *ans);
INTERNAL void SSCDECL transpose23(__2_columnset const *source, __3_columnset *target);
INTERNAL void SSCDECL transpose24(__2_columnset const *source, __4_columnset *target);
INTERNAL void SSCDECL addmatrix3_sse(__3_columnset *left, __3_columnset *right, __3_columnset *ans);
INTERNAL void SSCDECL addmatrix3_avx(__3_columnset *left, __3_columnset *right, __3_columnset *ans);
INTERNAL void SSCDECL addmatrix3_512(__3_columnset *left, __3_columnset *right, __3_columnset *ans);
INTERNAL void SSCDECL submatrix3_sse(__3_columnset *left, __3_columnset *right, __3_columnset *ans);
INTERNAL void SSCDECL submatrix3_avx(__3_columnset *left, __3_columnset *right, __3_columnset *ans);
INTERNAL void SSCDECL submatrix3_512(__3_columnset *left, __3_columnset *right, __3_columnset *ans);
INTERNAL void SSCDECL transpose32(__3_columnset const *source, __2_columnset *target);
INTERNAL void SSCDECL transpose33(__3_columnset const *source, __3_columnset *target);
INTERNAL void SSCDECL transpose34(__3_columnset const *source, __4_columnset *target);
@@ -78,6 +83,9 @@ INTERNAL float SSCDECL det_mat3(__3_columnset *matrix, __3_columnset *tranpose);
INTERNAL void SSCDECL addmatrix4_sse(__4_columnset *left, __4_columnset *right, __4_columnset *ans);
INTERNAL void SSCDECL addmatrix4_avx(__4_columnset *left, __4_columnset *right, __4_columnset *ans);
INTERNAL void SSCDECL addmatrix4_512(__4_columnset *left, __4_columnset *right, __4_columnset *ans);
INTERNAL void SSCDECL submatrix4_sse(__4_columnset *left, __4_columnset *right, __4_columnset *ans);
INTERNAL void SSCDECL submatrix4_avx(__4_columnset *left, __4_columnset *right, __4_columnset *ans);
INTERNAL void SSCDECL submatrix4_512(__4_columnset *left, __4_columnset *right, __4_columnset *ans);
INTERNAL void SSCDECL transpose42(__4_columnset const *source, __2_columnset *target);
INTERNAL void SSCDECL transpose43(__4_columnset const *source, __3_columnset *target);
INTERNAL void SSCDECL transpose44(__4_columnset const *source, __4_columnset *target);
@@ -99,7 +107,7 @@ INTERNAL void SSCDECL dot_42_avx(__4_columnset *transpose, __m128 *vector, __m12
INTERNAL void SSCDECL dot_43_sse(__4_columnset *transpose, __m128 *vector, __m128 *ans);
INTERNAL void SSCDECL dot_43_avx(__4_columnset *transpose, __m128 *vector, __m128 *ans);
INTERNAL void SSCDECL dot_43_512(__4_columnset *transpose, __m128 *vector, __m128 *ans);
//INTERNAL void SSCDECL dot_43_512(__4_columnset *transpose, __m128 *vector, __m128 *ans);
#pragma endregion
@@ -124,6 +132,9 @@ typedef struct ssc_intrinsic {
DOTPROC dot_43;
int (*index_pair)(short const *str, uint32_t target, int length);
VECTORNORMALIZEPROC normalize_3;
MATARITHMETIC sub_m2;
MATARITHMETIC sub_m3;
MATARITHMETIC sub_m4;
MATRIXTRANSPOSEPROC transpose_23;
MATRIXTRANSPOSEPROC transpose_24;
MATRIXTRANSPOSEPROC transpose_32;
+1 -1
View File
@@ -66,7 +66,7 @@ namespace StgSharp.Internal
public unsafe byte[] GetBytes()
{
byte[] ret = new byte[16];
fixed( Vector4* vptr = &data.Vec ) {
fixed( M128* vptr = &data ) {
byte* bptr = ( byte* )vptr;
for( int i = 0; i < 15; i++ ) {
ret[ i ] = *bptr;
+13 -13
View File
@@ -48,11 +48,11 @@ namespace StgSharp.HighPerformance
{
[FieldOffset( 0 )] internal fixed byte Buffer[ 16 ];
[FieldOffset( 0 )] internal Vector4 Vec;
[FieldOffset( 0 )] internal Vector128<byte> Vec;
internal M128( Vector4 v )
{
Vec = v;
Vec = v.AsVector128().AsByte();
}
public ref T AsRef<T>() where T: struct, INumber<T>
@@ -77,7 +77,7 @@ namespace StgSharp.HighPerformance
public T Read<T>( int index ) where T: struct, INumber<T>
{
fixed( Vector4* p = &Vec ) {
fixed( byte* p = Buffer ) {
#pragma warning disable CS8500
return *( ( T* )p + index );
#pragma warning restore CS8500
@@ -123,61 +123,61 @@ namespace StgSharp.HighPerformance
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<byte>( M128 m )
{
return m.Vec.AsVector128().As<float, byte>();
return m.Vec.As<byte, byte>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<double>( M128 m )
{
return m.Vec.AsVector128().As<float, double>();
return m.Vec.As<byte, double>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<float>( M128 m )
{
return m.Vec.AsVector128().As<float, float>();
return m.Vec.As<byte, float>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<int>( M128 m )
{
return m.Vec.AsVector128().As<float, int>();
return m.Vec.As<byte, int>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<long>( M128 m )
{
return m.Vec.AsVector128().As<float, long>();
return m.Vec.As<byte, long>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<sbyte>( M128 m )
{
return m.Vec.AsVector128().As<float, sbyte>();
return m.Vec.As<byte, sbyte>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<short>( M128 m )
{
return m.Vec.AsVector128().As<float, short>();
return m.Vec.As<byte, short>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<uint>( M128 m )
{
return m.Vec.AsVector128().As<float, uint>();
return m.Vec.As<byte, uint>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<ulong>( M128 m )
{
return m.Vec.AsVector128().As<float, ulong>();
return m.Vec.As<byte, ulong>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<ushort>( M128 m )
{
return m.Vec.AsVector128().As<float, ushort>();
return m.Vec.As<byte, ushort>();
}
}
-1
View File
@@ -30,7 +30,6 @@
//-----------------------------------------------------------------------
using StgSharp.Graphics;
using StgSharp.Graphics.OpenGL;
using StgSharp.Internal.OpenGL;
using System;
using System.Collections.Generic;
@@ -58,6 +58,9 @@ namespace StgSharp.Internal.Intrinsic
public delegate* unmanaged[Cdecl]<ColumnSet4*, Vector4*, Vector4*, void> dot_43;
public delegate* unmanaged[Cdecl]<char*, int, int, int> index_pair;
public delegate* unmanaged[Cdecl]<Vector4*, Vector4*, void> normalize_v3;
public delegate* unmanaged[Cdecl]<ColumnSet2*, ColumnSet2*, ColumnSet2*, void> sub_mat_2;
public delegate* unmanaged[Cdecl]<ColumnSet3*, ColumnSet3*, ColumnSet3*, void> sub_mat_3;
public delegate* unmanaged[Cdecl]<ColumnSet4*, ColumnSet4*, ColumnSet4*, void> sub_mat_4;
public delegate* unmanaged[Cdecl]<ColumnSet2*, ColumnSet3*, void> transpose23;
public delegate* unmanaged[Cdecl]<ColumnSet2*, ColumnSet4*, void> transpose24;
public delegate* unmanaged[Cdecl]<ColumnSet3*, ColumnSet2*, void> transpose32;
+28 -21
View File
@@ -42,6 +42,7 @@ namespace StgSharp.Math
Pack = 16 )]
public struct Matrix22 : IMat
{
[FieldOffset( 2 * 2 * 4 * sizeof( float ) )]
internal bool isTransposed = false;
@@ -50,12 +51,6 @@ namespace StgSharp.Math
[FieldOffset( 2 * 4 * sizeof( float ) )]
internal ColumnSet2 _transpose;
public Matrix22()
{
Unsafe.SkipInit( out this );
isTransposed = false;
}
internal Matrix22( ColumnSet2 mat )
{
this._mat = mat;
@@ -63,15 +58,21 @@ namespace StgSharp.Math
internal Matrix22( Vector4 c0, Vector4 c1 )
{
Unsafe.SkipInit(out this);
Unsafe.SkipInit( out this );
isTransposed = false;
_mat.colum0 = c0;
_mat.colum1 = c1;
}
public Matrix22()
{
Unsafe.SkipInit( out this );
isTransposed = false;
}
public Matrix22( float a00, float a01, float a10, float a11 )
{
Unsafe.SkipInit(out this);
Unsafe.SkipInit( out this );
isTransposed = false;
_mat.colum0 = new Vector4( a00, a10, 0, 0 );
_mat.colum1 = new Vector4( a01, a11, 0, 0 );
@@ -105,22 +106,17 @@ namespace StgSharp.Math
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix22 operator +(Matrix22 left, Matrix22 right)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix22 operator -(
Matrix22 left,
Matrix22 right )
{
Matrix22 ret = new Matrix22();
InternalIO.Intrinsic.add_mat_2( &left._mat, &right._mat, &ret._mat );
InternalIO.Intrinsic.sub_mat_2( &left._mat, &right._mat,
&ret._mat );
return ret;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix22 operator -( Matrix22 left, Matrix22 right )
{
return new Matrix22(
left._mat.colum0 + right._mat.colum0,
left._mat.colum1 + right._mat.colum1 );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix22 operator *( Matrix22 mat, float value )
{
@@ -137,7 +133,7 @@ namespace StgSharp.Math
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.colum1, right._mat.colum1 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
@@ -167,7 +163,7 @@ namespace StgSharp.Math
Vector4.Dot( left._transpose.colum1, right.mat.colum0 ),
Vector4.Dot( left._transpose.colum1, right.mat.colum1 ),
Vector4.Dot( left._transpose.colum1, right.mat.colum2 ),
Vector4.Dot( left._transpose.colum1, right.mat.colum3 ));
Vector4.Dot( left._transpose.colum1, right.mat.colum3 ) );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
@@ -177,5 +173,16 @@ namespace StgSharp.Math
mat._mat.colum0 / value, mat._mat.colum1 / value );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix22 operator +(
Matrix22 left,
Matrix22 right )
{
Matrix22 ret = new Matrix22();
InternalIO.Intrinsic.add_mat_2( &left._mat, &right._mat,
&ret._mat );
return ret;
}
}
}
+18 -13
View File
@@ -48,12 +48,6 @@ namespace StgSharp.Math
[FieldOffset( 3 * 4 * sizeof( float ) )] internal ColumnSet2 _transpose;
[FieldOffset( 0 )] internal ColumnSet3 _mat;
public Matrix23()
{
Unsafe.SkipInit( out _mat);
Unsafe.SkipInit(out _transpose);
}
internal Matrix23( Vector4 c0, Vector4 c1, Vector4 c2 )
{
_mat.colum0 = c0;
@@ -61,6 +55,12 @@ namespace StgSharp.Math
_mat.colum2 = c2;
}
public Matrix23()
{
Unsafe.SkipInit( out _mat );
Unsafe.SkipInit( out _transpose );
}
public Matrix23(
float a00,
float a01,
@@ -122,12 +122,14 @@ namespace StgSharp.Math
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix23 operator -( Matrix23 left, Matrix23 right )
public static unsafe Matrix23 operator -(
Matrix23 left,
Matrix23 right )
{
return new Matrix23(
left._mat.colum0 - right._mat.colum0,
left._mat.colum1 - right._mat.colum1,
left._mat.colum2 - right._mat.colum2 );
Matrix23 ret = new Matrix23();
InternalIO.Intrinsic.sub_mat_3( &left._mat, &right._mat,
&ret._mat );
return ret;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
@@ -189,10 +191,13 @@ namespace StgSharp.Math
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix23 operator +( Matrix23 left, Matrix23 right )
public static unsafe Matrix23 operator +(
Matrix23 left,
Matrix23 right )
{
Matrix23 ret = new Matrix23();
InternalIO.Intrinsic.add_mat_3(&left._mat, &right._mat, &ret._mat);
InternalIO.Intrinsic.add_mat_3( &left._mat, &right._mat,
&ret._mat );
return ret;
}
+19 -16
View File
@@ -43,6 +43,7 @@ namespace StgSharp.Math
Pack = 16 )]
public struct Matrix24 : IMat
{
[FieldOffset( 6 * 4 * sizeof( float ) )] internal bool isTransposed;
[FieldOffset( 4 * 4 * sizeof( float ) )] internal ColumnSet2 transpose;
@@ -53,15 +54,9 @@ namespace StgSharp.Math
[FieldOffset( 32 )] public Vec2 Colum2;
[FieldOffset( 48 )] public Vec2 Colum3;
public Matrix24()
{
Unsafe.SkipInit(out this);
isTransposed = false;
}
internal Matrix24( Vector4 c0, Vector4 c1, Vector4 c2, Vector4 c3 )
{
Unsafe.SkipInit(out this);
Unsafe.SkipInit( out this );
isTransposed = false;
mat.colum0 = c0;
mat.colum1 = c1;
@@ -69,6 +64,12 @@ namespace StgSharp.Math
mat.colum3 = c3;
}
public Matrix24()
{
Unsafe.SkipInit( out this );
isTransposed = false;
}
public Matrix24(
float a00,
float a01,
@@ -79,7 +80,7 @@ namespace StgSharp.Math
float a12,
float a13 )
{
Unsafe.SkipInit(out this);
Unsafe.SkipInit( out this );
isTransposed = false;
mat.colum0 = new Vector4( a00, a10, 0, 0 );
mat.colum1 = new Vector4( a01, a11, 0, 0 );
@@ -141,13 +142,13 @@ namespace StgSharp.Math
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix24 operator -( Matrix24 left, Matrix24 right )
public static unsafe Matrix24 operator -(
Matrix24 left,
Matrix24 right )
{
return new Matrix24(
left.mat.colum0 - right.mat.colum0,
left.mat.colum1 - right.mat.colum1,
left.mat.colum2 - right.mat.colum2,
left.mat.colum3 - right.mat.colum3 );
Matrix24 ret = new Matrix24();
InternalIO.Intrinsic.sub_mat_4( &left.mat, &right.mat, &ret.mat );
return ret;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
@@ -209,10 +210,12 @@ namespace StgSharp.Math
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix24 operator +( Matrix24 left, Matrix24 right )
public static unsafe Matrix24 operator +(
Matrix24 left,
Matrix24 right )
{
Matrix24 ret = new Matrix24();
InternalIO.Intrinsic.add_mat_4(&left.mat,&right.mat,&ret.mat);
InternalIO.Intrinsic.add_mat_4( &left.mat, &right.mat, &ret.mat );
return ret;
}
+12 -10
View File
@@ -52,20 +52,20 @@ namespace StgSharp.Math
[FieldOffset( 0 )] internal Vec3 colum0;
[FieldOffset( 4 * 4 )] internal Vec3 colum1;
public Matrix32()
{
Unsafe.SkipInit(out this);
isTransposed = false;
}
internal Matrix32( Vector4 c0, Vector4 c1 )
{
Unsafe.SkipInit(out this);
Unsafe.SkipInit( out this );
isTransposed = false;
mat.colum0 = c0;
mat.colum1 = c1;
}
public Matrix32()
{
Unsafe.SkipInit( out this );
isTransposed = false;
}
public unsafe Matrix32(
float a00,
float a01,
@@ -74,7 +74,7 @@ namespace StgSharp.Math
float a20,
float a21 )
{
Unsafe.SkipInit(out this);
Unsafe.SkipInit( out this );
isTransposed = false;
mat.colum0 = new Vector4( a00, a10, a20, 0 );
mat.colum1 = new Vector4( a01, a11, a21, 0 );
@@ -209,10 +209,12 @@ namespace StgSharp.Math
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix32 operator +( Matrix32 left, Matrix32 right )
public static unsafe Matrix32 operator +(
Matrix32 left,
Matrix32 right )
{
Matrix32 ret = new Matrix32();
InternalIO.Intrinsic.add_mat_2(&left.mat, &right.mat, &ret.mat);
InternalIO.Intrinsic.add_mat_2( &left.mat, &right.mat, &ret.mat );
return ret;
}
+18 -15
View File
@@ -52,21 +52,21 @@ namespace StgSharp.Math
[FieldOffset( 1 * 4 * sizeof( float ) )] public Vec3 Colum1;
[FieldOffset( 2 * 4 * sizeof( float ) )] public Vec3 Colum2;
public Matrix33()
{
Unsafe.SkipInit(out this);
isTransposed = false;
}
internal Matrix33( Vector4 c0, Vector4 c1, Vector4 c2 )
{
Unsafe.SkipInit(out this);
Unsafe.SkipInit( out this );
isTransposed = false;
mat.colum0 = c0;
mat.colum1 = c1;
mat.colum2 = c2;
}
public Matrix33()
{
Unsafe.SkipInit( out this );
isTransposed = false;
}
public Matrix33(
float a00,
float a01,
@@ -78,7 +78,7 @@ namespace StgSharp.Math
float a21,
float a22 )
{
Unsafe.SkipInit(out this);
Unsafe.SkipInit( out this );
isTransposed = false;
mat.colum0 = new Vector4( a00, a10, a20, 0 );
mat.colum1 = new Vector4( a01, a11, a21, 0 );
@@ -140,12 +140,13 @@ namespace StgSharp.Math
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix33 operator -( Matrix33 left, Matrix33 right )
public static unsafe Matrix33 operator -(
Matrix33 left,
Matrix33 right )
{
return new Matrix33(
left.mat.colum0 - right.mat.colum0,
left.mat.colum1 - right.mat.colum1,
left.mat.colum2 + right.mat.colum2 );
Matrix33 ret = new Matrix33();
InternalIO.Intrinsic.sub_mat_3( &left.mat, &right.mat, &ret.mat );
return ret;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
@@ -229,10 +230,12 @@ namespace StgSharp.Math
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix33 operator +( Matrix33 left, Matrix33 right )
public static unsafe Matrix33 operator +(
Matrix33 left,
Matrix33 right )
{
Matrix33 ret = new Matrix33();
InternalIO.Intrinsic.add_mat_3(&left.mat, &right.mat, &ret.mat);
InternalIO.Intrinsic.add_mat_3( &left.mat, &right.mat, &ret.mat );
return ret;
}
+18 -17
View File
@@ -55,12 +55,6 @@ namespace StgSharp.Math
[FieldOffset( 2 * 4 * sizeof( float ) )] public Vec3 Colum2;
[FieldOffset( 3 * 4 * sizeof( float ) )] public Vec3 Colum3;
public Matrix34()
{
Unsafe.SkipInit(out this);
isTransposed = false;
}
internal Matrix34( ColumnSet4 mat )
{
Unsafe.SkipInit( out this );
@@ -70,7 +64,7 @@ namespace StgSharp.Math
internal Matrix34( Vector4 c0, Vector4 c1, Vector4 c2, Vector4 c3 )
{
Unsafe.SkipInit(out this);
Unsafe.SkipInit( out this );
isTransposed = false;
mat.colum0 = c0;
mat.colum1 = c1;
@@ -78,6 +72,12 @@ namespace StgSharp.Math
mat.colum3 = c3;
}
public Matrix34()
{
Unsafe.SkipInit( out this );
isTransposed = false;
}
public Matrix34(
float a00,
float a01,
@@ -92,7 +92,7 @@ namespace StgSharp.Math
float a22,
float a23 )
{
Unsafe.SkipInit(out this);
Unsafe.SkipInit( out this );
isTransposed = false;
mat.colum0 = new Vector4( a00, a10, a20, 0 );
mat.colum0 = new Vector4( a01, a11, a21, 0 );
@@ -147,13 +147,13 @@ namespace StgSharp.Math
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Matrix34 operator -( Matrix34 left, Matrix34 right )
public static unsafe Matrix34 operator -(
Matrix34 left,
Matrix34 right )
{
return new Matrix34(
left.mat.colum0 - right.mat.colum0,
left.mat.colum1 - right.mat.colum1,
left.mat.colum2 - right.mat.colum2,
left.mat.colum3 - right.mat.colum3 );
Matrix34 ret = new Matrix34();
InternalIO.Intrinsic.sub_mat_4( &left.mat, &right.mat, &ret.mat );
return ret;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
@@ -227,12 +227,13 @@ namespace StgSharp.Math
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static unsafe Matrix34 operator +( Matrix34 left, Matrix34 right )
public static unsafe Matrix34 operator +(
Matrix34 left,
Matrix34 right )
{
Matrix34 ret = new Matrix34();
InternalIO.Intrinsic.add_mat_4(&left.mat,&right.mat,&ret.mat);
InternalIO.Intrinsic.add_mat_4( &left.mat, &right.mat, &ret.mat );
return ret;
}
}
+16 -16
View File
@@ -49,27 +49,27 @@ namespace StgSharp.Math
[FieldOffset( 0 )] internal ColumnSet2 mat;
[FieldOffset( 8 * sizeof( float ) )] internal ColumnSet4 transpose;
public Matrix42()
{
Unsafe.SkipInit(out this);
isTransposed = false;
}
internal Matrix42( ColumnSet2 mat )
{
Unsafe.SkipInit(out this);
Unsafe.SkipInit( out this );
isTransposed = false;
this.mat = mat;
}
internal Matrix42( Vector4 c0, Vector4 c1 )
{
Unsafe.SkipInit(out this);
isTransposed= false;
Unsafe.SkipInit( out this );
isTransposed = false;
mat.colum0 = c0;
mat.colum1 = c1;
}
public Matrix42()
{
Unsafe.SkipInit( out this );
isTransposed = false;
}
public Matrix42(
float a00,
float a01,
@@ -80,7 +80,7 @@ namespace StgSharp.Math
float a30,
float a31 )
{
Unsafe.SkipInit(out this);
Unsafe.SkipInit( out this );
isTransposed = false;
mat.colum0 = new Vector4( a00, a10, a20, a30 );
mat.colum1 = new Vector4( a01, a11, a21, a31 );
@@ -144,9 +144,9 @@ namespace StgSharp.Math
Matrix42 left,
Matrix42 right )
{
return new Matrix42(
left.mat.colum0 - right.mat.colum0,
left.mat.colum0 - right.mat.colum0 );
Matrix42 ret = new Matrix42();
InternalIO.Intrinsic.sub_mat_2( &left.mat, &right.mat, &ret.mat );
return ret;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
@@ -234,9 +234,9 @@ namespace StgSharp.Math
Matrix42 left,
Matrix42 right )
{
return new Matrix42(
left.mat.colum0 + right.mat.colum0,
left.mat.colum0 + right.mat.colum0 );
Matrix42 ret = new Matrix42();
InternalIO.Intrinsic.add_mat_2( &left.mat, &right.mat, &ret.mat );
return ret;
}
}
+7
View File
@@ -31,6 +31,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
@@ -60,6 +61,12 @@ namespace StgSharp.Script
public static Token Empty => EmptyToken;
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public Token ReLocate( int line, int column )
{
return new Token( Value, line, column, Flag );
}
}
public enum TokenFlag : int
@@ -51,5 +51,11 @@ namespace StgSharp.Script.Express
private set;
}
public static ExpTypeSource ExpBool
{
get;
private set;
}
}
}
@@ -109,6 +109,11 @@ namespace StgSharp.Script.Express
PoolString( KeyWord.Real ),
out ExpTypeSource? _expReal );
ExpReal = _expReal;
ExpSchema_Nitload.Only
.TryGetType(
PoolString( KeyWord.Bool ),
out ExpTypeSource? _expBool );
ExpBool = _expBool;
}
public static bool LetterIsOperator( string str )
@@ -72,6 +72,7 @@ namespace StgSharp.Script.Express
MUL = "*",
DIV = "/",
NOT = "NOT",
NotEqual = "<>",
Assignment = ":=",
Equal = "=",
Mod = "MOD",
@@ -112,6 +112,41 @@ namespace StgSharp.Script.Express
};
}
public static ExpBinaryOperatorNode EqualTo(
Token source,
ExpNode left,
ExpNode right )
{
if( left.EqualityTypeConvert != right.EqualityTypeConvert ) {
throw new ExpInvalidTypeException(
left.EqualityTypeConvert.Name,
right.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source )
{
_returnType = ExpCompile.ExpBool,
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
CodeConvertTemplate = "{0} == {1}",
};
}
public static ExpBinaryOperatorNode GreaterThan(
Token source,
ExpNode left,
ExpNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException(
"Number", left.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source )
{
_returnType = ExpCompile.ExpBool,
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
CodeConvertTemplate = "{0} > {1}",
};
}
public static ExpBinaryOperatorNode Mul(
Token source,
ExpNode left,
@@ -132,6 +167,41 @@ namespace StgSharp.Script.Express
};
}
public static ExpBinaryOperatorNode NotEqualTo(
Token source,
ExpNode left,
ExpNode right )
{
if( left.EqualityTypeConvert != right.EqualityTypeConvert ) {
throw new ExpInvalidTypeException(
left.EqualityTypeConvert.Name,
right.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source )
{
_returnType = ExpCompile.ExpBool,
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
CodeConvertTemplate = "{0} != {1}",
};
}
public static ExpBinaryOperatorNode SmallerThan(
Token source,
ExpNode left,
ExpNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException(
"Number", left.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source )
{
_returnType = ExpCompile.ExpBool,
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
CodeConvertTemplate = "{0} < {1}",
};
}
public static ExpBinaryOperatorNode Sub(
Token source,
ExpNode left,
@@ -0,0 +1,157 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpLiteralGenericNode.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Data;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Script.Express
{
public class ExpIntNode : ExpElementInstanceBase
{
private int _value;
public ExpIntNode( Token source, int value )
: base( source )
{
_value = value;
_nodeFlag = ExpNodeFlag.BuiltinType_Int | ExpNodeFlag.Element_Type;
}
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
.TryGetType(
ExpCompile.KeyWord.Int, out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException();
public int Value => _value;
public override string TypeName => ExpCompile.KeyWord.Int;
}
public class ExpStringNode : ExpElementInstanceBase
{
private readonly string _value;
public ExpStringNode( Token source, string value )
: base( source )
{
_value = value;
_nodeFlag = ExpNodeFlag.BuiltinType_String | ExpNodeFlag.Element_Type;
}
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
.TryGetType(
ExpCompile.KeyWord.String,
out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException();
public override string TypeName => EqualityTypeConvert.Name;
public string Value => _value;
}
public class ExpBoolNode : ExpElementInstanceBase
{
private readonly bool _value;
public ExpBoolNode( Token source, bool value )
: base( source )
{
_value = value;
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Element_Type;
}
public bool Value => _value;
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
.TryGetType(
ExpCompile.KeyWord.Bool, out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException();
public override string TypeName => EqualityTypeConvert.Name;
}
public class ExpRealNumberNode : ExpElementInstanceBase
{
private readonly float _value;
public ExpRealNumberNode( Token source, float value )
: base( source )
{
_value = value;
_nodeFlag = ExpNodeFlag.BuiltinType_Real | ExpNodeFlag.Element_Type;
}
public float Value => _value;
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
.TryGetType(
ExpCompile.KeyWord.String,
out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException();
public override string TypeName => EqualityTypeConvert.Name;
}
public class ExpLogicValueNode : ExpElementInstanceBase
{
private readonly ExpLogic _value;
public ExpLogicValueNode( Token source, ExpLogic value )
: base( source )
{
_value = value;
_nodeFlag = ExpNodeFlag.BuiltinType_Logic | ExpNodeFlag.Element_Type;
}
public ExpLogic Value => _value;
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
.TryGetType(
ExpCompile.KeyWord.Logic,
out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException();
public override string TypeName => EqualityTypeConvert.Name;
}
}
@@ -62,14 +62,14 @@ namespace StgSharp.Script.Express
if( increment == null ) {
switch( ( ExpNodeFlag )variable.NodeFlag | ExpNodeFlag.BuiltinType_Any ) {
case ExpNodeFlag.BuiltinType_Real:
increment = new ExpLiteralGenericNode<float>(
increment = new ExpRealNumberNode(
new Token(
ExpCompile.PoolString( "1.0f" ), source.Line,
-1, TokenFlag.Number ),
1.0f );
break;
case ExpNodeFlag.BuiltinType_Int:
increment = new ExpLiteralGenericNode<int>(
increment = new ExpIntNode(
new Token(
ExpCompile.PoolString( "1" ), source.Line, -1,
TokenFlag.Number ),
@@ -65,6 +65,13 @@ namespace StgSharp.Script.Express
case ExpCompile.KeyWord.DIV:
node = ExpBinaryOperatorNode.Div( t, left, right );
return true;
case ExpCompile.KeyWord.Equal:
node = ExpBinaryOperatorNode.EqualTo( t, left, right );
return true;
case ExpCompile.KeyWord.NotEqual:
node = ExpBinaryOperatorNode.NotEqualTo( t, left, right );
return true;
default:
node = ExpNode.Empty;
return false;
+9 -1
View File
@@ -76,17 +76,25 @@ namespace StgSharp.Script.Express
}
_cache.PushOperand( expToken );
break;
case TokenFlag.Number or TokenFlag.String or TokenFlag.Member:
case TokenFlag.Number or TokenFlag.String:
_cache.PushOperand( expToken );
break;
case TokenFlag.Member:
if( _context.TryGetFunction( expToken.Value, out _ ) ) {
_cache.PushOperator( expToken );
} else { }
break;
case TokenFlag.Separator_Single: //a , ; found
// if operator stack is not empty, convert all operators to node until meet a same separator
// or OperandAheadOfSeparator property is less than certain value
break;
case TokenFlag.Separator_Left: //a ( [ { found
// check if the last token is a function name, loop block or branch
// then increase depth
_cache.PushOperator( expToken );
break;
case TokenFlag.Separator_Right: //a } ] ) found
//Close current depth and cache call node in this depth as a partial AST
break;
case TokenFlag.Index_Left: // a [ found
break;
@@ -0,0 +1,72 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSchemaSource.Compile.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public enum ExpressCompileOption
{
Default = 0,
Translate = 1,
Compile = 2,
}
public partial class ExpSchemaSource
{
public ExpSchema Compile( ExpressCompileOption option )
{
switch( option ) {
case ExpressCompileOption.Default:
return Compile_Translate( option );
case ExpressCompileOption.Translate:
return Compile_Translate( option );
case ExpressCompileOption.Compile:
throw new NotImplementedException();
default:
throw new ArgumentException();
}
}
internal GeneratedExpSchema Compile_Translate(
ExpressCompileOption option )
{
throw new NotImplementedException();
}
}
}
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+6f494f25eff44526a1e002d5ebeab8cf7b86a51d")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+16b813646d8a2326551f05c69f727a292a719222")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/6f494f25eff44526a1e002d5ebeab8cf7b86a51d/*"}}
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/16b813646d8a2326551f05c69f727a292a719222/*"}}
+5 -35
View File
@@ -59,45 +59,15 @@ namespace StgSharp
try {
StgSharp.Init();
/*
/**/
ExpCompile.InitCompile();
ExpFileSource reader = new ExpFileSource( testExpPath );
ExpSchemaSource schemaSource = new ExpSchemaSource();
schemaSource.ReadSchema( reader );
ScriptSourceTransmitter st = new ScriptSourceTransmitter(
"end", 0 );
for( int i = 0; i < 10; i++ ) {
string str = $"rawCode () (\"\") {i}";
Console.WriteLine( str );
st.WriteLine( str );
}
for( int i = 0; i < 10; i++ ) {
string str = $"Code{i} {new string(' ', i + 1)}-- Comment{i}";
Console.WriteLine( str );
st.WriteLine( str );
}
st.WriteLine( "CodeBef (* comment" );
st.WriteLine( $"comment *) codeAft" );
Console.WriteLine( "CodeBef (* comment_" );
Console.WriteLine( $"_comment *) codeAft" );
for( int i = 0; i < 10; i++ ) {
string str = $" Code{i} (* (* Comment{i} *) *) Code{i}";
Console.WriteLine( str );
st.WriteLine( str );
}
st.WriteLine( "end" );
ExpSourceReader sr = new ExpSourceReader( st );
int count = 0;
while( !sr.IsEmpty ) {
count++;
Token str = sr.ReadToken();
Console.WriteLine(
$"{count}\t{str.Flag}\t\t{str.Value.ToString()}" );
}
IScriptSourceProvider slice = st.Slice( 5, 2 );
/**/
/**/
/*
StgSharp.InitGL( 4, 6 );
StgSharp.GlobalSetting.VSyncActivated = false;
@@ -126,8 +96,8 @@ namespace StgSharp
return;
}
catch( Exception ) {
throw;
catch( Exception ex ) {
Console.WriteLine( ex.Message );
/*
StgSharp.WriteLog($"{ex}", LogType.Error);
if( true ) { }