Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201105173854-bc9fc8d8c4bc / container / intsets / popcnt_generic.go
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.
4
5 // +build !amd64 appengine
6 // +build !gccgo
7
8 package intsets
9
10 import "runtime"
11
12 // We compared three algorithms---Hacker's Delight, table lookup,
13 // and AMD64's SSE4.1 hardware POPCNT---on a 2.67GHz Xeon X5550.
14 //
15 // % GOARCH=amd64 go test -run=NONE -bench=Popcount
16 // POPCNT               5.12 ns/op
17 // Table                8.53 ns/op
18 // HackersDelight       9.96 ns/op
19 //
20 // % GOARCH=386 go test -run=NONE -bench=Popcount
21 // Table               10.4  ns/op
22 // HackersDelight       5.23 ns/op
23 //
24 // (AMD64's ABM1 hardware supports ntz and nlz too,
25 // but they aren't critical.)
26
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))
31         }
32         return popcountTable(x)
33 }