crc32_amd64p32.go 972 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. //+build !appengine,!gccgo
  2. // Copyright 2011 The Go Authors. All rights reserved.
  3. // Use of this source code is governed by a BSD-style
  4. // license that can be found in the LICENSE file.
  5. package crc32
  6. // This file contains the code to call the SSE 4.2 version of the Castagnoli
  7. // CRC.
  8. // haveSSE42 is defined in crc_amd64p32.s and uses CPUID to test for 4.2
  9. // support.
  10. func haveSSE42() bool
  11. // castagnoliSSE42 is defined in crc_amd64.s and uses the SSE4.2 CRC32
  12. // instruction.
  13. func castagnoliSSE42(crc uint32, p []byte) uint32
  14. var sse42 = haveSSE42()
  15. func updateCastagnoli(crc uint32, p []byte) uint32 {
  16. if sse42 {
  17. return castagnoliSSE42(crc, p)
  18. }
  19. return update(crc, castagnoliTable, p)
  20. }
  21. func updateIEEE(crc uint32, p []byte) uint32 {
  22. // only use slicing-by-8 when input is >= 4KB
  23. if len(p) >= 4096 {
  24. iEEETable8Once.Do(func() {
  25. iEEETable8 = makeTable8(IEEE)
  26. })
  27. return updateSlicingBy8(crc, iEEETable8, p)
  28. }
  29. return update(crc, IEEETable, p)
  30. }