Commit b820ef5c authored by Lion Yang's avatar Lion Yang Committed by Ian Lance Taylor

x/crypto/chacha20poly1305: fix detection of BMI on AMD64

This change uses runtime.support_bmi2 as an additional condition
to examine the usability of AVX2 version algorithm, fixes
the crash on the platfrom which supports AVX2 but not support BMI2.

Fixes #18512

Change-Id: I408c0844ae2eb242dacf70cb9e8cec1b8f3bd941
Reviewed-on: https://go-review.googlesource.com/34851Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent a2b615d5
......@@ -278,9 +278,11 @@ TEXT ·chacha20Poly1305Open(SB), 0, $288-97
MOVQ ad+72(FP), adp
// Check for AVX2 support
CMPB runtime·support_avx2(SB), $1
JE chacha20Poly1305Open_AVX2
CMPB runtime·support_avx2(SB), $0
JE noavx2bmi2Open
CMPB runtime·support_bmi2(SB), $1 // for MULXQ
JE chacha20Poly1305Open_AVX2
noavx2bmi2Open:
// Special optimization, for very short buffers
CMPQ inl, $128
JBE openSSE128 // About 16% faster
......@@ -1485,9 +1487,11 @@ TEXT ·chacha20Poly1305Seal(SB), 0, $288-96
MOVQ ad+72(FP), adp
// Check for AVX2 support
CMPB runtime·support_avx2(SB), $1
CMPB runtime·support_avx2(SB), $0
JE noavx2bmi2Seal
CMPB runtime·support_bmi2(SB), $1 // for MULXQ
JE chacha20Poly1305Seal_AVX2
noavx2bmi2Seal:
// Special optimization, for very short buffers
CMPQ inl, $128
JBE sealSSE128 // About 15% faster
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment