Re: [PATCH v2] lib/crc: arm64: Add NEON PMULL+EOR3 crc64_nvme implementation
From: Eric Biggers
Date: Mon Nov 16 2026 - 19:01:30 EST
On Sat, Nov 14, 2026 at 10:59:51PM +0530, Shreesh Adiga wrote:
> Add a 4x-folding implementation for CPUs with FEAT_SHA3 which benefits
> newer ARMv9 CPUs like Cortex-X925.
> Usage of EOR3 from SHA3 extension improves performance by 20% compared
> to the regular PMULL without EOR3 on Cortex-X925 measure in userspace
> application via libbenchmark for 512 byte input size.
> Measured about 3x speedup for 512 byte input compared with the existing
> NEON single fold implementation on Cortex-X925 in userspace.
Was crc_kunit run? It already has a benchmark in it.
The commit message should also clarify that this benefits ARMv8.2 and
later processors with the sha3 extension, not just ARMv9. (E.g., Apple
M1 is an example of an ARMv8.4 processor that benefits.)
> +#ifdef CONFIG_ARM64
> +#define SHA3_TARGET __attribute__((target("arch=armv8.2-a+crypto+sha3")))
Doesn't this break the build with gcc 8.1? The kernel supports gcc 8.1
and later, but support for the sha3 target and intrinsics were added in
gcc 9.1. Either this code will need to check the gcc version, or inline
assembly will need to be used for eor3 like lib/raid/xor/ does.
> + v0 = fold_single_round(v0, v2, fold_consts_2x);
> + v1 = fold_single_round(v1, v3, fold_consts_2x);
> + v0 = fold_single_round(v0, v1, fold_consts);
> +
> + while (len >= 16) {
> + uint64x2_t t0 = vreinterpretq_u64_u8(vld1q_u8(p));
> +
> + v0 = fold_single_round(v0, t0, fold_consts);
> + p += 16;
> + len -= 16;
> + }
> +
> + /* Multiply the 128-bit value by x^64 and reduce it back to 128 bits. */
> + v0 = vextq_u64(v0, zero, 1) ^ pmull64_hi_lo(fold_consts, v0);
> +
> + /* Final Barrett reduction */
> + uint64x2_t bconsts = vld1q_u64(bconsts_val);
> + uint64x2_t final = pmull64(bconsts, v0);
> +
> + v0 = veor3q_u64(v0, vextq_u64(zero, final, 1),
> + pmull64_hi_lo(bconsts, final));
> +
> + return vgetq_lane_u64(v0, 1);
Note that this is missing several optimizations compared to the x86
version (lib/crc/x86/crc-pclmul-template.S), including using
fold_consts_2x for a tail of 'len & 32', efficiently handling lengths
that aren't a multiple of 16 bytes, and reducing to the final CRC in two
carryless multiplication instructions rather than three.
This is also just one of several CRC variants. This would have to be
done all over again for each variant if they are not going to be
generated by a template like x86 and riscv do.
So we can do this for now, but it isn't a very scalable solution.
- Eric