1
0
mirror of https://github.com/fumiama/blake2b-simd.git synced 2026-06-08 20:10:33 +08:00

asm: Add new defines

- Add UNDIAGONALIZE define
- Add DIAGONALIZE define
- Add G1 define
- Add G2 define
- Add LOAD_SHUFFLE define

Additionally check for AVX support.
This commit is contained in:
frankw
2016-06-28 12:15:46 +02:00
committed by Harshavardhana
parent 3a46db1cb4
commit f41b7a312a
5 changed files with 202 additions and 1300 deletions

View File

@@ -53,7 +53,7 @@ func compressSSE(d *digest, p []uint8) {
}
func compress(d *digest, p []uint8) {
if sse {
if avx {
compressSSE(d, p)
return
}

File diff suppressed because it is too large Load Diff

View File

@@ -18,12 +18,20 @@
package blake2b
func cpuid(op uint32) (eax, ebx, ecx, edx uint32)
func xgetbv(index uint32) (eax, edx uint32)
// True when SIMD instructions are available.
var sse = haveSSE()
var avx = haveAVX()
// haveSSE returns true if we have streaming SIMD instructions.
func haveSSE() bool {
_, _, _, d := cpuid(1)
return (d & (1 << 25)) != 0
func haveAVX() bool {
_, _, c, _ := cpuid(1)
// Check XGETBV, OXSAVE and AVX bits
if c&(1<<26) != 0 && c&(1<<27) != 0 && c&(1<<28) != 0 {
// Check for OS support
eax, _ := xgetbv(0)
return (eax & 0x6) == 0x6
}
return false
}

View File

@@ -13,3 +13,10 @@ TEXT ·cpuid(SB), 7, $0
MOVL DX, edx+16(FP)
RET
// func xgetbv(index uint32) (eax, edx uint32)
TEXT ·xgetbv(SB), 7, $0
MOVL index+0(FP), CX
BYTE $0x0f; BYTE $0x01; BYTE $0xd0 // XGETBV
MOVL AX, eax+4(FP)
MOVL DX, edx+8(FP)
RET

View File

@@ -12,3 +12,11 @@ TEXT ·cpuid(SB), 7, $0
MOVL CX, ecx+16(FP)
MOVL DX, edx+20(FP)
RET
// func xgetbv(index uint32) (eax, edx uint32)
TEXT ·xgetbv(SB), 7, $0
MOVL index+0(FP), CX
BYTE $0x0f; BYTE $0x01; BYTE $0xd0 // XGETBV
MOVL AX, eax+8(FP)
MOVL DX, edx+12(FP)
RET