Skip to content

Commit

Permalink
Changed: Redefined thresholds on GetHashCodeUnstableLower in terms of…
Browse files Browse the repository at this point in the history
… nuint
  • Loading branch information
Sewer56 committed Mar 12, 2024
1 parent c7f9f88 commit 970e502
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ internal static unsafe nuint GetHashCodeUnstable(this ReadOnlySpan<char> text)
// For our use of hashing file paths, this is okay, as files with different names but same extension
// would still hash differently. If I were to PR this to runtime though, this would need fixing.

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

// Over 4 Vec128 regs (16 * 4 = 64 bytes)
if (Vector128.IsHardwareAccelerated && length >= (sizeof(Vector128<ulong>) / sizeof(char)) * 4)
if (Vector128.IsHardwareAccelerated && length >= sizeof(nuint) * 4)
return text.UnstableHashVec128();
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,15 @@ internal static unsafe nuint GetHashCodeUnstableLower(this ReadOnlySpan<char> te
{
#if NET7_0_OR_GREATER
var length = text.Length; // Span has no guarantee of null terminator.
// For short strings below size of nuint, we need separate approach; so we use legacy runtime approach
// for said cold case.

// Note: The `/ sizeof(char)` accounts that length is measured in 2-byte chars, not bytes.

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

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

// Over 4 Vec128 regs (16 * 4 = 64 bytes)
if (Vector128.IsHardwareAccelerated && length >= (sizeof(Vector128<ulong>) / sizeof(char)) * 4)
if (Vector128.IsHardwareAccelerated && length >= sizeof(nuint) * 4)
return text.UnstableHashVec128Lower();
#endif

Expand Down

0 comments on commit 970e502

Please sign in to comment.