summaryrefslogtreecommitdiff
path: root/libgo/go/hash/crc32/crc32_s390x.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/hash/crc32/crc32_s390x.go')
-rw-r--r--libgo/go/hash/crc32/crc32_s390x.go81
1 files changed, 44 insertions, 37 deletions
diff --git a/libgo/go/hash/crc32/crc32_s390x.go b/libgo/go/hash/crc32/crc32_s390x.go
index 2a7926b4796..8815c70470b 100644
--- a/libgo/go/hash/crc32/crc32_s390x.go
+++ b/libgo/go/hash/crc32/crc32_s390x.go
@@ -27,58 +27,65 @@ func vectorizedCastagnoli(crc uint32, p []byte) uint32
//go:noescape
func vectorizedIEEE(crc uint32, p []byte) uint32
-func genericCastagnoli(crc uint32, p []byte) uint32 {
- // Use slicing-by-8 on larger inputs.
- if len(p) >= sliceBy8Cutoff {
- return updateSlicingBy8(crc, castagnoliTable8, p)
- }
- return update(crc, castagnoliTable, p)
+func archAvailableCastagnoli() bool {
+ return hasVX
}
-func genericIEEE(crc uint32, p []byte) uint32 {
- // Use slicing-by-8 on larger inputs.
- if len(p) >= sliceBy8Cutoff {
- ieeeTable8Once.Do(func() {
- ieeeTable8 = makeTable8(IEEE)
- })
- return updateSlicingBy8(crc, ieeeTable8, p)
+var archCastagnoliTable8 *slicing8Table
+
+func archInitCastagnoli() {
+ if !hasVX {
+ panic("not available")
}
- return update(crc, IEEETable, p)
+ // We still use slicing-by-8 for small buffers.
+ archCastagnoliTable8 = slicingMakeTable(Castagnoli)
}
-// updateCastagnoli calculates the checksum of p using
-// vectorizedCastagnoli if possible and falling back onto
-// genericCastagnoli as needed.
-func updateCastagnoli(crc uint32, p []byte) uint32 {
- // Use vectorized function if vector facility is available and
- // data length is above threshold.
- if hasVX && len(p) >= vxMinLen {
+// archUpdateCastagnoli calculates the checksum of p using
+// vectorizedCastagnoli.
+func archUpdateCastagnoli(crc uint32, p []byte) uint32 {
+ if !hasVX {
+ panic("not available")
+ }
+ // Use vectorized function if data length is above threshold.
+ if len(p) >= vxMinLen {
aligned := len(p) & ^vxAlignMask
crc = vectorizedCastagnoli(crc, p[:aligned])
p = p[aligned:]
- // process remaining data
- if len(p) > 0 {
- crc = genericCastagnoli(crc, p)
- }
+ }
+ if len(p) == 0 {
return crc
}
- return genericCastagnoli(crc, p)
+ return slicingUpdate(crc, archCastagnoliTable8, p)
+}
+
+func archAvailableIEEE() bool {
+ return hasVX
+}
+
+var archIeeeTable8 *slicing8Table
+
+func archInitIEEE() {
+ if !hasVX {
+ panic("not available")
+ }
+ // We still use slicing-by-8 for small buffers.
+ archIeeeTable8 = slicingMakeTable(IEEE)
}
-// updateIEEE calculates the checksum of p using vectorizedIEEE if
-// possible and falling back onto genericIEEE as needed.
-func updateIEEE(crc uint32, p []byte) uint32 {
- // Use vectorized function if vector facility is available and
- // data length is above threshold.
- if hasVX && len(p) >= vxMinLen {
+// archUpdateIEEE calculates the checksum of p using vectorizedIEEE.
+func archUpdateIEEE(crc uint32, p []byte) uint32 {
+ if !hasVX {
+ panic("not available")
+ }
+ // Use vectorized function if data length is above threshold.
+ if len(p) >= vxMinLen {
aligned := len(p) & ^vxAlignMask
crc = vectorizedIEEE(crc, p[:aligned])
p = p[aligned:]
- // process remaining data
- if len(p) > 0 {
- crc = genericIEEE(crc, p)
- }
+ }
+ if len(p) == 0 {
return crc
}
- return genericIEEE(crc, p)
+ return slicingUpdate(crc, archIeeeTable8, p)
}