pw_checksum#
Checksum calculation API
Stable C C++
The pw_checksum module provides functions for calculating checksums.
pw_checksum/crc8.h#
pw_checksum/crc16_ccitt.h#
pw_checksum/crc32.h#
Implementations#
Pigweed provides 3 different CRC32 implementations with different size and runtime tradeoffs. The below table summarizes the variants. For more detailed size information see the Size report below. Instructions counts were calculated by hand by analyzing the assembly. Clock Cycle counts were measured using pw_perf_test on a STM32F429I-DISC1 development board.
Variant |
Relative size (see Size Report below) |
Speed |
Lookup table size (entries) |
Instructions/byte (M33/-Os) |
Clock Cycles (123 char string) |
Clock Cycles (9 bytes) |
|---|---|---|---|---|---|---|
8 bits per iteration (default) |
large |
fastest |
256 |
8 |
1538 |
170 |
4 bits per iteration |
small |
fast |
16 |
13 |
2153 |
215 |
1 bit per iteration |
smallest |
slow |
0 |
43 |
7690 |
622 |
The default implementation provided by the APIs above can be selected through
Module Configuration Options. Additionally pw_checksum provides
variants of the C++ API to explicitly use each of the implementations. These
classes provide the same API as Crc32:
Crc32EightBitCrc32FourBitCrc32OneBit
Size report#
The CRC module currently optimizes for speed instead of binary size, by using pre-computed 256-entry tables to reduce the CPU cycles per byte CRC calculation.
Label |
Segment |
Delta |
||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CRC16 with 256-entry table |
FLASH
|
+560 |
||||||||||||||||||||||||
CRC32: 8 bits per iteration, 256-entry table |
FLASH
|
+1,088 |
||||||||||||||||||||||||
CRC32: 4 bit pers iteration, 16-entry table |
FLASH
|
+128 |
||||||||||||||||||||||||
CRC32: 1 bit per iteration, no table |
FLASH
|
+64 |
||||||||||||||||||||||||
Fletcher16 (illustrative only) |
FLASH
|
+104 |
Compatibility#
C
C++17
Dependencies#
Module Configuration Options#
The following configurations can be adjusted via compile-time configuration of this module, see the module documentation for more details.
-
PW_CHECKSUM_CRC32_DEFAULT_IMPL#
Selects which of the Implementations the default CRC32 APIs use. Set to one of the following values:
PW_CHECKSUM_CRC32_8BITSPW_CHECKSUM_CRC32_4BITSPW_CHECKSUM_CRC32_1BITS
Zephyr#
To enable pw_checksum for Zephyr add CONFIG_PIGWEED_CHECKSUM=y to the
project’s configuration.