Re: [PATCH 2/2] lib/crc: loongarch: Add 3-way parallel CRC32(C) for large buffers

From: Eric Biggers

Date: Sun Oct 11 2026 - 12:33:44 EST


On Sun, Oct 11, 2026 at 10:29:30PM +0800, Huacai Chen wrote:
> The crc* loop is a single serial dependency chain: every instruction
> consumes the previous one's result. CRC is linear over GF(2), so a
> buffer can be split into 3 contiguous lanes processed by independent
> chains and combined afterwards:
>
> crc(A|B|C) = shift(crc(A), |B|+|C|) ^ shift(crc(B), |C|) ^ crc(C)
>
> with lanes B and C seeded with 0. The shift (multiplication by x^(8n)
> mod P) is linear, so its multiplier is tabulated at module init as 4x256
> tables built from crc32_le_base()/crc32c_base(); each combine then costs
> 4 lookups instead of a log-time GF(2) square loop.
>
> Lanes use a fixed 2 KiB stride (6 KiB superblock); smaller buffers fall
> through to the serial path. The 3-way parallel loop CRC32 is measured on
> a Loongson-3C6000 machine (single core, cache-hot, with UAL):
>
> 8 KiB: 8.4 -> 12.0 GB/s
> 64 KiB: 8.4 -> 12.4 GB/s (+45% over the serial hw loop,
> ~12x over the generic table)
>
> Correctness was verified bit-exact against crc32c() over all lengths
> 0..6168 with 3 seeds, plus 3000 random offset/length/seed combinations.
>
> Signed-off-by: Tianyang Zhang <zhangtianyang@xxxxxxxxxxx>
> Signed-off-by: Huacai Chen <chenhuacai@xxxxxxxxxxx>

So is this new code testable in QEMU? That's a prerequisite for adding
new optimized CRC or crypto code.

Please also note that you should just run crc_kunit instead of writing
custom in-kernel CRC test code.

- Eric