From 5252be9436e8555db728c0f0ef83ce9f07809383 Mon Sep 17 00:00:00 2001 From: Youmu Liu <105042599+Nitload-NSI@users.noreply.github.com> Date: Wed, 22 Apr 2026 18:11:00 +0800 Subject: [PATCH] L4 removes RRPV array, will not support cross-predictor reuse, will use out-line predictcount and map count array, will not use inline predict count. --- .../HighPerformance/Memory/L4.Exceptions.cs | 12 ++++++++++++ .../HighPerformance/Memory/L4.Prefetch.cs | 9 ++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/StgSharp.Common/HighPerformance/Memory/L4.Exceptions.cs b/StgSharp.Common/HighPerformance/Memory/L4.Exceptions.cs index 162f4ae9..23b1cf77 100644 --- a/StgSharp.Common/HighPerformance/Memory/L4.Exceptions.cs +++ b/StgSharp.Common/HighPerformance/Memory/L4.Exceptions.cs @@ -42,4 +42,16 @@ namespace StgSharp.HighPerformance.Memory : base($"L4 predictor with id {id} is null. Maybe it has been unregistered.") { } } + + public sealed class L4PredictConflictException : Exception + { + + public L4PredictConflictException( + nuint basePtr, + ushort policy, + int current + ) + : base($"L4 predictor with id {current} has already registered a cache line with base pointer {basePtr} and policy {policy}.") { } + + } } diff --git a/StgSharp.Common/HighPerformance/Memory/L4.Prefetch.cs b/StgSharp.Common/HighPerformance/Memory/L4.Prefetch.cs index 987b67f3..def8d25a 100644 --- a/StgSharp.Common/HighPerformance/Memory/L4.Prefetch.cs +++ b/StgSharp.Common/HighPerformance/Memory/L4.Prefetch.cs @@ -93,16 +93,15 @@ namespace StgSharp.HighPerformance.Memory // This branch performs resident-line adoption rather than a simple policy // equality check. Returning true means the current predictor can keep using // the existing cache bytes without a write-back plus re-prefetch cycle. - if (predict.IsSamePolicy(head->Profile, belong)) + if (!ReferenceEquals(predict, belong)) { - head->Predictor = (short)predictIndex; + throw new L4PredictConflictException(head->Origin, head->Profile, predictId); } else { // Compatibility failed, so the old owner must first flush its view of // the line before the new predictor rematerializes the cache bytes. - belong.WriteBack(head->Origin, head->Profile, new ReadOnlySpan((byte*)head->Address, (int)head->Size)); - head->Profile = pHandle.MapPolicy; - predict.Prefetch(head->Origin, head->Profile, new Span((byte*)head->Address, (int)head->Size)); + + _ = Interlocked.Increment(ref head->RemainingPredictionCount); } #endregion