blake2bAVX2_amd64.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 go1.7,amd64,!gccgo,!appengine
  5. package blake2b
  6. import _ "unsafe"
  7. //go:linkname x86_HasAVX internal/cpu.X86.HasAVX
  8. var x86_HasAVX bool
  9. //go:linkname x86_HasAVX2 internal/cpu.X86.HasAVX2
  10. var x86_HasAVX2 bool
  11. //go:linkname x86_HasAVX internal/cpu.X86.HasSSE4
  12. var x86_HasSSE4 bool
  13. func init() {
  14. useAVX2 = x86_HasAVX2
  15. useAVX = x86_HasAVX
  16. useSSE4 = x86_HasSSE4
  17. }
  18. //go:noescape
  19. func hashBlocksAVX2(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte)
  20. //go:noescape
  21. func hashBlocksAVX(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte)
  22. //go:noescape
  23. func hashBlocksSSE4(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte)
  24. func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) {
  25. if useAVX2 {
  26. hashBlocksAVX2(h, c, flag, blocks)
  27. } else if useAVX {
  28. hashBlocksAVX(h, c, flag, blocks)
  29. } else if useSSE4 {
  30. hashBlocksSSE4(h, c, flag, blocks)
  31. } else {
  32. hashBlocksGeneric(h, c, flag, blocks)
  33. }
  34. }