solution to unsafe operation in l4

This commit is contained in:
Nitload
2026-04-13 00:12:29 +08:00
parent 556008ad8c
commit 61a5b49c22
2 changed files with 31 additions and 0 deletions
@@ -88,11 +88,16 @@ namespace StgSharp.HighPerformance.Memory
int predictId = head->_predictor;
IL4Predict belong = predictorSpan[predictId];
// 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))
{
head->_predictor =predictIndex;
} 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>((byte*)head->_address, Unsafe.SizeOf<CacheLineData>()));
head->_profile = pHandle.MapPolicy;
predict.Prefetch(head->_origin, head->_profile, new Span<byte>((byte*)head->_address, Unsafe.SizeOf<CacheLineData>()));