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:
Clement Burin des Roziers 2014-10-31 14:50:22 +01:00 committed by Laurent Bonnans
parent 61c6c767b0
commit 1f62fa4909
1 changed files with 11 additions and 5 deletions

View File

@ -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 crc = -1;
uint8_t byte;
static uint8_t bytes[128];
while (len--) {
byte = target_mem_read8(t, base);
while (len) {
uint32_t i;
uint32_t read_len = len >= 128 ? 128 : len;
crc = crc32_calc(crc, byte);
base++;
target_mem_read(t, bytes, base, read_len);
for (i=0; i<read_len; i++)
crc = crc32_calc(crc, bytes[i]);
base += read_len;
len -= read_len;
}
return crc;
}