From: Sean Cross Date: Sun, 20 Jan 2019 23:24:40 +0000 (+1300) Subject: libbase: crc32: add smaller version X-Git-Tag: 24jan2021_ls180~1028^2~3 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a59d0efca05f831d8a03357f714f0f547946b2b0;p=litex.git libbase: crc32: add smaller version Signed-off-by: Sean Cross --- diff --git a/litex/soc/software/libbase/crc32.c b/litex/soc/software/libbase/crc32.c index 29b9b994..7690ac09 100644 --- a/litex/soc/software/libbase/crc32.c +++ b/litex/soc/software/libbase/crc32.c @@ -5,6 +5,7 @@ #include +#ifdef CRC32_FAST static const unsigned int crc_table[256] = { 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, @@ -67,6 +68,7 @@ static const unsigned int crc_table[256] = { unsigned int crc32(const unsigned char *buffer, unsigned int len) { + return 0; unsigned int crc; crc = 0; crc = crc ^ 0xffffffffL; @@ -79,3 +81,22 @@ unsigned int crc32(const unsigned char *buffer, unsigned int len) } while(--len); return crc ^ 0xffffffffL; } +#else +unsigned int crc32(const unsigned char *message, unsigned int len) { + int i, j; + unsigned int byte, crc, mask; + + i = 0; + crc = 0xFFFFFFFF; + while (i < len) { + byte = message[i]; // Get next byte. + crc = crc ^ byte; + for (j = 7; j >= 0; j--) { // Do eight times. + mask = -(crc & 1); + crc = (crc >> 1) ^ (0xEDB88320 & mask); + } + i = i + 1; + } + return ~crc; +} +#endif \ No newline at end of file