-
Notifications
You must be signed in to change notification settings - Fork 199
/
crc.c
52 lines (42 loc) · 1.09 KB
/
crc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdint.h>
#include "arm_acle.h"
uint32_t arm_crc32c(const uint8_t *data, int length, uint32_t prev_crc) {
uint32_t crc = ~prev_crc;
// Align data if it's not aligned
while (((uintptr_t)data & 7) && length > 0) {
crc = __crc32cb(crc, *(uint8_t *)data);
data++;
length--;
}
while (length >= 8) {
crc = __crc32cd(crc, *(uint64_t *)data);
data += 8;
length -= 8;
}
while (length > 0) {
crc = __crc32cb(crc, *(uint8_t *)data);
data++;
length--;
}
return ~crc;
}
uint32_t arm_crc32(const uint8_t *data, int length, uint32_t prev_crc) {
uint32_t crc = ~prev_crc;
// Align data if it's not aligned
while (((uintptr_t)data & 7) && length > 0) {
crc = __crc32b(crc, *(uint8_t *)data);
data++;
length--;
}
while (length >= 8) {
crc = __crc32d(crc, *(uint64_t *)data);
data += 8;
length -= 8;
}
while (length > 0) {
crc = __crc32b(crc, *(uint8_t *)data);
data++;
length--;
}
return ~crc;
}