add isa check
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MatrixParallel"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
// 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
|
||||
|
||||
@@ -61,14 +61,20 @@
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<OutDir>$(SolutionDir)build</OutDir>
|
||||
<RunCodeAnalysis>true</RunCodeAnalysis>
|
||||
<EnableClangTidyCodeAnalysis>false</EnableClangTidyCodeAnalysis>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<OutDir>$(SolutionDir)build</OutDir>
|
||||
<GenerateManifest>false</GenerateManifest>
|
||||
<RunCodeAnalysis>true</RunCodeAnalysis>
|
||||
<EnableClangTidyCodeAnalysis>false</EnableClangTidyCodeAnalysis>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='PerformanceDebug|x64'">
|
||||
<OutDir>$(SolutionDir)build</OutDir>
|
||||
<GenerateManifest>false</GenerateManifest>
|
||||
<RunCodeAnalysis>true</RunCodeAnalysis>
|
||||
<EnableClangTidyCodeAnalysis>false</EnableClangTidyCodeAnalysis>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
@@ -175,6 +181,7 @@
|
||||
<ClInclude Include="sn-head\sn_internal.h" />
|
||||
<ClInclude Include="sn-head\sn_intrinsic.h" />
|
||||
<ClInclude Include="sn-head\sn_matkernel.h" />
|
||||
<ClInclude Include="sn-head\sn_target.h" />
|
||||
<ClInclude Include="sn-head\StgSharpNative.h" />
|
||||
<ClInclude Include="sn-head\wgl.h" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -92,6 +92,9 @@
|
||||
<ClInclude Include="lib\stbi\stb_image.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="sn-head\sn_target.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Library Include="lib\glfw\glfw3.lib">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifndef SSC_INTRIN
|
||||
#ifndef SSC_INTRIN
|
||||
#define SSC_INTRIN
|
||||
|
||||
#define SSC_INTRIN_HEAD
|
||||
@@ -328,4 +328,38 @@ typedef enum most_advanced_instruction {
|
||||
#endif
|
||||
} most_advanced_instruction;
|
||||
|
||||
#include "sn_target.h"
|
||||
|
||||
#if SN_IS_ARCH(SN_ARCH_X86_64)
|
||||
|
||||
typedef enum intrinsic_level {
|
||||
// No SIMD support, will cause error if used in matrix operations
|
||||
SIMD0 = 0,
|
||||
// SSE4.2 support
|
||||
SIMD1 = 1,
|
||||
// AVX2 support
|
||||
SIMD2 = 2,
|
||||
// AVX2 and AVX2-FMA support
|
||||
SIMD3 = 3,
|
||||
// AVX2-16C support based on SIMD3
|
||||
SIMD4 = 4,
|
||||
// AVX-512-dual support
|
||||
SIMD5 = 5,
|
||||
// AVX-512-native support
|
||||
SIMD6 = 6,
|
||||
// AVX-512 with 8/16-wide support
|
||||
SIMD7 = 7,
|
||||
// AMX support
|
||||
SIMD8 = 8,
|
||||
// AVX-10 support
|
||||
SIMD9 = 9,
|
||||
// future use
|
||||
SIMD_MAX = 10
|
||||
} intrinsic_level;
|
||||
|
||||
#else
|
||||
typedef enum intrinsic_level {
|
||||
} intrinsic_level;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
#ifndef SN_TARGET
|
||||
#define SN_TARGET
|
||||
|
||||
typedef enum SN_OS_T {
|
||||
SN_OS_WINDOWS,
|
||||
SN_OS_LINUX,
|
||||
SN_OS_MACOS,
|
||||
SN_OS_IOS,
|
||||
SN_OS_ANDROID,
|
||||
SN_OS_UNKNOWN
|
||||
} SN_OS_T;
|
||||
|
||||
typedef enum SN_ARCH_T {
|
||||
SN_ARCH_X86_64,
|
||||
SN_ARCH_ARM64,
|
||||
SN_ARCH_RISCV64,
|
||||
SN_ARCH_PPC64le,
|
||||
} SN_ARCH_T;
|
||||
|
||||
/*
|
||||
* Target selection policy:
|
||||
* - Default (no SN_EXTERN_TARGET): fixed Windows + x86_64.
|
||||
* - External (SN_EXTERN_TARGET): build system must provide SN_OS and SN_ARCH.
|
||||
*/
|
||||
#ifndef SN_EXTERN_TARGET
|
||||
|
||||
#define SN_OS_TARGET SN_OS_WINDOWS
|
||||
#define SN_ARCH_TARGET SN_ARCH_X86_64
|
||||
|
||||
#else
|
||||
|
||||
#ifndef SN_OS_TARGET
|
||||
#error "SN_EXTERN_TARGET is defined but SN_OS is not provided."
|
||||
#endif
|
||||
|
||||
#ifndef SN_ARCH_TARGET
|
||||
#error "SN_EXTERN_TARGET is defined but SN_ARCH is not provided."
|
||||
#endif
|
||||
|
||||
/* Validate externally supplied values are within known enum constants. */
|
||||
#if (SN_OS_TARGET != SN_OS_WINDOWS) && (SN_OS_TARGET != SN_OS_LINUX) && (SN_OS_TARGET != SN_OS_MACOS) && \
|
||||
(SN_OS_TARGET != SN_OS_IOS) && (SN_OS_TARGET != SN_OS_ANDROID) && (SN_OS_TARGET != SN_OS_UNKNOWN)
|
||||
#error "SN_OS has an invalid value. Use SN_OS_<...> enum constants."
|
||||
#endif
|
||||
|
||||
#if (SN_ARCH_TARGET != SN_ARCH_X86_64) && (SN_ARCH_TARGET != SN_ARCH_ARM64) && (SN_ARCH_TARGET != SN_ARCH_RISCV64) && \
|
||||
(SN_ARCH_TARGET != SN_ARCH_PPC64le)
|
||||
#error "SN_ARCH has an invalid value. Use SN_ARCH_<...> enum constants."
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef SN_IS_OS
|
||||
#define SN_IS_OS(os) ((SN_OS_TARGET) == (os))
|
||||
#endif
|
||||
|
||||
#ifndef SN_IS_ARCH
|
||||
#define SN_IS_ARCH(arch) ((SN_ARCH_TARGET) == (arch))
|
||||
#endif
|
||||
|
||||
#endif // SN_TARGET
|
||||
@@ -1,32 +0,0 @@
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <xmmintrin.h>
|
||||
|
||||
#ifndef SSC_INTERNAL
|
||||
#define SSC_INTERNAL
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define _CRT_SECURE_NO_WARNINGS 1
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define SSCDECL __cdecl
|
||||
#define SSCAPI __declspec(dllexport)
|
||||
#define FORCEINLINE __forceinline
|
||||
#include <windows.h>
|
||||
#elif defined(__clang__) || defined(__GNUC__)
|
||||
#define SSCDECL __attribute__((cdecl))
|
||||
#define SSCAPI __attribute__((dllexport))
|
||||
#define FORCEINLINE __attribute__((always_inline))
|
||||
#else
|
||||
#define SSCAPI
|
||||
#define SSCDECL
|
||||
#define FORCEINLINE
|
||||
#endif
|
||||
|
||||
#define SSCAPI_DEFINE
|
||||
|
||||
#define PRIVATE static
|
||||
#define INTERNAL extern
|
||||
|
||||
#endif //
|
||||
@@ -1,176 +0,0 @@
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#ifndef SSC_INTRIN
|
||||
#define SSC_INTRIN
|
||||
|
||||
#include "StgSharpC.h"
|
||||
#include <immintrin.h>
|
||||
#include <smmintrin.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <intrin.h>
|
||||
#include <isa_availability.h>
|
||||
#endif
|
||||
|
||||
#define LASTTWO(x) (x & 3)
|
||||
#define LAST(x) (x & 3)
|
||||
#define get_align_begin(x) ((x + 15) & (~15))
|
||||
|
||||
#define SSE_INSERT(source, target, reset3, reset2, reset1, reset0) \
|
||||
(LASTTWO(source - 1) << 6) | (LASTTWO(target - 1) << 4) | (LAST(reset3) << 3) | \
|
||||
(LAST(reset2) << 2) | (LAST(reset1) << 1) | LAST(reset0)
|
||||
#define SSE_INSERT_SIMPLE(source, target) SSE_INSERT(source, target, 0, 0, 0, 0)
|
||||
#define M256_PERMUTE(s3, s2, s1, s0) (LASTTWO(s3) << 6) | (LASTTWO(s2) << 4) | (LASTTWO(s1) << 2) | (LASTTWO(s0)
|
||||
|
||||
#define zero_vec _mm_setzero_ps()
|
||||
#define zero_vec_256 _mm256_setzero_ps()
|
||||
|
||||
typedef union uint64_u {
|
||||
uint64_t u64;
|
||||
uint32_t u32[2];
|
||||
} uint64_u;
|
||||
|
||||
typedef union mat_kernel{
|
||||
__m128 xmm[4];
|
||||
__m256 ymm[2];
|
||||
__m512 zmm[1];
|
||||
float m[4][4];
|
||||
}mat_kernel;
|
||||
|
||||
typedef union column_2 {
|
||||
__m256 stream;
|
||||
__m128 column[2];
|
||||
float m[4][2];
|
||||
} __2_columnset;
|
||||
|
||||
typedef union column_3 {
|
||||
__m256 part;
|
||||
__m128 column[3];
|
||||
float m[4][3];
|
||||
} __3_columnset;
|
||||
|
||||
typedef union column_4 {
|
||||
__m512 stream;
|
||||
__m256 half[2];
|
||||
__m128 column[4];
|
||||
float m[4][4];
|
||||
} __4_columnset;
|
||||
|
||||
typedef void(SSCDECL *VECTORNORMALIZEPROC)(__m128 *source, __m128 *target);
|
||||
typedef void(SSCDECL *DOTPROC)(void *transpose, __m128 *vector, __m128 *ans);
|
||||
typedef void(SSCDECL *MATRIXTRANSPOSEPROC)(void *source, void *target);
|
||||
typedef void(SSCDECL *MATRIXDETPROC)(void *mat, void *transpose);
|
||||
typedef void(SSCDECL *MATARITHMETIC)(void *left, void *right, void *ans);
|
||||
typedef void(SSCDECL *SCALERMATARITHMETIC)(void *left, void *right, void *ans);
|
||||
typedef uint64_t(SSCDECL *FACTORIALROC)(int n);
|
||||
|
||||
|
||||
#pragma region matix function
|
||||
|
||||
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);
|
||||
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);
|
||||
INTERNAL float SSCDECL det_mat4(__4_columnset *matrix, __4_columnset *transpose);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region dot
|
||||
|
||||
INTERNAL void FORCEINLINE SSCDECL dot_41_sse(__4_columnset *transpose, __m128 *vector, __m128 *ans);
|
||||
INTERNAL void FORCEINLINE SSCDECL dot_31_sse(__3_columnset *transpose, __m128 *vector, __m128 *ans);
|
||||
INTERNAL void FORCEINLINE SSCDECL dot_41_avx(__4_columnset *transpose, __m128 *vector, __m128 *ans);
|
||||
INTERNAL void FORCEINLINE SSCDECL dot_31_avx(__3_columnset *transpose, __m128 *vector, __m128 *ans);
|
||||
|
||||
INTERNAL void SSCDECL dot_32_sse(__3_columnset *transpose, __m128 *vector, __m128 *ans);
|
||||
INTERNAL void SSCDECL dot_32_avx(__3_columnset *transpose, __m128 *vector, __m128 *ans);
|
||||
INTERNAL void SSCDECL dot_42_sse(__4_columnset *transpose, __m128 *vector, __m128 *ans);
|
||||
INTERNAL void SSCDECL dot_42_avx(__4_columnset *transpose, __m128 *vector, __m128 *ans);
|
||||
|
||||
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);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region scaler_simd
|
||||
INTERNAL uint64_t SSCDECL factorial_simd_sse(int n);
|
||||
#pragma endregion
|
||||
|
||||
#pragma region string
|
||||
|
||||
INTERNAL int SSCDECL city_hash_simplify_sse(byte const *str, int length);
|
||||
INTERNAL int SSCDECL index_pair_sse(short const *str, uint32_t target, int length);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
typedef struct ssc_intrinsic {
|
||||
MATARITHMETIC add_m2;
|
||||
MATARITHMETIC add_m3;
|
||||
MATARITHMETIC add_m4;
|
||||
int (*city_hash_simplify)(byte *str, int length);
|
||||
MATRIXDETPROC det_matrix33;
|
||||
MATRIXDETPROC det_matrix44;
|
||||
DOTPROC dot_31;
|
||||
DOTPROC dot_32;
|
||||
DOTPROC dot_41;
|
||||
DOTPROC dot_42;
|
||||
DOTPROC dot_43;
|
||||
FACTORIALROC factorial_simd;
|
||||
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;
|
||||
MATRIXTRANSPOSEPROC transpose_33;
|
||||
MATRIXTRANSPOSEPROC transpose_34;
|
||||
MATRIXTRANSPOSEPROC transpose_42;
|
||||
MATRIXTRANSPOSEPROC transpose_43;
|
||||
MATRIXTRANSPOSEPROC transpose_44;
|
||||
} ssc_intrinsic;
|
||||
|
||||
typedef enum most_advanced_instruction {
|
||||
#ifdef _MSC_VER
|
||||
SSE = __IA_SUPPORT_SSE42,
|
||||
AVX256 = __IA_SUPPORT_VECTOR256,
|
||||
AVX512 = __IA_SUPPORT_VECTOR512,
|
||||
NEON
|
||||
#else
|
||||
SSE,
|
||||
AVX256,
|
||||
AVX512,
|
||||
NEON
|
||||
#endif
|
||||
} most_advanced_instruction;
|
||||
|
||||
#endif // !SSC_INTRIN
|
||||
@@ -1,3 +1,7 @@
|
||||
#include "sn_target.h"
|
||||
|
||||
#if SN_IS_ARCH(SN_ARCH_X86_64)
|
||||
|
||||
#include "sn_intrinsic.h"
|
||||
|
||||
DECLARE_BUF_PROC_ANS_SCALAR(float, sse, fill)
|
||||
@@ -315,3 +319,5 @@ DECLARE_BUF_PROC_RIGHT_ANS_SCALAR(double, 512, scalar_mul)
|
||||
ans[i].f64_z[1] = c1;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -12,6 +12,7 @@ PRIVATE void load_intrinsic_sse(sn_intrinsic *context);
|
||||
PRIVATE void load_intrinsic_avx(sn_intrinsic *context);
|
||||
PRIVATE void load_intrinsic_512(sn_intrinsic *context);
|
||||
|
||||
|
||||
PRIVATE int check_isa(most_advanced_instruction instruction_family)
|
||||
{
|
||||
if (instruction_family != NEON) {
|
||||
|
||||
@@ -1,175 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpLinearExpressionTest.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.Script;
|
||||
using StgSharp.Script.Express;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Schema;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal class ExpTestFuncSource : ExpFunctionSource
|
||||
{
|
||||
|
||||
public ExpTestFuncSource( string name, ScriptSourceTransmitter source )
|
||||
: base( name, source )
|
||||
{
|
||||
LocalVariables.Add(
|
||||
"a", new ExpIntNode( new Token( "a", 0, 0, TokenFlag.Number ), 1, false ) );
|
||||
LocalVariables.Add(
|
||||
"b", new ExpIntNode( new Token( "b", 0, 0, TokenFlag.Number ), 1, false ) );
|
||||
LocalVariables.Add(
|
||||
"c", new ExpIntNode( new Token( "c", 0, 0, TokenFlag.Number ), 1, false ) );
|
||||
LocalVariables.Add(
|
||||
"d", new ExpIntNode( new Token( "d", 0, 0, TokenFlag.Number ), 1, false ) );
|
||||
LocalVariables.Add(
|
||||
"e", new ExpIntNode( new Token( "e", 0, 0, TokenFlag.Number ), 1, false ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal class TestSchema : ExpSchema
|
||||
{
|
||||
|
||||
internal ExpTestFuncSource source;
|
||||
|
||||
public TestSchema( ExpTestFuncSource testType )
|
||||
{
|
||||
source = testType;
|
||||
}
|
||||
|
||||
public override void LoadFromSource( ExpSchemaSource source )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public override bool TryGetConst( string name, out ExpElementInstance c )
|
||||
{
|
||||
c = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool TryGetEntity( string name, out ExpEntitySource e )
|
||||
{
|
||||
e = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool TryGetFunction( string name, out ExpFunctionSource f )
|
||||
{
|
||||
if( name == "TestFunc" )
|
||||
{
|
||||
f = source;
|
||||
return true;
|
||||
}
|
||||
f = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool TryGetProcedure( string name, out ExpProcedureSource p )
|
||||
{
|
||||
p = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool TryGetRule( string name, out ExpRuleSource r )
|
||||
{
|
||||
r = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool TryGetSchemaInclude( string name, out ExpSchema include )
|
||||
{
|
||||
include = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool TryGetType( string name, out ExpTypeSource t )
|
||||
{
|
||||
t = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal static partial class Program
|
||||
{
|
||||
|
||||
private const string code = """
|
||||
a := ( b * E + d * 2 ) * d;
|
||||
(**)
|
||||
a := b + (c + d) - a;
|
||||
IF a = b THEN
|
||||
a := a * a;
|
||||
ELSE
|
||||
a := c * a;
|
||||
END_IF
|
||||
(**)
|
||||
CASE a OF
|
||||
1 : a := 1 + e ;
|
||||
OTHERWISE : a:=a;
|
||||
END_CASE
|
||||
REPEAT a := 1 TO 10;
|
||||
b := 10;
|
||||
END_REPEAT
|
||||
""";
|
||||
|
||||
public static void ExpLinearExpressionTest()
|
||||
{
|
||||
ExpressCompile.InitCompile();
|
||||
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter( "END", 0 );
|
||||
|
||||
foreach( string line in code.Split(
|
||||
Environment.NewLine, StringSplitOptions.RemoveEmptyEntries ) ) {
|
||||
transmitter.WriteLine( line );
|
||||
}
|
||||
transmitter.EndWriting();
|
||||
ExpTokenReader reader = new ExpTokenReader( transmitter );
|
||||
/**/
|
||||
ExpTestFuncSource func = new ExpTestFuncSource( "test", transmitter );
|
||||
TestSchema testSchema = new TestSchema( func );
|
||||
ExpSyntaxAnalyzer generator = new ExpSyntaxAnalyzer( testSchema, func );
|
||||
/**/
|
||||
|
||||
while( reader.TryReadToken( out Token t ) )
|
||||
{
|
||||
Console.WriteLine( t.Value );
|
||||
generator.AppendToken( t );
|
||||
}
|
||||
Console.WriteLine( "OK" );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Program"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
// 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
|
||||
@@ -39,16 +39,11 @@ namespace StgSharp
|
||||
|
||||
private static string testExpPath = @"D:\Programmer\stepcode\data\ap203\ap203.exp";
|
||||
|
||||
internal static unsafe void Main(
|
||||
string[] args
|
||||
)
|
||||
internal static unsafe void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
World.Initialize()
|
||||
.UseModule<NumericalModule>()
|
||||
.UseModule<GraphicModule>()
|
||||
.InitializeModule();
|
||||
World.Initialize().UseModule<NumericalModule>().UseModule<GraphicModule>().InitializeModule();
|
||||
|
||||
// TestRender();
|
||||
/**/
|
||||
@@ -56,14 +51,11 @@ namespace StgSharp
|
||||
unchecked {
|
||||
hlsf = new((nuint)(64 * (ulong)10000 * 10000));
|
||||
}
|
||||
Matrix<double> m = Matrix<double>.Create(4000, 4000, MatrixLayout.DenseRectangle,
|
||||
hlsf);
|
||||
Matrix<double> m = Matrix<double>.Create(4000, 4000, MatrixLayout.DenseRectangle, hlsf);
|
||||
MatrixCompute.Fill(m, 1.0f);
|
||||
Matrix<double> n = Matrix<double>.Create(4000, 4000, MatrixLayout.DenseRectangle,
|
||||
hlsf);
|
||||
Matrix<double> n = Matrix<double>.Create(4000, 4000, MatrixLayout.DenseRectangle, hlsf);
|
||||
MatrixCompute.Fill(n, 1.0f);
|
||||
Matrix<double> p = Matrix<double>.Create(4000, 4000, MatrixLayout.DenseRectangle,
|
||||
hlsf);
|
||||
Matrix<double> p = Matrix<double>.Create(4000, 4000, MatrixLayout.DenseRectangle, hlsf);
|
||||
MatrixCompute.Fill(p, 0.0f);
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="StepReadingTest.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.Model.Step;
|
||||
using StgSharp.PipeLine;
|
||||
using StgSharp.Script.Express;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal static partial class Program
|
||||
{
|
||||
|
||||
private static string[] stepFile = [
|
||||
@"D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\StepModel\_NPart#8299.stp",
|
||||
@"D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\StepModel\几何毛坯.STEP",
|
||||
];
|
||||
|
||||
private static void TestStepRead()
|
||||
{
|
||||
ExpressCompile.InitCompile();
|
||||
if( StepReader.FromFile( stepFile[ 1 ], out StepReader reader ) )
|
||||
{
|
||||
StepModel model = reader.ReadToModelSingleThread();
|
||||
PipeLineRunner.SetMaxTaskCount( 1 );
|
||||
string[] info = model.ShowStructure( int.MaxValue );
|
||||
FileStream fs = File.Open( "D:\\struct.txt", FileMode.Create,
|
||||
FileAccess.ReadWrite );
|
||||
StreamWriter sw = new StreamWriter( fs );
|
||||
foreach( string line in info )
|
||||
{
|
||||
sw.WriteLine( line );
|
||||
Console.WriteLine( line );
|
||||
}
|
||||
sw.Dispose();
|
||||
fs.Dispose();
|
||||
|
||||
//model.InitEntity();
|
||||
reader.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="TestFileRead.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.Script.Express;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal static partial class Program
|
||||
{
|
||||
|
||||
private static void TestFileRead()
|
||||
{
|
||||
ExpressCompile.InitCompile();
|
||||
ExpFileSource reader = new ExpFileSource( testExpPath );
|
||||
ExpSchemaSource schemaSource = new ExpSchemaSource();
|
||||
schemaSource.ReadSchema( reader );
|
||||
|
||||
ExpSchema schema = schemaSource.Compile( ExpressCompileOption.Translate );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user