WangXuan95 / FPGA-Gzip-compressor

An FPGA-based GZIP (Deflate algorithm) compressor, which inputs raw data and outputs standard GZIP format (as known as .gz file format). 基于FPGA的GZIP压缩器。输入原始数据,输出标准的GZIP格式,即常见的 .gz / .tar.gz 文件的格式。
https://gitee.com/wangxuan95/FPGA-Gzip-compressor
GNU General Public License v3.0
101 stars 23 forks source link

CRC32 in simulation #5

Open kkkKaiser opened 7 months ago

kkkKaiser commented 7 months ago

Hello, may I ask what is the polynomial of CRC32? I couldn't find it through Google search, and I tried using IEEE802 but failed. Meanwhile, I don't quite understand the meaning of your coding in fun calculate_crc, which is quite different from what I saw online. Can you briefly explain how coding work, or are there any similar blogs that can be recommended? Thank you very much for your help.

WangXuan95 commented 1 week ago

Hello, my CRC32 implementation is written according to the C language below. Note that the CRC polynomial of Gzip is fixed, and the different implementations you see are essentially the same polynomial.

uint32_t calcCrc32 (uint8_t *p_src, uint32_t len) {
    static const uint32_t TABLE_CRC32 [] = { 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c };
    uint32_t crc = 0xFFFFFFFF;
    uint8_t *p_end = p_src + len;
    for (; p_src<p_end; p_src++) {
        crc ^= *p_src;
        crc = TABLE_CRC32[crc & 0x0f] ^ (crc >> 4);
        crc = TABLE_CRC32[crc & 0x0f] ^ (crc >> 4);
    }
    return ~crc;
}