add multi predictor support to l4, working for ver 5 of mat parallel

This commit is contained in:
Youmu Liu
2026-04-09 18:07:49 +08:00
parent 0bad6bb480
commit f7187ca7fd
19 changed files with 653 additions and 187 deletions
@@ -0,0 +1,100 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="ConcurrentList"
// 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.Text;
using System.Threading.Tasks;
namespace StgSharp.Common.Collections
{
public class ConcurrentFlexibleArray<T>(
int capacity = 4
)
{
private volatile T[] _array = new T[capacity];
private readonly ReaderWriterLockSlim _rwLock = new();
public T this[
int index
]
{
get
{
_rwLock.EnterReadLock();
try
{
if ((uint)index >= (uint)_array.Length) {
throw new ArgumentOutOfRangeException(nameof(index));
}
return _array[index];
}
finally
{
_rwLock.ExitReadLock();
}
}
set
{
if ((uint)index >= (uint)_array.Length)
{
_rwLock.EnterWriteLock();
try
{
if ((uint)index >= (uint)_array.Length)
{
int newSize = Math.Max(_array.Length * 2, index + 1);
T[] newArray = new T[newSize];
Array.Copy(_array, newArray, _array.Length);
_array = newArray;
_array[index] = value;
}
}
finally
{
_rwLock.ExitWriteLock();
}
} else
{
_rwLock.EnterReadLock();
try
{
_array[index] = value;
}
finally
{
_rwLock.ExitReadLock();
}
}
}
}
}
}
+28 -11
View File
@@ -1,4 +1,4 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="ListSegment"
// Project: StgSharp
@@ -50,7 +50,11 @@ namespace StgSharp.Collections
private int _length;
private List<T> _collection;
public ListSegment(List<T> collection, int begin, int length)
public ListSegment(
List<T> collection,
int begin,
int length
)
{
ArgumentNullException.ThrowIfNull(collection);
ArgumentOutOfRangeException.ThrowIfLessThan(begin, 0);
@@ -61,7 +65,9 @@ namespace StgSharp.Collections
_length = length;
}
public T this[int indexValue]
public T this[
int indexValue
]
{
get
{
@@ -71,11 +77,13 @@ namespace StgSharp.Collections
}
}
public T this[Index i]
public T this[
Index i
]
{
get
{
int offset = i.IsFromEnd ? _length - i.Value : i.Value;
int offset = i.IsFromEnd ? (_length - i.Value) : i.Value;
ArgumentOutOfRangeException.ThrowIfLessThan(offset, 0);
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(offset, _length);
return _collection[offset + _begin];
@@ -86,17 +94,22 @@ namespace StgSharp.Collections
public int Count => _length;
public bool Contains(T item)
public bool Contains(
T item
)
{
int index = _collection.IndexOf(item);
return index >= _begin && index < _length + index;
return (index >= _begin) && (index < _length + index);
}
public void CopyTo(T[] array, int arrayIndex)
public void CopyTo(
T[] array,
int arrayIndex
)
{
ArgumentNullException.ThrowIfNull(array);
Span<T> span = CollectionsMarshal.AsSpan<T>(_collection).Slice(_begin, _length);
Span<T> target = new Span<T>(array, arrayIndex, _length);
Span<T> target = new(array, arrayIndex, _length);
span.CopyTo(target);
}
@@ -107,7 +120,9 @@ namespace StgSharp.Collections
}
}
void ICollection<T>.Add(T item)
void ICollection<T>.Add(
T item
)
{
throw new NotSupportedException();
}
@@ -117,7 +132,9 @@ namespace StgSharp.Collections
throw new NotSupportedException();
}
bool ICollection<T>.Remove(T item)
bool ICollection<T>.Remove(
T item
)
{
throw new NotSupportedException();
}
@@ -107,8 +107,6 @@ namespace StgSharp.Collections
byte ctrl = (byte)((hash >> EntryMaskWidth) & 0x7F); // H2: upper 8 bits (highest bit is naturally 0)
Vector128<byte> ctrlVector = Vector128.Create(ctrl);
int firstAvailableSlot = -1; // Record the first insertable slot
Vector128<byte> bucketCtrl = Sse2.LoadVector128(
(byte*)&bucket->Control);