Skip to content

Commit 225d480

Browse files
authored
dedupe (#234)
* dedupe * ns
1 parent 763d7ff commit 225d480

File tree

3 files changed

+12
-74
lines changed

3 files changed

+12
-74
lines changed

BitFaster.Caching/BitOps.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Numerics;
4-
using System.Text;
1+
using System.Numerics;
52

63
namespace BitFaster.Caching
74
{
@@ -70,5 +67,14 @@ public static int BitCount(ulong x)
7067
return BitOperations.PopCount(x);
7168
#endif
7269
}
70+
71+
// Computes Stafford variant 13 of 64-bit mix function.
72+
// http://zimbry.blogspot.com/2011/09/better-bit-mixing-improving-on.html
73+
public static ulong Mix64(ulong z)
74+
{
75+
z = (z ^ z >> 30) * 0xbf58476d1ce4e5b9L;
76+
z = (z ^ z >> 27) * 0x94d049bb133111ebL;
77+
return z ^ z >> 31;
78+
}
7379
}
7480
}

BitFaster.Caching/Buffers/StripedMpmcBuffer.cs

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
using System;
22

3-
#if !NETSTANDARD2_0
4-
using System.Runtime.Intrinsics.X86;
5-
#endif
6-
73
namespace BitFaster.Caching.Buffers
84
{
95
/// <summary>
@@ -59,28 +55,7 @@ public int DrainTo(T[] outputBuffer)
5955

6056
public BufferStatus TryAdd(T item)
6157
{
62-
// Is using Sse42.Crc32 faster?
63-
//#if NETSTANDARD2_0
64-
// ulong z = Mix64((ulong)Environment.CurrentManagedThreadId);
65-
// int inc = (int)(z >> 32) | 1;
66-
// int h = (int)z;
67-
//#else
68-
// int inc, h;
69-
70-
// // https://rigtorp.se/notes/hashing/
71-
// if (Sse42.IsSupported)
72-
// {
73-
// h = inc = (int)Sse42.Crc32(486187739, (uint)Environment.CurrentManagedThreadId);
74-
// }
75-
// else
76-
// {
77-
// ulong z = Mix64((ulong)Environment.CurrentManagedThreadId);
78-
// inc = (int)(z >> 32) | 1;
79-
// h = (int)z;
80-
// }
81-
//#endif
82-
83-
var z = Mix64((ulong)Environment.CurrentManagedThreadId);
58+
var z = BitOps.Mix64((ulong)Environment.CurrentManagedThreadId);
8459
var inc = (int)(z >> 32) | 1;
8560
var h = (int)z;
8661

@@ -110,14 +85,5 @@ public void Clear()
11085
buffers[i].Clear();
11186
}
11287
}
113-
114-
// Computes Stafford variant 13 of 64-bit mix function.
115-
// http://zimbry.blogspot.com/2011/09/better-bit-mixing-improving-on.html
116-
private static ulong Mix64(ulong z)
117-
{
118-
z = (z ^ z >> 30) * 0xbf58476d1ce4e5b9L;
119-
z = (z ^ z >> 27) * 0x94d049bb133111ebL;
120-
return z ^ z >> 31;
121-
}
12288
}
12389
}

BitFaster.Caching/Buffers/StripedMpscBuffer.cs

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
using System.Diagnostics;
33
using System.Linq;
44

5-
#if !NETSTANDARD2_0
6-
using System.Runtime.Intrinsics.X86;
7-
#endif
8-
95
namespace BitFaster.Caching.Buffers
106
{
117
/// <summary>
@@ -60,28 +56,7 @@ public int DrainTo(T[] outputBuffer)
6056

6157
public BufferStatus TryAdd(T item)
6258
{
63-
// Is using Sse42.Crc32 faster?
64-
//#if NETSTANDARD2_0
65-
// ulong z = Mix64((ulong)Environment.CurrentManagedThreadId);
66-
// int inc = (int)(z >> 32) | 1;
67-
// int h = (int)z;
68-
//#else
69-
// int inc, h;
70-
71-
// // https://rigtorp.se/notes/hashing/
72-
// if (Sse42.IsSupported)
73-
// {
74-
// h = inc = (int)Sse42.Crc32(486187739, (uint)Environment.CurrentManagedThreadId);
75-
// }
76-
// else
77-
// {
78-
// ulong z = Mix64((ulong)Environment.CurrentManagedThreadId);
79-
// inc = (int)(z >> 32) | 1;
80-
// h = (int)z;
81-
// }
82-
//#endif
83-
84-
var z = Mix64((ulong)Environment.CurrentManagedThreadId);
59+
var z = BitOps.Mix64((ulong)Environment.CurrentManagedThreadId);
8560
var inc = (int)(z >> 32) | 1;
8661
var h = (int)z;
8762

@@ -111,14 +86,5 @@ public void Clear()
11186
buffers[i].Clear();
11287
}
11388
}
114-
115-
// Computes Stafford variant 13 of 64-bit mix function.
116-
// http://zimbry.blogspot.com/2011/09/better-bit-mixing-improving-on.html
117-
private static ulong Mix64(ulong z)
118-
{
119-
z = (z ^ z >> 30) * 0xbf58476d1ce4e5b9L;
120-
z = (z ^ z >> 27) * 0x94d049bb133111ebL;
121-
return z ^ z >> 31;
122-
}
12389
}
12490
}

0 commit comments

Comments
 (0)