Skip to content

Commit 63b584b

Browse files
committed
Fix bug with GetHashCodeUnstable and GetHashCodeUnstableLower
When using tiered compilation, the method can switch from use of e.g. UnstableHashNonVectorLower and UnstableHashVec256Lower . However, these algorithms produce different results. Therefore, we force compilation of final Jit Tier (Tier 2) by forcing the AggressiveOptimization flag
1 parent d4ce3a9 commit 63b584b

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/Reloaded.Memory/Internals/Algorithms/UnstableStringHash.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ internal static class UnstableStringHash
2626
/// </remarks>
2727
[ExcludeFromCodeCoverage] // "Cannot be accurately measured without multiple architectures. Known good impl." This is still tested tho.
2828
[SuppressMessage("ReSharper", "InconsistentNaming")]
29+
#if NET5_0_OR_GREATER
30+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
31+
#else
2932
[MethodImpl(MethodImplOptions.AggressiveInlining)]
33+
#endif
3034
internal static unsafe nuint GetHashCodeUnstable(this ReadOnlySpan<char> text)
3135
{
3236
#if NET7_0_OR_GREATER
@@ -51,9 +55,7 @@ internal static unsafe nuint GetHashCodeUnstable(this ReadOnlySpan<char> text)
5155
}
5256

5357
#if NET7_0_OR_GREATER
54-
#if NET8_0 // Bug in .NET 8 seems to cause this to not re-jit to tier1 till like 200k calls on Linux x64
5558
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
56-
#endif
5759
internal static unsafe UIntPtr UnstableHashVec128(this ReadOnlySpan<char> text)
5860
{
5961
fixed (char* src = &text.GetPinnableReference())
@@ -118,9 +120,7 @@ internal static unsafe UIntPtr UnstableHashVec128(this ReadOnlySpan<char> text)
118120
}
119121
}
120122

121-
#if NET8_0 // Bug in .NET 8 seems to cause this to not re-jit to tier1 till like 200k calls on Linux x64
122123
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
123-
#endif
124124
internal static unsafe UIntPtr UnstableHashVec256(this ReadOnlySpan<char> text)
125125
{
126126
fixed (char* src = &text.GetPinnableReference())

src/Reloaded.Memory/Internals/Algorithms/UnstableStringHashLower.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ internal static class UnstableStringHashLower
3030
/// </remarks>
3131
[ExcludeFromCodeCoverage] // "Cannot be accurately measured without multiple architectures. Known good impl." This is still tested tho.
3232
[SuppressMessage("ReSharper", "InconsistentNaming")]
33+
#if NET5_0_OR_GREATER
34+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
35+
#else
3336
[MethodImpl(MethodImplOptions.AggressiveInlining)]
37+
#endif
3438
internal static unsafe nuint GetHashCodeUnstableLower(this ReadOnlySpan<char> text)
3539
{
3640
#if NET7_0_OR_GREATER
@@ -99,9 +103,7 @@ internal static unsafe nuint GetHashCodeUnstableLowerSlow(this ReadOnlySpan<char
99103
}
100104

101105
#if NET7_0_OR_GREATER
102-
#if NET8_0 // Bug in .NET 8 seems to cause this to not re-jit to tier1 till like 200k calls on Linux x64
103106
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
104-
#endif
105107
internal static unsafe UIntPtr UnstableHashVec128Lower(this ReadOnlySpan<char> text)
106108
{
107109
fixed (char* src = &text.GetPinnableReference())
@@ -222,9 +224,7 @@ internal static unsafe UIntPtr UnstableHashVec128Lower(this ReadOnlySpan<char> t
222224
return GetHashCodeUnstableLowerSlow(text);
223225
}
224226

225-
#if NET8_0 // Bug in .NET 8 seems to cause this to not re-jit to tier1 till like 200k calls on Linux x64
226227
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
227-
#endif
228228
internal static unsafe UIntPtr UnstableHashVec256Lower(this ReadOnlySpan<char> text)
229229
{
230230
fixed (char* src = &text.GetPinnableReference())

0 commit comments

Comments
 (0)