Move cpuid facility to separate package
This commit is contained in:
parent
2470efda43
commit
648b1deca7
4 changed files with 15 additions and 8 deletions
|
@ -28,7 +28,7 @@
|
|||
|
||||
// +build 386 amd64 amd64p32
|
||||
|
||||
package tz
|
||||
package cpuid
|
||||
|
||||
const (
|
||||
bitOSXSAVE = 1 << 27
|
||||
|
@ -36,14 +36,19 @@ const (
|
|||
bitAVX2 = 1 << 5
|
||||
)
|
||||
|
||||
func setFeatures() {
|
||||
var (
|
||||
hasAVX bool
|
||||
hasAVX2 bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
maxID, _, _, _ := cpuid(0, 0)
|
||||
if maxID < 1 {
|
||||
return
|
||||
}
|
||||
|
||||
_, _, ecx1, _ := cpuid(1, 0)
|
||||
hasOSXSAVE = isSet(ecx1, bitOSXSAVE)
|
||||
hasOSXSAVE := isSet(ecx1, bitOSXSAVE)
|
||||
|
||||
osSupportsAVX := false
|
||||
if hasOSXSAVE {
|
||||
|
@ -61,6 +66,9 @@ func setFeatures() {
|
|||
hasAVX2 = isSet(ebx7, bitAVX2) && osSupportsAVX
|
||||
}
|
||||
|
||||
func HasAVX() bool { return hasAVX }
|
||||
func HasAVX2() bool { return hasAVX2 }
|
||||
|
||||
func isSet(hwc uint32, value uint32) bool {
|
||||
return hwc&value != 0
|
||||
}
|
|
@ -6,6 +6,8 @@ package tz
|
|||
import (
|
||||
"errors"
|
||||
"hash"
|
||||
|
||||
"github.com/nspcc-dev/tzhash/internal/cpuid"
|
||||
)
|
||||
|
||||
type Implementation int
|
||||
|
@ -22,9 +24,8 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
hasAVX bool
|
||||
hasAVX2 bool
|
||||
hasOSXSAVE bool
|
||||
hasAVX = cpuid.HasAVX()
|
||||
hasAVX2 = cpuid.HasAVX2()
|
||||
)
|
||||
|
||||
func (impl Implementation) String() string {
|
||||
|
|
|
@ -17,8 +17,6 @@ var id = sl2{
|
|||
var mul func(a, b, c *sl2, x *[4]gf127.GF127)
|
||||
|
||||
func init() {
|
||||
setFeatures()
|
||||
|
||||
if hasAVX {
|
||||
mul = mulSL2AVX
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue