CRC32: improved computation time
Reading one byte at a time was so slow that it caused the gdb client to timeout.
This commit is contained in:
parent
61c6c767b0
commit
1f62fa4909
16
src/crc32.c
16
src/crc32.c
|
@ -97,13 +97,19 @@ uint32_t crc32_calc(uint32_t crc, uint8_t data)
|
||||||
uint32_t generic_crc32(target *t, uint32_t base, int len)
|
uint32_t generic_crc32(target *t, uint32_t base, int len)
|
||||||
{
|
{
|
||||||
uint32_t crc = -1;
|
uint32_t crc = -1;
|
||||||
uint8_t byte;
|
static uint8_t bytes[128];
|
||||||
|
|
||||||
while (len--) {
|
while (len) {
|
||||||
byte = target_mem_read8(t, base);
|
uint32_t i;
|
||||||
|
uint32_t read_len = len >= 128 ? 128 : len;
|
||||||
|
|
||||||
crc = crc32_calc(crc, byte);
|
target_mem_read(t, bytes, base, read_len);
|
||||||
base++;
|
|
||||||
|
for (i=0; i<read_len; i++)
|
||||||
|
crc = crc32_calc(crc, bytes[i]);
|
||||||
|
|
||||||
|
base += read_len;
|
||||||
|
len -= read_len;
|
||||||
}
|
}
|
||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue