Commit 8c15a172 authored by Radu Berinde's avatar Radu Berinde Committed by Brad Fitzpatrick

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/27934Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 0c6c3d1d
...@@ -57,9 +57,12 @@ func castagnoliInit() { ...@@ -57,9 +57,12 @@ func castagnoliInit() {
needGenericTables := castagnoliInitArch() needGenericTables := castagnoliInitArch()
if needGenericTables { if needGenericTables {
castagnoliTable = makeTable(Castagnoli)
castagnoliTable8 = makeTable8(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. // IEEETable is the table for the IEEE polynomial.
......
...@@ -15,11 +15,10 @@ func TestCastagnoliSSE42(t *testing.T) { ...@@ -15,11 +15,10 @@ func TestCastagnoliSSE42(t *testing.T) {
} }
// Init the SSE42 tables. // Init the SSE42 tables.
MakeTable(Castagnoli) castagnoliOnce.Do(castagnoliInit)
// Manually init the software implementation to compare against. // Generate a table to use with the non-SSE version.
castagnoliTable = makeTable(Castagnoli) slicingTable := makeTable8(Castagnoli)
castagnoliTable8 = makeTable8(Castagnoli)
// The optimized SSE4.2 implementation behaves differently for different // The optimized SSE4.2 implementation behaves differently for different
// lengths (especially around multiples of K*3). Crosscheck against the // lengths (especially around multiples of K*3). Crosscheck against the
...@@ -32,7 +31,7 @@ func TestCastagnoliSSE42(t *testing.T) { ...@@ -32,7 +31,7 @@ func TestCastagnoliSSE42(t *testing.T) {
p := make([]byte, length) p := make([]byte, length)
_, _ = rand.Read(p) _, _ = rand.Read(p)
crcInit := uint32(rand.Int63()) crcInit := uint32(rand.Int63())
correct := updateSlicingBy8(crcInit, castagnoliTable8, p) correct := updateSlicingBy8(crcInit, slicingTable, p)
result := updateCastagnoli(crcInit, p) result := updateCastagnoli(crcInit, p)
if result != correct { if result != correct {
t.Errorf("SSE42 implementation = 0x%x want 0x%x (buffer length %d)", t.Errorf("SSE42 implementation = 0x%x want 0x%x (buffer length %d)",
......
...@@ -51,6 +51,9 @@ var golden = []test{ ...@@ -51,6 +51,9 @@ var golden = []test{
func TestGolden(t *testing.T) { func TestGolden(t *testing.T) {
castagnoliTab := MakeTable(Castagnoli) castagnoliTab := MakeTable(Castagnoli)
if castagnoliTab == nil {
t.Errorf("nil Castagnoli Table")
}
for _, g := range golden { for _, g := range golden {
ieee := NewIEEE() ieee := NewIEEE()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment