diff --git a/libs/libc/misc/Kconfig b/libs/libc/misc/Kconfig index 1813ba476f8..77ed665c504 100644 --- a/libs/libc/misc/Kconfig +++ b/libs/libc/misc/Kconfig @@ -11,6 +11,12 @@ config LIBC_CRC64_FAST ---help--- Enable the CRC64 lookup table to compute the CRC64 faster. +config LIBC_CRC32_SLOW + bool "CRC32 not use table to decrease rodata size" + default n + ---help--- + Optional disable the CRC32 lookup table to decrease rodata usage. + config LIBC_KBDCODEC bool "Keyboard CODEC" default n diff --git a/libs/libc/misc/lib_crc32.c b/libs/libc/misc/lib_crc32.c index cd7eb2dcae4..e464157fd4d 100644 --- a/libs/libc/misc/lib_crc32.c +++ b/libs/libc/misc/lib_crc32.c @@ -52,6 +52,9 @@ * Private Data ************************************************************************************************/ +#ifdef CONFIG_LIBC_CRC32_SLOW +# define LIBC_CRC32_POLY 0xedb88320 +#else static const uint32_t crc32_tab[] = { 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, @@ -87,6 +90,7 @@ static const uint32_t crc32_tab[] = 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; +#endif /************************************************************************************************ * Public Functions @@ -103,11 +107,29 @@ static const uint32_t crc32_tab[] = uint32_t crc32part(FAR const uint8_t *src, size_t len, uint32_t crc32val) { size_t i; - +#ifdef CONFIG_LIBC_CRC32_SLOW + for (i = 0; i < len; i++) + { + size_t j; + crc32val ^= src[i]; + for (j = 0; j < 8; j++) + { + if (crc32val & 1) + { + crc32val = (crc32val >> 1) ^ LIBC_CRC32_POLY; + } + else + { + crc32val = crc32val >> 1; + } + } + } +#else for (i = 0; i < len; i++) { crc32val = crc32_tab[(crc32val & 0xff) ^ src[i]] ^ (crc32val >> 8); } +#endif return crc32val; }