diff options
author | Mariam Arutunian <mariamarutunian@gmail.com> | 2024-11-28 14:35:23 -0700 |
---|---|---|
committer | Jeff Law <jlaw@ventanamicro.com> | 2024-11-29 08:02:32 -0700 |
commit | 74eb3570e6fba73b0e2bfce2a14d7696e30b48a8 (patch) | |
tree | 85fdb3573cc53891b7fd9dfec3dc99966613dc91 /gcc/expr.cc | |
parent | fe29b03825c9971ef1726bf9c7288de3389511b3 (diff) | |
download | gcc-74eb3570e6fba73b0e2bfce2a14d7696e30b48a8.zip gcc-74eb3570e6fba73b0e2bfce2a14d7696e30b48a8.tar.gz gcc-74eb3570e6fba73b0e2bfce2a14d7696e30b48a8.tar.bz2 |
[PATCH v7 03/12] RISC-V: Add CRC expander to generate faster CRC.
If the target is ZBC or ZBKC, it uses clmul instruction for the CRC
calculation. Otherwise, if the target is ZBKB, generates table-based
CRC, but for reversing inputs and the output uses bswap and brev8
instructions. Add new tests to check CRC generation for ZBC, ZBKC and
ZBKB targets.
gcc/
* expr.cc (gf2n_poly_long_div_quotient): New function.
* expr.h (gf2n_poly_long_div_quotient): New function declaration.
* hwint.cc (reflect_hwi): New function.
* hwint.h (reflect_hwi): New function declaration.
* config/riscv/bitmanip.md (crc_rev<ANYI1:mode><ANYI:mode>4): New
expander for reversed CRC.
(crc<SUBX1:mode><SUBX:mode>4): New expander for bit-forward CRC.
* config/riscv/iterators.md (SUBX1, ANYI1): New iterators.
* config/riscv/riscv-protos.h (generate_reflecting_code_using_brev):
New function declaration.
(expand_crc_using_clmul): Likewise.
(expand_reversed_crc_using_clmul): Likewise.
* config/riscv/riscv.cc (generate_reflecting_code_using_brev): New
function.
(expand_crc_using_clmul): Likewise.
(expand_reversed_crc_using_clmul): Likewise.
* config/riscv/riscv.md (UNSPEC_CRC, UNSPEC_CRC_REV): New unspecs.
* doc/sourcebuild.texi: Document new target selectors.
gcc/testsuite
* lib/target-supports.exp (check_effective_target_riscv_zbc): New
target supports predicate.
(check_effective_target_riscv_zbkb): Likewise.
(check_effective_target_riscv_zbkc): Likewise.
(check_effective_target_zbc_ok): Likewise.
(check_effective_target_zbkb_ok): Likewise.
(check_effective_target_zbkc_ok): Likewise.
(riscv_get_arch): Add zbkb and zbkc support.
* gcc.target/riscv/crc-builtin-zbc32.c: New file.
* gcc.target/riscv/crc-builtin-zbc64.c: Likewise.
Co-author: Jeff Law <jlaw@ventanamicro.com>
Diffstat (limited to 'gcc/expr.cc')
-rw-r--r-- | gcc/expr.cc | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/gcc/expr.cc b/gcc/expr.cc index de25437..70f2ece 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -14178,6 +14178,33 @@ int_expr_size (const_tree exp) return tree_to_shwi (size); } +/* Return the quotient of polynomial long division of x^2N by POLYNOMIAL + in GF (2^N). + Author: Richard Sandiford <richard.sandiford@arm.com> */ + +unsigned HOST_WIDE_INT +gf2n_poly_long_div_quotient (unsigned HOST_WIDE_INT polynomial, + unsigned short n) +{ + /* The result has degree N, so needs N + 1 bits. */ + gcc_assert (n < 64); + + /* Perform a division step for the x^2N coefficient. At this point the + quotient and remainder have N implicit trailing zeros. */ + unsigned HOST_WIDE_INT quotient = 1; + unsigned HOST_WIDE_INT remainder = polynomial; + + /* Process the coefficients for x^(2N-1) down to x^N, with each step + reducing the number of implicit trailing zeros by one. */ + for (unsigned int i = 0; i < n; ++i) + { + bool coeff = remainder & (HOST_WIDE_INT_1U << (n - 1)); + quotient = (quotient << 1) | coeff; + remainder = (remainder << 1) ^ (coeff ? polynomial : 0); + } + return quotient; +} + /* Calculate CRC for the initial CRC and given POLYNOMIAL. CRC_BITS is CRC size. */ |