GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
risc-v Performance Win

RISC-V RV32 uses CLMULR for reversed CRC32, improving performance.

Optimizes reversed CRC32 calculation on RISC-V RV32 by using the CLMULR instruction, avoiding a slower table-based fallback.

This commit enhances the CRC32 calculation for the RISC-V 32-bit architecture (rv32) by utilizing the CLMULR instruction. Previously, calculating a reflected polynomial for 32-bit CRC required an operand that was 33 bits wide, exceeding register capacity and forcing a fallback to a less efficient table-based method. By leveraging the CLMULR instruction’s property to produce specific bits of a carry-less product, the compiler can now use the unshifted 32-bit reflected polynomial, resulting in a performance improvement for CRC32 operations on RV32 systems with the Zbc extension.

In Details

For word-sized reversed CRC32 on rv32 with the Zbc extension, the previous clmul-based expansion required a 33-bit operand (ref_poly << 1), falling back to a table. This commit modifies expand_reversed_crc_using_clmul in riscv.cc to use clmulr with the unshifted 32-bit reflected polynomial. This is based on the identity clmulh(a, ref_poly << 1) = clmulr(a, ref_poly). The crc_rev expansion in bitmanip.md is updated to use this new logic, and riscv_optab_supported_p allows it for size optimization.

For Context
CLMULR
A RISC-V instruction (part of the Zbc extension) that performs a carry-less multiplication and returns the higher bits of the result. It's useful for polynomial arithmetic operations like CRC.
CRC32
Cyclic Redundancy Check, a type of error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data.
RV32
The 32-bit variant of the RISC-V instruction set architecture.
Zbc
A RISC-V extension that adds bit manipulation instructions, including carry-less multiplication (CLMUL, CLMULH, CLMULR).
reflected polynomial
In CRC calculations, the polynomial used is sometimes 'reflected', meaning the order of its bits is reversed. This affects how the polynomial is applied during the CRC computation.
Filed Under: risc-voptimizationcompilercrc32