mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-14 01:24:04 -08:00
16 lines
400 B
Go
16 lines
400 B
Go
// +build !amd64 appengine popcntgo
|
|
|
|
package bits
|
|
|
|
// Popcnt counts the number of bits set
|
|
func Popcnt(x uint64) uint64 {
|
|
// bit population count, see
|
|
// http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
|
|
x -= (x >> 1) & 0x5555555555555555
|
|
x = (x>>2)&0x3333333333333333 + x&0x3333333333333333
|
|
x += x >> 4
|
|
x &= 0x0f0f0f0f0f0f0f0f
|
|
x *= 0x0101010101010101
|
|
return x >> 56
|
|
}
|