From 7e3ed8b0fd2009ce66f1c713054e726107522137 Mon Sep 17 00:00:00 2001 From: Youmu Liu <105042599+Nitload-NSI@users.noreply.github.com> Date: Mon, 2 Mar 2026 17:33:03 +0800 Subject: [PATCH] decide to use L4 to solve numa and pack problem for large compute. --- StgSharp.Common/Collections/SwissTable.cs | 59 +++++++++++++ StgSharp.Native/sn-head/sn_intrinsic.h | 1 - StgSharp.Native/sn-head/sn_intrinsic.std.h | 53 +++++++----- StgSharp.Native/sn-src/load_intrinsic.x86.c | 95 ++++++++++----------- StgSharp.Native/sn-src/m.basic.x86.c | 21 +++-- StgSharp.Native/sn-src/m.bufop.x86.c | 39 +++++++++ StgSharp.Native/sn-src/m.fma_tile.x86.c | 5 +- StgSharp.Native/sn-src/simdid_compare.x86.c | 2 +- todo.md | 3 +- 9 files changed, 192 insertions(+), 86 deletions(-) create mode 100644 StgSharp.Common/Collections/SwissTable.cs diff --git a/StgSharp.Common/Collections/SwissTable.cs b/StgSharp.Common/Collections/SwissTable.cs new file mode 100644 index 00000000..b9f62859 --- /dev/null +++ b/StgSharp.Common/Collections/SwissTable.cs @@ -0,0 +1,59 @@ +//----------------------------------------------------------------------- +// ----------------------------------------------------------------------- +// file="SwissTable" +// Project: StgSharp +// AuthorGroup: Nitload +// Copyright (c) Nitload. 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.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; + +namespace StgSharp.Collections +{ + public unsafe class SwissTable + { + public bool TryGet(nint key, out nint value) + { + throw new NotImplementedException(); + /* + * hash = CRC32 of key + * entry = low 8 of hash + * ctrl = 8-15 of hash + * index = rest of hash + * find value of hash + */ + } + + private struct Entry + { + public fixed byte entry[256]; //entry is fully occupied, or empty, or deleted + // array of ctrl array + // array of value array + // array of hash array + } + } +} diff --git a/StgSharp.Native/sn-head/sn_intrinsic.h b/StgSharp.Native/sn-head/sn_intrinsic.h index 30888e7e..77496e3c 100644 --- a/StgSharp.Native/sn-head/sn_intrinsic.h +++ b/StgSharp.Native/sn-head/sn_intrinsic.h @@ -91,7 +91,6 @@ typedef struct mat_intrinsic { UNI_MK_PROC buffer_scalar_mul; UNI_MK_PROC buffer_sub; UNI_MK_PROC buffer_transpose; - UNI_MK_PROC clear_panel; UNI_MK_PROC ker_fma; UNI_MK_PROC ker_tile_fma; UNI_MK_PROC pivot; diff --git a/StgSharp.Native/sn-head/sn_intrinsic.std.h b/StgSharp.Native/sn-head/sn_intrinsic.std.h index 5b089c11..1cd4c27e 100644 --- a/StgSharp.Native/sn-head/sn_intrinsic.std.h +++ b/StgSharp.Native/sn-head/sn_intrinsic.std.h @@ -17,6 +17,11 @@ INTERNAL void SN_DECL STD_MK_PROC_NAME(T_type, T_arch, T_feature, \ T_op)(MAT_TASK(T_type) const *task) +#define _SN_STD__PROBE_0 0 +#define _SN_STD__PROBE_1 1 +#define SN_STD__PROBE_PRINT(x) _SN_STD__PROBE_##x +#define SN_STD__PROBE(x) SN_STD__PROBE_PRINT(x) + #pragma region param styles #define _SN_MATPROC_LEFT_RIGHT_ANS 1 @@ -25,32 +30,32 @@ #define _SN_MATPROC_RIGHT_ANS_SCALAR 1 #define _SN_MATPROC_ANS_SCALAR 1 -#define _SN_MK_EXPAND_RIGHT_ANS(T) \ - MAT_KERNEL(T) const *right = mat_task_local->mat_1; \ - MAT_KERNEL(T) *restrict ans = mat_task_local->mat_2; +#define _SN_MK_EXPAND_RIGHT_ANS \ + _mat_kernel_local const *right = mat_task_local->mat_1; \ + _mat_kernel_local *restrict ans = mat_task_local->mat_2; -#define _SN_MK_EXPAND_LEFT_RIGHT_ANS(T) \ - MAT_KERNEL(T) const *left = mat_task_local->mat_0; \ - MAT_KERNEL(T) const *right = mat_task_local->mat_1; \ - MAT_KERNEL(T) *restrict ans = mat_task_local->mat_2; +#define _SN_MK_EXPAND_LEFT_RIGHT_ANS(T) \ + _mat_kernel_local const *left = mat_task_local->mat_0; \ + _mat_kernel_local const *right = mat_task_local->mat_1; \ + _mat_kernel_local *restrict ans = mat_task_local->mat_2; -#define _SN_MK_EXPAND_RIGHT_ANS_SCALAR(T) \ - MAT_KERNEL(T) const *right = mat_task_local->mat_1; \ - MAT_KERNEL(T) *restrict ans = mat_task_local->mat_2; \ - void *restrict scalar = mat_task_local->scalar; +#define _SN_MK_EXPAND_RIGHT_ANS_SCALAR(T) \ + _mat_kernel_local const *right = mat_task_local->mat_1; \ + _mat_kernel_local *restrict ans = mat_task_local->mat_2; \ + scalar_pack *restrict scalar = mat_task_local->scalar; -#define _SN_MK_EXPAND_LEFT_RIGHT_ANS_SCALAR(T) \ - MAT_KERNEL(T) const *left = mat_task_local->mat_0; \ - MAT_KERNEL(T) const *right = mat_task_local->mat_1; \ - MAT_KERNEL(T) *restrict ans = mat_task_local->mat_2; \ - void *restrict scalar = mat_task_local->scalar; +#define _SN_MK_EXPAND_LEFT_RIGHT_ANS_SCALAR(T) \ + _mat_kernel_local const *left = mat_task_local->mat_0; \ + _mat_kernel_local const *right = mat_task_local->mat_1; \ + _mat_kernel_local *restrict ans = mat_task_local->mat_2; \ + scalar_pack *restrict scalar = mat_task_local->scalar; #define _SN_MK_EXPAND_ANS_SCALAR(T) \ MAT_KERNEL(T) *restrict ans = mat_task_local->mat_2; \ scalar_pack *restrict scalar = &(mat_task_local->padding); #define _SN_PARAM_STYLE(T) _SN_MATPROC_##T -#define _SN_MK_EXPAND_PARAM(style, T) _SN_MK_EXPAND_##style##(T) +#define _SN_MK_EXPAND_PARAM(style) _SN_MK_EXPAND_##style #pragma endregion @@ -65,6 +70,8 @@ size_t count = UNSAFE_AS(size_t, task->padding.data[1]); #define _MK_MKPROC_EXPAND_INDEX_KERNEL \ + size_t i = UNSAFE_AS(size_t, task->i); \ + size_t j = UNSAFE_AS(size_t, task->j); \ size_t common_i = UNSAFE_AS(size_t, task->common_i); \ size_t common_j = UNSAFE_AS(size_t, task->common_j); \ size_t common_k = UNSAFE_AS(size_t, task->common_k); @@ -74,10 +81,10 @@ #pragma endregion -#define __mk_param_std(mem, param, T) \ - static_assert((_SN_PARAM_STYLE(param)) == 1, \ - "EXPAND_PARAM: invalid param style '" #param "'"); \ - static_assert((_SN_MEM_LAYOUT(mem)) == 1, "EXPAND_PARAM: invalid mem layout '" #mem "'"); \ - typedef MAT_TASK(T) _mat_task_local; \ - _SN_MK_EXPAND_PARAM(param, T) _SN_MK_EXPAND_MEM(mem) +#define __mk_param_std(mem, param, T) \ + typedef MAT_KERNEL(T) _mat_kernel_local; \ + typedef MAT_TASK(T) _mat_task_local; \ + _mat_task_local *_ = (_SN_PARAM_STYLE(param), (_SN_MEM_LAYOUT(mem)), task); \ + _SN_MK_EXPAND_PARAM(param); \ + _SN_MK_EXPAND_MEM(mem) #endif // !SN_INTRINSIC_PARAM_EXPAND diff --git a/StgSharp.Native/sn-src/load_intrinsic.x86.c b/StgSharp.Native/sn-src/load_intrinsic.x86.c index 2e56ff57..746bc383 100644 --- a/StgSharp.Native/sn-src/load_intrinsic.x86.c +++ b/StgSharp.Native/sn-src/load_intrinsic.x86.c @@ -4,7 +4,8 @@ #include "StgSharpNative.h" #include "sn_intrinsic.h" -#include "sn_intrincontext.x86.h" +#include "sn_intrinsic.std.h" +#include "sn_intrinsic.context.x86.h" #if defined(_MSC_VER) && !defined(__clang__) #include @@ -51,24 +52,22 @@ void load_intrinsic_sse(sn_intrinsic *context, SIMDID id) context->factorial_simd = factorial_simd_sse; context->index_pair = index_pair_sse; - context->mat[F32].buffer_add = BUF_PROC(float, sse, , add); - context->mat[F32].buffer_fill = BUF_PROC(float, sse, , fill); - context->mat[F32].buffer_scalar_mul = BUF_PROC(float, sse, , scalar_mul); - context->mat[F32].buffer_sub = BUF_PROC(float, sse, , sub); - context->mat[F32].buffer_transpose = KER_PROC(float, sse, , transpose); - context->mat[F32].clear_panel = PNL_PROC(float, sse, , clear); - context->mat[F32].ker_fma = KER_PROC(float, sse, , fma); - context->mat[F32].ker_tile_fma = KERTILE_PROC(float, sse, , fma); + context->mat[F32].buffer_add = STD_MK_PROC_NAME(float, sse, , add); + context->mat[F32].buffer_fill = STD_MK_PROC_NAME(float, sse, , fill); + context->mat[F32].buffer_scalar_mul = STD_MK_PROC_NAME(float, sse, , scalar_mul); + context->mat[F32].buffer_sub = STD_MK_PROC_NAME(float, sse, , sub); + context->mat[F32].buffer_transpose = STD_MK_PROC_NAME(float, sse, , transpose); + context->mat[F32].ker_fma = STD_MK_PROC_NAME(float, sse, , fma); + context->mat[F32].ker_tile_fma = STD_MK_PROC_NAME(float, sse, , fma); context->mat[F32].pivot = NULL; - context->mat[F64].buffer_add = BUF_PROC(double, sse, , add); - context->mat[F64].buffer_fill = BUF_PROC(double, sse, , fill); - context->mat[F64].buffer_scalar_mul = BUF_PROC(double, sse, , scalar_mul); - context->mat[F64].buffer_sub = BUF_PROC(double, sse, , sub); + context->mat[F64].buffer_add = STD_MK_PROC_NAME(double, sse, , add); + context->mat[F64].buffer_fill = STD_MK_PROC_NAME(double, sse, , fill); + context->mat[F64].buffer_scalar_mul = STD_MK_PROC_NAME(double, sse, , scalar_mul); + context->mat[F64].buffer_sub = STD_MK_PROC_NAME(double, sse, , sub); context->mat[F64].buffer_transpose = NULL; - context->mat[F64].clear_panel = PNL_PROC(double, sse, , clear); - context->mat[F64].ker_fma = KER_PROC(double, sse, , fma); - context->mat[F64].ker_tile_fma = KERTILE_PROC(double, sse, , fma); + context->mat[F64].ker_fma = STD_MK_PROC_NAME(double, sse, , fma); + context->mat[F64].ker_tile_fma = STD_MK_PROC_NAME(double, sse, , fma); context->mat[F64].pivot = NULL; context->vec_f32_normalize_3 = f32_normalize; @@ -84,28 +83,26 @@ void load_intrinsic_avx(sn_intrinsic *context, SIMDID id) context->factorial_simd = factorial_simd_sse; context->index_pair = index_pair_sse; - context->mat[F32].buffer_add = BUF_PROC(float, avx, , add); - context->mat[F32].buffer_fill = BUF_PROC(float, avx, , fill); - context->mat[F32].buffer_scalar_mul = BUF_PROC(float, avx, , scalar_mul); - context->mat[F32].buffer_sub = BUF_PROC(float, avx, , sub); - context->mat[F32].buffer_transpose = KER_PROC(float, avx, , transpose); - context->mat[F32].clear_panel = PNL_PROC(float, avx, , clear); - context->mat[F32].ker_fma = is_fma ? KER_PROC(float, avx, , fma) : - KER_PROC(float, avx, _fma, fma); - context->mat[F32].ker_tile_fma = is_fma ? KERTILE_PROC(float, avx, , fma) : - KERTILE_PROC(float, avx, _fma, fma); + context->mat[F32].buffer_add = STD_MK_PROC_NAME(float, avx, , add); + context->mat[F32].buffer_fill = STD_MK_PROC_NAME(float, avx, , fill); + context->mat[F32].buffer_scalar_mul = STD_MK_PROC_NAME(float, avx, , scalar_mul); + context->mat[F32].buffer_sub = STD_MK_PROC_NAME(float, avx, , sub); + context->mat[F32].buffer_transpose = STD_MK_PROC_NAME(float, avx, , transpose); + context->mat[F32].ker_fma = is_fma ? STD_MK_PROC_NAME(float, avx, , fma) : + STD_MK_PROC_NAME(float, avx, _fma, fma); + context->mat[F32].ker_tile_fma = is_fma ? STD_MK_PROC_NAME(float, avx, , fma) : + STD_MK_PROC_NAME(float, avx, _fma, fma); context->mat[F32].pivot = NULL; - context->mat[F64].buffer_add = BUF_PROC(double, avx, , add); - context->mat[F64].buffer_fill = BUF_PROC(double, avx, , fill); - context->mat[F64].buffer_scalar_mul = BUF_PROC(double, avx, , scalar_mul); - context->mat[F64].buffer_sub = BUF_PROC(double, avx, , sub); + context->mat[F64].buffer_add = STD_MK_PROC_NAME(double, avx, , add); + context->mat[F64].buffer_fill = STD_MK_PROC_NAME(double, avx, , fill); + context->mat[F64].buffer_scalar_mul = STD_MK_PROC_NAME(double, avx, , scalar_mul); + context->mat[F64].buffer_sub = STD_MK_PROC_NAME(double, avx, , sub); context->mat[F64].buffer_transpose = NULL; - context->mat[F64].clear_panel = PNL_PROC(double, avx, , clear); - context->mat[F64].ker_fma = is_fma ? KER_PROC(double, avx, , fma) : - KER_PROC(double, avx, _fma, fma); - context->mat[F64].ker_tile_fma = is_fma ? KERTILE_PROC(double, avx, , fma) : - KERTILE_PROC(double, avx, _fma, fma); + context->mat[F64].ker_fma = is_fma ? STD_MK_PROC_NAME(double, avx, , fma) : + STD_MK_PROC_NAME(double, avx, _fma, fma); + context->mat[F64].ker_tile_fma = is_fma ? STD_MK_PROC_NAME(double, avx, , fma) : + STD_MK_PROC_NAME(double, avx, _fma, fma); context->mat[F64].pivot = NULL; context->vec_f32_normalize_3 = f32_normalize; @@ -117,24 +114,22 @@ void load_intrinsic_512(sn_intrinsic *context, SIMDID id) context->factorial_simd = factorial_simd_sse; context->index_pair = index_pair_sse; - context->mat[F32].buffer_add = BUF_PROC(float, 512, , add); - context->mat[F32].buffer_fill = BUF_PROC(float, 512, , fill); - context->mat[F32].buffer_scalar_mul = BUF_PROC(float, 512, , scalar_mul); - context->mat[F32].buffer_sub = BUF_PROC(float, 512, , sub); - context->mat[F32].buffer_transpose = KER_PROC(float, 512, , transpose); - context->mat[F32].clear_panel = PNL_PROC(float, 512, , clear); - context->mat[F32].ker_fma = KER_PROC(float, 512, , fma); - context->mat[F32].ker_tile_fma = KERTILE_PROC(float, 512, , fma); + context->mat[F32].buffer_add = STD_MK_PROC_NAME(float, 512, , add); + context->mat[F32].buffer_fill = STD_MK_PROC_NAME(float, 512, , fill); + context->mat[F32].buffer_scalar_mul = STD_MK_PROC_NAME(float, 512, , scalar_mul); + context->mat[F32].buffer_sub = STD_MK_PROC_NAME(float, 512, , sub); + context->mat[F32].buffer_transpose = STD_MK_PROC_NAME(float, 512, , transpose); + context->mat[F32].ker_fma = STD_MK_PROC_NAME(float, 512, , fma); + context->mat[F32].ker_tile_fma = STD_MK_PROC_NAME(float, 512, , fma); context->mat[F32].pivot = NULL; - context->mat[F64].buffer_add = BUF_PROC(double, 512, , add); - context->mat[F64].buffer_fill = BUF_PROC(double, 512, , fill); - context->mat[F64].buffer_scalar_mul = BUF_PROC(double, 512, , scalar_mul); - context->mat[F64].buffer_sub = BUF_PROC(double, 512, , sub); + context->mat[F64].buffer_add = STD_MK_PROC_NAME(double, 512, , add); + context->mat[F64].buffer_fill = STD_MK_PROC_NAME(double, 512, , fill); + context->mat[F64].buffer_scalar_mul = STD_MK_PROC_NAME(double, 512, , scalar_mul); + context->mat[F64].buffer_sub = STD_MK_PROC_NAME(double, 512, , sub); context->mat[F64].buffer_transpose = NULL; - context->mat[F64].clear_panel = PNL_PROC(double, 512, , clear); - context->mat[F64].ker_fma = KER_PROC(double, 512, , fma); - context->mat[F64].ker_tile_fma = KERTILE_PROC(double, 512, , fma); + context->mat[F64].ker_fma = STD_MK_PROC_NAME(double, 512, , fma); + context->mat[F64].ker_tile_fma = STD_MK_PROC_NAME(double, 512, , fma); context->mat[F64].pivot = NULL; context->vec_f32_normalize_3 = f32_normalize; diff --git a/StgSharp.Native/sn-src/m.basic.x86.c b/StgSharp.Native/sn-src/m.basic.x86.c index f28f7adf..a5ee5c95 100644 --- a/StgSharp.Native/sn-src/m.basic.x86.c +++ b/StgSharp.Native/sn-src/m.basic.x86.c @@ -6,10 +6,11 @@ #include "sn_intrinsic.context.x86.h" #include "sn_intrinsic.std.h" - // Matrix transpose implementations SN_MK_PROC_DECL_STD(float, sse, , transpose) { + __mk_param_std(KERNEL, RIGHT_ANS, float); + register __m128 col0 = right->f32_x[0]; register __m128 col1 = right->f32_x[1]; register __m128 col2 = right->f32_x[2]; @@ -19,14 +20,15 @@ SN_MK_PROC_DECL_STD(float, sse, , transpose) register __m128 tmp2 = _mm_unpacklo_ps(col2, col3); register __m128 tmp3 = _mm_unpackhi_ps(col2, col3); - ans->f32_x[0] = _mm_movelh_ps(tmp0, tmp2); - ans->f32_x[1] = _mm_movehl_ps(tmp2, tmp0); - ans->f32_x[2] = _mm_movelh_ps(tmp1, tmp3); - ans->f32_x[3] = _mm_movehl_ps(tmp3, tmp1); + _mm_store_ps(&(ans->f32_x[0]), _mm_movelh_ps(tmp0, tmp2)); + _mm_store_ps(&(ans->f32_x[1]), _mm_movehl_ps(tmp2, tmp0)); + _mm_store_ps(&(ans->f32_x[2]), _mm_movelh_ps(tmp1, tmp3)); + _mm_store_ps(&(ans->f32_x[3]), _mm_movehl_ps(tmp3, tmp1)); } SN_MK_PROC_DECL_STD(float, avx, , transpose) { + __mk_param_std(KERNEL, RIGHT_ANS, float); register __m256 col_low = right->f32_y[0]; register __m256 col_high = right->f32_y[1]; @@ -36,18 +38,21 @@ SN_MK_PROC_DECL_STD(float, avx, , transpose) col_low = _mm256_permute2f128_ps(unpack_low, unpack_high, 0x20); col_high = _mm256_permute2f128_ps(unpack_low, unpack_high, 0x31); - ans->f32_y[0] = _mm256_shuffle_ps(col_high, col_low, _MM_SHUFFLE(2, 0, 2, 0)); - ans->f32_y[1] = _mm256_shuffle_ps(col_high, col_low, _MM_SHUFFLE(3, 1, 3, 1)); + _mm256_store_ps(&(ans->f32_y[0]), + _mm256_shuffle_ps(col_high, col_low, _MM_SHUFFLE(2, 0, 2, 0))); + _mm256_store_ps(&(ans->f32_y[1]), + _mm256_shuffle_ps(col_high, col_low, _MM_SHUFFLE(3, 1, 3, 1))); } SN_MK_PROC_DECL_STD(float, 512, , transpose) { + __mk_param_std(KERNEL, RIGHT_ANS, float); register __m512 matrix = right->f32_z[0]; const __m512i transpose_indices = _mm512_setr_epi32(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15); - ans->f32_z[0] = _mm512_permutexvar_ps(transpose_indices, matrix); + _mm512_store_ps(&(ans->f32_z[0]), _mm512_permutexvar_ps(transpose_indices, matrix)); } #endif diff --git a/StgSharp.Native/sn-src/m.bufop.x86.c b/StgSharp.Native/sn-src/m.bufop.x86.c index a42b5266..686ad429 100644 --- a/StgSharp.Native/sn-src/m.bufop.x86.c +++ b/StgSharp.Native/sn-src/m.bufop.x86.c @@ -20,6 +20,7 @@ SN_MK_PROC_DECL_STD(float, sse, , fill) SN_MK_PROC_DECL_STD(float, avx, , fill) { + __mk_param_std(BUFFER, ANS_SCALAR, float); register __m256 vec = _mm256_broadcast_ss(((float *)(scalar->data))); for (size_t i = 0; i < count; i++) { ans[i].f32_y[0] = vec; @@ -29,6 +30,7 @@ SN_MK_PROC_DECL_STD(float, avx, , fill) SN_MK_PROC_DECL_STD(float, 512, , fill) { + __mk_param_std(BUFFER, ANS_SCALAR, float); register __m512 vec = _mm512_broadcastss_ps(((__m128 *)(scalar->data))[0]); for (size_t i = 0; i < count; i++) { ans[i].f32_z[0] = vec; @@ -37,6 +39,7 @@ SN_MK_PROC_DECL_STD(float, 512, , fill) SN_MK_PROC_DECL_STD(double, sse, , fill) { + __mk_param_std(BUFFER, ANS_SCALAR, float); register __m128d vec = _mm_set1_pd(((double *)(scalar->data))[0]); for (size_t i = 0; i < count; i++) { ans[i].f64_x[0] = vec; @@ -52,6 +55,7 @@ SN_MK_PROC_DECL_STD(double, sse, , fill) SN_MK_PROC_DECL_STD(double, avx, , fill) { + __mk_param_std(BUFFER, ANS_SCALAR, float); register __m256d vec = _mm256_broadcast_sd(((double *)(scalar->data))); for (size_t i = 0; i < count; i++) { ans[i].f64_y[0] = vec; @@ -63,6 +67,7 @@ SN_MK_PROC_DECL_STD(double, avx, , fill) SN_MK_PROC_DECL_STD(double, 512, , fill) { + __mk_param_std(BUFFER, ANS_SCALAR, float); register __m512d vec = _mm512_broadcastsd_pd(_mm_loadu_pd(scalar)); for (size_t i = 0; i < count; i++) { ans[i].f64_z[0] = vec; @@ -89,6 +94,8 @@ SN_MK_PROC_DECL_STD(float, sse, , add) SN_MK_PROC_DECL_STD(float, avx, , add) { + __mk_param_std(BUFFER, LEFT_RIGHT_ANS, float); + for (size_t i = 0; i < count; i++) { size_t s = sizeof(MAT_KERNEL(float)); register __m256 c0 = _mm256_add_ps(left[i].f32_y[0], right[i].f32_y[0]); @@ -100,6 +107,8 @@ SN_MK_PROC_DECL_STD(float, avx, , add) SN_MK_PROC_DECL_STD(float, 512, , add) { + __mk_param_std(BUFFER, LEFT_RIGHT_ANS, float); + for (size_t i = 0; i < count; i++) { register __m512 c0 = _mm512_add_ps(left[i].f32_z[0], right[i].f32_z[0]); ans[i].f32_z[0] = c0; @@ -107,6 +116,8 @@ SN_MK_PROC_DECL_STD(float, 512, , add) } SN_MK_PROC_DECL_STD(double, sse, , add) { + __mk_param_std(BUFFER, LEFT_RIGHT_ANS, float); + for (size_t i = 0; i < count; i++) { register __m128d c0 = _mm_add_pd(_mm_castps_pd(left[i].f32_x[0]), _mm_castps_pd(right[i].f32_x[0])); @@ -138,6 +149,8 @@ SN_MK_PROC_DECL_STD(double, sse, , add) SN_MK_PROC_DECL_STD(double, avx, , add) { + __mk_param_std(BUFFER, LEFT_RIGHT_ANS, float); + for (size_t i = 0; i < count; i++) { size_t s = sizeof(MAT_KERNEL(float)); register __m256d c0 = _mm256_add_pd(left[i].f64_y[0], right[i].f64_y[0]); @@ -153,6 +166,8 @@ SN_MK_PROC_DECL_STD(double, avx, , add) SN_MK_PROC_DECL_STD(double, 512, , add) { + __mk_param_std(BUFFER, LEFT_RIGHT_ANS, float); + for (size_t i = 0; i < count; i++) { register __m512d c0 = _mm512_add_pd(left[i].f64_z[0], right[i].f64_z[0]); register __m512d c1 = _mm512_add_pd(left[i].f64_z[1], right[i].f64_z[1]); @@ -163,6 +178,8 @@ SN_MK_PROC_DECL_STD(double, 512, , add) SN_MK_PROC_DECL_STD(float, sse, , sub) { + __mk_param_std(BUFFER, LEFT_RIGHT_ANS, float); + for (size_t i = 0; i < count; i++) { register __m128 c0 = _mm_sub_ps(left[i].f32_x[0], right[i].f32_x[0]); register __m128 c1 = _mm_sub_ps(left[i].f32_x[1], right[i].f32_x[1]); @@ -178,6 +195,8 @@ SN_MK_PROC_DECL_STD(float, sse, , sub) SN_MK_PROC_DECL_STD(float, avx, , sub) { + __mk_param_std(BUFFER, LEFT_RIGHT_ANS, float); + for (size_t i = 0; i < count; i++) { register __m256 c0 = _mm256_sub_ps(left[i].f32_y[0], right[i].f32_y[0]); register __m256 c1 = _mm256_sub_ps(left[i].f32_y[1], right[i].f32_y[1]); @@ -188,6 +207,8 @@ SN_MK_PROC_DECL_STD(float, avx, , sub) SN_MK_PROC_DECL_STD(float, 512, , sub) { + __mk_param_std(BUFFER, LEFT_RIGHT_ANS, float); + for (size_t i = 0; i < count; i++) { register __m512 c0 = _mm512_sub_ps(left[i].f32_z[0], right[i].f32_z[0]); ans[i].f32_z[0] = c0; @@ -196,6 +217,8 @@ SN_MK_PROC_DECL_STD(float, 512, , sub) SN_MK_PROC_DECL_STD(double, sse, , sub) { + __mk_param_std(BUFFER, LEFT_RIGHT_ANS, float); + for (size_t i = 0; i < count; i++) { register __m128d c0 = _mm_sub_pd(left[i].f64_x[0], right[i].f64_x[0]); register __m128d c1 = _mm_sub_pd(left[i].f64_x[1], right[i].f64_x[1]); @@ -219,6 +242,8 @@ SN_MK_PROC_DECL_STD(double, sse, , sub) SN_MK_PROC_DECL_STD(double, avx, , sub) { + __mk_param_std(BUFFER, LEFT_RIGHT_ANS, float); + for (size_t i = 0; i < count; i++) { register __m256 c0 = _mm256_sub_ps(left[i].f32_y[0], right[i].f32_y[0]); register __m256 c1 = _mm256_sub_ps(left[i].f32_y[1], right[i].f32_y[1]); @@ -229,6 +254,8 @@ SN_MK_PROC_DECL_STD(double, avx, , sub) SN_MK_PROC_DECL_STD(double, 512, , sub) { + __mk_param_std(BUFFER, LEFT_RIGHT_ANS, float); + for (size_t i = 0; i < count; i++) { register __m512 c0 = _mm512_sub_ps(left[i].f32_z[0], right[i].f32_z[0]); ans[i].f32_z[0] = c0; @@ -237,6 +264,8 @@ SN_MK_PROC_DECL_STD(double, 512, , sub) SN_MK_PROC_DECL_STD(float, sse, , scalar_mul) { + __mk_param_std(BUFFER, RIGHT_ANS_SCALAR, float); + register __m128 vec = _mm_set_ps1(((float *)(scalar->data))[0]); for (size_t i = 0; i < count; i++) { register __m128 c0 = _mm_mul_ps(right[i].f32_x[0], vec); @@ -253,6 +282,8 @@ SN_MK_PROC_DECL_STD(float, sse, , scalar_mul) SN_MK_PROC_DECL_STD(float, avx, , scalar_mul) { + __mk_param_std(BUFFER, RIGHT_ANS_SCALAR, float); + register __m256 vec = _mm256_broadcast_ss(((float *)(scalar->data))); for (size_t i = 0; i < count; i++) { register __m256 c0 = _mm256_mul_ps(right[i].f32_y[0], vec); @@ -265,6 +296,8 @@ SN_MK_PROC_DECL_STD(float, avx, , scalar_mul) SN_MK_PROC_DECL_STD(float, 512, , scalar_mul) { + __mk_param_std(BUFFER, RIGHT_ANS_SCALAR, float); + register __m512 vec = _mm512_broadcastss_ps(((__m128 *)(scalar->data))[0]); for (size_t i = 0; i < count; i++) { register __m512 c0 = _mm512_mul_ps(right[i].f32_z[0], vec); @@ -275,6 +308,8 @@ SN_MK_PROC_DECL_STD(float, 512, , scalar_mul) SN_MK_PROC_DECL_STD(double, sse, , scalar_mul) { + __mk_param_std(BUFFER, RIGHT_ANS_SCALAR, double); + register __m128d vec = _mm_set1_pd(((double *)(scalar->data))[0]); for (size_t i = 0; i < count; i++) { register __m128d c0 = _mm_mul_pd(right[i].f64_x[0], vec); @@ -299,6 +334,8 @@ SN_MK_PROC_DECL_STD(double, sse, , scalar_mul) SN_MK_PROC_DECL_STD(double, avx, , scalar_mul) { + __mk_param_std(BUFFER, RIGHT_ANS_SCALAR, double); + register __m256d vec = _mm256_broadcast_sd(((double *)(scalar->data))); for (size_t i = 0; i < count; i++) { register __m256d c0 = _mm256_mul_pd(right[i].f64_y[0], vec); @@ -315,6 +352,8 @@ SN_MK_PROC_DECL_STD(double, avx, , scalar_mul) SN_MK_PROC_DECL_STD(double, 512, , scalar_mul) { + __mk_param_std(BUFFER, RIGHT_ANS_SCALAR, double); + register __m512d vec = _mm512_broadcastsd_pd(_mm_load_pd(scalar)); for (size_t i = 0; i < count; i++) { register __m512d c0 = _mm512_mul_pd(right[i].f64_z[0], vec); diff --git a/StgSharp.Native/sn-src/m.fma_tile.x86.c b/StgSharp.Native/sn-src/m.fma_tile.x86.c index 2a067d50..631ba2bd 100644 --- a/StgSharp.Native/sn-src/m.fma_tile.x86.c +++ b/StgSharp.Native/sn-src/m.fma_tile.x86.c @@ -3,7 +3,8 @@ #if SN_IS_ARCH(SN_ARCH_X86_64) #include "sn_intrinsic.h" -#include "sn_intrincontext.x86.h" +#include "sn_intrinsic.std.h" +#include "sn_intrinsic.context.x86.h" #define _FMA_SELECT(i) _MM_SHUFFLE(i, i, i, i) @@ -13,6 +14,8 @@ SN_MK_PROC_DECL_STD(float, sse, , fma) { + __mk_param_std(); + int i = enumeration->m128_i32[0]; int j = enumeration->m128_i32[1]; int commonK = enumeration->m128_i32[2]; diff --git a/StgSharp.Native/sn-src/simdid_compare.x86.c b/StgSharp.Native/sn-src/simdid_compare.x86.c index 40a4f4bd..934c8ba8 100644 --- a/StgSharp.Native/sn-src/simdid_compare.x86.c +++ b/StgSharp.Native/sn-src/simdid_compare.x86.c @@ -4,7 +4,7 @@ #include "StgSharpNative.h" #include "sn_intrinsic.h" -#include "sn_intrincontext.x86.h" +#include "sn_intrinsic.context.x86.h" /* ----------------------------------------------------------------------- * Field extraction helpers. diff --git a/todo.md b/todo.md index 3f99d289..9f05062d 100644 --- a/todo.md +++ b/todo.md @@ -1,5 +1,4 @@ -1. native 核函数标识关键字宏和展开宏 -2. 核函数参数表重整 +2. L4缓存模拟器 3. C#侧核函数调度器重整适配 4. 正则表达式源生成 5. imgae及pixel存储优化 \ No newline at end of file