Initial commit
This commit is contained in:
20
vendor/golang.org/x/tools/container/intsets/popcnt_amd64.go
generated
vendored
Normal file
20
vendor/golang.org/x/tools/container/intsets/popcnt_amd64.go
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
// 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,!gccgo
|
||||
|
||||
package intsets
|
||||
|
||||
func popcnt(x word) int
|
||||
func havePOPCNT() bool
|
||||
|
||||
var hasPOPCNT = havePOPCNT()
|
||||
|
||||
// popcount returns the population count (number of set bits) of x.
|
||||
func popcount(x word) int {
|
||||
if hasPOPCNT {
|
||||
return popcnt(x)
|
||||
}
|
||||
return popcountTable(x) // faster than Hacker's Delight
|
||||
}
|
||||
30
vendor/golang.org/x/tools/container/intsets/popcnt_amd64.s
generated
vendored
Normal file
30
vendor/golang.org/x/tools/container/intsets/popcnt_amd64.s
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
// 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,!gccgo
|
||||
|
||||
#include "textflag.h"
|
||||
|
||||
// func havePOPCNT() bool
|
||||
TEXT ·havePOPCNT(SB),4,$0
|
||||
MOVQ $1, AX
|
||||
CPUID
|
||||
SHRQ $23, CX
|
||||
ANDQ $1, CX
|
||||
MOVB CX, ret+0(FP)
|
||||
RET
|
||||
|
||||
// func popcnt(word) int
|
||||
TEXT ·popcnt(SB),NOSPLIT,$0-8
|
||||
XORQ AX, AX
|
||||
MOVQ x+0(FP), SI
|
||||
// POPCNT (SI), AX is not recognized by Go assembler,
|
||||
// so we assemble it ourselves.
|
||||
BYTE $0xf3
|
||||
BYTE $0x48
|
||||
BYTE $0x0f
|
||||
BYTE $0xb8
|
||||
BYTE $0xc6
|
||||
MOVQ AX, ret+8(FP)
|
||||
RET
|
||||
9
vendor/golang.org/x/tools/container/intsets/popcnt_gccgo.go
generated
vendored
Normal file
9
vendor/golang.org/x/tools/container/intsets/popcnt_gccgo.go
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// 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 gccgo
|
||||
|
||||
package intsets
|
||||
|
||||
func popcount(x word) int
|
||||
19
vendor/golang.org/x/tools/container/intsets/popcnt_gccgo_c.c
generated
vendored
Normal file
19
vendor/golang.org/x/tools/container/intsets/popcnt_gccgo_c.c
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
// 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 gccgo
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define _STRINGIFY2_(x) #x
|
||||
#define _STRINGIFY_(x) _STRINGIFY2_(x)
|
||||
#define GOSYM_PREFIX _STRINGIFY_(__USER_LABEL_PREFIX__)
|
||||
|
||||
extern intptr_t popcount(uintptr_t x) __asm__(GOSYM_PREFIX GOPKGPATH ".popcount");
|
||||
|
||||
intptr_t popcount(uintptr_t x) {
|
||||
return __builtin_popcountl((unsigned long)(x));
|
||||
}
|
||||
33
vendor/golang.org/x/tools/container/intsets/popcnt_generic.go
generated
vendored
Normal file
33
vendor/golang.org/x/tools/container/intsets/popcnt_generic.go
generated
vendored
Normal file
@@ -0,0 +1,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)
|
||||
}
|
||||
1091
vendor/golang.org/x/tools/container/intsets/sparse.go
generated
vendored
Normal file
1091
vendor/golang.org/x/tools/container/intsets/sparse.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
84
vendor/golang.org/x/tools/container/intsets/util.go
generated
vendored
Normal file
84
vendor/golang.org/x/tools/container/intsets/util.go
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
// Copyright 2013 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.
|
||||
|
||||
package intsets
|
||||
|
||||
// From Hacker's Delight, fig 5.2.
|
||||
func popcountHD(x uint32) int {
|
||||
x -= (x >> 1) & 0x55555555
|
||||
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
|
||||
x = (x + (x >> 4)) & 0x0f0f0f0f
|
||||
x = x + (x >> 8)
|
||||
x = x + (x >> 16)
|
||||
return int(x & 0x0000003f)
|
||||
}
|
||||
|
||||
var a [1 << 8]byte
|
||||
|
||||
func init() {
|
||||
for i := range a {
|
||||
var n byte
|
||||
for x := i; x != 0; x >>= 1 {
|
||||
if x&1 != 0 {
|
||||
n++
|
||||
}
|
||||
}
|
||||
a[i] = n
|
||||
}
|
||||
}
|
||||
|
||||
func popcountTable(x word) int {
|
||||
return int(a[byte(x>>(0*8))] +
|
||||
a[byte(x>>(1*8))] +
|
||||
a[byte(x>>(2*8))] +
|
||||
a[byte(x>>(3*8))] +
|
||||
a[byte(x>>(4*8))] +
|
||||
a[byte(x>>(5*8))] +
|
||||
a[byte(x>>(6*8))] +
|
||||
a[byte(x>>(7*8))])
|
||||
}
|
||||
|
||||
// nlz returns the number of leading zeros of x.
|
||||
// From Hacker's Delight, fig 5.11.
|
||||
func nlz(x word) int {
|
||||
x |= (x >> 1)
|
||||
x |= (x >> 2)
|
||||
x |= (x >> 4)
|
||||
x |= (x >> 8)
|
||||
x |= (x >> 16)
|
||||
x |= (x >> 32)
|
||||
return popcount(^x)
|
||||
}
|
||||
|
||||
// ntz returns the number of trailing zeros of x.
|
||||
// From Hacker's Delight, fig 5.13.
|
||||
func ntz(x word) int {
|
||||
if x == 0 {
|
||||
return bitsPerWord
|
||||
}
|
||||
n := 1
|
||||
if bitsPerWord == 64 {
|
||||
if (x & 0xffffffff) == 0 {
|
||||
n = n + 32
|
||||
x = x >> 32
|
||||
}
|
||||
}
|
||||
if (x & 0x0000ffff) == 0 {
|
||||
n = n + 16
|
||||
x = x >> 16
|
||||
}
|
||||
if (x & 0x000000ff) == 0 {
|
||||
n = n + 8
|
||||
x = x >> 8
|
||||
}
|
||||
if (x & 0x0000000f) == 0 {
|
||||
n = n + 4
|
||||
x = x >> 4
|
||||
}
|
||||
if (x & 0x00000003) == 0 {
|
||||
n = n + 2
|
||||
x = x >> 2
|
||||
}
|
||||
return n - int(x&1)
|
||||
}
|
||||
Reference in New Issue
Block a user