Skip to content

Commit 8c15a17

Browse files
RaduBerindebradfitz
authored andcommitted
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 <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 0c6c3d1 commit 8c15a17

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/hash/crc32/crc32.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ func castagnoliInit() {
5757
needGenericTables := castagnoliInitArch()
5858

5959
if needGenericTables {
60-
castagnoliTable = makeTable(Castagnoli)
6160
castagnoliTable8 = makeTable8(Castagnoli)
6261
}
62+
63+
// Even if we don't need the contents of this table, we use it as a handle
64+
// returned by MakeTable. We should find a way to clean this up (see #16909).
65+
castagnoliTable = makeTable(Castagnoli)
6366
}
6467

6568
// IEEETable is the table for the IEEE polynomial.

src/hash/crc32/crc32_amd64_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ func TestCastagnoliSSE42(t *testing.T) {
1515
}
1616

1717
// Init the SSE42 tables.
18-
MakeTable(Castagnoli)
18+
castagnoliOnce.Do(castagnoliInit)
1919

20-
// Manually init the software implementation to compare against.
21-
castagnoliTable = makeTable(Castagnoli)
22-
castagnoliTable8 = makeTable8(Castagnoli)
20+
// Generate a table to use with the non-SSE version.
21+
slicingTable := makeTable8(Castagnoli)
2322

2423
// The optimized SSE4.2 implementation behaves differently for different
2524
// lengths (especially around multiples of K*3). Crosscheck against the
@@ -32,7 +31,7 @@ func TestCastagnoliSSE42(t *testing.T) {
3231
p := make([]byte, length)
3332
_, _ = rand.Read(p)
3433
crcInit := uint32(rand.Int63())
35-
correct := updateSlicingBy8(crcInit, castagnoliTable8, p)
34+
correct := updateSlicingBy8(crcInit, slicingTable, p)
3635
result := updateCastagnoli(crcInit, p)
3736
if result != correct {
3837
t.Errorf("SSE42 implementation = 0x%x want 0x%x (buffer length %d)",

src/hash/crc32/crc32_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ var golden = []test{
5151

5252
func TestGolden(t *testing.T) {
5353
castagnoliTab := MakeTable(Castagnoli)
54+
if castagnoliTab == nil {
55+
t.Errorf("nil Castagnoli Table")
56+
}
5457

5558
for _, g := range golden {
5659
ieee := NewIEEE()

0 commit comments

Comments
 (0)