crc32c/
hw_tables.rs
1pub struct CrcTable([[u32; 256]; 4]);
2
3#[allow(dead_code)]
4impl CrcTable {
5 pub fn at(&self, i: u8, j: u8) -> u32 {
6 let i = i as usize;
7 let j = j as usize;
8 self.0[i][j]
9 }
10
11 pub fn shift_u32(&self, crc: u32) -> u32 {
12 let mut result = self.at(0, crc as u8);
13
14 for i in 1..4 {
15 let shift = i * 8;
16 result ^= self.at(i, (crc >> shift) as u8);
17 }
18
19 result
20 }
21
22 pub fn shift_u64(&self, crc: u64) -> u64 {
23 let mut result = u64::from(self.at(0, crc as u8));
24
25 for i in 1..4 {
26 let shift = i * 8;
27 result ^= u64::from(self.at(i, (crc >> shift) as u8));
28 }
29
30 result
31 }
32}
33
34pub const LONG: usize = 8192;
35pub const SHORT: usize = 256;
36pub const LONG_TABLE: CrcTable = CrcTable(include!(concat!(env!("OUT_DIR"), "/", "hw.long.table")));
37pub const SHORT_TABLE: CrcTable =
38 CrcTable(include!(concat!(env!("OUT_DIR"), "/", "hw.short.table")));