CRC computation is a performance bottleneck · Issue #185 · OpenCyphal/libcanard (original) (raw)

Changing the CRC implementation to a table-based one improves the CRC computation time for a 21-frame transfer from 32us to 12us on a 180 MHz Cortex-M4 system. The rest of the serialization pipeline is comparatively cheap to execute -- the CRC is one of the worst offenders that is easy to fix. The cost is <512 bytes of ROM.

--- a/lib/libcanard/canard.c +++ b/lib/libcanard/canard.c @@ -73,22 +73,33 @@ typedef uint16_t TransferCRC; #define CRC_RESIDUE 0x0000U #define CRC_SIZE_BYTES 2U

+static const uint16_t CRCTable[256] = {

+}; + CANARD_PRIVATE TransferCRC crcAddByte(const TransferCRC crc, const uint8_t byte) {

}

CANARD_PRIVATE TransferCRC crcAdd(const TransferCRC crc, const size_t size, const void* const data)