diff options
| author | Lion Yang <lion@aosc.xyz> | 2017-01-05 05:13:53 +0800 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2017-01-05 15:37:37 +0000 |
| commit | a2b615d5270f0bc2ee1dfcdd7849bdd05ee76a14 (patch) | |
| tree | 2446db40f137cdf160d3c16c8299ed5dae6381d7 /src/runtime | |
| parent | f5608c20f7b88c20fa2cd70090d9917df63f5c8e (diff) | |
| download | go-a2b615d5270f0bc2ee1dfcdd7849bdd05ee76a14.tar.xz | |
crypto: detect BMI usability on AMD64 for sha1 and sha256
The existing implementations on AMD64 only detects AVX2 usability,
when they also contains BMI (bit-manipulation instructions).
These instructions crash the running program as 'unknown instructions'
on the architecture, e.g. i3-4000M, which supports AVX2 but not
support BMI.
This change added the detections for BMI1 and BMI2 to AMD64 runtime with
two flags as the result, `support_bmi1` and `support_bmi2`,
in runtime/runtime2.go. It also completed the condition to run AVX2 version
in packages crypto/sha1 and crypto/sha256.
Fixes #18512
Change-Id: I917bf0de365237740999de3e049d2e8f2a4385ad
Reviewed-on: https://go-review.googlesource.com/34850
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/asm_amd64.s | 15 | ||||
| -rw-r--r-- | src/runtime/runtime2.go | 2 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/runtime/asm_amd64.s b/src/runtime/asm_amd64.s index 0070e9d203..cb428d6de3 100644 --- a/src/runtime/asm_amd64.s +++ b/src/runtime/asm_amd64.s @@ -75,11 +75,24 @@ no7: TESTL $(1<<5), runtime·cpuid_ebx7(SB) // check for AVX2 bit JEQ noavx2 MOVB $1, runtime·support_avx2(SB) - JMP nocpuinfo + JMP testbmi1 noavx: MOVB $0, runtime·support_avx(SB) noavx2: MOVB $0, runtime·support_avx2(SB) +testbmi1: + // Detect BMI1 and BMI2 extensions as per + // 5.1.16.1 Detection of VEX-encoded GPR Instructions, + // LZCNT and TZCNT, PREFETCHW chapter of [1] + MOVB $0, runtime·support_bmi1(SB) + TESTL $(1<<3), runtime·cpuid_ebx7(SB) // check for BMI1 bit + JEQ testbmi2 + MOVB $1, runtime·support_bmi1(SB) +testbmi2: + MOVB $0, runtime·support_bmi2(SB) + TESTL $(1<<8), runtime·cpuid_ebx7(SB) // check for BMI2 bit + JEQ nocpuinfo + MOVB $1, runtime·support_bmi2(SB) nocpuinfo: // if there is an _cgo_init, call it. diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go index acc9426142..1ceab0ad8c 100644 --- a/src/runtime/runtime2.go +++ b/src/runtime/runtime2.go @@ -745,6 +745,8 @@ var ( lfenceBeforeRdtsc bool support_avx bool support_avx2 bool + support_bmi1 bool + support_bmi2 bool goarm uint8 // set by cmd/link on arm systems framepointer_enabled bool // set by cmd/link |
