1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package crc32
- const (
- vxMinLen = 64
- vxAlignMask = 15
- )
- func hasVectorFacility() bool
- var hasVX = hasVectorFacility()
- // vectorizedCastagnoli implements CRC32 using vector instructions.
- // It is defined in crc32_s390x.s.
- //go:noescape
- func vectorizedCastagnoli(crc uint32, p []byte) uint32
- // vectorizedIEEE implements CRC32 using vector instructions.
- // It is defined in crc32_s390x.s.
- //go:noescape
- func vectorizedIEEE(crc uint32, p []byte) uint32
- func archAvailableCastagnoli() bool {
- return hasVX
- }
- var archCastagnoliTable8 *slicing8Table
- func archInitCastagnoli() {
- if !hasVX {
- panic("not available")
- }
-
- archCastagnoliTable8 = slicingMakeTable(Castagnoli)
- }
- func archUpdateCastagnoli(crc uint32, p []byte) uint32 {
- if !hasVX {
- panic("not available")
- }
-
- if len(p) >= vxMinLen {
- aligned := len(p) & ^vxAlignMask
- crc = vectorizedCastagnoli(crc, p[:aligned])
- p = p[aligned:]
- }
- if len(p) == 0 {
- return crc
- }
- return slicingUpdate(crc, archCastagnoliTable8, p)
- }
- func archAvailableIEEE() bool {
- return hasVX
- }
- var archIeeeTable8 *slicing8Table
- func archInitIEEE() {
- if !hasVX {
- panic("not available")
- }
-
- archIeeeTable8 = slicingMakeTable(IEEE)
- }
- func archUpdateIEEE(crc uint32, p []byte) uint32 {
- if !hasVX {
- panic("not available")
- }
-
- if len(p) >= vxMinLen {
- aligned := len(p) & ^vxAlignMask
- crc = vectorizedIEEE(crc, p[:aligned])
- p = p[aligned:]
- }
- if len(p) == 0 {
- return crc
- }
- return slicingUpdate(crc, archIeeeTable8, p)
- }
|