L4 is now on new algo, using tricky way to init entryies

This commit is contained in:
Youmu Liu
2026-04-23 18:07:14 +08:00
parent 1a6ce24a27
commit 2f6617447c
4 changed files with 19 additions and 4 deletions
@@ -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
@@ -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>((byte*)head->Address, (int)head->Size));
_ = _map.TryAddOrSet(address, (nuint)head, out _);
@@ -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<ulong>(i);
}
}
public nuint ByteCapacity { get; init; }
@@ -42,7 +42,13 @@ namespace StgSharp.HighPerformance.ProcessorAbstraction
{
[FieldOffset(0)] private fixed byte _buffer[64];
[FieldOffset(0)] private Vector512<float> Vec;
[FieldOffset(0)] private Vector512<byte> Vec;
public M512()
{
Unsafe.SkipInit(out this);
Unsafe.SkipInit(out Vec);
}
public ref T AsRef<T>() where T : unmanaged, INumber<T>
{
@@ -53,7 +59,7 @@ namespace StgSharp.HighPerformance.ProcessorAbstraction
T value
) where T : unmanaged, INumber<T>
{
Vec = Vector512.Create(value).AsSingle();
Vec = Vector512.Create(value).AsByte();
}
public ref T Member<T>(