mirror of
https://github.com/fumiama/blake2b-simd.git
synced 2026-06-16 16:48:45 +08:00
16
cpuid.go
16
cpuid.go
@@ -18,12 +18,14 @@
|
||||
package blake2b
|
||||
|
||||
func cpuid(op uint32) (eax, ebx, ecx, edx uint32)
|
||||
func cpuidex(op, op2 uint32) (eax, ebx, ecx, edx uint32)
|
||||
func xgetbv(index uint32) (eax, edx uint32)
|
||||
|
||||
// True when SIMD instructions are available.
|
||||
var avx2 = haveAVX2()
|
||||
var avx = haveAVX()
|
||||
|
||||
// haveSSE returns true if we have streaming SIMD instructions.
|
||||
// haveAVX returns true if when there is AVX support
|
||||
func haveAVX() bool {
|
||||
_, _, c, _ := cpuid(1)
|
||||
|
||||
@@ -35,3 +37,15 @@ func haveAVX() bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// haveAVX2 returns true if when there is AVX2 support
|
||||
func haveAVX2() bool {
|
||||
|
||||
mfi, _, _, _ := cpuid(0)
|
||||
// Check AVX2, AVX2 requires OS support, but BMI1/2 don't.
|
||||
if mfi >= 7 && haveAVX() {
|
||||
_, ebx, _, _ := cpuidex(7, 0)
|
||||
return (ebx & 0x00000020) != 0
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user