Skip to content

Commit 6877b0d

Browse files
author
Alex Peck
committed
cleanup
1 parent 3bf061d commit 6877b0d

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

BitFaster.Caching/Lfu/CmSketchCore.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System.Collections.Generic;
33
using System.Diagnostics.CodeAnalysis;
44
using System.Runtime.CompilerServices;
5+
using System.Runtime.InteropServices;
6+
57

68
#if !NETSTANDARD2_0
79
using System.Runtime.Intrinsics;
@@ -129,9 +131,10 @@ private void EnsureCapacity(long maximumSize)
129131
table = GC.AllocateArray<long>(Math.Max(BitOps.CeilingPowerOfTwo(maximum), 8) + pad, true);
130132

131133
tableAddr = (long*)Unsafe.AsPointer(ref table[0]);
132-
//long pointer = (long)Unsafe.AsPointer(ref table[0]);
133-
//tableAddr = (long*)pointer + pointer % 32;
134-
blockMask = (int)((uint)(table.Length-pad) >> 3) - 1;
134+
tableAddr = (long*)((long)tableAddr + (long)tableAddr % 32);
135+
136+
blockMask = (int)((uint)(table.Length - pad) >> 3) - 1;
137+
135138
#else
136139
table = new long[Math.Max(BitOps.CeilingPowerOfTwo(maximum), 8)];
137140
blockMask = (int)((uint)(table.Length) >> 3) - 1;
@@ -260,11 +263,11 @@ private unsafe int EstimateFrequencyAvx(T value)
260263
Vector128<int> blockOffset = Avx2.Add(Vector128.Create(block), offset); // i - table index
261264
blockOffset = Avx2.Add(blockOffset, Vector128.Create(0, 2, 4, 6)); // + (i << 1)
262265

263-
#if NET6_0_OR_GREATER
266+
#if NET6_0_OR_GREATER
264267
long* tablePtr = tableAddr;
265-
#else
268+
#else
266269
fixed (long* tablePtr = table)
267-
#endif
270+
#endif
268271
{
269272
Vector256<long> tableVector = Avx2.GatherVector256(tablePtr, blockOffset, 8);
270273
index = Avx2.ShiftLeftLogical(index, 2);
@@ -307,11 +310,11 @@ private unsafe void IncrementAvx(T value)
307310
Vector128<int> blockOffset = Avx2.Add(Vector128.Create(block), offset); // i - table index
308311
blockOffset = Avx2.Add(blockOffset, Vector128.Create(0, 2, 4, 6)); // + (i << 1)
309312

310-
#if NET6_0_OR_GREATER
313+
#if NET6_0_OR_GREATER
311314
long* tablePtr = tableAddr;
312-
#else
315+
#else
313316
fixed (long* tablePtr = table)
314-
#endif
317+
#endif
315318
{
316319
Vector256<long> tableVector = Avx2.GatherVector256(tablePtr, blockOffset, 8);
317320

0 commit comments

Comments
 (0)