diff --git a/BitFaster.Caching.Benchmarks/Lfu/SketchFrequency.cs b/BitFaster.Caching.Benchmarks/Lfu/SketchFrequency.cs index cd6fef90..e3f84544 100644 --- a/BitFaster.Caching.Benchmarks/Lfu/SketchFrequency.cs +++ b/BitFaster.Caching.Benchmarks/Lfu/SketchFrequency.cs @@ -12,8 +12,8 @@ namespace BitFaster.Caching.Benchmarks.Lfu public class SketchFrequency { const int iterations = 512; - private static CmSketch std = new CmSketch(10, EqualityComparer.Default); - private static CmSketch avx = new CmSketch(10, EqualityComparer.Default); + private static CmSketch std = new CmSketch(10, EqualityComparer.Default); + private static CmSketch avx = new CmSketch(10, EqualityComparer.Default); [GlobalSetup] public void Setup() diff --git a/BitFaster.Caching.Benchmarks/Lfu/SketchIncrement.cs b/BitFaster.Caching.Benchmarks/Lfu/SketchIncrement.cs index c1c38732..33aba15a 100644 --- a/BitFaster.Caching.Benchmarks/Lfu/SketchIncrement.cs +++ b/BitFaster.Caching.Benchmarks/Lfu/SketchIncrement.cs @@ -12,8 +12,8 @@ namespace BitFaster.Caching.Benchmarks.Lfu public class SketchIncrement { const int iterations = 1024; - private static CmSketch std = new CmSketch(10, EqualityComparer.Default); - private static CmSketch avx = new CmSketch(10, EqualityComparer.Default); + private static CmSketch std = new CmSketch(10, EqualityComparer.Default); + private static CmSketch avx = new CmSketch(10, EqualityComparer.Default); [Benchmark(Baseline = true)] public void Inc() diff --git a/BitFaster.Caching.UnitTests/Lfu/CmSketchTests.cs b/BitFaster.Caching.UnitTests/Lfu/CmSketchTests.cs index f04c5813..54e29b6c 100644 --- a/BitFaster.Caching.UnitTests/Lfu/CmSketchTests.cs +++ b/BitFaster.Caching.UnitTests/Lfu/CmSketchTests.cs @@ -8,18 +8,18 @@ namespace BitFaster.Caching.UnitTests.Lfu { // Test with AVX2 if it is supported - public class CMSketchAvx2Tests : CmSketchTestBase + public class CMSketchAvx2Tests : CmSketchTestBase { } // Test with AVX2 disabled - public class CmSketchTests : CmSketchTestBase + public class CmSketchTests : CmSketchTestBase { } - public abstract class CmSketchTestBase where AVX2 : struct, IAvx2 + public abstract class CmSketchTestBase where I : struct, IsaProbe { - private CmSketch sketch = new CmSketch(512, EqualityComparer.Default); + private CmSketch sketch = new CmSketch(512, EqualityComparer.Default); public CmSketchTestBase() { @@ -29,7 +29,7 @@ public CmSketchTestBase() [SkippableFact] public void WhenCapacityIsZeroDefaultsSelected() { - sketch = new CmSketch(0, EqualityComparer.Default); + sketch = new CmSketch(0, EqualityComparer.Default); sketch.ResetSampleSize.Should().Be(10); } @@ -68,7 +68,7 @@ public void WhenSampleSizeExceededCountIsReset() { bool reset = false; - sketch = new CmSketch(64, EqualityComparer.Default); + sketch = new CmSketch(64, EqualityComparer.Default); for (int i = 1; i < 20 * 64; i++) { @@ -101,7 +101,7 @@ public void WhenClearedCountIsReset() private static void SkipAvxIfNotSupported() { // when we are trying to test Avx2, skip the test if it's not supported - Skip.If(typeof(AVX2) == typeof(DetectAvx2) && !Avx2.IsSupported); + Skip.If(typeof(I) == typeof(DetectIsa) && !Avx2.IsSupported); } } } diff --git a/BitFaster.Caching/Intrinsics.cs b/BitFaster.Caching/Intrinsics.cs index 4c487ecc..8a1bd29a 100644 --- a/BitFaster.Caching/Intrinsics.cs +++ b/BitFaster.Caching/Intrinsics.cs @@ -5,36 +5,36 @@ namespace BitFaster.Caching { /// - /// Represents a marker interface to enable AVX2 specific optimization. + /// Represents a marker interface to enable instruction set hardware intrinsics. /// - public interface IAvx2 + public interface IsaProbe { /// - /// Gets a value indicating whether Avx2 is supported + /// Gets a value indicating whether AVX2 is supported. /// - bool IsSupported { get; } + bool IsAvx2Supported { get; } } /// - /// Detect AVX2 support and enable if available. + /// Detect support for hardware instructions via intrinsics. /// - public struct DetectAvx2 : IAvx2 + public readonly struct DetectIsa : IsaProbe { #if NETSTANDARD2_0 /// - public bool IsSupported => false; + public bool IsAvx2Supported => false; #else /// - public bool IsSupported => Avx2.IsSupported; + public bool IsAvx2Supported => Avx2.IsSupported; #endif } /// - /// Force disable AVX2. + /// Force disable hardware instructions via intrinsics. /// - public struct DisableAvx2 : IAvx2 + public readonly struct DisableHardwareIntrinsics : IsaProbe { /// - public bool IsSupported => false; + public bool IsAvx2Supported => false; } } diff --git a/BitFaster.Caching/Lfu/CmSketch.cs b/BitFaster.Caching/Lfu/CmSketch.cs index 73e744fe..f0ea491d 100644 --- a/BitFaster.Caching/Lfu/CmSketch.cs +++ b/BitFaster.Caching/Lfu/CmSketch.cs @@ -15,7 +15,7 @@ namespace BitFaster.Caching.Lfu /// /// This is a direct C# translation of FrequencySketch in the Caffeine library by ben.manes@gmail.com (Ben Manes). /// https://github.com/ben-manes/caffeine - public sealed class CmSketch where AVX2 : struct, IAvx2 + public sealed class CmSketch where I : struct, IsaProbe { // A mixture of seeds from FNV-1a, CityHash, and Murmur3 private static readonly ulong[] Seed = { 0xc3a5c85c97cb3127L, 0xb492b66fbe98f273L, 0x9ae16a3b2f90404fL, 0xcbf29ce484222325L}; @@ -61,9 +61,9 @@ public int EstimateFrequency(T value) return EstimateFrequencyStd(value); #else - AVX2 avx2 = default; + I isa = default; - if (avx2.IsSupported) + if (isa.IsAvx2Supported) { return EstimateFrequencyAvx(value); } @@ -84,9 +84,9 @@ public void Increment(T value) IncrementStd(value); #else - AVX2 avx2 = default; + I isa = default; - if (avx2.IsSupported) + if (isa.IsAvx2Supported) { IncrementAvx(value); } diff --git a/BitFaster.Caching/Lfu/ConcurrentLfu.cs b/BitFaster.Caching/Lfu/ConcurrentLfu.cs index d3410891..949f4ea9 100644 --- a/BitFaster.Caching/Lfu/ConcurrentLfu.cs +++ b/BitFaster.Caching/Lfu/ConcurrentLfu.cs @@ -57,7 +57,7 @@ public sealed class ConcurrentLfu : ICache, IAsyncCache, IBoun private readonly CacheMetrics metrics = new CacheMetrics(); - private readonly CmSketch cmSketch; + private readonly CmSketch cmSketch; private readonly LfuNodeList windowLru; private readonly LfuNodeList probationLru; @@ -100,7 +100,7 @@ public ConcurrentLfu(int concurrencyLevel, int capacity, IScheduler scheduler, I int writeBufferSize = Math.Min(BitOps.CeilingPowerOfTwo(capacity), 128); this.writeBuffer = new MpscBoundedBuffer>(writeBufferSize); - this.cmSketch = new CmSketch(capacity, comparer); + this.cmSketch = new CmSketch(capacity, comparer); this.windowLru = new LfuNodeList(); this.probationLru = new LfuNodeList(); this.protectedLru = new LfuNodeList(); @@ -617,11 +617,11 @@ private LfuNode EvictFromWindow() private ref struct EvictIterator { - private readonly CmSketch sketch; + private readonly CmSketch sketch; public LfuNode node; public int freq; - public EvictIterator(CmSketch sketch, LfuNode node) + public EvictIterator(CmSketch sketch, LfuNode node) { this.sketch = sketch; this.node = node;