crc32c/
hw_tables.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
pub struct CrcTable([[u32; 256]; 4]);

#[allow(dead_code)]
impl CrcTable {
    pub fn at(&self, i: u8, j: u8) -> u32 {
        let i = i as usize;
        let j = j as usize;
        self.0[i][j]
    }

    pub fn shift_u32(&self, crc: u32) -> u32 {
        let mut result = self.at(0, crc as u8);

        for i in 1..4 {
            let shift = i * 8;
            result ^= self.at(i, (crc >> shift) as u8);
        }

        result
    }

    pub fn shift_u64(&self, crc: u64) -> u64 {
        let mut result = u64::from(self.at(0, crc as u8));

        for i in 1..4 {
            let shift = i * 8;
            result ^= u64::from(self.at(i, (crc >> shift) as u8));
        }

        result
    }
}

pub const LONG: usize = 8192;
pub const SHORT: usize = 256;
pub const LONG_TABLE: CrcTable = CrcTable(include!(concat!(env!("OUT_DIR"), "/", "hw.long.table")));
pub const SHORT_TABLE: CrcTable =
    CrcTable(include!(concat!(env!("OUT_DIR"), "/", "hw.short.table")));