sha1block_amd64.go 924 B

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