github.com/coyove/sdss@v0.0.0-20231129015646-c2ec58cca6a2/contrib/roaring/popcnt_compat.go (about) 1 //go:build !go1.9 2 // +build !go1.9 3 4 package roaring 5 6 // bit population count, take from 7 // https://code.google.com/p/go/issues/detail?id=4988#c11 8 // credit: https://code.google.com/u/arnehormann/ 9 // credit: https://play.golang.org/p/U7SogJ7psJ 10 // credit: http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel 11 func popcount(x uint64) uint64 { 12 x -= (x >> 1) & 0x5555555555555555 13 x = (x>>2)&0x3333333333333333 + x&0x3333333333333333 14 x += x >> 4 15 x &= 0x0f0f0f0f0f0f0f0f 16 x *= 0x0101010101010101 17 return x >> 56 18 }