aboutsummaryrefslogtreecommitdiff
path: root/src/bytes
diff options
context:
space:
mode:
authorMartin Möhrmann <moehrmann@google.com>2017-04-03 22:38:09 +0200
committerKeith Randall <khr@golang.org>2017-05-10 17:02:21 +0000
commit69972aea74de6a0397a05281475d1ca006da7bb0 (patch)
treef2147a8505d70bd63a2f51ffe57a33a4df2a1444 /src/bytes
parent4fc498d89a1e7cef854ed95c00ce7fed817e75a4 (diff)
downloadgo-69972aea74de6a0397a05281475d1ca006da7bb0.tar.xz
internal/cpu: new package to detect cpu features
Implements detection of x86 cpu features that are used in the go standard library. Changes all standard library packages to use the new cpu package instead of using runtime internal variables to check x86 cpu features. Updates: #15403 Change-Id: I2999a10cb4d9ec4863ffbed72f4e021a1dbc4bb9 Reviewed-on: https://go-review.googlesource.com/41476 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/bytes')
-rw-r--r--src/bytes/bytes_amd64.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/bytes/bytes_amd64.go b/src/bytes/bytes_amd64.go
index e68a3920d0..77d5970152 100644
--- a/src/bytes/bytes_amd64.go
+++ b/src/bytes/bytes_amd64.go
@@ -4,19 +4,19 @@
package bytes
+import "internal/cpu"
+
//go:noescape
// indexShortStr returns the index of the first instance of c in s, or -1 if c is not present in s.
// indexShortStr requires 2 <= len(c) <= shortStringLen
-func indexShortStr(s, c []byte) int // ../runtime/asm_$GOARCH.s
-func supportAVX2() bool // ../runtime/asm_$GOARCH.s
-func supportPOPCNT() bool // ../runtime/asm_$GOARCH.s
-func countByte(s []byte, c byte) int // ../runtime/asm_$GOARCH.s
+func indexShortStr(s, c []byte) int // ../runtime/asm_amd64.s
+func countByte(s []byte, c byte) int // ../runtime/asm_amd64.s
var shortStringLen int
func init() {
- if supportAVX2() {
+ if cpu.X86.HasAVX2 {
shortStringLen = 63
} else {
shortStringLen = 31
@@ -99,7 +99,7 @@ func Index(s, sep []byte) int {
// Count counts the number of non-overlapping instances of sep in s.
// If sep is an empty slice, Count returns 1 + the number of Unicode code points in s.
func Count(s, sep []byte) int {
- if len(sep) == 1 && supportPOPCNT() {
+ if len(sep) == 1 && cpu.X86.HasPOPCNT {
return countByte(s, sep[0])
}
return countGeneric(s, sep)