Debian Codegraph @

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

raw
1 /* { dg-do run } */
2 /* { dg-options "-fdump-tree-crc-details" } */
3 /* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */
4 /* { dg-require-effective-target int32plus } */
5
6 #include <stdlib.h>
7
8 __attribute__ ((noinline,optimize(0)))
9 unsigned short crc16_O0 (unsigned char newByte, unsigned short crcValue) {
10 unsigned char i;
11
12 for (i = 0; i < 8; i++) {
13
14 if (((crcValue & 0x8000) >> 8) ^ (newByte & 0x80)) {
15 crcValue = (crcValue << 1) ^ 0x102;
16 } else {
17 crcValue = (crcValue << 1);
18 }
19
20 newByte <<= 1;
21 }
22
23 return crcValue;
24 }
25
26 unsigned short crc16 (unsigned char newByte, unsigned short crcValue) {
27 unsigned char i;
28
29 for (i = 0; i < 8; i++) {
30
31 if (((crcValue & 0x8000) >> 8) ^ (newByte & 0x80)) {
32 crcValue = (crcValue << 1) ^ 0x102;
33 } else {
34 crcValue = (crcValue << 1);
35 }
36
37 newByte <<= 1;
38 }
39
40 return crcValue;
41 }
42
43 int main ()
44 {
45 unsigned short crc = 0x0D80;
46 for (unsigned char i = 0; i < 255; i++)
47 {
48 unsigned short res1 = crc16_O0 (crc, i);
49 unsigned short res2 = crc16 (crc, i);
50 if (res1 != res2)
51 __builtin_abort ();
52 crc = res1;
53 }
54 __builtin_exit (0);
55 }
56 /* { dg-final { scan-tree-dump "function maybe contains CRC calculation." "crc" } } */
57 /* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc" } } */
58 /* { dg-final { scan-tree-dump "Bit forward" "crc" } } */
59 /* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */
60 /* { dg-final { scan-tree-dump-times "Couldn't generate faster CRC code." 0 "crc" } } */