| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#ifdef ARM_ACLE_CRC_HASH |
| 9 |
#ifdef _MSC_VER |
| 10 |
# include <intrin.h> |
| 11 |
#else |
| 12 |
# include <arm_acle.h> |
| 13 |
#endif |
| 14 |
#include "../../zbuild.h" |
| 15 |
|
| 16 |
uint32_t crc32_acle(uint32_t crc, const uint8_t *buf, uint64_t len) { |
| 17 |
Z_REGISTER uint32_t c; |
| 18 |
Z_REGISTER const uint16_t *buf2; |
| 19 |
Z_REGISTER const uint32_t *buf4; |
| 20 |
|
| 21 |
c = ~crc; |
| 22 |
if (len && ((ptrdiff_t)buf & 1)) { |
| 23 |
c = __crc32b(c, *buf++); |
| 24 |
len--; |
| 25 |
} |
| 26 |
|
| 27 |
if ((len >= sizeof(uint16_t)) && ((ptrdiff_t)buf & sizeof(uint16_t))) { |
| 28 |
buf2 = (const uint16_t *) buf; |
| 29 |
c = __crc32h(c, *buf2++); |
| 30 |
len -= sizeof(uint16_t); |
| 31 |
buf4 = (const uint32_t *) buf2; |
| 32 |
} else { |
| 33 |
buf4 = (const uint32_t *) buf; |
| 34 |
} |
| 35 |
|
| 36 |
#if defined(__aarch64__) || defined(_M_ARM64) |
| 37 |
if ((len >= sizeof(uint32_t)) && ((ptrdiff_t)buf & sizeof(uint32_t))) { |
| 38 |
c = __crc32w(c, *buf4++); |
| 39 |
len -= sizeof(uint32_t); |
| 40 |
} |
| 41 |
|
| 42 |
if (len == 0) { |
| 43 |
c = ~c; |
| 44 |
return c; |
| 45 |
} |
| 46 |
|
| 47 |
const uint64_t *buf8 = (const uint64_t *) buf4; |
| 48 |
|
| 49 |
while (len >= sizeof(uint64_t)) { |
| 50 |
c = __crc32d(c, *buf8++); |
| 51 |
len -= sizeof(uint64_t); |
| 52 |
} |
| 53 |
|
| 54 |
if (len >= sizeof(uint32_t)) { |
| 55 |
buf4 = (const uint32_t *) buf8; |
| 56 |
c = __crc32w(c, *buf4++); |
| 57 |
len -= sizeof(uint32_t); |
| 58 |
buf2 = (const uint16_t *) buf4; |
| 59 |
} else { |
| 60 |
buf2 = (const uint16_t *) buf8; |
| 61 |
} |
| 62 |
|
| 63 |
if (len >= sizeof(uint16_t)) { |
| 64 |
c = __crc32h(c, *buf2++); |
| 65 |
len -= sizeof(uint16_t); |
| 66 |
} |
| 67 |
|
| 68 |
buf = (const unsigned char *) buf2; |
| 69 |
#else |
| 70 |
|
| 71 |
if (len == 0) { |
| 72 |
c = ~c; |
| 73 |
return c; |
| 74 |
} |
| 75 |
|
| 76 |
while (len >= sizeof(uint32_t)) { |
| 77 |
c = __crc32w(c, *buf4++); |
| 78 |
len -= sizeof(uint32_t); |
| 79 |
} |
| 80 |
|
| 81 |
if (len >= sizeof(uint16_t)) { |
| 82 |
buf2 = (const uint16_t *) buf4; |
| 83 |
c = __crc32h(c, *buf2++); |
| 84 |
len -= sizeof(uint16_t); |
| 85 |
buf = (const unsigned char *) buf2; |
| 86 |
} else { |
| 87 |
buf = (const unsigned char *) buf4; |
| 88 |
} |
| 89 |
#endif |
| 90 |
|
| 91 |
if (len) { |
| 92 |
c = __crc32b(c, *buf); |
| 93 |
} |
| 94 |
|
| 95 |
c = ~c; |
| 96 |
return c; |
| 97 |
} |
| 98 |
#endif |