Browse Source

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

This reverts commit d6449816ce06963d9d136eee5a56fca5b0616e7e because of golang/go#24828.

Change-Id: I14b4e1265b2e75897fa12548dbdfb77c308afaaf
Reviewed-on: https://go-review.googlesource.com/108795
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Andreas Auernhammer 7 years ago
parent
commit
b0697eccbe
2 changed files with 23 additions and 13 deletions
  1. 11 13
      blake2b/blake2bAVX2_amd64.go
  2. 12 0
      blake2b/blake2bAVX2_amd64.s

+ 11 - 13
blake2b/blake2bAVX2_amd64.go

@@ -6,22 +6,20 @@
 
 
 package blake2b
 package blake2b
 
 
-import _ "unsafe"
-
-//go:linkname x86_HasAVX internal/cpu.X86.HasAVX
-var x86_HasAVX bool
+func init() {
+	useAVX2 = supportsAVX2()
+	useAVX = supportsAVX()
+	useSSE4 = supportsSSE4()
+}
 
 
-//go:linkname x86_HasAVX2 internal/cpu.X86.HasAVX2
-var x86_HasAVX2 bool
+//go:noescape
+func supportsSSE4() bool
 
 
-//go:linkname x86_HasAVX internal/cpu.X86.HasSSE4
-var x86_HasSSE4 bool
+//go:noescape
+func supportsAVX() bool
 
 
-func init() {
-	useAVX2 = x86_HasAVX2
-	useAVX = x86_HasAVX
-	useSSE4 = x86_HasSSE4
-}
+//go:noescape
+func supportsAVX2() bool
 
 
 //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)

+ 12 - 0
blake2b/blake2bAVX2_amd64.s

@@ -748,3 +748,15 @@ 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