forked from bits-and-blooms/bitset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitset_sandbox.go
35 lines (32 loc) · 1.08 KB
/
bitset_sandbox.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package bitset
var popcount_tab = [256]uint32 {
0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8,
}
// alter popcount_tab type uint32|uint64 for benchmarking
func gcc_popcount_2(x uint64) uint64 {
ret := popcount_tab[x & 0xff]
ret += popcount_tab[(x >> 8) & 0xff]
ret += popcount_tab[(x >> 16) & 0xff]
ret += popcount_tab[(x >> 24) & 0xff]
ret += popcount_tab[(x >> 32) & 0xff]
ret += popcount_tab[(x >> 40) & 0xff]
ret += popcount_tab[(x >> 48) & 0xff]
ret += popcount_tab[(x >> 56) & 0xff]
return uint64(ret)
}
func asmhamming_popcount_2(x uint64) uint64