Debian Codegraph @

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

raw
1 /* { dg-do compile } */
2 /* { dg-options "-fdump-tree-crc" } */
3 /* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */
4
5 /* We don't detect this case, because there are many conditional branches.
6 Even if we detected it won't be verified,
7 because we would get more than two execution paths (states). */
8
9 #include <stdint.h>
10
11 typedef uint8_t byte;
12 byte Compute_CRC8_Simple_OneByte_ShiftReg (byte byteVal)
13 {
14 const byte generator = 0x1D;
15 byte crc = 0; /* init crc register with 0 */
16 byte b = byteVal;
17 for (int i = 7; i >= 0; i--)
18 {
19 /* check if MSB is set */
20 if ((crc & 0x80) != 0)
21 { /* MSB set, shift it out of the register */
22 crc = (byte) (crc << 1);
23 /* shift in next bit of input stream:
24 * If it's 1, set LSB of crc to 1.
25 * If it's 0, set LSB of crc to 0. */
26 crc = ((byte) (b & (1 << i)) != 0) ? (byte) (crc | 0x01)
27 : (byte) (crc & 0xFE);
28 /* Perform the 'division' by XORing the crc register with the generator polynomial */
29 crc = (byte) (crc ^ generator);
30 }
31 else
32 { /* MSB not set, shift it out and shift in next bit of input stream. Same as above, just no division */
33 crc = (byte) (crc << 1);
34 crc = ((byte) (b & (1 << i)) != 0) ? (byte) (crc | 0x01)
35 : (byte) (crc & 0xFE);
36 }
37 }
38 return crc;
39 }