1// Copyright 2018 The Wuffs Authors. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// https://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15// +build ignore 16 17package main 18 19// print-crc32-magic-numbers.go prints the std/crc32 magic number tables. 20// 21// Usage: go run print-crc32-magic-numbers.go 22 23import ( 24 "fmt" 25 "hash/crc32" 26 "os" 27) 28 29func main() { 30 if err := main1(); err != nil { 31 os.Stderr.WriteString(err.Error() + "\n") 32 os.Exit(1) 33 } 34} 35 36func main1() error { 37 tables := [16]crc32.Table{} 38 tables[0] = *crc32.MakeTable(crc32.IEEE) 39 40 // See "Multi-Byte Lookup Tables" in std/crc32/README.md for more detail on 41 // the slicing-by-M algorithm. We use an M of 16. 42 for i := 0; i < 256; i++ { 43 crc := tables[0][i] 44 for j := 1; j < 16; j++ { 45 crc = tables[0][crc&0xFF] ^ (crc >> 8) 46 tables[j][i] = crc 47 } 48 } 49 50 for i, t := range tables { 51 if i != 0 { 52 fmt.Println("],[") 53 } 54 for j, x := range t { 55 fmt.Printf("0x%08X,", x) 56 if j&7 == 7 { 57 fmt.Println() 58 } 59 } 60 } 61 return nil 62} 63