Debian Codegraph @

libgo/go/crypto/sha1/sha1block_amd64.go

raw
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 // +build ignore
6
7 package sha1
8
9 import "internal/cpu"
10
11 //go:noescape
12 func blockAVX2(dig *digest, p []byte)
13
14 //go:noescape
15 func blockAMD64(dig *digest, p []byte)
16
17 var useAVX2 = cpu.X86.HasAVX2 && cpu.X86.HasBMI1 && cpu.X86.HasBMI2
18
19 func block(dig *digest, p []byte) {
20 if useAVX2 && len(p) >= 256 {
21 // blockAVX2 calculates sha1 for 2 block per iteration
22 // it also interleaves precalculation for next block.
23 // So it may read up-to 192 bytes past end of p
24 // We may add checks inside blockAVX2, but this will
25 // just turn it into a copy of blockAMD64,
26 // so call it directly, instead.
27 safeLen := len(p) - 128
28 if safeLen%128 != 0 {
29 safeLen -= 64
30 }
31 blockAVX2(dig, p[:safeLen])
32 blockAMD64(dig, p[safeLen:])
33 } else {
34 blockAMD64(dig, p)
35 }
36 }