This repository has been archived on 2023-05-01. You can view files and clone it, but cannot push or open issues or pull requests.
blake3/cpu_darwin.go

23 lines
399 B
Go
Raw Normal View History

2020-08-04 22:13:57 +00:00
package blake3
import (
"syscall"
2021-09-06 16:38:15 +00:00
"github.com/klauspost/cpuid/v2"
2020-08-04 22:13:57 +00:00
)
var (
haveAVX2 bool
haveAVX512 bool
)
func init() {
2021-09-06 16:38:15 +00:00
haveAVX2 = cpuid.CPU.Supports(cpuid.AVX2)
haveAVX512 = cpuid.CPU.Supports(cpuid.AVX512F)
2020-08-04 22:13:57 +00:00
if !haveAVX512 {
// On some Macs, AVX512 detection is buggy, so fallback to sysctl
b, _ := syscall.Sysctl("hw.optional.avx512f")
haveAVX512 = len(b) > 0 && b[0] == 1
2020-08-04 22:13:57 +00:00
}
}