Re: [PATCH 2/2] lib/crc: loongarch: Add 3-way parallel CRC32(C) for large buffers
From: Huacai Chen
Date: Mon Oct 12 2026 - 02:51:00 EST
Hi, Eric,
On Sun, Oct 11, 2026 at 11:12 PM Eric Biggers <ebiggers@xxxxxxxxxx> wrote:
>
> 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.
Yes, it is testable in QEMU (for correctness). But the improvement
comes from super-scalar hardware, so the performance may be the same
for QEMU.
>
> Please also note that you should just run crc_kunit instead of writing
> custom in-kernel CRC test code.
Yes, crc_kunit is passed. Tianyang wrote his custom code but I have
run crc_kunit, I will update the commit message.
Huacai
>
> - Eric