Skip to content

Commit dbe9b79

Browse files
committed
fix
1 parent adc9869 commit dbe9b79

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

BitFaster.Caching.Benchmarks/Lfu/SketchIncrement.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
using System.Collections.Generic;
3+
using Benchly;
34
using BenchmarkDotNet.Attributes;
45
using BenchmarkDotNet.Jobs;
56
using BitFaster.Caching.Lfu;
@@ -9,6 +10,7 @@ namespace BitFaster.Caching.Benchmarks.Lfu
910
[SimpleJob(RuntimeMoniker.Net60)]
1011
[MemoryDiagnoser(displayGenColumns: false)]
1112
[HideColumns("Job", "Median", "RatioSD", "Alloc Ratio")]
13+
[ColumnChart(Title = "Sketch Increment ({JOB})")]
1214
public class SketchIncrement
1315
{
1416
const int iterations = 1_048_576;

BitFaster.Caching.UnitTests/Intrinsics.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ public static class Intrinsics
1414
public static void SkipAvxIfNotSupported<I>()
1515
{
1616
#if NETCOREAPP3_1_OR_GREATER
17-
#if NET6_0_OR_GREATER
18-
// when we are trying to test Avx2, skip the test if it's not supported
17+
#if NET6_0_OR_GREATER
18+
// when we are trying to test Avx2/Arm64, skip the test if it's not supported
1919
Skip.If(typeof(I) == typeof(DetectIsa) && !(Avx2.IsSupported || AdvSimd.Arm64.IsSupported));
20-
#else
21-
// when we are trying to test Avx2, skip the test if it's not supported
20+
#else
21+
// when we are trying to test Avx2, skip the test if it's not supported
2222
Skip.If(typeof(I) == typeof(DetectIsa) && !Avx2.IsSupported);
23-
#endif
24-
23+
#endif
2524

2625
#else
2726
Skip.If(true);

BitFaster.Caching.UnitTests/Lfu/CmSketchTests.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
namespace BitFaster.Caching.UnitTests.Lfu
88
{
9-
// Test with AVX2 or ARM64 if it is supported
10-
public class CMSketchAvx2Tests : CmSketchTestBase<DetectIsa>
9+
// Test with AVX2/ARM64 if it is supported
10+
public class CMSketchIntrinsicsTests : CmSketchTestBase<DetectIsa>
1111
{
1212
}
1313

14-
// Test with AVX2 disabled
14+
// Test with AVX2/ARM64 disabled
1515
public class CmSketchTests : CmSketchTestBase<DisableHardwareIntrinsics>
1616
{
1717
}
@@ -29,14 +29,23 @@ public CmSketchTestBase()
2929
public void Repro()
3030
{
3131
sketch = new CmSketchCore<int, I>(1_048_576, EqualityComparer<int>.Default);
32+
var baseline = new CmSketchCore<int, DisableHardwareIntrinsics>(1_048_576, EqualityComparer<int>.Default);
3233

3334
for (int i = 0; i < 1_048_576; i++)
3435
{
3536
if (i % 3 == 0)
3637
{
3738
sketch.Increment(i);
39+
baseline.Increment(i);
3840
}
3941
}
42+
43+
baseline.Size.Should().Be(sketch.Size);
44+
45+
for (int i = 0; i < 1_048_576; i++)
46+
{
47+
sketch.EstimateFrequency(i).Should().Be(baseline.EstimateFrequency(i));
48+
}
4049
}
4150

4251

BitFaster.Caching/Lfu/CmSketchCore.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -473,12 +473,15 @@ private unsafe int EstimateFrequencyArm(T value)
473473
a = AdvSimd.And(a, fifteen);
474474
b = AdvSimd.And(b, fifteen);
475475

476-
var minA = AdvSimd.Arm64.MinAcross(a.AsInt32());
477-
var minB = AdvSimd.Arm64.MinAcross(b.AsInt32());
478-
minA = AdvSimd.Arm64.InsertSelectedScalar(minA, 1, minB, 0);
479-
var min = AdvSimd.Arm64.MinAcross(minA.AsInt16());
476+
// TODO: VectorTableLookup
477+
Vector128<int> x = AdvSimd.Arm64.InsertSelectedScalar(Vector128<int>.Zero, 0, a.AsInt32(), 0);
478+
x = AdvSimd.Arm64.InsertSelectedScalar(x, 1, a.AsInt32(), 2);
479+
x = AdvSimd.Arm64.InsertSelectedScalar(x, 2, b.AsInt32(), 0);
480+
x = AdvSimd.Arm64.InsertSelectedScalar(x, 3, b.AsInt32(), 2);
481+
482+
var minA = AdvSimd.Arm64.MinAcross(x);
480483

481-
return min.ToScalar();
484+
return minA.ToScalar();
482485
}
483486
}
484487
#endif

0 commit comments

Comments
 (0)