willf/bitset — pull request #21 by lemire (2014-05-07 19:06:16+00:00)
Title: Using faster popcnt function in pure Go

The following pure Go popcnt function is nearly as fast as the AMD64 assembly version. It is significantly faster than the version found on Wikipedia that we were using previously.

On a recent Haswell processor (2013), there is no benefit at all to using the assembly version, as I can demonstrate:

$ go test -bench=BenchmarkCount
PASS
BenchmarkCount	1000000	2424 ns/op
ok	_/home/dlemire/CVS/github/bitset	2.455s
$ vim popcnt_asm.go
$ git diff
diff --git a/popcnt_asm.go b/popcnt_asm.go
index ef75be7..9825bb6 100644
--- a/popcnt_asm.go
+++ b/popcnt_asm.go
@@ -6,7 +6,7 @@ package bitset

func hasAsm() bool

-var useAsm = hasAsm()
+var useAsm = false //hasAsm()

//go:noescape

$ go test -bench=BenchmarkCount
PASS
BenchmarkCount	1000000	2464 ns/op
ok	_/home/dlemire/CVS/github/bitset	2.495s