github.com/euank/go@v0.0.0-20160829210321-495514729181/src/hash/crc32/crc32_amd64_test.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package crc32 6 7 import ( 8 "math/rand" 9 "testing" 10 ) 11 12 func TestCastagnoliSSE42(t *testing.T) { 13 if !sse42 { 14 t.Skip("SSE42 not supported") 15 } 16 17 // Init the SSE42 tables. 18 castagnoliOnce.Do(castagnoliInit) 19 20 // Generate a table to use with the non-SSE version. 21 slicingTable := makeTable8(Castagnoli) 22 23 // The optimized SSE4.2 implementation behaves differently for different 24 // lengths (especially around multiples of K*3). Crosscheck against the 25 // software implementation for various lengths. 26 for _, base := range []int{castagnoliK1, castagnoliK2, castagnoliK1 + castagnoliK2} { 27 for _, baseMult := range []int{2, 3, 5, 6, 9, 30} { 28 for _, variation := range []int{0, 1, 2, 3, 4, 7, 10, 16, 32, 50, 128} { 29 for _, varMult := range []int{-2, -1, +1, +2} { 30 length := base*baseMult + variation*varMult 31 p := make([]byte, length) 32 _, _ = rand.Read(p) 33 crcInit := uint32(rand.Int63()) 34 correct := updateSlicingBy8(crcInit, slicingTable, p) 35 result := updateCastagnoli(crcInit, p) 36 if result != correct { 37 t.Errorf("SSE42 implementation = 0x%x want 0x%x (buffer length %d)", 38 result, correct, len(p)) 39 } 40 } 41 } 42 } 43 } 44 }