Lines Matching +full:32 +full:k

1 /* crc32.c -- compute the CRC-32 of a data stream
64 z_crc_t must be at least 32 bits. z_word_t must be at least as long as
65 z_crc_t. It is assumed here that z_word_t is either 32 bits or 64 bits, and
110 instruction, if one is available. This assumes that word_t is either 32 bits
136 * Table of powers of x for combining CRC-32s, filled in by make_crc_table()
139 local z_crc_t FAR x2n_table[32];
142 * Tables for byte-wise and braided CRC-32 calculations, and a table of powers
143 * of x for combining CRC-32s, all made by make_crc_table().
149 #define POLY 0xedb88320 /* p(x) reflected, with x^32 implied */
173 Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been
176 local z_crc_t x2nmodp(z_off64_t n, unsigned k) { in x2nmodp() argument
182 p = multmodp(x2n_table[k & 31], p); in x2nmodp()
184 k++; in x2nmodp()
191 * Build the tables for byte-wise and braided CRC-32 calculations, and a table
192 * of powers of x for combining CRC-32s.
286 Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
287 x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
294 byte 0xb1 is the polynomial x^7+x^3+x^2+1), then the CRC is (q*x^32) mod p,
299 incoming bit, x^32 is added mod p to the register if the bit is a one (where
300 x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by x
301 (which is shifting right by one and adding x^32 mod p if the bit shifted out
328 for (n = 1; n < 32; n++) in make_crc_table()
339 The crc32.h header file contains tables for both 32-bit and 64-bit in make_crc_table()
342 and writes out the tables for the case that z_word_t is 32 bits. in make_crc_table()
348 int k, n; in make_crc_table() local
379 /* write out big-endian CRC table for 32-bit z_word_t to crc32.h */ in make_crc_table()
407 for (k = 0; k < 8; k++) { in make_crc_table()
409 write_table(out, ltl[k], 256); in make_crc_table()
410 fprintf(out, "}%s", k < 7 ? ",\n" : ""); in make_crc_table()
416 for (k = 0; k < 8; k++) { in make_crc_table()
418 write_table64(out, big[k], 256); in make_crc_table()
419 fprintf(out, "}%s", k < 7 ? ",\n" : ""); in make_crc_table()
424 /* compute braid tables for this N and 32-bit word_t */ in make_crc_table()
427 /* write out braid tables for 32-bit z_word_t to crc32.h */ in make_crc_table()
433 for (k = 0; k < 4; k++) { in make_crc_table()
435 write_table(out, ltl[k], 256); in make_crc_table()
436 fprintf(out, "}%s", k < 3 ? ",\n" : ""); in make_crc_table()
442 for (k = 0; k < 4; k++) { in make_crc_table()
444 write_table32hi(out, big[k], 256); in make_crc_table()
445 fprintf(out, "}%s", k < 3 ? ",\n" : ""); in make_crc_table()
463 write_table(out, x2n_table, 32); in make_crc_table()
474 Write the 32-bit values in table[0..k-1] to out, five per line in
477 local void write_table(FILE *out, const z_crc_t FAR *table, int k) { in write_table() argument
480 for (n = 0; n < k; n++) in write_table()
483 n == k - 1 ? "" : (n % 5 == 4 ? ",\n" : ", ")); in write_table()
487 Write the high 32-bits of each value in table[0..k-1] to out, five per line
490 local void write_table32hi(FILE *out, const z_word_t FAR *table, int k) { in write_table32hi() argument
493 for (n = 0; n < k; n++) in write_table32hi()
495 (unsigned long)(table[n] >> 32), in write_table32hi()
496 n == k - 1 ? "" : (n % 5 == 4 ? ",\n" : ", ")); in write_table32hi()
500 Write the 64-bit values in table[0..k-1] to out, three per line in
506 local void write_table64(FILE *out, const z_word_t FAR *table, int k) { in write_table64() argument
509 for (n = 0; n < k; n++) in write_table64()
512 n == k - 1 ? "" : (n % 3 == 2 ? ",\n" : ", ")); in write_table64()
529 int k; in braid() local
531 for (k = 0; k < w; k++) { in braid()
532 p = x2nmodp((n * w + 3 - k) << 3, 0); in braid()
533 ltl[k][0] = 0; in braid()
534 big[w - 1 - k][0] = 0; in braid()
536 ltl[k][i] = q = multmodp(i << 24, p); in braid()
537 big[w - 1 - k][i] = byte_swap(q); in braid()
677 int k; in crc_word() local
678 for (k = 0; k < W; k++) in crc_word()
684 int k; in crc_word_big() local
685 for (k = 0; k < W; k++) in crc_word_big()
713 int k; in crc32_z() local
817 for (k = 1; k < W; k++) { in crc32_z()
818 crc0 ^= crc_braid_table[k][(word0 >> (k << 3)) & 0xff]; in crc32_z()
820 crc1 ^= crc_braid_table[k][(word1 >> (k << 3)) & 0xff]; in crc32_z()
822 crc2 ^= crc_braid_table[k][(word2 >> (k << 3)) & 0xff]; in crc32_z()
824 crc3 ^= crc_braid_table[k][(word3 >> (k << 3)) & 0xff]; in crc32_z()
826 crc4 ^= crc_braid_table[k][(word4 >> (k << 3)) & 0xff]; in crc32_z()
828 crc5 ^= crc_braid_table[k][(word5 >> (k << 3)) & 0xff]; in crc32_z()
939 for (k = 1; k < W; k++) { in crc32_z()
940 crc0 ^= crc_braid_big_table[k][(word0 >> (k << 3)) & 0xff]; in crc32_z()
942 crc1 ^= crc_braid_big_table[k][(word1 >> (k << 3)) & 0xff]; in crc32_z()
944 crc2 ^= crc_braid_big_table[k][(word2 >> (k << 3)) & 0xff]; in crc32_z()
946 crc3 ^= crc_braid_big_table[k][(word3 >> (k << 3)) & 0xff]; in crc32_z()
948 crc4 ^= crc_braid_big_table[k][(word4 >> (k << 3)) & 0xff]; in crc32_z()
950 crc5 ^= crc_braid_big_table[k][(word5 >> (k << 3)) & 0xff]; in crc32_z()