Daily update on 20260307-020120 by Nitload Youmu. Additional Message : None

Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
Nitload
2026-03-07 02:01:20 +08:00
parent 405f895e29
commit 64360b63a1
4 changed files with 475 additions and 192 deletions
+11 -39
View File
@@ -2,8 +2,8 @@
// -----------------------------------------------------------------------
// file="SwissTable"
// 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
@@ -43,14 +43,12 @@ namespace StgSharp.Collections
private const int BucketCount = 1 << EntryMaskWidth;
private const int BucketSize = 16;
private const uint CrcMagic = 0xffff9961; // Magic number for CRC32C, used in hash computation
private const int EntryMaskWidth = 16; // 65536 entries total, 16 per bucket
private const int EntryMaskWidth = 10; // 1024 entries total, 16 per bucket
public const int MaxCapacity = BucketCount * BucketSize; // 256 entries per bucket, 1024 buckets
private readonly Entry* _entries;
private SwissTable(
Entry* buffer
)
private SwissTable(Entry* buffer)
{
_entries = buffer;
}
@@ -66,11 +64,7 @@ namespace StgSharp.Collections
return new SwissTable(buffer);
}
public bool TryAddOrSet(
nint key,
nint value,
out bool isNewKey
)
public bool TryAddOrSet(nint key, nint value, out bool isNewKey)
{
uint hash = BitOperations.Crc32C(CrcMagic, (ulong)key);
ushort entry = (ushort)(hash & (BucketCount - 1));
@@ -78,10 +72,7 @@ namespace StgSharp.Collections
return IBucketScanner.Current.TrySet(key, hash, bucket, value, out isNewKey);
}
public bool TryGet(
nint key,
out nint value
)
public bool TryGet(nint key, out nint value)
{
uint hash = BitOperations.Crc32C(CrcMagic, (ulong)key);
ushort entry = (ushort)(hash & (BucketCount - 1));
@@ -96,10 +87,7 @@ namespace StgSharp.Collections
*/
}
public bool TryRemove(
nint key,
out nint value
)
public bool TryRemove(nint key, out nint value)
{
uint hash = BitOperations.Crc32C(CrcMagic, (ulong)key);
ushort entry = (ushort)(hash & (BucketCount - 1));
@@ -134,27 +122,11 @@ namespace StgSharp.Collections
static IBucketScanner Current { get; } = Create();
bool TryFind(
nint key,
uint Hash,
Bucket* bucket,
out nint value
);
bool TryFind(nint key, uint Hash, Bucket* bucket, out nint value);
unsafe bool TryRemove(
nint key,
uint hash,
Bucket* bucket,
out nint value
);
unsafe bool TryRemove(nint key, uint hash, Bucket* bucket, out nint value);
bool TrySet(
nint key,
uint hash,
Bucket* bucket,
nint value,
out bool isNewKey
);
bool TrySet(nint key, uint hash, Bucket* bucket, nint value, out bool isNewKey);
private static IBucketScanner Create()
{
@@ -197,4 +169,4 @@ namespace StgSharp.Collections
}
}
}
}
@@ -0,0 +1,59 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="L4"
// 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.Collections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.HighPerformance.Memory
{
public unsafe class L4
{
private readonly byte* _buffer;
private readonly SwissTable _map;
public nint MapMemory(nint address)
{
if (_map.TryGet(address, out nint ptr))
{
return ptr;
} else
{
/*
* register a request for memory mapping,
* and return a pointer to the mapped memory.
*/
return 0;
}
}
}
}
@@ -77,8 +77,8 @@ L4 缓存器是一个纯软件实现的**线程本地数据缓存层**,
| 参数 | 值 | 说明 |
|-------------------|-----------------------|-----------------------------------|
| 缓存区总容量 | 5-10 MB | 线程本地连续内存 |
| 缓存行大小 | 1024 Bytes | = 8 个 `double MAT_KERNEL` 的大小 |
| 映射表类型 | Swiss Table | 1024 桶 × 256 槽,SIMD 加速 |
| 缓存行大小 | 8192 Bytes | = 64 个 `double MAT_KERNEL` 的大小 |
| 映射表类型 | Swiss Table | 65536 桶 × 16 槽,SIMD 加速 |
| 缓存行存储池 | Slab Allocator | 非并发、固定容量、不自动扩容 |
| 逐出策略 | 4 级热度环形链表 | 基于访问频率的近似 LFU |
| 写回策略 | 无(只读缓存) | 逐出时直接丢弃,不写回远端 |