On 11/19/26 8:50 AM, Jiawei wrote:
Use clmul and clmulh for reversed CRC64 updates that consume 32 or
64 bits on RV64 with Zbkc. Each update replaces four or eight byte
table lookups. Zbc targets already use clmulr.
Shift the reflected polynomial left by one to align the high product.
If the shift drops its top bit, XOR the multiplicand into the result.
To choose the cutoff, I compared the multiply sequence with table lookups
at all four input widths on a SpacemiT K1 and in gem5. The benchmark
used a warm 4 KiB buffer and -O2 -march=rv64gc_zbkc. Negative values
in the table indicate a reduction in cycles. K1 figures are
medians over 20 paired runs. The gem5 Minor and four-wide O3 models
used their integer multiply units for clmul and clmulh.
Inlined update One call per update
Input bits K1 Minor O3 K1 O3
8 +22.7% +20.0% +24.9% +61.8% +50.2%
16 -27.0% -23.7% -37.5% +22.3% -24.8%
32 -59.2% -57.6% -68.7% -33.2% -65.4%
64 -83.1% -81.1% -87.5% -70.5% -82.6%
For 16-bit inputs, a separate call materializes the multiply constants
on each update and regresses on K1. The byte loop was also sensitive
to the gem5 execution unit. With the default ALU mapping it took 24.9%
fewer cycles on O3. The 32- and 64-bit updates saved cycles on K1 and in
both gem5 mappings.
Testing gcc.target/riscv/crc-*.c with make -j4 report-gcc on RV32GC
and RV64GC showed no regressions.
gcc/ChangeLog:
* config/riscv/bitmanip.md (crc_rev<ANYI1:mode><ANYI:mode>4):
Use Zbkc for 32- and 64-bit inputs to CRC64.
* config/riscv/riscv.cc (riscv_optab_supported_p): Update comment.
(expand_reversed_crc_using_clmul): Correct the high product for
a full-width polynomial when clmulr is unavailable.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/crc-rev-zbkc.c: New test.
Thanks. LGTM and Sashiko clean.
It's not obvious, but I think that expansion change is likely a
correctness fix. And the bitmanip.md change is trivially correct.
Anyway, I've pushed this to the trunk.
Jeff