File: popcnt_generic.go

package info (click to toggle)
golang-golang-x-tools 1%3A0.0~git20190125.d66bd3c%2Bds-4
  • links: PTS, VCS
  • area: main
  • in suites: buster, buster-backports
  • size: 8,912 kB
  • sloc: asm: 1,394; yacc: 155; makefile: 109; sh: 108; ansic: 17; xml: 11
file content (33 lines) | stat: -rw-r--r-- 927 bytes parent folder | download | duplicates (7)
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
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build !amd64 appengine
// +build !gccgo

package intsets

import "runtime"

// We compared three algorithms---Hacker's Delight, table lookup,
// and AMD64's SSE4.1 hardware POPCNT---on a 2.67GHz Xeon X5550.
//
// % GOARCH=amd64 go test -run=NONE -bench=Popcount
// POPCNT               5.12 ns/op
// Table                8.53 ns/op
// HackersDelight       9.96 ns/op
//
// % GOARCH=386 go test -run=NONE -bench=Popcount
// Table               10.4  ns/op
// HackersDelight       5.23 ns/op
//
// (AMD64's ABM1 hardware supports ntz and nlz too,
// but they aren't critical.)

// popcount returns the population count (number of set bits) of x.
func popcount(x word) int {
	if runtime.GOARCH == "386" {
		return popcountHD(uint32(x))
	}
	return popcountTable(x)
}