On 9/13/24 5:05 AM, Mariam Arutunian wrote:

This patch introduces two new expanders for the i386 backend,
dedicated to generating optimized code for CRC computations.
The new expanders are designed to leverage specific hardware capabilities to achieve faster CRC calculations, particularly using the pclmulqdq or crc32 instructions when supported by the target architecture.

Expander 1: Bit-Forward CRC (crc<SWI124dup:mode><SWI124:mode>4)
For targets that support both pclmulqdq instruction (TARGET_PCLMUL) and are 64-bit (TARGET_64BIT), the expander will generate code that uses the pclmulqdq instruction for CRC computation.

Expander 2: Bit-Reversed CRC (crc_rev<SWI124dup:mode><SWI124:mode>4)
The expander first checks if the target supports the CRC32 instruction set (TARGET_CRC32)
and the polynomial in use is 0x1EDC6F41 (iSCSI). If the conditions are met,
it emits calls to the corresponding crc32 instruction (crc32b, crc32w, or crc32l depending on the data size). If the target does not support crc32 but supports pclmulqdq, it then uses the pclmulqdq instruction for bit-reversed CRC computation.

Otherwise table-based CRC is generated.

   gcc/config/i386/

    * i386-protos.h (ix86_expand_crc_using_pclmul): New extern function declaration.
     (ix86_expand_reversed_crc_using_pclmul):  Likewise.
     * i386.cc (ix86_expand_crc_using_pclmul): New function.
     (ix86_expand_reversed_crc_using_pclmul):  Likewise.
     * i386.md (UNSPEC_CRC, UNSPEC_CRC_REV):  New unspecs.
     (SWI124dup): New iterator.
     (crc<SWI124dup:mode><SWI124:mode>4): New expander for bit-forward CRC.
     (crc_rev<SWI124dup:mode><SWI124:mode>4): New expander for reversed CRC.

   gcc/testsuite/gcc.target/i386/

     * crc-crc32-data16.c: New test.
     * crc-crc32-data32.c: Likewise.
     * crc-crc32-data8.c: Likewise.
     * crc-1-pclmul.c: Likewise.
     * crc-10-pclmul.c: Likewise.
     * crc-12-pclmul.c: Likewise.
     * crc-13-pclmul.c: Likewise.
     * crc-14-pclmul.c: Likewise.
     * crc-17-pclmul.c: Likewise.
     * crc-18-pclmul.c: Likewise.
     * crc-21-pclmul.c: Likewise.
     * crc-22-pclmul.c: Likewise.
     * crc-23-pclmul.c: Likewise.
     * crc-4-pclmul.c: Likewise.
     * crc-5-pclmul.c: Likewise.
     * crc-6-pclmul.c: Likewise.
     * crc-7-pclmul.c: Likewise.
     * crc-8-pclmul.c: Likewise.
     * crc-9-pclmul.c: Likewise.
     * crc-CCIT-data16-pclmul.c: Likewise.
     * crc-CCIT-data8-pclmul.c: Likewise.
     * crc-coremark-16bitdata-pclmul.c: Likewise.
This is OK.

jeff

Reply via email to