Debian Codegraph @

gcc/testsuite/gcc.dg/torture/crc-26.c

raw
1 /* { dg-do run } */
2 /* { dg-options "-fdump-tree-crc-details" } */
3 /* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-g" "-Os" "-funroll-loops" "-fpeel-loops" "-flto" } } */
4 /* { dg-require-effective-target int32plus } */
5
6 //Test from roms/u-boot-sam460ex/drivers/mtd/ubi/crc32.c
7 #include <stdint.h>
8 #include <stdlib.h>
9
10 typedef uint8_t u8;
11 typedef uint32_t u32;
12 #define CRCPOLY_LE 0xedb88320
13
14 __attribute__ ((noinline,optimize(0)))
15 u32 crc32_le_O0 (u32 crc, unsigned char const *p, size_t len)
16 {
17 int i;
18 while (len--) {
19 crc ^= *p++;
20 for (i = 0; i < 8; i++)
21 crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
22 }
23 return crc;
24 }
25
26 u32 crc32_le (u32 crc, unsigned char const *p, size_t len)
27 {
28 int i;
29 while (len--) {
30 crc ^= *p++;
31 for (i = 0; i < 8; i++)
32 crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
33 }
34 return crc;
35 }
36
37
38 int main ()
39 {
40 u32 crc = 0x0D800D80;
41 unsigned char st[2] = {'H','i'};
42 for (unsigned char i = 0; i < 255; i++)
43 {
44 st[0] = i;
45 u32 res1 = crc32_le_O0 (crc, st, 2);
46 u32 res2 = crc32_le (crc, st, 2);
47 if (res1 != res2)
48 __builtin_abort ();
49 crc = res1;
50 }
51 __builtin_exit (0);
52 }
53 /* { dg-final { scan-tree-dump "function maybe contains CRC calculation." "crc" } } */
54 /* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc"} } */
55 /* { dg-final { scan-tree-dump "Bit reversed" "crc"} } */
56 /* { dg-final { scan-tree-dump "calculates CRC!" "crc"} } */
57 /* { dg-final { scan-tree-dump-times "Couldn't generate faster CRC code." 0 "crc"} } */