Use the accelerated Count on AVX-512 CPUs

The AVX-512 level fell through to the generic loop. _count only needs
POPCNT, which every AVX-512 CPU has.

Fixes #46
This commit is contained in:
dualfroz committed 2026-10-02 16:28:14 +02:00
1 parent 47698fd8b9
commit d648d30d86
2 files changed
+15 -1

No files matched your search

+1 -1
View File
@@ -156,7 +156,7 @@ func (dst Bitmap) Count() int {
} }
switch hardware { switch hardware {
case isAccelerated: case isAccelerated, isAVX512:
var res uint64 var res uint64
_count(unsafe.Pointer(&dst[0]), uint64(len(dst)), unsafe.Pointer(&res)) _count(unsafe.Pointer(&dst[0]), uint64(len(dst)), unsafe.Pointer(&res))
return int(res) return int(res)
+14
View File
@@ -419,6 +419,20 @@ func TestCount(t *testing.T) {
assert.Equal(t, 9, b.CountTo(128)) assert.Equal(t, 9, b.CountTo(128))
} }
func TestCountWithHardware(t *testing.T) {
defer func(level int) { hardware = level }(hardware)
var b Bitmap
for i := uint32(0); i < 10000; i += 3 {
b.Set(i)
}
for _, level := range []int{isUnsupported, isAccelerated, isAVX512} {
hardware = level
assert.Equal(t, 3334, b.Count(), "hardware=%d", level)
}
}
func TestGrow(t *testing.T) { func TestGrow(t *testing.T) {
bitmap := make(Bitmap, 1, 5) bitmap := make(Bitmap, 1, 5)
bitmap[0] = 42 bitmap[0] = 42