diff --git a/StgSharp.Mathematics/Numeric/MatrixCompute.Additional.cs b/StgSharp.Mathematics/Numeric/MatrixCompute.Additional.cs index 9b3b2030..beccf2c2 100644 --- a/StgSharp.Mathematics/Numeric/MatrixCompute.Additional.cs +++ b/StgSharp.Mathematics/Numeric/MatrixCompute.Additional.cs @@ -29,6 +29,7 @@ using StgSharp.HighPerformance; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; @@ -37,17 +38,23 @@ namespace StgSharp.Mathematics.Numeric public partial class MatrixCompute { - private static unsafe void ComputeFmaPanelF32( - MatrixKernel* left, - MatrixKernel* right, - MatrixKernel* ans, - ScalarPacket* scalar) + internal static unsafe void ComputeFmaPanelF32(MatrixParallelTaskPackage* p) { - const int eSize = 32; - int colum = scalar->Data(0); - int row = scalar->Data(1); - int k = - + MatrixPanel* leftPanel = MatrixPanel.Create(); + MatrixPanel* rightPanel = MatrixPanel.Create(); + MatrixPanel* ansPanel = MatrixPanel.Create(); + ref long offsetRef = ref Unsafe.As(ref p->PrimTileOffset); + ref long lengthRef = ref Unsafe.As(ref p->PrimCount); + int i_length = p->PrimCount; + int j_length = p->SecCount; + int k_length = 0; + for (long i = 0; i < lengthRef; i++) + { + for (int k = 0; k < k_length; k++) { } + } + MatrixPanel.Destroy(leftPanel); + MatrixPanel.Destroy(rightPanel); + MatrixPanel.Destroy(ansPanel); } } diff --git a/StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs b/StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs index 99bfe321..71bade0c 100644 --- a/StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs +++ b/StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs @@ -222,7 +222,7 @@ namespace StgSharp.Mathematics.Numeric package->PrimCount = left.KernelColumnLength; package->SecCount = left.KernelRowLength; package->Scalar = scalar; - package->ComputeMode = new MatrixOpMode(MatrixOperationStyle.BUFFER_OP, MatrixOperationParam.RIGHT_ANS_SCALAR_PARAM); + package->ComputeMode = new MatrixOpMode(MatrixOperationStyle.BUFFER_OP, MatrixOperationSpecial.SEQ_FMA); package->ComputeHandle = (IntPtr)NativeIntrinsic.Intrinsic.f32_buffer_scalar_mul; MatrixParallelHandle taskGroup = MatrixParallel.ScheduleTask(package); diff --git a/StgSharp.Mathematics/Numeric/MatrixComputeModel.cs b/StgSharp.Mathematics/Numeric/MatrixComputeModel.cs index a96db5e0..7878055f 100644 --- a/StgSharp.Mathematics/Numeric/MatrixComputeModel.cs +++ b/StgSharp.Mathematics/Numeric/MatrixComputeModel.cs @@ -34,7 +34,7 @@ namespace StgSharp.Mathematics.Numeric internal static class MatrixComputeModel { - internal static unsafe void BufferComputeBinary(MatrixParallelTaskPackage* p) + internal static unsafe void KernelComputeBinary(MatrixParallelTaskPackage* p) { int size = p->ElementSize * 16; long count = Unsafe.As(ref p->PrimCount); @@ -47,7 +47,21 @@ namespace StgSharp.Mathematics.Numeric MatrixParallelFactory.Release(p); } - internal static unsafe void BufferComputeNoOperatorScalar(MatrixParallelTaskPackage* p) + internal static unsafe void KernelComputeBinaryScalar(MatrixParallelTaskPackage* p) + { + int size = p->ElementSize * 16; + long count = Unsafe.As(ref p->PrimCount); + long offset = Unsafe.As(ref p->PrimTileOffset) * size; + ScalarPacket* scalar = p->Scalar; + ((delegate* unmanaged[Cdecl])p->ComputeHandle)((void*)(p->Left + offset), + (void*)(p->Right + offset), + (void*)(p->Result + offset), + scalar, + count); + MatrixParallelFactory.Release(p); + } + + internal static unsafe void KernelComputeNoOperatorScalar(MatrixParallelTaskPackage* p) { int size = p->ElementSize * 16; long count = Unsafe.As(ref p->PrimCount); @@ -57,7 +71,7 @@ namespace StgSharp.Mathematics.Numeric MatrixParallelFactory.Release(p); } - internal static unsafe void BufferComputeUnary(MatrixParallelTaskPackage* p) + internal static unsafe void KernelComputeUnary(MatrixParallelTaskPackage* p) { int size = p->ElementSize * 16; long count = Unsafe.As(ref p->PrimCount); @@ -69,7 +83,7 @@ namespace StgSharp.Mathematics.Numeric MatrixParallelFactory.Release(p); } - internal static unsafe void BufferComputeUnaryScalar(MatrixParallelTaskPackage* p) + internal static unsafe void KernelComputeUnaryScalar(MatrixParallelTaskPackage* p) { int size = p->ElementSize * 16; long count = Unsafe.As(ref p->PrimCount); @@ -81,201 +95,19 @@ namespace StgSharp.Mathematics.Numeric MatrixParallelFactory.Release(p); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static unsafe void KernelComputeBinary(MatrixParallelTaskPackage* p) - { - int eSize = p->ElementSize; - - // base pointer to matrix kernels - nint l = p->Left, r = p->Right, a = p->Result; - long - - // set beginning value to counters for primary offsets - lCount = (long)p->LeftPrimOffset * p->LeftPrimStride, - rCount = (long)p->RightPrimOffset * p->RightPrimStride, - aCount = (long)p->ResultPrimOffset * p->ResultPrimStride, - pCount = int.Min(p->PrimCount, p->PrimColumnCountInTile + p->PrimTileOffset) /*_count of tile may be too much*/, - //edge to reset counters - lLimit = pCount - p->LeftPrimOffset, - rLimit = pCount - p->RightPrimOffset, - aLimit = pCount - p->ResultPrimOffset; - delegate* unmanaged[Cdecl] op = - (delegate* unmanaged[Cdecl])p->ComputeHandle; - for (long i = p->PrimTileOffset % pCount; i < pCount; i++) - { - // update primary counters - // if reaches edge, reset to zero - lCount = i < lLimit ? lCount + p->LeftPrimStride : 0; - rCount = i < rLimit ? rCount + p->RightPrimStride : 0; - aCount = i < rLimit ? aCount + p->ResultPrimStride : 0; - - // get kernel column pointers - nint left = l + (nint)(lCount * eSize); - nint right = r + (nint)(rCount * eSize); - nint ans = a + (nint)(aCount * eSize); - long - lc = (long)p->LeftSecOffset * p->LeftSecStride, - rc = (long)p->RightSecOffset * p->RightSecStride, - ac = (long)p->ResultSecOffset * p->ResultSecStride, - sCount = int.Min(p->SecCount, p->PrimColumnCountInTile * p->SecTileOffset); - long - ll = sCount - p->LeftSecOffset, - rl = sCount - p->RightSecOffset, - al = sCount - p->ResultSecOffset; - for (long j = p->SecTileOffset % sCount; j < sCount; j++) - { - lc = j < ll ? lc + p->LeftSecStride : 0; - rc = j < rl ? rc + p->RightSecStride : 0; - ac = j < al ? ac + p->ResultSecStride : 0; - op(left + (nint)lc, right + (nint)rc, ans + (nint)ac); - } - } - MatrixParallelFactory.Release(p); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static unsafe void KernelComputeBinaryScalar(MatrixParallelTaskPackage* p) - { - int eSize = p->ElementSize; - - // base pointer to matrix kernels - nint l = p->Left, r = p->Right, a = p->Result; - long - - // set beginning value to counters for primary offsets - lCount = (long)p->LeftPrimOffset * p->LeftPrimStride, - rCount = (long)p->RightPrimOffset * p->RightPrimStride, - aCount = (long)p->ResultPrimOffset * p->ResultPrimStride, - pCount = int.Min(p->PrimCount, p->PrimColumnCountInTile + p->PrimTileOffset) /*_count of tile may be too much*/, - //edge to reset counters - lLimit = pCount - p->LeftPrimOffset, - rLimit = pCount - p->RightPrimOffset, - aLimit = pCount - p->ResultPrimOffset; - delegate* unmanaged[Cdecl] op = - (delegate* unmanaged[Cdecl])p->ComputeHandle; - for (long i = p->PrimTileOffset % pCount; i < pCount; i++) - { - // update primary counters - // if reaches edge, reset to zero - lCount = i < lLimit ? lCount + p->LeftPrimStride : 0; - rCount = i < rLimit ? rCount + p->RightPrimStride : 0; - aCount = i < rLimit ? aCount + p->ResultPrimStride : 0; - - // get kernel column pointers - nint left = l + (nint)(lCount * eSize); - nint right = r + (nint)(rCount * eSize); - nint ans = a + (nint)(aCount * eSize); - long - lc = (long)p->LeftSecOffset * p->LeftSecStride, - rc = (long)p->RightSecOffset * p->RightSecStride, - ac = (long)p->ResultSecOffset * p->ResultSecStride, - sCount = int.Min(p->SecCount, p->PrimColumnCountInTile * p->SecTileOffset); - long - ll = sCount - p->LeftSecOffset, - rl = sCount - p->RightSecOffset, - al = sCount - p->ResultSecOffset; - for (long j = p->SecTileOffset % sCount; j < sCount; j++) - { - lc = j < ll ? lc + p->LeftSecStride : 0; - rc = j < rl ? rc + p->RightSecStride : 0; - ac = j < al ? ac + p->ResultSecStride : 0; - op(left + (nint)lc, right + (nint)rc, ans + (nint)ac, p->Scalar); - } - } - MatrixParallelFactory.Release(p); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static unsafe void KernelComputeUnary(MatrixParallelTaskPackage* p) - { - int eSize = p->ElementSize; - - // base pointer to matrix kernels - nint r = p->Right, a = p->Result; - long - - // set beginning value to counters for primary offsets - rCount = (long)p->RightPrimOffset * p->RightPrimStride, - aCount = (long)p->ResultPrimOffset * p->ResultPrimStride, - pCount = int.Min(p->PrimCount, p->PrimColumnCountInTile + p->PrimTileOffset) /*_count of tile may be too much*/, - //edge to reset counters - rLimit = pCount - p->RightPrimOffset, - aLimit = pCount - p->ResultPrimOffset; - delegate* unmanaged[Cdecl] op = - (delegate* unmanaged[Cdecl])p->ComputeHandle; - for (long i = p->PrimTileOffset % pCount; i < pCount; i++) - { - // update primary counters - // if reaches edge, reset to zero - rCount = i < rLimit ? rCount + p->RightPrimStride : 0; - aCount = i < rLimit ? aCount + p->ResultPrimStride : 0; - - // get kernel column pointers - nint right = r + (nint)(rCount * eSize); - nint ans = a + (nint)(aCount * eSize); - long - rc = (long)p->RightSecOffset * p->RightSecStride, - ac = (long)p->ResultSecOffset * p->ResultSecStride, - sCount = int.Min(p->SecCount, p->PrimColumnCountInTile * p->SecTileOffset); - long - rl = sCount - p->RightSecOffset, - al = sCount - p->ResultSecOffset; - for (long j = p->SecTileOffset % sCount; j < sCount; j++) - { - rc = j < rl ? rc + p->RightSecStride : 0; - ac = j < al ? ac + p->ResultSecStride : 0; - op(right + (nint)rc, ans + (nint)ac); - } - } - MatrixParallelFactory.Release(p); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static unsafe void KernelComputeUnaryScalar(MatrixParallelTaskPackage* p) - { - int eSize = p->ElementSize; - - // base pointer to matrix kernels - nint r = p->Right, a = p->Result; - long - - // set beginning value to counters for primary offsets - rCount = (long)p->RightPrimOffset * p->RightPrimStride, - aCount = (long)p->ResultPrimOffset * p->ResultPrimStride, - pCount = int.Min(p->PrimCount, p->PrimColumnCountInTile + p->PrimTileOffset) /*_count of tile may be too much*/, - //edge to reset counters - rLimit = pCount - p->RightPrimOffset, - aLimit = pCount - p->ResultPrimOffset; - delegate* unmanaged[Cdecl] op = - (delegate* unmanaged[Cdecl])p->ComputeHandle; - for (long i = p->PrimTileOffset % pCount; i < pCount; i++) - { - // update primary counters - // if reaches edge, reset to zero - rCount = i < rLimit ? rCount + p->RightPrimStride : 0; - aCount = i < rLimit ? aCount + p->ResultPrimStride : 0; - - // get kernel column pointers - nint right = r + (nint)(rCount * eSize); - nint ans = a + (nint)(aCount * eSize); - long - rc = (long)p->RightSecOffset * p->RightSecStride, - ac = (long)p->ResultSecOffset * p->ResultSecStride, - sCount = int.Min(p->SecCount, p->PrimColumnCountInTile * p->SecTileOffset); - long - rl = sCount - p->RightSecOffset, - al = sCount - p->ResultSecOffset; - for (long j = p->SecTileOffset % sCount; j < sCount; j++) - { - rc = j < rl ? rc + p->RightSecStride : 0; - ac = j < al ? ac + p->ResultSecStride : 0; - op(right + (nint)rc, ans + (nint)ac, p->Scalar); - } - } - MatrixParallelFactory.Release(p); - } - internal static unsafe void PanelComputeBinary(MatrixParallelTaskPackage* p) { } + internal static unsafe void SpecialCompute(MatrixParallelTaskPackage* p) + { + switch ((MatrixOperationSpecial)p->ComputeMode.OperationStyle) + { + case MatrixOperationSpecial.SEQ_FMA: + MatrixCompute.ComputeFmaPanelF32(p); + break; + default: + throw new NotSupportedException("The special matrix operation style is not supported."); + } + } + } } \ No newline at end of file diff --git a/StgSharp.Mathematics/Numeric/MatrixParallel.Publish.cs b/StgSharp.Mathematics/Numeric/MatrixParallel.Publish.cs index 437efd04..de3f2b3d 100644 --- a/StgSharp.Mathematics/Numeric/MatrixParallel.Publish.cs +++ b/StgSharp.Mathematics/Numeric/MatrixParallel.Publish.cs @@ -1,4 +1,4 @@ -//----------------------------------------------------------------------- +//----------------------------------------------------------------------- // ----------------------------------------------------------------------- // file="MatrixParallel.Publish" // Project: StgSharp @@ -51,18 +51,15 @@ namespace StgSharp.Mathematics.Numeric MatrixParallelTaskPackage* nonGeneric = package; switch (nonGeneric->ComputeMode.OperationStyle) { - case MatrixOperationStyle.PANEL_OP: - throw new NotImplementedException(); - case MatrixOperationStyle.BUFFER_OP: + case MatrixOperationStyle.BUFFER_INDEX: return ScheduleBufferTask(nonGeneric); - case MatrixOperationStyle.KERNEL_OP: - return ScheduleKernelTask(nonGeneric); default: throw new InvalidOperationException($"Unknown mode {nonGeneric->ComputeMode.OperationStyle}."); } } - private static unsafe MatrixParallelHandle ScheduleBufferTask(MatrixParallelTaskPackage* package) + private static unsafe MatrixParallelHandle ScheduleBufferTask( + MatrixParallelTaskPackage* package) { int primCount = package->PrimCount; int secCount = package->SecCount; @@ -113,7 +110,8 @@ namespace StgSharp.Mathematics.Numeric return handle; } - private static unsafe MatrixParallelHandle ScheduleKernelTask(MatrixParallelTaskPackage* package) + private static unsafe MatrixParallelHandle ScheduleKernelTask( + MatrixParallelTaskPackage* package) { int primCount = package->PrimCount; int secCount = package->SecCount; diff --git a/StgSharp.Mathematics/Numeric/MatrixParallelTaskPackage.cs b/StgSharp.Mathematics/Numeric/MatrixParallelTaskPackage.cs index c6429ee1..71a9eb32 100644 --- a/StgSharp.Mathematics/Numeric/MatrixParallelTaskPackage.cs +++ b/StgSharp.Mathematics/Numeric/MatrixParallelTaskPackage.cs @@ -1,4 +1,4 @@ -//----------------------------------------------------------------------- +//----------------------------------------------------------------------- // ----------------------------------------------------------------------- // file="MatrixParallelTaskPackage" // Project: StgSharp @@ -52,12 +52,17 @@ namespace StgSharp.Mathematics.Numeric * matrix_op_mode; */ + public enum MatrixOperationSpecial : short + { + + SEQ_FMA = -1, + + } + public enum MatrixOperationStyle : short { - PANEL_OP = 1, - BUFFER_OP = 2, - KERNEL_OP = 3, + BUFFER_INDEX = 1, } @@ -79,6 +84,9 @@ namespace StgSharp.Mathematics.Numeric public MatrixOperationParam ParameterStyle = paramLayout; public MatrixOperationStyle OperationStyle = style; + public MatrixOpMode(MatrixOperationStyle style, MatrixOperationSpecial paramLayout) + : this(style, (MatrixOperationParam)paramLayout) { } + } [StructLayout(LayoutKind.Explicit, Size = 128)] @@ -86,9 +94,12 @@ namespace StgSharp.Mathematics.Numeric { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe void Copy(MatrixParallelTaskPackage* source, MatrixParallelTaskPackage* target) + public static unsafe void Copy( + MatrixParallelTaskPackage* source, + MatrixParallelTaskPackage* target) { - Buffer.MemoryCopy(source, target, sizeof(MatrixParallelTaskPackage), sizeof(MatrixParallelTaskPackage)); + Buffer.MemoryCopy(source, target, sizeof(MatrixParallelTaskPackage), + sizeof(MatrixParallelTaskPackage)); } #region source diff --git a/StgSharp.Mathematics/Numeric/MatrixParallelThread.cs b/StgSharp.Mathematics/Numeric/MatrixParallelThread.cs index 0afa39ef..d16e3422 100644 --- a/StgSharp.Mathematics/Numeric/MatrixParallelThread.cs +++ b/StgSharp.Mathematics/Numeric/MatrixParallelThread.cs @@ -85,26 +85,30 @@ namespace StgSharp.Mathematics.Numeric while (taskQueue.TryDequeue(out nint handle)) { MatrixParallelTaskPackage* p = (MatrixParallelTaskPackage*)handle; + if ((int)p->ComputeMode.ParameterStyle < 0) { + MatrixComputeModel.SpecialCompute(p); + } switch (p->ComputeMode.OperationStyle) { case MatrixOperationStyle.PANEL_OP: - break; - case MatrixOperationStyle.BUFFER_OP: switch (p->ComputeMode.ParameterStyle) { case MatrixOperationParam.RIGHT_ANS_PARAM: - MatrixComputeModel.BufferComputeUnary(p); + + // MatrixComputeModel.PanelComputeUnary(p); break; case MatrixOperationParam.LEFT_RIGHT_ANS_PARAM: - MatrixComputeModel.BufferComputeBinary(p); + MatrixComputeModel.PanelComputeBinary(p); break; case MatrixOperationParam.RIGHT_ANS_SCALAR_PARAM: - MatrixComputeModel.BufferComputeUnaryScalar(p); + + // MatrixComputeModel.PanelComputeUnaryScalar(p); break; case MatrixOperationParam.LEFT_RIGHT_ANS_SCALAR_PARAM: break; case MatrixOperationParam.ANS_SCALAR_PARAM: - MatrixComputeModel.BufferComputeNoOperatorScalar(p); + + // MatrixComputeModel.PanelComputeNoOperatorScalar(p); break; default: break; diff --git a/StgSharp.Mathematics/Numeric/MatrixParallelWrap.cs b/StgSharp.Mathematics/Numeric/MatrixParallelWrap.cs index 0bb04ec7..1c27d8ba 100644 --- a/StgSharp.Mathematics/Numeric/MatrixParallelWrap.cs +++ b/StgSharp.Mathematics/Numeric/MatrixParallelWrap.cs @@ -1,4 +1,4 @@ -//----------------------------------------------------------------------- +//----------------------------------------------------------------------- // ----------------------------------------------------------------------- // file="MatrixParallelWrap" // Project: StgSharp @@ -104,18 +104,12 @@ namespace StgSharp.Mathematics.Numeric while (tasks.TryDequeue(out nint handle)) { MatrixParallelTaskPackage* task = (MatrixParallelTaskPackage*)handle; - switch (task->ComputeMode.OperationStyle) + if ((int)task->ComputeMode.OperationStyle > 0) { - case MatrixOperationStyle.PANEL_OP: - break; - case MatrixOperationStyle.BUFFER_OP: - PublishBufferTaskToWorkers(task); - break; - case MatrixOperationStyle.KERNEL_OP: - PublishBufferTaskToWorkers(task); - break; - default: - break; + PublishBufferTaskToWorkers(task); + } else + { + throw new NotImplementedException(); } } } @@ -169,73 +163,6 @@ namespace StgSharp.Mathematics.Numeric // Console.WriteLine(msg); } - private void PublishKernelTaskToWorkers(MatrixParallelTaskPackage* package) - { - int primCount = package->PrimCount; - int secCount = package->SecCount; - ReadOnlySpan pool = Threads; - - if (pool.Length == 1) - { - pool[0].Tasks.Enqueue((nint)package); - return; - } - throw new NotImplementedException(); - /* - int threadCount = pool.Length; - int tilePerThreadLess = tileCount / threadCount; // tiles per thread without extra slice - int columnAfterBaseTile = tileCount % threadCount * tileWidth; // tile sliced into columns - int extraColumnPerThread = columnAfterBaseTile / threadCount; - int extraColumnCount = columnAfterBaseTile % threadCount; // columns to be sliced - - int total = primCount; - Stack taskBunch = new Stack(threadCount); - MatrixParallelTaskPackageNonGeneric* current = package; - foreach (MatrixParallelWrap wrap in pool.Wraps) - { - bool hasSlice = columnAfterBaseTile > 0; - bool isLargeSlice = extraColumnCount > 0; - - // _count tiles for wrap - int wrapWidth = wrap!.WrapTaskCapacity; - int columnFromSlicingCount = (hasSlice ? extraColumnPerThread : 0) * wrapWidth; - int baseColumn = wrapWidth * tilePerThreadLess * tileWidth; - int columnInWrap = baseColumn + columnFromSlicingCount + (isLargeSlice ? 1 : 0); - - // set tasks - if (columnInWrap == 0) - { -#if DEBUG - throw new InvalidOperationException("Zero tasks published."); -#else - break; -#endif - } - - // update current task - current->PrimColumnCountInTile = columnInWrap; - current->SecColumnCountInTile = current->SecCount; - current->SecTileOffset = 0; - - // remove tiles _count - extraColumnCount--; - columnAfterBaseTile -= columnFromSlicingCount; - total -= columnInWrap; - - // set to wrap and push - wrap.WrapTask = current; - - if (total <= 0) - { - break; - } - current = MatrixParallelFactory.FromExistPackage(current); - current->PrimTileOffset += columnInWrap; - } - /**/ - return; - } - #region wrap task internal unsafe Queue WrapTask { get; set; } = []; diff --git a/StgSharp.Native/sn-src/dllmain.c b/StgSharp.Native/sn-src/dllmain.c index 677a0b71..38b0014c 100644 --- a/StgSharp.Native/sn-src/dllmain.c +++ b/StgSharp.Native/sn-src/dllmain.c @@ -1,4 +1,4 @@ -#include "StgSharpNative.h" +#include "StgSharpNative.h" #include "sn_matkernel.h" #include diff --git a/StgSharp.Native/sn-src/k_panel.c b/StgSharp.Native/sn-src/k_panel.c index 95c302bc..4d3c8bb6 100644 --- a/StgSharp.Native/sn-src/k_panel.c +++ b/StgSharp.Native/sn-src/k_panel.c @@ -54,7 +54,7 @@ DECLARE_BUILD_PANEL(sse, float) DECLARE_BUILD_PANEL(512, float) { const MAT_KERNEL(float) *const zero = (const MAT_KERNEL(float) *)&SN_ZERO_KERNEL; - const MAT_KERNEL(float) *k[4][4]; + const MAT_KERNEL(float) * k[4][4]; for (int kc = 0; kc < 4; ++kc) { for (int kr = 0; kr < 4; ++kr) { @@ -68,8 +68,8 @@ DECLARE_BUILD_PANEL(512, float) /* Each panel column corresponds to a kernel column (0..3) within a block col (0..3). */ for (int pc = 0; pc < 16; ++pc) { - const int blk_col = pc >> 2; /* which kernel column block (0..3) */ - const int kc_col = pc & 3; /* column inside a 4x4 kernel */ + const int blk_col = pc >> 2; /* which kernel column block (0..3) */ + const int kc_col = pc & 3; /* column inside a 4x4 kernel */ const __m128 r0 = k[blk_col][0]->xmm[kc_col]; const __m128 r1 = k[blk_col][1]->xmm[kc_col]; @@ -155,7 +155,7 @@ DECLARE_STORE_PANEL(sse, float) DECLARE_STORE_PANEL(512, float) { MAT_KERNEL(float) zero; - MAT_KERNEL(float) *k[4][4]; + MAT_KERNEL(float) * k[4][4]; for (int kc = 0; kc < 4; ++kc) { for (int kr = 0; kr < 4; ++kr) { @@ -168,8 +168,8 @@ DECLARE_STORE_PANEL(512, float) } for (int pc = 0; pc < 16; ++pc) { - const int blk_col = pc >> 2; /* which kernel column block (0..3) */ - const int kc_col = pc & 3; /* column inside a 4x4 kernel */ + const int blk_col = pc >> 2; /* which kernel column block (0..3) */ + const int kc_col = pc & 3; /* column inside a 4x4 kernel */ const __m512 col = PANEL_COL_VEC((*panel), pc, 0); diff --git a/StgSharp.Native/sn-src/load_glfw.c b/StgSharp.Native/sn-src/load_glfw.c index f225f968..02f0ec0b 100644 --- a/StgSharp.Native/sn-src/load_glfw.c +++ b/StgSharp.Native/sn-src/load_glfw.c @@ -4,120 +4,120 @@ SN_API void SN_DECL load_glfw_functions(GLFWFunctionTable *table) { - table->glfwCreateCursor = glfwCreateCursor; - table->glfwCreateStandardCursor = glfwCreateStandardCursor; - table->glfwCreateWindow = glfwCreateWindow; - table->glfwDefaultWindowHints = glfwDefaultWindowHints; - table->glfwDestroyCursor = glfwDestroyCursor; - table->glfwDestroyWindow = glfwDestroyWindow; - table->glfwExtensionSupported = glfwExtensionSupported; - table->glfwFocusWindow = glfwFocusWindow; - table->glfwGetClipboardString = glfwGetClipboardString; - table->glfwGetCurrentContext = glfwGetCurrentContext; - table->glfwGetCursorPos = glfwGetCursorPos; - table->glfwGetError = glfwGetError; - table->glfwGetFrameBufferSize = glfwGetFramebufferSize; - table->glfwGetGamepadName = glfwGetGamepadName; - table->glfwGetGamepadState = glfwGetGamepadState; - table->glfwGetGammaRamp = glfwGetGammaRamp; - table->glfwGetInputMode = glfwGetInputMode; - table->glfwGetJoystickAxes = glfwGetJoystickAxes; - table->glfwGetJoystickButtons = glfwGetJoystickButtons; - table->glfwGetJoystickGUID = glfwGetJoystickGUID; - table->glfwGetJoystickHats = glfwGetJoystickHats; - table->glfwGetJoystickName = glfwGetJoystickName; - table->glfwGetJoystickUserPointer = glfwGetJoystickUserPointer; - table->glfwGetKey = glfwGetKey; - table->glfwGetKeyName = glfwGetKeyName; - table->glfwGetKeyScancode = glfwGetKeyScancode; - table->glfwGetMonitorContentScale = glfwGetMonitorContentScale; - table->glfwGetMonitorName = glfwGetMonitorName; - table->glfwGetMonitorPhysicalSize = glfwGetMonitorPhysicalSize; - table->glfwGetMonitorPos = glfwGetMonitorPos; - table->glfwGetMonitors = glfwGetMonitors; - table->glfwGetMonitorUserPointer = glfwGetMonitorUserPointer; - table->glfwGetMonitorWorkarea = glfwGetMonitorWorkarea; - table->glfwGetMouseButton = glfwGetMouseButton; - table->glfwGetPrimaryMonitor = glfwGetPrimaryMonitor; - table->glfwGetProcAddress = glfwGetProcAddress; - table->glfwGetRequiredInstanceExtensions = glfwGetRequiredInstanceExtensions; - table->glfwGetTime = glfwGetTime; - table->glfwGetTimerFrequency = glfwGetTimerFrequency; - table->glfwGetTimerValue = glfwGetTimerValue; - table->glfwGetVersion = glfwGetVersion; - table->glfwGetVersionString = glfwGetVersionString; - table->glfwGetVideoMode = glfwGetVideoMode; - table->glfwGetVideoModes = glfwGetVideoModes; - table->glfwGetWindowAttrib = glfwGetWindowAttrib; - table->glfwGetWindowContentScale = glfwGetWindowContentScale; - table->glfwGetWindowFrameSize = glfwGetWindowFrameSize; - table->glfwGetWindowMonitor = glfwGetWindowMonitor; - table->glfwGetWindowOpacity = glfwGetWindowOpacity; - table->glfwGetWindowPos = glfwGetWindowPos; - table->glfwGetWindowSize = glfwGetWindowSize; - table->glfwGetWindowUserPointer = glfwGetWindowUserPointer; - table->glfwHideWindow = glfwHideWindow; - table->glfwIconifyWindow = glfwIconifyWindow; - table->glfwInit = glfwInit; - table->glfwInitHint = glfwInitHint; - table->glfwJoystickIsGamePad = glfwJoystickIsGamepad; - table->glfwJoystickPresent = glfwJoystickPresent; - table->glfwMakeContextCurrent = glfwMakeContextCurrent; - table->glfwMaximizeWindow = glfwMaximizeWindow; - table->glfwPollEvents = glfwPollEvents; - table->glfwPostEmptyEvent = glfwPostEmptyEvent; - table->glfwRawMouseMotionSupported = glfwRawMouseMotionSupported; - table->glfwRequestWindowAttention = glfwRequestWindowAttention; - table->glfwRestoreWindow = glfwRestoreWindow; - table->glfwSetCharCallback = glfwSetCharCallback; - table->glfwSetCharModsCallback = glfwSetCharModsCallback; - table->glfwSetClipboardString = glfwSetClipboardString; - table->glfwSetCursor = glfwSetCursor; - table->glfwSetCursorEnterCallback = glfwSetCursorEnterCallback; - table->glfwSetCursorPos = glfwSetCursorPos; - table->glfwSetCursorPosCallback = glfwSetCursorPosCallback; - table->glfwSetDropCallback = glfwSetDropCallback; - table->glfwSetErrorCallback = glfwSetErrorCallback; - table->glfwSetFramebufferSizeCallback = glfwSetFramebufferSizeCallback; - table->glfwSetGamma = glfwSetGamma; - table->glfwSetGammaRamp = glfwSetGammaRamp; - table->glfwSetInputMode = glfwSetInputMode; - table->glfwSetJoystickCallback = glfwSetJoystickCallback; - table->glfwSetJoystickUserPointer = glfwSetJoystickUserPointer; - table->glfwSetKeyCallback = glfwSetKeyCallback; - table->glfwSetMonitorCallback = glfwSetMonitorCallback; - table->glfwSetMonitorUserPointer = glfwSetMonitorUserPointer; - table->glfwSetMouseButtonCallback = glfwSetMouseButtonCallback; - table->glfwSetScrollCallback = glfwSetScrollCallback; - table->glfwSetTime = glfwSetTime; - table->glfwSetWindowAspectRatio = glfwSetWindowAspectRatio; - table->glfwSetWindowAttrib = glfwSetWindowAttrib; - table->glfwSetWindowCloseCallback = glfwSetWindowCloseCallback; - table->glfwSetWindowContentScaleCallback = glfwSetWindowContentScaleCallback; - table->glfwSetWindowFocusCallback = glfwSetWindowFocusCallback; - table->glfwSetWindowIcon = glfwSetWindowIcon; - table->glfwSetWindowIconifyCallback = glfwSetWindowIconifyCallback; - table->glfwSetWindowMaximizeCallback = glfwSetWindowMaximizeCallback; - table->glfwSetWindowMonitor = glfwSetWindowMonitor; - table->glfwSetWindowOpacity = glfwSetWindowOpacity; - table->glfwSetWindowPos = glfwSetWindowPos; - table->glfwSetWindowPosCallback = glfwSetWindowPosCallback; - table->glfwSetWindowRefreshCallback = glfwSetWindowRefreshCallback; - table->glfwSetWindowShouldClose = glfwSetWindowShouldClose; - table->glfwSetWindowSize = glfwSetWindowSize; - table->glfwSetWindowSizeCallback = glfwSetWindowSizeCallback; - table->glfwSetWindowSizeLimits = glfwSetWindowSizeLimits; - table->glfwSetWindowTitle = glfwSetWindowTitle; - table->glfwSetWindowUserPointer = glfwSetWindowUserPointer; - table->glfwShowWindow = glfwShowWindow; - table->glfwSwapBuffers = glfwSwapBuffers; - table->glfwSwapInterval = glfwSwapInterval; - table->glfwTerminate = glfwTerminate; - table->glfwUpdateGamePadMappings = glfwUpdateGamepadMappings; - table->glfwVulkanSupported = glfwVulkanSupported; - table->glfwWaitEvents = glfwWaitEvents; - table->glfwWaitEventsTimeout = glfwWaitEventsTimeout; - table->glfwWindowHint = glfwWindowHint; - table->glfwWindowHintString = glfwWindowHintString; - table->glfwWindowShouldClose = glfwWindowShouldClose; + table->glfwCreateCursor = glfwCreateCursor; + table->glfwCreateStandardCursor = glfwCreateStandardCursor; + table->glfwCreateWindow = glfwCreateWindow; + table->glfwDefaultWindowHints = glfwDefaultWindowHints; + table->glfwDestroyCursor = glfwDestroyCursor; + table->glfwDestroyWindow = glfwDestroyWindow; + table->glfwExtensionSupported = glfwExtensionSupported; + table->glfwFocusWindow = glfwFocusWindow; + table->glfwGetClipboardString = glfwGetClipboardString; + table->glfwGetCurrentContext = glfwGetCurrentContext; + table->glfwGetCursorPos = glfwGetCursorPos; + table->glfwGetError = glfwGetError; + table->glfwGetFrameBufferSize = glfwGetFramebufferSize; + table->glfwGetGamepadName = glfwGetGamepadName; + table->glfwGetGamepadState = glfwGetGamepadState; + table->glfwGetGammaRamp = glfwGetGammaRamp; + table->glfwGetInputMode = glfwGetInputMode; + table->glfwGetJoystickAxes = glfwGetJoystickAxes; + table->glfwGetJoystickButtons = glfwGetJoystickButtons; + table->glfwGetJoystickGUID = glfwGetJoystickGUID; + table->glfwGetJoystickHats = glfwGetJoystickHats; + table->glfwGetJoystickName = glfwGetJoystickName; + table->glfwGetJoystickUserPointer = glfwGetJoystickUserPointer; + table->glfwGetKey = glfwGetKey; + table->glfwGetKeyName = glfwGetKeyName; + table->glfwGetKeyScancode = glfwGetKeyScancode; + table->glfwGetMonitorContentScale = glfwGetMonitorContentScale; + table->glfwGetMonitorName = glfwGetMonitorName; + table->glfwGetMonitorPhysicalSize = glfwGetMonitorPhysicalSize; + table->glfwGetMonitorPos = glfwGetMonitorPos; + table->glfwGetMonitors = glfwGetMonitors; + table->glfwGetMonitorUserPointer = glfwGetMonitorUserPointer; + table->glfwGetMonitorWorkarea = glfwGetMonitorWorkarea; + table->glfwGetMouseButton = glfwGetMouseButton; + table->glfwGetPrimaryMonitor = glfwGetPrimaryMonitor; + table->glfwGetProcAddress = glfwGetProcAddress; + table->glfwGetRequiredInstanceExtensions = glfwGetRequiredInstanceExtensions; + table->glfwGetTime = glfwGetTime; + table->glfwGetTimerFrequency = glfwGetTimerFrequency; + table->glfwGetTimerValue = glfwGetTimerValue; + table->glfwGetVersion = glfwGetVersion; + table->glfwGetVersionString = glfwGetVersionString; + table->glfwGetVideoMode = glfwGetVideoMode; + table->glfwGetVideoModes = glfwGetVideoModes; + table->glfwGetWindowAttrib = glfwGetWindowAttrib; + table->glfwGetWindowContentScale = glfwGetWindowContentScale; + table->glfwGetWindowFrameSize = glfwGetWindowFrameSize; + table->glfwGetWindowMonitor = glfwGetWindowMonitor; + table->glfwGetWindowOpacity = glfwGetWindowOpacity; + table->glfwGetWindowPos = glfwGetWindowPos; + table->glfwGetWindowSize = glfwGetWindowSize; + table->glfwGetWindowUserPointer = glfwGetWindowUserPointer; + table->glfwHideWindow = glfwHideWindow; + table->glfwIconifyWindow = glfwIconifyWindow; + table->glfwInit = glfwInit; + table->glfwInitHint = glfwInitHint; + table->glfwJoystickIsGamePad = glfwJoystickIsGamepad; + table->glfwJoystickPresent = glfwJoystickPresent; + table->glfwMakeContextCurrent = glfwMakeContextCurrent; + table->glfwMaximizeWindow = glfwMaximizeWindow; + table->glfwPollEvents = glfwPollEvents; + table->glfwPostEmptyEvent = glfwPostEmptyEvent; + table->glfwRawMouseMotionSupported = glfwRawMouseMotionSupported; + table->glfwRequestWindowAttention = glfwRequestWindowAttention; + table->glfwRestoreWindow = glfwRestoreWindow; + table->glfwSetCharCallback = glfwSetCharCallback; + table->glfwSetCharModsCallback = glfwSetCharModsCallback; + table->glfwSetClipboardString = glfwSetClipboardString; + table->glfwSetCursor = glfwSetCursor; + table->glfwSetCursorEnterCallback = glfwSetCursorEnterCallback; + table->glfwSetCursorPos = glfwSetCursorPos; + table->glfwSetCursorPosCallback = glfwSetCursorPosCallback; + table->glfwSetDropCallback = glfwSetDropCallback; + table->glfwSetErrorCallback = glfwSetErrorCallback; + table->glfwSetFramebufferSizeCallback = glfwSetFramebufferSizeCallback; + table->glfwSetGamma = glfwSetGamma; + table->glfwSetGammaRamp = glfwSetGammaRamp; + table->glfwSetInputMode = glfwSetInputMode; + table->glfwSetJoystickCallback = glfwSetJoystickCallback; + table->glfwSetJoystickUserPointer = glfwSetJoystickUserPointer; + table->glfwSetKeyCallback = glfwSetKeyCallback; + table->glfwSetMonitorCallback = glfwSetMonitorCallback; + table->glfwSetMonitorUserPointer = glfwSetMonitorUserPointer; + table->glfwSetMouseButtonCallback = glfwSetMouseButtonCallback; + table->glfwSetScrollCallback = glfwSetScrollCallback; + table->glfwSetTime = glfwSetTime; + table->glfwSetWindowAspectRatio = glfwSetWindowAspectRatio; + table->glfwSetWindowAttrib = glfwSetWindowAttrib; + table->glfwSetWindowCloseCallback = glfwSetWindowCloseCallback; + table->glfwSetWindowContentScaleCallback = glfwSetWindowContentScaleCallback; + table->glfwSetWindowFocusCallback = glfwSetWindowFocusCallback; + table->glfwSetWindowIcon = glfwSetWindowIcon; + table->glfwSetWindowIconifyCallback = glfwSetWindowIconifyCallback; + table->glfwSetWindowMaximizeCallback = glfwSetWindowMaximizeCallback; + table->glfwSetWindowMonitor = glfwSetWindowMonitor; + table->glfwSetWindowOpacity = glfwSetWindowOpacity; + table->glfwSetWindowPos = glfwSetWindowPos; + table->glfwSetWindowPosCallback = glfwSetWindowPosCallback; + table->glfwSetWindowRefreshCallback = glfwSetWindowRefreshCallback; + table->glfwSetWindowShouldClose = glfwSetWindowShouldClose; + table->glfwSetWindowSize = glfwSetWindowSize; + table->glfwSetWindowSizeCallback = glfwSetWindowSizeCallback; + table->glfwSetWindowSizeLimits = glfwSetWindowSizeLimits; + table->glfwSetWindowTitle = glfwSetWindowTitle; + table->glfwSetWindowUserPointer = glfwSetWindowUserPointer; + table->glfwShowWindow = glfwShowWindow; + table->glfwSwapBuffers = glfwSwapBuffers; + table->glfwSwapInterval = glfwSwapInterval; + table->glfwTerminate = glfwTerminate; + table->glfwUpdateGamePadMappings = glfwUpdateGamepadMappings; + table->glfwVulkanSupported = glfwVulkanSupported; + table->glfwWaitEvents = glfwWaitEvents; + table->glfwWaitEventsTimeout = glfwWaitEventsTimeout; + table->glfwWindowHint = glfwWindowHint; + table->glfwWindowHintString = glfwWindowHintString; + table->glfwWindowShouldClose = glfwWindowShouldClose; } diff --git a/StgSharp.Native/sn-src/str_hash.c b/StgSharp.Native/sn-src/str_hash.c index 89794198..8662dab9 100644 --- a/StgSharp.Native/sn-src/str_hash.c +++ b/StgSharp.Native/sn-src/str_hash.c @@ -15,7 +15,7 @@ INTERNAL int SN_DECL city_hash_simplify_sse(byte const *str, int const length) for (; ptr < end; ptr += 4) { hash = _mm_crc32_u32(hash, *(uint32_t *)ptr); } - for (; ptr < end; ptr++) { + for (; ptr < end; ptr++) { hash = _mm_crc32_u16(hash, *ptr); } } else { @@ -30,10 +30,10 @@ INTERNAL int SN_DECL city_hash_simplify_sse(byte const *str, int const length) hash = _mm_crc32_u8(hash, hash64); hash = _mm_crc32_u8(hash, hash64 >> 32); for (; ptr < last_32; ptr += 4) { - hash = _mm_crc32_u32(hash,*(uint32_t *)ptr); + hash = _mm_crc32_u32(hash, *(uint32_t *)ptr); } for (; ptr < end; ptr += 2) { - hash = _mm_crc32_u8(hash,*ptr); + hash = _mm_crc32_u8(hash, *ptr); } } hash ^= hash >> 16; diff --git a/StgSharp.Native/sn-src/vector_dot.c b/StgSharp.Native/sn-src/vector_dot.c index 4d00414d..7b18cf27 100644 --- a/StgSharp.Native/sn-src/vector_dot.c +++ b/StgSharp.Native/sn-src/vector_dot.c @@ -15,7 +15,8 @@ INTERNAL void FORCEINLINE SN_DECL dot_41_sse(MAT_KERNEL(float) const *transpose, SSE_INSERT_SIMPLE(1, 4)); } -INTERNAL void SN_DECL dot_41_avx(MAT_KERNEL(float) const *transpose, __m128 const *vector, __m128 *ans) +INTERNAL void SN_DECL dot_41_avx(MAT_KERNEL(float) const *transpose, __m128 const *vector, + __m128 *ans) { __m256 _double = _mm256_set_m128(vector[0], vector[0]); __m256 tmp = _mm256_dp_ps(transpose->ymm[0], _double, 0B11110001); @@ -25,7 +26,8 @@ INTERNAL void SN_DECL dot_41_avx(MAT_KERNEL(float) const *transpose, __m128 cons _mm256_permutevar8x32_ps(tmp, _mm256_loadu_epi32(avxdot_indices))); } -INTERNAL void SN_DECL dot_42_sse(MAT_KERNEL(float) const *transpose, __m128 const *vector, __m128 *ans) +INTERNAL void SN_DECL dot_42_sse(MAT_KERNEL(float) const *transpose, __m128 const *vector, + __m128 *ans) { ans[0] = _mm_dp_ps(transpose->xmm[0], vector[0], 0B11110001); ans[0] = _mm_insert_ps(*ans, _mm_dp_ps(transpose->xmm[1], vector[0], 0B11110001), @@ -44,24 +46,22 @@ INTERNAL void SN_DECL dot_42_sse(MAT_KERNEL(float) const *transpose, __m128 cons SSE_INSERT_SIMPLE(1, 4)); } -INTERNAL void SN_DECL dot_42_avx(MAT_KERNEL(float) const *transpose, __m128 const *vector, __m128 *ans) +INTERNAL void SN_DECL dot_42_avx(MAT_KERNEL(float) const *transpose, __m128 const *vector, + __m128 *ans) { __m256 temp = transpose->ymm[0]; __m256 vector_stream = _mm256_set_m128(vector[1], vector[0]); __m256 result = _mm256_dp_ps(temp, vector_stream, 0B11110001); temp = _mm256_permute2f128_ps(temp, temp, 0B00000001); - result = _mm256_blend_ps( - result, _mm256_dp_ps(temp, vector_stream, 0B11110010), 0B00100010); + result = _mm256_blend_ps(result, _mm256_dp_ps(temp, vector_stream, 0B11110010), 0B00100010); temp = transpose->ymm[1]; - result = _mm256_blend_ps( - result, _mm256_dp_ps(temp, vector_stream, 0B11110100), 0B01000100); + result = _mm256_blend_ps(result, _mm256_dp_ps(temp, vector_stream, 0B11110100), 0B01000100); temp = _mm256_permute2f128_ps(temp, temp, 0B00000001); - result = _mm256_blend_ps( - result, _mm256_dp_ps(temp, vector_stream, 0B11111000), 0B10001000); + result = _mm256_blend_ps(result, _mm256_dp_ps(temp, vector_stream, 0B11111000), 0B10001000); ans[0] = _mm256_castps256_ps128(result); ans[1] = _mm256_extractf128_ps(result, 1); ans[1] = _mm_shuffle_ps(ans[1], ans[1], _MM_SHUFFLE(2, 3, 0, 1)); -} \ No newline at end of file +}