Z_REGISTER uint32_t c;
Z_REGISTER const uint16_t *buf2;
Z_REGISTER const uint32_t *buf4;
+ Z_REGISTER const uint64_t *buf8;
c = ~crc;
- if (len && ((ptrdiff_t)buf & 1)) {
- c = __crc32b(c, *buf++);
- len--;
- }
-
- if ((len >= sizeof(uint16_t)) && ((ptrdiff_t)buf & sizeof(uint16_t))) {
- buf2 = (const uint16_t *) buf;
- c = __crc32h(c, *buf2++);
- len -= sizeof(uint16_t);
- buf4 = (const uint32_t *) buf2;
- } else {
- buf4 = (const uint32_t *) buf;
- }
-#if defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC)
- if ((len >= sizeof(uint32_t)) && ((ptrdiff_t)buf & sizeof(uint32_t))) {
- c = __crc32w(c, *buf4++);
- len -= sizeof(uint32_t);
- }
-
- if (len == 0) {
+ if (UNLIKELY(len == 1)) {
+ c = __crc32b(c, *buf);
c = ~c;
return c;
}
- const uint64_t *buf8 = (const uint64_t *) buf4;
+ if ((ptrdiff_t)buf & (sizeof(uint64_t) - 1)) {
+ if (len && ((ptrdiff_t)buf & 1)) {
+ c = __crc32b(c, *buf++);
+ len--;
+ }
+
+ if ((len >= sizeof(uint16_t)) && ((ptrdiff_t)buf & sizeof(uint16_t))) {
+ buf2 = (const uint16_t *) buf;
+ c = __crc32h(c, *buf2++);
+ len -= sizeof(uint16_t);
+ buf4 = (const uint32_t *) buf2;
+ } else {
+ buf4 = (const uint32_t *) buf;
+ }
+
+ if ((len >= sizeof(uint32_t)) && ((ptrdiff_t)buf & sizeof(uint32_t))) {
+ c = __crc32w(c, *buf4++);
+ len -= sizeof(uint32_t);
+ }
+
+ buf8 = (const uint64_t *) buf4;
+ } else {
+ buf8 = (const uint64_t *) buf;
+ }
while (len >= sizeof(uint64_t)) {
c = __crc32d(c, *buf8++);
}
buf = (const unsigned char *) buf2;
-#else /* __aarch64__ */
-
- if (len == 0) {
- c = ~c;
- return c;
- }
-
- while (len >= sizeof(uint32_t)) {
- c = __crc32w(c, *buf4++);
- len -= sizeof(uint32_t);
- }
-
- if (len >= sizeof(uint16_t)) {
- buf2 = (const uint16_t *) buf4;
- c = __crc32h(c, *buf2++);
- len -= sizeof(uint16_t);
- buf = (const unsigned char *) buf2;
- } else {
- buf = (const unsigned char *) buf4;
- }
-#endif /* __aarch64__ */
-
if (len) {
c = __crc32b(c, *buf);
}