github.com/euank/go@v0.0.0-20160829210321-495514729181/src/crypto/sha1/sha1block_amd64.go (about) 1 // Copyright 2016 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package sha1 6 7 //go:noescape 8 9 func blockAVX2(dig *digest, p []byte) 10 11 //go:noescape 12 func blockAMD64(dig *digest, p []byte) 13 func checkAVX2() bool 14 15 var hasAVX2 = checkAVX2() 16 17 func block(dig *digest, p []byte) { 18 if hasAVX2 && len(p) >= 256 { 19 // blockAVX2 calculates sha1 for 2 block per iteration 20 // it also interleaves precalculation for next block. 21 // So it may read up-to 192 bytes past end of p 22 // We may add checks inside blockAVX2, but this will 23 // just turn it into a copy of blockAMD64, 24 // so call it directly, instead. 25 safeLen := len(p) - 128 26 if safeLen%128 != 0 { 27 safeLen -= 64 28 } 29 blockAVX2(dig, p[:safeLen]) 30 blockAMD64(dig, p[safeLen:]) 31 } else { 32 blockAMD64(dig, p) 33 } 34 }