pw_checksum#

Checksum calculation API

Stable C C++

The pw_checksum module provides functions for calculating checksums.

pw_checksum/crc8.h#

pw::checksum::Crc8

pw_checksum/crc16_ccitt.h#

pw::checksum::Crc16Ccitt

pw_checksum/crc32.h#

pw::checksum::Crc32

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:

  • Crc32EightBit

  • Crc32FourBit

  • Crc32OneBit

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

-4

pw::checksum::RunChecksum()

+8

vClearInterruptMaskFromISR

DEL

-4

pw::checksum::NoOpChecksum::value()

DEL

-2

pw::checksum::NoOpChecksum::Update()

NEW

+512

pw::checksum::(anonymous namespace)::kCrc16CcittTable

NEW

+40

pw_checksum_Crc16Ccitt

NEW

+10

pw::checksum::Crc16Ccitt::Calculate()

+560

CRC32: 8 bits per iteration, 256-entry table

FLASH

+4

pw::checksum::RunChecksum()

+2

main

+8

vClearInterruptMaskFromISR

DEL

-4

pw::checksum::NoOpChecksum::value()

DEL

-2

pw::checksum::NoOpChecksum::Update()

NEW

+1,024

_pw_checksum_InternalCrc32EightBit::kCrc32Table

NEW

+36

_pw_checksum_InternalCrc32EightBit

NEW

+20

pw::checksum::Crc32Impl<>::Update()

+1,088

CRC32: 4 bit pers iteration, 16-entry table

FLASH

+4

pw::checksum::RunChecksum()

+2

main

-4

vClearInterruptMaskFromISR

DEL

-4

pw::checksum::NoOpChecksum::value()

DEL

-2

pw::checksum::NoOpChecksum::Update()

NEW

+64

_pw_checksum_InternalCrc32FourBit::kCrc32Table

NEW

+48

_pw_checksum_InternalCrc32FourBit

NEW

+20

pw::checksum::Crc32Impl<>::Update()

+128

CRC32: 1 bit per iteration, no table

FLASH

+4

pw::checksum::RunChecksum()

+2

main

-4

vClearInterruptMaskFromISR

DEL

-4

pw::checksum::NoOpChecksum::value()

DEL

-2

pw::checksum::NoOpChecksum::Update()

NEW

+48

_pw_checksum_InternalCrc32OneBit

NEW

+20

pw::checksum::Crc32Impl<>::Update()

+64

Fletcher16 (illustrative only)

FLASH

+8

pw::checksum::RunChecksum()

+2

main

+8

vClearInterruptMaskFromISR

DEL

-4

pw::checksum::NoOpChecksum::value()

DEL

-2

pw::checksum::NoOpChecksum::Update()

NEW

+58

pw::checksum::Fletcher16::Update()

NEW

+24

__aeabi_uidivmod

NEW

+10

pw::checksum::Fletcher16::value()

+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_8BITS

  • PW_CHECKSUM_CRC32_4BITS

  • PW_CHECKSUM_CRC32_1BITS

Zephyr#

To enable pw_checksum for Zephyr add CONFIG_PIGWEED_CHECKSUM=y to the project’s configuration.