Browse Source

blake2b: use internal/cpu to determine AVX and SSE 4 support

CL 106235 removed runtime.support_avx on which blake2b depends to
determine AVX support. Switch to use the corresponding feature flags
from internal/cpu instead. While at it, also use AVX2 and SSE4 (for Go
1.7 and later) from there.

Change-Id: I4f7a27fcfa0c5d0d7a50444c7aa32519b97e90dd
Reviewed-on: https://go-review.googlesource.com/106336
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Tobias Klauser 7 years ago
parent
commit
d6449816ce
2 changed files with 13 additions and 23 deletions
  1. 13 11
      blake2b/blake2bAVX2_amd64.go
  2. 0 12
      blake2b/blake2bAVX2_amd64.s

+ 13 - 11
blake2b/blake2bAVX2_amd64.go

@@ -6,20 +6,22 @@
 
 
 package blake2b
 package blake2b
 
 
-func init() {
-	useAVX2 = supportsAVX2()
-	useAVX = supportsAVX()
-	useSSE4 = supportsSSE4()
-}
+import _ "unsafe"
 
 
-//go:noescape
-func supportsSSE4() bool
+//go:linkname x86_HasAVX internal/cpu.X86.HasAVX
+var x86_HasAVX bool
 
 
-//go:noescape
-func supportsAVX() bool
+//go:linkname x86_HasAVX2 internal/cpu.X86.HasAVX2
+var x86_HasAVX2 bool
 
 
-//go:noescape
-func supportsAVX2() bool
+//go:linkname x86_HasAVX internal/cpu.X86.HasSSE4
+var x86_HasSSE4 bool
+
+func init() {
+	useAVX2 = x86_HasAVX2
+	useAVX = x86_HasAVX
+	useSSE4 = x86_HasSSE4
+}
 
 
 //go:noescape
 //go:noescape
 func hashBlocksAVX2(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte)
 func hashBlocksAVX2(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte)

+ 0 - 12
blake2b/blake2bAVX2_amd64.s

@@ -748,15 +748,3 @@ noinc:
 
 
 	MOVQ BP, SP
 	MOVQ BP, SP
 	RET
 	RET
-
-// func supportsAVX2() bool
-TEXT ·supportsAVX2(SB), 4, $0-1
-	MOVQ runtime·support_avx2(SB), AX
-	MOVB AX, ret+0(FP)
-	RET
-
-// func supportsAVX() bool
-TEXT ·supportsAVX(SB), 4, $0-1
-	MOVQ runtime·support_avx(SB), AX
-	MOVB AX, ret+0(FP)
-	RET