Skip to content

Commit 87eb6e4

Browse files
authored
zero again (#296)
* zero * AllBitsSet
1 parent ca3b8da commit 87eb6e4

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

BitFaster.Caching/Lfu/CmSketch.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ private unsafe int EstimateFrequencyAvx(T value)
247247
index = Avx2.ShiftLeftLogical(index, 2);
248248

249249
// convert index from int to long via permute
250-
Vector256<long> indexLong = Vector256.Create(index, Vector128.Create(0)).AsInt64();
250+
Vector256<long> indexLong = Vector256.Create(index, Vector128<int>.Zero).AsInt64();
251251
Vector256<int> permuteMask2 = Vector256.Create(0, 4, 1, 5, 2, 5, 3, 7);
252252
indexLong = Avx2.PermuteVar8x32(indexLong.AsInt32(), permuteMask2).AsInt64();
253253
tableVector = Avx2.ShiftRightLogicalVariable(tableVector, indexLong.AsUInt64());
@@ -259,7 +259,12 @@ private unsafe int EstimateFrequencyAvx(T value)
259259
.AsUInt16();
260260

261261
// set the zeroed high parts of the long value to ushort.Max
262+
#if NET6_0
263+
count = Avx2.Blend(count, Vector128<ushort>.AllBitsSet, 0b10101010);
264+
#else
262265
count = Avx2.Blend(count, Vector128.Create(ushort.MaxValue), 0b10101010);
266+
#endif
267+
263268
return Avx2.MinHorizontal(count).GetElement(0);
264269
}
265270
}
@@ -309,7 +314,7 @@ private unsafe void IncrementAvx(T value)
309314
tablePtr[blockOffset.GetElement(2)] += inc.GetElement(2);
310315
tablePtr[blockOffset.GetElement(3)] += inc.GetElement(3);
311316

312-
Vector256<byte> result = Avx2.CompareEqual(masked.AsByte(), Vector256.Create(0).AsByte());
317+
Vector256<byte> result = Avx2.CompareEqual(masked.AsByte(), Vector256<byte>.Zero);
313318
bool wasInc = Avx2.MoveMask(result.AsByte()) == unchecked((int)(0b1111_1111_1111_1111_1111_1111_1111_1111));
314319

315320
if (wasInc && (++size == sampleSize))
@@ -319,5 +324,5 @@ private unsafe void IncrementAvx(T value)
319324
}
320325
}
321326
#endif
322-
}
327+
}
323328
}

0 commit comments

Comments
 (0)