This commit is contained in:
Youmu Liu
2026-03-26 18:02:13 +08:00
parent d960d02972
commit 06e3aa119b
20 changed files with 198 additions and 169 deletions
@@ -33,9 +33,11 @@ using System.Threading.Tasks;
namespace StgSharp.HighPerformance.Memory
{
public interface IPrefetchPredict
public interface IL4Predict
{
bool IsExhausted { get; }
/// <summary>
/// Writes predicted cache line descriptors into <paramref name="node" />.
/// </summary>
@@ -43,17 +45,20 @@ namespace StgSharp.HighPerformance.Memory
/// Prediction output buffer.
/// </param>
/// <param name="count">
/// When this method returns, contains the number of valid entries written to <paramref
/// When this method returns, contains the number of valid entries written to <paramref ///
/// name="node" />. The value must not exceed <paramref name="node" />.Length.
/// </param>
/// <returns>
/// <see langword="true" /> if any prediction data was produced; otherwise, <see langword="false"
/// />.
/// </returns>
bool Predict(Span<CacheLinePrediction> node, out int count);
bool Predict(
Span<CacheLinePrediction> node,
out int count
);
/// <summary>
/// Materializes the cache line identified by <paramref name="origin" /> into <paramref
/// Materializes the cache line identified by <paramref name="origin" /> into <paramref ///
/// name="cache" />.
/// </summary>
/// <param name="origin">
@@ -65,7 +70,11 @@ namespace StgSharp.HighPerformance.Memory
/// <param name="cache">
/// Destination cache line buffer.
/// </param>
void Prefetch(nuint origin, ulong policy, Span<byte> cache);
void Prefetch(
nuint origin,
ulong policy,
Span<byte> cache
);
/// <summary>
/// Writes the cache line in <paramref name="cache" /> back to <paramref name="origin" />.
@@ -79,21 +88,29 @@ namespace StgSharp.HighPerformance.Memory
/// <param name="cache">
/// Source cache line buffer.
/// </param>
void WriteBack(nuint origin, ulong policy, ReadOnlySpan<byte> cache);
void WriteBack(
nuint origin,
ulong policy,
ReadOnlySpan<byte> cache
);
}
public struct CacheLinePrediction : IEquatable<CacheLinePrediction>
{
public override readonly bool Equals(object? obj)
public override readonly bool Equals(
object? obj
)
{
return obj is CacheLinePrediction prediction &&
Address.Equals(prediction.Address) &&
MapPolicy == prediction.MapPolicy;
}
public readonly bool Equals(CacheLinePrediction other)
public readonly bool Equals(
CacheLinePrediction other
)
{
return
Address == other.Address && MapPolicy == other.MapPolicy;
@@ -104,11 +121,17 @@ namespace StgSharp.HighPerformance.Memory
return HashCode.Combine(Address, MapPolicy);
}
public static bool operator !=(CacheLinePrediction left, CacheLinePrediction right)
public static bool operator !=(
CacheLinePrediction left,
CacheLinePrediction right
)
{
return !(left == right);
}
public static bool operator ==(CacheLinePrediction left, CacheLinePrediction right)
public static bool operator ==(
CacheLinePrediction left,
CacheLinePrediction right
)
{
return left.Equals(right);
}