|
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Diagnostics.CodeAnalysis; |
4 | 4 | using System.Runtime.CompilerServices; |
| 5 | +using System.Runtime.InteropServices; |
| 6 | + |
5 | 7 |
|
6 | 8 | #if !NETSTANDARD2_0 |
7 | 9 | using System.Runtime.Intrinsics; |
@@ -129,9 +131,10 @@ private void EnsureCapacity(long maximumSize) |
129 | 131 | table = GC.AllocateArray<long>(Math.Max(BitOps.CeilingPowerOfTwo(maximum), 8) + pad, true); |
130 | 132 |
|
131 | 133 | 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 | + |
135 | 138 | #else |
136 | 139 | table = new long[Math.Max(BitOps.CeilingPowerOfTwo(maximum), 8)]; |
137 | 140 | blockMask = (int)((uint)(table.Length) >> 3) - 1; |
@@ -260,11 +263,11 @@ private unsafe int EstimateFrequencyAvx(T value) |
260 | 263 | Vector128<int> blockOffset = Avx2.Add(Vector128.Create(block), offset); // i - table index |
261 | 264 | blockOffset = Avx2.Add(blockOffset, Vector128.Create(0, 2, 4, 6)); // + (i << 1) |
262 | 265 |
|
263 | | - #if NET6_0_OR_GREATER |
| 266 | +#if NET6_0_OR_GREATER |
264 | 267 | long* tablePtr = tableAddr; |
265 | | - #else |
| 268 | +#else |
266 | 269 | fixed (long* tablePtr = table) |
267 | | - #endif |
| 270 | +#endif |
268 | 271 | { |
269 | 272 | Vector256<long> tableVector = Avx2.GatherVector256(tablePtr, blockOffset, 8); |
270 | 273 | index = Avx2.ShiftLeftLogical(index, 2); |
@@ -307,11 +310,11 @@ private unsafe void IncrementAvx(T value) |
307 | 310 | Vector128<int> blockOffset = Avx2.Add(Vector128.Create(block), offset); // i - table index |
308 | 311 | blockOffset = Avx2.Add(blockOffset, Vector128.Create(0, 2, 4, 6)); // + (i << 1) |
309 | 312 |
|
310 | | - #if NET6_0_OR_GREATER |
| 313 | +#if NET6_0_OR_GREATER |
311 | 314 | long* tablePtr = tableAddr; |
312 | | - #else |
| 315 | +#else |
313 | 316 | fixed (long* tablePtr = table) |
314 | | - #endif |
| 317 | +#endif |
315 | 318 | { |
316 | 319 | Vector256<long> tableVector = Avx2.GatherVector256(tablePtr, blockOffset, 8); |
317 | 320 |
|
|
0 commit comments