rewrite out some weirdness
This commit is contained in:
parent
c3921c69e4
commit
accb4a3e26
1 changed files with 9 additions and 11 deletions
20
crc32.c
20
crc32.c
|
@ -4,7 +4,7 @@ static inline uint32_t
|
|||
crc_reflect(uint32_t input)
|
||||
{
|
||||
uint32_t reflected = 0;
|
||||
for (int i = 0; i < 4 * 8; i++) {
|
||||
for (int i = 0; i < 32; i++) {
|
||||
reflected <<= 1;
|
||||
reflected |= input & 1;
|
||||
input >>= 1;
|
||||
|
@ -18,7 +18,7 @@ crc_be_fill_table(uint32_t *table, uint32_t polynomial)
|
|||
const uint32_t lsb = 1 << 31;
|
||||
uint32_t poly = polynomial;
|
||||
|
||||
for (int c = 0; c < CRC_TABLE_SIZE; c++, table++) {
|
||||
for (int c = 0; c < CRC_TABLE_SIZE; c++) {
|
||||
uint32_t v = c << 24;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (v & lsb) {
|
||||
|
@ -28,7 +28,7 @@ crc_be_fill_table(uint32_t *table, uint32_t polynomial)
|
|||
v <<= 1;
|
||||
}
|
||||
}
|
||||
*table = v;
|
||||
*table++ = v;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ crc_le_fill_table(uint32_t *table, uint32_t polynomial)
|
|||
const uint32_t lsb = 1;
|
||||
uint32_t poly = crc_reflect(polynomial);
|
||||
|
||||
for (int c = 0; c < CRC_TABLE_SIZE; c++, table++) {
|
||||
for (int c = 0; c < CRC_TABLE_SIZE; c++) {
|
||||
uint32_t v = c;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (v & lsb) {
|
||||
|
@ -48,22 +48,20 @@ crc_le_fill_table(uint32_t *table, uint32_t polynomial)
|
|||
v >>= 1;
|
||||
}
|
||||
}
|
||||
*table = v;
|
||||
*table++ = v;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
crc_be_cycle(uint32_t *table, uint32_t *remainder, uint8_t c)
|
||||
{
|
||||
const uint8_t i = ((*remainder) >> 24) ^ c;
|
||||
const uint32_t next = table[i];
|
||||
*remainder = ((*remainder) << 8) ^ next;
|
||||
const uint8_t i = (*remainder >> 24) ^ c;
|
||||
*remainder = (*remainder << 8) ^ table[i];
|
||||
}
|
||||
|
||||
static inline void
|
||||
crc_le_cycle(uint32_t *table, uint32_t *remainder, uint8_t c)
|
||||
{
|
||||
const uint8_t i = (*remainder) ^ c;
|
||||
const uint32_t next = table[i];
|
||||
*remainder = ((*remainder) >> 8) ^ next;
|
||||
const uint8_t i = (*remainder & 0xFF) ^ c;
|
||||
*remainder = (*remainder >> 8) ^ table[i];
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue