This patch introduces new built-in functions to GCC for computing
bit-forward and bit-reversed CRCs.
These builtins aim to provide efficient CRC calculation capabilities.
When the target architecture supports CRC operations (as indicated
by the presence of a CRC optab),
the builtins will utilize the expander to generate CRC code.
In the absence of hardware support, the builtins default to
generating code for a table-based CRC calculation.
The built-ins are defined as follows:
__builtin_rev_crc16_data8,
__builtin_rev_crc32_data8, __builtin_rev_crc32_data16,
__builtin_rev_crc32_data32
__builtin_rev_crc64_data8, __builtin_rev_crc64_data16,
__builtin_rev_crc64_data32, __builtin_rev_crc64_data64,
__builtin_crc8_data8,
__builtin_crc16_data16, __builtin_crc16_data8,
__builtin_crc32_data8, __builtin_crc32_data16, __builtin_crc32_data32,
__builtin_crc64_data8, __builtin_crc64_data16,
__builtin_crc64_data32, __builtin_crc64_data64
Each built-in takes three parameters:
crc: The initial CRC value.
data: The data to be processed.
polynomial: The CRC polynomial without the leading 1.
To validate the correctness of these built-ins, this patch also
includes additions to the GCC testsuite.
This enhancement allows GCC to offer developers high-performance CRC
computation options
that automatically adapt to the capabilities of the target hardware.
Co-authored-by: Joern Rennecke <joern.renne...@embecosm.com
<mailto:joern.renne...@embecosm.com>>
Not complete. May continue the work if these built-ins are needed.
gcc/
* builtin-types.def (BT_FN_UINT8_UINT8_UINT8_CONST_SIZE):
Define.
(BT_FN_UINT16_UINT16_UINT8_CONST_SIZE): Likewise.
(BT_FN_UINT16_UINT16_UINT16_CONST_SIZE): Likewise.
(BT_FN_UINT32_UINT32_UINT8_CONST_SIZE): Likewise.
(BT_FN_UINT32_UINT32_UINT16_CONST_SIZE): Likewise.
(BT_FN_UINT32_UINT32_UINT32_CONST_SIZE): Likewise.
(BT_FN_UINT64_UINT64_UINT8_CONST_SIZE): Likewise.
(BT_FN_UINT64_UINT64_UINT16_CONST_SIZE): Likewise.
(BT_FN_UINT64_UINT64_UINT32_CONST_SIZE): Likewise.
(BT_FN_UINT64_UINT64_UINT64_CONST_SIZE): Likewise.
* builtins.cc (associated_internal_fn): Handle
BUILT_IN_CRC8_DATA8,
BUILT_IN_CRC16_DATA8, BUILT_IN_CRC16_DATA16,
BUILT_IN_CRC32_DATA8, BUILT_IN_CRC32_DATA16,
BUILT_IN_CRC32_DATA32,
BUILT_IN_CRC64_DATA8, BUILT_IN_CRC64_DATA16,
BUILT_IN_CRC64_DATA32,
BUILT_IN_CRC64_DATA64,
BUILT_IN_REV_CRC8_DATA8,
BUILT_IN_REV_CRC16_DATA8, BUILT_IN_REV_CRC16_DATA16,
BUILT_IN_REV_CRC32_DATA8, BUILT_IN_REV_CRC32_DATA16,
BUILT_IN_REV_CRC32_DATA32.
(expand_builtin_crc_table_based): New function.
(expand_builtin): Handle BUILT_IN_CRC8_DATA8,
BUILT_IN_CRC16_DATA8, BUILT_IN_CRC16_DATA16,
BUILT_IN_CRC32_DATA8, BUILT_IN_CRC32_DATA16,
BUILT_IN_CRC32_DATA32,
BUILT_IN_CRC64_DATA8, BUILT_IN_CRC64_DATA16,
BUILT_IN_CRC64_DATA32,
BUILT_IN_CRC64_DATA64,
BUILT_IN_REV_CRC8_DATA8,
BUILT_IN_REV_CRC16_DATA8, BUILT_IN_REV_CRC16_DATA16,
BUILT_IN_REV_CRC32_DATA8, BUILT_IN_REV_CRC32_DATA16,
BUILT_IN_REV_CRC32_DATA32,
BUILT_IN_REV_CRC64_DATA8, BUILT_IN_REV_CRC64_DATA16,
BUILT_IN_REV_CRC64_DATA32,
BUILT_IN_REV_CRC64_DATA64.
* builtins.def (BUILT_IN_CRC8_DATA8): New builtin.
(BUILT_IN_CRC16_DATA8): Likewise.
(BUILT_IN_CRC16_DATA16): Likewise.
(BUILT_IN_CRC32_DATA8): Likewise.
(BUILT_IN_CRC32_DATA16): Likewise.
(BUILT_IN_CRC32_DATA32): Likewise.
(BUILT_IN_CRC64_DATA8): Likewise.
(BUILT_IN_CRC64_DATA16): Likewise.
(BUILT_IN_CRC64_DATA32): Likewise.
(BUILT_IN_CRC64_DATA64): Likewise.
(BUILT_IN_REV_CRC8_DATA8): New builtin.
(BUILT_IN_REV_CRC16_DATA8): Likewise.
(BUILT_IN_REV_CRC16_DATA16): Likewise.
(BUILT_IN_REV_CRC32_DATA8): Likewise.
(BUILT_IN_REV_CRC32_DATA16): Likewise.
(BUILT_IN_REV_CRC32_DATA32): Likewise.
(BUILT_IN_REV_CRC64_DATA8): Likewise.
(BUILT_IN_REV_CRC64_DATA16): Likewise.
(BUILT_IN_REV_CRC64_DATA32): Likewise.
(BUILT_IN_REV_CRC64_DATA64): Likewise.
* builtins.h (expand_builtin_crc_table_based): New
function declaration.
* doc/extend.texti (__builtin_rev_crc8_data8,
__builtin_rev_crc16_data16, __builtin_rev_crc16_data8,
__builtin_rev_crc32_data32, __builtin_rev_crc32_data8,
__builtin_rev_crc32_data16, __builtin_rev_crc64_data64,
__builtin_rev_crc64_data8, __builtin_rev_crc64_data16,
__builtin_rev_crc64_data32, __builtin_crc8_data8,
__builtin_crc16_data16, __builtin_crc16_data8,
__builtin_crc32_data32, __builtin_crc32_data8,
__builtin_crc32_data16, __builtin_crc64_data64,
__builtin_crc64_data8, __builtin_crc64_data16,
__builtin_crc64_data32): Document.
gcc/testsuite/
(BT_FN_UINT64_UINT64_UINT64_CONST_SIZE): Likewise.
* builtins.cc (associated_internal_fn): Handle
BUILT_IN_CRC8_DATA8,
BUILT_IN_CRC16_DATA8, BUILT_IN_CRC16_DATA16,
BUILT_IN_CRC32_DATA8, BUILT_IN_CRC32_DATA16,
BUILT_IN_CRC32_DATA32,
BUILT_IN_CRC64_DATA8, BUILT_IN_CRC64_DATA16,
BUILT_IN_CRC64_DATA32,
BUILT_IN_CRC64_DATA64,
BUILT_IN_REV_CRC8_DATA8,
BUILT_IN_REV_CRC16_DATA8, BUILT_IN_REV_CRC16_DATA16,
BUILT_IN_REV_CRC32_DATA8, BUILT_IN_REV_CRC32_DATA16,
BUILT_IN_REV_CRC32_DATA32.
(expand_builtin_crc_table_based): New function.
(expand_builtin): Handle BUILT_IN_CRC8_DATA8,
BUILT_IN_CRC16_DATA8, BUILT_IN_CRC16_DATA16,
BUILT_IN_CRC32_DATA8, BUILT_IN_CRC32_DATA16,
BUILT_IN_CRC32_DATA32,
BUILT_IN_CRC64_DATA8, BUILT_IN_CRC64_DATA16,
BUILT_IN_CRC64_DATA32,
BUILT_IN_CRC64_DATA64,
BUILT_IN_REV_CRC8_DATA8,
BUILT_IN_REV_CRC16_DATA8, BUILT_IN_REV_CRC16_DATA16,
BUILT_IN_REV_CRC32_DATA8, BUILT_IN_REV_CRC32_DATA16,
BUILT_IN_REV_CRC32_DATA32,
BUILT_IN_REV_CRC64_DATA8, BUILT_IN_REV_CRC64_DATA16,
BUILT_IN_REV_CRC64_DATA32,
BUILT_IN_REV_CRC64_DATA64.
* builtins.def (BUILT_IN_CRC8_DATA8): New builtin.
(BUILT_IN_CRC16_DATA8): Likewise.
(BUILT_IN_CRC16_DATA16): Likewise.
(BUILT_IN_CRC32_DATA8): Likewise.
(BUILT_IN_CRC32_DATA16): Likewise.
(BUILT_IN_CRC32_DATA32): Likewise.
(BUILT_IN_CRC64_DATA8): Likewise.
(BUILT_IN_CRC64_DATA16): Likewise.
(BUILT_IN_CRC64_DATA32): Likewise.
(BUILT_IN_CRC64_DATA64): Likewise.
(BUILT_IN_REV_CRC8_DATA8): New builtin.
(BUILT_IN_REV_CRC16_DATA8): Likewise.
(BUILT_IN_REV_CRC16_DATA16): Likewise.
(BUILT_IN_REV_CRC32_DATA8): Likewise.
(BUILT_IN_REV_CRC32_DATA16): Likewise.
(BUILT_IN_REV_CRC32_DATA32): Likewise.
(BUILT_IN_REV_CRC64_DATA8): Likewise.
(BUILT_IN_REV_CRC64_DATA16): Likewise.
(BUILT_IN_REV_CRC64_DATA32): Likewise.
(BUILT_IN_REV_CRC64_DATA64): Likewise.
* builtins.h (expand_builtin_crc_table_based): New
function declaration.
* doc/extend.texti (__builtin_rev_crc8_data8,
__builtin_rev_crc16_data16, __builtin_rev_crc16_data8,
__builtin_rev_crc32_data32, __builtin_rev_crc32_data8,
__builtin_rev_crc32_data16, __builtin_rev_crc64_data64,
__builtin_rev_crc64_data8, __builtin_rev_crc64_data16,
__builtin_rev_crc64_data32, __builtin_crc8_data8,
__builtin_crc16_data16, __builtin_crc16_data8,
__builtin_crc32_data32, __builtin_crc32_data8,
__builtin_crc32_data16, __builtin_crc64_data64,
__builtin_crc64_data8, __builtin_crc64_data16,
__builtin_crc64_data32): Document.
gcc/testsuite/
* gcc.dg/crc-builtin-rev-target32.c
* gcc.dg/crc-builtin-rev-target64.c
* gcc.dg/crc-builtin-target32.c
* gcc.dg/crc-builtin-target64.c
Signed-off-by: Mariam Arutunian <mariamarutun...@gmail.com
<mailto:mariamarutun...@gmail.com>>