sum_s390x.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2018 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 s390x,go1.11,!gccgo,!appengine
  5. package poly1305
  6. import (
  7. "golang.org/x/sys/cpu"
  8. )
  9. // poly1305vx is an assembly implementation of Poly1305 that uses vector
  10. // instructions. It must only be called if the vector facility (vx) is
  11. // available.
  12. //go:noescape
  13. func poly1305vx(out *[16]byte, m *byte, mlen uint64, key *[32]byte)
  14. // poly1305vmsl is an assembly implementation of Poly1305 that uses vector
  15. // instructions, including VMSL. It must only be called if the vector facility (vx) is
  16. // available and if VMSL is supported.
  17. //go:noescape
  18. func poly1305vmsl(out *[16]byte, m *byte, mlen uint64, key *[32]byte)
  19. func sum(out *[16]byte, m []byte, key *[32]byte) {
  20. if cpu.S390X.HasVX {
  21. var mPtr *byte
  22. if len(m) > 0 {
  23. mPtr = &m[0]
  24. }
  25. if cpu.S390X.HasVXE && len(m) > 256 {
  26. poly1305vmsl(out, mPtr, uint64(len(m)), key)
  27. } else {
  28. poly1305vx(out, mPtr, uint64(len(m)), key)
  29. }
  30. } else {
  31. sumGeneric(out, m, key)
  32. }
  33. }