]> Cypherpunks repositories - gostls13.git/commitdiff
hash/crc32: fix nil Castagnoli table problem
authorRadu Berinde <radu@cockroachlabs.com>
Sun, 28 Aug 2016 15:47:14 +0000 (11:47 -0400)
committerBrad Fitzpatrick <bradfitz@golang.org>
Sun, 28 Aug 2016 19:01:07 +0000 (19:01 +0000)
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>

src/hash/crc32/crc32.go
src/hash/crc32/crc32_amd64_test.go
src/hash/crc32/crc32_test.go

index 57089a700d326fff2087bca5e47a43db440cf2f7..6eed8ff30098c6cd272a2fca63e17e8bfd48f2e7 100644 (file)
@@ -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.
index 8bbaa10221802c9fdc1f20b0f57e49d982a42dc0..e136f788d6a7abf266bb1c3a463ff416a2b94e6a 100644 (file)
@@ -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)",
index 113a1096988b277b355d03ef22433d4e603dcf7a..7f7f0a2f744877e8311a9c230ec5cd8f0be142a0 100644 (file)
@@ -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()