Debian Codegraph @

gcc/testsuite/gcc.dg/torture/crc-CCIT-data16-xorOutside_InsideFor.c

raw
1 /* { dg-do run } */
2 /* { dg-options "-fdump-tree-crc-details" } */
3 /* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-g" "-Os" "-flto" } } */
4
5 #include <stdlib.h>
6 #include <stdint.h>
7
8 __attribute__ ((noinline))
9 uint16_t crc16_xor_outside (uint16_t data, uint16_t crc)
10 {
11 int carry;
12 crc ^= data;
13 for (int i = 0; i < 16; ++i) {
14 carry = ((crc & 0x8000));
15 crc <<= 1;
16 if (carry) crc ^= 0x1021;
17 }
18 return crc;
19 }
20
21 __attribute__ ((noinline))
22 uint16_t crc16_xor_inside (uint16_t data, uint16_t crc)
23 {
24 int carry;
25 for (int i = 0; i < 16; ++i) {
26 carry = ((crc & 0x8000) ^ (data & 0x8000));
27 crc <<= 1;
28 data <<= 1;
29 if (carry) crc ^= 0x1021;
30 }
31 return crc;
32 }
33
34 int main ()
35 {
36 uint16_t crc = 0;
37
38 for (uint16_t i = 0; i < 655; i++)
39 {
40 uint16_t res1 = crc16_xor_outside (i, crc);
41 uint16_t res2 = crc16_xor_inside (i, crc);
42 crc = res1;
43 if (res1 != res2)
44 abort ();
45 }
46
47 if (crc16_xor_outside (0x1111, 0xFFFF) != 0x2f5d)
48 abort ();
49
50 if (crc16_xor_inside (0x1111, 0xFFFF) != 0x2f5d)
51 abort ();
52 }
53
54 /* { dg-final { scan-tree-dump "crc16_xor_outside function maybe contains CRC calculation." "crc" } } */
55 /* { dg-final { scan-tree-dump "crc16_xor_inside function maybe contains CRC calculation." "crc" } } */
56 /* { dg-final { scan-tree-dump "Loop iteration number is 15" "crc" } } */
57 /* { dg-final { scan-tree-dump "Bit forward" "crc" } } */
58 /* { dg-final { scan-tree-dump-times "calculates CRC!" 2 "crc" } } */