From b820ef5c33c1b508c7b0df8827b6f13c9480acea Mon Sep 17 00:00:00 2001 From: Lion Yang Date: Thu, 5 Jan 2017 06:25:59 +0800 Subject: 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/34851 Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- .../x/crypto/chacha20poly1305/chacha20poly1305_amd64.s | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/vendor/golang_org/x/crypto/chacha20poly1305/chacha20poly1305_amd64.s b/src/vendor/golang_org/x/crypto/chacha20poly1305/chacha20poly1305_amd64.s index 2fa9b555a8..7c6a1a5e68 100644 --- a/src/vendor/golang_org/x/crypto/chacha20poly1305/chacha20poly1305_amd64.s +++ b/src/vendor/golang_org/x/crypto/chacha20poly1305/chacha20poly1305_amd64.s @@ -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 -- cgit v1.2.3-54-g00ecf