Skip to content

Commit 6f5bf86

Browse files
authored
isa (#268)
* isa * rename * rename * rename
1 parent 6c008fc commit 6f5bf86

File tree

6 files changed

+31
-31
lines changed

6 files changed

+31
-31
lines changed

BitFaster.Caching.Benchmarks/Lfu/SketchFrequency.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ namespace BitFaster.Caching.Benchmarks.Lfu
1212
public class SketchFrequency
1313
{
1414
const int iterations = 512;
15-
private static CmSketch<int, DisableAvx2> std = new CmSketch<int, DisableAvx2>(10, EqualityComparer<int>.Default);
16-
private static CmSketch<int, DetectAvx2> avx = new CmSketch<int, DetectAvx2>(10, EqualityComparer<int>.Default);
15+
private static CmSketch<int, DisableHardwareIntrinsics> std = new CmSketch<int, DisableHardwareIntrinsics>(10, EqualityComparer<int>.Default);
16+
private static CmSketch<int, DetectIsa> avx = new CmSketch<int, DetectIsa>(10, EqualityComparer<int>.Default);
1717

1818
[GlobalSetup]
1919
public void Setup()

BitFaster.Caching.Benchmarks/Lfu/SketchIncrement.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ namespace BitFaster.Caching.Benchmarks.Lfu
1212
public class SketchIncrement
1313
{
1414
const int iterations = 1024;
15-
private static CmSketch<int, DisableAvx2> std = new CmSketch<int, DisableAvx2>(10, EqualityComparer<int>.Default);
16-
private static CmSketch<int, DetectAvx2> avx = new CmSketch<int, DetectAvx2>(10, EqualityComparer<int>.Default);
15+
private static CmSketch<int, DisableHardwareIntrinsics> std = new CmSketch<int, DisableHardwareIntrinsics>(10, EqualityComparer<int>.Default);
16+
private static CmSketch<int, DetectIsa> avx = new CmSketch<int, DetectIsa>(10, EqualityComparer<int>.Default);
1717

1818
[Benchmark(Baseline = true)]
1919
public void Inc()

BitFaster.Caching.UnitTests/Lfu/CmSketchTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
namespace BitFaster.Caching.UnitTests.Lfu
99
{
1010
// Test with AVX2 if it is supported
11-
public class CMSketchAvx2Tests : CmSketchTestBase<DetectAvx2>
11+
public class CMSketchAvx2Tests : CmSketchTestBase<DetectIsa>
1212
{
1313
}
1414

1515
// Test with AVX2 disabled
16-
public class CmSketchTests : CmSketchTestBase<DisableAvx2>
16+
public class CmSketchTests : CmSketchTestBase<DisableHardwareIntrinsics>
1717
{
1818
}
1919

20-
public abstract class CmSketchTestBase<AVX2> where AVX2 : struct, IAvx2
20+
public abstract class CmSketchTestBase<I> where I : struct, IsaProbe
2121
{
22-
private CmSketch<int, AVX2> sketch = new CmSketch<int, AVX2>(512, EqualityComparer<int>.Default);
22+
private CmSketch<int, I> sketch = new CmSketch<int, I>(512, EqualityComparer<int>.Default);
2323

2424
public CmSketchTestBase()
2525
{
@@ -29,7 +29,7 @@ public CmSketchTestBase()
2929
[SkippableFact]
3030
public void WhenCapacityIsZeroDefaultsSelected()
3131
{
32-
sketch = new CmSketch<int, AVX2>(0, EqualityComparer<int>.Default);
32+
sketch = new CmSketch<int, I>(0, EqualityComparer<int>.Default);
3333

3434
sketch.ResetSampleSize.Should().Be(10);
3535
}
@@ -68,7 +68,7 @@ public void WhenSampleSizeExceededCountIsReset()
6868
{
6969
bool reset = false;
7070

71-
sketch = new CmSketch<int, AVX2>(64, EqualityComparer<int>.Default);
71+
sketch = new CmSketch<int, I>(64, EqualityComparer<int>.Default);
7272

7373
for (int i = 1; i < 20 * 64; i++)
7474
{
@@ -101,7 +101,7 @@ public void WhenClearedCountIsReset()
101101
private static void SkipAvxIfNotSupported()
102102
{
103103
// when we are trying to test Avx2, skip the test if it's not supported
104-
Skip.If(typeof(AVX2) == typeof(DetectAvx2) && !Avx2.IsSupported);
104+
Skip.If(typeof(I) == typeof(DetectIsa) && !Avx2.IsSupported);
105105
}
106106
}
107107
}

BitFaster.Caching/Intrinsics.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,36 @@
55
namespace BitFaster.Caching
66
{
77
/// <summary>
8-
/// Represents a marker interface to enable AVX2 specific optimization.
8+
/// Represents a marker interface to enable instruction set hardware intrinsics.
99
/// </summary>
10-
public interface IAvx2
10+
public interface IsaProbe
1111
{
1212
/// <summary>
13-
/// Gets a value indicating whether Avx2 is supported
13+
/// Gets a value indicating whether AVX2 is supported.
1414
/// </summary>
15-
bool IsSupported { get; }
15+
bool IsAvx2Supported { get; }
1616
}
1717

1818
/// <summary>
19-
/// Detect AVX2 support and enable if available.
19+
/// Detect support for hardware instructions via intrinsics.
2020
/// </summary>
21-
public struct DetectAvx2 : IAvx2
21+
public readonly struct DetectIsa : IsaProbe
2222
{
2323
#if NETSTANDARD2_0
2424
/// <inheritdoc/>
25-
public bool IsSupported => false;
25+
public bool IsAvx2Supported => false;
2626
#else
2727
/// <inheritdoc/>
28-
public bool IsSupported => Avx2.IsSupported;
28+
public bool IsAvx2Supported => Avx2.IsSupported;
2929
#endif
3030
}
3131

3232
/// <summary>
33-
/// Force disable AVX2.
33+
/// Force disable hardware instructions via intrinsics.
3434
/// </summary>
35-
public struct DisableAvx2 : IAvx2
35+
public readonly struct DisableHardwareIntrinsics : IsaProbe
3636
{
3737
/// <inheritdoc/>
38-
public bool IsSupported => false;
38+
public bool IsAvx2Supported => false;
3939
}
4040
}

BitFaster.Caching/Lfu/CmSketch.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace BitFaster.Caching.Lfu
1515
/// </summary>
1616
/// This is a direct C# translation of FrequencySketch in the Caffeine library by ben.manes@gmail.com (Ben Manes).
1717
/// https://github.com/ben-manes/caffeine
18-
public sealed class CmSketch<T, AVX2> where AVX2 : struct, IAvx2
18+
public sealed class CmSketch<T, I> where I : struct, IsaProbe
1919
{
2020
// A mixture of seeds from FNV-1a, CityHash, and Murmur3
2121
private static readonly ulong[] Seed = { 0xc3a5c85c97cb3127L, 0xb492b66fbe98f273L, 0x9ae16a3b2f90404fL, 0xcbf29ce484222325L};
@@ -61,9 +61,9 @@ public int EstimateFrequency(T value)
6161
return EstimateFrequencyStd(value);
6262
#else
6363

64-
AVX2 avx2 = default;
64+
I isa = default;
6565

66-
if (avx2.IsSupported)
66+
if (isa.IsAvx2Supported)
6767
{
6868
return EstimateFrequencyAvx(value);
6969
}
@@ -84,9 +84,9 @@ public void Increment(T value)
8484
IncrementStd(value);
8585
#else
8686

87-
AVX2 avx2 = default;
87+
I isa = default;
8888

89-
if (avx2.IsSupported)
89+
if (isa.IsAvx2Supported)
9090
{
9191
IncrementAvx(value);
9292
}

BitFaster.Caching/Lfu/ConcurrentLfu.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public sealed class ConcurrentLfu<K, V> : ICache<K, V>, IAsyncCache<K, V>, IBoun
5757

5858
private readonly CacheMetrics metrics = new CacheMetrics();
5959

60-
private readonly CmSketch<K, DetectAvx2> cmSketch;
60+
private readonly CmSketch<K, DetectIsa> cmSketch;
6161

6262
private readonly LfuNodeList<K, V> windowLru;
6363
private readonly LfuNodeList<K, V> probationLru;
@@ -100,7 +100,7 @@ public ConcurrentLfu(int concurrencyLevel, int capacity, IScheduler scheduler, I
100100
int writeBufferSize = Math.Min(BitOps.CeilingPowerOfTwo(capacity), 128);
101101
this.writeBuffer = new MpscBoundedBuffer<LfuNode<K, V>>(writeBufferSize);
102102

103-
this.cmSketch = new CmSketch<K, DetectAvx2>(capacity, comparer);
103+
this.cmSketch = new CmSketch<K, DetectIsa>(capacity, comparer);
104104
this.windowLru = new LfuNodeList<K, V>();
105105
this.probationLru = new LfuNodeList<K, V>();
106106
this.protectedLru = new LfuNodeList<K, V>();
@@ -617,11 +617,11 @@ private LfuNode<K, V> EvictFromWindow()
617617

618618
private ref struct EvictIterator
619619
{
620-
private readonly CmSketch<K, DetectAvx2> sketch;
620+
private readonly CmSketch<K, DetectIsa> sketch;
621621
public LfuNode<K, V> node;
622622
public int freq;
623623

624-
public EvictIterator(CmSketch<K, DetectAvx2> sketch, LfuNode<K, V> node)
624+
public EvictIterator(CmSketch<K, DetectIsa> sketch, LfuNode<K, V> node)
625625
{
626626
this.sketch = sketch;
627627
this.node = node;

0 commit comments

Comments
 (0)