RISC-V: Optimize CRC64 updates using Zbkc extension
Improves CRC64 calculation performance on RV64 by using clmul and clmulh instructions from the Zbkc extension.
CRC64 calculations on RV64 systems are now optimized by leveraging the clmul and clmulh instructions provided by the Zbkc extension. This change replaces multiple byte table lookups with more efficient multiply operations, leading to significant performance gains for 32- and 64-bit updates. The implementation also correctly handles polynomial shifts and XOR operations for accurate CRC calculation.
In Details
The config/riscv/bitmanip.md machine description is updated to use the RISC-V Zbkc (Bit Manipulation) extension for reversed CRC64 updates on RV64. Specifically, the crc_rev<ANYI1:mode><ANYI:mode>4 pattern now employs clmul and clmulh for 32- and 64-bit input widths. This provides a performance improvement over table lookups. The commit also corrects the handling of the high product for full-width polynomials when clmulr is unavailable and introduces a new test case (crc-rev-zbkc.c) to verify the functionality.
- RISC-V
- An open-standard instruction set architecture (ISA) based on Reduced Instruction Set Computer principles.
- CRC64
- Cyclic Redundancy Check algorithm producing a 64-bit checksum, commonly used for error detection.
- RV64
- A 64-bit variant of the RISC-V architecture.
- Zbkc
- A RISC-V extension providing bit manipulation instructions, including carry-less multiplication (
clmul). - clmul
- Carry-Less Multiplication. An instruction that performs multiplication without carry propagation, used in various hashing and checksum algorithms.
- clmulh
- Carry-Less Multiplication High. An instruction that performs the higher part of a carry-less multiplication.
- table lookup
- A method of implementing operations by using precomputed values stored in a table, often used for performance optimization in algorithms like CRC.
- polynomial
- In the context of CRC, a generator polynomial used in the calculation.