Skip to content

Fletcher short inputs: one pass below the kernel threshold, plus doc gaps - #3

Merged
jmacheta merged 6 commits into
mainfrom
perf/fletcher-short-inputs
Oct 5, 2026
Merged

jmacheta merged 6 commits into
mainfrom
perf/fletcher-short-inputs

Conversation

@jmacheta

@jmacheta jmacheta commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

Performance

On 64-bit targets the portable Fletcher/Adler-32 loop now takes the input bound from its caller. Below the kernel threshold it sums in one run, with no loop over reduction runs and no reduction of the incoming sums first. That removes a stack frame. Empty data goes to the unfinished-block path, and finished sums return through std::bit_cast.

Fletcher-32 against the deferred-modulo loop (Wikipedia), -O2, one pinned core:

Cell Before After
x86-64 GCC 16, 20 B 0.73× 0.94×
Cortex-A72 AArch64 -mcpu=cortex-a72, 20 B 0.84× 0.94×
Cortex-A72 AArch64 -march=armv8-a, 20 B 0.79× 0.88×
  • Fletcher-16/64 and Adler-32 at 20 B run 1.15-1.28× faster on x86-64 and 1.06-1.18× faster on the A72. Other sizes are within ±3 %.
  • 32-bit targets (AArch32 and Cortex-M4 at -O2 and -Os) compile to the same code as before.
  • With Clang on x86-64, Fletcher-32 is still 0.80-0.83× at 20-64 B, because Clang compiles the reference loop faster.

Tests: adler32|fletcher pass on native-gcc, native-clang, native-asan, native-gcc-portable, x86_64-gcc-pclmul, cross-aarch64-pmull, cross-aarch64-portable, cross-arm-crc32, cross-arm-portable, cross-riscv64-rvv, cross-riscv64-portable, and a local -march=native build with AVX-VNNI. The big-endian branch was not run, because no aarch64_be toolchain is available.

Cortex-M33 (nRF54L15)

All algorithms were measured on an nRF54L15 at 128 MHz, with code in RRAM and the instruction cache on. Every result matched the host's checksums.

On 32-bit Arm without NEON:

  • MurmurHash3_x86_32 takes four blocks per iteration: 3.77 → 2.27 cycles per byte at 4 KiB.
  • The fletcher4 word loop takes two words per iteration: 3.78 → 2.79 cycles per byte.

Other targets compile to the same code as before. The cross-arm-portable preset tests the new loops in QEMU. On a Cortex-M4 (nRF52840), with both builds aligned the same way, the changes give 1.20× (MurmurHash3_x86_32, 3.02 → 2.52 cycles per byte) and 1.12× (fletcher4, 3.54 → 3.17). At 20 B they are 0.98-0.99× as fast as before.

The new doc sections cover:

  • the Cortex-M33 figures for every algorithm;
  • CRC engines in RAM against RRAM (1.2-1.9× at 1 KiB);
  • the M4 kernel thresholds rechecked on the M33;
  • updated Cortex-M4 code sizes.

The chip has no general-purpose CRC unit. Its CRACEN block is a crypto engine, which is out of scope.

Includes

Unused includes were removed from three architecture headers.

Documentation

  • Untested acceleration paths: SSSE3 without AVX2, SSE4.2 crc32 without PCLMULQDQ, Arm-state ldm, big-endian, and RVV vector lengths other than 128.
  • EOR3 with +sha3, and Zve64x.
  • CRC on the A72 against zlib-ng and ISA-L.
  • The braid count and the rejected table layouts.
  • xxHash and MurmurHash3 reference comparisons.
  • Reduction bounds that no test reaches.
  • Cortex-M4 code size.

On 64-bit targets sum_portable() gets the input bound from its caller and,
below the kernel threshold, sums in one run without the loop over
reduction runs or reducing the incoming sums first. Empty data takes the
unfinished-block path, and finished sums return through std::bit_cast.

Fletcher-32 at 20 B against the deferred-modulo loop: x86-64 GCC
0.73x -> 0.94x, Cortex-A72 0.84x -> 0.94x. 32-bit targets compile to the
same code.
Re-measured Fletcher/Adler-32 short inputs; untested acceleration paths;
EOR3, Zve64x, RVV vector lengths; CRC on the A72 against zlib-ng and ISA-L;
braid count and rejected table layouts; xxHash and MurmurHash3 reference
comparisons; reduction bounds no test reaches; Cortex-M4 code size.
misc-include-cleaner over every header, each architecture header with the
prelude of its dispatcher, in nine target configurations; only includes
unused where their code is active are removed.
On 32-bit Arm without NEON (Cortex-M, small A-profile cores), the one-shot
and streamed MurmurHash3_x86_32 take four blocks per iteration, and the
fletcher4 word loop takes two words. In-order cores then overlap the
independent work with the dependency chains. On a Cortex-M33 (nRF54L15)
at 4 KiB: MurmurHash3_x86_32 3.77 -> 2.27 cycles per byte, fletcher4
3.78 -> 2.79. Other targets compile to the same code as before; x86-64
lost 2-4 % from 4 KiB with the unrolled MurmurHash3 loop.
Cycles and MB/s at 128 MHz with code in RRAM and the instruction cache
on. Also: CRC tables in RAM vs RRAM, kernel thresholds rechecked on the
M33, no general-purpose CRC unit on the chip, and updated Cortex-M4 code
sizes.
…letcher4 loops

Same harness and code alignment for both builds: MurmurHash3_x86_32 3.02 ->
2.52 cycles per byte at 4 KiB (1.20x), fletcher4 3.54 -> 3.17 (1.12x),
0.98-0.99x at 20 B.
@jmacheta
jmacheta merged commit 1a2c737 into main Oct 5, 2026
16 checks passed
@jmacheta
jmacheta deleted the perf/fletcher-short-inputs branch October 5, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant