Debian Codegraph @

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

raw
1 /* { dg-do run } */
2 /* { dg-options "-fdump-tree-crc-details -ftree-cselim" } */
3 /* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-g" "-Os" "-flto" } } */
4 /* { dg-require-effective-target int32plus } */
5
6 // Modified example from crc-from-fedora-packages-24.c
7
8 #include <stdint.h>
9 #include <stdlib.h>
10
11 __attribute__ ((noinline,optimize(0)))
12 void crc_byte_O0 (const char data, uint16_t *crc16)
13 {
14 int k;
15 uint16_t c,d ;
16
17 c = data << 8 ;
18 d = c;
19
20 for (k = 0; k < 16; k++) {
21 *crc16 = (c & 0x8000) ^ *crc16;
22
23 if (*crc16 & 0x8000) {
24 *crc16 = *crc16 << 1;
25 *crc16 = *crc16 ^ 0x8005;
26 } else
27 *crc16 = *crc16 << 1;
28
29 d = d << 1;
30 c = d;
31 }
32 }
33
34 void crc_byte (const char data, uint16_t *crc16)
35 {
36 int k;
37 uint16_t c,d ;
38
39 c = data << 8 ;
40 d = c;
41
42 for (k = 0; k < 16; k++) {
43 *crc16 = (c & 0x8000) ^ *crc16;
44
45 if (*crc16 & 0x8000) {
46 *crc16 = *crc16 << 1;
47 *crc16 = *crc16 ^ 0x8005;
48 } else
49 *crc16 = *crc16 << 1;
50
51 d = d << 1;
52 c = d;
53 }
54 }
55
56 int main ()
57 {
58 uint16_t crc = 0x0D80;
59 for (char i = 0; i < 127; i++)
60 {
61 uint16_t res1 = crc, res2 = crc;
62 crc_byte_O0 (i, &res1);
63 crc_byte (i, &res2);
64
65 if (res1 != res2)
66 __builtin_abort ();
67 crc = res1;
68 }
69 __builtin_exit (0);
70 }
71
72 /* { dg-final { scan-tree-dump "function maybe contains CRC calculation." "crc" } } */
73 /* { dg-final { scan-tree-dump "Loop iteration number is 15" "crc"} } */
74 /* { dg-final { scan-tree-dump "Bit forward" "crc"} } */
75 /* { dg-final { scan-tree-dump "calculates CRC!" "crc"} } */
76 /* { dg-final { scan-tree-dump-times "Couldn't generate faster CRC code." 0 "crc"} } */