Commit 090cc60 for zlib
commit 090cc609e9f898ffe6244636368d570470551df6
Author: Mark Adler <git@madler.net>
Date: Sun Nov 15 21:09:24 2026 -0800
Tune the choice of crc32 braids to the register size and length.
After careful cycle counting on many processors, it was found that
four-byte words should be used for braiding in all cases. It was
further determined that on 32-bit register machines, two braids
should be used. On 64-bit register machines, five braids should be
used unless the length of the data is less than 320 bytes, in which
case two braids should be used. That is what is now implemented.
There are defines that permit building with four or eight-byte
words, where the latter is still supported in the code and tables,
and that permit two values for the number of braids and the length
cutoff between them. This permits finer tuning to a particular
processor. Your mileage may vary.
The testing was done over x86-64 AMD and Intel processors, ARM and
Apple aarch64 and 32-bit ARM, POWER10, and SPARC, using gcc, clang,
and MSVC compilers.
diff --git a/crc32.c b/crc32.c
index 19a2f3e..8daf6bf 100644
--- a/crc32.c
+++ b/crc32.c
@@ -49,23 +49,136 @@
crc32.h would need to be regenerated, if the maximum N value is increased.
N and W are chosen empirically by benchmarking the execution time on a given
- processor. The choices for N and W below were based on testing on Intel Kaby
- Lake i7, AMD Ryzen 7, ARM Cortex-A57, Sparc64-VII, PowerPC POWER9, and MIPS64
- Octeon II processors. The Intel, AMD, and ARM processors were all fastest
- with N=5, W=8. The Sparc, PowerPC, and MIPS64 were all fastest at N=5, W=4.
- They were all tested with either gcc or clang, all using the -O3 optimization
- level. Your mileage may vary.
+ processor. The choices below were based on testing on Intel Haswell, AMD Zen
+ 4, Apple M1, ARM Cortex-A76, another ARM64 server, IBM POWER10, UltraSPARC
+ T5, LoongArch64, and ARM Cortex-A7 (32-bit) processors, with gcc and clang,
+ and MSVC and clang-cl on Windows, at -O2 and -O3. W=4 was faster than W=8 on
+ all of them for lengths up to 1K, and as fast or nearly so on most of them
+ for long lengths. With 64-bit registers (see Z_REG64 in zutil.h), N=5 was the
+ fastest, or within 10% of the fastest, for lengths of 1K and more. For
+ lengths less than about 320 bytes, N=2 was faster, due to the cost of
+ combining the N braids at the end. So both are used, divided at BRAID_CUT.
+ With 32-bit registers on the Cortex-A7, more than two braids ran out of
+ registers, and N=2 was the fastest at all lengths. Your mileage may vary.
*/
-/* Define N */
+/*
+ These can be defined when compiling, to change the calculation:
+
+ Z_REG64 Use the choices for 64-bit registers below. zutil.h
+ defines Z_REG64 when the architecture has 64-bit general
+ registers, unless Z_REG32 is defined. It requires an
+ eight-byte unsigned integer type, Z_U8.
+ Z_REG32 Use the choices for 32-bit registers below, even if the
+ architecture has 64-bit registers. Z_REG64 and Z_REG32
+ cannot both be defined.
+ Z_TESTW=w Use words of w bytes, 4 or 8, for the braids, in place of
+ DEF_W. 8 requires Z_U8, and 4 is used without it. If w is
+ 0 or empty (-DZ_TESTW=), then the braided calculation is
+ not compiled, and the CRC is computed a byte at a time.
+ Any other value is taken as 4.
+ Z_TESTN=n Use n braids, 1..6, in place of DEF_N. If Z_TESTCUT is not
+ defined, then n braids are used at all lengths.
+ Z_TESTCUT=len Use Z_TESTNLOW braids for lengths less than len, and N
+ braids for lengths of len or more, in place of DEF_CUT and
+ DEF_NLOW. Z_TESTCUT and Z_TESTNLOW must be defined
+ together.
+ Z_TESTNLOW=n The number of braids, 1..6, for lengths less than
+ Z_TESTCUT. It may be more or less than N.
+ DYNAMIC_CRC_TABLE
+ Compute the tables at run time, instead of using those in
+ crc32.h. Only the braid tables for N and NLOW are made.
+ MAKECRCH Compile a program that writes crc32.h, with the braid
+ tables for N from 1 to 6, for both word sizes, and for
+ both little and big-endian. It requires Z_U8.
+ Z_U4, Z_U8 The four and eight-byte unsigned integer types, if they are
+ not found by zconf.h and zutil.h. Without Z_U4, the CRC is
+ computed a byte at a time. Without Z_U8, Z_REG64 is not
+ defined, and W is 4.
+
+ These are defined by the compiler or the build, and also change the
+ calculation:
+
+ __ARM_FEATURE_CRC32
+ On 64-bit ARM, use the CRC32 instructions instead of the
+ braided calculation. The compiler defines this when the
+ target architecture has them, e.g. with
+ -march=armv8-a+crc, -march=armv8.1-a, or -march=native on
+ a machine that has them.
+ HAVE_S390X_VX On s390x, crc32() uses the vector instruction code in
+ contrib/crc32vx.
+ */
+
+/*
+ The default choices, used unless overridden by the defines above:
+
+ DEF_W The size in bytes of the words that the braids are computed
+ on, 4 or 8.
+ DEF_N The number of braids, 1..6, for lengths of DEF_CUT or more, or
+ for all lengths if there is no cutoff.
+ DEF_CUT The length below which DEF_NLOW braids are used instead of
+ DEF_N. If it is empty or zero, then there is no cutoff, and
+ DEF_N braids are used at all lengths.
+ DEF_NLOW The number of braids, 1..6, for lengths less than DEF_CUT. It
+ must be set if DEF_CUT is set. If it is equal to DEF_N, then
+ there is no cutoff.
+ */
+#ifdef Z_REG64
+# define DEF_W 4
+# define DEF_N 5
+# define DEF_CUT 320
+# define DEF_NLOW 2
+#else
+# define DEF_W 4
+# define DEF_N 2
+# define DEF_CUT
+# define DEF_NLOW
+#endif
+
+/*
+ Define N, and if there is a cutoff, BRAID_CUT and NLOW, from the defaults,
+ or from Z_TESTN, Z_TESTCUT, and Z_TESTNLOW. If there is no cutoff, then NLOW
+ is N.
+ */
#ifdef Z_TESTN
# define N Z_TESTN
#else
-# define N 5
+# define N DEF_N
+#endif
+#if defined(Z_TESTCUT) != defined(Z_TESTNLOW)
+# error Z_TESTCUT and Z_TESTNLOW must be set together
+#endif
+#ifdef Z_TESTCUT
+# define BRAID_CUT Z_TESTCUT
+# define NLOW Z_TESTNLOW
+#elif !defined(Z_TESTN) && DEF_CUT-1 != -1
+# if DEF_NLOW-1 == -1
+# error DEF_NLOW must be set when DEF_CUT is
+# define NLOW N
+# elif DEF_NLOW != DEF_N
+# define BRAID_CUT DEF_CUT
+# define NLOW DEF_NLOW
+# else
+# define NLOW N
+# endif
+#else
+# define NLOW N
#endif
-#if N < 1 || N > 6
-# error N must be in 1..6
+#if N < 1 || N > 6 || NLOW < 1 || NLOW > 6
+# error N and NLOW must be in 1..6
#endif
+#if NLOW < N
+# define NMIN NLOW /* the fewest braids used */
+#else
+# define NMIN N
+#endif
+
+/* The names of the braid tables for n braids, in crc32.h or made by
+ make_crc_table(). */
+#define BRAID_TABLE_(n) crc_braid##n##_table
+#define BRAID_TABLE(n) BRAID_TABLE_(n)
+#define BRAID_BIG_TABLE_(n) crc_braid##n##_big_table
+#define BRAID_BIG_TABLE(n) BRAID_BIG_TABLE_(n)
/*
z_crc_t must be at least 32 bits. z_word_t must be at least as long as
@@ -86,11 +199,7 @@
# ifdef MAKECRCH
# define W 8 /* required for MAKECRCH */
# else
-# if defined(__x86_64__) || defined(__aarch64__)
-# define W 8
-# else
-# define W 4
-# endif
+# define W DEF_W
# endif
#endif
#ifdef W
@@ -202,8 +311,12 @@ local uLong x2nmodp(z_off64_t n, unsigned k) {
local z_crc_t FAR crc_table[256];
#ifdef W
local z_word_t FAR crc_big_table[256];
- local z_crc_t FAR crc_braid_table[W][256];
- local z_word_t FAR crc_braid_big_table[W][256];
+ local z_crc_t FAR BRAID_TABLE(N)[W][256];
+ local z_word_t FAR BRAID_BIG_TABLE(N)[W][256];
+# if NLOW != N
+ local z_crc_t FAR BRAID_TABLE(NLOW)[W][256];
+ local z_word_t FAR BRAID_BIG_TABLE(NLOW)[W][256];
+# endif
local void braid(z_crc_t [][256], z_word_t [][256], int, int);
#endif
#ifdef MAKECRCH
@@ -263,7 +376,10 @@ local void make_crc_table(void) {
#ifdef W
/* initialize the braiding tables -- needs x2n_table[] */
- braid(crc_braid_table, crc_braid_big_table, N, W);
+ braid(BRAID_TABLE(N), BRAID_BIG_TABLE(N), N, W);
+# if NLOW != N
+ braid(BRAID_TABLE(NLOW), BRAID_BIG_TABLE(NLOW), NLOW, W);
+# endif
#endif
#ifdef MAKECRCH
@@ -322,11 +438,11 @@ local void make_crc_table(void) {
"\n"
"#endif\n");
- /* write out braid tables for each value of N */
+ /* write out braid tables for each value of N, and of NLOW */
for (n = 1; n <= 6; n++) {
fprintf(out,
"\n"
- "#if N == %d\n", n);
+ "#if N == %d || NLOW == %d\n", n, n);
/* compute braid tables for this N and 64-bit word_t */
braid(ltl, big, n, 8);
@@ -336,7 +452,7 @@ local void make_crc_table(void) {
"\n"
"#if W == 8\n"
"\n"
- "local const z_crc_t FAR crc_braid_table[][256] = {\n");
+ "local const z_crc_t FAR crc_braid%d_table[][256] = {\n", n);
for (k = 0; k < 8; k++) {
fprintf(out, " {");
write_table(out, ltl[k], 256);
@@ -345,7 +461,7 @@ local void make_crc_table(void) {
fprintf(out,
"};\n"
"\n"
- "local const z_word_t FAR crc_braid_big_table[][256] = {\n");
+ "local const z_word_t FAR crc_braid%d_big_table[][256] = {\n", n);
for (k = 0; k < 8; k++) {
fprintf(out, " {");
write_table64(out, big[k], 256);
@@ -362,7 +478,7 @@ local void make_crc_table(void) {
"\n"
"#else /* W == 4 */\n"
"\n"
- "local const z_crc_t FAR crc_braid_table[][256] = {\n");
+ "local const z_crc_t FAR crc_braid%d_table[][256] = {\n", n);
for (k = 0; k < 4; k++) {
fprintf(out, " {");
write_table(out, ltl[k], 256);
@@ -371,7 +487,7 @@ local void make_crc_table(void) {
fprintf(out,
"};\n"
"\n"
- "local const z_word_t FAR crc_braid_big_table[][256] = {\n");
+ "local const z_word_t FAR crc_braid%d_big_table[][256] = {\n", n);
for (k = 0; k < 4; k++) {
fprintf(out, " {");
write_table32hi(out, big[k], 256);
@@ -638,6 +754,281 @@ local z_word_t crc_word_big(z_word_t data) {
(CRCB(t, w, 2) ^ CRCB(t, w, 3)))
#endif
+#ifdef BRAID_CUT
+/*
+ Return the CRC of buf[0..len-1] starting with crc, computed on NLOW braids.
+ crc is pre-conditioned, and the result is not post-conditioned. crc32_z()
+ uses this for lengths less than BRAID_CUT, and N braids for longer lengths.
+ The N braids are in crc32_z() itself, since compiled there, clang does not
+ spill a braid's CRC to the stack in the loop on x86-64 for N=5, as it did
+ when the N braids were here. A compiler can be expected to inline this, so
+ that short lengths do not incur a function call.
+ */
+local uLong crc32_braid(uLong crc, const unsigned char FAR *buf,
+ z_size_t len) {
+ /* If provided enough bytes, do a braided CRC calculation. */
+ if (len >= NLOW * W + W - 1) {
+ z_size_t blks;
+ z_word_t const *words;
+ unsigned endian;
+
+ /* Compute the CRC up to a z_word_t boundary. */
+ while (len && ((z_size_t)buf & (W - 1)) != 0) {
+ len--;
+ crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
+ }
+
+ /* Compute the CRC on as many NLOW z_word_t blocks as are available. */
+ blks = len / (NLOW * W);
+ len -= blks * NLOW * W;
+ words = (z_word_t const *)buf;
+
+ /* Do endian check at execution time instead of compile time, since ARM
+ processors can change the endianness at execution time. If the
+ compiler knows what the endianness will be, it can optimize out the
+ check and the unused branch. */
+ endian = 1;
+ if (*(unsigned char *)&endian) {
+ /* Little endian. */
+
+ z_crc_t crc0;
+ z_word_t word0;
+#if NLOW > 1
+ z_crc_t crc1;
+ z_word_t word1;
+#if NLOW > 2
+ z_crc_t crc2;
+ z_word_t word2;
+#if NLOW > 3
+ z_crc_t crc3;
+ z_word_t word3;
+#if NLOW > 4
+ z_crc_t crc4;
+ z_word_t word4;
+#if NLOW > 5
+ z_crc_t crc5;
+ z_word_t word5;
+#endif
+#endif
+#endif
+#endif
+#endif
+
+ /* Initialize the CRC for each braid. */
+ crc0 = (z_crc_t)crc;
+#if NLOW > 1
+ crc1 = 0;
+#if NLOW > 2
+ crc2 = 0;
+#if NLOW > 3
+ crc3 = 0;
+#if NLOW > 4
+ crc4 = 0;
+#if NLOW > 5
+ crc5 = 0;
+#endif
+#endif
+#endif
+#endif
+#endif
+
+ /*
+ Process the first blks-1 blocks, computing the CRCs on each braid
+ independently.
+ */
+ while (--blks) {
+ /* Load the word for each braid into registers. */
+ word0 = crc0 ^ words[0];
+#if NLOW > 1
+ word1 = crc1 ^ words[1];
+#if NLOW > 2
+ word2 = crc2 ^ words[2];
+#if NLOW > 3
+ word3 = crc3 ^ words[3];
+#if NLOW > 4
+ word4 = crc4 ^ words[4];
+#if NLOW > 5
+ word5 = crc5 ^ words[5];
+#endif
+#endif
+#endif
+#endif
+#endif
+ words += NLOW;
+
+ /* Compute and update the CRC for each word. */
+ crc0 = CRCWORD(BRAID_TABLE(NLOW), word0);
+#if NLOW > 1
+ crc1 = CRCWORD(BRAID_TABLE(NLOW), word1);
+#if NLOW > 2
+ crc2 = CRCWORD(BRAID_TABLE(NLOW), word2);
+#if NLOW > 3
+ crc3 = CRCWORD(BRAID_TABLE(NLOW), word3);
+#if NLOW > 4
+ crc4 = CRCWORD(BRAID_TABLE(NLOW), word4);
+#if NLOW > 5
+ crc5 = CRCWORD(BRAID_TABLE(NLOW), word5);
+#endif
+#endif
+#endif
+#endif
+#endif
+ }
+
+ /*
+ Process the last block, combining the CRCs of the NLOW braids at
+ the same time.
+ */
+ crc = crc_word(crc0 ^ words[0]);
+#if NLOW > 1
+ crc = crc_word(crc1 ^ words[1] ^ crc);
+#if NLOW > 2
+ crc = crc_word(crc2 ^ words[2] ^ crc);
+#if NLOW > 3
+ crc = crc_word(crc3 ^ words[3] ^ crc);
+#if NLOW > 4
+ crc = crc_word(crc4 ^ words[4] ^ crc);
+#if NLOW > 5
+ crc = crc_word(crc5 ^ words[5] ^ crc);
+#endif
+#endif
+#endif
+#endif
+#endif
+ words += NLOW;
+ }
+ else {
+ /* Big endian. */
+
+ z_word_t crc0, word0, comb;
+#if NLOW > 1
+ z_word_t crc1, word1;
+#if NLOW > 2
+ z_word_t crc2, word2;
+#if NLOW > 3
+ z_word_t crc3, word3;
+#if NLOW > 4
+ z_word_t crc4, word4;
+#if NLOW > 5
+ z_word_t crc5, word5;
+#endif
+#endif
+#endif
+#endif
+#endif
+
+ /* Initialize the CRC for each braid. */
+ crc0 = byte_swap(crc);
+#if NLOW > 1
+ crc1 = 0;
+#if NLOW > 2
+ crc2 = 0;
+#if NLOW > 3
+ crc3 = 0;
+#if NLOW > 4
+ crc4 = 0;
+#if NLOW > 5
+ crc5 = 0;
+#endif
+#endif
+#endif
+#endif
+#endif
+
+ /*
+ Process the first blks-1 blocks, computing the CRCs on each braid
+ independently.
+ */
+ while (--blks) {
+ /* Load the word for each braid into registers. */
+ word0 = crc0 ^ words[0];
+#if NLOW > 1
+ word1 = crc1 ^ words[1];
+#if NLOW > 2
+ word2 = crc2 ^ words[2];
+#if NLOW > 3
+ word3 = crc3 ^ words[3];
+#if NLOW > 4
+ word4 = crc4 ^ words[4];
+#if NLOW > 5
+ word5 = crc5 ^ words[5];
+#endif
+#endif
+#endif
+#endif
+#endif
+ words += NLOW;
+
+ /* Compute and update the CRC for each word. */
+ crc0 = CRCWORD(BRAID_BIG_TABLE(NLOW), word0);
+#if NLOW > 1
+ crc1 = CRCWORD(BRAID_BIG_TABLE(NLOW), word1);
+#if NLOW > 2
+ crc2 = CRCWORD(BRAID_BIG_TABLE(NLOW), word2);
+#if NLOW > 3
+ crc3 = CRCWORD(BRAID_BIG_TABLE(NLOW), word3);
+#if NLOW > 4
+ crc4 = CRCWORD(BRAID_BIG_TABLE(NLOW), word4);
+#if NLOW > 5
+ crc5 = CRCWORD(BRAID_BIG_TABLE(NLOW), word5);
+#endif
+#endif
+#endif
+#endif
+#endif
+ }
+
+ /*
+ Process the last block, combining the CRCs of the NLOW braids at
+ the same time.
+ */
+ comb = crc_word_big(crc0 ^ words[0]);
+#if NLOW > 1
+ comb = crc_word_big(crc1 ^ words[1] ^ comb);
+#if NLOW > 2
+ comb = crc_word_big(crc2 ^ words[2] ^ comb);
+#if NLOW > 3
+ comb = crc_word_big(crc3 ^ words[3] ^ comb);
+#if NLOW > 4
+ comb = crc_word_big(crc4 ^ words[4] ^ comb);
+#if NLOW > 5
+ comb = crc_word_big(crc5 ^ words[5] ^ comb);
+#endif
+#endif
+#endif
+#endif
+#endif
+ words += NLOW;
+ crc = byte_swap(comb);
+ }
+
+ /*
+ Update the pointer to the remaining bytes to process.
+ */
+ buf = (unsigned char const *)words;
+ }
+
+ /* Complete the computation of the CRC on any remaining bytes. */
+ while (len >= 8) {
+ len -= 8;
+ crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
+ crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
+ crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
+ crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
+ crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
+ crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
+ crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
+ crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
+ }
+ while (len) {
+ len--;
+ crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
+ }
+
+ return crc;
+}
+#endif
+
#endif
/* ========================================================================= */
@@ -655,11 +1046,17 @@ uLong ZEXPORT crc32_z(uLong crc, const unsigned char FAR *buf, z_size_t len) {
#ifdef W
/* If provided enough bytes, do a braided CRC calculation. */
- if (len >= N * W + W - 1) {
+ if (len >= NMIN * W + W - 1) {
z_size_t blks;
z_word_t const *words;
unsigned endian;
+#ifdef BRAID_CUT
+ /* For shorter lengths, use NLOW braids. */
+ if (len < BRAID_CUT || len < N * W + W - 1)
+ return crc32_braid(crc, buf, len) ^ 0xffffffff;
+#endif
+
/* Compute the CRC up to a z_word_t boundary. */
while (len && ((z_size_t)buf & (W - 1)) != 0) {
len--;
@@ -745,17 +1142,17 @@ uLong ZEXPORT crc32_z(uLong crc, const unsigned char FAR *buf, z_size_t len) {
words += N;
/* Compute and update the CRC for each word. */
- crc0 = CRCWORD(crc_braid_table, word0);
+ crc0 = CRCWORD(BRAID_TABLE(N), word0);
#if N > 1
- crc1 = CRCWORD(crc_braid_table, word1);
+ crc1 = CRCWORD(BRAID_TABLE(N), word1);
#if N > 2
- crc2 = CRCWORD(crc_braid_table, word2);
+ crc2 = CRCWORD(BRAID_TABLE(N), word2);
#if N > 3
- crc3 = CRCWORD(crc_braid_table, word3);
+ crc3 = CRCWORD(BRAID_TABLE(N), word3);
#if N > 4
- crc4 = CRCWORD(crc_braid_table, word4);
+ crc4 = CRCWORD(BRAID_TABLE(N), word4);
#if N > 5
- crc5 = CRCWORD(crc_braid_table, word5);
+ crc5 = CRCWORD(BRAID_TABLE(N), word5);
#endif
#endif
#endif
@@ -848,17 +1245,17 @@ uLong ZEXPORT crc32_z(uLong crc, const unsigned char FAR *buf, z_size_t len) {
words += N;
/* Compute and update the CRC for each word. */
- crc0 = CRCWORD(crc_braid_big_table, word0);
+ crc0 = CRCWORD(BRAID_BIG_TABLE(N), word0);
#if N > 1
- crc1 = CRCWORD(crc_braid_big_table, word1);
+ crc1 = CRCWORD(BRAID_BIG_TABLE(N), word1);
#if N > 2
- crc2 = CRCWORD(crc_braid_big_table, word2);
+ crc2 = CRCWORD(BRAID_BIG_TABLE(N), word2);
#if N > 3
- crc3 = CRCWORD(crc_braid_big_table, word3);
+ crc3 = CRCWORD(BRAID_BIG_TABLE(N), word3);
#if N > 4
- crc4 = CRCWORD(crc_braid_big_table, word4);
+ crc4 = CRCWORD(BRAID_BIG_TABLE(N), word4);
#if N > 5
- crc5 = CRCWORD(crc_braid_big_table, word5);
+ crc5 = CRCWORD(BRAID_BIG_TABLE(N), word5);
#endif
#endif
#endif
diff --git a/crc32.h b/crc32.h
index 137df68..67cd463 100644
--- a/crc32.h
+++ b/crc32.h
@@ -206,11 +206,11 @@ local const z_word_t FAR crc_big_table[] = {
#endif
-#if N == 1
+#if N == 1 || NLOW == 1
#if W == 8
-local const z_crc_t FAR crc_braid_table[][256] = {
+local const z_crc_t FAR crc_braid1_table[][256] = {
{0x00000000, 0xccaa009e, 0x4225077d, 0x8e8f07e3, 0x844a0efa,
0x48e00e64, 0xc66f0987, 0x0ac50919, 0xd3e51bb5, 0x1f4f1b2b,
0x91c01cc8, 0x5d6a1c56, 0x57af154f, 0x9b0515d1, 0x158a1232,
@@ -628,7 +628,7 @@ local const z_crc_t FAR crc_braid_table[][256] = {
0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
0x2d02ef8d}};
-local const z_word_t FAR crc_braid_big_table[][256] = {
+local const z_word_t FAR crc_braid1_big_table[][256] = {
{0x0000000000000000, 0x9630077700000000, 0x2c610eee00000000,
0xba51099900000000, 0x19c46d0700000000, 0x8ff46a7000000000,
0x35a563e900000000, 0xa395649e00000000, 0x3288db0e00000000,
@@ -1320,7 +1320,7 @@ local const z_word_t FAR crc_braid_big_table[][256] = {
#else /* W == 4 */
-local const z_crc_t FAR crc_braid_table[][256] = {
+local const z_crc_t FAR crc_braid1_table[][256] = {
{0x00000000, 0xb8bc6765, 0xaa09c88b, 0x12b5afee, 0x8f629757,
0x37def032, 0x256b5fdc, 0x9dd738b9, 0xc5b428ef, 0x7d084f8a,
0x6fbde064, 0xd7018701, 0x4ad6bfb8, 0xf26ad8dd, 0xe0df7733,
@@ -1530,7 +1530,7 @@ local const z_crc_t FAR crc_braid_table[][256] = {
0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
0x2d02ef8d}};
-local const z_word_t FAR crc_braid_big_table[][256] = {
+local const z_word_t FAR crc_braid1_big_table[][256] = {
{0x00000000, 0x96300777, 0x2c610eee, 0xba510999, 0x19c46d07,
0x8ff46a70, 0x35a563e9, 0xa395649e, 0x3288db0e, 0xa4b8dc79,
0x1ee9d5e0, 0x88d9d297, 0x2b4cb609, 0xbd7cb17e, 0x072db8e7,
@@ -1744,11 +1744,11 @@ local const z_word_t FAR crc_braid_big_table[][256] = {
#endif
-#if N == 2
+#if N == 2 || NLOW == 2
#if W == 8
-local const z_crc_t FAR crc_braid_table[][256] = {
+local const z_crc_t FAR crc_braid2_table[][256] = {
{0x00000000, 0xae689191, 0x87a02563, 0x29c8b4f2, 0xd4314c87,
0x7a59dd16, 0x539169e4, 0xfdf9f875, 0x73139f4f, 0xdd7b0ede,
0xf4b3ba2c, 0x5adb2bbd, 0xa722d3c8, 0x094a4259, 0x2082f6ab,
@@ -2166,7 +2166,7 @@ local const z_crc_t FAR crc_braid_table[][256] = {
0x03d84904, 0x14a35d47, 0x70c2308e, 0x67b924cd, 0x5e341808,
0x494f0c4b}};
-local const z_word_t FAR crc_braid_big_table[][256] = {
+local const z_word_t FAR crc_braid2_big_table[][256] = {
{0x0000000000000000, 0x43147b1700000000, 0x8628f62e00000000,
0xc53c8d3900000000, 0x0c51ec5d00000000, 0x4f45974a00000000,
0x8a791a7300000000, 0xc96d616400000000, 0x18a2d8bb00000000,
@@ -2858,7 +2858,7 @@ local const z_word_t FAR crc_braid_big_table[][256] = {
#else /* W == 4 */
-local const z_crc_t FAR crc_braid_table[][256] = {
+local const z_crc_t FAR crc_braid2_table[][256] = {
{0x00000000, 0xccaa009e, 0x4225077d, 0x8e8f07e3, 0x844a0efa,
0x48e00e64, 0xc66f0987, 0x0ac50919, 0xd3e51bb5, 0x1f4f1b2b,
0x91c01cc8, 0x5d6a1c56, 0x57af154f, 0x9b0515d1, 0x158a1232,
@@ -3068,7 +3068,7 @@ local const z_crc_t FAR crc_braid_table[][256] = {
0x028448fc, 0x3fe4614c, 0x8dc4bd5c, 0xb0a494ec, 0xf704ee3c,
0xca64c78c}};
-local const z_word_t FAR crc_braid_big_table[][256] = {
+local const z_word_t FAR crc_braid2_big_table[][256] = {
{0x00000000, 0xb029603d, 0x6053c07a, 0xd07aa047, 0xc0a680f5,
0x708fe0c8, 0xa0f5408f, 0x10dc20b2, 0xc14b7030, 0x7162100d,
0xa118b04a, 0x1131d077, 0x01edf0c5, 0xb1c490f8, 0x61be30bf,
@@ -3282,11 +3282,11 @@ local const z_word_t FAR crc_braid_big_table[][256] = {
#endif
-#if N == 3
+#if N == 3 || NLOW == 3
#if W == 8
-local const z_crc_t FAR crc_braid_table[][256] = {
+local const z_crc_t FAR crc_braid3_table[][256] = {
{0x00000000, 0x81256527, 0xd93bcc0f, 0x581ea928, 0x69069e5f,
0xe823fb78, 0xb03d5250, 0x31183777, 0xd20d3cbe, 0x53285999,
0x0b36f0b1, 0x8a139596, 0xbb0ba2e1, 0x3a2ec7c6, 0x62306eee,
@@ -3704,7 +3704,7 @@ local const z_crc_t FAR crc_braid_table[][256] = {
0xec14dac2, 0x6bb21181, 0x4b206dca, 0xcc86a689, 0x9f1cfd0d,
0x18ba364e}};
-local const z_word_t FAR crc_braid_big_table[][256] = {
+local const z_word_t FAR crc_braid3_big_table[][256] = {
{0x0000000000000000, 0x43cba68700000000, 0xc7903cd400000000,
0x845b9a5300000000, 0xcf27087300000000, 0x8cecaef400000000,
0x08b734a700000000, 0x4b7c922000000000, 0x9e4f10e600000000,
@@ -4396,7 +4396,7 @@ local const z_word_t FAR crc_braid_big_table[][256] = {
#else /* W == 4 */
-local const z_crc_t FAR crc_braid_table[][256] = {
+local const z_crc_t FAR crc_braid3_table[][256] = {
{0x00000000, 0x9ba54c6f, 0xec3b9e9f, 0x779ed2f0, 0x03063b7f,
0x98a37710, 0xef3da5e0, 0x7498e98f, 0x060c76fe, 0x9da93a91,
0xea37e861, 0x7192a40e, 0x050a4d81, 0x9eaf01ee, 0xe931d31e,
@@ -4606,7 +4606,7 @@ local const z_crc_t FAR crc_braid_table[][256] = {
0x03d84904, 0x14a35d47, 0x70c2308e, 0x67b924cd, 0x5e341808,
0x494f0c4b}};
-local const z_word_t FAR crc_braid_big_table[][256] = {
+local const z_word_t FAR crc_braid3_big_table[][256] = {
{0x00000000, 0x43147b17, 0x8628f62e, 0xc53c8d39, 0x0c51ec5d,
0x4f45974a, 0x8a791a73, 0xc96d6164, 0x18a2d8bb, 0x5bb6a3ac,
0x9e8a2e95, 0xdd9e5582, 0x14f334e6, 0x57e74ff1, 0x92dbc2c8,
@@ -4820,11 +4820,11 @@ local const z_word_t FAR crc_braid_big_table[][256] = {
#endif
-#if N == 4
+#if N == 4 || NLOW == 4
#if W == 8
-local const z_crc_t FAR crc_braid_table[][256] = {
+local const z_crc_t FAR crc_braid4_table[][256] = {
{0x00000000, 0xf1da05aa, 0x38c50d15, 0xc91f08bf, 0x718a1a2a,
0x80501f80, 0x494f173f, 0xb8951295, 0xe3143454, 0x12ce31fe,
0xdbd13941, 0x2a0b3ceb, 0x929e2e7e, 0x63442bd4, 0xaa5b236b,
@@ -5242,7 +5242,7 @@ local const z_crc_t FAR crc_braid_table[][256] = {
0x42537612, 0xe7d8e61c, 0x29881ab4, 0x8c038aba, 0xb9ee3ce9,
0x1c65ace7}};
-local const z_word_t FAR crc_braid_big_table[][256] = {
+local const z_word_t FAR crc_braid4_big_table[][256] = {
{0x0000000000000000, 0x0e908ba500000000, 0x5d26669000000000,
0x53b6ed3500000000, 0xfb4abdfb00000000, 0xf5da365e00000000,
0xa66cdb6b00000000, 0xa8fc50ce00000000, 0xb7930b2c00000000,
@@ -5934,7 +5934,7 @@ local const z_word_t FAR crc_braid_big_table[][256] = {
#else /* W == 4 */
-local const z_crc_t FAR crc_braid_table[][256] = {
+local const z_crc_t FAR crc_braid4_table[][256] = {
{0x00000000, 0xae689191, 0x87a02563, 0x29c8b4f2, 0xd4314c87,
0x7a59dd16, 0x539169e4, 0xfdf9f875, 0x73139f4f, 0xdd7b0ede,
0xf4b3ba2c, 0x5adb2bbd, 0xa722d3c8, 0x094a4259, 0x2082f6ab,
@@ -6144,7 +6144,7 @@ local const z_crc_t FAR crc_braid_table[][256] = {
0x20c13fb5, 0xfd57e630, 0x8024e068, 0x5db239ed, 0xe0785523,
0x3dee8ca6}};
-local const z_word_t FAR crc_braid_big_table[][256] = {
+local const z_word_t FAR crc_braid4_big_table[][256] = {
{0x00000000, 0x85d996dd, 0x4bb55c60, 0xce6ccabd, 0x966ab9c0,
0x13b32f1d, 0xdddfe5a0, 0x5806737d, 0x6dd3035a, 0xe80a9587,
0x26665f3a, 0xa3bfc9e7, 0xfbb9ba9a, 0x7e602c47, 0xb00ce6fa,
@@ -6358,11 +6358,11 @@ local const z_word_t FAR crc_braid_big_table[][256] = {
#endif
-#if N == 5
+#if N == 5 || NLOW == 5
#if W == 8
-local const z_crc_t FAR crc_braid_table[][256] = {
+local const z_crc_t FAR crc_braid5_table[][256] = {
{0x00000000, 0xaf449247, 0x85f822cf, 0x2abcb088, 0xd08143df,
0x7fc5d198, 0x55796110, 0xfa3df357, 0x7a7381ff, 0xd53713b8,
0xff8ba330, 0x50cf3177, 0xaaf2c220, 0x05b65067, 0x2f0ae0ef,
@@ -6780,7 +6780,7 @@ local const z_crc_t FAR crc_braid_table[][256] = {
0x190fa237, 0x2ffd32c4, 0xaf20c01d, 0x99d250ee, 0xc2c5e1fb,
0xf4377108}};
-local const z_word_t FAR crc_braid_big_table[][256] = {
+local const z_word_t FAR crc_braid5_big_table[][256] = {
{0x0000000000000000, 0xf390f23600000000, 0xe621e56d00000000,
0x15b1175b00000000, 0xcc43cadb00000000, 0x3fd338ed00000000,
0x2a622fb600000000, 0xd9f2dd8000000000, 0xd981e56c00000000,
@@ -7472,7 +7472,7 @@ local const z_word_t FAR crc_braid_big_table[][256] = {
#else /* W == 4 */
-local const z_crc_t FAR crc_braid_table[][256] = {
+local const z_crc_t FAR crc_braid5_table[][256] = {
{0x00000000, 0x65673b46, 0xcace768c, 0xafa94dca, 0x4eedeb59,
0x2b8ad01f, 0x84239dd5, 0xe144a693, 0x9ddbd6b2, 0xf8bcedf4,
0x5715a03e, 0x32729b78, 0xd3363deb, 0xb65106ad, 0x19f84b67,
@@ -7682,7 +7682,7 @@ local const z_crc_t FAR crc_braid_table[][256] = {
0xec14dac2, 0x6bb21181, 0x4b206dca, 0xcc86a689, 0x9f1cfd0d,
0x18ba364e}};
-local const z_word_t FAR crc_braid_big_table[][256] = {
+local const z_word_t FAR crc_braid5_big_table[][256] = {
{0x00000000, 0x43cba687, 0xc7903cd4, 0x845b9a53, 0xcf270873,
0x8cecaef4, 0x08b734a7, 0x4b7c9220, 0x9e4f10e6, 0xdd84b661,
0x59df2c32, 0x1a148ab5, 0x51681895, 0x12a3be12, 0x96f82441,
@@ -7896,11 +7896,11 @@ local const z_word_t FAR crc_braid_big_table[][256] = {
#endif
-#if N == 6
+#if N == 6 || NLOW == 6
#if W == 8
-local const z_crc_t FAR crc_braid_table[][256] = {
+local const z_crc_t FAR crc_braid6_table[][256] = {
{0x00000000, 0x3db1ecdc, 0x7b63d9b8, 0x46d23564, 0xf6c7b370,
0xcb765fac, 0x8da46ac8, 0xb0158614, 0x36fe60a1, 0x0b4f8c7d,
0x4d9db919, 0x702c55c5, 0xc039d3d1, 0xfd883f0d, 0xbb5a0a69,
@@ -8318,7 +8318,7 @@ local const z_crc_t FAR crc_braid_table[][256] = {
0xc39adf05, 0x2b8d4fa4, 0xde78b600, 0x366f26a1, 0xd5269103,
0x3d3101a2}};
-local const z_word_t FAR crc_braid_big_table[][256] = {
+local const z_word_t FAR crc_braid6_big_table[][256] = {
{0x0000000000000000, 0xa19017e800000000, 0x03275e0b00000000,
0xa2b749e300000000, 0x064ebc1600000000, 0xa7deabfe00000000,
0x0569e21d00000000, 0xa4f9f5f500000000, 0x0c9c782d00000000,
@@ -9010,7 +9010,7 @@ local const z_word_t FAR crc_braid_big_table[][256] = {
#else /* W == 4 */
-local const z_crc_t FAR crc_braid_table[][256] = {
+local const z_crc_t FAR crc_braid6_table[][256] = {
{0x00000000, 0x81256527, 0xd93bcc0f, 0x581ea928, 0x69069e5f,
0xe823fb78, 0xb03d5250, 0x31183777, 0xd20d3cbe, 0x53285999,
0x0b36f0b1, 0x8a139596, 0xbb0ba2e1, 0x3a2ec7c6, 0x62306eee,
@@ -9220,7 +9220,7 @@ local const z_crc_t FAR crc_braid_table[][256] = {
0xdb48ef6d, 0x44926cf3, 0x2d75eaab, 0xb2af6935, 0xc9b1ebd6,
0x566b6848}};
-local const z_word_t FAR crc_braid_big_table[][256] = {
+local const z_word_t FAR crc_braid6_big_table[][256] = {
{0x00000000, 0x9e83da9f, 0x7d01c4e4, 0xe3821e7b, 0xbb04f912,
0x2587238d, 0xc6053df6, 0x5886e769, 0x7609f225, 0xe88a28ba,
0x0b0836c1, 0x958bec5e, 0xcd0d0b37, 0x538ed1a8, 0xb00ccfd3,