forked from klauspost/compress
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use math and internal/cpu packages from Go 1.9.7
- Loading branch information
Showing
306 changed files
with
41,458 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ package main | |
import ( | ||
"os" | ||
"strings" | ||
|
||
"github.com/klauspost/compress/math/bits" | ||
) | ||
|
||
func main() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,8 @@ import ( | |
"encoding/binary" | ||
"fmt" | ||
"io" | ||
"math" | ||
|
||
"github.com/klauspost/compress/math" | ||
) | ||
|
||
const ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,8 @@ import ( | |
"encoding/binary" | ||
"fmt" | ||
"io" | ||
"math" | ||
|
||
"github.com/klauspost/compress/math" | ||
) | ||
|
||
const ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,9 @@ package flate | |
|
||
import ( | ||
"io" | ||
"math" | ||
"sync" | ||
|
||
"github.com/klauspost/compress/math" | ||
) | ||
|
||
const ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,8 @@ import ( | |
"encoding/binary" | ||
"fmt" | ||
"io" | ||
"math" | ||
|
||
"github.com/klauspost/compress/math" | ||
) | ||
|
||
const ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,8 @@ package fse | |
import ( | ||
"errors" | ||
"fmt" | ||
"math/bits" | ||
|
||
"github.com/klauspost/compress/math/bits" | ||
) | ||
|
||
const ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2017 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 cpu implements processor feature detection | ||
// used by the Go standard libary. | ||
package cpu | ||
|
||
var X86 x86 | ||
|
||
// The booleans in x86 contain the correspondingly named cpuid feature bit. | ||
// HasAVX and HasAVX2 are only set if the OS does support XMM and YMM registers | ||
// in addition to the cpuid feature bit being set. | ||
// The struct is padded to avoid false sharing. | ||
type x86 struct { | ||
_ [CacheLineSize]byte | ||
HasAES bool | ||
HasAVX bool | ||
HasAVX2 bool | ||
HasBMI1 bool | ||
HasBMI2 bool | ||
HasERMS bool | ||
HasOSXSAVE bool | ||
HasPCLMULQDQ bool | ||
HasPOPCNT bool | ||
HasSSE2 bool | ||
HasSSE3 bool | ||
HasSSSE3 bool | ||
HasSSE41 bool | ||
HasSSE42 bool | ||
_ [CacheLineSize]byte | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2017 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 cpu_test | ||
|
||
import ( | ||
"internal/cpu" | ||
"runtime" | ||
"testing" | ||
) | ||
|
||
func TestAMD64minimalFeatures(t *testing.T) { | ||
if runtime.GOARCH == "amd64" { | ||
if !cpu.X86.HasSSE2 { | ||
t.Fatalf("HasSSE2 expected true, got false") | ||
} | ||
} | ||
} | ||
|
||
func TestAVX2hasAVX(t *testing.T) { | ||
if runtime.GOARCH == "amd64" { | ||
if cpu.X86.HasAVX2 && !cpu.X86.HasAVX { | ||
t.Fatalf("HasAVX expected true, got false") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2017 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 386 amd64 amd64p32 | ||
|
||
package cpu | ||
|
||
const CacheLineSize = 64 | ||
|
||
// cpuid is implemented in cpu_x86.s. | ||
func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32) | ||
|
||
// xgetbv with ecx = 0 is implemented in cpu_x86.s. | ||
func xgetbv() (eax, edx uint32) | ||
|
||
func init() { | ||
maxId, _, _, _ := cpuid(0, 0) | ||
|
||
if maxId < 1 { | ||
return | ||
} | ||
|
||
_, _, ecx1, edx1 := cpuid(1, 0) | ||
X86.HasSSE2 = isSet(26, edx1) | ||
|
||
X86.HasSSE3 = isSet(0, ecx1) | ||
X86.HasPCLMULQDQ = isSet(1, ecx1) | ||
X86.HasSSSE3 = isSet(9, ecx1) | ||
X86.HasSSE41 = isSet(19, ecx1) | ||
X86.HasSSE42 = isSet(20, ecx1) | ||
X86.HasPOPCNT = isSet(23, ecx1) | ||
X86.HasAES = isSet(25, ecx1) | ||
X86.HasOSXSAVE = isSet(27, ecx1) | ||
|
||
osSupportsAVX := false | ||
// For XGETBV, OSXSAVE bit is required and sufficient. | ||
if X86.HasOSXSAVE { | ||
eax, _ := xgetbv() | ||
// Check if XMM and YMM registers have OS support. | ||
osSupportsAVX = isSet(1, eax) && isSet(2, eax) | ||
} | ||
|
||
X86.HasAVX = isSet(28, ecx1) && osSupportsAVX | ||
|
||
if maxId < 7 { | ||
return | ||
} | ||
|
||
_, ebx7, _, _ := cpuid(7, 0) | ||
X86.HasBMI1 = isSet(3, ebx7) | ||
X86.HasAVX2 = isSet(5, ebx7) && osSupportsAVX | ||
X86.HasBMI2 = isSet(8, ebx7) | ||
X86.HasERMS = isSet(9, ebx7) | ||
} | ||
|
||
func isSet(bitpos uint, value uint32) bool { | ||
return value&(1<<bitpos) != 0 | ||
} |
Oops, something went wrong.