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 // +build !amd64 appengine
12 // We compared three algorithms---Hacker's Delight, table lookup,
13 // and AMD64's SSE4.1 hardware POPCNT---on a 2.67GHz Xeon X5550.
15 // % GOARCH=amd64 go test -run=NONE -bench=Popcount
18 // HackersDelight 9.96 ns/op
20 // % GOARCH=386 go test -run=NONE -bench=Popcount
22 // HackersDelight 5.23 ns/op
24 // (AMD64's ABM1 hardware supports ntz and nlz too,
25 // but they aren't critical.)
27 // popcount returns the population count (number of set bits) of x.
28 func popcount(x word) int {
29 if runtime.GOARCH == "386" {
30 return popcountHD(uint32(x))
32 return popcountTable(x)