cpu: Remove pkg/cpu in favor of better klauspost/cpuid.

Fixes #1128
This commit is contained in:
Harshavardhana
2016-02-15 12:45:02 -08:00
parent a173313bc2
commit 9e10ee7e47
24 changed files with 2750 additions and 200 deletions

View File

@@ -1,39 +0,0 @@
/*
* Minio Cloud Storage, (C) 2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cpu
// cpuid, cpuidex
func cpuid(op uint32) (eax, ebx, ecx, edx uint32)
func cpuidex(op, op2 uint32) (eax, ebx, ecx, edx uint32)
// HasSSE41 - CPUID instruction verification wrapper for SSE41 extensions
func HasSSE41() bool {
_, _, c, _ := cpuid(1)
return ((c & (1 << 19)) != 0)
}
// HasAVX - CPUID instruction verification wrapper for AVX extensions
func HasAVX() bool {
_, _, c, _ := cpuid(1)
return ((c & (1 << 28)) != 0)
}
// HasAVX2 - CPUID instruction verification wrapper for AVX2 extensions
func HasAVX2() bool {
_, b, _, _ := cpuidex(7, 0)
return ((b & (1 << 5)) != 0)
}

View File

@@ -1,27 +0,0 @@
// Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file.
//
// See https://github.com/klauspost/cpuid/blob/master/LICENSE
//
// Using this inside Minio with modifications
//
// func cpuid(op uint32) (eax, ebx, ecx, edx uint32)
TEXT ·cpuid(SB),7,$0
MOVL op+0(FP),AX
CPUID
MOVL AX,eax+8(FP)
MOVL BX,ebx+12(FP)
MOVL CX,ecx+16(FP)
MOVL DX,edx+20(FP)
RET
// func cpuidex(op, op2 uint32) (eax, ebx, ecx, edx uint32)
TEXT ·cpuidex(SB),7,$0
MOVL op+0(FP),AX
MOVL op2+4(FP),CX
CPUID
MOVL AX,eax+8(FP)
MOVL BX,ebx+12(FP)
MOVL CX,ecx+16(FP)
MOVL DX,edx+20(FP)
RET

View File

@@ -1,32 +0,0 @@
/*
* Minio Cloud Storage, (C) 2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cpu
// HasSSE41 - CPUID instruction verification wrapper for SSE41 extensions
func HasSSE41() bool {
return false
}
// HasAVX - CPUID instruction verification wrapper for AVX extensions
func HasAVX() bool {
return false
}
// HasAVX2 - CPUID instruction verification wrapper for AVX2 extensions
func HasAVX2() bool {
return false
}

View File

@@ -1,76 +0,0 @@
/*
* Minio Cloud Storage, (C) 2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cpu_test
import (
"errors"
"os/exec"
"runtime"
"strings"
"testing"
"github.com/minio/minio/pkg/cpu"
. "gopkg.in/check.v1"
)
func Test(t *testing.T) { TestingT(t) }
type MySuite struct{}
var _ = Suite(&MySuite{})
func hasCPUFeatureFromOS(feature string) (bool, error) {
if runtime.GOOS == "linux" {
command := exec.Command("/bin/cat", "/proc/cpuinfo")
output, err := command.Output()
if err != nil {
return false, err
}
if strings.Contains(string(output), feature) {
return true, nil
}
return false, nil
}
return false, errors.New("Not Implemented on this platform")
}
func (s *MySuite) TestHasSSE41(c *C) {
if runtime.GOOS == "linux" {
var flag = cpu.HasSSE41()
osCheck, err := hasCPUFeatureFromOS("sse4_1")
c.Assert(err, IsNil)
c.Check(flag, Equals, osCheck)
}
}
func (s *MySuite) TestHasAVX(c *C) {
if runtime.GOOS == "linux" {
var flag = cpu.HasAVX()
osFlag, err := hasCPUFeatureFromOS("avx")
c.Assert(err, IsNil)
c.Check(osFlag, Equals, flag)
}
}
func (s *MySuite) TestHasAVX2(c *C) {
if runtime.GOOS == "linux" {
var flag = cpu.HasAVX2()
osFlag, err := hasCPUFeatureFromOS("avx2")
c.Assert(err, IsNil)
c.Check(osFlag, Equals, flag)
}
}

View File

@@ -1,11 +0,0 @@
// Package cpu provides wrapper around assembly functions for checking processor
// instruction capabilities for SSE4.1, AVX, AVX2 support
//
// Example
//
// ``cpu.HasSSE41()`` returns true for SSE4.1 instruction support, false otherwise
//
// ``cpu.HasAVX()`` returns true for AVX instruction support, false otherwise
//
// ``cpu.HasAVX2()`` returns true for AVX2 instruction support, false otherwise
package cpu

View File

@@ -26,12 +26,12 @@ import "C"
import (
"unsafe"
"github.com/minio/minio/pkg/cpu"
"github.com/klauspost/cpuid"
)
func block(dig *digest, p []byte) {
switch true {
case cpu.HasSSE41() == true:
case cpuid.CPU.SSE3():
blockSSE3(dig, p)
default:
blockGeneric(dig, p)

View File

@@ -27,14 +27,14 @@ import "C"
import (
"unsafe"
"github.com/minio/minio/pkg/cpu"
"github.com/klauspost/cpuid"
)
func block(dig *digest, p []byte) {
switch true {
case cpu.HasAVX2():
case cpuid.CPU.AVX2():
blockAVX2(dig, p)
case cpu.HasSSE41():
case cpuid.CPU.SSE3():
blockSSE3(dig, p)
default:
blockGeneric(dig, p)

View File

@@ -31,7 +31,7 @@ package sha256
import (
"hash"
"github.com/minio/minio/pkg/cpu"
"github.com/klauspost/cpuid"
)
// Size - The size of a SHA256 checksum in bytes.
@@ -76,11 +76,11 @@ func (d *digest) Reset() {
func block(dig *digest, p []byte) {
switch true {
case cpu.HasAVX2() == true:
case cpuid.CPU.AVX2():
blockAVX2(dig, p)
case cpu.HasAVX() == true:
case cpuid.CPU.AVX():
blockAVX(dig, p)
case cpu.HasSSE41() == true:
case cpuid.CPU.SSSE3():
blockSSE(dig, p)
default:
blockGeneric(dig, p)

View File

@@ -16,7 +16,7 @@ package sha512
import (
"hash"
"github.com/minio/minio/pkg/cpu"
"github.com/klauspost/cpuid"
)
// Size - The size of a SHA512 checksum in bytes.
@@ -47,11 +47,11 @@ type digest struct {
func block(dig *digest, p []byte) {
switch true {
case cpu.HasAVX2() == true:
case cpuid.CPU.AVX2():
blockAVX2(dig, p)
case cpu.HasAVX() == true:
case cpuid.CPU.AVX():
blockAVX(dig, p)
case cpu.HasSSE41() == true:
case cpuid.CPU.SSSE3():
blockSSE(dig, p)
default:
blockGeneric(dig, p)