crypto: crc32: Optimize dynamic CRC table generation
In barebox we have an option for dynamic formation of the CRC32 table (DYNAMIC_CRC_TABLE), but the source code declares a static array which is simply filled with data, the resulting code becomes even more than without DYNAMIC_CRC_TABLE option, due to the BSS usage. CONFIG_DYNAMIC_CRC_TABLE=n text data bss dec hex filename 1884 0 0 1884 75c crc32.o CONFIG_DYNAMIC_CRC_TABLE=y text data bss dec hex filename 1066 4 1024 2094 82e crc32.o This patch provides dynamic buffer allocation for the CRC table, which saves about 1 Kbyte, as it should be. CONFIG_DYNAMIC_CRC_TABLE=y text data bss dec hex filename 1062 0 4 1066 42a crc32.o Signed-off-by: Alexander Shiyan <shc_work@mail.ru> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
c672fda23a
commit
2049dbb6fe
|
@ -24,9 +24,7 @@
|
||||||
|
|
||||||
#ifdef CONFIG_DYNAMIC_CRC_TABLE
|
#ifdef CONFIG_DYNAMIC_CRC_TABLE
|
||||||
|
|
||||||
static int crc_table_empty = 1;
|
static ulong *crc_table;
|
||||||
static ulong crc_table[256];
|
|
||||||
static void make_crc_table(void);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
|
Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
|
||||||
|
@ -65,6 +63,8 @@ static void make_crc_table(void)
|
||||||
for (n = 0; n < sizeof(p)/sizeof(char); n++)
|
for (n = 0; n < sizeof(p)/sizeof(char); n++)
|
||||||
poly |= 1L << (31 - p[n]);
|
poly |= 1L << (31 - p[n]);
|
||||||
|
|
||||||
|
crc_table = xmalloc(sizeof(ulong) * 256);
|
||||||
|
|
||||||
for (n = 0; n < 256; n++)
|
for (n = 0; n < 256; n++)
|
||||||
{
|
{
|
||||||
c = (ulong)n;
|
c = (ulong)n;
|
||||||
|
@ -72,7 +72,6 @@ static void make_crc_table(void)
|
||||||
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
|
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
|
||||||
crc_table[n] = c;
|
crc_table[n] = c;
|
||||||
}
|
}
|
||||||
crc_table_empty = 0;
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
/* ========================================================================
|
/* ========================================================================
|
||||||
|
@ -147,7 +146,7 @@ STATIC uint32_t crc32(uint32_t crc, const void *_buf, unsigned int len)
|
||||||
const unsigned char *buf = _buf;
|
const unsigned char *buf = _buf;
|
||||||
|
|
||||||
#ifdef CONFIG_DYNAMIC_CRC_TABLE
|
#ifdef CONFIG_DYNAMIC_CRC_TABLE
|
||||||
if (crc_table_empty)
|
if (!crc_table)
|
||||||
make_crc_table();
|
make_crc_table();
|
||||||
#endif
|
#endif
|
||||||
crc = crc ^ 0xffffffffL;
|
crc = crc ^ 0xffffffffL;
|
||||||
|
@ -173,7 +172,7 @@ STATIC uint32_t crc32_no_comp(uint32_t crc, const void *_buf, unsigned int len)
|
||||||
const unsigned char *buf = _buf;
|
const unsigned char *buf = _buf;
|
||||||
|
|
||||||
#ifdef CONFIG_DYNAMIC_CRC_TABLE
|
#ifdef CONFIG_DYNAMIC_CRC_TABLE
|
||||||
if (crc_table_empty)
|
if (!crc_table)
|
||||||
make_crc_table();
|
make_crc_table();
|
||||||
#endif
|
#endif
|
||||||
while (len >= 8)
|
while (len >= 8)
|
||||||
|
|
Loading…
Reference in New Issue