From a59d0efca05f831d8a03357f714f0f547946b2b0 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Mon, 21 Jan 2019 12:24:40 +1300 Subject: [PATCH] libbase: crc32: add smaller version Signed-off-by: Sean Cross --- litex/soc/software/libbase/crc32.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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 -- 2.30.2