Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions BitFaster.Caching/BitOps.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Text;
using System.Numerics;

namespace BitFaster.Caching
{
Expand Down Expand Up @@ -70,5 +67,14 @@ public static int BitCount(ulong x)
return BitOperations.PopCount(x);
#endif
}

// Computes Stafford variant 13 of 64-bit mix function.
// http://zimbry.blogspot.com/2011/09/better-bit-mixing-improving-on.html
public static ulong Mix64(ulong z)
{
z = (z ^ z >> 30) * 0xbf58476d1ce4e5b9L;
z = (z ^ z >> 27) * 0x94d049bb133111ebL;
return z ^ z >> 31;
}
}
}
36 changes: 1 addition & 35 deletions BitFaster.Caching/Buffers/StripedMpmcBuffer.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;

#if !NETSTANDARD2_0
using System.Runtime.Intrinsics.X86;
#endif

namespace BitFaster.Caching.Buffers
{
/// <summary>
Expand Down Expand Up @@ -59,28 +55,7 @@ public int DrainTo(T[] outputBuffer)

public BufferStatus TryAdd(T item)
{
// Is using Sse42.Crc32 faster?
//#if NETSTANDARD2_0
// ulong z = Mix64((ulong)Environment.CurrentManagedThreadId);
// int inc = (int)(z >> 32) | 1;
// int h = (int)z;
//#else
// int inc, h;

// // https://rigtorp.se/notes/hashing/
// if (Sse42.IsSupported)
// {
// h = inc = (int)Sse42.Crc32(486187739, (uint)Environment.CurrentManagedThreadId);
// }
// else
// {
// ulong z = Mix64((ulong)Environment.CurrentManagedThreadId);
// inc = (int)(z >> 32) | 1;
// h = (int)z;
// }
//#endif

var z = Mix64((ulong)Environment.CurrentManagedThreadId);
var z = BitOps.Mix64((ulong)Environment.CurrentManagedThreadId);
var inc = (int)(z >> 32) | 1;
var h = (int)z;

Expand Down Expand Up @@ -110,14 +85,5 @@ public void Clear()
buffers[i].Clear();
}
}

// Computes Stafford variant 13 of 64-bit mix function.
// http://zimbry.blogspot.com/2011/09/better-bit-mixing-improving-on.html
private static ulong Mix64(ulong z)
{
z = (z ^ z >> 30) * 0xbf58476d1ce4e5b9L;
z = (z ^ z >> 27) * 0x94d049bb133111ebL;
return z ^ z >> 31;
}
}
}
36 changes: 1 addition & 35 deletions BitFaster.Caching/Buffers/StripedMpscBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
using System.Diagnostics;
using System.Linq;

#if !NETSTANDARD2_0
using System.Runtime.Intrinsics.X86;
#endif

namespace BitFaster.Caching.Buffers
{
/// <summary>
Expand Down Expand Up @@ -60,28 +56,7 @@ public int DrainTo(T[] outputBuffer)

public BufferStatus TryAdd(T item)
{
// Is using Sse42.Crc32 faster?
//#if NETSTANDARD2_0
// ulong z = Mix64((ulong)Environment.CurrentManagedThreadId);
// int inc = (int)(z >> 32) | 1;
// int h = (int)z;
//#else
// int inc, h;

// // https://rigtorp.se/notes/hashing/
// if (Sse42.IsSupported)
// {
// h = inc = (int)Sse42.Crc32(486187739, (uint)Environment.CurrentManagedThreadId);
// }
// else
// {
// ulong z = Mix64((ulong)Environment.CurrentManagedThreadId);
// inc = (int)(z >> 32) | 1;
// h = (int)z;
// }
//#endif

var z = Mix64((ulong)Environment.CurrentManagedThreadId);
var z = BitOps.Mix64((ulong)Environment.CurrentManagedThreadId);
var inc = (int)(z >> 32) | 1;
var h = (int)z;

Expand Down Expand Up @@ -111,14 +86,5 @@ public void Clear()
buffers[i].Clear();
}
}

// Computes Stafford variant 13 of 64-bit mix function.
// http://zimbry.blogspot.com/2011/09/better-bit-mixing-improving-on.html
private static ulong Mix64(ulong z)
{
z = (z ^ z >> 30) * 0xbf58476d1ce4e5b9L;
z = (z ^ z >> 27) * 0x94d049bb133111ebL;
return z ^ z >> 31;
}
}
}