1
0
mirror of https://github.com/fumiama/blake2b-simd.git synced 2026-06-16 16:48:45 +08:00

Added AVX2 support (#6)

* Added AVX2 support
This commit is contained in:
Frank
2016-07-03 20:54:51 +02:00
committed by Harshavardhana
parent f0521e8972
commit 00562011ad
8 changed files with 808 additions and 19 deletions

View File

@@ -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
}