Commit dca5f89 for zlib
commit dca5f89779b71dc6f51b711945219bebfc94d68e
Author: Mark Adler <git@madler.net>
Date: Sun Nov 22 21:35:53 2026 -0800
Unroll the ARM CRC-32 loop on the remaining words.
After the batches, and for all of a buffer shorter than 1392 bytes,
the words are now done four per loop, followed by up to three words
one at a time. This reduces the overhead cost of the loop, which
was significant on the Cortex-A72, and avoids a code alignment
issue on the Cortex-A76 that made the one-word loop randomly take
two cycles per word instead of one.
This is roughly 1.1 to 2 times faster for 128 bytes to 1.4 KB,
except on the Apple M1, where it is the same, and up to a third
slower for 8 to 24 bytes. This remedies the penalty noted in the
previous commit.
diff --git a/crc32.c b/crc32.c
index 26aa1f5..f42e165 100644
--- a/crc32.c
+++ b/crc32.c
@@ -1007,8 +1007,21 @@ local ARMCRC32_ATTR uLong crc32_arm(uLong crc, const unsigned char FAR *buf,
}
}
- /* Compute the CRC on any remaining words. */
- for (i = 0; i < num; i++) {
+ /* Compute the CRC on any remaining words, four at a time, and then one at
+ a time. The four-at-a-time loop reduces the loop overhead and avoids
+ a code alignment issue observed on one processor that would randomly
+ halve the speed of the single-word loop. */
+ for (i = 3; i < num; i += 4) {
+ val0 = word[i - 3];
+ val1 = word[i - 2];
+ val2 = word[i - 1];
+ CRC32W(crc, val0);
+ CRC32W(crc, val1);
+ CRC32W(crc, val2);
+ val0 = word[i];
+ CRC32W(crc, val0);
+ }
+ for (i -= 3; i < num; i++) {
val0 = word[i];
CRC32W(crc, val0);
}