Debian Codegraph @

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

raw
1 /* { dg-do run } */
2 /* { dg-options "-fdump-tree-crc-details" } */
3 /* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */
4
5 #include <stdlib.h>
6
7 __attribute__ ((noinline,optimize(0)))
8 unsigned short calc_crc_O0 (unsigned short crc, unsigned char data)
9 {
10 unsigned int i, j, org, dst;
11 org = data;
12 dst = 0;
13
14 for (i = 0; i < 8; i++) {
15 org <<= 1;
16 dst >>= 1;
17 if (org & 0x100)
18 dst |= 0x80;
19 }
20 data = (unsigned char) dst;
21 crc ^= (unsigned int) data << (16 - 8);
22 for (j = 0; j < 8; j++) {
23 if (crc & 0x8000U)
24 crc = (crc << 1) ^ 0x1021U ;
25 else
26 crc <<= 1 ;
27 }
28 return crc;
29 }
30
31 unsigned short calc_crc (unsigned short crc, unsigned char data)
32 {
33 unsigned int i, j, org, dst;
34 org = data;
35 dst = 0;
36
37 for (i = 0; i < 8; i++) {
38 org <<= 1;
39 dst >>= 1;
40 if (org & 0x100)
41 dst |= 0x80;
42 }
43 data = (unsigned char) dst;
44 crc ^= (unsigned int) data << (16 - 8);
45 for (j = 0; j < 8; j++) {
46 if (crc & 0x8000U)
47 crc = (crc << 1) ^ 0x1021U ;
48 else
49 crc <<= 1 ;
50 }
51 return crc;
52 }
53
54
55 int main ()
56 {
57 unsigned short crc = 0x0D80;
58 for (unsigned char i = 0; i < 255; i++)
59 {
60 unsigned short res1 = calc_crc_O0 (crc, i);
61 unsigned short res2 = calc_crc (crc, i);
62 if (res1 != res2)
63 __builtin_abort ();
64 crc = res1;
65 }
66 __builtin_exit (0);
67 }
68 /* { dg-final { scan-tree-dump "calc_crc function maybe contains CRC calculation." "crc" } } */
69 /* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc" } } */
70 /* { dg-final { scan-tree-dump "Bit forward" "crc"} } */
71 /* { dg-final { scan-tree-dump-times "Polynomial's value is \\\{\[0, \]*1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1\\\}" 1 "crc"} } */
72 /* { dg-final { scan-tree-dump "calculates CRC!" "crc"} } */
73 /* { dg-final { scan-tree-dump-times "Couldn't generate faster CRC code." 0 "crc"} } */