Lines Matching full:crc
1 /* crc32.c -- compute the CRC-32 of a data stream
5 * This interleaved implementation of a CRC makes use of pipelined multiple
7 * Kadatch and Jenkins (2010). See doc/crc-doc.1.0.pdf in this distribution.
15 of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
33 A CRC of a message is computed on N braids of words in the message, where
39 into a single CRC at the end. For this code, N must be in the range 1..6 and
136 * Table of powers of x for combining CRC-32s, filled in by make_crc_table()
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().
148 /* CRC polynomial. */
152 Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial,
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:
294 byte 0xb1 is the polynomial x^7+x^3+x^2+1), then the CRC is (q*x^32) mod p,
305 The table is simply the CRC of all possible eight bit values. This is all the
307 combinations of CRC register values and incoming bytes.
314 /* initialize the CRC of bytes tables */ in make_crc_table()
355 /* write out little-endian CRC table to crc32.h */ in make_crc_table()
357 "/* crc32.h -- tables for rapid CRC calculation\n" in make_crc_table()
366 /* write out big-endian CRC table for 64-bit z_word_t to crc32.h */ in make_crc_table()
379 /* write out big-endian CRC table for 32-bit z_word_t to crc32.h */ in make_crc_table()
547 * generation of the CRC tables in a threaded application.
557 * Use ARM machine instructions if available. This will compute the CRC about
559 * the presence of the CRC instruction at run time. __ARM_FEATURE_CRC32 will
562 * -march=armv8-a+crc, or -march=native if the compile machine has the crc32
575 unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, in crc32_z() argument
584 /* Return initial CRC, if requested. */ in crc32_z()
591 /* Pre-condition the CRC */ in crc32_z()
592 crc = (~crc) & 0xffffffff; in crc32_z()
594 /* Compute the CRC up to a word boundary. */ in crc32_z()
598 __asm__ volatile("crc32b %w0, %w0, %w1" : "+r"(crc) : "r"(val)); in crc32_z()
601 /* Prepare to compute the CRC on full 64-bit words word[0..num-1]. */ in crc32_z()
607 instruction per cycle. Each CRC is calculated on Z_BATCH words. The in crc32_z()
608 three CRCs are combined into a single CRC after each set of batches. */ in crc32_z()
616 __asm__ volatile("crc32x %w0, %w0, %x1" : "+r"(crc) : "r"(val0)); in crc32_z()
622 crc = multmodp(Z_BATCH_ZEROS, crc) ^ crc1; in crc32_z()
623 crc = multmodp(Z_BATCH_ZEROS, crc) ^ crc2; in crc32_z()
637 __asm__ volatile("crc32x %w0, %w0, %x1" : "+r"(crc) : "r"(val0)); in crc32_z()
644 crc = multmodp(val, crc) ^ crc1; in crc32_z()
645 crc = multmodp(val, crc) ^ crc2; in crc32_z()
648 /* Compute the CRC on any remaining words. */ in crc32_z()
651 __asm__ volatile("crc32x %w0, %w0, %x1" : "+r"(crc) : "r"(val0)); in crc32_z()
655 /* Complete the CRC on any remaining bytes. */ in crc32_z()
660 __asm__ volatile("crc32b %w0, %w0, %w1" : "+r"(crc) : "r"(val)); in crc32_z()
663 /* Return the CRC, post-conditioned. */ in crc32_z()
664 return crc ^ 0xffffffff; in crc32_z()
672 Return the CRC of the W bytes in the word_t data, taking the
694 unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, in crc32_z() argument
696 /* Return initial CRC, if requested. */ in crc32_z()
703 /* Pre-condition the CRC */ in crc32_z()
704 crc = (~crc) & 0xffffffff; in crc32_z()
708 /* If provided enough bytes, do a braided CRC calculation. */ in crc32_z()
715 /* Compute the CRC up to a z_word_t boundary. */ in crc32_z()
718 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff]; in crc32_z()
721 /* Compute the CRC on as many N z_word_t blocks as are available. */ in crc32_z()
757 /* Initialize the CRC for each braid. */ in crc32_z()
758 crc0 = crc; in crc32_z()
799 /* Compute and update the CRC for each word. The loop should in crc32_z()
841 crc = crc_word(crc0 ^ words[0]); in crc32_z()
843 crc = crc_word(crc1 ^ words[1] ^ crc); in crc32_z()
845 crc = crc_word(crc2 ^ words[2] ^ crc); in crc32_z()
847 crc = crc_word(crc3 ^ words[3] ^ crc); in crc32_z()
849 crc = crc_word(crc4 ^ words[4] ^ crc); in crc32_z()
851 crc = crc_word(crc5 ^ words[5] ^ crc); in crc32_z()
879 /* Initialize the CRC for each braid. */ in crc32_z()
880 crc0 = byte_swap(crc); in crc32_z()
921 /* Compute and update the CRC for each word. The loop should in crc32_z()
980 crc = byte_swap(comb); in crc32_z()
991 /* Complete the computation of the CRC on any remaining bytes. */ in crc32_z()
994 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff]; in crc32_z()
995 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff]; in crc32_z()
996 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff]; in crc32_z()
997 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff]; in crc32_z()
998 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff]; in crc32_z()
999 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff]; in crc32_z()
1000 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff]; in crc32_z()
1001 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff]; in crc32_z()
1005 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff]; in crc32_z()
1008 /* Return the CRC, post-conditioned. */ in crc32_z()
1009 return crc ^ 0xffffffff; in crc32_z()
1015 unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, in crc32() argument
1017 return crc32_z(crc, buf, len); in crc32()