1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 //go:build (!amd64 || appengine) && !gccgo
6 // +build !amd64 appengine
13 // We compared three algorithms---Hacker's Delight, table lookup,
14 // and AMD64's SSE4.1 hardware POPCNT---on a 2.67GHz Xeon X5550.
16 // % GOARCH=amd64 go test -run=NONE -bench=Popcount
19 // HackersDelight 9.96 ns/op
21 // % GOARCH=386 go test -run=NONE -bench=Popcount
23 // HackersDelight 5.23 ns/op
25 // (AMD64's ABM1 hardware supports ntz and nlz too,
26 // but they aren't critical.)
28 // popcount returns the population count (number of set bits) of x.
29 func popcount(x word) int {
30 if runtime.GOARCH == "386" {
31 return popcountHD(uint32(x))
33 return popcountTable(x)