From 2f6617447c3479ff08d36f22c0a4ce28eedaab27 Mon Sep 17 00:00:00 2001 From: Youmu Liu <105042599+Nitload-NSI@users.noreply.github.com> Date: Thu, 23 Apr 2026 18:07:14 +0800 Subject: [PATCH] L4 is now on new algo, using tricky way to init entryies --- StgSharp.Common/HighPerformance/Memory/L4.CacheLine.cs | 4 +++- StgSharp.Common/HighPerformance/Memory/L4.Prefetch.cs | 4 +++- StgSharp.Common/HighPerformance/Memory/L4.cs | 5 +++++ .../HighPerformance/ProcessorAbstraction/M512.cs | 10 ++++++++-- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/StgSharp.Common/HighPerformance/Memory/L4.CacheLine.cs b/StgSharp.Common/HighPerformance/Memory/L4.CacheLine.cs index b871b479..7f74300d 100644 --- a/StgSharp.Common/HighPerformance/Memory/L4.CacheLine.cs +++ b/StgSharp.Common/HighPerformance/Memory/L4.CacheLine.cs @@ -25,6 +25,7 @@ // // ----------------------------------------------------------------------- // ----------------------------------------------------------------------- +using StgSharp.HighPerformance.ProcessorAbstraction; using System.Runtime.InteropServices; using Hlsf = StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocator; @@ -55,12 +56,13 @@ namespace StgSharp.HighPerformance.Memory { [FieldOffset(0)] internal Hlsf.Entry AllocatorEntry; + [FieldOffset(0)] internal readonly M512 Buffer; #region reference counting and state information [FieldOffset(52)] internal int RefCount; [FieldOffset(60)] private readonly int Reverse; - [FieldOffset(56)] internal int Id; + [FieldOffset(56)] internal readonly int Id; #endregion diff --git a/StgSharp.Common/HighPerformance/Memory/L4.Prefetch.cs b/StgSharp.Common/HighPerformance/Memory/L4.Prefetch.cs index 56835b88..f12531dd 100644 --- a/StgSharp.Common/HighPerformance/Memory/L4.Prefetch.cs +++ b/StgSharp.Common/HighPerformance/Memory/L4.Prefetch.cs @@ -137,12 +137,14 @@ namespace StgSharp.HighPerformance.Memory } } head = _head + index; - head->Id = index; head->Origin = address; head->Profile = pHandle.MapPolicy; head->RefCount = 0; head->Predictor = (short)predictIndex; + (*_predictCount)[index] = 1; + (*_mapCount)[index] = 1; + // pre fetch them here predict.Prefetch(head->Origin, head->Profile, new Span((byte*)head->Address, (int)head->Size)); _ = _map.TryAddOrSet(address, (nuint)head, out _); diff --git a/StgSharp.Common/HighPerformance/Memory/L4.cs b/StgSharp.Common/HighPerformance/Memory/L4.cs index 75f9df92..84ff2ef6 100644 --- a/StgSharp.Common/HighPerformance/Memory/L4.cs +++ b/StgSharp.Common/HighPerformance/Memory/L4.cs @@ -103,6 +103,11 @@ namespace StgSharp.HighPerformance.Memory ptr += predictionCountSize; _mapCount = (MapArray*)ptr; ptr += predictionCountSize; + + M512* mPtr = (M512*)_head; + for (uint i = 0; i < CacheLineCount; i++) { + mPtr->BroadCastFrom(i); + } } public nuint ByteCapacity { get; init; } diff --git a/StgSharp.Common/HighPerformance/ProcessorAbstraction/M512.cs b/StgSharp.Common/HighPerformance/ProcessorAbstraction/M512.cs index a3c75117..a29b9f77 100644 --- a/StgSharp.Common/HighPerformance/ProcessorAbstraction/M512.cs +++ b/StgSharp.Common/HighPerformance/ProcessorAbstraction/M512.cs @@ -42,7 +42,13 @@ namespace StgSharp.HighPerformance.ProcessorAbstraction { [FieldOffset(0)] private fixed byte _buffer[64]; - [FieldOffset(0)] private Vector512 Vec; + [FieldOffset(0)] private Vector512 Vec; + + public M512() + { + Unsafe.SkipInit(out this); + Unsafe.SkipInit(out Vec); + } public ref T AsRef() where T : unmanaged, INumber { @@ -53,7 +59,7 @@ namespace StgSharp.HighPerformance.ProcessorAbstraction T value ) where T : unmanaged, INumber { - Vec = Vector512.Create(value).AsSingle(); + Vec = Vector512.Create(value).AsByte(); } public ref T Member(