On 11/9/24 11:39 AM, Mariam Arutunian wrote:
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.

   gcc/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.
      * iterators.md (SUBX1, ANYI1): New iterators.
     * riscv-protos.h (generate_reflecting_code_using_brev): New function declaration.
      (expand_crc_using_clmul): Likewise.
      (expand_reversed_crc_using_clmul): Likewise.
      * riscv.cc (generate_reflecting_code_using_brev): New function.
      (expand_crc_using_clmul): Likewise.
      (expand_reversed_crc_using_clmul): Likewise.
      * riscv.md (UNSPEC_CRC, UNSPEC_CRC_REV):  New unspecs.

   gcc/testsuite/gcc.target/riscv/

         * crc-1-zbc.c: New test.
         * crc-1-zbkc.c: Likewise.
         * crc-10-zbc.c: Likewise.
         * crc-10-zbkc.c: Likewise.
         * crc-12-zbc.c: Likewise.
         * crc-12-zbkc.c: Likewise.
         * crc-13-zbc.c: Likewise.
         * crc-13-zbkc.c: Likewise.
         * crc-14-zbc.c: Likewise.
         * crc-14-zbkc.c: Likewise.
         * crc-17-zbc.c: Likewise.
         * crc-17-zbkc.c: Likewise.
         * crc-18-zbc.c: Likewise.
         * crc-18-zbkc.c: Likewise.
         * crc-21-zbc.c: Likewise.
         * crc-21-zbkc.c: Likewise.
         * crc-22-rv64-zbc.c: Likewise.
         * crc-22-rv64-zbkb.c: Likewise.
         * crc-22-rv64-zbkc.c: Likewise.
         * crc-23-zbc.c: Likewise.
         * crc-23-zbkc.c: Likewise.
         * crc-4-zbc.c: Likewise.
         * crc-4-zbkb.c: Likewise.
         * crc-4-zbkc.c: Likewise.
         * crc-5-zbc.c: Likewise.
         * crc-5-zbkb.c: Likewise.
         * crc-5-zbkc.c: Likewise.
         * crc-6-zbc.c: Likewise.
         * crc-6-zbkc.c: Likewise.
         * crc-7-zbc.c: Likewise.
         * crc-7-zbkc.c: Likewise.
         * crc-8-zbc.c: Likewise.
         * crc-8-zbkb.c: Likewise.
         * crc-8-zbkc.c: Likewise.
         * crc-9-zbc.c: Likewise.
         * crc-9-zbkc.c: Likewise.
         * crc-CCIT-data16-zbc.c: Likewise.
         * crc-CCIT-data16-zbkc.c: Likewise.
         * crc-CCIT-data8-zbc.c: Likewise.
         * crc-CCIT-data8-zbkc.c: Likewise.
         * crc-coremark-16bitdata-zbc.c: Likewise.
         * crc-coremark-16bitdata-zbkc.c: Likewise.


+
+
+/* Generate assembly to calculate CRC using clmul instruction.
+   The following code will be generated when the CRC and data sizes are equal:
+     li      a4,quotient
+     li      a5,polynomial
+     xor     a0,a1,a0
+     clmul   a0,a0,a4
+     srli    a0,a0,crc_size
+     clmul   a0,a0,a5
+     slli    a0,a0,word_mode_size - crc_size
+     srli    a0,a0,word_mode_size - crc_size
Not something you need to change. Aren't the final two instructions here just a zero extension?

I suspect combine would pick this up. So it's probably not worth adding more conditionals in expander.





\ No newline at end of file
diff --git a/gcc/testsuite/gcc.target/riscv/crc-1-zbkc.c 
b/gcc/testsuite/gcc.target/riscv/crc-1-zbkc.c
new file mode 100644
index 00000000000..8c627c0431a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/crc-1-zbkc.c
@@ -0,0 +1,11 @@
+/* { dg-do run } */
+/* { dg-options "-fdump-tree-crc -fdump-rtl-dfinish  -fdisable-tree-phiopt2 
-fdisable-tree-phiopt3" } */
+/* { dg-additional-options "-march=rv64gc_zbkc" { target { rv64 } } } */
+/* { dg-additional-options "-march=rv32gc_zbkc" { target { rv32 } } } */
So I think we probably need to add a bit of code to the testsuite. Essentially we don't want to run this test on targets that don't have zbkc support.

I think we probably end up wanting something similar to what we do with vector where we have a test to tell us when V is supported. I'm planning to pick that up. Similarly I think we want to do something similar for Zbc.


Jeff

Reply via email to