| 1 |
/* crc32_acle.c -- compute the CRC-32 of a data stream |
| 2 |
* Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler |
| 3 |
* Copyright (C) 2016 Yang Zhang |
| 4 |
* For conditions of distribution and use, see copyright notice in zlib.h |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifdef ARM_ACLE |
| 9 |
#include "acle_intrins.h" |
| 10 |
#include "../../zbuild.h" |
| 11 |
|
| 12 |
Z_INTERNAL Z_TARGET_CRC uint32_t crc32_acle(uint32_t crc, const uint8_t *buf, size_t len) { |
| 13 |
Z_REGISTER uint32_t c; |
| 14 |
Z_REGISTER const uint16_t *buf2; |
| 15 |
Z_REGISTER const uint32_t *buf4; |
| 16 |
Z_REGISTER const uint64_t *buf8; |
| 17 |
|
| 18 |
c = ~crc; |
| 19 |
|
| 20 |
if (UNLIKELY(len == 1)) { |
| 21 |
c = __crc32b(c, *buf); |
| 22 |
c = ~c; |
| 23 |
return c; |
| 24 |
} |
| 25 |
|
| 26 |
if ((ptrdiff_t)buf & (sizeof(uint64_t) - 1)) { |
| 27 |
if (len && ((ptrdiff_t)buf & 1)) { |
| 28 |
c = __crc32b(c, *buf++); |
| 29 |
len--; |
| 30 |
} |
| 31 |
|
| 32 |
if ((len >= sizeof(uint16_t)) && ((ptrdiff_t)buf & sizeof(uint16_t))) { |
| 33 |
buf2 = (const uint16_t *) buf; |
| 34 |
c = __crc32h(c, *buf2++); |
| 35 |
len -= sizeof(uint16_t); |
| 36 |
buf4 = (const uint32_t *) buf2; |
| 37 |
} else { |
| 38 |
buf4 = (const uint32_t *) buf; |
| 39 |
} |
| 40 |
|
| 41 |
if ((len >= sizeof(uint32_t)) && ((ptrdiff_t)buf & sizeof(uint32_t))) { |
| 42 |
c = __crc32w(c, *buf4++); |
| 43 |
len -= sizeof(uint32_t); |
| 44 |
} |
| 45 |
|
| 46 |
buf8 = (const uint64_t *) buf4; |
| 47 |
} else { |
| 48 |
buf8 = (const uint64_t *) buf; |
| 49 |
} |
| 50 |
|
| 51 |
while (len >= sizeof(uint64_t)) { |
| 52 |
c = __crc32d(c, *buf8++); |
| 53 |
len -= sizeof(uint64_t); |
| 54 |
} |
| 55 |
|
| 56 |
if (len >= sizeof(uint32_t)) { |
| 57 |
buf4 = (const uint32_t *) buf8; |
| 58 |
c = __crc32w(c, *buf4++); |
| 59 |
len -= sizeof(uint32_t); |
| 60 |
buf2 = (const uint16_t *) buf4; |
| 61 |
} else { |
| 62 |
buf2 = (const uint16_t *) buf8; |
| 63 |
} |
| 64 |
|
| 65 |
if (len >= sizeof(uint16_t)) { |
| 66 |
c = __crc32h(c, *buf2++); |
| 67 |
len -= sizeof(uint16_t); |
| 68 |
} |
| 69 |
|
| 70 |
buf = (const unsigned char *) buf2; |
| 71 |
if (len) { |
| 72 |
c = __crc32b(c, *buf); |
| 73 |
} |
| 74 |
|
| 75 |
c = ~c; |
| 76 |
return c; |
| 77 |
} |
| 78 |
#endif |