Skip to content

Commit 970e502

Browse files
committed
Changed: Redefined thresholds on GetHashCodeUnstableLower in terms of nuint
1 parent c7f9f88 commit 970e502

2 files changed

Lines changed: 4 additions & 12 deletions

File tree

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@ internal static unsafe nuint GetHashCodeUnstable(this ReadOnlySpan<char> text)
4040
// For our use of hashing file paths, this is okay, as files with different names but same extension
4141
// would still hash differently. If I were to PR this to runtime though, this would need fixing.
4242

43-
// Over 4 Vec256 regs (32 * 4 = 128 bytes)
44-
if (Vector256.IsHardwareAccelerated && length >= (sizeof(Vector256<ulong>) / sizeof(char)) * 4)
43+
if (Vector256.IsHardwareAccelerated && length >= sizeof(nuint) * 8)
4544
return text.UnstableHashVec256();
4645

47-
// Over 4 Vec128 regs (16 * 4 = 64 bytes)
48-
if (Vector128.IsHardwareAccelerated && length >= (sizeof(Vector128<ulong>) / sizeof(char)) * 4)
46+
if (Vector128.IsHardwareAccelerated && length >= sizeof(nuint) * 4)
4947
return text.UnstableHashVec128();
5048
#endif
5149

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,15 @@ internal static unsafe nuint GetHashCodeUnstableLower(this ReadOnlySpan<char> te
3535
{
3636
#if NET7_0_OR_GREATER
3737
var length = text.Length; // Span has no guarantee of null terminator.
38-
// For short strings below size of nuint, we need separate approach; so we use legacy runtime approach
39-
// for said cold case.
40-
41-
// Note: The `/ sizeof(char)` accounts that length is measured in 2-byte chars, not bytes.
4238

4339
// Note. In these SIMD implementations we leave some (< sizeof(nuint)) data from the hash.
4440
// For our use of hashing file paths, this is okay, as files with different names but same extension
4541
// would still hash differently. If I were to PR this to runtime though, this would need fixing.
4642

47-
// Over 4 Vec256 regs (32 * 4 = 128 bytes)
48-
if (Vector256.IsHardwareAccelerated && length >= (sizeof(Vector256<ulong>) / sizeof(char)) * 4)
43+
if (Vector256.IsHardwareAccelerated && length >= sizeof(nuint) * 8)
4944
return text.UnstableHashVec256Lower();
5045

51-
// Over 4 Vec128 regs (16 * 4 = 64 bytes)
52-
if (Vector128.IsHardwareAccelerated && length >= (sizeof(Vector128<ulong>) / sizeof(char)) * 4)
46+
if (Vector128.IsHardwareAccelerated && length >= sizeof(nuint) * 4)
5347
return text.UnstableHashVec128Lower();
5448
#endif
5549

0 commit comments

Comments
 (0)