Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/google/uuid v1.6.0
github.com/mschoch/smat v0.2.0
github.com/stretchr/testify v1.11.1
golang.org/x/sys v0.30.0
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ golang.org/x/mod v0.23.0 h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM=
golang.org/x/mod v0.23.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
golang.org/x/tools v0.30.0 h1:BgcpHewrV5AUp2G9MebG4XPFI1E2W41zU1SaqVA9vJY=
Expand Down
15 changes: 15 additions & 0 deletions popcnt_avx2_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,49 @@ func _popcntXorSliceAVX2(s, m []uint64) uint64
var useAVX2 = _hasAVX2()

func popcntSlice(s []uint64) uint64 {
if useAVX512Popcnt {
return popcntSliceAVX512(s)
}
if useAVX2 {
return _popcntSliceAVX2(s)
}
return popcntSliceGo(s)
}

func popcntMaskSlice(s, m []uint64) uint64 {
if useAVX512Popcnt {
return popcntMaskSliceAVX512(s, m)
}
if useAVX2 {
return _popcntMaskSliceAVX2(s, m)
}
return popcntMaskSliceGo(s, m)
}

func popcntAndSlice(s, m []uint64) uint64 {
if useAVX512Popcnt {
return popcntAndSliceAVX512(s, m)
}
if useAVX2 {
return _popcntAndSliceAVX2(s, m)
}
return popcntAndSliceGo(s, m)
}

func popcntOrSlice(s, m []uint64) uint64 {
if useAVX512Popcnt {
return popcntOrSliceAVX512(s, m)
}
if useAVX2 {
return _popcntOrSliceAVX2(s, m)
}
return popcntOrSliceGo(s, m)
}

func popcntXorSlice(s, m []uint64) uint64 {
if useAVX512Popcnt {
return popcntXorSliceAVX512(s, m)
}
if useAVX2 {
return _popcntXorSliceAVX2(s, m)
}
Expand Down
31 changes: 31 additions & 0 deletions popcnt_avx512_amd64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//go:build amd64 && !appengine
// +build amd64,!appengine

package roaring

import "golang.org/x/sys/cpu"

// The functions below are implemented in popcnt_avx512_amd64.s using
// AVX512_VPOPCNTDQ. They are used in preference to the AVX2 kernels when the
// CPU provides VPOPCNTQ (see useAVX512Popcnt).

//go:noescape
func popcntSliceAVX512(s []uint64) uint64

//go:noescape
func popcntMaskSliceAVX512(s, m []uint64) uint64

//go:noescape
func popcntAndSliceAVX512(s, m []uint64) uint64

//go:noescape
func popcntOrSliceAVX512(s, m []uint64) uint64

//go:noescape
func popcntXorSliceAVX512(s, m []uint64) uint64

// useAVX512Popcnt selects the AVX-512 implementations when the running CPU has
// AVX512_VPOPCNTDQ. x/sys/cpu verifies that the operating system saves the
// opmask and ZMM state, and honors GODEBUG=cpu.avx512vpopcntdq=off so the path
// can be disabled at run time. Evaluated once at package initialization.
var useAVX512Popcnt = cpu.X86.HasAVX512VPOPCNTDQ
Loading
Loading