Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
f216ddd
refactor(internet): name internet_state{} in internet_compute, as adl…
jmacheta Oct 4, 2026
5d4095a
test(internet): rename the test file to ut_internet.cpp, like the oth…
jmacheta Oct 4, 2026
0a86e00
docs(internet): definition section, fixed quick start, examples
jmacheta Oct 4, 2026
5fb6e8d
examples(internet): IPv4 header, UDP datagram and TTL decrement
jmacheta Oct 4, 2026
a9f4e1a
refactor(fletcher4): contiguous ranges take compute_loop, one AVX2 block
jmacheta Oct 4, 2026
9ae2b2d
examples(fletcher4): ZFS block verification and file checksum
jmacheta Oct 4, 2026
d0545b8
docs(fletcher4): mention the examples
jmacheta Oct 4, 2026
cf65250
refactor(murmur3): read the 2-byte tail word with load()
jmacheta Oct 4, 2026
aac0778
feat(murmur3): murmur3_32 and murmur3_128 aliases
jmacheta Oct 4, 2026
abdd113
examples(murmur3): command dispatch, Bloom filter and deduplication
jmacheta Oct 4, 2026
2465724
docs(murmur3): aliases, examples, section order like the other guides
jmacheta Oct 4, 2026
0b8ffe2
examples(murmur3): plain wording in the Bloom filter comment
jmacheta Oct 4, 2026
ca94ec4
feat(xxhash): add xxh32 and xxh64 aliases
jmacheta Oct 4, 2026
d917482
examples(xxhash): compile-time IDs, file hash and cache key
jmacheta Oct 4, 2026
680c69a
docs(xxhash): aliases, examples and the run-time XXH32 path
jmacheta Oct 4, 2026
3a129fd
feat(xxh3): xxh3_64 and xxh3_128 state and compute aliases
jmacheta Oct 4, 2026
c33b258
refactor(xxh3): accumulate and scramble only as portable_kernel members
jmacheta Oct 4, 2026
f410396
examples(xxh3): file hash, block dedup and seeded hash table
jmacheta Oct 4, 2026
59a3f5f
examples(xxh3): plain words for spelling
jmacheta Oct 4, 2026
edd1a36
docs(xxh3): aliases, examples and the AArch64 kernel threshold in str…
jmacheta Oct 4, 2026
b9994f2
build: GCC-only warning flags only for GCC
jmacheta Oct 4, 2026
7ab7729
docs(crc): CHECKSUM_EXAMPLES builds every example
jmacheta Oct 4, 2026
038ba5b
refactor(xxhash, xxh3, murmur3): one little-endian load, one XXH64 av…
jmacheta Oct 4, 2026
36baf20
refactor(fletcher, adler32): share the run-time loops
jmacheta Oct 4, 2026
c9782e5
feat(fletcher): fletcher16, fletcher32 and fletcher64 aliases
jmacheta Oct 4, 2026
11bb98d
refactor(adler32): start compute from {} like the Internet checksum
jmacheta Oct 4, 2026
35061a0
examples(fletcher, adler32): frame check, file checksum, compile time…
jmacheta Oct 4, 2026
d8efee3
docs(fletcher, adler32): aliases, examples, chunk sizes, shared loops
jmacheta Oct 4, 2026
9f9a6b4
perf(fletcher): 32-bit byte loop for Fletcher-16 and Fletcher-32
jmacheta Oct 4, 2026
15aa023
perf(fletcher, adler32): no Cortex-M4 regressions from the shared loops
jmacheta Oct 4, 2026
63c7b97
refactor: each dispatch header selects its architecture directory
jmacheta Oct 4, 2026
9fdaf88
test: one pseudo-random data generator for tests and benchmarks
jmacheta Oct 4, 2026
1917282
feat: checksum::hash128, one result type for 128-bit hashes
jmacheta Oct 4, 2026
d3b83b9
refactor(xxh3)!: XXH3-128 returns hash128, xxh3_hash128 removed
jmacheta Oct 4, 2026
3e81fbc
refactor(murmur3)!: MurmurHash3_x64_128 returns hash128
jmacheta Oct 4, 2026
b92aac3
feat(adler32, internet, fletcher): continue from a stored checksum
jmacheta Oct 4, 2026
5754684
docs(adler32, internet, fletcher): continuing from a stored checksum
jmacheta Oct 4, 2026
661779a
examples(adler32, internet): continue from the stored checksum
jmacheta Oct 4, 2026
81fbab0
examples: one structure in every directory
jmacheta Oct 4, 2026
587e85d
examples(adler32, fletcher4, internet, xxh3): compile-time examples
jmacheta Oct 4, 2026
a9846e0
docs, examples: review fixes (NDEBUG note, fletcher4 continuation, on…
jmacheta Oct 4, 2026
3668b35
fix(xxh3, fletcher4): portable XXH3 without SSE2, fletcher4_arch.hpp …
jmacheta Oct 4, 2026
e688377
perf(xxh3): AArch64 kernel keeps its lanes in registers at -O2
jmacheta Oct 4, 2026
c1f1d53
perf(xxhash): one-shot XXH64 keeps its lanes in locals on 64-bit targets
jmacheta Oct 4, 2026
61d0918
perf(murmur3): one-shot x86_32 keeps its lane in a register
jmacheta Oct 4, 2026
785870e
docs(xxhash, murmur3): -O2 measurements on the A72, AArch64 kernel fr…
jmacheta Oct 4, 2026
73212ab
test: -Og Debug builds, fewer Fletcher/Adler-32 offsets, VPCLMULQDQ a…
jmacheta Oct 4, 2026
8821843
perf(crc): x86 wide fold reduces its last 8 blocks in parallel
jmacheta Oct 4, 2026
7d0f50a
perf(crc): straight-line 256-byte path, CRC-32C ends with crc32 instr…
jmacheta Oct 4, 2026
bfee6b7
docs(crc): x86 256-byte folding, 160 B of constants, ISA-L comparison
jmacheta Oct 4, 2026
3dfe17d
perf(internet): adc chains on x86-64, masked last word, rotate fold
jmacheta Oct 4, 2026
9ff962c
docs(internet): re-measured portable loop, code size, reference compa…
jmacheta Oct 4, 2026
fac5f3a
perf(fletcher4): scalar lane combination, no stack protector check, A…
jmacheta Oct 4, 2026
eeda7a2
perf(fletcher4): zero the long result only on the long path, SSE2 lan…
jmacheta Oct 4, 2026
69897fc
perf(fletcher4): NEON lanes from 192 B on AArch32 too
jmacheta Oct 4, 2026
5e2b35f
refactor(fletcher4): lane weights as powers of the lane count
jmacheta Oct 4, 2026
fb7ab88
docs(fletcher4): new thresholds, re-measured x86 and A72 tables, Open…
jmacheta Oct 4, 2026
c1dfc6e
perf(adler32, fletcher): AVX-VNNI byte kernel, four blocks per iteration
jmacheta Oct 4, 2026
a893f54
perf(adler32, fletcher): AArch64 NEON byte kernel over 64-byte groups
jmacheta Oct 4, 2026
5e30156
perf(fletcher, adler32): short inputs without store-forwarding stalls
jmacheta Oct 4, 2026
40042d6
docs(adler32, fletcher): AVX-VNNI and 64-byte NEON kernels, short-inp…
jmacheta Oct 4, 2026
e7bc480
docs: bring the guides in line with the gap fixes
jmacheta Oct 4, 2026
b615792
chore: spelling words for the gap-fix docs
jmacheta Oct 4, 2026
9565d12
docs: re-measure the Fletcher, Adler-32 and Internet tables
jmacheta Oct 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .cspell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ words:
- adccp
- adcs
- addc
- addcll
- addtogroup
- aixm
- alderlake
- argn
- armv
- asan
- autosar
- avxvnni
- broadcastsi
- bugprone
- buypass
Expand All @@ -49,6 +51,7 @@ words:
- castsi
- ccitt
- cdma
- cinc
- cksum
- clmul
- clmulepi
Expand All @@ -62,13 +65,17 @@ words:
- crcs
- crosscompiling
- cstdint
- csum
- ctest
- cvref
- cvtepu
- cvtsi
- cxxflags
- darc
- datagram
- dect
- dpbusd
- DPDK
- dtcm
- eabi
- endforeach
Expand Down Expand Up @@ -113,6 +120,7 @@ words:
- maddubs
- madler
- mavx
- mavxvnni
- mcpu
- mcrf
- memcpy
Expand Down Expand Up @@ -143,6 +151,7 @@ words:
- pclmul
- pclmulqdq
- pmaddubsw
- pmaddwd
- pmull
- polys
- predefines
Expand Down Expand Up @@ -174,6 +183,7 @@ words:
- stdint
- storeu
- strequal
- superscalar
- taskset
- teledisk
- templatize
Expand Down Expand Up @@ -207,9 +217,11 @@ words:
- vmul
- vmull
- vmulq
- VNNI
- vpadalq
- VPCLMULQDQ
- vpaddlq
- VPCLMULQDQ
- vpdpbusd
- vqtbl
- vreinterpret
- vreinterpretq
Expand Down
1 change: 1 addition & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"CMAKE_EXE_LINKER_FLAGS": "-fsanitize=address,undefined -Wl,--gc-sections"
},
"environment": {
"CHECKSUM_GCC_WARNINGS": "",
"CHECKSUM_EXTRA_CFLAGS": "-fsanitize=address,undefined -fno-sanitize-recover=all -g -O1",
"CHECKSUM_EXTRA_CXXFLAGS": "-fsanitize=address,undefined -fno-sanitize-recover=all -g -O1"
}
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ CPU acceleration follows your compiler flags (for example `-march=native` or `-m
- [MurmurHash3 user guide](doc/murmur3.md): the API, seeds, byte order, measured performance and limitations.
- [examples/crc](examples/crc): compile-time CRC, a file checksum, a custom CRC, run-time parameters, a MODBUS frame
and a strategy driving an MCU CRC peripheral.
- [examples/internet](examples/internet): a header checksum computed at compile time, an IPv4 header, a UDP
datagram with its pseudo-header and an incremental update after a TTL decrement.
- [examples/fletcher](examples/fletcher) and [examples/adler32](examples/adler32): compile-time checksums, a file
checksum, a frame check, a zlib trailer and extending a stored Adler-32.
- [examples/fletcher4](examples/fletcher4): a compile-time checksum, a file checksum and verifying a ZFS block.
- [examples/xxhash](examples/xxhash) and [examples/xxh3](examples/xxh3): compile-time message and asset IDs, file
hashes, a cache key, block deduplication and a seeded hash table.
- [examples/murmur3](examples/murmur3): command dispatch, a Bloom filter and record deduplication.

## Contributing

Expand Down
10 changes: 7 additions & 3 deletions cmake/common_presets.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
"hidden": true,
"inherits": "common",
"cacheVariables": {
"CMAKE_C_FLAGS_DEBUG": "-g -D_GLIBCXX_ASSERTIONS -fstack-protector-strong -ftrivial-auto-var-init=pattern",
"CMAKE_CXX_FLAGS_DEBUG": "-g -D_GLIBCXX_ASSERTIONS -fstack-protector-strong -ftrivial-auto-var-init=pattern"
"CMAKE_C_FLAGS_DEBUG": "-g -Og -D_GLIBCXX_ASSERTIONS -fstack-protector-strong -ftrivial-auto-var-init=pattern",
"CMAKE_CXX_FLAGS_DEBUG": "-g -Og -D_GLIBCXX_ASSERTIONS -fstack-protector-strong -ftrivial-auto-var-init=pattern"
},
"environment": {
"CHECKSUM_WARNINGS": "-Wall -Wextra -Wpedantic -Wunused-parameter -Winit-self -Wcast-align -Wconversion -Wnull-dereference -Wduplicated-cond -Wsign-conversion -Wlogical-op -Wno-psabi",
"CHECKSUM_WARNINGS": "-Wall -Wextra -Wpedantic -Wunused-parameter -Winit-self -Wcast-align -Wconversion -Wnull-dereference -Wsign-conversion -Wno-psabi $env{CHECKSUM_GCC_WARNINGS}",
"CHECKSUM_GCC_WARNINGS": "-Wduplicated-cond -Wlogical-op",
"CFLAGS": "$env{CHECKSUM_WARNINGS} $env{CHECKSUM_SECTIONS} $env{CHECKSUM_EXTRA_CFLAGS}",
"CXXFLAGS": "$env{CHECKSUM_WARNINGS} $env{CHECKSUM_SECTIONS} $env{CHECKSUM_EXTRA_CXXFLAGS}",
"CHECKSUM_EXTRA_CFLAGS": "",
Expand All @@ -49,6 +50,9 @@
"inherits": "gcc-clang-common",
"cacheVariables": {
"CMAKE_CXX_COMPILER": "clang++"
},
"environment": {
"CHECKSUM_GCC_WARNINGS": ""
}
}
],
Expand Down
12 changes: 8 additions & 4 deletions cmake/emulator_presets.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@
{
"name": "cross-aarch64-pmull",
"displayName": "AArch64 Linux in QEMU (PMULL and CRC32)",
"description": "AArch64 cross build with -march=armv8-a+crc+crypto: PMULL folding and CRC32 instructions (aarch64 header); tests run in QEMU",
"description": "AArch64 cross build with -march=armv8.2-a+crc+crypto+sha3: PMULL folding with EOR3 and CRC32 instructions (aarch64 header); tests run in QEMU",
"inherits": "cross-aarch64-base",
"environment": {
"CHECKSUM_EXTRA_CFLAGS": "-march=armv8-a+crc+crypto",
"CHECKSUM_EXTRA_CXXFLAGS": "-march=armv8-a+crc+crypto"
"CHECKSUM_EXTRA_CFLAGS": "-march=armv8.2-a+crc+crypto+sha3",
"CHECKSUM_EXTRA_CXXFLAGS": "-march=armv8.2-a+crc+crypto+sha3"
}
},
{
Expand Down Expand Up @@ -113,8 +113,12 @@
{
"name": "cross-arm-portable",
"displayName": "32-bit Arm Linux in QEMU (no NEON)",
"description": "32-bit Arm (hard float) cross build with -mfpu=vfpv3-d16: portable CRC loops and the ldm + adcs Internet checksum kernel on a 32-bit target; tests run in QEMU. CHECKSUM_TEST_ARM_DSP enables the M-profile DSP kernel of Fletcher-16 and Adler-32, which QEMU user mode cannot run on an M-profile core",
"description": "32-bit Arm (hard float) cross build with -mfpu=vfpv3-d16: portable CRC loops and the ldm + adcs Internet checksum kernel on a 32-bit target; tests run in QEMU. CHECKSUM_TEST_ARM_DSP enables the M-profile DSP kernel of Fletcher-16 and Adler-32, which QEMU user mode cannot run on an M-profile core. Debug stays at -O0 here so that the inline assembly is built without optimization",
"inherits": "cross-arm-base",
"cacheVariables": {
"CMAKE_C_FLAGS_DEBUG": "-g -O0 -D_GLIBCXX_ASSERTIONS -fstack-protector-strong -ftrivial-auto-var-init=pattern",
"CMAKE_CXX_FLAGS_DEBUG": "-g -O0 -D_GLIBCXX_ASSERTIONS -fstack-protector-strong -ftrivial-auto-var-init=pattern"
},
"environment": {
"CHECKSUM_EXTRA_CFLAGS": "-mfpu=vfpv3-d16",
"CHECKSUM_EXTRA_CXXFLAGS": "-mfpu=vfpv3-d16 -DCHECKSUM_TEST_ARM_DSP"
Expand Down
6 changes: 3 additions & 3 deletions cmake/x86_64_presets.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
{
"name": "x86_64-gcc-pclmul",
"displayName": "x86-64 (GCC, PCLMULQDQ, SSE4.2 and AVX2 at compile time)",
"description": "Native Linux build using GCC with -mpclmul -msse4.2 -mavx2: CRC folding with PCLMULQDQ, the SSE4.2 crc32 instruction and the AVX2 Internet checksum kernel",
"description": "Native Linux build using GCC with -mpclmul -mvpclmulqdq -msse4.2 -mavx2: CRC folding with PCLMULQDQ and 256-byte VPCLMULQDQ, the SSE4.2 crc32 instruction and the AVX2 Internet checksum kernel",
"inherits": "gcc",
"environment": {
"CHECKSUM_EXTRA_CFLAGS": "-mpclmul -msse4.2 -mavx2",
"CHECKSUM_EXTRA_CXXFLAGS": "-mpclmul -msse4.2 -mavx2"
"CHECKSUM_EXTRA_CFLAGS": "-mpclmul -mvpclmulqdq -msse4.2 -mavx2",
"CHECKSUM_EXTRA_CXXFLAGS": "-mpclmul -mvpclmulqdq -msse4.2 -mavx2"
}
}
],
Expand Down
47 changes: 35 additions & 12 deletions doc/adler32.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ state = checksum::adler32_update(state, first_part);
state = checksum::adler32_update(state, second_part);
std::uint32_t stream_checksum = checksum::adler32_finalize(state);

// Continue from a stored checksum.
std::uint32_t extended = checksum::adler32_update(stream_checksum, third_part);

// Compile time.
static_assert(checksum::adler32_compute("123456789"sv) == 0x091E01DE);
static_assert(checksum::adler32_compute("Wikipedia"sv) == 0x11E60398);
```

`examples/adler32` has complete programs: the checksum of default settings computed at compile time, checking the
Adler-32 trailer of a zlib stream, and extending a stored checksum when data is appended.

## 2. Definition

Adler-32 keeps two sums modulo 65521, the largest prime below 2^16: `sum1` starts at 1 and adds each byte, `sum2`
Expand All @@ -38,6 +44,7 @@ starts at 0 and adds `sum1` after each byte. The checksum is `(sum2 << 16) | sum
| --- | --- |
| `adler32_state` | The two sums, `sum1` and `sum2`. A plain value: copy it, compare it, store it. The default (`sum1 = 1`, `sum2 = 0`) is the empty message. |
| `adler32_update(state, data)` | Folds `data` into `state` and returns the new state. |
| `adler32_update(checksum, data)` | Folds `data` into the message whose checksum is `checksum`, a `std::uint32_t`, and returns the new checksum. |
| `adler32_finalize(state)` | The checksum. |
| `adler32_compute(data)` | `adler32_finalize(adler32_update({}, data))`. |

Expand All @@ -52,10 +59,13 @@ Every state value is valid, so nothing has preconditions: sums from 65521 up cou

- **Splits:** a message may be split anywhere; the result is the same as for one call.
- **Empty message:** gives 1.
- **Resuming from a checksum:** `adler32_state{.sum1 = value & 0xFFFF, .sum2 = value >> 16}` continues a message whose
checksum is `value`, for example one computed by zlib.
- **Byte order:** the result is a number; zlib stores it most significant byte first.

**Continuing from a stored checksum.** The checksum holds both sums, so `adler32_update(value, data)` continues a
message whose checksum is `value`, for example one computed by zlib, after any number of bytes, and returns the new
checksum, as zlib's `adler32(adler, buf, len)` does. `value` must be a `std::uint32_t`: another integer type does not
compile, so that `adler32_update({}, data)` still starts from the empty state, not from checksum 0.

## 5. CPU acceleration

The portable loop adds bytes into `std::size_t` sums and reduces them only when an overflow could otherwise happen:
Expand All @@ -67,9 +77,11 @@ From 64 bytes, Adler-32 runs the byte kernel of Fletcher-16 with modulus 65521:

| Target and flags | Kernel |
| --- | --- |
| x86-64 with AVX-VNNI (`-mavxvnni`, or a `-march` that includes it, e.g. Alder Lake, Meteor Lake) | `vpdpbusd`, 128 bytes per iteration |
| x86-64 with AVX2 (`-mavx2`, or a `-march` that includes it) | 32-byte vectors |
| x86-64 without AVX2 (SSE2 is always there; SSSE3 used if enabled) | 16-byte vectors |
| AArch64 and 32-bit Arm with NEON, little-endian | NEON, 16-byte vectors |
| AArch64 with NEON, little-endian | NEON, 16-byte vectors; from 320 bytes 64 bytes per iteration |
| 32-bit Arm with NEON, little-endian | NEON, 16-byte vectors |
| Little-endian M-profile Arm with the DSP extension (Cortex-M4/M7/M33) | `usada8` + `smlad`, 8 bytes per iteration |
| everything else, or `CHECKSUM_ACCELERATION=OFF` | portable loop |

Expand All @@ -81,21 +93,32 @@ evaluation always runs a byte-by-byte loop with the same result. The measurement

### 6.1 x86-64: Core Ultra 7 155H

GCC 16, 4 KiB, measured on a loaded host: 7 365 MB/s (10⁶ bytes per second) for the portable loop, 54 211 MB/s with
the AVX2 kernel, 7.4× faster.
GCC 16, 4 KiB, one pinned core, the better median of two runs: 7 309 MB/s (10⁶ bytes per second) for the portable
loop, 22 964 MB/s with SSE2 and 58 088 MB/s with the AVX2 kernel, 7.9× faster. With `-march=native` the AVX-VNNI
kernel runs (MB/s, GCC 16 and Clang 21):

| Input | 20 B | 64 B | 256 B | 1500 B | 4 KiB | 1 MiB |
| --- | --- | --- | --- | --- | --- | --- |
| GCC | 3 781 | 11 570 | 35 225 | 56 789 | 84 504 | 88 630 |
| Clang | 3 746 | 11 655 | 36 649 | 57 952 | 85 027 | 89 914 |

In a separate comparison harness, against zlib-ng (develop, its AVX-VNNI kernel, same flags) the library runs 0.98×
at 20 B, 0.78× at 64 B, 0.91× at 256 B and 1.13-1.17× from 4 KiB; the AVX2 kernel reached 0.71-0.83× there.

### 6.2 Cortex-A72: Raspberry Pi 4, 1.5 GHz

GCC 14.3, `-O2`, one core, start address aligned. GiB/s:
GCC 14.3, `-O2`, AArch64 `-march=armv8-a`, one core, start address aligned. GiB/s:

| Build | 64 B | 256 B | 1500 B | 4 KiB |
| --- | --- | --- | --- | --- |
| AArch64 portable | 0.68 | 0.77 | 0.83 | 0.84 |
| AArch64 NEON | 1.15 | 2.59 | 3.79 | 4.39 |
| AArch32 portable | 0.52 | 0.71 | 0.85 | 0.86 |
| AArch32 NEON | 0.98 | 2.44 | 3.75 | 4.32 |

NEON is about 5× faster at 4 KiB and 1.7-1.9× at 64 bytes.
| AArch64 portable | 0.69 | 0.77 | 0.83 | 0.84 |
| AArch64 NEON | 1.15 | 2.60 | 5.01 | 6.16 |
| AArch32 portable | 0.66 | 0.77 | 0.85 | 0.87 |
| AArch32 NEON | 0.95 | 2.42 | 3.75 | 4.30 |

NEON is 5.0-7.3× faster at 4 KiB and 1.4-1.7× at 64 bytes. On AArch64, from 320 bytes the kernel sums 64 bytes per
iteration: 0.96-0.99× zlib-ng and ISA-L from 1500 B in the comparison harness, where 16 bytes per iteration reached
0.72-0.79×.

### 6.3 Cortex-M4: nRF52840 at 64 MHz, STM32L4A6 at 80 MHz

Expand Down
28 changes: 15 additions & 13 deletions doc/crc.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ target_link_libraries(app PRIVATE checksum::checksum)
| `CHECKSUM_ACCELERATION` | `ON` | Lets `crc_lut_sliced` and `crc_lut_braided` use the CPU instructions that the compiler flags enable (section 7). `OFF` keeps only the portable loops. |
| `CHECKSUM_TESTS` | top-level project | Unit tests and negative compile tests (downloads GoogleTest). |
| `CHECKSUM_BENCHMARKS` | `OFF` | Benchmarks (downloads Google Benchmark and zlib); on in the `native-*-bench` presets. |
| `CHECKSUM_EXAMPLES` | top-level project | Builds `examples/crc`. |
| `CHECKSUM_EXAMPLES` | top-level project | Builds `examples/`. |

Compile and link the application with `-ffunction-sections -fdata-sections` and `-Wl,--gc-sections`: the library
compiles the run-time loops of every strategy and register type, and the linker then keeps only the ones the
Expand Down Expand Up @@ -154,7 +154,7 @@ std::uint16_t crc = can.compute(bits, 83); // bits: std::array<std::byte, 11>

A state passed to `update` or `finalize` must be below 2^width, and `bit_length` must not exceed
`8 * data.size()`. Both are checked with `assert`. With `NDEBUG` the state is masked and the bit length clamped,
so a violation gives a wrong CRC but never undefined behavior. During constant evaluation a failed `assert` is a
so a violation gives a wrong CRC but never undefined behavior. Without `NDEBUG`, a failed `assert` during constant evaluation is a
compile error.

## 6. Strategies
Expand All @@ -168,10 +168,10 @@ results.
| `crc_lut_none` (default) | 11 / 16 / 32 / 64 B | Bitwise, no table. Smallest code and data. |
| `crc_lut_nibble` | 27 / 48 / 96 / 192 B | 16-entry table, two lookups per byte. |
| `crc_lut_byte` | 267 / 528 / 1056 / 2112 B | 256-entry table, one lookup per byte. |
| `crc_lut_sliced` | 2.1 / 4.1 / 8.1 / 16.1 KiB | Slicing-by-8: eight 256-entry tables, one 8-byte word per step. CPU acceleration (section 7). |
| `crc_lut_braided` | 4.1 / 8.1 / 16.1 / 32.1 KiB | Slicing-by-8 plus 8 braid tables: five interleaved streams of 8-byte words from 128 B on. CPU acceleration (section 7). |
| `crc_lut_sliced` | 2.2 / 4.2 / 8.2 / 16.2 KiB | Slicing-by-8: eight 256-entry tables, one 8-byte word per step. CPU acceleration (section 7). |
| `crc_lut_braided` | 4.2 / 8.2 / 16.2 / 32.2 KiB | Slicing-by-8 plus 8 braid tables: five interleaved streams of 8-byte words from 128 B on. CPU acceleration (section 7). |

Sizes are `sizeof(crc_engine)` on a 64-bit host. The sliced and braided engines include 80 B of folding constants
Sizes are `sizeof(crc_engine)` on a 64-bit host. The sliced and braided engines include 160 B of folding constants
for the CPU kernels. Large engines belong in static storage (`crc_engine_for`, or a `static`/global object), not on
an MCU stack.

Expand Down Expand Up @@ -243,12 +243,14 @@ GCC 16. Accelerated = `-march=native` (PCLMULQDQ, VPCLMULQDQ, AVX2, SSE4.2). MB/

| CRC | none | nibble | byte | sliced, portable | braided, portable | sliced, accelerated |
| --- | --- | --- | --- | --- | --- | --- |
| CRC-8/SMBUS | 180 | 252 | 797 | 3814 / 3540 / 3091 / 3019 | 3705 / 4940 / 5976 / 6045 | 8591 / 39081 / 70047 / 73570 |
| CRC-16/XMODEM | 176 | 245 | 781 | 4099 / 3012 / 2579 / 2589 | 3664 / 4703 / 5884 / 6009 | 8525 / 39037 / 70187 / 73350 |
| CRC-32/ISO-HDLC | 137 | 289 | 673 | 4663 / 3657 / 2923 / 2896 | 4332 / 5345 / 6685 / 6556 | 7906 / 40503 / 71581 / 74656 |
| CRC-64/XZ | 137 | 287 | 661 | 4758 / 2761 / 2501 / 2424 | 4456 / 5192 / 6710 / 6485 | 8395 / 41592 / 71870 / 74835 |
| CRC-8/SMBUS | 180 | 252 | 797 | 3814 / 3540 / 3091 / 3019 | 3705 / 4940 / 5976 / 6045 | 10564 / 49017 / 71769 / 74200 |
| CRC-16/XMODEM | 176 | 245 | 781 | 4099 / 3012 / 2579 / 2589 | 3664 / 4703 / 5884 / 6009 | 10573 / 48774 / 72463 / 71670 |
| CRC-32/ISO-HDLC | 137 | 289 | 673 | 4663 / 3657 / 2923 / 2896 | 4332 / 5345 / 6685 / 6556 | 9754 / 52967 / 74320 / 75889 |
| CRC-64/XZ | 137 | 287 | 661 | 4758 / 2761 / 2501 / 2424 | 4456 / 5192 / 6710 / 6485 | 10291 / 53467 / 73653 / 75693 |

The accelerated `crc_lut_braided` is within 6 % of the accelerated `crc_lut_sliced`. Clang gives the same picture.
Against Intel ISA-L (hand-written AVX2 VPCLMULQDQ assembly), the accelerated CRC-32, CRC-32C and CRC-64/XZ run at
0.89-1.45× its speed from 20 B to 1 MiB with GCC 16, and 0.95-1.01× at 256 B.

### 8.2 Cortex-A72 (Raspberry Pi 4, 1.5 GHz)

Expand Down Expand Up @@ -283,10 +285,10 @@ code added over an empty program / engine in `.rodata`, bytes.

| CRC | none | nibble | byte | sliced | braided |
| --- | --- | --- | --- | --- | --- |
| CRC-32/ISO-HDLC | 100 / 32 | 104 / 96 | 80 / 1056 | 252 / 8320 | 1116 / 16512 |
| CRC-16/XMODEM | 104 / 16 | 104 / 48 | 76 / 528 | 252 / 4208 | 1212 / 8304 |
| CRC-8/SMBUS | 101 / 11 | 101 / 27 | 97 / 267 | 252 / 2160 | 1068 / 4208 |
| CRC-64/XZ | 116 / 64 | 140 / 192 | 100 / 2112 | 380 / 16528 | 1868 / 32912 |
| CRC-32/ISO-HDLC | 100 / 32 | 104 / 96 | 80 / 1056 | 252 / 8400 | 1116 / 16592 |
| CRC-16/XMODEM | 104 / 16 | 104 / 48 | 76 / 528 | 252 / 4288 | 1212 / 8384 |
| CRC-8/SMBUS | 101 / 11 | 101 / 27 | 97 / 267 | 252 / 2240 | 1068 / 4288 |
| CRC-64/XZ | 116 / 64 | 140 / 192 | 100 / 2112 | 380 / 16608 | 1868 / 32992 |

### 8.4 Cortex-M4 with a CRC peripheral (STM32L4A6, 80 MHz)

Expand Down
Loading
Loading