aboutsummaryrefslogtreecommitdiff
path: root/src/hash
diff options
context:
space:
mode:
authorRadu Berinde <radu@cockroachlabs.com>2016-08-28 11:47:14 -0400
committerBrad Fitzpatrick <bradfitz@golang.org>2016-08-28 19:01:07 +0000
commit8c15a1725147692e1106f2e32fae657e1b7f27aa (patch)
treeff5621e8239d1629894680c167b22f724d348198 /src/hash
parent0c6c3d1de7bfe40d3589109bf2adb1726d6caca8 (diff)
downloadgo-8c15a1725147692e1106f2e32fae657e1b7f27aa.tar.gz
go-8c15a1725147692e1106f2e32fae657e1b7f27aa.zip
hash/crc32: fix nil Castagnoli table problem
When SSE is available, we don't need the Table. However, it is returned as a handle by MakeTable. Fix this to always generate the table. Further cleanup is discussed in #16909. Change-Id: Ic05400d68c6b5d25073ebd962000451746137afc Reviewed-on: https://go-review.googlesource.com/27934 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/hash')
-rw-r--r--src/hash/crc32/crc32.go5
-rw-r--r--src/hash/crc32/crc32_amd64_test.go9
-rw-r--r--src/hash/crc32/crc32_test.go3
3 files changed, 11 insertions, 6 deletions
diff --git a/src/hash/crc32/crc32.go b/src/hash/crc32/crc32.go
index 57089a700d..6eed8ff300 100644
--- a/src/hash/crc32/crc32.go
+++ b/src/hash/crc32/crc32.go
@@ -57,9 +57,12 @@ func castagnoliInit() {
needGenericTables := castagnoliInitArch()
if needGenericTables {
- castagnoliTable = makeTable(Castagnoli)
castagnoliTable8 = makeTable8(Castagnoli)
}
+
+ // Even if we don't need the contents of this table, we use it as a handle
+ // returned by MakeTable. We should find a way to clean this up (see #16909).
+ castagnoliTable = makeTable(Castagnoli)
}
// IEEETable is the table for the IEEE polynomial.
diff --git a/src/hash/crc32/crc32_amd64_test.go b/src/hash/crc32/crc32_amd64_test.go
index 8bbaa10221..e136f788d6 100644
--- a/src/hash/crc32/crc32_amd64_test.go
+++ b/src/hash/crc32/crc32_amd64_test.go
@@ -15,11 +15,10 @@ func TestCastagnoliSSE42(t *testing.T) {
}
// Init the SSE42 tables.
- MakeTable(Castagnoli)
+ castagnoliOnce.Do(castagnoliInit)
- // Manually init the software implementation to compare against.
- castagnoliTable = makeTable(Castagnoli)
- castagnoliTable8 = makeTable8(Castagnoli)
+ // Generate a table to use with the non-SSE version.
+ slicingTable := makeTable8(Castagnoli)
// The optimized SSE4.2 implementation behaves differently for different
// lengths (especially around multiples of K*3). Crosscheck against the
@@ -32,7 +31,7 @@ func TestCastagnoliSSE42(t *testing.T) {
p := make([]byte, length)
_, _ = rand.Read(p)
crcInit := uint32(rand.Int63())
- correct := updateSlicingBy8(crcInit, castagnoliTable8, p)
+ correct := updateSlicingBy8(crcInit, slicingTable, p)
result := updateCastagnoli(crcInit, p)
if result != correct {
t.Errorf("SSE42 implementation = 0x%x want 0x%x (buffer length %d)",
diff --git a/src/hash/crc32/crc32_test.go b/src/hash/crc32/crc32_test.go
index 113a109698..7f7f0a2f74 100644
--- a/src/hash/crc32/crc32_test.go
+++ b/src/hash/crc32/crc32_test.go
@@ -51,6 +51,9 @@ var golden = []test{
func TestGolden(t *testing.T) {
castagnoliTab := MakeTable(Castagnoli)
+ if castagnoliTab == nil {
+ t.Errorf("nil Castagnoli Table")
+ }
for _, g := range golden {
ieee := NewIEEE()