On Thu, Aug 27, 2026 at 9:19 AM Andrea Pinski < [email protected]> wrote:
> On Sat, Aug 22, 2026 at 8:36 PM Shreesh Adiga > <[email protected]> wrote: > > > > This change attempts to compute the various __builtin_crc and rev_crc > > functions when all the arguments are compile-time known constants using > > simple CRC loop calculation at compile-time and avoid emitting the table > > based computation. > > > > Architecture specific CRC builtin folding will be done later as a follow > > up. > > > > gcc/ChangeLog: > > > > * fold-const-call.cc (fold_const_crc): new function to fold crc > > (fold_const_call): invoke fold_const_crc to fold builtin crc > > > > gcc/testsuite/ChangeLog: > > > > * gcc.dg/crc-builtin-rev-target32.c: modified test to avoid > > const fold. > > * gcc.dg/crc-builtin-rev-target64.c: likewise. > > * gcc.dg/crc-builtin-target32.c: likewise. > > * gcc.dg/crc-builtin-target64.c: likewise. > > * gcc.target/aarch64/crc-builtin-pmul64.c: likewise. > > * gcc.target/riscv/crc-builtin-zbc32.c: likewise. > > * gcc.target/riscv/crc-builtin-zbc64.c: likewise. > > * gcc.target/riscv/rvv/base/crc-builtin-zvbc.c: likewise. > > * gcc.dg/crc-builtin-const-fold-target32.c: New test. > > * gcc.dg/crc-builtin-const-fold-target64.c: New test. > > > > Signed-off-by: Shreesh Adiga <[email protected]> > > --- > > > > Changes in v3: > > Use the crc functions from hwint.cc > > > > gcc/fold-const-call.cc | 52 ++++++ > > .../gcc.dg/crc-builtin-const-fold-target32.c | 94 +++++++++++ > > .../gcc.dg/crc-builtin-const-fold-target64.c | 156 ++++++++++++++++++ > > .../gcc.dg/crc-builtin-rev-target32.c | 25 +-- > > .../gcc.dg/crc-builtin-rev-target64.c | 45 +++-- > > gcc/testsuite/gcc.dg/crc-builtin-target32.c | 25 +-- > > gcc/testsuite/gcc.dg/crc-builtin-target64.c | 43 +++-- > > .../gcc.target/aarch64/crc-builtin-pmul64.c | 52 +++--- > > .../gcc.target/riscv/crc-builtin-zbc32.c | 13 +- > > .../gcc.target/riscv/crc-builtin-zbc64.c | 49 +++--- > > .../riscv/rvv/base/crc-builtin-zvbc.c | 49 +++--- > > 11 files changed, 454 insertions(+), 149 deletions(-) > > create mode 100644 > gcc/testsuite/gcc.dg/crc-builtin-const-fold-target32.c > > create mode 100644 > gcc/testsuite/gcc.dg/crc-builtin-const-fold-target64.c > > > > diff --git a/gcc/fold-const-call.cc b/gcc/fold-const-call.cc > > index b3a9d7715d6..983273f0b28 100644 > > --- a/gcc/fold-const-call.cc > > +++ b/gcc/fold-const-call.cc > > @@ -2044,6 +2044,35 @@ fold_const_call_1 (combined_fn fn, tree type, > tree arg0, tree arg1, tree arg2) > > return NULL_TREE; > > } > > > > +static tree > > +fold_const_crc (internal_fn fn, tree type, tree crc_arg, tree data_arg, > > + tree polynomial_arg) > > +{ > > + if (!integer_cst_p (crc_arg) > > + || !integer_cst_p (data_arg) > > + || !integer_cst_p (polynomial_arg)) > > + return NULL_TREE; > > + > > + unsigned int crc_bits = TYPE_PRECISION (type); > > + unsigned int data_bits = TYPE_PRECISION (TREE_TYPE (data_arg)); > > + > > + if ((data_bits != 8 && data_bits != 16 && data_bits != 32 && > data_bits != 64) > > + || (crc_bits != 8 && crc_bits != 16 && crc_bits != 32 && crc_bits > != 64) > > + || data_bits > crc_bits) > > + return NULL_TREE; > > + > > + unsigned HOST_WIDE_INT crc = tree_to_uhwi (crc_arg); > > + unsigned HOST_WIDE_INT data = tree_to_uhwi (data_arg); > > + unsigned HOST_WIDE_INT polynomial = tree_to_uhwi (polynomial_arg); > > Can you add a check for tree_fits_uhwi_p for each of the arguments? I > am not 100% sure they will fail but it would be best if there is a > test just in case. > Otherwise this looks good; the other patch is ok and when you come > back with an updated patch here I will push both of them. > > Okay I have sent an updated patch for this commit with the extra checks added. Kindly let me know if instead I should send both patch in a series rather than just updating this second commit here. Thanks, Shreesh > Thanks, > Andrea > > > + > > + if (fn == IFN_CRC_REV) > > + crc = calculate_reversed_crc (crc, data, polynomial, crc_bits, > data_bits); > > + else > > + crc = calculate_crc (crc, data, polynomial, crc_bits, data_bits); > > + > > + return build_int_cstu (type, crc); > > +} > > + > > /* Try to fold FN (ARG0, ARG1, ARG2) to a constant. Return the > constant on > > success, otherwise return null. TYPE is the type of the return > value. */ > > > > @@ -2145,6 +2174,29 @@ fold_const_call (combined_fn fn, tree type, tree > arg0, tree arg1, tree arg2) > > } > > return NULL_TREE; > > > > + case CFN_BUILT_IN_CRC8_DATA8: > > + case CFN_BUILT_IN_CRC16_DATA8: > > + case CFN_BUILT_IN_CRC16_DATA16: > > + case CFN_BUILT_IN_CRC32_DATA8: > > + case CFN_BUILT_IN_CRC32_DATA16: > > + case CFN_BUILT_IN_CRC32_DATA32: > > + case CFN_BUILT_IN_CRC64_DATA8: > > + case CFN_BUILT_IN_CRC64_DATA16: > > + case CFN_BUILT_IN_CRC64_DATA32: > > + case CFN_BUILT_IN_CRC64_DATA64: > > + case CFN_BUILT_IN_REV_CRC8_DATA8: > > + case CFN_BUILT_IN_REV_CRC16_DATA8: > > + case CFN_BUILT_IN_REV_CRC16_DATA16: > > + case CFN_BUILT_IN_REV_CRC32_DATA8: > > + case CFN_BUILT_IN_REV_CRC32_DATA16: > > + case CFN_BUILT_IN_REV_CRC32_DATA32: > > + case CFN_BUILT_IN_REV_CRC64_DATA8: > > + case CFN_BUILT_IN_REV_CRC64_DATA16: > > + case CFN_BUILT_IN_REV_CRC64_DATA32: > > + case CFN_BUILT_IN_REV_CRC64_DATA64: > > + return fold_const_crc (associated_internal_fn (fn, type), > > + type, arg0, arg1, arg2); > > + > > default: > > return fold_const_call_1 (fn, type, arg0, arg1, arg2); > > } > > diff --git a/gcc/testsuite/gcc.dg/crc-builtin-const-fold-target32.c > b/gcc/testsuite/gcc.dg/crc-builtin-const-fold-target32.c > > new file mode 100644 > > index 00000000000..00124811161 > > --- /dev/null > > +++ b/gcc/testsuite/gcc.dg/crc-builtin-const-fold-target32.c > > @@ -0,0 +1,94 @@ > > +/* { dg-do compile } */ > > +/* { dg-require-effective-target int32plus } */ > > +/* { dg-additional-options "-O2 -fdump-tree-optimized" } */ > > + > > +#include <stdint.h> > > + > > +uint8_t crc8_data8 () > > +{ > > + return __builtin_crc8_data8 (0x34, 'a', 0x12); > > +} > > + > > +uint16_t crc16_data8 () > > +{ > > + return __builtin_crc16_data8 (0x1234, 'a', 0x1021); > > +} > > + > > +uint16_t crc16_data16 () > > +{ > > + return __builtin_crc16_data16 (0x1234, 0x3214, 0x1021); > > +} > > + > > +uint32_t crc32_data8 () > > +{ > > + return __builtin_crc32_data8 (0xffffffff, 0x32, 0x4002123); > > +} > > + > > +uint32_t crc32_data16 () > > +{ > > + return __builtin_crc32_data16 (0xffffffff, 0x3232, 0x4002123); > > +} > > + > > +uint32_t crc32_data32 () > > +{ > > + return __builtin_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123); > > +} > > + > > +uint8_t rev_crc8_data8 () > > +{ > > + return __builtin_rev_crc8_data8 (0x34, 'a', 0x12); > > +} > > + > > +uint16_t rev_crc16_data8 () > > +{ > > + return __builtin_rev_crc16_data8 (0x1234, 'a', 0x1021); > > +} > > + > > +uint16_t rev_crc16_data16 () > > +{ > > + return __builtin_rev_crc16_data16 (0x1234, 0x3214, 0x1021); > > +} > > + > > +uint32_t rev_crc32_data8 () > > +{ > > + return __builtin_rev_crc32_data8 (0xffffffff, 0x32, 0x4002123); > > +} > > + > > +uint32_t rev_crc32_data16 () > > +{ > > + return __builtin_rev_crc32_data16 (0xffffffff, 0x3232, 0x4002123); > > +} > > + > > +uint32_t rev_crc32_data32 () > > +{ > > + return __builtin_rev_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123); > > +} > > + > > + > > +/* Test that builtin calls are optimized away and not present */ > > +/* { dg-final { scan-tree-dump-not "__builtin_crc8_data8" "optimized" } > } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_crc16_data8" "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_crc16_data16" "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_crc32_data8" "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_crc32_data16" "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_crc32_data32" "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc8_data8" > "optimized" } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc16_data8" > "optimized" } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc16_data16" > "optimized" } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc32_data8" > "optimized" } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc32_data16" > "optimized" } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc32_data32" > "optimized" } } */ > > + > > +/* Test that the builtins are folded to the expected values. */ > > +/* { dg-final { scan-tree-dump-times "return 160;" 1 "optimized" } } */ > > +/* { dg-final { scan-tree-dump-times "return 31476;" 1 "optimized" } } > */ > > +/* { dg-final { scan-tree-dump-times "return 8836;" 1 "optimized" } } */ > > +/* { dg-final { scan-tree-dump-times "return 3353799058;" 1 "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-times "return 1056422874;" 1 "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-times "return 2325894126;" 1 "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-times "return 74;" 1 "optimized" } } */ > > +/* { dg-final { scan-tree-dump-times "return 1338;" 1 "optimized" } } */ > > +/* { dg-final { scan-tree-dump-times "return 561;" 1 "optimized" } } */ > > +/* { dg-final { scan-tree-dump-times "return 3483277276;" 1 "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-times "return 1523773068;" 1 "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-times "return 340857104;" 1 "optimized" > } } */ > > diff --git a/gcc/testsuite/gcc.dg/crc-builtin-const-fold-target64.c > b/gcc/testsuite/gcc.dg/crc-builtin-const-fold-target64.c > > new file mode 100644 > > index 00000000000..ef0c1ba9504 > > --- /dev/null > > +++ b/gcc/testsuite/gcc.dg/crc-builtin-const-fold-target64.c > > @@ -0,0 +1,156 @@ > > +/* { dg-do compile { target lp64 } } */ > > +/* { dg-require-effective-target int32plus } */ > > +/* { dg-additional-options "-O2 -fdump-tree-optimized" } */ > > + > > +#include <stdint.h> > > + > > +uint8_t crc8_data8 () > > +{ > > + return __builtin_crc8_data8 (0x34, 'a', 0x12); > > +} > > + > > +uint16_t crc16_data8 () > > +{ > > + return __builtin_crc16_data8 (0x1234, 'a', 0x1021); > > +} > > + > > +uint16_t crc16_data16 () > > +{ > > + return __builtin_crc16_data16 (0x1234, 0x3214, 0x1021); > > +} > > + > > +uint32_t crc32_data8 () > > +{ > > + return __builtin_crc32_data8 (0xffffffff, 0x32, 0x4002123); > > +} > > + > > +uint32_t crc32_data16 () > > +{ > > + return __builtin_crc32_data16 (0xffffffff, 0x3232, 0x4002123); > > +} > > + > > +uint32_t crc32_data32 () > > +{ > > + return __builtin_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123); > > +} > > + > > +uint64_t crc64_data8 () > > +{ > > + return __builtin_crc64_data8 (0xffffffffffffffff, 0x32, > 0x40021234002123); > > +} > > + > > +uint64_t crc64_data16 () > > +{ > > + return __builtin_crc64_data16 (0xffffffffffffffff, 0x3232, > 0x40021234002123); > > +} > > + > > +uint64_t crc64_data32 () > > +{ > > + return __builtin_crc64_data32 (0xffffffffffffffff, 0x123546ff, > > + 0x40021234002123); > > +} > > + > > +uint64_t crc64_data64 () > > +{ > > + return __builtin_crc64_data64 (0xffffffffffffffff, 0x123546ff123546ff, > > + 0x40021234002123); > > +} > > + > > +uint8_t rev_crc8_data8 () > > +{ > > + return __builtin_rev_crc8_data8 (0x34, 'a', 0x12); > > +} > > + > > +uint16_t rev_crc16_data8 () > > +{ > > + return __builtin_rev_crc16_data8 (0x1234, 'a', 0x1021); > > +} > > + > > +uint16_t rev_crc16_data16 () > > +{ > > + return __builtin_rev_crc16_data16 (0x1234, 0x3214, 0x1021); > > +} > > + > > +uint32_t rev_crc32_data8 () > > +{ > > + return __builtin_rev_crc32_data8 (0xffffffff, 0x32, 0x4002123); > > +} > > + > > +uint32_t rev_crc32_data16 () > > +{ > > + return __builtin_rev_crc32_data16 (0xffffffff, 0x3232, 0x4002123); > > +} > > + > > +uint32_t rev_crc32_data32 () > > +{ > > + return __builtin_rev_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123); > > +} > > + > > +uint64_t rev_crc64_data8 () > > +{ > > + return __builtin_rev_crc64_data8 (0xffffffffffffffff, 0x32, > > + 0x40021234002123); > > +} > > + > > +uint64_t rev_crc64_data16 () > > +{ > > + return __builtin_rev_crc64_data16 (0xffffffffffffffff, 0x3232, > > + 0x40021234002123); > > +} > > + > > +uint64_t rev_crc64_data32 () > > +{ > > + return __builtin_rev_crc64_data32 (0xffffffffffffffff, 0x123546ff, > > + 0x40021234002123); > > +} > > + > > +uint64_t rev_crc64_data64 () > > +{ > > + return __builtin_rev_crc64_data64 (0xffffffffffffffff, > 0x123546ff123546ff, > > + 0x40021234002123); > > +} > > + > > + > > +/* Test that builtin calls are optimized away and not present */ > > +/* { dg-final { scan-tree-dump-not "__builtin_crc8_data8" "optimized" } > } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_crc16_data8" "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_crc16_data16" "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_crc32_data8" "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_crc32_data16" "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_crc32_data32" "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_crc64_data8" "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_crc64_data16" "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_crc64_data32" "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_crc64_data64" "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc8_data8" > "optimized" } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc16_data8" > "optimized" } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc16_data16" > "optimized" } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc32_data8" > "optimized" } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc32_data16" > "optimized" } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc32_data32" > "optimized" } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc64_data8" > "optimized" } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc64_data16" > "optimized" } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc64_data32" > "optimized" } } */ > > +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc64_data64" > "optimized" } } */ > > + > > +/* Test that the builtins are folded to the expected values. */ > > +/* { dg-final { scan-tree-dump-times "return 160;" 1 "optimized" } } */ > > +/* { dg-final { scan-tree-dump-times "return 31476;" 1 "optimized" } } > */ > > +/* { dg-final { scan-tree-dump-times "return 8836;" 1 "optimized" } } */ > > +/* { dg-final { scan-tree-dump-times "return 3353799058;" 1 "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-times "return 1056422874;" 1 "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-times "return 2325894126;" 1 "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-times "return 14753344481753729783;" 1 > "optimized" } } */ > > +/* { dg-final { scan-tree-dump-times "return 9361103135052257218;" 1 > "optimized" } } */ > > +/* { dg-final { scan-tree-dump-times "return 2386776299826502735;" 1 > "optimized" } } */ > > +/* { dg-final { scan-tree-dump-times "return 16682003383967693607;" 1 > "optimized" } } */ > > +/* { dg-final { scan-tree-dump-times "return 74;" 1 "optimized" } } */ > > +/* { dg-final { scan-tree-dump-times "return 1338;" 1 "optimized" } } */ > > +/* { dg-final { scan-tree-dump-times "return 561;" 1 "optimized" } } */ > > +/* { dg-final { scan-tree-dump-times "return 3483277276;" 1 "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-times "return 1523773068;" 1 "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-times "return 340857104;" 1 "optimized" > } } */ > > +/* { dg-final { scan-tree-dump-times "return 12528055141939117259;" 1 > "optimized" } } */ > > +/* { dg-final { scan-tree-dump-times "return 9375109733926652568;" 1 > "optimized" } } */ > > +/* { dg-final { scan-tree-dump-times "return 13461549257995699439;" 1 > "optimized" } } */ > > +/* { dg-final { scan-tree-dump-times "return 16230122087500358547;" 1 > "optimized" } } */ > > diff --git a/gcc/testsuite/gcc.dg/crc-builtin-rev-target32.c > b/gcc/testsuite/gcc.dg/crc-builtin-rev-target32.c > > index 25dc9a226c3..e729e9efb4b 100644 > > --- a/gcc/testsuite/gcc.dg/crc-builtin-rev-target32.c > > +++ b/gcc/testsuite/gcc.dg/crc-builtin-rev-target32.c > > @@ -4,34 +4,35 @@ > > > > #include <stdint.h> > > > > -int8_t rev_crc8_data8 () > > +/* Due to constant folding, use a runtime arg to confirm crc table > emitting */ > > +int8_t rev_crc8_data8 (int8_t x) > > { > > - return __builtin_rev_crc8_data8 (0x34, 'a', 0x12); > > + return __builtin_rev_crc8_data8 (x, 'a', 0x12); > > } > > > > -int16_t rev_crc16_data8 () > > +int16_t rev_crc16_data8 (int16_t x) > > { > > - return __builtin_rev_crc16_data8 (0x1234, 'a', 0x1021); > > + return __builtin_rev_crc16_data8 (x, 'a', 0x1021); > > } > > > > -int16_t rev_crc16_data16 () > > +int16_t rev_crc16_data16 (int16_t x) > > { > > - return __builtin_rev_crc16_data16 (0x1234, 0x3214, 0x1021); > > + return __builtin_rev_crc16_data16 (x, 0x3214, 0x1021); > > } > > > > -int32_t rev_crc32_data8 () > > +int32_t rev_crc32_data8 (int32_t x) > > { > > - return __builtin_rev_crc32_data8 (0xffffffff, 0x32, 0x4002123); > > + return __builtin_rev_crc32_data8 (x, 0x32, 0x4002123); > > } > > > > -int32_t rev_crc32_data16 () > > +int32_t rev_crc32_data16 (int32_t x) > > { > > - return __builtin_rev_crc32_data16 (0xffffffff, 0x3232, 0x4002123); > > + return __builtin_rev_crc32_data16 (x, 0x3232, 0x4002123); > > } > > > > -int32_t rev_crc32_data32 () > > +int32_t rev_crc32_data32 (int32_t x) > > { > > - return __builtin_rev_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123); > > + return __builtin_rev_crc32_data32 (x, 0x123546ff, 0x4002123); > > } > > > > /* { dg-final { scan-rtl-dump ";; (?:using optab for|emitting reversed > crc table) crc_8_polynomial_0x12" "expand" } } */ > > diff --git a/gcc/testsuite/gcc.dg/crc-builtin-rev-target64.c > b/gcc/testsuite/gcc.dg/crc-builtin-rev-target64.c > > index bc9dfa5b619..b6ef9696314 100644 > > --- a/gcc/testsuite/gcc.dg/crc-builtin-rev-target64.c > > +++ b/gcc/testsuite/gcc.dg/crc-builtin-rev-target64.c > > @@ -4,58 +4,55 @@ > > > > #include <stdint.h> > > > > -int8_t rev_crc8_data8 () > > +/* Due to constant folding, use a runtime arg to confirm crc table > emitting */ > > +int8_t rev_crc8_data8 (int8_t x) > > { > > - return __builtin_rev_crc8_data8 (0x34, 'a', 0x12); > > + return __builtin_rev_crc8_data8 (x, 'a', 0x12); > > } > > > > -int16_t rev_crc16_data8 () > > +int16_t rev_crc16_data8 (int16_t x) > > { > > - return __builtin_rev_crc16_data8 (0x1234, 'a', 0x1021); > > + return __builtin_rev_crc16_data8 (x, 'a', 0x1021); > > } > > > > -int16_t rev_crc16_data16 () > > +int16_t rev_crc16_data16 (int16_t x) > > { > > - return __builtin_rev_crc16_data16 (0x1234, 0x3214, 0x1021); > > + return __builtin_rev_crc16_data16 (x, 0x3214, 0x1021); > > } > > > > -int32_t rev_crc32_data8 () > > +int32_t rev_crc32_data8 (int32_t x) > > { > > - return __builtin_rev_crc32_data8 (0xffffffff, 0x32, 0x4002123); > > + return __builtin_rev_crc32_data8 (x, 0x32, 0x4002123); > > } > > > > -int32_t rev_crc32_data16 () > > +int32_t rev_crc32_data16 (int32_t x) > > { > > - return __builtin_rev_crc32_data16 (0xffffffff, 0x3232, 0x4002123); > > + return __builtin_rev_crc32_data16 (x, 0x3232, 0x4002123); > > } > > > > -int32_t rev_crc32_data32 () > > +int32_t rev_crc32_data32 (int32_t x) > > { > > - return __builtin_rev_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123); > > + return __builtin_rev_crc32_data32 (x, 0x123546ff, 0x4002123); > > } > > > > -int64_t rev_crc64_data8 () > > +int64_t rev_crc64_data8 (int64_t x) > > { > > - return __builtin_rev_crc64_data8 (0xffffffffffffffff, 0x32, > > - 0x40021234002123); > > + return __builtin_rev_crc64_data8 (x, 0x32, 0x40021234002123); > > } > > > > -int64_t rev_crc64_data16 () > > +int64_t rev_crc64_data16 (int64_t x) > > { > > - return __builtin_rev_crc64_data16 (0xffffffffffffffff, 0x3232, > > - 0x40021234002123); > > + return __builtin_rev_crc64_data16 (x, 0x3232, 0x40021234002123); > > } > > > > -int64_t rev_crc64_data32 () > > +int64_t rev_crc64_data32 (int64_t x) > > { > > - return __builtin_rev_crc64_data32 (0xffffffffffffffff, 0x123546ff, > > - 0x40021234002123); > > + return __builtin_rev_crc64_data32 (x, 0x123546ff, 0x40021234002123); > > } > > > > -int64_t rev_crc64_data64 () > > +int64_t rev_crc64_data64 (int64_t x) > > { > > - return __builtin_rev_crc64_data64 (0xffffffffffffffff, > 0x123546ff123546ff, > > - 0x40021234002123); > > + return __builtin_rev_crc64_data64 (x, 0x123546ff123546ff, > 0x40021234002123); > > } > > > > /* { dg-final { scan-rtl-dump ";; (?:using optab for|emitting reversed > crc table) crc_8_polynomial_0x12" "expand" } } */ > > diff --git a/gcc/testsuite/gcc.dg/crc-builtin-target32.c > b/gcc/testsuite/gcc.dg/crc-builtin-target32.c > > index 43db8c96e16..492f3209bbb 100644 > > --- a/gcc/testsuite/gcc.dg/crc-builtin-target32.c > > +++ b/gcc/testsuite/gcc.dg/crc-builtin-target32.c > > @@ -4,34 +4,35 @@ > > > > #include <stdint.h> > > > > -int8_t crc8_data8 () > > +/* Due to constant folding, use a runtime arg to confirm crc table > emitting */ > > +int8_t crc8_data8 (int8_t x) > > { > > - return __builtin_crc8_data8 (0x34, 'a', 0x12); > > + return __builtin_crc8_data8 (x, 'a', 0x12); > > } > > > > -int16_t crc16_data8 () > > +int16_t crc16_data8 (int16_t x) > > { > > - return __builtin_crc16_data8 (0x1234, 'a', 0x1021); > > + return __builtin_crc16_data8 (x, 'a', 0x1021); > > } > > > > -int16_t crc16_data16 () > > +int16_t crc16_data16 (int16_t x) > > { > > - return __builtin_crc16_data16 (0x1234, 0x3214, 0x1021); > > + return __builtin_crc16_data16 (x, 0x3214, 0x1021); > > } > > > > -int32_t crc32_data8 () > > +int32_t crc32_data8 (int32_t x) > > { > > - return __builtin_crc32_data8 (0xffffffff, 0x32, 0x4002123); > > + return __builtin_crc32_data8 (x, 0x32, 0x4002123); > > } > > > > -int32_t crc32_data16 () > > +int32_t crc32_data16 (int32_t x) > > { > > - return __builtin_crc32_data16 (0xffffffff, 0x3232, 0x4002123); > > + return __builtin_crc32_data16 (x, 0x3232, 0x4002123); > > } > > > > -int32_t crc32_data32 () > > +int32_t crc32_data32 (int32_t x) > > { > > - return __builtin_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123); > > + return __builtin_crc32_data32 (x, 0x123546ff, 0x4002123); > > } > > > > /* { dg-final { scan-rtl-dump ";; (?:using optab for|emitting crc > table) crc_8_polynomial_0x12" "expand" } } */ > > diff --git a/gcc/testsuite/gcc.dg/crc-builtin-target64.c > b/gcc/testsuite/gcc.dg/crc-builtin-target64.c > > index 09aa39fcd86..d5040cfe1e0 100644 > > --- a/gcc/testsuite/gcc.dg/crc-builtin-target64.c > > +++ b/gcc/testsuite/gcc.dg/crc-builtin-target64.c > > @@ -4,56 +4,55 @@ > > > > #include <stdint.h> > > > > -int8_t crc8_data8 () > > +/* Due to constant folding, use a runtime arg to confirm crc table > emitting */ > > +int8_t crc8_data8 (int8_t x) > > { > > - return __builtin_crc8_data8 (0x34, 'a', 0x12); > > + return __builtin_crc8_data8 (x, 'a', 0x12); > > } > > > > -int16_t crc16_data8 () > > +int16_t crc16_data8 (int16_t x) > > { > > - return __builtin_crc16_data8 (0x1234, 'a', 0x1021); > > + return __builtin_crc16_data8 (x, 'a', 0x1021); > > } > > > > -int16_t crc16_data16 () > > +int16_t crc16_data16 (int16_t x) > > { > > - return __builtin_crc16_data16 (0x1234, 0x3214, 0x1021); > > + return __builtin_crc16_data16 (x, 0x3214, 0x1021); > > } > > > > -int32_t crc32_data8 () > > +int32_t crc32_data8 (int32_t x) > > { > > - return __builtin_crc32_data8 (0xffffffff, 0x32, 0x4002123); > > + return __builtin_crc32_data8 (x, 0x32, 0x4002123); > > } > > > > -int32_t crc32_data16 () > > +int32_t crc32_data16 (int32_t x) > > { > > - return __builtin_crc32_data16 (0xffffffff, 0x3232, 0x4002123); > > + return __builtin_crc32_data16 (x, 0x3232, 0x4002123); > > } > > > > -int32_t crc32_data32 () > > +int32_t crc32_data32 (int32_t x) > > { > > - return __builtin_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123); > > + return __builtin_crc32_data32 (x, 0x123546ff, 0x4002123); > > } > > > > -int64_t crc64_data8 () > > +int64_t crc64_data8 (int64_t x) > > { > > - return __builtin_crc64_data8 (0xffffffffffffffff, 0x32, > 0x40021234002123); > > + return __builtin_crc64_data8 (x, 0x32, 0x40021234002123); > > } > > > > -int64_t crc64_data16 () > > +int64_t crc64_data16 (int64_t x) > > { > > - return __builtin_crc64_data16 (0xffffffffffffffff, 0x3232, > 0x40021234002123); > > + return __builtin_crc64_data16 (x, 0x3232, 0x40021234002123); > > } > > > > -int64_t crc64_data32 () > > +int64_t crc64_data32 (int64_t x) > > { > > - return __builtin_crc64_data32 (0xffffffffffffffff, 0x123546ff, > > - 0x40021234002123); > > + return __builtin_crc64_data32 (x, 0x123546ff, 0x40021234002123); > > } > > > > -int64_t crc64_data64 () > > +int64_t crc64_data64 (int64_t x) > > { > > - return __builtin_crc64_data64 (0xffffffffffffffff, 0x123546ff123546ff, > > - 0x40021234002123); > > + return __builtin_crc64_data64 (x, 0x123546ff123546ff, > 0x40021234002123); > > } > > > > /* { dg-final { scan-rtl-dump ";; (?:using optab for|emitting crc > table) crc_16_polynomial_0x1021" "expand" } } */ > > diff --git a/gcc/testsuite/gcc.target/aarch64/crc-builtin-pmul64.c > b/gcc/testsuite/gcc.target/aarch64/crc-builtin-pmul64.c > > index cf2fa506981..3363562a5d0 100644 > > --- a/gcc/testsuite/gcc.target/aarch64/crc-builtin-pmul64.c > > +++ b/gcc/testsuite/gcc.target/aarch64/crc-builtin-pmul64.c > > @@ -1,61 +1,63 @@ > > /* { dg-options "-march=armv8-a+crypto" } */ > > > > #include <stdint.h> > > -int8_t crc8_data8 () > > + > > +/* Due to constant folding, use a runtime arg to confirm pmull emitting > */ > > +int8_t crc8_data8 (int8_t x) > > { > > - return __builtin_crc8_data8 ('a', 0xff, 0x12); > > + return __builtin_crc8_data8 (x, 0xff, 0x12); > > } > > -int16_t crc16_data8 () > > +int16_t crc16_data8 (int16_t x) > > { > > - return __builtin_crc16_data8 (0x1234, 'a', 0x1021); > > + return __builtin_crc16_data8 (x, 'a', 0x1021); > > } > > > > -int16_t crc16_data16 () > > +int16_t crc16_data16 (int16_t x) > > { > > - return __builtin_crc16_data16 (0x1234, 0x3214, 0x1021); > > + return __builtin_crc16_data16 (x, 0x3214, 0x1021); > > } > > > > -int32_t crc32_data8 () > > +int32_t crc32_data8 (int32_t x) > > { > > - return __builtin_crc32_data8 (0xffffffff, 0x32, 0x4002123); > > + return __builtin_crc32_data8 (x, 0x32, 0x4002123); > > } > > -int32_t crc32_data16 () > > +int32_t crc32_data16 (int32_t x) > > { > > - return __builtin_crc32_data16 (0xffffffff, 0x3232, 0x4002123); > > + return __builtin_crc32_data16 (x, 0x3232, 0x4002123); > > } > > > > -int32_t crc32_data32 () > > +int32_t crc32_data32 (int32_t x) > > { > > - return __builtin_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123); > > + return __builtin_crc32_data32 (x, 0x123546ff, 0x4002123); > > } > > > > -int8_t rev_crc8_data8 () > > +int8_t rev_crc8_data8 (int8_t x) > > { > > - return __builtin_rev_crc8_data8 (0x34, 'a', 0x12); > > + return __builtin_rev_crc8_data8 (x, 'a', 0x12); > > } > > > > -int16_t rev_crc16_data8 () > > +int16_t rev_crc16_data8 (int16_t x) > > { > > - return __builtin_rev_crc16_data8 (0x1234, 'a', 0x1021); > > + return __builtin_rev_crc16_data8 (x, 'a', 0x1021); > > } > > > > -int16_t rev_crc16_data16 () > > +int16_t rev_crc16_data16 (int16_t x) > > { > > - return __builtin_rev_crc16_data16 (0x1234, 0x3214, 0x1021); > > + return __builtin_rev_crc16_data16 (x, 0x3214, 0x1021); > > } > > > > -int32_t rev_crc32_data8 () > > +int32_t rev_crc32_data8 (int32_t x) > > { > > - return __builtin_rev_crc32_data8 (0xffffffff, 0x32, 0x4002123); > > + return __builtin_rev_crc32_data8 (x, 0x32, 0x4002123); > > } > > > > -int32_t rev_crc32_data16 () > > +int32_t rev_crc32_data16 (int32_t x) > > { > > - return __builtin_rev_crc32_data16 (0xffffffff, 0x3232, 0x4002123); > > + return __builtin_rev_crc32_data16 (x, 0x3232, 0x4002123); > > } > > > > -int32_t rev_crc32_data32 () > > +int32_t rev_crc32_data32 (int32_t x) > > { > > - return __builtin_rev_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123); > > -} > > + return __builtin_rev_crc32_data32 (x, 0x123546ff, 0x4002123); > > +} > > /* { dg-final { scan-assembler-times "pmull" 24 } } */ > > diff --git a/gcc/testsuite/gcc.target/riscv/crc-builtin-zbc32.c > b/gcc/testsuite/gcc.target/riscv/crc-builtin-zbc32.c > > index d4e47608e33..8496555b93d 100644 > > --- a/gcc/testsuite/gcc.target/riscv/crc-builtin-zbc32.c > > +++ b/gcc/testsuite/gcc.target/riscv/crc-builtin-zbc32.c > > @@ -3,19 +3,20 @@ > > > > #include <stdint-gcc.h> > > > > -int8_t crc8_data8 () > > +/* Due to constant folding, use a runtime arg to confirm clmul emitting > */ > > +int8_t crc8_data8 (int8_t x) > > { > > - return __builtin_crc8_data8 (0x34, 'a', 0x12); > > + return __builtin_crc8_data8 (x, 'a', 0x12); > > } > > > > -int16_t crc16_data8 () > > +int16_t crc16_data8 (int16_t x) > > { > > - return __builtin_crc16_data8 (0x1234, 'a', 0x1021); > > + return __builtin_crc16_data8 (x, 'a', 0x1021); > > } > > > > -int16_t crc16_data16 () > > +int16_t crc16_data16 (int16_t x) > > { > > - return __builtin_crc16_data16 (0x1234, 0x3214, 0x1021); > > + return __builtin_crc16_data16 (x, 0x3214, 0x1021); > > } > > > > /* { dg-final { scan-assembler-times "clmul\t" 6 } } */ > > diff --git a/gcc/testsuite/gcc.target/riscv/crc-builtin-zbc64.c > b/gcc/testsuite/gcc.target/riscv/crc-builtin-zbc64.c > > index 298d47b802f..1f46300b140 100644 > > --- a/gcc/testsuite/gcc.target/riscv/crc-builtin-zbc64.c > > +++ b/gcc/testsuite/gcc.target/riscv/crc-builtin-zbc64.c > > @@ -3,64 +3,65 @@ > > > > #include <stdint-gcc.h> > > > > -int8_t crc8_data8 () > > +/* Due to constant folding, use a runtime arg to confirm clmul emitting > */ > > +int8_t crc8_data8 (int8_t x) > > { > > - return __builtin_crc8_data8 (0x34, 'a', 0x12); > > + return __builtin_crc8_data8 (x, 'a', 0x12); > > } > > > > -int16_t crc16_data8 () > > +int16_t crc16_data8 (int16_t x) > > { > > - return __builtin_crc16_data8 (0x1234, 'a', 0x1021); > > + return __builtin_crc16_data8 (x, 'a', 0x1021); > > } > > > > -int16_t crc16_data16 () > > +int16_t crc16_data16 (int16_t x) > > { > > - return __builtin_crc16_data16 (0x1234, 0x3214, 0x1021); > > + return __builtin_crc16_data16 (x, 0x3214, 0x1021); > > } > > > > -int32_t crc32_data8 () > > +int32_t crc32_data8 (int32_t x) > > { > > - return __builtin_crc32_data8 (0xffffffff, 0x32, 0x4002123); > > + return __builtin_crc32_data8 (x, 0x32, 0x4002123); > > } > > > > -int32_t crc32_data16 () > > +int32_t crc32_data16 (int32_t x) > > { > > - return __builtin_crc32_data16 (0xffffffff, 0x3232, 0x4002123); > > + return __builtin_crc32_data16 (x, 0x3232, 0x4002123); > > } > > > > -int32_t crc32_data32 () > > +int32_t crc32_data32 (int32_t x) > > { > > - return __builtin_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123); > > + return __builtin_crc32_data32 (x, 0x123546ff, 0x4002123); > > } > > > > -int8_t rev_crc8_data8 () > > +int8_t rev_crc8_data8 (int8_t x) > > { > > - return __builtin_rev_crc8_data8 (0x34, 'a', 0x12); > > + return __builtin_rev_crc8_data8 (x, 'a', 0x12); > > } > > > > -int16_t rev_crc16_data8 () > > +int16_t rev_crc16_data8 (int16_t x) > > { > > - return __builtin_rev_crc16_data8 (0x1234, 'a', 0x1021); > > + return __builtin_rev_crc16_data8 (x, 'a', 0x1021); > > } > > > > -int16_t rev_crc16_data16 () > > +int16_t rev_crc16_data16 (int16_t x) > > { > > - return __builtin_rev_crc16_data16 (0x1234, 0x3214, 0x1021); > > + return __builtin_rev_crc16_data16 (x, 0x3214, 0x1021); > > } > > > > -int32_t rev_crc32_data8 () > > +int32_t rev_crc32_data8 (int32_t x) > > { > > - return __builtin_rev_crc32_data8 (0xffffffff, 0x32, 0x4002123); > > + return __builtin_rev_crc32_data8 (x, 0x32, 0x4002123); > > } > > > > -int32_t rev_crc32_data16 () > > +int32_t rev_crc32_data16 (int32_t x) > > { > > - return __builtin_rev_crc32_data16 (0xffffffff, 0x3232, 0x4002123); > > + return __builtin_rev_crc32_data16 (x, 0x3232, 0x4002123); > > } > > > > -int32_t rev_crc32_data32 () > > +int32_t rev_crc32_data32 (int32_t x) > > { > > - return __builtin_rev_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123); > > + return __builtin_rev_crc32_data32 (x, 0x123546ff, 0x4002123); > > } > > /* { dg-final { scan-assembler-times "clmul\t" 18 } } */ > > /* { dg-final { scan-assembler-times "clmulh" 6 } } */ > > diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/crc-builtin-zvbc.c > b/gcc/testsuite/gcc.target/riscv/rvv/base/crc-builtin-zvbc.c > > index 2d5fa88acc9..16c550e2e5a 100644 > > --- a/gcc/testsuite/gcc.target/riscv/rvv/base/crc-builtin-zvbc.c > > +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/crc-builtin-zvbc.c > > @@ -3,64 +3,65 @@ > > > > #include <stdint-gcc.h> > > > > -int8_t crc8_data8 () > > +/* Due to constant folding, use a runtime arg to confirm clmul emitting > */ > > +int8_t crc8_data8 (int8_t x) > > { > > - return __builtin_crc8_data8 (0x34, 'a', 0x12); > > + return __builtin_crc8_data8 (x, 'a', 0x12); > > } > > > > -int16_t crc16_data8 () > > +int16_t crc16_data8 (int16_t x) > > { > > - return __builtin_crc16_data8 (0x1234, 'a', 0x1021); > > + return __builtin_crc16_data8 (x, 'a', 0x1021); > > } > > > > -int16_t crc16_data16 () > > +int16_t crc16_data16 (int16_t x) > > { > > - return __builtin_crc16_data16 (0x1234, 0x3214, 0x1021); > > + return __builtin_crc16_data16 (x, 0x3214, 0x1021); > > } > > > > -int32_t crc32_data8 () > > +int32_t crc32_data8 (int32_t x) > > { > > - return __builtin_crc32_data8 (0xffffffff, 0x32, 0x4002123); > > + return __builtin_crc32_data8 (x, 0x32, 0x4002123); > > } > > > > -int32_t crc32_data16 () > > +int32_t crc32_data16 (int32_t x) > > { > > - return __builtin_crc32_data16 (0xffffffff, 0x3232, 0x4002123); > > + return __builtin_crc32_data16 (x, 0x3232, 0x4002123); > > } > > > > -int32_t crc32_data32 () > > +int32_t crc32_data32 (int32_t x) > > { > > - return __builtin_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123); > > + return __builtin_crc32_data32 (x, 0x123546ff, 0x4002123); > > } > > > > -int8_t rev_crc8_data8 () > > +int8_t rev_crc8_data8 (int8_t x) > > { > > - return __builtin_rev_crc8_data8 (0x34, 'a', 0x12); > > + return __builtin_rev_crc8_data8 (x, 'a', 0x12); > > } > > > > -int16_t rev_crc16_data8 () > > +int16_t rev_crc16_data8 (int16_t x) > > { > > - return __builtin_rev_crc16_data8 (0x1234, 'a', 0x1021); > > + return __builtin_rev_crc16_data8 (x, 'a', 0x1021); > > } > > > > -int16_t rev_crc16_data16 () > > +int16_t rev_crc16_data16 (int16_t x) > > { > > - return __builtin_rev_crc16_data16 (0x1234, 0x3214, 0x1021); > > + return __builtin_rev_crc16_data16 (x, 0x3214, 0x1021); > > } > > > > -int32_t rev_crc32_data8 () > > +int32_t rev_crc32_data8 (int32_t x) > > { > > - return __builtin_rev_crc32_data8 (0xffffffff, 0x32, 0x4002123); > > + return __builtin_rev_crc32_data8 (x, 0x32, 0x4002123); > > } > > > > -int32_t rev_crc32_data16 () > > +int32_t rev_crc32_data16 (int32_t x) > > { > > - return __builtin_rev_crc32_data16 (0xffffffff, 0x3232, 0x4002123); > > + return __builtin_rev_crc32_data16 (x, 0x3232, 0x4002123); > > } > > > > -int32_t rev_crc32_data32 () > > +int32_t rev_crc32_data32 (int32_t x) > > { > > - return __builtin_rev_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123); > > + return __builtin_rev_crc32_data32 (x, 0x123546ff, 0x4002123); > > } > > /* { dg-final { scan-assembler-times "vclmul.vx" 12 } } */ > > /* { dg-final { scan-assembler-times "vclmulh.vx" 12 } } */ > > -- > > 2.54.0 > > >
