// This file was originally from https://golang.org/cl/24717 by Vlad Krasnov of CloudFlare.
-// +build go1.7
+// +build go1.7,amd64,!gccgo,!appengine
#include "textflag.h"
// General register allocation
// Check for AVX2 support
CMPB runtime·support_avx2(SB), $0
JE noavx2bmi2Open
- CMPB runtime·support_bmi2(SB), $1 // for MULXQ
- JE chacha20Poly1305Open_AVX2
+
+ // Check BMI2 bit for MULXQ.
+ // runtime·cpuid_ebx7 is always available here
+ // because it passed avx2 check
+ TESTL $(1<<8), runtime·cpuid_ebx7(SB)
+ JNE chacha20Poly1305Open_AVX2
noavx2bmi2Open:
+
// Special optimization, for very short buffers
CMPQ inl, $128
JBE openSSE128 // About 16% faster
// Check for AVX2 support
CMPB runtime·support_avx2(SB), $0
JE noavx2bmi2Seal
- CMPB runtime·support_bmi2(SB), $1 // for MULXQ
- JE chacha20Poly1305Seal_AVX2
+
+ // Check BMI2 bit for MULXQ.
+ // runtime·cpuid_ebx7 is always available here
+ // because it passed avx2 check
+ TESTL $(1<<8), runtime·cpuid_ebx7(SB)
+ JNE chacha20Poly1305Seal_AVX2
noavx2bmi2Seal:
+
// Special optimization, for very short buffers
CMPQ inl, $128
JBE sealSSE128 // About 15% faster
MOVO D1, ctr0Store
sealSSETail64LoopA:
- // Perform ChaCha rounds, while hashing the prevsiosly encrpyted ciphertext
+ // Perform ChaCha rounds, while hashing the previously encrypted ciphertext
polyAdd(0(oup))
polyMul
LEAQ 16(oup), oup
MOVO A0, A1; MOVO B0, B1; MOVO C0, C1; MOVO D0, D1; PADDL ·sseIncMask<>(SB), D1; MOVO D1, ctr1Store
sealSSETail128LoopA:
- // Perform ChaCha rounds, while hashing the prevsiosly encrpyted ciphertext
+ // Perform ChaCha rounds, while hashing the previously encrypted ciphertext
polyAdd(0(oup))
polyMul
LEAQ 16(oup), oup
MOVO A1, A2; MOVO B1, B2; MOVO C1, C2; MOVO D1, D2; PADDL ·sseIncMask<>(SB), D2; MOVO D2, ctr2Store
sealSSETail192LoopA:
- // Perform ChaCha rounds, while hashing the prevsiosly encrpyted ciphertext
+ // Perform ChaCha rounds, while hashing the previously encrypted ciphertext
polyAdd(0(oup))
polyMul
LEAQ 16(oup), oup